12 return s.decode("latin-1").encode("utf-8") |
12 return s.decode("latin-1").encode("utf-8") |
13 except: |
13 except: |
14 return s.decode("utf-8", "replace").encode("utf-8") |
14 return s.decode("utf-8", "replace").encode("utf-8") |
15 |
15 |
16 class convert_git(converter_source): |
16 class convert_git(converter_source): |
|
17 def gitcmd(self, s): |
|
18 return os.popen('GIT_DIR=%s %s' % (self.path, s)) |
|
19 |
17 def __init__(self, ui, path): |
20 def __init__(self, ui, path): |
18 if os.path.isdir(path + "/.git"): |
21 if os.path.isdir(path + "/.git"): |
19 path += "/.git" |
22 path += "/.git" |
20 self.path = path |
23 self.path = path |
21 self.ui = ui |
24 self.ui = ui |
22 if not os.path.exists(path + "/objects"): |
25 if not os.path.exists(path + "/objects"): |
23 raise NoRepo("couldn't open GIT repo %s" % path) |
26 raise NoRepo("couldn't open GIT repo %s" % path) |
24 |
27 |
25 def getheads(self): |
28 def getheads(self): |
26 fh = os.popen("GIT_DIR=%s git-rev-parse --verify HEAD" % self.path) |
29 fh = self.gitcmd("git-rev-parse --verify HEAD") |
27 return [fh.read()[:-1]] |
30 return [fh.read()[:-1]] |
28 |
31 |
29 def catfile(self, rev, type): |
32 def catfile(self, rev, type): |
30 if rev == "0" * 40: raise IOError() |
33 if rev == "0" * 40: raise IOError() |
31 fh = os.popen("GIT_DIR=%s git-cat-file %s %s 2>/dev/null" |
34 fh = self.gitcmd("git-cat-file %s %s 2>/dev/null" % (type, rev)) |
32 % (self.path, type, rev)) |
|
33 return fh.read() |
35 return fh.read() |
34 |
36 |
35 def getfile(self, name, rev): |
37 def getfile(self, name, rev): |
36 return self.catfile(rev, "blob") |
38 return self.catfile(rev, "blob") |
37 |
39 |
38 def getmode(self, name, rev): |
40 def getmode(self, name, rev): |
39 return self.modecache[(name, rev)] |
41 return self.modecache[(name, rev)] |
40 |
42 |
41 def getchanges(self, version): |
43 def getchanges(self, version): |
42 self.modecache = {} |
44 self.modecache = {} |
43 fh = os.popen("GIT_DIR=%s git-diff-tree --root -m -r %s" |
45 fh = self.gitcmd("git-diff-tree --root -m -r %s" % version) |
44 % (self.path, version)) |
|
45 changes = [] |
46 changes = [] |
46 for l in fh: |
47 for l in fh: |
47 if "\t" not in l: continue |
48 if "\t" not in l: continue |
48 m, f = l[:-1].split("\t") |
49 m, f = l[:-1].split("\t") |
49 m = m.split() |
50 m = m.split() |