Mercurial > hg > mercurial-crew-with-dirclash
comparison hgext/convert/git.py @ 5228:39e6deaa8b81
convert: gitcmd wrapper for os.popen
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Sun, 01 Jul 2007 21:09:08 -0700 |
parents | 96614af3c679 |
children | 149742a628fd |
comparison
equal
deleted
inserted
replaced
5219:74723744d8e0 | 5228:39e6deaa8b81 |
---|---|
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() |
87 c = commit(parents=parents, date=date, author=author, desc=message) | 88 c = commit(parents=parents, date=date, author=author, desc=message) |
88 return c | 89 return c |
89 | 90 |
90 def gettags(self): | 91 def gettags(self): |
91 tags = {} | 92 tags = {} |
92 fh = os.popen('git-ls-remote --tags "%s" 2>/dev/null' % self.path) | 93 fh = self.gitcmd('git-ls-remote --tags "%s" 2>/dev/null' % self.path) |
93 prefix = 'refs/tags/' | 94 prefix = 'refs/tags/' |
94 for line in fh: | 95 for line in fh: |
95 line = line.strip() | 96 line = line.strip() |
96 if not line.endswith("^{}"): | 97 if not line.endswith("^{}"): |
97 continue | 98 continue |