diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2012-09-14 13:40:14 +0300 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2014-12-05 15:35:14 +0100 |
commit | cb9271fe113bae56088c9c1d07870c408a518a52 (patch) | |
tree | c8b53e9859e7ea9cc412b171a4f1d04b01b2e812 /gbp/git | |
parent | 7a503e926669041847f568d1ee26ff948e261ffd (diff) |
GitRepository: add diff_status method
This is a method of getting the filename and status information of a
diff. That is, a list of files that changed and their status, "added",
"modified" etc.
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Diffstat (limited to 'gbp/git')
-rw-r--r-- | gbp/git/repository.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py index 23f9482..edb8e21 100644 --- a/gbp/git/repository.py +++ b/gbp/git/repository.py @@ -1639,6 +1639,33 @@ class GitRepository(object): if ret: raise GitRepositoryError("Git diff failed") return output + + def diff_status(self, obj1, obj2): + """ + Get file-status of two git repository objects + + @param obj1: first object + @type obj1: C{str} + @param obj2: second object + @type obj2: C{str} + @return: name-status + @rtype: C{defaultdict} of C{str} + """ + options = GitArgs('--name-status', '-z', obj1, obj2) + output, stderr, ret = self._git_inout('diff', options.args) + + elements = output.split('\x00') + result = defaultdict(list) + + while elements[0] != '': + status = elements.pop(0)[0] + filepath = elements.pop(0) + # Expect to have two filenames for renames and copies + if status in ['R', 'C']: + filepath = elements.pop(0) + '\x00' + filepath + result[status].append(filepath) + + return result #} def archive(self, format, prefix, output, treeish, **kwargs): |