Permalink
Browse files

persistent command signature changed to also return the hexsha from a…

… possible input ref - the objects pointed to by refs are now baked on demand - perhaps it should change to always be re-retrieved using a property as it is relatively fast - this way refs can always be cached
  • Loading branch information...
Byron committed Oct 14, 2009
1 parent 6745f45 commit c5df44408218003eb49e3b8fc94329c5e8b46c7d
Showing with 18 additions and 15 deletions.
  1. +6 −6 lib/git/cmd.py
  2. +2 −2 lib/git/objects/base.py
  3. +8 −5 lib/git/refs.py
  4. +2 −2 test/git/test_git.py
View
@@ -272,7 +272,7 @@ def _parse_object_header(self, header_line):
<hex_sha> type_string size_as_int
Returns
- (type_string, size_as_int)
+ (hex_sha, type_string, size_as_int)
Raises
ValueError if the header contains indication for an error due to incorrect
@@ -282,7 +282,7 @@ def _parse_object_header(self, header_line):
if len(tokens) != 3:
raise ValueError( "SHA named %s could not be resolved" % tokens[0] )
- return (tokens[1], int(tokens[2]))
+ return (tokens[0], tokens[1], int(tokens[2]))
def __prepare_ref(self, ref):
# required for command to separate refs on stdin
@@ -318,7 +318,7 @@ def get_object_header(self, ref):
once and reuses the command in subsequent calls.
Return:
- (type_string, size_as_int)
+ (hexsha, type_string, size_as_int)
"""
cmd = self.__get_persistent_cmd("cat_file_header", "cat_file", batch_check=True)
return self.__get_object_header(cmd, ref)
@@ -328,11 +328,11 @@ def get_object_data(self, ref):
As get_object_header, but returns object data as well
Return:
- (type_string, size_as_int,data_string)
+ (hexsha, type_string, size_as_int,data_string)
"""
cmd = self.__get_persistent_cmd("cat_file_all", "cat_file", batch=True)
- typename, size = self.__get_object_header(cmd, ref)
+ hexsha, typename, size = self.__get_object_header(cmd, ref)
data = cmd.stdout.read(size)
cmd.stdout.read(1) # finishing newlines
- return (typename, size, data)
+ return (hexsha, typename, size, data)
View
@@ -48,10 +48,10 @@ def _set_cache_(self, attr):
Retrieve object information
"""
if attr == "size":
- typename, self.size = self.repo.git.get_object_header(self.id)
+ hexsha, typename, self.size = self.repo.git.get_object_header(self.id)
assert typename == self.type, "Created object whose python type %r disagrees with the acutal git object type %r" % (typename, self.type)
elif attr == "data":
- typename, self.size, self.data = self.repo.git.get_object_data(self.id)
+ hexsha, typename, self.size, self.data = self.repo.git.get_object_data(self.id)
assert typename == self.type, "Created object whose python type %r disagrees with the acutal git object type %r" % (typename, self.type)
else:
super(Object,self)._set_cache_(attr)
View
@@ -38,10 +38,11 @@ def _set_cache_(self, attr):
if attr == "object":
# have to be dynamic here as we may be a tag which can point to anything
# it uses our path to stay dynamic
- typename, size = self.repo.git.get_object_header(self.path)
- # explicitly do not set the size as it may change if the our ref path points
- # at some other place when the head changes for instance ...
- self.object = get_object_type_by_name(typename)(self.repo, self.path)
+ hexsha, typename, size = self.repo.git.get_object_header(self.path)
+ # pin-point our object to a specific sha, even though it might not
+ # reflect the our cached object anymore in case our rev now points
+ # to a different commit
+ self.object = get_object_type_by_name(typename)(self.repo, hexsha)
else:
super(Ref, self)._set_cache_(attr)
@@ -128,7 +129,9 @@ def _from_string(cls, repo, line):
full_path, hexsha, type_name, object_size = line.split("\x00")
# No, we keep the object dynamic by allowing it to be retrieved by
- # our path on demand - due to perstent commands it is fast
+ # our path on demand - due to perstent commands it is fast.
+ # This reduces the risk that the object does not match
+ # the changed ref anymore in case it changes in the meanwhile
return cls(repo, full_path)
# obj = get_object_type_by_name(type_name)(repo, hexsha)
View
@@ -84,6 +84,6 @@ def test_persistent_cat_file_command(self):
# same can be achived using the respective command functions
- typename, size = self.git.get_object_header(hexsha)
- typename_two, size_two, data = self.git.get_object_data(hexsha)
+ hexsha, typename, size = self.git.get_object_header(hexsha)
+ hexsha, typename_two, size_two, data = self.git.get_object_data(hexsha)
assert typename == typename_two and size == size_two

0 comments on commit c5df444

Please sign in to comment.