Skip to content

Commit

Permalink
Repository: make use of peel for diff()
Browse files Browse the repository at this point in the history
Instead of trying to reimplement parts of it, make use of Object.peel()
to get to a Tree, with short-circuit returns for None and Blob which can
be handled differently.
  • Loading branch information
carlosmn committed Oct 6, 2014
1 parent 6831983 commit 747a154
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions pygit2/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,20 +375,20 @@ def diff(self, a=None, b=None, cached=False, flags=GIT_DIFF_NORMAL,
API (Tree.diff_to_tree()) directly.
"""

def treeish_to_tree(obj):
try:
def tree_or_blob(obj):
if obj is None:
return obj

if is_string(obj):
obj = self.revparse_single(obj)
except:
pass

if isinstance(obj, Commit):
return obj.tree
elif isinstance(obj, Reference):
oid = obj.resolve().target
return self[oid]
if isinstance(obj, Blob):
return obj

return obj.peel(Tree)

a = treeish_to_tree(a) or a
b = treeish_to_tree(b) or b
a = tree_or_blob(a)
b = tree_or_blob(b)

opt_keys = ['flags', 'context_lines', 'interhunk_lines']
opt_values = [flags, context_lines, interhunk_lines]
Expand Down

0 comments on commit 747a154

Please sign in to comment.