diff options
Diffstat (limited to 'lib/git')
-rw-r--r-- | lib/git/db.py | 27 | ||||
m--------- | lib/git/ext/gitdb | 0 | ||||
-rw-r--r-- | lib/git/repo/base.py | 3 | ||||
-rw-r--r-- | lib/git/repo/fun.py | 23 |
4 files changed, 40 insertions, 13 deletions
diff --git a/lib/git/db.py b/lib/git/db.py index c36446d0..945031bb 100644 --- a/lib/git/db.py +++ b/lib/git/db.py @@ -1,11 +1,15 @@ -"""Module with our own gitdb implementation - it uses the git command""" +"""Module with our own gitdb implementation - it uses the git command""" +from exc import GitCommandError + from gitdb.base import ( OInfo, OStream ) -from gitdb.util import bin_to_hex - +from gitdb.util import ( + bin_to_hex, + hex_to_bin + ) from gitdb.db import GitDB from gitdb.db import LooseObjectDB @@ -35,3 +39,20 @@ class GitCmdObjectDB(LooseObjectDB): t = self._git.stream_object_data(bin_to_hex(sha)) return OStream(*t) + + # { Interface + + def partial_to_complete_sha_hex(partial_hexsha): + """:return: Full binary 20 byte sha from the given partial hexsha + :raise AmbiguousObjectName: + :raise BadObject: + :note: currently we only raise BadObject as git does not communicate + AmbiguousObjects separately""" + try: + hexsha, typename, size = self._git.get_object_header(partial_hexsha) + return hex_to_bin(hexsha) + except GitCommandError: + raise BadObject(partial_hexsha) + # END handle exceptions + + #} END interface diff --git a/lib/git/ext/gitdb b/lib/git/ext/gitdb -Subproject 46bf4710e0f7184ac4875e8037de30b5081bfda +Subproject ac7d4757ab4041f5f0f5806934130024b098bb8 diff --git a/lib/git/repo/base.py b/lib/git/repo/base.py index 976a68bf..e659225e 100644 --- a/lib/git/repo/base.py +++ b/lib/git/repo/base.py @@ -58,8 +58,7 @@ class Repo(object): # precompiled regex re_whitespace = re.compile(r'\s+') re_hexsha_only = re.compile('^[0-9A-Fa-f]{40}$') - re_hexsha_shortened = re.compile('^[0-9A-Fa-f]{7,40}$') - re_hexsha_domain = re.compile('^[0-9A-Fa-f]{1,40}$') + re_hexsha_shortened = re.compile('^[0-9A-Fa-f]{4,40}$') re_author_committer_start = re.compile(r'^(author|committer)') re_tab_full_line = re.compile(r'^\t(.*)$') diff --git a/lib/git/repo/fun.py b/lib/git/repo/fun.py index ab2eb8be..a0f66fe5 100644 --- a/lib/git/repo/fun.py +++ b/lib/git/repo/fun.py @@ -7,9 +7,9 @@ from gitdb.util import ( join, isdir, isfile, - hex_to_bin + hex_to_bin, + bin_to_hex ) - from string import digits __all__ = ('rev_parse', 'is_git_dir', 'touch') @@ -30,6 +30,18 @@ def is_git_dir(d): os.readlink(headref).startswith('refs')) return False + +def short_to_long(odb, hexsha): + """:return: long hexadecimal sha1 from the given less-than-40 byte hexsha + or None if no candidate could be found. + :param hexsha: hexsha with less than 40 byte""" + try: + return bin_to_hex(odb.partial_to_complete_sha_hex(hexsha)) + except BadObject: + return None + # END exception handling + + def name_to_object(repo, name): """:return: object specified by the given name, hexshas ( short and long ) as well as references are supported""" @@ -39,7 +51,7 @@ def name_to_object(repo, name): if repo.re_hexsha_shortened.match(name): if len(name) != 40: # find long sha for short sha - raise NotImplementedError("short sha parsing") + hexsha = short_to_long(repo.odb, name) else: hexsha = name # END handle short shas @@ -55,11 +67,6 @@ def name_to_object(repo, name): # tried everything ? fail if hexsha is None: - # it could also be a very short ( less than 7 ) hexsha, which - # wasnt tested in the first run - if len(name) < 7 and repo.re_hexsha_domain.match(name): - raise NotImplementedError() - # END try short name raise BadObject(name) # END assert hexsha was found |