Mercurial > hg > hg-fastimport
changeset 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 | 3048a2dcf68a |
| children | 0eb03c70c8f0 |
| files | hgfastimport/hgimport.py tests/test-fastimport-cvs2git-fixup tests/test-fastimport-cvs2git-fixup.out |
| diffstat | 3 files changed, 222 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/hgfastimport/hgimport.py Fri May 08 11:03:51 2009 -0400 +++ b/hgfastimport/hgimport.py Sat May 09 18:52:33 2009 -0400 @@ -42,6 +42,7 @@ self.last_mark = None self.mark_map = {} self.branch_map = {} + self.last_commit = None # CommitCommand object #self.tag_map = {} #self.tag_back_map = {} self.finished = False @@ -96,11 +97,20 @@ return self.branch_map[committish] def commit_handler(self, cmd): - if cmd.ref == "refs/heads/TAG.FIXUP": - #self.tag_back_map[cmd.mark] == first_parent - commit_handler = hgechoprocessor.HgEchoCommitHandler(cmd, self.ui, self.repo, **self.opts) - commit_handler.process() - return + # XXX this assumes the fixup branch name used by cvs2git. In + # contrast, git-fast-import(1) recommends "TAG_FIXUP" (not under + # refs/heads), and implies that it can be called whatever the + # creator of the fastimport dump wants to call it. So the name + # of the fixup branch should be configurable! + fixup = (cmd.ref == "refs/heads/TAG.FIXUP") + + if fixup and self.last_commit is not None: + # If this is a fixup commit, pretend it is on the same + # branch as the previous commit. This gives sensible + # behaviour for selecting the first parent and for + # determining the Mercurial branch name. + cmd.ref = self.last_commit.ref + if cmd.from_: first_parent = self.committish_rev(cmd.from_) else: @@ -153,7 +163,9 @@ rev = self.repo.changelog.rev(node) if cmd.mark is not None: self.mark_map[":" + cmd.mark] = rev - self.branch_map[cmd.ref] = rev + if not fixup: + self.branch_map[cmd.ref] = rev + self.last_commit = cmd self.ui.write("Done commit of rev %d\n" % rev) #self.ui.write("%s\n" % self.mark_map)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-fastimport-cvs2git-fixup Sat May 09 18:52:33 2009 -0400 @@ -0,0 +1,136 @@ +#!/bin/sh + +# Test a dump created by cvs2git from a CVS repository with branches and +# tags. Specifically, we're looking at the creation of a new branch +# REL-2-2-3 where the branch point is tagged REL-2-2-3-P1. + +# Rather than create an artificial example, this is derived from +# a real-life CVS repository. + +. $TESTDIR/fastimport-common + +cat > git-blob.dat <<EOF +blob +mark :2308 +data 5 +boo! + +blob +mark :14693 +data 18 +# Doxyfile 1.2.14 + +blob +mark :11363 +data 6 +hello + +EOF + +# XXX this is the dump that cvs2git actually produces. Subtle +# bogosities: +# - commit 1619 has no first parent, but the "merge" directive +# (second parent) points to the commit that should be its first parent +# - commit 1620 should have 1619 as its first parent, but 1619 is +# set to the second parent... and there is no first parent +# +# I'm not using this one; I'm just recording it here to vent about +# cvs2git. See below for the dump that I want cvs2git to produce, +# and the one that is correctly handled by hg-fastimport. +#cat > git-dump.dat <<EOF +cat > /dev/null <<EOF +commit refs/heads/master +mark :1000000373 +committer Example <example> 991793180 +0000 +data 15 +added Makefile + +M 100644 :2308 Makefile + +commit refs/heads/REL-2-2-3 +mark :1000001619 +committer cvs2git <cvs2git> 1022533494 +0000 +data 47 +create branch 'REL-2-2-3' (manufactured commit) +merge :1000000373 +M 100644 :2308 Makefile + +commit refs/heads/TAG.FIXUP +mark :1000001620 +committer cvs2git <cvs2git> 1022533495 +0000 +data 47 +create tag 'REL-2-2-3-P1' (manufactured commit) +merge :1000001619 +M 100644 :14693 Tools/Debug/C++/DebugCpp.doxygen + +reset refs/tags/REL-2-2-3-P1 +from :1000001620 +reset refs/heads/TAG.FIXUP + +commit refs/heads/master +mark :1000001621 +committer Other <other@example.com> 1022536868 +0000 +data 18 +added iostream.h + +M 100644 :11363 main.cpp +EOF + +# XXX this is the dump that I think cvs2git *should* produce, not what +# it actually does produce (hmmm) +cat > git-dump.dat <<EOF +commit refs/heads/master +mark :1000000373 +committer Example <example> 991793180 +0000 +data 15 +added Makefile + +M 100644 :2308 Makefile + +commit refs/heads/REL-2-2-3 +mark :1000001619 +committer cvs2git <cvs2git> 1022533494 +0000 +data 47 +create branch 'REL-2-2-3' (manufactured commit) +from :1000000373 +M 100644 :2308 Makefile + +commit refs/heads/TAG.FIXUP +mark :1000001620 +committer cvs2git <cvs2git> 1022533495 +0000 +data 47 +create tag 'REL-2-2-3-P1' (manufactured commit) +from :1000001619 +M 100644 :14693 Tools/Debug/C++/DebugCpp.doxygen + +reset refs/tags/REL-2-2-3-P1 +from :1000001620 +reset refs/heads/TAG.FIXUP + +commit refs/heads/master +mark :1000001621 +committer Other <other@example.com> 1022536868 +0000 +data 18 +added iostream.h + +M 100644 :11363 main.cpp +EOF + +echo "% import cvs2git with branch/tag" +set -e +hg init realcvs +hg -R realcvs fastimport git-blob.dat git-dump.dat \ + | sed "s|$HGTMP|HGTMP|g" + +echo "% hg glog" +cd realcvs +hg glog -v + +echo "% hg branches" +hg branches + +echo "% hg heads -v" +hg heads + +echo "% hg tags -v" +hg tags
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-fastimport-cvs2git-fixup.out Sat May 09 18:52:33 2009 -0400 @@ -0,0 +1,68 @@ +% import cvs2git with branch/tag +Reading source: git-blob.dat +Reading source: git-dump.dat +0 files updated, 0 files merged, 0 files removed, 0 files unresolved +Done commit of rev 0 +1 files updated, 0 files merged, 0 files removed, 0 files unresolved +Done commit of rev 1 +0 files updated, 0 files merged, 0 files removed, 0 files unresolved +Done commit of rev 2 +0 files updated, 0 files merged, 0 files removed, 0 files unresolved +Done commit of rev 3 +Removing blob dir 'HGTMP/test-fastimport-cvs2git-fixup/realcvs/.hg/blobs' ... +% hg glog +@ changeset: 3:158529dd7d57 +| tag: tip +| parent: 0:8c270455072a +| user: Other <other@example.com> +| date: Mon May 27 22:01:08 2002 +0000 +| files: main.cpp +| description: +| added iostream.h +| +| +| o changeset: 2:9c706dffba0e +| | branch: REL-2-2-3 +| | user: cvs2git <cvs2git> +| | date: Mon May 27 21:04:55 2002 +0000 +| | files: Tools/Debug/C++/DebugCpp.doxygen +| | description: +| | create tag 'REL-2-2-3-P1' (manufactured commit) +| | +| | +| o changeset: 1:fd354e4cf420 +|/ branch: REL-2-2-3 +| user: cvs2git <cvs2git> +| date: Mon May 27 21:04:54 2002 +0000 +| description: +| create branch 'REL-2-2-3' (manufactured commit) +| +| +o changeset: 0:8c270455072a + user: Example <example> + date: Wed Jun 06 02:06:20 2001 +0000 + files: Makefile + description: + added Makefile + + +% hg branches +default 3:158529dd7d57 +REL-2-2-3 2:9c706dffba0e +% hg heads -v +changeset: 3:158529dd7d57 +tag: tip +parent: 0:8c270455072a +user: Other <other@example.com> +date: Mon May 27 22:01:08 2002 +0000 +summary: added iostream.h + +changeset: 2:9c706dffba0e +branch: REL-2-2-3 +user: cvs2git <cvs2git> +date: Mon May 27 21:04:55 2002 +0000 +summary: create tag 'REL-2-2-3-P1' (manufactured commit) + +% hg tags -v +tip 3:158529dd7d57 +REL-2-2-3-P1 2:9c706dffba0e
