summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/git/index/base.py2
-rw-r--r--lib/git/objects/base.py5
-rw-r--r--lib/git/refs.py2
-rw-r--r--lib/git/remote.py2
-rw-r--r--lib/git/repo/base.py19
-rw-r--r--test/git/test_repo.py21
6 files changed, 28 insertions, 23 deletions
diff --git a/lib/git/index/base.py b/lib/git/index/base.py
index 4b3197a2..0f02352f 100644
--- a/lib/git/index/base.py
+++ b/lib/git/index/base.py
@@ -1122,7 +1122,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
# item. Handle existing -R flags properly. Transform strings to the object
# so that we can call diff on it
if isinstance(other, basestring):
- other = Object.new(self.repo, other)
+ other = self.repo.rev_parse(other)
# END object conversion
if isinstance(other, Object):
diff --git a/lib/git/objects/base.py b/lib/git/objects/base.py
index 21b9b1ea..41862ac2 100644
--- a/lib/git/objects/base.py
+++ b/lib/git/objects/base.py
@@ -49,10 +49,7 @@ class Object(LazyMixin):
:note: This cannot be a __new__ method as it would always call __init__
with the input id which is not necessarily a binsha."""
- hexsha, typename, size = repo.git.get_object_header(id)
- inst = get_object_type_by_name(typename)(repo, hex_to_bin(hexsha))
- inst.size = size
- return inst
+ return repo.rev_parse(str(id))
@classmethod
def new_from_sha(cls, repo, sha1):
diff --git a/lib/git/refs.py b/lib/git/refs.py
index be094d01..03b80690 100644
--- a/lib/git/refs.py
+++ b/lib/git/refs.py
@@ -345,7 +345,7 @@ class SymbolicReference(object):
# figure out target data
target = reference
if resolve:
- target = Object.new(repo, reference)
+ target = repo.rev_parse(str(reference))
if not force and isfile(abs_ref_path):
target_data = str(target)
diff --git a/lib/git/remote.py b/lib/git/remote.py
index 1598e55a..801dcd62 100644
--- a/lib/git/remote.py
+++ b/lib/git/remote.py
@@ -391,7 +391,7 @@ class FetchInfo(object):
split_token = '...'
if control_character == ' ':
split_token = split_token[:-1]
- old_commit = Commit.new(repo, operation.split(split_token)[0])
+ old_commit = repo.rev_parse(operation.split(split_token)[0])
# END handle refspec
# END reference flag handling
diff --git a/lib/git/repo/base.py b/lib/git/repo/base.py
index e659225e..ed805991 100644
--- a/lib/git/repo/base.py
+++ b/lib/git/repo/base.py
@@ -323,11 +323,9 @@ class Repo(object):
:param rev: revision specifier, see git-rev-parse for viable options.
:return: ``git.Commit``"""
if rev is None:
- rev = self.active_branch
-
- c = Object.new(self, rev)
- assert c.type == "commit", "Revision %s did not point to a commit, but to %s" % (rev, c)
- return c
+ return self.active_branch.commit
+ else:
+ return self.rev_parse(str(rev)+"^0")
def iter_trees(self, *args, **kwargs):
""":return: Iterator yielding Tree objects
@@ -348,14 +346,9 @@ class Repo(object):
it cannot know about its path relative to the repository root and subsequent
operations might have unexpected results."""
if rev is None:
- rev = self.active_branch
-
- c = Object.new(self, rev)
- if c.type == "commit":
- return c.tree
- elif c.type == "tree":
- return c
- raise ValueError( "Revision %s did not point to a treeish, but to %s" % (rev, c))
+ return self.active_branch.commit.tree
+ else:
+ return self.rev_parse(str(rev)+"^{tree}")
def iter_commits(self, rev=None, paths='', **kwargs):
"""A list of Commit objects representing the history of a given ref/commit
diff --git a/test/git/test_repo.py b/test/git/test_repo.py
index 5f663d6f..53829556 100644
--- a/test/git/test_repo.py
+++ b/test/git/test_repo.py
@@ -7,7 +7,7 @@ from test.testlib import *
from git import *
from git.util import join_path_native
from git.exc import BadObject
-from gitdb.util import hex_to_bin
+from gitdb.util import hex_to_bin, bin_to_hex
import os, sys
import tempfile
@@ -57,7 +57,12 @@ class TestRepo(TestBase):
assert self.rorepo.tree(tree) == tree
# try from invalid revision that does not exist
- self.failUnlessRaises(ValueError, self.rorepo.tree, 'hello world')
+ self.failUnlessRaises(BadObject, self.rorepo.tree, 'hello world')
+
+ def test_commit_from_revision(self):
+ commit = self.rorepo.commit('0.1.4')
+ assert commit.type == 'commit'
+ assert self.rorepo.commit(commit) == commit
def test_commits(self):
mc = 10
@@ -445,7 +450,7 @@ class TestRepo(TestBase):
rev_parse = self.rorepo.rev_parse
# try special case: This one failed beforehand
- assert self.rorepo.odb.partial_to_complete_sha_hex("33ebe") == hex_to_bin("33ebe7acec14b25c5f84f35a664803fcab2f7781")
+ assert rev_parse("33ebe").hexsha == "33ebe7acec14b25c5f84f35a664803fcab2f7781"
# start from reference
num_resolved = 0
@@ -507,6 +512,16 @@ class TestRepo(TestBase):
assert tag.object == rev_parse('0.1.4%s' % token)
# END handle multiple tokens
+ # try partial parsing
+ max_items = 40
+ for i, binsha in enumerate(self.rorepo.odb.sha_iter()):
+ assert rev_parse(bin_to_hex(binsha)[:8-(i%2)]).binsha == binsha
+ if i > max_items:
+ # this is rather slow currently, as rev_parse returns an object
+ # which requires accessing packs, it has some additional overhead
+ break
+ # END for each binsha in repo
+
# missing closing brace commit^{tree
self.failUnlessRaises(ValueError, rev_parse, '0.1.4^{tree')