Show More
@@ -20,7 +20,7 b'' | |||||
20 | # This updates the mapfile on each commit copied, so it can be |
|
20 | # This updates the mapfile on each commit copied, so it can be | |
21 | # interrupted and can be run repeatedly to copy new commits. |
|
21 | # interrupted and can be run repeatedly to copy new commits. | |
22 |
|
22 | |||
23 | import sys, os, zlib, sha |
|
23 | import sys, os, zlib, sha, time | |
24 | from mercurial import hg, ui, util |
|
24 | from mercurial import hg, ui, util | |
25 |
|
25 | |||
26 | class convert_git: |
|
26 | class convert_git: | |
@@ -35,7 +35,7 b' class convert_git:' | |||||
35 | if rev == "0" * 40: raise IOError() |
|
35 | if rev == "0" * 40: raise IOError() | |
36 | path = os.getcwd() |
|
36 | path = os.getcwd() | |
37 | os.chdir(self.path) |
|
37 | os.chdir(self.path) | |
38 | fh = os.popen("git-cat-file %s %s" % (type, rev)) |
|
38 | fh = os.popen("git-cat-file %s %s 2>/dev/null" % (type, rev)) | |
39 | os.chdir(path) |
|
39 | os.chdir(path) | |
40 | return fh.read() |
|
40 | return fh.read() | |
41 |
|
41 | |||
@@ -81,6 +81,18 b' class convert_git:' | |||||
81 | if n == "parent": parents.append(v) |
|
81 | if n == "parent": parents.append(v) | |
82 | return (parents, author, date, message) |
|
82 | return (parents, author, date, message) | |
83 |
|
83 | |||
|
84 | def gettags(self): | |||
|
85 | tags = {} | |||
|
86 | for f in os.listdir(self.path + "/.git/refs/tags"): | |||
|
87 | try: | |||
|
88 | h = file(self.path + "/.git/refs/tags/" + f).read().strip() | |||
|
89 | p, a, d, m = self.getcommit(h) | |||
|
90 | if not p: p = [h] # git is ugly, don't blame me | |||
|
91 | tags[f] = p[0] | |||
|
92 | except: | |||
|
93 | pass | |||
|
94 | return tags | |||
|
95 | ||||
84 | class convert_mercurial: |
|
96 | class convert_mercurial: | |
85 | def __init__(self, path): |
|
97 | def __init__(self, path): | |
86 | self.path = path |
|
98 | self.path = path | |
@@ -128,6 +140,32 b' class convert_mercurial:' | |||||
128 |
|
140 | |||
129 | return hg.hex(self.repo.changelog.tip()) |
|
141 | return hg.hex(self.repo.changelog.tip()) | |
130 |
|
142 | |||
|
143 | def puttags(self, tags): | |||
|
144 | try: | |||
|
145 | old = self.repo.wfile(".hgtags").read() | |||
|
146 | oldlines = old.splitlines(1) | |||
|
147 | oldlines.sort() | |||
|
148 | except: | |||
|
149 | oldlines = [] | |||
|
150 | ||||
|
151 | k = tags.keys() | |||
|
152 | k.sort() | |||
|
153 | newlines = [] | |||
|
154 | for tag in k: | |||
|
155 | newlines.append("%s %s\n" % (tags[tag], tag)) | |||
|
156 | ||||
|
157 | newlines.sort() | |||
|
158 | ||||
|
159 | if newlines != oldlines: | |||
|
160 | print "updating tags" | |||
|
161 | f = self.repo.wfile(".hgtags", "w") | |||
|
162 | f.write("".join(newlines)) | |||
|
163 | f.close() | |||
|
164 | if not oldlines: self.repo.add([".hgtags"]) | |||
|
165 | date = "%s 0" % time.mktime(time.gmtime()) | |||
|
166 | self.repo.rawcommit([".hgtags"], "update tags", "convert-repo", | |||
|
167 | date, self.repo.changelog.tip(), hg.nullid) | |||
|
168 | ||||
131 | class convert: |
|
169 | class convert: | |
132 | def __init__(self, source, dest, mapfile): |
|
170 | def __init__(self, source, dest, mapfile): | |
133 | self.source = source |
|
171 | self.source = source | |
@@ -229,6 +267,15 b' class convert:' | |||||
229 | print num, desc |
|
267 | print num, desc | |
230 | self.copy(c) |
|
268 | self.copy(c) | |
231 |
|
269 | |||
|
270 | tags = self.source.gettags() | |||
|
271 | ctags = {} | |||
|
272 | for k in tags: | |||
|
273 | v = tags[k] | |||
|
274 | if v in self.map: | |||
|
275 | ctags[k] = self.map[v] | |||
|
276 | ||||
|
277 | self.dest.puttags(ctags) | |||
|
278 | ||||
232 | gitpath, hgpath, mapfile = sys.argv[1:] |
|
279 | gitpath, hgpath, mapfile = sys.argv[1:] | |
233 |
|
280 | |||
234 | c = convert(convert_git(gitpath), convert_mercurial(hgpath), mapfile) |
|
281 | c = convert(convert_git(gitpath), convert_mercurial(hgpath), mapfile) |
General Comments 0
You need to be logged in to leave comments.
Login now