GitRepository: make get_commit_info() more robust
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Mon, 18 Jun 2012 13:20:39 +0000 (16:20 +0300)
committerGuido Günther <agx@sigxcpu.org>
Sat, 30 Jun 2012 07:35:03 +0000 (09:35 +0200)
Now uses git-show instead of git-log. This is needed for further
enhancements (namely to get name-status for merge commits). Also, use
null-character as the field separator which makes parsing more reliable.

The method now returns 'body' of the commit message as is, without
stripping or splitting to lines.

In addition, 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/dch.py
gbp/git/repository.py
tests/test_GitRepository.py

index ddd5e8e..dc0149c 100644 (file)
@@ -106,7 +106,7 @@ def format_changelog_entry(commit_info, options, last_commit=False):
     GitRepository.get_commit_info()).  If last_commit is not False,
     then this entry is the last one in the series."""
     entry = [commit_info['subject']]
-    body = commit_info['body']
+    body = commit_info['body'].splitlines()
     commitid = commit_info['id']
     (git_dch_cmds, body) = extract_git_dch_cmds(body, options)
 
index c4ac66c..2a8cdd8 100644 (file)
@@ -1192,17 +1192,19 @@ 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%s%n%b%n',
-                                          '-n1', commit])
-        if ret:
-            raise GitRepositoryError("Unable to retrieve log entry for %s"
+        args = GitArgs('--pretty=format:%an%x00%ae%x00%s%x00%b%x00',
+                       '-z', '--quiet', commit)
+        out, err, ret =  self._git_inout('show', args.args)
+        if ret > 1:
+            raise GitRepositoryError("Unable to retrieve commit info for %s"
                                      % commit)
+
+        fields = out.split('\x00')
         return {'id' : commit,
-                'author' : out[0].strip(),
-                'email' : out[1].strip(),
-                'subject' : out[2].rstrip(),
-                'body' : [line.rstrip() for line in  out[3:]]}
+                'author' : fields[0].strip(),
+                'email' : fields[1].strip(),
+                'subject' : fields[2],
+                'body' : fields[3]}
 
 
 #{ Patches
index 8461904..78c38b4 100644 (file)
@@ -354,7 +354,7 @@ def test_get_commit_info():
     >>> info['id']
     'HEAD'
     >>> info['body']
-    ['']
+    ''
     >>> info['subject']
     'foo'
     >>> '@' in info['email']