Merge with TAH
authormpm@selenic.com
Thu, 14 Jul 2005 22:56:55 -0800
changeset 705 574869103985
parent 694 51eb248d3348 (diff)
parent 704 5ca319a641e1 (current diff)
child 706 5107a7b6b14a
child 723 9e0f3ba4a9c2
Merge with TAH manifest hash: 197e0d1a0d7376a9eb72381330462f06490ab821
contrib/convert-repo
doc/hgrc.5.txt
mercurial/commands.py
mercurial/hg.py
mercurial/lock.py
mercurial/util.py
tests/test-bad-pull
tests/test-bad-pull.out
tests/test-basic.out
tests/test-copy.out
tests/test-flags.out
tests/test-tag.out
tests/test-up-local-change.out
--- 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)
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1335,7 +1335,7 @@ def dispatch(args):
         elif hasattr(inst, "reason"):
             u.warn("abort: error %d: %s\n" % (inst.reason[0], inst.reason[1]))
         elif hasattr(inst, "args") and inst[0] == errno.EPIPE:
-            u.warn("broken pipe\n")
+            if u.debugflag: u.warn("broken pipe\n")
         else:
             raise
     except OSError, inst: