comparison hgfastimport/hgimport.py @ 39:177a133519bc

Handle fixup branches for tag/branch creation better. - ensure that fixup commits actually become Mercurial changesets (rather than dropping them on the floor) - pretend that fixup commits happen on the same branch as the previous commit - don't track fixup commits as branch heads - add test-fastimport-cvs2git-fixup (currently failing because tags are not converted)
author Greg Ward <greg-hg@gerg.ca>
date Sat, 09 May 2009 18:52:33 -0400
parents 513449a88de2
children 0eb03c70c8f0
comparison
equal deleted inserted replaced
38:3048a2dcf68a 39:177a133519bc
40 self.repo = repo 40 self.repo = repo
41 self.opts = opts 41 self.opts = opts
42 self.last_mark = None 42 self.last_mark = None
43 self.mark_map = {} 43 self.mark_map = {}
44 self.branch_map = {} 44 self.branch_map = {}
45 self.last_commit = None # CommitCommand object
45 #self.tag_map = {} 46 #self.tag_map = {}
46 #self.tag_back_map = {} 47 #self.tag_back_map = {}
47 self.finished = False 48 self.finished = False
48 49
49 self.numblobs = 0 # for progress reporting 50 self.numblobs = 0 # for progress reporting
94 return self.mark_map[committish] 95 return self.mark_map[committish]
95 else: 96 else:
96 return self.branch_map[committish] 97 return self.branch_map[committish]
97 98
98 def commit_handler(self, cmd): 99 def commit_handler(self, cmd):
99 if cmd.ref == "refs/heads/TAG.FIXUP": 100 # XXX this assumes the fixup branch name used by cvs2git. In
100 #self.tag_back_map[cmd.mark] == first_parent 101 # contrast, git-fast-import(1) recommends "TAG_FIXUP" (not under
101 commit_handler = hgechoprocessor.HgEchoCommitHandler(cmd, self.ui, self.repo, **self.opts) 102 # refs/heads), and implies that it can be called whatever the
102 commit_handler.process() 103 # creator of the fastimport dump wants to call it. So the name
103 return 104 # of the fixup branch should be configurable!
105 fixup = (cmd.ref == "refs/heads/TAG.FIXUP")
106
107 if fixup and self.last_commit is not None:
108 # If this is a fixup commit, pretend it is on the same
109 # branch as the previous commit. This gives sensible
110 # behaviour for selecting the first parent and for
111 # determining the Mercurial branch name.
112 cmd.ref = self.last_commit.ref
113
104 if cmd.from_: 114 if cmd.from_:
105 first_parent = self.committish_rev(cmd.from_) 115 first_parent = self.committish_rev(cmd.from_)
106 else: 116 else:
107 first_parent = self.branch_map.get(cmd.ref, nullrev) 117 first_parent = self.branch_map.get(cmd.ref, nullrev)
108 #self.ui.write("First parent: %s\n" % first_parent) 118 #self.ui.write("First parent: %s\n" % first_parent)
151 node = self.repo.rawcommit( 161 node = self.repo.rawcommit(
152 files=files, text=text, user=user, date=date) 162 files=files, text=text, user=user, date=date)
153 rev = self.repo.changelog.rev(node) 163 rev = self.repo.changelog.rev(node)
154 if cmd.mark is not None: 164 if cmd.mark is not None:
155 self.mark_map[":" + cmd.mark] = rev 165 self.mark_map[":" + cmd.mark] = rev
156 self.branch_map[cmd.ref] = rev 166 if not fixup:
167 self.branch_map[cmd.ref] = rev
168 self.last_commit = cmd
157 self.ui.write("Done commit of rev %d\n" % rev) 169 self.ui.write("Done commit of rev %d\n" % rev)
158 #self.ui.write("%s\n" % self.mark_map) 170 #self.ui.write("%s\n" % self.mark_map)
159 171
160 def convert_date(self, c): 172 def convert_date(self, c):
161 res = (int(c[2]), int(c[3])) 173 res = (int(c[2]), int(c[3]))