# HG changeset patch # User Patrick Mezard # Date 2009-09-06 13:29:14 # Node ID d1b135f2f4153e815e777690605fac18aed9863d # Parent d8143769e1d4d88186bb7affa8fca920cc573958 convert: fix history topology when using hg.tagsbranch When using hg.tagsbranch, all conversions fail at transcribing the source repo topology with conversion scenarios interleaving: - initial repo conversion, - then upstream tag - then later incremental conversion The problem is caused by the usage of the last source revid as source revid for the tagnode in the revision map. On a later incremental conversion, when resolving some child commit of the true last source revid, convert will parent the nodes to the tag node. If using tagsbranch you get a bad topology where all incremental commit nodes end up in the tag branch. Analysis and test by Edouard Gomez diff --git a/hgext/convert/common.py b/hgext/convert/common.py --- a/hgext/convert/common.py +++ b/hgext/convert/common.py @@ -203,6 +203,8 @@ class converter_sink(object): """Put tags into sink. tags: {tagname: sink_rev_id, ...} where tagname is an UTF-8 string. + Return a pair (tag_revision, tag_parent_revision), or (None, None) + if nothing was changed. """ raise NotImplementedError() diff --git a/hgext/convert/convcmd.py b/hgext/convert/convcmd.py --- a/hgext/convert/convcmd.py +++ b/hgext/convert/convcmd.py @@ -336,11 +336,14 @@ class converter(object): ctags[k] = self.map[v] if c and ctags: - nrev = self.dest.puttags(ctags) - # write another hash correspondence to override the previous - # one so we don't end up with extra tag heads - if nrev: - self.map[c] = nrev + nrev, tagsparent = self.dest.puttags(ctags) + if nrev and tagsparent: + # write another hash correspondence to override the previous + # one so we don't end up with extra tag heads + tagsparents = [e for e in self.map.iteritems() + if e[1] == tagsparent] + if tagsparents: + self.map[tagsparents[0][0]] = nrev self.writeauthormap() finally: diff --git a/hgext/convert/hg.py b/hgext/convert/hg.py --- a/hgext/convert/hg.py +++ b/hgext/convert/hg.py @@ -189,7 +189,7 @@ class mercurial_sink(converter_sink): newlines = sorted([("%s %s\n" % (tags[tag], tag)) for tag in tags]) if newlines == oldlines: - return None + return None, None data = "".join(newlines) def getfilectx(repo, memctx, f): return context.memfilectx(f, data, False, False, None) @@ -201,7 +201,7 @@ class mercurial_sink(converter_sink): [".hgtags"], getfilectx, "convert-repo", date, extra) self.repo.commitctx(ctx) - return hex(self.repo.changelog.tip()) + return hex(self.repo.changelog.tip()), hex(tagparent) def setfilemapmode(self, active): self.filemapmode = active diff --git a/tests/test-convert-clonebranches.out b/tests/test-convert-clonebranches.out --- a/tests/test-convert-clonebranches.out +++ b/tests/test-convert-clonebranches.out @@ -18,12 +18,12 @@ marked working directory as branch branc % incremental conversion 2 c1 pulling from branch0 into branch1 -2 changesets found +4 changesets found 1 c2 pulling from branch0 into branch2 -2 changesets found +4 changesets found 0 c3 pulling from branch2 into branch3 -3 changesets found +5 changesets found pulling from branch1 into branch3 1 changesets found diff --git a/tests/test-convert-tagsbranch-topology b/tests/test-convert-tagsbranch-topology new file mode 100755 --- /dev/null +++ b/tests/test-convert-tagsbranch-topology @@ -0,0 +1,64 @@ +#!/bin/sh + +"$TESTDIR/hghave" git || exit 80 + +echo "[extensions]" >> $HGRCPATH +echo "convert=" >> $HGRCPATH +echo 'hgext.graphlog =' >> $HGRCPATH +echo '[convert]' >> $HGRCPATH +echo 'hg.usebranchnames = True' >> $HGRCPATH +echo 'hg.tagsbranch = tags-update' >> $HGRCPATH + +GIT_AUTHOR_NAME='test'; export GIT_AUTHOR_NAME +GIT_AUTHOR_EMAIL='test@example.org'; export GIT_AUTHOR_EMAIL +GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0000"; export GIT_AUTHOR_DATE +GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"; export GIT_COMMITTER_NAME +GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"; export GIT_COMMITTER_EMAIL +GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"; export GIT_COMMITTER_DATE + +count=10 +action() +{ + GIT_AUTHOR_DATE="2007-01-01 00:00:$count +0000" + GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE" + git "$@" >/dev/null 2>/dev/null || echo "git command error" + count=`expr $count + 1` +} + +glog() +{ + hg glog --template '{rev} "{desc|firstline}" files: {files}\n' "$@" +} + +convertrepo() +{ + hg convert --datesort git-repo hg-repo +} + +# Build a GIT repo with at least 1 tag +mkdir git-repo +cd git-repo +git init >/dev/null 2>&1 +echo a > a +git add a +action commit -m "rev1" +action tag -m "tag1" tag1 +cd .. + +# Do a first conversion +convertrepo + +# Simulate upstream updates after first conversion +cd git-repo +echo b > a +git add a +action commit -m "rev2" +action tag -m "tag2" tag2 +cd .. + +# Perform an incremental conversion +convertrepo + +# Print the log +cd hg-repo +glog diff --git a/tests/test-convert-tagsbranch-topology.out b/tests/test-convert-tagsbranch-topology.out new file mode 100644 --- /dev/null +++ b/tests/test-convert-tagsbranch-topology.out @@ -0,0 +1,19 @@ +initializing destination hg-repo repository +scanning source... +sorting... +converting... +0 rev1 +updating tags +scanning source... +sorting... +converting... +0 rev2 +updating tags +o 3 "update tags" files: .hgtags +| +| o 2 "rev2" files: a +| | +o | 1 "update tags" files: .hgtags + / +o 0 "rev1" files: a +