Show More
@@ -1,99 +1,100 b'' | |||||
1 | # git support for the convert extension |
|
1 | # git support for the convert extension | |
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 | class convert_git(converter_source): |
|
7 | class convert_git(converter_source): | |
|
8 | def gitcmd(self, s): | |||
|
9 | return os.popen('GIT_DIR=%s %s' % (self.path, s)) | |||
|
10 | ||||
8 | def __init__(self, ui, path, rev=None): |
|
11 | def __init__(self, ui, path, rev=None): | |
9 | if os.path.isdir(path + "/.git"): |
|
12 | if os.path.isdir(path + "/.git"): | |
10 | path += "/.git" |
|
13 | path += "/.git" | |
11 | if not os.path.exists(path + "/objects"): |
|
14 | if not os.path.exists(path + "/objects"): | |
12 | raise NoRepo("couldn't open GIT repo %s" % path) |
|
15 | raise NoRepo("couldn't open GIT repo %s" % path) | |
13 |
|
16 | |||
14 | self.path = path |
|
17 | self.path = path | |
15 | self.ui = ui |
|
18 | self.ui = ui | |
16 | self.rev = rev |
|
19 | self.rev = rev | |
17 | self.encoding = 'utf-8' |
|
20 | self.encoding = 'utf-8' | |
18 |
|
21 | |||
19 | def getheads(self): |
|
22 | def getheads(self): | |
20 | rev = self.rev or 'HEAD' |
|
23 | rev = self.rev or 'HEAD' | |
21 |
fh = |
|
24 | fh = self.gitcmd("git-rev-parse --verify %s" % rev) | |
22 | return [fh.read()[:-1]] |
|
25 | return [fh.read()[:-1]] | |
23 |
|
26 | |||
24 | def catfile(self, rev, type): |
|
27 | def catfile(self, rev, type): | |
25 | if rev == "0" * 40: raise IOError() |
|
28 | if rev == "0" * 40: raise IOError() | |
26 |
fh = |
|
29 | fh = self.gitcmd("git-cat-file %s %s 2>/dev/null" % (type, rev)) | |
27 | % (self.path, type, rev)) |
|
|||
28 | return fh.read() |
|
30 | return fh.read() | |
29 |
|
31 | |||
30 | def getfile(self, name, rev): |
|
32 | def getfile(self, name, rev): | |
31 | return self.catfile(rev, "blob") |
|
33 | return self.catfile(rev, "blob") | |
32 |
|
34 | |||
33 | def getmode(self, name, rev): |
|
35 | def getmode(self, name, rev): | |
34 | return self.modecache[(name, rev)] |
|
36 | return self.modecache[(name, rev)] | |
35 |
|
37 | |||
36 | def getchanges(self, version): |
|
38 | def getchanges(self, version): | |
37 | self.modecache = {} |
|
39 | self.modecache = {} | |
38 |
fh = |
|
40 | fh = self.gitcmd("git-diff-tree --root -m -r %s" % version) | |
39 | % (self.path, version)) |
|
|||
40 | changes = [] |
|
41 | changes = [] | |
41 | for l in fh: |
|
42 | for l in fh: | |
42 | if "\t" not in l: continue |
|
43 | if "\t" not in l: continue | |
43 | m, f = l[:-1].split("\t") |
|
44 | m, f = l[:-1].split("\t") | |
44 | m = m.split() |
|
45 | m = m.split() | |
45 | h = m[3] |
|
46 | h = m[3] | |
46 | p = (m[1] == "100755") |
|
47 | p = (m[1] == "100755") | |
47 | s = (m[1] == "120000") |
|
48 | s = (m[1] == "120000") | |
48 | self.modecache[(f, h)] = (p and "x") or (s and "l") or "" |
|
49 | self.modecache[(f, h)] = (p and "x") or (s and "l") or "" | |
49 | changes.append((f, h)) |
|
50 | changes.append((f, h)) | |
50 | return changes |
|
51 | return changes | |
51 |
|
52 | |||
52 | def getcommit(self, version): |
|
53 | def getcommit(self, version): | |
53 | c = self.catfile(version, "commit") # read the commit hash |
|
54 | c = self.catfile(version, "commit") # read the commit hash | |
54 | end = c.find("\n\n") |
|
55 | end = c.find("\n\n") | |
55 | message = c[end+2:] |
|
56 | message = c[end+2:] | |
56 | message = self.recode(message) |
|
57 | message = self.recode(message) | |
57 | l = c[:end].splitlines() |
|
58 | l = c[:end].splitlines() | |
58 | manifest = l[0].split()[1] |
|
59 | manifest = l[0].split()[1] | |
59 | parents = [] |
|
60 | parents = [] | |
60 | for e in l[1:]: |
|
61 | for e in l[1:]: | |
61 | n, v = e.split(" ", 1) |
|
62 | n, v = e.split(" ", 1) | |
62 | if n == "author": |
|
63 | if n == "author": | |
63 | p = v.split() |
|
64 | p = v.split() | |
64 | tm, tz = p[-2:] |
|
65 | tm, tz = p[-2:] | |
65 | author = " ".join(p[:-2]) |
|
66 | author = " ".join(p[:-2]) | |
66 | if author[0] == "<": author = author[1:-1] |
|
67 | if author[0] == "<": author = author[1:-1] | |
67 | author = self.recode(author) |
|
68 | author = self.recode(author) | |
68 | if n == "committer": |
|
69 | if n == "committer": | |
69 | p = v.split() |
|
70 | p = v.split() | |
70 | tm, tz = p[-2:] |
|
71 | tm, tz = p[-2:] | |
71 | committer = " ".join(p[:-2]) |
|
72 | committer = " ".join(p[:-2]) | |
72 | if committer[0] == "<": committer = committer[1:-1] |
|
73 | if committer[0] == "<": committer = committer[1:-1] | |
73 | committer = self.recode(committer) |
|
74 | committer = self.recode(committer) | |
74 | message += "\ncommitter: %s\n" % committer |
|
75 | message += "\ncommitter: %s\n" % committer | |
75 | if n == "parent": parents.append(v) |
|
76 | if n == "parent": parents.append(v) | |
76 |
|
77 | |||
77 | tzs, tzh, tzm = tz[-5:-4] + "1", tz[-4:-2], tz[-2:] |
|
78 | tzs, tzh, tzm = tz[-5:-4] + "1", tz[-4:-2], tz[-2:] | |
78 | tz = -int(tzs) * (int(tzh) * 3600 + int(tzm)) |
|
79 | tz = -int(tzs) * (int(tzh) * 3600 + int(tzm)) | |
79 | date = tm + " " + str(tz) |
|
80 | date = tm + " " + str(tz) | |
80 | author = author or "unknown" |
|
81 | author = author or "unknown" | |
81 |
|
82 | |||
82 | c = commit(parents=parents, date=date, author=author, desc=message) |
|
83 | c = commit(parents=parents, date=date, author=author, desc=message) | |
83 | return c |
|
84 | return c | |
84 |
|
85 | |||
85 | def gettags(self): |
|
86 | def gettags(self): | |
86 | tags = {} |
|
87 | tags = {} | |
87 |
fh = |
|
88 | fh = self.gitcmd('git-ls-remote --tags "%s" 2>/dev/null' % self.path) | |
88 | prefix = 'refs/tags/' |
|
89 | prefix = 'refs/tags/' | |
89 | for line in fh: |
|
90 | for line in fh: | |
90 | line = line.strip() |
|
91 | line = line.strip() | |
91 | if not line.endswith("^{}"): |
|
92 | if not line.endswith("^{}"): | |
92 | continue |
|
93 | continue | |
93 | node, tag = line.split(None, 1) |
|
94 | node, tag = line.split(None, 1) | |
94 | if not tag.startswith(prefix): |
|
95 | if not tag.startswith(prefix): | |
95 | continue |
|
96 | continue | |
96 | tag = tag[len(prefix):-3] |
|
97 | tag = tag[len(prefix):-3] | |
97 | tags[tag] = node |
|
98 | tags[tag] = node | |
98 |
|
99 | |||
99 | return tags |
|
100 | return tags |
General Comments 0
You need to be logged in to leave comments.
Login now