Refactored: get rid of type check for treeish_to_tree in Diff
This commit is contained in:
@@ -30,7 +30,6 @@ from string import hexdigits
|
||||
from collections import OrderedDict
|
||||
|
||||
# Import from pygit2
|
||||
from utils import text_type
|
||||
from _pygit2 import Repository as _Repository
|
||||
from _pygit2 import Oid, GIT_OID_HEXSZ, GIT_OID_MINPREFIXLEN
|
||||
from _pygit2 import GIT_CHECKOUT_SAFE_CREATE
|
||||
@@ -180,8 +179,10 @@ class Repository(_Repository):
|
||||
"""
|
||||
|
||||
def treeish_to_tree(obj):
|
||||
if isinstance(obj, text_type):
|
||||
try:
|
||||
obj = self.revparse_single(obj)
|
||||
except:
|
||||
pass
|
||||
|
||||
if isinstance(obj, Commit):
|
||||
return obj.tree
|
||||
|
@@ -27,13 +27,3 @@
|
||||
|
||||
|
||||
# feel free to add utils functions here
|
||||
|
||||
import sys
|
||||
|
||||
# python2/3 compability types for isinstance()
|
||||
if sys.version < '3':
|
||||
text_type = unicode
|
||||
binary_type = str
|
||||
else:
|
||||
text_type = str
|
||||
binary_type = bytes
|
||||
|
@@ -196,13 +196,17 @@ class DiffTest(utils.BareRepoTestCase):
|
||||
self.assertAll(lambda x: commit_a.tree[x], entries)
|
||||
self.assertAll(lambda x: '+' == x, get_context_for_lines(diff_swaped))
|
||||
|
||||
def test_diff_revparse(self):
|
||||
diff = self.repo.diff('HEAD','HEAD~6')
|
||||
self.assertEqual(type(diff), pygit2.Diff)
|
||||
|
||||
def test_diff_tree_opts(self):
|
||||
commit_c = self.repo[COMMIT_SHA1_3]
|
||||
commit_d = self.repo[COMMIT_SHA1_4]
|
||||
|
||||
for opt in [pygit2.GIT_DIFF_IGNORE_WHITESPACE,
|
||||
for flag in [pygit2.GIT_DIFF_IGNORE_WHITESPACE,
|
||||
pygit2.GIT_DIFF_IGNORE_WHITESPACE_EOL]:
|
||||
diff = commit_c.tree.diff_to_tree(commit_d.tree, opt)
|
||||
diff = commit_c.tree.diff_to_tree(commit_d.tree, flag)
|
||||
self.assertTrue(diff is not None)
|
||||
self.assertEqual(0, len(diff[0].hunks))
|
||||
|
||||
|
Reference in New Issue
Block a user