summaryrefslogtreecommitdiff
path: root/lib/git
diff options
context:
space:
mode:
Diffstat (limited to 'lib/git')
-rw-r--r--lib/git/objects/base.py8
-rw-r--r--lib/git/objects/commit.py14
-rw-r--r--lib/git/objects/tag.py3
-rw-r--r--lib/git/refs.py17
4 files changed, 29 insertions, 13 deletions
diff --git a/lib/git/objects/base.py b/lib/git/objects/base.py
index 9789d72a..7b693be9 100644
--- a/lib/git/objects/base.py
+++ b/lib/git/objects/base.py
@@ -48,9 +48,13 @@ class Object(LazyMixin):
Retrieve object information
"""
if attr == "size":
- self.size = int(self.repo.git.cat_file(self.id, s=True).rstrip())
+ 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":
- self.data = self.repo.git.cat_file(self.id, p=True, with_raw_output=True)
+ 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)
def __eq__(self, other):
"""
diff --git a/lib/git/objects/commit.py b/lib/git/objects/commit.py
index 69fb3710..101014ab 100644
--- a/lib/git/objects/commit.py
+++ b/lib/git/objects/commit.py
@@ -81,7 +81,10 @@ class Commit(base.Object, Iterable):
We set all values at once.
"""
if attr in Commit.__slots__:
- temp = Commit.list_items(self.repo, self.id, max_count=1)[0]
+ # prepare our data lines to match rev-list
+ data_lines = self.data.splitlines()
+ data_lines.insert(0, "commit %s" % self.id)
+ temp = self._iter_from_process_or_stream(self.repo, iter(data_lines)).next()
self.parents = temp.parents
self.tree = temp.tree
self.author = temp.author
@@ -147,10 +150,10 @@ class Commit(base.Object, Iterable):
# the test system might confront us with string values -
proc = repo.git.rev_list(ref, '--', path, **options)
- return cls._iter_from_process(repo, proc)
+ return cls._iter_from_process_or_stream(repo, proc)
@classmethod
- def _iter_from_process(cls, repo, proc):
+ def _iter_from_process_or_stream(cls, repo, proc_or_stream):
"""
Parse out commit information into a list of Commit objects
@@ -163,7 +166,10 @@ class Commit(base.Object, Iterable):
Returns
iterator returning Commit objects
"""
- stream = proc.stdout
+ stream = proc_or_stream
+ if not hasattr(stream,'next'):
+ stream = proc_or_stream.stdout
+
for line in stream:
id = line.split()[1]
assert line.split()[0] == "commit"
diff --git a/lib/git/objects/tag.py b/lib/git/objects/tag.py
index 77d715c7..ecf6349d 100644
--- a/lib/git/objects/tag.py
+++ b/lib/git/objects/tag.py
@@ -49,8 +49,7 @@ class TagObject(base.Object):
Cache all our attributes at once
"""
if attr in TagObject.__slots__:
- output = self.repo.git.cat_file(self.type,self.id)
- lines = output.split("\n")
+ lines = self.data.splitlines()
obj, hexsha = lines[0].split(" ") # object <hexsha>
type_token, type_name = lines[1].split(" ") # type <type_name>
diff --git a/lib/git/refs.py b/lib/git/refs.py
index df914b78..9754f65d 100644
--- a/lib/git/refs.py
+++ b/lib/git/refs.py
@@ -38,8 +38,10 @@ class Ref(LazyMixin, Iterable):
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
- type_string = self.repo.git.cat_file(self.path, t=True).rstrip()
- self.object = get_object_type_by_name(type_string)(self.repo, self.path)
+ 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)
else:
super(Ref, self)._set_cache_(attr)
@@ -124,9 +126,14 @@ class Ref(LazyMixin, Iterable):
id: [0-9A-Fa-f]{40}
Returns git.Head """
full_path, hexsha, type_name, object_size = line.split("\x00")
- obj = get_object_type_by_name(type_name)(repo, hexsha)
- obj.size = object_size
- return cls(repo, full_path, obj)
+
+ # No, we keep the object dynamic by allowing it to be retrieved by
+ # our path on demand - due to perstent commands it is fast
+ return cls(repo, full_path)
+
+ # obj = get_object_type_by_name(type_name)(repo, hexsha)
+ # obj.size = object_size
+ # return cls(repo, full_path, obj)
class Head(Ref):