Mercurial > hg
comparison hgext/convert/git.py @ 5481:003d1f174fe1
Fix Windows os.popen bug with interleaved stdout/stderr output
See python bug 1366 "popen spawned process may not write to stdout under windows" for more details.
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Thu, 01 Nov 2007 12:05:14 +0100 |
parents | 67d3daa8ac42 |
children | 4d38e6970b8c 03496d4fa509 |
comparison
equal
deleted
inserted
replaced
5480:81bef3c355c5 | 5481:003d1f174fe1 |
---|---|
12 if hasattr(os, 'unsetenv'): | 12 if hasattr(os, 'unsetenv'): |
13 def gitcmd(self, s): | 13 def gitcmd(self, s): |
14 prevgitdir = os.environ.get('GIT_DIR') | 14 prevgitdir = os.environ.get('GIT_DIR') |
15 os.environ['GIT_DIR'] = self.path | 15 os.environ['GIT_DIR'] = self.path |
16 try: | 16 try: |
17 return os.popen(s) | 17 return util.popen(s) |
18 finally: | 18 finally: |
19 if prevgitdir is None: | 19 if prevgitdir is None: |
20 del os.environ['GIT_DIR'] | 20 del os.environ['GIT_DIR'] |
21 else: | 21 else: |
22 os.environ['GIT_DIR'] = prevgitdir | 22 os.environ['GIT_DIR'] = prevgitdir |
23 else: | 23 else: |
24 def gitcmd(self, s): | 24 def gitcmd(self, s): |
25 return os.popen('GIT_DIR=%s %s' % (self.path, s)) | 25 return util.popen('GIT_DIR=%s %s' % (self.path, s)) |
26 | 26 |
27 def __init__(self, ui, path, rev=None): | 27 def __init__(self, ui, path, rev=None): |
28 super(convert_git, self).__init__(ui, path, rev=rev) | 28 super(convert_git, self).__init__(ui, path, rev=rev) |
29 | 29 |
30 if os.path.isdir(path + "/.git"): | 30 if os.path.isdir(path + "/.git"): |
40 fh = self.gitcmd("git-rev-parse --verify %s" % self.rev) | 40 fh = self.gitcmd("git-rev-parse --verify %s" % self.rev) |
41 return [fh.read()[:-1]] | 41 return [fh.read()[:-1]] |
42 | 42 |
43 def catfile(self, rev, type): | 43 def catfile(self, rev, type): |
44 if rev == "0" * 40: raise IOError() | 44 if rev == "0" * 40: raise IOError() |
45 fh = self.gitcmd("git-cat-file %s %s 2>%s" % (type, rev, | 45 fh = self.gitcmd("git-cat-file %s %s" % (type, rev)) |
46 util.nulldev)) | |
47 return fh.read() | 46 return fh.read() |
48 | 47 |
49 def getfile(self, name, rev): | 48 def getfile(self, name, rev): |
50 return self.catfile(rev, "blob") | 49 return self.catfile(rev, "blob") |
51 | 50 |
106 rev=version) | 105 rev=version) |
107 return c | 106 return c |
108 | 107 |
109 def gettags(self): | 108 def gettags(self): |
110 tags = {} | 109 tags = {} |
111 fh = self.gitcmd('git-ls-remote --tags "%s" 2>%s' % (self.path, | 110 fh = self.gitcmd('git-ls-remote --tags "%s"' % self.path) |
112 util.nulldev)) | |
113 prefix = 'refs/tags/' | 111 prefix = 'refs/tags/' |
114 for line in fh: | 112 for line in fh: |
115 line = line.strip() | 113 line = line.strip() |
116 if not line.endswith("^{}"): | 114 if not line.endswith("^{}"): |
117 continue | 115 continue |