Mercurial > hg > mercurial-crew-with-dirclash
comparison hgext/convert/git.py @ 4760:2d0a823cbba5
convert: gitcmd wrapper for os.popen
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Sun, 01 Jul 2007 21:09:08 -0700 |
parents | 07efcce17d28 |
children | f52bfe566583 |
comparison
equal
deleted
inserted
replaced
4759:95cbb6b74790 | 4760:2d0a823cbba5 |
---|---|
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) |
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 = os.popen("GIT_DIR=%s git-rev-parse --verify %s" % (self.path, rev)) | 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 = os.popen("GIT_DIR=%s git-cat-file %s %s 2>/dev/null" | 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 = os.popen("GIT_DIR=%s git-diff-tree --root -m -r %s" | 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() |
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 = os.popen('git-ls-remote --tags "%s" 2>/dev/null' % self.path) | 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 |