# HG changeset patch # User mpm@selenic.com # Date 1121248407 28800 # Node ID 695dd9a491dad2a63fe7770149da096c194bf0da # Parent 61c6b4178b9e34e0da0ec950ba25c534a7640ece convert-repo: deal with packed git and other fixes call out to git-cat-file directly to deal with packed files use git-diff-tree --root to handle import of first commit quiet some dirstate warnings fix parent logic in commit whitespace bits topological sort fix manifest hash: 2943af0168dd2f5e85bba6515fd08687e264863f diff --git a/contrib/convert-repo b/contrib/convert-repo --- a/contrib/convert-repo +++ b/contrib/convert-repo @@ -31,20 +31,23 @@ class convert_git: 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 @@ class convert_git: 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 @@ class convert_git: 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 @@ class convert_mercurial: 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 @@ class convert_mercurial: 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 @@ class convert: visit = parents.keys() seen = {} children = {} + while visit: n = visit.pop(0) if n in seen: continue @@ -169,7 +175,7 @@ class convert: s = [] removed = {} - visit = parents.keys() + visit = children.keys() while visit: n = visit.pop(0) if n in removed: continue