# HG changeset patch # User Patrick Mezard # Date 1243869162 -7200 # Node ID 68e0a55eee6e97df2bbb4548c6b6dbd2d2b7bb97 # Parent 827d4e807d57ae31a91811c0c889f442186b8fe6 convert: rewrite tags when converting from hg to hg diff -r 827d4e807d57 -r 68e0a55eee6e hgext/convert/common.py --- a/hgext/convert/common.py Mon Jun 01 17:12:41 2009 +0200 +++ b/hgext/convert/common.py Mon Jun 01 17:12:42 2009 +0200 @@ -144,6 +144,12 @@ """ return False + def lookuprev(self, rev): + """If rev is a meaningful revision reference in source, return + the referenced identifier in the same format used by getcommit(). + return None otherwise. + """ + return None class converter_sink(object): """Conversion sink (target) interface""" @@ -174,13 +180,15 @@ mapping equivalent authors identifiers for each system.""" return None - def putcommit(self, files, copies, parents, commit, source): + def putcommit(self, files, copies, parents, commit, source, revmap): """Create a revision with all changed files listed in 'files' - and having listed parents. 'commit' is a commit object containing - at a minimum the author, date, and message for this changeset. - 'files' is a list of (path, version) tuples, 'copies'is a dictionary - mapping destinations to sources, and 'source' is the source repository. - Only getfile() and getmode() should be called on 'source'. + and having listed parents. 'commit' is a commit object + containing at a minimum the author, date, and message for this + changeset. 'files' is a list of (path, version) tuples, + 'copies' is a dictionary mapping destinations to sources, + 'source' is the source repository, and 'revmap' is a mapfile + of source revisions to converted revisions. Only getfile(), + getmode(), and lookuprev() should be called on 'source'. Note that the sink repository is not told to update itself to a particular revision (or even what that revision would be) diff -r 827d4e807d57 -r 68e0a55eee6e hgext/convert/convcmd.py --- a/hgext/convert/convcmd.py Mon Jun 01 17:12:41 2009 +0200 +++ b/hgext/convert/convcmd.py Mon Jun 01 17:12:42 2009 +0200 @@ -297,7 +297,8 @@ parents = [self.map.get(p, p) for p in parents] except KeyError: parents = [b[0] for b in pbranches] - newnode = self.dest.putcommit(files, copies, parents, commit, self.source) + newnode = self.dest.putcommit(files, copies, parents, commit, + self.source, self.map) self.source.converted(rev, newnode) self.map[rev] = newnode diff -r 827d4e807d57 -r 68e0a55eee6e hgext/convert/filemap.py --- a/hgext/convert/filemap.py Mon Jun 01 17:12:41 2009 +0200 +++ b/hgext/convert/filemap.py Mon Jun 01 17:12:42 2009 +0200 @@ -354,3 +354,6 @@ def hasnativeorder(self): return self.base.hasnativeorder() + + def lookuprev(self, rev): + return self.base.lookuprev(rev) diff -r 827d4e807d57 -r 68e0a55eee6e hgext/convert/hg.py --- a/hgext/convert/hg.py Mon Jun 01 17:12:41 2009 +0200 +++ b/hgext/convert/hg.py Mon Jun 01 17:12:42 2009 +0200 @@ -18,7 +18,7 @@ # source. -import os, time +import os, time, cStringIO from mercurial.i18n import _ from mercurial.node import bin, hex, nullid from mercurial import hg, util, context, error @@ -112,13 +112,27 @@ self.repo.pull(prepo, [prepo.lookup(h) for h in heads]) self.before() - def putcommit(self, files, copies, parents, commit, source): + def _rewritetags(self, source, revmap, data): + fp = cStringIO.StringIO() + for line in data.splitlines(): + s = line.split(' ', 1) + if len(s) != 2: + continue + revid = revmap.get(source.lookuprev(s[0])) + if not revid: + continue + fp.write('%s %s\n' % (revid, s[1])) + return fp.getvalue() + + def putcommit(self, files, copies, parents, commit, source, revmap): files = dict(files) def getfilectx(repo, memctx, f): v = files[f] data = source.getfile(f, v) e = source.getmode(f, v) + if f == '.hgtags': + data = self._rewritetags(source, revmap, data) return context.memfilectx(f, data, 'l' in e, 'x' in e, copies.get(f)) pl = [] @@ -341,3 +355,9 @@ def hasnativeorder(self): return True + + def lookuprev(self, rev): + try: + return hex(self.repo.lookup(rev)) + except error.RepoError: + return None diff -r 827d4e807d57 -r 68e0a55eee6e hgext/convert/subversion.py --- a/hgext/convert/subversion.py Mon Jun 01 17:12:41 2009 +0200 +++ b/hgext/convert/subversion.py Mon Jun 01 17:12:42 2009 +0200 @@ -1170,7 +1170,7 @@ def revid(self, rev): return u"svn:%s@%s" % (self.uuid, rev) - def putcommit(self, files, copies, parents, commit, source): + def putcommit(self, files, copies, parents, commit, source, revmap): # Apply changes to working copy for f, v in files: try: diff -r 827d4e807d57 -r 68e0a55eee6e tests/test-convert-hg-sink --- a/tests/test-convert-hg-sink Mon Jun 01 17:12:41 2009 +0200 +++ b/tests/test-convert-hg-sink Mon Jun 01 17:12:42 2009 +0200 @@ -55,3 +55,13 @@ echo '% no copies' hg up -C hg debugrename baz +cd .. + +echo '% test tag rewriting' +cat > filemap <&1 | grep -v 'subversion python bindings could not be loaded' +cd new-filemap +hg tags +cd .. diff -r 827d4e807d57 -r 68e0a55eee6e tests/test-convert-hg-sink.out --- a/tests/test-convert-hg-sink.out Mon Jun 01 17:12:41 2009 +0200 +++ b/tests/test-convert-hg-sink.out Mon Jun 01 17:12:42 2009 +0200 @@ -48,3 +48,15 @@ % no copies 1 files updated, 0 files merged, 0 files removed, 0 files unresolved baz not renamed +% test tag rewriting +initializing destination new-filemap repository +scanning source... +sorting... +converting... +4 add foo and bar +3 remove foo +2 add foo/file +1 Added tag some-tag for changeset ad681a868e44 +0 add baz +tip 2:6f4fd1df87fb +some-tag 0:ba8636729451