Thanks to Yann Dirson for submitting the initial patch. The patch was
modified to only call git-rev-list when the commit parents are
required, otherwise operations like 'push' would be slowed down.
Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
self.__id_hash = id_hash
lines = _output_lines('git-cat-file commit %s' % id_hash)
- self.__parents = []
for i in range(len(lines)):
line = lines[i]
if line == '\n':
field = line.strip().split(' ', 1)
if field[0] == 'tree':
self.__tree = field[1]
- elif field[0] == 'parent':
- self.__parents.append(field[1])
if field[0] == 'author':
self.__author = field[1]
if field[0] == 'committer':
return self.__tree
def get_parent(self):
- return self.__parents[0]
+ return self.get_parents()[0]
def get_parents(self):
- return self.__parents
+ return _output_lines('git-rev-list --parents --max-count=1 %s'
+ % self.__id_hash)[0].split()[1:]
def get_author(self):
return self.__author