Show More
@@ -1,94 +1,94 b'' | |||||
1 | # hg backend for convert extension |
|
1 | # hg backend for convert extension | |
2 |
|
2 | |||
3 | import os, time |
|
3 | import os, time | |
4 | from mercurial import hg |
|
4 | from mercurial import hg, util | |
5 |
|
5 | |||
6 | from common import NoRepo, converter_sink |
|
6 | from common import NoRepo, converter_sink | |
7 |
|
7 | |||
8 | class convert_mercurial(converter_sink): |
|
8 | class convert_mercurial(converter_sink): | |
9 | def __init__(self, ui, path): |
|
9 | def __init__(self, ui, path): | |
10 | self.path = path |
|
10 | self.path = path | |
11 | self.ui = ui |
|
11 | self.ui = ui | |
12 | try: |
|
12 | try: | |
13 | self.repo = hg.repository(self.ui, path) |
|
13 | self.repo = hg.repository(self.ui, path) | |
14 | except: |
|
14 | except: | |
15 | raise NoRepo("could open hg repo %s" % path) |
|
15 | raise NoRepo("could open hg repo %s" % path) | |
16 |
|
16 | |||
17 | def mapfile(self): |
|
17 | def mapfile(self): | |
18 | return os.path.join(self.path, ".hg", "shamap") |
|
18 | return os.path.join(self.path, ".hg", "shamap") | |
19 |
|
19 | |||
20 | def authorfile(self): |
|
20 | def authorfile(self): | |
21 | return os.path.join(self.path, ".hg", "authormap") |
|
21 | return os.path.join(self.path, ".hg", "authormap") | |
22 |
|
22 | |||
23 | def getheads(self): |
|
23 | def getheads(self): | |
24 | h = self.repo.changelog.heads() |
|
24 | h = self.repo.changelog.heads() | |
25 | return [ hg.hex(x) for x in h ] |
|
25 | return [ hg.hex(x) for x in h ] | |
26 |
|
26 | |||
27 | def putfile(self, f, e, data): |
|
27 | def putfile(self, f, e, data): | |
28 | self.repo.wwrite(f, data, e) |
|
28 | self.repo.wwrite(f, data, e) | |
29 | if self.repo.dirstate.state(f) == '?': |
|
29 | if self.repo.dirstate.state(f) == '?': | |
30 | self.repo.dirstate.update([f], "a") |
|
30 | self.repo.dirstate.update([f], "a") | |
31 |
|
31 | |||
32 | def delfile(self, f): |
|
32 | def delfile(self, f): | |
33 | try: |
|
33 | try: | |
34 | util.unlink(self.repo.wjoin(f)) |
|
34 | util.unlink(self.repo.wjoin(f)) | |
35 | #self.repo.remove([f]) |
|
35 | #self.repo.remove([f]) | |
36 | except: |
|
36 | except OSError: | |
37 | pass |
|
37 | pass | |
38 |
|
38 | |||
39 | def putcommit(self, files, parents, commit): |
|
39 | def putcommit(self, files, parents, commit): | |
40 | seen = {} |
|
40 | seen = {} | |
41 | pl = [] |
|
41 | pl = [] | |
42 | for p in parents: |
|
42 | for p in parents: | |
43 | if p not in seen: |
|
43 | if p not in seen: | |
44 | pl.append(p) |
|
44 | pl.append(p) | |
45 | seen[p] = 1 |
|
45 | seen[p] = 1 | |
46 | parents = pl |
|
46 | parents = pl | |
47 |
|
47 | |||
48 | if len(parents) < 2: parents.append("0" * 40) |
|
48 | if len(parents) < 2: parents.append("0" * 40) | |
49 | if len(parents) < 2: parents.append("0" * 40) |
|
49 | if len(parents) < 2: parents.append("0" * 40) | |
50 | p2 = parents.pop(0) |
|
50 | p2 = parents.pop(0) | |
51 |
|
51 | |||
52 | text = commit.desc |
|
52 | text = commit.desc | |
53 | extra = {} |
|
53 | extra = {} | |
54 | try: |
|
54 | try: | |
55 | extra["branch"] = commit.branch |
|
55 | extra["branch"] = commit.branch | |
56 | except AttributeError: |
|
56 | except AttributeError: | |
57 | pass |
|
57 | pass | |
58 |
|
58 | |||
59 | while parents: |
|
59 | while parents: | |
60 | p1 = p2 |
|
60 | p1 = p2 | |
61 | p2 = parents.pop(0) |
|
61 | p2 = parents.pop(0) | |
62 | a = self.repo.rawcommit(files, text, commit.author, commit.date, |
|
62 | a = self.repo.rawcommit(files, text, commit.author, commit.date, | |
63 | hg.bin(p1), hg.bin(p2), extra=extra) |
|
63 | hg.bin(p1), hg.bin(p2), extra=extra) | |
64 | text = "(octopus merge fixup)\n" |
|
64 | text = "(octopus merge fixup)\n" | |
65 | p2 = hg.hex(self.repo.changelog.tip()) |
|
65 | p2 = hg.hex(self.repo.changelog.tip()) | |
66 |
|
66 | |||
67 | return p2 |
|
67 | return p2 | |
68 |
|
68 | |||
69 | def puttags(self, tags): |
|
69 | def puttags(self, tags): | |
70 | try: |
|
70 | try: | |
71 | old = self.repo.wfile(".hgtags").read() |
|
71 | old = self.repo.wfile(".hgtags").read() | |
72 | oldlines = old.splitlines(1) |
|
72 | oldlines = old.splitlines(1) | |
73 | oldlines.sort() |
|
73 | oldlines.sort() | |
74 | except: |
|
74 | except: | |
75 | oldlines = [] |
|
75 | oldlines = [] | |
76 |
|
76 | |||
77 | k = tags.keys() |
|
77 | k = tags.keys() | |
78 | k.sort() |
|
78 | k.sort() | |
79 | newlines = [] |
|
79 | newlines = [] | |
80 | for tag in k: |
|
80 | for tag in k: | |
81 | newlines.append("%s %s\n" % (tags[tag], tag)) |
|
81 | newlines.append("%s %s\n" % (tags[tag], tag)) | |
82 |
|
82 | |||
83 | newlines.sort() |
|
83 | newlines.sort() | |
84 |
|
84 | |||
85 | if newlines != oldlines: |
|
85 | if newlines != oldlines: | |
86 | self.ui.status("updating tags\n") |
|
86 | self.ui.status("updating tags\n") | |
87 | f = self.repo.wfile(".hgtags", "w") |
|
87 | f = self.repo.wfile(".hgtags", "w") | |
88 | f.write("".join(newlines)) |
|
88 | f.write("".join(newlines)) | |
89 | f.close() |
|
89 | f.close() | |
90 | if not oldlines: self.repo.add([".hgtags"]) |
|
90 | if not oldlines: self.repo.add([".hgtags"]) | |
91 | date = "%s 0" % int(time.mktime(time.gmtime())) |
|
91 | date = "%s 0" % int(time.mktime(time.gmtime())) | |
92 | self.repo.rawcommit([".hgtags"], "update tags", "convert-repo", |
|
92 | self.repo.rawcommit([".hgtags"], "update tags", "convert-repo", | |
93 | date, self.repo.changelog.tip(), hg.nullid) |
|
93 | date, self.repo.changelog.tip(), hg.nullid) | |
94 | return hg.hex(self.repo.changelog.tip()) |
|
94 | return hg.hex(self.repo.changelog.tip()) |
General Comments 0
You need to be logged in to leave comments.
Login now