contrib/convert-repo
changeset 692 695dd9a491da
parent 450 9d785fd7deec
child 694 51eb248d3348
child 705 574869103985
--- a/contrib/convert-repo	Wed Jul 13 01:48:03 2005 -0800
+++ b/contrib/convert-repo	Wed Jul 13 01:53:27 2005 -0800
@@ -31,20 +31,23 @@
         h = file(self.path + "/.git/HEAD").read()[:-1]
         return [h]
 
+    def catfile(self, rev, type):
+        if rev == "0" * 40: raise IOError()
+        path = os.getcwd()
+        os.chdir(self.path)
+        fh = os.popen("git-cat-file %s %s" % (type, rev))
+        os.chdir(path)
+        return fh.read()
+
     def getfile(self, name, rev):
-        a = file(self.path + ("/.git/objects/%s/%s"
-                              % (rev[:2], rev[2:]))).read()
-        b = zlib.decompress(a)
-        if sha.sha(b).hexdigest() != rev: raise "bad hash"
-        head, text = b.split('\0', 1)
-        return text
+        return self.catfile(rev, "blob")
 
     def getchanges(self, version):
         path = os.getcwd()
         os.chdir(self.path)
-        fh = os.popen("git-diff-tree -m -r %s" % (version))
+        fh = os.popen("git-diff-tree --root -m -r %s" % (version))
         os.chdir(path)
-        
+
         changes = []
         for l in fh:
             if "\t" not in l: continue
@@ -56,7 +59,7 @@
         return changes
 
     def getcommit(self, version):
-        c = self.getfile("", version) # read the commit hash
+        c = self.catfile(version, "commit") # read the commit hash
         end = c.find("\n\n")
         message = c[end+2:]
         l = c[:end].splitlines()
@@ -69,7 +72,7 @@
                 date = " ".join(p[-2:])
                 author = " ".join(p[:-2])
                 if author[0] == "<": author = author[1:-1]
-            if n == "committer": 
+            if n == "committer":
                 p = v.split()
                 date = " ".join(p[-2:])
                 committer = " ".join(p[:-2])
@@ -88,22 +91,22 @@
         h = self.repo.changelog.heads()
         h = [ hg.hex(x) for x in h ]
         return h
-        
+
     def putfile(self, f, e, data):
         self.repo.wfile(f, "w").write(data)
+        if self.repo.dirstate.state(f) == '?':
+            self.repo.dirstate.update([f], "a")
+
         util.set_exec(self.repo.wjoin(f), e)
 
     def delfile(self, f):
         try:
             os.unlink(self.repo.wjoin(f))
-            self.repo.remove([f])
+            #self.repo.remove([f])
         except:
             pass
 
     def putcommit(self, files, parents, author, dest, text):
-        if not parents: parents = ["0" * 40]
-        if len(parents) < 2: parents.append("0" * 40)
-
         seen = {}
         pl = []
         for p in parents:
@@ -112,16 +115,18 @@
                 seen[p] = 1
         parents = pl
 
+        if len(parents) < 2: parents.append("0" * 40)
+        if len(parents) < 2: parents.append("0" * 40)
         p2 = parents.pop(0)
-        c = self.repo.changelog.count()
+
         while parents:
             p1 = p2
             p2 = parents.pop(0)
-            self.repo.rawcommit(files, text, author, dest, 
+            self.repo.rawcommit(files, text, author, dest,
                                 hg.bin(p1), hg.bin(p2))
             text = "(octopus merge fixup)\n"
 
-        return hg.hex(self.repo.changelog.node(c))
+        return hg.hex(self.repo.changelog.tip())
 
 class convert:
     def __init__(self, source, dest, mapfile):
@@ -155,6 +160,7 @@
         visit = parents.keys()
         seen = {}
         children = {}
+
         while visit:
             n = visit.pop(0)
             if n in seen: continue
@@ -169,7 +175,7 @@
 
         s = []
         removed = {}
-        visit = parents.keys()
+        visit = children.keys()
         while visit:
             n = visit.pop(0)
             if n in removed: continue