diff options
Diffstat (limited to 'lib/git')
-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 |
9 files changed, 54 insertions, 39 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""" |