git-cc icon indicating copy to clipboard operation
git-cc copied to clipboard

file content is lost during rebase when that new file is checked in at the same time as its parent folder in clearcase

Open jslhcl opened this issue 9 years ago • 2 comments

Hi, charleso,

I run into this problem during executing "gitcc rebase" command. Let me elaborate the reproduce steps:

  1. check in a new file using some tools like CCRC (clear case remote client) which makes the version 1 of this file shares the same modified time as that in its parent folder
  2. then migrate that repository to git. After rebase the new file's content is lost, it becomes an empty file.

I think the reason is that:

when check in a new file in clearcase, it will automatically add two versions: version 0 (with the type mkelemversion, which is an empty file) and version 1 (with the type checkinversion, which contains the real content), and if we check in the new file with some tool like CCRC, the file's parent folder will be automatically checked in, so the check in time of version 1 and the folder is the same (the check in time of version 0 is a little earlier)

Then in the rebase.py code, first the version 1 of that file is checked in through Changeset.add(), then we will check in the folder through Uncataloged.add(), in this function:

class Uncataloged(Changeset):
    def add(self, files):
                ......
                history = filter(None, history.split('\n'))    # contains version1 and version0
                all_versions = self.parse_history(history)

                date = cc_exec(['describe', '-fmt', '%Nd', dir])
                actual_versions = self.filter_versions(all_versions, lambda x: x[1] < date)  # version1 is filtered out since its date is the same as that in folder 

                versions = self.checkin_versions(actual_versions)  #version 0 is also filtered out, versions is empty now
                if not versions:
                    print("No proper versions of '%s' file. Check if it is empty." % added)
                    versions = self.empty_file_versions(actual_versions)  #version 0 is added back
                if not versions:
                    print("It appears that you may be missing a branch in the includes section of your gitcc config for file '%s'." % added)
                    continue
                self._add(added, versions[0][2].strip())   # this file becomes blank since version 1 is overwritten by version 0

As the comments in the code above, the file's content is lost since it is overwritten by the empty file version 0.

I think there are two possible solutions:

  1. change
lambda x: x[1] < date

to

lambda x: x[1] <= date
  1. if the versions is empty after
versions = self.checkin_versions(actual_versions)

just continue and do not add the empty version file back.

I prefer No.2 since the 1st solution will cause a duplicate commit for version 1.

What do you think? Thanks.

jslhcl avatar Apr 22 '15 03:04 jslhcl

Hi @jslhcl,

Honestly? I haven't use git-cc in about 5 years and I'm afraid I can't remember what the original intention is for the code.

I have a suspicion it used to work before this change:

https://github.com/charleso/git-cc/commit/3b2998d555b0a0f196923d650d85670e576cdf7f

If you checkout the commit before that you may find it works.

In any case, there isn't much I can do I'm afraid. :( Feel free to fork and make the changes you see fit.

Charles

charleso avatar Apr 22 '15 11:04 charleso

Hi, @charleso

Yes, you are right, it is due to issue #20 . But I don't think it is an issue. As far as I know, if you create a new branch and add a new file in the new branch, not only the version 0 and version 1 will be added in the new branch, but also version 0 (empty file) will be added in the origin branch.

in #20's case, XieDong added the file in the "css_refactor" branch, there should be no such file in the main branch, but due to some mechanism in clear case, this file is added into main branch as an empty file.

So I don't think we should add this empty file back after migrating. Let me fork and make the change.

Thanks Lei

jslhcl avatar Apr 23 '15 08:04 jslhcl