# HG changeset patch # User Patrick Mezard # Date 2008-06-18 22:14:24 # Node ID 2011bb8ada9ad4e9fafd087453ee0158c050028e # Parent c9b8d2565b922474c09b6af63d95210339f51bb1 convert: hg sink commits without working dir diff --git a/hgext/convert/hg.py b/hgext/convert/hg.py --- a/hgext/convert/hg.py +++ b/hgext/convert/hg.py @@ -17,7 +17,7 @@ import os, time from mercurial.i18n import _ from mercurial.repo import RepoError from mercurial.node import bin, hex, nullid -from mercurial import hg, revlog, util +from mercurial import hg, revlog, util, context from common import NoRepo, commit, converter_source, converter_sink @@ -54,11 +54,9 @@ class mercurial_sink(converter_sink): self.ui.debug(_('run hg sink pre-conversion action\n')) self.wlock = self.repo.wlock() self.lock = self.repo.lock() - self.repo.dirstate.clear() def after(self): self.ui.debug(_('run hg sink post-conversion action\n')) - self.repo.dirstate.invalidate() self.lock = None self.wlock = None @@ -111,30 +109,18 @@ class mercurial_sink(converter_sink): self.before() def putcommit(self, files, copies, parents, commit, source): - # Apply changes to working copy - for f, v in files: - try: - data = source.getfile(f, v) - except IOError, inst: - try: - util.unlink(self.repo.wjoin(f)) - except OSError: - pass - else: - e = source.getmode(f, v) - self.repo.wwrite(f, data, e) - if f not in self.repo.dirstate: - self.repo.dirstate.normallookup(f) - if f in copies: - self.repo.copy(copies[f], f) - files = [f[0] for f in files] - seen = {} + files = dict(files) + def getfilectx(repo, memctx, f): + v = files[f] + data = source.getfile(f, v) + e = source.getmode(f, v) + return context.memfilectx(f, data, 'l' in e, 'x' in e, copies.get(f)) + pl = [] for p in parents: - if p not in seen: + if p not in pl: pl.append(p) - seen[p] = 1 parents = pl nparents = len(parents) if self.filemapmode and nparents == 1: @@ -155,9 +141,9 @@ class mercurial_sink(converter_sink): while parents: p1 = p2 p2 = parents.pop(0) - a = self.repo.rawcommit(files, text, commit.author, commit.date, - bin(p1), bin(p2), extra=extra) - self.repo.dirstate.clear() + ctx = context.memctx(self.repo, (p1, p2), text, files.keys(), getfilectx, + commit.author, commit.date, extra) + a = self.repo.commitctx(ctx) text = "(octopus merge fixup)\n" p2 = hex(self.repo.changelog.tip()) @@ -166,43 +152,42 @@ class mercurial_sink(converter_sink): mnode = self.repo.changelog.read(bin(p2))[0] if not man.cmp(m1node, man.revision(mnode)): self.repo.rollback() - self.repo.dirstate.clear() return parent return p2 def puttags(self, tags): - try: - old = self.repo.wfile(".hgtags").read() - oldlines = old.splitlines(1) - oldlines.sort() - except: - oldlines = [] + try: + parentctx = self.repo.changectx(self.tagsbranch) + tagparent = parentctx.node() + except RepoError, inst: + parentctx = None + tagparent = nullid - k = tags.keys() - k.sort() - newlines = [] - for tag in k: - newlines.append("%s %s\n" % (tags[tag], tag)) - - newlines.sort() + try: + old = parentctx.filectx(".hgtags").data() + oldlines = old.splitlines(1) + oldlines.sort() + except: + oldlines = [] - if newlines != oldlines: - self.ui.status("updating tags\n") - f = self.repo.wfile(".hgtags", "w") - f.write("".join(newlines)) - f.close() - if not oldlines: self.repo.add([".hgtags"]) - date = "%s 0" % int(time.mktime(time.gmtime())) - extra = {} - if self.tagsbranch != 'default': - extra['branch'] = self.tagsbranch - try: - tagparent = self.repo.changectx(self.tagsbranch).node() - except RepoError, inst: - tagparent = nullid - self.repo.rawcommit([".hgtags"], "update tags", "convert-repo", - date, tagparent, nullid, extra=extra) - return hex(self.repo.changelog.tip()) + newlines = [("%s %s\n" % (tags[tag], tag)) for tag in tags.keys()] + newlines.sort() + + if newlines == oldlines: + return None + data = "".join(newlines) + + def getfilectx(repo, memctx, f): + return context.memfilectx(f, data, False, False, None) + + self.ui.status("updating tags\n") + date = "%s 0" % int(time.mktime(time.gmtime())) + extra = {'branch': self.tagsbranch} + ctx = context.memctx(self.repo, (tagparent, None), "update tags", + [".hgtags"], getfilectx, "convert-repo", date, + extra) + self.repo.commitctx(ctx) + return hex(self.repo.changelog.tip()) def setfilemapmode(self, active): self.filemapmode = active diff --git a/tests/test-convert-cvs b/tests/test-convert-cvs --- a/tests/test-convert-cvs +++ b/tests/test-convert-cvs @@ -7,6 +7,11 @@ cvscall() cvs -f $@ } +hgcat() +{ + hg --cwd src-hg cat -r tip "$1" +} + echo "[extensions]" >> $HGRCPATH echo "convert = " >> $HGRCPATH @@ -45,13 +50,13 @@ cd .. echo % convert fresh repo hg convert src src-hg | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g' -cat src-hg/a -cat src-hg/b/c +hgcat a +hgcat b/c echo % convert fresh repo with --filemap echo include b/c > filemap hg convert --filemap filemap src src-filemap | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g' -cat src-hg/b/c +hgcat b/c hg -R src-filemap log --template '#rev# #desc# files: #files#\n' echo % commit new file revisions @@ -64,12 +69,12 @@ cd .. echo % convert again hg convert src src-hg | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g' -cat src-hg/a -cat src-hg/b/c +hgcat a +hgcat b/c echo % convert again with --filemap hg convert --filemap filemap src src-filemap | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g' -cat src-hg/b/c +hgcat b/c hg -R src-filemap log --template '#rev# #desc# files: #files#\n' echo % commit branch @@ -84,12 +89,12 @@ cd .. echo % convert again hg convert src src-hg | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g' -cat src-hg/a -cat src-hg/b/c +hgcat a +hgcat b/c echo % convert again with --filemap hg convert --filemap filemap src src-filemap | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g' -cat src-hg/b/c +hgcat b/c hg -R src-filemap log --template '#rev# #desc# files: #files#\n' echo "graphlog = " >> $HGRCPATH diff --git a/tests/test-convert-cvs-builtincvsps b/tests/test-convert-cvs-builtincvsps --- a/tests/test-convert-cvs-builtincvsps +++ b/tests/test-convert-cvs-builtincvsps @@ -7,6 +7,11 @@ cvscall() cvs -f "$@" } +hgcat() +{ + hg --cwd src-hg cat -r tip "$1" +} + echo "[extensions]" >> $HGRCPATH echo "convert = " >> $HGRCPATH echo "graphlog = " >> $HGRCPATH @@ -48,13 +53,13 @@ cd .. echo % convert fresh repo hg convert src src-hg | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g' -cat src-hg/a -cat src-hg/b/c +hgcat a +hgcat b/c echo % convert fresh repo with --filemap echo include b/c > filemap hg convert --filemap filemap src src-filemap | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g' -cat src-hg/b/c +hgcat b/c hg -R src-filemap log --template '#rev# #desc# files: #files#\n' echo % commit new file revisions @@ -67,12 +72,12 @@ cd .. echo % convert again hg convert src src-hg | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g' -cat src-hg/a -cat src-hg/b/c +hgcat a +hgcat b/c echo % convert again with --filemap hg convert --filemap filemap src src-filemap | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g' -cat src-hg/b/c +hgcat b/c hg -R src-filemap log --template '#rev# #desc# files: #files#\n' echo % commit branch @@ -87,12 +92,12 @@ cd .. echo % convert again hg convert src src-hg | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g' -cat src-hg/a -cat src-hg/b/c +hgcat a +hgcat b/c echo % convert again with --filemap hg convert --filemap filemap src src-filemap | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g' -cat src-hg/b/c +hgcat b/c hg -R src-filemap log --template '#rev# #desc# files: #files#\n' echo "graphlog = " >> $HGRCPATH diff --git a/tests/test-convert-cvs-builtincvsps.out b/tests/test-convert-cvs-builtincvsps.out --- a/tests/test-convert-cvs-builtincvsps.out +++ b/tests/test-convert-cvs-builtincvsps.out @@ -104,7 +104,6 @@ sorting... converting... 0 ci2 a -a c d % convert again with --filemap diff --git a/tests/test-convert-cvs.out b/tests/test-convert-cvs.out --- a/tests/test-convert-cvs.out +++ b/tests/test-convert-cvs.out @@ -79,7 +79,6 @@ sorting... converting... 0 ci2 a -a c d % convert again with --filemap