diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2010-07-06 12:09:11 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2010-07-06 14:19:31 +0200 |
commit | 73959f3a2d4f224fbda03c8a8850f66f53d8cb3b (patch) | |
tree | 42e1930667a159c90a7f0bacbd83ba35091f6c82 /lib/git | |
parent | a32a6bcd784fca9cb2b17365591c29d15c2f638e (diff) | |
download | gitpython-73959f3a2d4f224fbda03c8a8850f66f53d8cb3b.tar.gz |
Implemented main rev-parsing, including long hexshas, tags and refs. Short Shas still to be done
Diffstat (limited to 'lib/git')
-rw-r--r-- | lib/git/repo.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/git/repo.py b/lib/git/repo.py index 5a1af920..e9dfabcd 100644 --- a/lib/git/repo.py +++ b/lib/git/repo.py @@ -71,7 +71,8 @@ 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_shortened = re.compile('^[0-9A-Fa-f]{7,40}$') + re_hexsha_domain = re.compile('^[0-9A-Fa-f]{1,40}$') re_author_committer_start = re.compile(r'^(author|committer)') re_tab_full_line = re.compile(r'^\t(.*)$') @@ -724,7 +725,7 @@ class Repo(object): def name_to_object(name): hexsha = None - # is it a hexsha ? + # is it a hexsha ? Try the most common ones, which is 7 to 40 if self.re_hexsha_shortened.match(name): if len(name) != 40: # find long sha for short sha @@ -744,6 +745,11 @@ class Repo(object): # 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 self.re_hexsha_domain.match(name): + raise NotImplementedError() + # END try short name raise BadObject(name) # END assert hexsha was found @@ -806,7 +812,7 @@ class Repo(object): # END exception handling elif output_type in ('', 'blob'): if obj.type == 'tag': - obj = deref_tag(tag) + obj = deref_tag(obj) else: # cannot do anything for non-tags pass @@ -815,8 +821,9 @@ class Repo(object): raise ValueError("Invalid output type: %s ( in %s )" % (output_type, rev)) # END handle output type - if obj.type != output_type: - raise ValueError("Could not accomodate requested object type %s, got %s" % (output_type, obj.type)) + # empty output types don't require any specific type, its just about dereferencing tags + if output_type and obj.type != output_type: + raise ValueError("Could not accomodate requested object type %r, got %s" % (output_type, obj.type)) # END verify ouput type start = end+1 # skip brace @@ -849,12 +856,13 @@ class Repo(object): parsed_to = start # handle hiererarchy walk try: - obj = to_commit(obj) if token == "~": + obj = to_commit(obj) for item in xrange(num): obj = obj.parents[0] # END for each history item to walk elif token == "^": + obj = to_commit(obj) # must be n'th parent if num: obj = obj.parents[num-1] |