diff options
Diffstat (limited to 'git/repo/fun.py')
-rw-r--r-- | git/repo/fun.py | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/git/repo/fun.py b/git/repo/fun.py index 2c49d836..fe26d8ce 100644 --- a/git/repo/fun.py +++ b/git/repo/fun.py @@ -53,8 +53,8 @@ def short_to_long(odb, hexsha): except BadObject: return None # END exception handling - - + + def name_to_object(repo, name, return_ref=False): """ :return: object specified by the given name, hexshas ( short and long ) @@ -63,7 +63,7 @@ def name_to_object(repo, name, return_ref=False): instead of the object. Otherwise it will raise BadObject """ hexsha = None - + # is it a hexsha ? Try the most common ones, which is 7 to 40 if repo.re_hexsha_shortened.match(name): if len(name) != 40: @@ -73,7 +73,7 @@ def name_to_object(repo, name, return_ref=False): hexsha = name # END handle short shas #END find sha if it matches - + # if we couldn't find an object for what seemed to be a short hexsha # try to find it as reference anyway, it could be named 'aaa' for instance if hexsha is None: @@ -98,7 +98,7 @@ def name_to_object(repo, name, return_ref=False): if hexsha is None: raise BadObject(name) # END assert hexsha was found - + return Object.new_from_sha(repo, hex_to_bin(hexsha)) def deref_tag(tag): @@ -115,7 +115,7 @@ def to_commit(obj): """Convert the given object to a commit if possible and return it""" if obj.type == 'tag': obj = deref_tag(obj) - + if obj.type != "commit": raise ValueError("Cannot convert object %r to type commit" % obj) # END verify type @@ -132,13 +132,13 @@ def rev_parse(repo, rev): :raise BadObject: if the given revision could not be found :raise ValueError: If rev couldn't be parsed :raise IndexError: If invalid reflog index is specified""" - + # colon search mode ? if rev.startswith(':/'): # colon search mode raise NotImplementedError("commit by message search ( regex )") # END handle search - + obj = None ref = None output_type = "commit" @@ -150,9 +150,9 @@ def rev_parse(repo, rev): start += 1 continue # END handle start - + token = rev[start] - + if obj is None: # token is a rev name if start == 0: @@ -164,22 +164,22 @@ def rev_parse(repo, rev): obj = name_to_object(repo, rev[:start]) #END handle token #END handle refname - + if ref is not None: obj = ref.commit #END handle ref # END initialize obj on first token - - + + start += 1 - + # try to parse {type} if start < lr and rev[start] == '{': end = rev.find('}', start) if end == -1: raise ValueError("Missing closing brace to define type in %s" % rev) output_type = rev[start+1:end] # exclude brace - + # handle type if output_type == 'commit': pass # default @@ -208,31 +208,31 @@ def rev_parse(repo, rev): # maybe raise NotImplementedError("Support for additional @{...} modes not implemented") #END handle revlog index - + try: entry = ref.log_entry(revlog_index) except IndexError: raise IndexError("Invalid revlog index: %i" % revlog_index) #END handle index out of bound - + obj = Object.new_from_sha(repo, hex_to_bin(entry.newhexsha)) - + # make it pass the following checks output_type = None else: - raise ValueError("Invalid output type: %s ( in %s )" % (output_type, rev)) + raise ValueError("Invalid output type: %s ( in %s )" % (output_type, rev)) # END handle output 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 parsed_to = start continue # END parse type - + # try to parse a number num = 0 if token != ":": @@ -246,15 +246,15 @@ def rev_parse(repo, rev): break # END handle number # END number parse loop - + # no explicit number given, 1 is the default # It could be 0 though if not found_digit: num = 1 # END set default num # END number parsing only if non-blob mode - - + + parsed_to = start # handle hiererarchy walk try: @@ -281,17 +281,17 @@ def rev_parse(repo, rev): raise BadObject("Invalid Revision in %s" % rev) # END exception handling # END parse loop - + # still no obj ? Its probably a simple name if obj is None: obj = name_to_object(repo, rev) parsed_to = lr # END handle simple name - + if obj is None: raise ValueError("Revision specifier could not be parsed: %s" % rev) if parsed_to != lr: raise ValueError("Didn't consume complete rev spec %s, consumed part: %s" % (rev, rev[:parsed_to])) - + return obj |