diff options
-rw-r--r-- | lib/git/diff.py | 6 | ||||
-rw-r--r-- | lib/git/objects/blob.py | 24 | ||||
-rw-r--r-- | lib/git/objects/commit.py | 19 | ||||
-rw-r--r-- | lib/git/objects/tag.py | 2 | ||||
-rw-r--r-- | lib/git/objects/tree.py | 9 | ||||
-rw-r--r-- | lib/git/refs.py | 15 | ||||
-rw-r--r-- | lib/git/remote.py | 7 | ||||
-rw-r--r-- | lib/git/repo.py | 5 | ||||
-rw-r--r-- | lib/git/utils.py | 6 | ||||
-rw-r--r-- | test/fixtures/diff_new_mode | 2 | ||||
-rw-r--r-- | test/git/test_base.py | 164 | ||||
-rw-r--r-- | test/git/test_blob.py | 10 | ||||
-rw-r--r-- | test/git/test_commit.py | 35 | ||||
-rw-r--r-- | test/git/test_fun.py | 25 | ||||
-rw-r--r-- | test/git/test_index.py | 6 | ||||
-rw-r--r-- | test/git/test_remote.py | 1 | ||||
-rw-r--r-- | test/git/test_repo.py | 10 | ||||
-rw-r--r-- | test/git/test_tree.py | 10 | ||||
-rw-r--r-- | test/testlib/helper.py | 15 |
19 files changed, 198 insertions, 173 deletions
diff --git a/lib/git/diff.py b/lib/git/diff.py index 24cba3ed..b8585a4c 100644 --- a/lib/git/diff.py +++ b/lib/git/diff.py @@ -8,6 +8,8 @@ import re from objects.blob import Blob from objects.utils import mode_str_to_int from errors import GitCommandError + +from gitdb.util import hex_to_bin __all__ = ('Diffable', 'DiffIndex', 'Diff') @@ -197,11 +199,11 @@ class Diff(object): if a_blob_id is None: self.a_blob = None else: - self.a_blob = Blob(repo, a_blob_id, mode=a_mode, path=a_path) + self.a_blob = Blob(repo, hex_to_bin(a_blob_id), mode=a_mode, path=a_path) if b_blob_id is None: self.b_blob = None else: - self.b_blob = Blob(repo, b_blob_id, mode=b_mode, path=b_path) + self.b_blob = Blob(repo, hex_to_bin(b_blob_id), mode=b_mode, path=b_path) self.a_mode = a_mode self.b_mode = b_mode diff --git a/lib/git/objects/blob.py b/lib/git/objects/blob.py index ed7a8d04..8263e9a2 100644 --- a/lib/git/objects/blob.py +++ b/lib/git/objects/blob.py @@ -10,11 +10,11 @@ import base __all__ = ('Blob', ) class Blob(base.IndexObject): - """A Blob encapsulates a git blob object""" - DEFAULT_MIME_TYPE = "text/plain" - type = "blob" + """A Blob encapsulates a git blob object""" + DEFAULT_MIME_TYPE = "text/plain" + type = "blob" - __slots__ = "data" + __slots__ = "data" def _set_cache_(self, attr): if attr == "data": @@ -26,11 +26,11 @@ class Blob(base.IndexObject): super(Blob, self)._set_cache_(attr) # END handle data - @property - def mime_type(self): - """ :return:String describing the mime type of this file (based on the filename) - :note: Defaults to 'text/plain' in case the actual file type is unknown. """ - guesses = None - if self.path: - guesses = guess_type(self.path) - return guesses and guesses[0] or self.DEFAULT_MIME_TYPE + @property + def mime_type(self): + """ :return:String describing the mime type of this file (based on the filename) + :note: Defaults to 'text/plain' in case the actual file type is unknown. """ + guesses = None + if self.path: + guesses = guess_type(self.path) + return guesses and guesses[0] or self.DEFAULT_MIME_TYPE diff --git a/lib/git/objects/commit.py b/lib/git/objects/commit.py index 3bf1fbc4..f365c994 100644 --- a/lib/git/objects/commit.py +++ b/lib/git/objects/commit.py @@ -23,13 +23,14 @@ from utils import ( get_user_id, parse_date, Actor, - altz_to_utctz_str + altz_to_utctz_str, parse_actor_and_date ) from time import ( time, altzone ) +import os __all__ = ('Commit', ) @@ -76,7 +77,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): :param parents: tuple( Commit, ... ) is a tuple of commit ids or actual Commits :param tree: Tree - 20 byte tree sha + Tree object :param author: Actor is the author string ( will be implicitly converted into an Actor object ) :param authored_date: int_seconds_since_epoch @@ -103,7 +104,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): :note: Timezone information is in the same format and in the same sign as what time.altzone returns. The sign is inverted compared to git's UTC timezone.""" - super(Commit,self).__init__(repo, sha) + super(Commit,self).__init__(repo, binsha) self._set_self_from_args_(locals()) @classmethod @@ -227,14 +228,14 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): line = readline() if not line: break - sha = line.strip() - if len(sha) > 40: + hexsha = line.strip() + if len(hexsha) > 40: # split additional information, as returned by bisect for instance - sha, rest = line.split(None, 1) + hexsha, rest = line.split(None, 1) # END handle extra info - assert len(sha) == 40, "Invalid line: %s" % sha - yield Commit(repo, sha) + assert len(hexsha) == 40, "Invalid line: %s" % hexsha + yield Commit(repo, hex_to_bin(hexsha)) # END for each line in stream @@ -282,7 +283,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): # COMMITER AND AUTHOR INFO cr = repo.config_reader() - env = environ + env = os.environ default_email = get_user_id() default_name = default_email.split('@')[0] diff --git a/lib/git/objects/tag.py b/lib/git/objects/tag.py index 2e6ec878..702eae35 100644 --- a/lib/git/objects/tag.py +++ b/lib/git/objects/tag.py @@ -32,7 +32,7 @@ class TagObject(base.Object): it into a different format :param tagged_tz_offset: int_seconds_west_of_utc is the timezone that the authored_date is in, in a format similar to time.altzone""" - super(TagObject, self).__init__(repo, sha ) + super(TagObject, self).__init__(repo, binsha ) self._set_self_from_args_(locals()) def _set_cache_(self, attr): diff --git a/lib/git/objects/tree.py b/lib/git/objects/tree.py index b6902fbb..056d3da9 100644 --- a/lib/git/objects/tree.py +++ b/lib/git/objects/tree.py @@ -15,7 +15,10 @@ from fun import ( tree_to_stream ) -from gitdb.util import to_bin_sha +from gitdb.util import ( + to_bin_sha, + join + ) __all__ = ("TreeModifier", "Tree") @@ -61,7 +64,7 @@ class TreeModifier(object): :return: self""" if '/' in name: raise ValueError("Name must not contain '/' characters") - if (mode >> 12) not in self._map_id_to_type: + if (mode >> 12) not in Tree._map_id_to_type: raise ValueError("Invalid object type according to mode %o" % mode) sha = to_bin_sha(sha) @@ -150,7 +153,7 @@ class Tree(IndexObject, diff.Diffable, utils.Traversable, utils.Serializable): for binsha, mode, name in iterable: path = join(self.path, name) try: - yield self._map_id_to_type[type_id](self.repo, binsha, mode >> 12, path) + yield self._map_id_to_type[mode >> 12](self.repo, binsha, mode, path) except KeyError: raise TypeError("Unknown mode %o found in tree data for path '%s'" % (mode, path)) # END for each item diff --git a/lib/git/refs.py b/lib/git/refs.py index d5fe70c7..8258ca8d 100644 --- a/lib/git/refs.py +++ b/lib/git/refs.py @@ -25,7 +25,8 @@ from gitdb.util import ( isdir, exists, isfile, - rename + rename, + hex_to_bin ) @@ -147,11 +148,11 @@ class SymbolicReference(object): Commit object we point to, works for detached and non-detached SymbolicReferences""" # we partially reimplement it to prevent unnecessary file access - sha, target_ref_path = self._get_ref_info() + hexsha, target_ref_path = self._get_ref_info() # it is a detached reference - if sha: - return Commit(self.repo, sha) + if hexsha: + return Commit(self.repo, hex_to_bin(hexsha)) return self.from_path(self.repo, target_ref_path).commit @@ -402,9 +403,9 @@ class SymbolicReference(object): os.remove(new_abs_path) # END handle existing target file - dirname = dirname(new_abs_path) - if not isdir(dirname): - os.makedirs(dirname) + dname = dirname(new_abs_path) + if not isdir(dname): + os.makedirs(dname) # END create directory rename(cur_abs_path, new_abs_path) diff --git a/lib/git/remote.py b/lib/git/remote.py index 5991a020..94bd285b 100644 --- a/lib/git/remote.py +++ b/lib/git/remote.py @@ -21,7 +21,9 @@ from refs import ( TagReference ) -from gitdb.util import join +from gitdb.util import ( + join, + ) import re __all__ = ('RemoteProgress', 'PushInfo', 'FetchInfo', 'Remote') @@ -256,7 +258,8 @@ class PushInfo(object): if control_character == " ": split_token = ".." old_sha, new_sha = summary.split(' ')[0].split(split_token) - old_commit = Commit(remote.repo, old_sha) + # have to use constructor here as the sha usually is abbreviated + old_commit = remote.repo.commit(old_sha) # END message handling return PushInfo(flags, from_ref, to_ref_string, remote, old_commit, summary) diff --git a/lib/git/repo.py b/lib/git/repo.py index 2cae0508..9b25653f 100644 --- a/lib/git/repo.py +++ b/lib/git/repo.py @@ -21,7 +21,8 @@ from db import ( from gitdb.util import ( join, isdir, - isfile + isfile, + hex_to_bin ) import os import sys @@ -576,7 +577,7 @@ class Repo(object): sha = info['id'] c = commits.get(sha) if c is None: - c = Commit( self, sha, + c = Commit( self, hex_to_bin(sha), author=Actor._from_string(info['author'] + ' ' + info['author_email']), authored_date=info['author_date'], committer=Actor._from_string(info['committer'] + ' ' + info['committer_email']), diff --git a/lib/git/utils.py b/lib/git/utils.py index b224cb97..e49fcc2a 100644 --- a/lib/git/utils.py +++ b/lib/git/utils.py @@ -18,6 +18,9 @@ from gitdb.util import ( to_bin_sha ) +__all__ = ( "stream_copy", "join_path", "to_native_path_windows", "to_native_path_linux", + "join_path_native", "Stats", "IndexFileSHA1Writer", "Iterable", "IterableList", + "BlockingLockFile", "LockFile" ) def stream_copy(source, destination, chunk_size=512*1024): """Copy all data from the source stream into the destination stream in chunks @@ -104,7 +107,7 @@ class Stats(object): """Create a Stat object from output retrieved by git-diff. :return: git.Stat""" - hsh = {'total': {'insertions': 0, 'deletions': 0, 'lines': 0, 'files': 0}, 'files': {}} + hsh = {'total': {'insertions': 0, 'deletions': 0, 'lines': 0, 'files': 0}, 'files': dict()} for line in text.splitlines(): (raw_insertions, raw_deletions, filename) = line.split("\t") insertions = raw_insertions != '-' and int(raw_insertions) or 0 @@ -305,6 +308,7 @@ class IterableList(list): except AttributeError: raise IndexError( "No item found with id %r" % (self._prefix + index) ) + class Iterable(object): """Defines an interface for iterable items which is to assure a uniform way to retrieve and iterate items within the git repository""" diff --git a/test/fixtures/diff_new_mode b/test/fixtures/diff_new_mode index 663c9099..29705386 100644 --- a/test/fixtures/diff_new_mode +++ b/test/fixtures/diff_new_mode @@ -1,7 +1,7 @@ diff --git a/conf/global_settings.py b/conf/global_settings.py old mode 100644 new mode 100755 -index 9ec1bac..1c4f83b +index 9ec1bac000000000000000000000000000000000..1c4f83b000000000000000000000000000000000 --- a/conf/global_settings.py +++ b/conf/global_settings.py @@ -58,6 +58,7 @@ TEMPLATE_CONTEXT_PROCESSORS = ( diff --git a/test/git/test_base.py b/test/git/test_base.py index 81931ad0..1b01cda3 100644 --- a/test/git/test_base.py +++ b/test/git/test_base.py @@ -12,87 +12,91 @@ from test.testlib import * from git import * from itertools import chain from git.objects.utils import get_object_type_by_name +from gitdb.util import hex_to_bin import tempfile class TestBase(TestBase): - - type_tuples = ( ("blob", "8741fc1d09d61f02ffd8cded15ff603eff1ec070", "blob.py"), - ("tree", "3a6a5e3eeed3723c09f1ef0399f81ed6b8d82e79", "directory"), - ("commit", "4251bd59fb8e11e40c40548cba38180a9536118c", None), - ("tag", "e56a60e8e9cd333cfba0140a77cd12b0d9398f10", None) ) - - def test_base_object(self): - # test interface of base object classes - types = (Blob, Tree, Commit, TagObject) - assert len(types) == len(self.type_tuples) - - s = set() - num_objs = 0 - num_index_objs = 0 - for obj_type, (typename, hexsha, path) in zip(types, self.type_tuples): - item = None - if path is None: - item = obj_type(self.rorepo,hexsha) - else: - item = obj_type(self.rorepo,hexsha, 0, path) - num_objs += 1 - assert item.sha == hexsha - assert item.type == typename - assert item.size - assert item.data - assert item == item - assert not item != item - assert str(item) == item.sha - assert repr(item) - s.add(item) - - if isinstance(item, base.IndexObject): - num_index_objs += 1 - if hasattr(item,'path'): # never runs here - assert not item.path.startswith("/") # must be relative - assert isinstance(item.mode, int) - # END index object check - - # read from stream - data_stream = item.data_stream - data = data_stream.read() - assert data - - tmpfile = os.tmpfile() - assert item == item.stream_data(tmpfile) - tmpfile.seek(0) - assert tmpfile.read() == data - # END stream to file directly - # END for each object type to create - - # each has a unique sha - assert len(s) == num_objs - assert len(s|s) == num_objs - assert num_index_objs == 2 - - def test_get_object_type_by_name(self): - for tname in base.Object.TYPES: - assert base.Object in get_object_type_by_name(tname).mro() - # END for each known type - - assert_raises( ValueError, get_object_type_by_name, "doesntexist" ) + + type_tuples = ( ("blob", "8741fc1d09d61f02ffd8cded15ff603eff1ec070", "blob.py"), + ("tree", "3a6a5e3eeed3723c09f1ef0399f81ed6b8d82e79", "directory"), + ("commit", "4251bd59fb8e11e40c40548cba38180a9536118c", None), + ("tag", "e56a60e8e9cd333cfba0140a77cd12b0d9398f10", None) ) + + def test_base_object(self): + # test interface of base object classes + types = (Blob, Tree, Commit, TagObject) + assert len(types) == len(self.type_tuples) + + s = set() + num_objs = 0 + num_index_objs = 0 + for obj_type, (typename, hexsha, path) in zip(types, self.type_tuples): + binsha = hex_to_bin(hexsha) + item = None + if path is None: + item = obj_type(self.rorepo,binsha) + else: + item = obj_type(self.rorepo,binsha, 0, path) + # END handle index objects + num_objs += 1 + assert item.hexsha == hexsha + assert item.type == typename + assert item.size + if isinstance(item, Blob): + assert item.data + assert item == item + assert not item != item + assert str(item) == item.hexsha + assert repr(item) + s.add(item) + + if isinstance(item, base.IndexObject): + num_index_objs += 1 + if hasattr(item,'path'): # never runs here + assert not item.path.startswith("/") # must be relative + assert isinstance(item.mode, int) + # END index object check + + # read from stream + data_stream = item.data_stream + data = data_stream.read() + assert data + + tmpfile = os.tmpfile() + assert item == item.stream_data(tmpfile) + tmpfile.seek(0) + assert tmpfile.read() == data + # END stream to file directly + # END for each object type to create + + # each has a unique sha + assert len(s) == num_objs + assert len(s|s) == num_objs + assert num_index_objs == 2 + + def test_get_object_type_by_name(self): + for tname in base.Object.TYPES: + assert base.Object in get_object_type_by_name(tname).mro() + # END for each known type + + assert_raises( ValueError, get_object_type_by_name, "doesntexist" ) - def test_object_resolution(self): - # objects must be resolved to shas so they compare equal - assert self.rorepo.head.reference.object == self.rorepo.active_branch.object - - @with_bare_rw_repo - def test_with_bare_rw_repo(self, bare_rw_repo): - assert bare_rw_repo.config_reader("repository").getboolean("core", "bare") - assert os.path.isfile(os.path.join(bare_rw_repo.git_dir,'HEAD')) - - @with_rw_repo('0.1.6') - def test_with_rw_repo(self, rw_repo): - assert not rw_repo.config_reader("repository").getboolean("core", "bare") - assert os.path.isdir(os.path.join(rw_repo.working_tree_dir,'lib')) - - @with_rw_and_rw_remote_repo('0.1.6') - def test_with_rw_remote_and_rw_repo(self, rw_repo, rw_remote_repo): - assert not rw_repo.config_reader("repository").getboolean("core", "bare") - assert rw_remote_repo.config_reader("repository").getboolean("core", "bare") - assert os.path.isdir(os.path.join(rw_repo.working_tree_dir,'lib')) + def test_object_resolution(self): + # objects must be resolved to shas so they compare equal + assert self.rorepo.head.reference.object == self.rorepo.active_branch.object + + @with_bare_rw_repo + def test_with_bare_rw_repo(self, bare_rw_repo): + assert bare_rw_repo.config_reader("repository").getboolean("core", "bare") + assert os.path.isfile(os.path.join(bare_rw_repo.git_dir,'HEAD')) + + @with_rw_repo('0.1.6') + def test_with_rw_repo(self, rw_repo): + assert not rw_repo.config_reader("repository").getboolean("core", "bare") + assert os.path.isdir(os.path.join(rw_repo.working_tree_dir,'lib')) + + @with_rw_and_rw_remote_repo('0.1.6') + def test_with_rw_remote_and_rw_repo(self, rw_repo, rw_remote_repo): + assert not rw_repo.config_reader("repository").getboolean("core", "bare") + assert rw_remote_repo.config_reader("repository").getboolean("core", "bare") + assert os.path.isdir(os.path.join(rw_repo.working_tree_dir,'lib')) diff --git a/test/git/test_blob.py b/test/git/test_blob.py index cf70cb8c..e5fca0a6 100644 --- a/test/git/test_blob.py +++ b/test/git/test_blob.py @@ -6,25 +6,23 @@ from test.testlib import * from git import * +from gitdb.util import hex_to_bin class TestBlob(TestBase): def test_should_cache_data(self): bid = 'a802c139d4767c89dcad79d836d05f7004d39aac' - blob = Blob(self.rorepo, bid) + blob = Blob(self.rorepo, hex_to_bin(bid)) blob.data assert blob.data blob.size blob.size def test_mime_type_should_return_mime_type_for_known_types(self): - blob = Blob(self.rorepo, **{'sha': 'abc', 'path': 'foo.png'}) + blob = Blob(self.rorepo, **{'binsha': Blob.NULL_BIN_SHA, 'path': 'foo.png'}) assert_equal("image/png", blob.mime_type) def test_mime_type_should_return_text_plain_for_unknown_types(self): - blob = Blob(self.rorepo, **{'sha': 'abc','path': 'something'}) + blob = Blob(self.rorepo, **{'binsha': Blob.NULL_BIN_SHA,'path': 'something'}) assert_equal("text/plain", blob.mime_type) - def test_should_return_appropriate_representation(self): - blob = Blob(self.rorepo, **{'sha': 'abc'}) - assert_equal('<git.Blob "abc">', repr(blob)) diff --git a/test/git/test_commit.py b/test/git/test_commit.py index 8629e625..31ce2c4e 100644 --- a/test/git/test_commit.py +++ b/test/git/test_commit.py @@ -7,6 +7,7 @@ from test.testlib import * from git import * from gitdb import IStream +from gitdb.util import hex_to_bin from cStringIO import StringIO import time @@ -33,9 +34,9 @@ def assert_commit_serialization(rwrepo, commit_id, print_performance_info=False) stream.seek(0) istream = rwrepo.odb.store(IStream(Commit.type, streamlen, stream)) - assert istream.sha == cm.sha + assert istream.hexsha == cm.hexsha - nc = Commit(rwrepo, Commit.NULL_HEX_SHA, cm.tree.sha, + nc = Commit(rwrepo, Commit.NULL_BIN_SHA, cm.tree, cm.author, cm.authored_date, cm.author_tz_offset, cm.committer, cm.committed_date, cm.committer_tz_offset, cm.message, cm.parents, cm.encoding) @@ -50,11 +51,11 @@ def assert_commit_serialization(rwrepo, commit_id, print_performance_info=False) # reuse istream istream.size = streamlen istream.stream = stream - istream.sha = None - nc.sha = rwrepo.odb.store(istream).sha + istream.binsha = None + nc.binsha = rwrepo.odb.store(istream).binsha # if it worked, we have exactly the same contents ! - assert nc.sha == cm.sha + assert nc.hexsha == cm.hexsha # END check commits elapsed = time.time() - st @@ -67,7 +68,7 @@ class TestCommit(TestBase): def test_bake(self): - commit = Commit(self.rorepo, '2454ae89983a4496a445ce347d7a41c0bb0ea7ae') + commit = self.rorepo.commit('2454ae89983a4496a445ce347d7a41c0bb0ea7ae') commit.author # bake assert_equal("Sebastian Thiel", commit.author.name) @@ -79,7 +80,7 @@ class TestCommit(TestBase): def test_stats(self): - commit = Commit(self.rorepo, '33ebe7acec14b25c5f84f35a664803fcab2f7781') + commit = self.rorepo.commit('33ebe7acec14b25c5f84f35a664803fcab2f7781') stats = commit.stats def check_entries(d): @@ -158,7 +159,7 @@ class TestCommit(TestBase): assert all_commits == list(self.rorepo.iter_commits()) # this includes merge commits - mcomit = Commit(self.rorepo, 'd884adc80c80300b4cc05321494713904ef1df2d') + mcomit = self.rorepo.commit('d884adc80c80300b4cc05321494713904ef1df2d') assert mcomit in all_commits # we can limit the result to paths @@ -190,26 +191,26 @@ class TestCommit(TestBase): '933d23bf95a5bd1624fbcdf328d904e1fa173474' ) for sha1, commit in zip(expected_ids, commits): - assert_equal(sha1, commit.sha) + assert_equal(sha1, commit.hexsha) def test_count(self): assert self.rorepo.tag('refs/tags/0.1.5').commit.count( ) == 143 def test_list(self): - assert isinstance(Commit.list_items(self.rorepo, '0.1.5', max_count=5)['5117c9c8a4d3af19a9958677e45cda9269de1541'], Commit) + assert isinstance(Commit.list_items(self.rorepo, '0.1.5', max_count=5)[hex_to_bin('5117c9c8a4d3af19a9958677e45cda9269de1541')], Commit) def test_str(self): - commit = Commit(self.rorepo, 'abc') - assert_equal ("abc", str(commit)) + commit = Commit(self.rorepo, Commit.NULL_BIN_SHA) + assert_equal(Commit.NULL_HEX_SHA, str(commit)) def test_repr(self): - commit = Commit(self.rorepo, 'abc') - assert_equal('<git.Commit "abc">', repr(commit)) + commit = Commit(self.rorepo, Commit.NULL_BIN_SHA) + assert_equal('<git.Commit "%s">' % Commit.NULL_HEX_SHA, repr(commit)) def test_equality(self): - commit1 = Commit(self.rorepo, 'abc') - commit2 = Commit(self.rorepo, 'abc') - commit3 = Commit(self.rorepo, 'zyx') + commit1 = Commit(self.rorepo, Commit.NULL_BIN_SHA) + commit2 = Commit(self.rorepo, Commit.NULL_BIN_SHA) + commit3 = Commit(self.rorepo, "\1"*20) assert_equal(commit1, commit2) assert_not_equal(commit2, commit3) diff --git a/test/git/test_fun.py b/test/git/test_fun.py index dad9fcda..3fdc13fd 100644 --- a/test/git/test_fun.py +++ b/test/git/test_fun.py @@ -9,6 +9,7 @@ from git.index.fun import ( aggressive_tree_merge ) +from gitdb.util import bin_to_hex from gitdb.base import IStream from gitdb.typ import str_tree_type @@ -24,7 +25,7 @@ from cStringIO import StringIO class TestFun(TestBase): def _assert_index_entries(self, entries, trees): - index = IndexFile.from_tree(self.rorepo, *trees) + index = IndexFile.from_tree(self.rorepo, *[self.rorepo.tree(bin_to_hex(t)) for t in trees]) assert entries assert len(index.entries) == len(entries) for entry in entries: @@ -39,11 +40,11 @@ class TestFun(TestBase): B = HC.parents[0].tree # entries from single tree - trees = [H.sha] + trees = [H.binsha] self._assert_index_entries(aggressive_tree_merge(odb, trees), trees) # from multiple trees - trees = [B.sha, H.sha] + trees = [B.binsha, H.binsha] self._assert_index_entries(aggressive_tree_merge(odb, trees), trees) # three way, no conflict @@ -51,14 +52,14 @@ class TestFun(TestBase): B = tree("35a09c0534e89b2d43ec4101a5fb54576b577905") H = tree("4fe5cfa0e063a8d51a1eb6f014e2aaa994e5e7d4") M = tree("1f2b19de3301e76ab3a6187a49c9c93ff78bafbd") - trees = [B.sha, H.sha, M.sha] + trees = [B.binsha, H.binsha, M.binsha] self._assert_index_entries(aggressive_tree_merge(odb, trees), trees) # three-way, conflict in at least one file, both modified B = tree("a7a4388eeaa4b6b94192dce67257a34c4a6cbd26") H = tree("f9cec00938d9059882bb8eabdaf2f775943e00e5") M = tree("44a601a068f4f543f73fd9c49e264c931b1e1652") - trees = [B.sha, H.sha, M.sha] + trees = [B.binsha, H.binsha, M.binsha] self._assert_index_entries(aggressive_tree_merge(odb, trees), trees) # too many trees @@ -70,7 +71,7 @@ class TestFun(TestBase): tree_to_stream(entries, sio.write) sio.seek(0) istream = odb.store(IStream(str_tree_type, len(sio.getvalue()), sio)) - return istream.sha + return istream.binsha @with_rw_repo('0.1.6') def test_three_way_merge(self, rwrepo): @@ -216,25 +217,25 @@ class TestFun(TestBase): B_old = self.rorepo.tree('1f66cfbbce58b4b552b041707a12d437cc5f400a') # old base tree # two very different trees - entries = traverse_trees_recursive(odb, [B_old.sha, H.sha], '') + entries = traverse_trees_recursive(odb, [B_old.binsha, H.binsha], '') self._assert_tree_entries(entries, 2) - oentries = traverse_trees_recursive(odb, [H.sha, B_old.sha], '') + oentries = traverse_trees_recursive(odb, [H.binsha, B_old.binsha], '') assert len(oentries) == len(entries) self._assert_tree_entries(oentries, 2) # single tree is_no_tree = lambda i, d: i.type != 'tree' - entries = traverse_trees_recursive(odb, [B.sha], '') + entries = traverse_trees_recursive(odb, [B.binsha], '') assert len(entries) == len(list(B.traverse(predicate=is_no_tree))) self._assert_tree_entries(entries, 1) # two trees - entries = traverse_trees_recursive(odb, [B.sha, H.sha], '') + entries = traverse_trees_recursive(odb, [B.binsha, H.binsha], '') self._assert_tree_entries(entries, 2) # tree trees - entries = traverse_trees_recursive(odb, [B.sha, H.sha, M.sha], '') + entries = traverse_trees_recursive(odb, [B.binsha, H.binsha, M.binsha], '') self._assert_tree_entries(entries, 3) def test_tree_traversal_single(self): @@ -245,6 +246,6 @@ class TestFun(TestBase): if count >= max_count: break count += 1 - entries = traverse_tree_recursive(odb, commit.tree.sha, '') + entries = traverse_tree_recursive(odb, commit.tree.binsha, '') assert entries # END for each commit diff --git a/test/git/test_index.py b/test/git/test_index.py index e9f99f04..705d8029 100644 --- a/test/git/test_index.py +++ b/test/git/test_index.py @@ -354,7 +354,7 @@ class TestIndex(TestBase): if type_id == 0: # path yield entry.path elif type_id == 1: # blob - yield Blob(rw_repo, entry.hexsha, entry.mode, entry.path) + yield Blob(rw_repo, entry.binsha, entry.mode, entry.path) elif type_id == 2: # BaseIndexEntry yield BaseIndexEntry(entry[:4]) elif type_id == 3: # IndexEntry @@ -449,7 +449,7 @@ class TestIndex(TestBase): old_blob = new_commit.parents[0].tree.blobs[0] entries = index.reset(new_commit).add([old_blob], fprogress=self._fprogress_add) self._assert_fprogress(entries) - assert index.entries[(old_blob.path,0)].hexsha == old_blob.sha and len(entries) == 1 + assert index.entries[(old_blob.path,0)].hexsha == old_blob.hexsha and len(entries) == 1 # mode 0 not allowed null_hex_sha = Diff.NULL_HEX_SHA @@ -567,7 +567,7 @@ class TestIndex(TestBase): for fid in range(3): fname = 'newfile%i' % fid open(fname, 'wb').write("abcd") - yield Blob(rw_repo, Blob.NULL_HEX_SHA, 0100644, fname) + yield Blob(rw_repo, Blob.NULL_BIN_SHA, 0100644, fname) # END for each new file # END path producer paths = list(make_paths()) diff --git a/test/git/test_remote.py b/test/git/test_remote.py index 58fad308..9d4da034 100644 --- a/test/git/test_remote.py +++ b/test/git/test_remote.py @@ -6,6 +6,7 @@ from test.testlib import * from git import * +from git.utils import IterableList import tempfile import shutil import os diff --git a/test/git/test_repo.py b/test/git/test_repo.py index d2c7c742..a3ff564d 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -49,7 +49,7 @@ class TestRepo(TestBase): def test_tree_from_revision(self): tree = self.rorepo.tree('0.1.6') - assert len(tree.sha) == 40 + assert len(tree.hexsha) == 40 assert tree.type == "tree" assert self.rorepo.tree(tree) == tree @@ -62,9 +62,9 @@ class TestRepo(TestBase): assert len(commits) == mc c = commits[0] - assert_equal('9a4b1d4d11eee3c5362a4152216376e634bd14cf', c.sha) - assert_equal(["c76852d0bff115720af3f27acdb084c59361e5f6"], [p.sha for p in c.parents]) - assert_equal("ce41fc29549042f1aa09cc03174896cf23f112e3", c.tree.sha) + assert_equal('9a4b1d4d11eee3c5362a4152216376e634bd14cf', c.hexsha) + assert_equal(["c76852d0bff115720af3f27acdb084c59361e5f6"], [p.hexsha for p in c.parents]) + assert_equal("ce41fc29549042f1aa09cc03174896cf23f112e3", c.tree.hexsha) assert_equal("Michael Trier", c.author.name) assert_equal("mtrier@gmail.com", c.author.email) assert_equal(1232829715, c.authored_date) @@ -255,7 +255,7 @@ class TestRepo(TestBase): assert_true(git.called) assert_equal(git.call_args, (('blame', 'master', '--', 'lib/git.py'), {'p': True})) - assert_equal('634396b2f541a9f2d58b00be1a07f0c358b999b3', c.sha) + assert_equal('634396b2f541a9f2d58b00be1a07f0c358b999b3', c.hexsha) assert_equal('Tom Preston-Werner', c.author.name) assert_equal('tom@mojombo.com', c.author.email) assert_equal(1191997100, c.authored_date) diff --git a/test/git/test_tree.py b/test/git/test_tree.py index a443bd97..d08999bd 100644 --- a/test/git/test_tree.py +++ b/test/git/test_tree.py @@ -23,7 +23,7 @@ class TestTree(TestBase): continue # END skip non-trees tree = item - orig_data = tree.data + orig_data = tree.data_stream.read() orig_cache = tree._cache stream = StringIO() @@ -31,7 +31,7 @@ class TestTree(TestBase): assert stream.getvalue() == orig_data stream.seek(0) - testtree = Tree(self.rorepo, Tree.NULL_HEX_SHA, 0, '') + testtree = Tree(self.rorepo, Tree.NULL_BIN_SHA, 0, '') testtree._deserialize(stream) assert testtree._cache == orig_cache @@ -61,7 +61,7 @@ class TestTree(TestBase): # force it - replace existing one mod.add(hexsha, tree.mode, name, force=True) - assert testtree[name].sha == hexsha + assert testtree[name].hexsha == hexsha assert len(testtree) == cur_count # unchecked addition always works, even with invalid items @@ -137,7 +137,3 @@ class TestTree(TestBase): # END for each item assert found_slash - def test_repr(self): - tree = Tree(self.rorepo, 'abc') - assert_equal('<git.Tree "abc">', repr(tree)) - diff --git a/test/testlib/helper.py b/test/testlib/helper.py index 4399561c..0bfdfa69 100644 --- a/test/testlib/helper.py +++ b/test/testlib/helper.py @@ -74,10 +74,19 @@ def with_bare_rw_repo(func): rw_repo = self.rorepo.clone(repo_dir, shared=True, bare=True) prev_cwd = os.getcwd() try: - return func(self, rw_repo) + try: + return func(self, rw_repo) + except: + # assure we keep the repo for debugging + print >> sys.stderr, "Keeping bare repo after failure: %s" % repo_dir + repo_dir = None + raise + # END handle exceptions finally: rw_repo.git.clear_cache() - shutil.rmtree(repo_dir, onerror=_rmtree_onerror) + if repo_dir is not None: + shutil.rmtree(repo_dir, onerror=_rmtree_onerror) + # END remove repo dir # END cleanup # END bare repo creator bare_repo_creator.__name__ = func.__name__ @@ -99,7 +108,7 @@ def with_rw_repo(working_tree_ref): repo_dir = tempfile.mktemp("non_bare_%s" % func.__name__) rw_repo = self.rorepo.clone(repo_dir, shared=True, bare=False, n=True) - rw_repo.head.commit = working_tree_ref + rw_repo.head.commit = rw_repo.commit(working_tree_ref) rw_repo.head.reference.checkout() prev_cwd = os.getcwd() |