Repository: make use of peel for diff()
Instead of trying to reimplement parts of it, make use of Object.peel() and Reference.peel() to get to a Blob or Tree.
This commit is contained in:
@@ -385,26 +385,24 @@ class Repository(_Repository):
|
|||||||
if obj is None:
|
if obj is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Would be better to test by the type of obj, but it is boring to
|
# If it's a string, then it has to be valid revspec
|
||||||
# deal with Python 2 & 3 differences
|
if is_string(obj):
|
||||||
try:
|
|
||||||
obj = self.revparse_single(obj)
|
obj = self.revparse_single(obj)
|
||||||
except TypeError:
|
|
||||||
|
# First we try to get to a blob
|
||||||
|
try:
|
||||||
|
obj = obj.peel(Blob)
|
||||||
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# If reference, resolve
|
# And if that failed, try to get a tree, raising a type
|
||||||
if isinstance(obj, Reference):
|
# error if that still doesn't work
|
||||||
oid = obj.resolve().target
|
try:
|
||||||
obj = self[oid]
|
obj = obj.peel(Tree)
|
||||||
|
except Exception:
|
||||||
if isinstance(obj, Commit):
|
raise TypeError('unexpected "%s"' % type(obj))
|
||||||
return obj.tree
|
|
||||||
|
|
||||||
if isinstance(obj, (Blob, Tree)):
|
|
||||||
return obj
|
|
||||||
|
|
||||||
raise TypeError('unexpected "%s"' % type(obj))
|
|
||||||
|
|
||||||
|
return obj
|
||||||
|
|
||||||
a = whatever_to_tree_or_blob(a)
|
a = whatever_to_tree_or_blob(a)
|
||||||
b = whatever_to_tree_or_blob(b)
|
b = whatever_to_tree_or_blob(b)
|
||||||
|
Reference in New Issue
Block a user