# HG changeset patch # User mpm@selenic.com # Date 1121409466 28800 # Node ID 51eb248d33488dc3cf9372304095ceeeab412535 # Parent 10c0264751dad77c6b461d55d86d80e33a76ddc9 Teach convert-repo about tags Git tags are bad, very bad. More importantly, they're horribly inconsistent. This drops tags which don't appear to work like most of the others. manifest hash: f2dda9e9a3ae8a0d84b19e496059b8a795b8e603 diff --git a/contrib/convert-repo b/contrib/convert-repo --- a/contrib/convert-repo +++ b/contrib/convert-repo @@ -20,7 +20,7 @@ # This updates the mapfile on each commit copied, so it can be # interrupted and can be run repeatedly to copy new commits. -import sys, os, zlib, sha +import sys, os, zlib, sha, time from mercurial import hg, ui, util class convert_git: @@ -35,7 +35,7 @@ class convert_git: if rev == "0" * 40: raise IOError() path = os.getcwd() os.chdir(self.path) - fh = os.popen("git-cat-file %s %s" % (type, rev)) + fh = os.popen("git-cat-file %s %s 2>/dev/null" % (type, rev)) os.chdir(path) return fh.read() @@ -81,6 +81,18 @@ class convert_git: if n == "parent": parents.append(v) return (parents, author, date, message) + def gettags(self): + tags = {} + for f in os.listdir(self.path + "/.git/refs/tags"): + try: + h = file(self.path + "/.git/refs/tags/" + f).read().strip() + p, a, d, m = self.getcommit(h) + if not p: p = [h] # git is ugly, don't blame me + tags[f] = p[0] + except: + pass + return tags + class convert_mercurial: def __init__(self, path): self.path = path @@ -128,6 +140,32 @@ class convert_mercurial: return hg.hex(self.repo.changelog.tip()) + def puttags(self, tags): + try: + old = self.repo.wfile(".hgtags").read() + oldlines = old.splitlines(1) + oldlines.sort() + except: + oldlines = [] + + k = tags.keys() + k.sort() + newlines = [] + for tag in k: + newlines.append("%s %s\n" % (tags[tag], tag)) + + newlines.sort() + + if newlines != oldlines: + print "updating tags" + f = self.repo.wfile(".hgtags", "w") + f.write("".join(newlines)) + f.close() + if not oldlines: self.repo.add([".hgtags"]) + date = "%s 0" % time.mktime(time.gmtime()) + self.repo.rawcommit([".hgtags"], "update tags", "convert-repo", + date, self.repo.changelog.tip(), hg.nullid) + class convert: def __init__(self, source, dest, mapfile): self.source = source @@ -229,6 +267,15 @@ class convert: print num, desc self.copy(c) + tags = self.source.gettags() + ctags = {} + for k in tags: + v = tags[k] + if v in self.map: + ctags[k] = self.map[v] + + self.dest.puttags(ctags) + gitpath, hgpath, mapfile = sys.argv[1:] c = convert(convert_git(gitpath), convert_mercurial(hgpath), mapfile)