29 |
29 |
30 def getheads(self): |
30 def getheads(self): |
31 h = file(self.path + "/.git/HEAD").read()[:-1] |
31 h = file(self.path + "/.git/HEAD").read()[:-1] |
32 return [h] |
32 return [h] |
33 |
33 |
|
34 def catfile(self, rev, type): |
|
35 if rev == "0" * 40: raise IOError() |
|
36 path = os.getcwd() |
|
37 os.chdir(self.path) |
|
38 fh = os.popen("git-cat-file %s %s" % (type, rev)) |
|
39 os.chdir(path) |
|
40 return fh.read() |
|
41 |
34 def getfile(self, name, rev): |
42 def getfile(self, name, rev): |
35 a = file(self.path + ("/.git/objects/%s/%s" |
43 return self.catfile(rev, "blob") |
36 % (rev[:2], rev[2:]))).read() |
|
37 b = zlib.decompress(a) |
|
38 if sha.sha(b).hexdigest() != rev: raise "bad hash" |
|
39 head, text = b.split('\0', 1) |
|
40 return text |
|
41 |
44 |
42 def getchanges(self, version): |
45 def getchanges(self, version): |
43 path = os.getcwd() |
46 path = os.getcwd() |
44 os.chdir(self.path) |
47 os.chdir(self.path) |
45 fh = os.popen("git-diff-tree -m -r %s" % (version)) |
48 fh = os.popen("git-diff-tree --root -m -r %s" % (version)) |
46 os.chdir(path) |
49 os.chdir(path) |
47 |
50 |
48 changes = [] |
51 changes = [] |
49 for l in fh: |
52 for l in fh: |
50 if "\t" not in l: continue |
53 if "\t" not in l: continue |
51 m, f = l[:-1].split("\t") |
54 m, f = l[:-1].split("\t") |
52 m = m.split() |
55 m = m.split() |
54 p = (m[1] == "100755") |
57 p = (m[1] == "100755") |
55 changes.append((f, h, p)) |
58 changes.append((f, h, p)) |
56 return changes |
59 return changes |
57 |
60 |
58 def getcommit(self, version): |
61 def getcommit(self, version): |
59 c = self.getfile("", version) # read the commit hash |
62 c = self.catfile(version, "commit") # read the commit hash |
60 end = c.find("\n\n") |
63 end = c.find("\n\n") |
61 message = c[end+2:] |
64 message = c[end+2:] |
62 l = c[:end].splitlines() |
65 l = c[:end].splitlines() |
63 manifest = l[0].split()[1] |
66 manifest = l[0].split()[1] |
64 parents = [] |
67 parents = [] |
67 if n == "author": |
70 if n == "author": |
68 p = v.split() |
71 p = v.split() |
69 date = " ".join(p[-2:]) |
72 date = " ".join(p[-2:]) |
70 author = " ".join(p[:-2]) |
73 author = " ".join(p[:-2]) |
71 if author[0] == "<": author = author[1:-1] |
74 if author[0] == "<": author = author[1:-1] |
72 if n == "committer": |
75 if n == "committer": |
73 p = v.split() |
76 p = v.split() |
74 date = " ".join(p[-2:]) |
77 date = " ".join(p[-2:]) |
75 committer = " ".join(p[:-2]) |
78 committer = " ".join(p[:-2]) |
76 if committer[0] == "<": committer = committer[1:-1] |
79 if committer[0] == "<": committer = committer[1:-1] |
77 message += "\ncommitter: %s %s\n" % (committer, date) |
80 message += "\ncommitter: %s %s\n" % (committer, date) |
86 |
89 |
87 def getheads(self): |
90 def getheads(self): |
88 h = self.repo.changelog.heads() |
91 h = self.repo.changelog.heads() |
89 h = [ hg.hex(x) for x in h ] |
92 h = [ hg.hex(x) for x in h ] |
90 return h |
93 return h |
91 |
94 |
92 def putfile(self, f, e, data): |
95 def putfile(self, f, e, data): |
93 self.repo.wfile(f, "w").write(data) |
96 self.repo.wfile(f, "w").write(data) |
|
97 if self.repo.dirstate.state(f) == '?': |
|
98 self.repo.dirstate.update([f], "a") |
|
99 |
94 util.set_exec(self.repo.wjoin(f), e) |
100 util.set_exec(self.repo.wjoin(f), e) |
95 |
101 |
96 def delfile(self, f): |
102 def delfile(self, f): |
97 try: |
103 try: |
98 os.unlink(self.repo.wjoin(f)) |
104 os.unlink(self.repo.wjoin(f)) |
99 self.repo.remove([f]) |
105 #self.repo.remove([f]) |
100 except: |
106 except: |
101 pass |
107 pass |
102 |
108 |
103 def putcommit(self, files, parents, author, dest, text): |
109 def putcommit(self, files, parents, author, dest, text): |
104 if not parents: parents = ["0" * 40] |
|
105 if len(parents) < 2: parents.append("0" * 40) |
|
106 |
|
107 seen = {} |
110 seen = {} |
108 pl = [] |
111 pl = [] |
109 for p in parents: |
112 for p in parents: |
110 if p not in seen: |
113 if p not in seen: |
111 pl.append(p) |
114 pl.append(p) |
112 seen[p] = 1 |
115 seen[p] = 1 |
113 parents = pl |
116 parents = pl |
114 |
117 |
|
118 if len(parents) < 2: parents.append("0" * 40) |
|
119 if len(parents) < 2: parents.append("0" * 40) |
115 p2 = parents.pop(0) |
120 p2 = parents.pop(0) |
116 c = self.repo.changelog.count() |
121 |
117 while parents: |
122 while parents: |
118 p1 = p2 |
123 p1 = p2 |
119 p2 = parents.pop(0) |
124 p2 = parents.pop(0) |
120 self.repo.rawcommit(files, text, author, dest, |
125 self.repo.rawcommit(files, text, author, dest, |
121 hg.bin(p1), hg.bin(p2)) |
126 hg.bin(p1), hg.bin(p2)) |
122 text = "(octopus merge fixup)\n" |
127 text = "(octopus merge fixup)\n" |
123 |
128 |
124 return hg.hex(self.repo.changelog.node(c)) |
129 return hg.hex(self.repo.changelog.tip()) |
125 |
130 |
126 class convert: |
131 class convert: |
127 def __init__(self, source, dest, mapfile): |
132 def __init__(self, source, dest, mapfile): |
128 self.source = source |
133 self.source = source |
129 self.dest = dest |
134 self.dest = dest |