# HG changeset patch # User Patrick Mezard # Date 1272229190 -7200 # Node ID 610f047326b9ad2a05fdec5d108a84104917b360 # Parent 7fab6ae3f6883b95b4d533f1da1b64942b6a0a2e convert/git: check status when reading the whole output diff -r 7fab6ae3f688 -r 610f047326b9 hgext/convert/git.py --- a/hgext/convert/git.py Sun Apr 25 22:32:27 2010 +0200 +++ b/hgext/convert/git.py Sun Apr 25 22:59:50 2010 +0200 @@ -30,6 +30,11 @@ def gitopen(self, s): return util.popen('GIT_DIR=%s %s' % (self.path, s), 'rb') + def gitread(self, s): + fh = self.gitopen(s) + data = fh.read() + return data, fh.close() + def __init__(self, ui, path, rev=None): super(convert_git, self).__init__(ui, path, rev=rev) @@ -44,17 +49,22 @@ def getheads(self): if not self.rev: - fh = self.gitopen('git rev-parse --branches --remotes') - return fh.read().splitlines() + heads, ret = self.gitread('git rev-parse --branches --remotes') + heads = heads.splitlines() else: - fh = self.gitopen("git rev-parse --verify %s" % self.rev) - return [fh.read()[:-1]] + heads, ret = self.gitread("git rev-parse --verify %s" % self.rev) + heads = [heads[:-1]] + if ret: + raise util.Abort(_('cannot retrieve git heads')) + return heads def catfile(self, rev, type): if rev == "0" * 40: raise IOError() - fh = self.gitopen("git cat-file %s %s" % (type, rev)) - return fh.read() + data, ret = self.gitread("git cat-file %s %s" % (type, rev)) + if ret: + raise util.Abort(_('cannot read %r object at %s') % (type, rev)) + return data def getfile(self, name, rev): return self.catfile(rev, "blob")