From 77b5cdce5b50b9edcde3a1aed4d7117e6e47bc24 Mon Sep 17 00:00:00 2001 From: Nico von Geyso Date: Mon, 20 May 2013 14:58:54 +0200 Subject: [PATCH] Refactored: get rid of type check for treeish_to_tree in Diff --- pygit2/repository.py | 5 +++-- pygit2/utils.py | 10 ---------- test/test_diff.py | 8 ++++++-- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/pygit2/repository.py b/pygit2/repository.py index d62d08a..6a5ec38 100644 --- a/pygit2/repository.py +++ b/pygit2/repository.py @@ -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 diff --git a/pygit2/utils.py b/pygit2/utils.py index 2f6645a..79e6040 100644 --- a/pygit2/utils.py +++ b/pygit2/utils.py @@ -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 diff --git a/test/test_diff.py b/test/test_diff.py index d690265..7ff9946 100644 --- a/test/test_diff.py +++ b/test/test_diff.py @@ -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))