Mercurial > hg > hg-fastimport
comparison hgfastimport/hgimport.py @ 44:61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Update test script to test real cvs2git output, not my idealized
version of it.
| author | Greg Ward <greg-hg@gerg.ca> |
|---|---|
| date | Mon, 11 May 2009 17:46:19 -0400 |
| parents | 000d4174071c |
| children | 93c2b1e832bd |
comparison
equal
deleted
inserted
replaced
| 43:000d4174071c | 44:61ff7b929cea |
|---|---|
| 107 # refs/heads), and implies that it can be called whatever the | 107 # refs/heads), and implies that it can be called whatever the |
| 108 # creator of the fastimport dump wants to call it. So the name | 108 # creator of the fastimport dump wants to call it. So the name |
| 109 # of the fixup branch should be configurable! | 109 # of the fixup branch should be configurable! |
| 110 fixup = (cmd.ref == "refs/heads/TAG.FIXUP") | 110 fixup = (cmd.ref == "refs/heads/TAG.FIXUP") |
| 111 | 111 |
| 112 if fixup and self.last_commit is not None: | |
| 113 # If this is a fixup commit, pretend it is on the same | |
| 114 # branch as the previous commit. This gives sensible | |
| 115 # behaviour for selecting the first parent and for | |
| 116 # determining the Mercurial branch name. | |
| 117 cmd.ref = self.last_commit.ref | |
| 118 | |
| 119 if cmd.from_: | 112 if cmd.from_: |
| 120 first_parent = self.committish_rev(cmd.from_) | 113 first_parent = self.committish_rev(cmd.from_) |
| 121 else: | 114 else: |
| 122 first_parent = self.branch_map.get(cmd.ref, nullrev) | 115 first_parent = self.branch_map.get(cmd.ref, nullrev) |
| 123 #self.ui.write("First parent: %s\n" % first_parent) | |
| 124 # Update to the first parent | |
| 125 mercurial.hg.clean(self.repo, self.repo.lookup(first_parent)) | |
| 126 #self.ui.write("Bing\n") | 116 #self.ui.write("Bing\n") |
| 127 if cmd.merges: | 117 if cmd.merges: |
| 128 #self.ui.write("foo") | 118 #self.ui.write("foo") |
| 129 if len(cmd.merges) > 1: | 119 if len(cmd.merges) > 1: |
| 130 raise NotImplementedError("Can't handle more than two parents") | 120 raise NotImplementedError("Can't handle more than two parents") |
| 131 second_parent = self.committish_rev(cmd.merges[0]) | 121 second_parent = self.committish_rev(cmd.merges[0]) |
| 132 #self.ui.write("Second parent: %s\n" % second_parent) | 122 #self.ui.write("Second parent: %s\n" % second_parent) |
| 133 mercurial.commands.debugsetparents(self.ui, self.repo, | 123 else: |
| 134 first_parent, second_parent) | 124 second_parent = nullrev |
| 125 | |
| 126 if first_parent is nullrev and second_parent is not nullrev: | |
| 127 # First commit on a new branch that has 'merge' but no 'from': | |
| 128 # special case meaning branch starts with no files; the contents of | |
| 129 # the first commit (this one) determine the list of files at branch | |
| 130 # time. | |
| 131 first_parent = second_parent | |
| 132 second_parent = nullrev | |
| 133 no_files = True # XXX not handled | |
| 134 | |
| 135 self.ui.debug("commit %s: first_parent = %r, second_parent = %r\n" | |
| 136 % (cmd.id, first_parent, second_parent)) | |
| 137 assert ((first_parent != second_parent) or | |
| 138 (first_parent == second_parent == -1)), \ | |
| 139 ("commit %s: first_parent == second parent = %r" | |
| 140 % (cmd.id, first_parent)) | |
| 141 | |
| 142 # Update to the first parent | |
| 143 mercurial.hg.clean(self.repo, self.repo.lookup(first_parent)) | |
| 144 mercurial.commands.debugsetparents( | |
| 145 self.ui, self.repo, first_parent, second_parent) | |
| 146 | |
| 135 #self.ui.write("Bing\n") | 147 #self.ui.write("Bing\n") |
| 136 if cmd.ref == "refs/heads/master": | 148 if cmd.ref == "refs/heads/master": |
| 137 branch = "default" | 149 branch = "default" |
| 150 elif fixup and first_parent is not nullrev: | |
| 151 # If this is a fixup commit, pretend it happened on the same branch | |
| 152 # as its first parent. (We don't want a Mercurial named branch | |
| 153 # called "TAG.FIXUP" in the output repository.) | |
| 154 branch = self.repo.changectx(first_parent).branch() | |
| 138 else: | 155 else: |
| 139 branch = cmd.ref[len("refs/heads/"):] | 156 branch = cmd.ref[len("refs/heads/"):] |
| 140 #self.ui.write("Branch: %s\n" % branch) | 157 #self.ui.write("Branch: %s\n" % branch) |
| 141 self.repo.dirstate.setbranch(branch) | 158 self.repo.dirstate.setbranch(branch) |
| 142 #self.ui.write("Bing\n") | 159 #self.ui.write("Bing\n") |
| 187 if cmd.ref.startswith("refs/heads/"): | 204 if cmd.ref.startswith("refs/heads/"): |
| 188 # The usual case for 'reset': (re)create the named branch. | 205 # The usual case for 'reset': (re)create the named branch. |
| 189 # XXX what should we do if cmd.from_ is None? | 206 # XXX what should we do if cmd.from_ is None? |
| 190 if cmd.from_ is not None: | 207 if cmd.from_ is not None: |
| 191 self.branch_map[cmd.ref] = self.committish_rev(cmd.from_) | 208 self.branch_map[cmd.ref] = self.committish_rev(cmd.from_) |
| 209 else: | |
| 210 # pretend the branch never existed... is this right?!? | |
| 211 try: | |
| 212 del self.branch_map[cmd.ref] | |
| 213 except KeyError: | |
| 214 pass | |
| 192 #else: | 215 #else: |
| 193 # # XXX filename? line number? | 216 # # XXX filename? line number? |
| 194 # self.ui.warn("ignoring branch reset with no 'from'\n") | 217 # self.ui.warn("ignoring branch reset with no 'from'\n") |
| 195 elif cmd.ref.startswith("refs/tags/"): | 218 elif cmd.ref.startswith("refs/tags/"): |
| 196 # Create a "lightweight tag" in Git terms. As I understand | 219 # Create a "lightweight tag" in Git terms. As I understand |
