19 # |
19 # |
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, time |
23 import sys, os, zlib, sha, time |
|
24 |
|
25 os.environ["HGENCODING"] = "utf-8" |
|
26 |
24 from mercurial import hg, ui, util |
27 from mercurial import hg, ui, util |
|
28 |
|
29 def recode(s): |
|
30 try: |
|
31 return s.decode("utf-8").encode("utf-8") |
|
32 except: |
|
33 try: |
|
34 return s.decode("latin-1").encode("utf-8") |
|
35 except: |
|
36 return s.decode("utf-8", "replace").encode("utf-8") |
25 |
37 |
26 class convert_git: |
38 class convert_git: |
27 def __init__(self, path): |
39 def __init__(self, path): |
28 self.path = path |
40 self.path = path |
29 |
41 |
53 |
65 |
54 def getcommit(self, version): |
66 def getcommit(self, version): |
55 c = self.catfile(version, "commit") # read the commit hash |
67 c = self.catfile(version, "commit") # read the commit hash |
56 end = c.find("\n\n") |
68 end = c.find("\n\n") |
57 message = c[end+2:] |
69 message = c[end+2:] |
|
70 message = recode(message) |
58 l = c[:end].splitlines() |
71 l = c[:end].splitlines() |
59 manifest = l[0].split()[1] |
72 manifest = l[0].split()[1] |
60 parents = [] |
73 parents = [] |
61 for e in l[1:]: |
74 for e in l[1:]: |
62 n,v = e.split(" ", 1) |
75 n,v = e.split(" ", 1) |
63 if n == "author": |
76 if n == "author": |
64 p = v.split() |
77 p = v.split() |
65 tm, tz = p[-2:] |
78 tm, tz = p[-2:] |
66 author = " ".join(p[:-2]) |
79 author = " ".join(p[:-2]) |
67 if author[0] == "<": author = author[1:-1] |
80 if author[0] == "<": author = author[1:-1] |
|
81 author = recode(author) |
68 if n == "committer": |
82 if n == "committer": |
69 p = v.split() |
83 p = v.split() |
70 tm, tz = p[-2:] |
84 tm, tz = p[-2:] |
71 committer = " ".join(p[:-2]) |
85 committer = " ".join(p[:-2]) |
72 if committer[0] == "<": committer = committer[1:-1] |
86 if committer[0] == "<": committer = committer[1:-1] |
|
87 committer = recode(committer) |
73 message += "\ncommitter: %s\n" % v |
88 message += "\ncommitter: %s\n" % v |
74 if n == "parent": parents.append(v) |
89 if n == "parent": parents.append(v) |
75 |
90 |
76 tzs, tzh, tzm = tz[-5:-4] + "1", tz[-4:-2], tz[-2:] |
91 tzs, tzh, tzm = tz[-5:-4] + "1", tz[-4:-2], tz[-2:] |
77 tz = -int(tzs) * (int(tzh) * 3600 + int(tzm)) |
92 tz = -int(tzs) * (int(tzh) * 3600 + int(tzm)) |