Mercurial > hg
comparison hgext/convert/git.py @ 4759:20ec5cc02f18
convert: ove recode method into converter_source
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Sun, 01 Jul 2007 12:58:08 -0700 |
parents | 96614af3c679 |
children | 07efcce17d28 |
comparison
equal
deleted
inserted
replaced
4758:a72dd3bfce41 | 4759:20ec5cc02f18 |
---|---|
2 | 2 |
3 import os | 3 import os |
4 | 4 |
5 from common import NoRepo, commit, converter_source | 5 from common import NoRepo, commit, converter_source |
6 | 6 |
7 def recode(s): | |
8 try: | |
9 return s.decode("utf-8").encode("utf-8") | |
10 except: | |
11 try: | |
12 return s.decode("latin-1").encode("utf-8") | |
13 except: | |
14 return s.decode("utf-8", "replace").encode("utf-8") | |
15 | |
16 class convert_git(converter_source): | 7 class convert_git(converter_source): |
17 def __init__(self, ui, path): | 8 def __init__(self, ui, path): |
18 if os.path.isdir(path + "/.git"): | 9 if os.path.isdir(path + "/.git"): |
19 path += "/.git" | 10 path += "/.git" |
11 if not os.path.exists(path + "/objects"): | |
12 raise NoRepo("couldn't open GIT repo %s" % path) | |
13 | |
20 self.path = path | 14 self.path = path |
21 self.ui = ui | 15 self.ui = ui |
22 if not os.path.exists(path + "/objects"): | 16 self.encoding = 'utf-8' |
23 raise NoRepo("couldn't open GIT repo %s" % path) | |
24 | 17 |
25 def getheads(self): | 18 def getheads(self): |
26 fh = os.popen("GIT_DIR=%s git-rev-parse --verify HEAD" % self.path) | 19 fh = os.popen("GIT_DIR=%s git-rev-parse --verify HEAD" % self.path) |
27 return [fh.read()[:-1]] | 20 return [fh.read()[:-1]] |
28 | 21 |
56 | 49 |
57 def getcommit(self, version): | 50 def getcommit(self, version): |
58 c = self.catfile(version, "commit") # read the commit hash | 51 c = self.catfile(version, "commit") # read the commit hash |
59 end = c.find("\n\n") | 52 end = c.find("\n\n") |
60 message = c[end+2:] | 53 message = c[end+2:] |
61 message = recode(message) | 54 message = self.recode(message) |
62 l = c[:end].splitlines() | 55 l = c[:end].splitlines() |
63 manifest = l[0].split()[1] | 56 manifest = l[0].split()[1] |
64 parents = [] | 57 parents = [] |
65 for e in l[1:]: | 58 for e in l[1:]: |
66 n, v = e.split(" ", 1) | 59 n, v = e.split(" ", 1) |
67 if n == "author": | 60 if n == "author": |
68 p = v.split() | 61 p = v.split() |
69 tm, tz = p[-2:] | 62 tm, tz = p[-2:] |
70 author = " ".join(p[:-2]) | 63 author = " ".join(p[:-2]) |
71 if author[0] == "<": author = author[1:-1] | 64 if author[0] == "<": author = author[1:-1] |
72 author = recode(author) | 65 author = self.recode(author) |
73 if n == "committer": | 66 if n == "committer": |
74 p = v.split() | 67 p = v.split() |
75 tm, tz = p[-2:] | 68 tm, tz = p[-2:] |
76 committer = " ".join(p[:-2]) | 69 committer = " ".join(p[:-2]) |
77 if committer[0] == "<": committer = committer[1:-1] | 70 if committer[0] == "<": committer = committer[1:-1] |
78 committer = recode(committer) | 71 committer = self.recode(committer) |
79 message += "\ncommitter: %s\n" % committer | 72 message += "\ncommitter: %s\n" % committer |
80 if n == "parent": parents.append(v) | 73 if n == "parent": parents.append(v) |
81 | 74 |
82 tzs, tzh, tzm = tz[-5:-4] + "1", tz[-4:-2], tz[-2:] | 75 tzs, tzh, tzm = tz[-5:-4] + "1", tz[-4:-2], tz[-2:] |
83 tz = -int(tzs) * (int(tzh) * 3600 + int(tzm)) | 76 tz = -int(tzs) * (int(tzh) * 3600 + int(tzm)) |