GitRepository/get_commit_info: add file status
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Tue, 19 Jun 2012 06:09:11 +0000 (09:09 +0300)
committerGuido Günther <agx@sigxcpu.org>
Fri, 27 Jul 2012 11:46:59 +0000 (13:46 +0200)
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>
gbp/git/repository.py
tests/test_GitRepository.py

index 9f70dd1..c9f3610 100644 (file)
@@ -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):
index 5a590ff..10b448b 100644 (file)
@@ -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():