GitRepository: make get_commit_info() more robust 2.0alpha 2.0_alpha
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Mon, 18 Jun 2012 13:20:39 +0000 (16:20 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Tue, 19 Jun 2012 05:03:29 +0000 (08:03 +0300)
Now uses git-show instead of git-log. This way we get the file status
for merge commits, too. Also, use null-character as the field separator
which makes parsing more reliable. For example, should handle exotic
filenames/paths reliably, now.

Also, get_commit_info() now uses GitArgs and _git_inout() instead of the
deprecated _git_getoutput().

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gbp/git/repository.py

index 9dcaac93e67ea929ae3c5cc40f2c43217a36fb36..9387fbe14a51ee8100d0a47fad10626aa7e2d6b4 100644 (file)
@@ -1159,27 +1159,25 @@ class GitRepository(object):
         @return: the commit's including id, author, email, subject and body
         @rtype: dict
         """
-        out, ret =  self._git_getoutput('log',
-                                         ['--pretty=format:%an%n%ae%n%at%n%s%n%b%n',
-                                          '-n1', '--name-status', commit])
+        args = GitArgs('--pretty=format:%an%x00%ae%x00%at%x00%s%x00%b%x00',
+                       '-z', '--name-status', commit)
+        out, err, ret =  self._git_inout('show', args.args)
         if ret:
             raise GitRepositoryError("Unable to retrieve log entry for %s"
                                      % commit)
 
+        fields = out.split('\x00')
         files = defaultdict(list)
-        for line in reversed(out):
-            if not line.strip():
-                break
-            key, val = line.strip().split(None, 1)
-            files[key].append(val)
-            out.remove(line)
+        starti = 5 if fields[5] != '' else 6
+        for i in range(starti, len(fields)-1, 2):
+            files[fields[i].strip()].append(fields[i+1])
 
         return {'id' : commit,
-                'author' : out[0].strip(),
-                'email' : out[1].strip(),
-                'timestamp': out[2].strip(),
-                'subject' : out[3].rstrip(),
-                'body' : [line.rstrip() for line in  out[4:]],
+                'author' : fields[0].strip(),
+                'email' : fields[1].strip(),
+                'timestamp': fields[2].strip(),
+                'subject' : fields[3].rstrip(),
+                'body' : fields[4],
                 'files' : files}