diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2012-06-19 09:09:11 +0300 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2012-07-27 13:46:59 +0200 |
commit | 6e4138faae673bd3398b1c85829a41e348e40caf (patch) | |
tree | ab6909ef577c69fbccefceff8e536c6da9c4688d | |
parent | 32f725f9e27165c25ef11d61952f22eb29a1f12d (diff) |
GitRepository/get_commit_info: add file status
Add file status and name to the info returned by the get_commit_info()
method.
Signed-off-by: Zhang Qiang <qiang.z.zhang@intel.com>
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
-rw-r--r-- | gbp/git/repository.py | 15 | ||||
-rw-r--r-- | tests/test_GitRepository.py | 2 |
2 files changed, 15 insertions, 2 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py index 9f70dd1..c9f3610 100644 --- a/gbp/git/repository.py +++ b/gbp/git/repository.py @@ -19,6 +19,7 @@ import re import subprocess import os.path +from collections import defaultdict import gbp.log as log from gbp.command_wrappers import (GitCommand, CommandExecFailed) @@ -1210,7 +1211,7 @@ class GitRepository(object): @rtype: dict """ args = GitArgs('--pretty=format:%an%x00%ae%x00%ad%x00%cn%x00%ce%x00%cd%x00%s%x00%b%x00', - '-z', '--quiet', '--date=raw', commit) + '-z', '--date=raw', '--name-status', commit) out, err, ret = self._git_inout('show', args.args) if ret: raise GitRepositoryError("Unable to retrieve commit info for %s" @@ -1225,11 +1226,21 @@ class GitRepository(object): fields[4].strip(), fields[5].strip()) + files = defaultdict(list) + file_fields = fields[8:] + # For some reason git returns one extra empty field for merge commits + if file_fields[0] == '': file_fields.pop(0) + while len(file_fields) and file_fields[0] != '': + status = file_fields.pop(0).strip() + path = file_fields.pop(0) + files[status].append(path) + return {'id' : commit, 'author' : author, 'committer' : committer, 'subject' : fields[6], - 'body' : fields[7]} + 'body' : fields[7], + 'files' : files} #{ Patches def format_patches(self, start, end, output_dir, signature=True, thread=None): diff --git a/tests/test_GitRepository.py b/tests/test_GitRepository.py index 5a590ff..10b448b 100644 --- a/tests/test_GitRepository.py +++ b/tests/test_GitRepository.py @@ -369,6 +369,8 @@ def test_get_commit_info(): True >>> (now - datetime.fromtimestamp(int(info['committer'].date.split()[0]))).seconds < 10 True + >>> info['files'] + defaultdict(<type 'list'>, {'M': ['testfile']}) """ def test_mirror_clone(): |