summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO13
-rw-r--r--lib/git/diff.py4
-rw-r--r--lib/git/index.py4
-rw-r--r--lib/git/objects/base.py34
-rw-r--r--lib/git/objects/blob.py2
-rw-r--r--lib/git/objects/commit.py26
-rw-r--r--lib/git/objects/tag.py6
-rw-r--r--lib/git/objects/tree.py6
-rw-r--r--lib/git/refs.py8
-rw-r--r--lib/git/repo.py2
-rw-r--r--test/git/test_base.py4
-rw-r--r--test/git/test_blob.py6
-rw-r--r--test/git/test_commit.py16
-rw-r--r--test/git/test_index.py2
-rw-r--r--test/git/test_repo.py10
-rw-r--r--test/git/test_tree.py2
16 files changed, 69 insertions, 76 deletions
diff --git a/TODO b/TODO
index e77ba340..5fa2477d 100644
--- a/TODO
+++ b/TODO
@@ -27,15 +27,6 @@ Object
It would be good to improve things there as cat-file keeps all the data in a buffer
before it writes it. Hence it does not write to a stream directly, which can be
bad if files are large, say 1GB :).
-* Effectively Objects only store hexsha's in their id attributes, so in fact
- it should be renamed to 'sha'. There was a time when references where allowed as
- well, but now objects will be 'baked' to the actual sha to assure comparisons work.
-
-Commit
-------
-* message is stipped during parsing, which is wrong unless we parse from
- rev-list output. In fact we don't know that, and can't really tell either.
- Currently we strip away white space that might actually belong to the message
Config
------
@@ -115,7 +106,9 @@ Repo
* Blame: Read the blame format making assumptions about its structure,
currently regex are used a lot although we can deduct what will be next.
- Read data from a stream directly from git command
-* Figure out how to implement a proper merge API
+* Figure out how to implement a proper merge API. It should be index based, but provide
+ all necessary information to the ones willing to ask for it. The index implementation
+ actually provides this already, but some real use-cases would be great to have a least.
* repo.checkout should be added that does everything HEAD.reset does, but in addition
it allows to checkout heads beforehand, hence its more like a repo.head.reference = other_head.
diff --git a/lib/git/diff.py b/lib/git/diff.py
index b0e0898a..9a826630 100644
--- a/lib/git/diff.py
+++ b/lib/git/diff.py
@@ -186,11 +186,11 @@ class Diff(object):
if not a_blob_id or self.re_is_null_hexsha.search(a_blob_id):
self.a_blob = None
else:
- self.a_blob = blob.Blob(repo, id=a_blob_id, mode=a_mode, path=a_path)
+ self.a_blob = blob.Blob(repo, a_blob_id, mode=a_mode, path=a_path)
if not b_blob_id or self.re_is_null_hexsha.search(b_blob_id):
self.b_blob = None
else:
- self.b_blob = blob.Blob(repo, id=b_blob_id, mode=b_mode, path=b_path)
+ self.b_blob = blob.Blob(repo, b_blob_id, mode=b_mode, path=b_path)
self.a_mode = a_mode
self.b_mode = b_mode
diff --git a/lib/git/index.py b/lib/git/index.py
index cc3f3a4e..705b1ae7 100644
--- a/lib/git/index.py
+++ b/lib/git/index.py
@@ -92,7 +92,7 @@ class BaseIndexEntry(tuple):
Returns
Fully equipped BaseIndexEntry at the given stage
"""
- return cls((blob.mode, blob.id, stage, blob.path))
+ return cls((blob.mode, blob.sha, stage, blob.path))
class IndexEntry(BaseIndexEntry):
@@ -165,7 +165,7 @@ class IndexEntry(BaseIndexEntry):
Minimal entry resembling the given blob objecft
"""
time = struct.pack(">LL", 0, 0)
- return IndexEntry((blob.mode, blob.id, 0, blob.path, time, time, 0, 0, 0, 0, blob.size))
+ return IndexEntry((blob.mode, blob.sha, 0, blob.path, time, time, 0, 0, 0, 0, blob.size))
def clear_cache(func):
diff --git a/lib/git/objects/base.py b/lib/git/objects/base.py
index 0bece6f1..6dd03ba4 100644
--- a/lib/git/objects/base.py
+++ b/lib/git/objects/base.py
@@ -16,13 +16,13 @@ class Object(LazyMixin):
This Object also serves as a constructor for instances of the correct type::
inst = Object.new(repo,id)
- inst.id # objects sha in hex
+ inst.sha # objects sha in hex
inst.size # objects uncompressed data size
inst.data # byte string containing the whole data of the object
"""
NULL_HEX_SHA = '0'*40
TYPES = ("blob", "tree", "commit", "tag")
- __slots__ = ("repo", "id", "size", "data" )
+ __slots__ = ("repo", "sha", "size", "data" )
type = None # to be set by subclass
def __init__(self, repo, id):
@@ -38,7 +38,7 @@ class Object(LazyMixin):
"""
super(Object,self).__init__()
self.repo = repo
- self.id = id
+ self.sha = id
@classmethod
def new(cls, repo, id):
@@ -76,11 +76,11 @@ class Object(LazyMixin):
Retrieve object information
"""
if attr == "size":
- hexsha, typename, self.size = self.repo.git.get_object_header(self.id)
- assert typename == self.type, _assertion_msg_format % (self.id, typename, self.type)
+ hexsha, typename, self.size = self.repo.git.get_object_header(self.sha)
+ assert typename == self.type, _assertion_msg_format % (self.sha, typename, self.type)
elif attr == "data":
- hexsha, typename, self.size, self.data = self.repo.git.get_object_data(self.id)
- assert typename == self.type, _assertion_msg_format % (self.id, typename, self.type)
+ hexsha, typename, self.size, self.data = self.repo.git.get_object_data(self.sha)
+ assert typename == self.type, _assertion_msg_format % (self.sha, typename, self.type)
else:
super(Object,self)._set_cache_(attr)
@@ -89,35 +89,35 @@ class Object(LazyMixin):
Returns
True if the objects have the same SHA1
"""
- return self.id == other.id
+ return self.sha == other.sha
def __ne__(self, other):
"""
Returns
True if the objects do not have the same SHA1
"""
- return self.id != other.id
+ return self.sha != other.sha
def __hash__(self):
"""
Returns
Hash of our id allowing objects to be used in dicts and sets
"""
- return hash(self.id)
+ return hash(self.sha)
def __str__(self):
"""
Returns
string of our SHA1 as understood by all git commands
"""
- return self.id
+ return self.sha
def __repr__(self):
"""
Returns
string with pythonic representation of our object
"""
- return '<git.%s "%s">' % (self.__class__.__name__, self.id)
+ return '<git.%s "%s">' % (self.__class__.__name__, self.sha)
@property
def data_stream(self):
@@ -125,7 +125,7 @@ class Object(LazyMixin):
Returns
File Object compatible stream to the uncompressed raw data of the object
"""
- proc = self.repo.git.cat_file(self.type, self.id, as_process=True)
+ proc = self.repo.git.cat_file(self.type, self.sha, as_process=True)
return utils.ProcessStreamAdapter(proc, "stdout")
def stream_data(self, ostream):
@@ -138,7 +138,7 @@ class Object(LazyMixin):
Returns
self
"""
- self.repo.git.cat_file(self.type, self.id, output_stream=ostream)
+ self.repo.git.cat_file(self.type, self.sha, output_stream=ostream)
return self
class IndexObject(Object):
@@ -148,13 +148,13 @@ class IndexObject(Object):
"""
__slots__ = ("path", "mode")
- def __init__(self, repo, id, mode=None, path=None):
+ def __init__(self, repo, sha, mode=None, path=None):
"""
Initialize a newly instanced IndexObject
``repo``
is the Repo we are located in
- ``id`` : string
+ ``sha`` : string
is the git object id as hex sha
``mode`` : int
@@ -168,7 +168,7 @@ class IndexObject(Object):
Path may not be set of the index object has been created directly as it cannot
be retrieved without knowing the parent tree.
"""
- super(IndexObject, self).__init__(repo, id)
+ super(IndexObject, self).__init__(repo, sha)
self._set_self_from_args_(locals())
if isinstance(mode, basestring):
self.mode = self._mode_str_to_int(mode)
diff --git a/lib/git/objects/blob.py b/lib/git/objects/blob.py
index 88ca73d6..11dee323 100644
--- a/lib/git/objects/blob.py
+++ b/lib/git/objects/blob.py
@@ -33,4 +33,4 @@ class Blob(base.IndexObject):
def __repr__(self):
- return '<git.Blob "%s">' % self.id
+ return '<git.Blob "%s">' % self.sha
diff --git a/lib/git/objects/commit.py b/lib/git/objects/commit.py
index d9f87116..80b3ad23 100644
--- a/lib/git/objects/commit.py
+++ b/lib/git/objects/commit.py
@@ -23,9 +23,9 @@ class Commit(base.Object, Iterable, diff.Diffable):
type = "commit"
__slots__ = ("tree", "author", "authored_date", "committer", "committed_date",
"message", "parents")
- _id_attribute_ = "id"
+ _id_attribute_ = "sha"
- def __init__(self, repo, id, tree=None, author=None, authored_date=None,
+ def __init__(self, repo, sha, tree=None, author=None, authored_date=None,
committer=None, committed_date=None, message=None, parents=None):
"""
Instantiate a new Commit. All keyword arguments taking None as default will
@@ -33,7 +33,7 @@ class Commit(base.Object, Iterable, diff.Diffable):
The parameter documentation indicates the type of the argument after a colon ':'.
- ``id``
+ ``sha``
is the sha id of the commit or a ref
``parents`` : tuple( Commit, ... )
@@ -62,15 +62,15 @@ class Commit(base.Object, Iterable, diff.Diffable):
Returns
git.Commit
"""
- super(Commit,self).__init__(repo, id)
+ super(Commit,self).__init__(repo, sha)
self._set_self_from_args_(locals())
if parents is not None:
self.parents = tuple( self.__class__(repo, p) for p in parents )
# END for each parent to convert
- if self.id and tree is not None:
- self.tree = Tree(repo, id=tree, path='')
+ if self.sha and tree is not None:
+ self.tree = Tree(repo, tree, path='')
# END id to tree conversion
def _set_cache_(self, attr):
@@ -82,7 +82,7 @@ class Commit(base.Object, Iterable, diff.Diffable):
if attr in Commit.__slots__:
# prepare our data lines to match rev-list
data_lines = self.data.splitlines()
- data_lines.insert(0, "commit %s" % self.id)
+ data_lines.insert(0, "commit %s" % self.sha)
temp = self._iter_from_process_or_stream(self.repo, iter(data_lines), False).next()
self.parents = temp.parents
self.tree = temp.tree
@@ -116,7 +116,7 @@ class Commit(base.Object, Iterable, diff.Diffable):
Returns
int
"""
- return len(self.repo.git.rev_list(self.id, '--', paths, **kwargs).strip().splitlines())
+ return len(self.repo.git.rev_list(self.sha, '--', paths, **kwargs).strip().splitlines())
@property
def name_rev(self):
@@ -189,14 +189,14 @@ class Commit(base.Object, Iterable, diff.Diffable):
git.Stats
"""
if not self.parents:
- text = self.repo.git.diff_tree(self.id, '--', numstat=True, root=True)
+ text = self.repo.git.diff_tree(self.sha, '--', numstat=True, root=True)
text2 = ""
for line in text.splitlines()[1:]:
(insertions, deletions, filename) = line.split("\t")
text2 += "%s\t%s\t%s\n" % (insertions, deletions, filename)
text = text2
else:
- text = self.repo.git.diff(self.parents[0].id, self.id, '--', numstat=True)
+ text = self.repo.git.diff(self.parents[0].sha, self.sha, '--', numstat=True)
return stats.Stats._list_from_string(self.repo, text)
@classmethod
@@ -259,15 +259,15 @@ class Commit(base.Object, Iterable, diff.Diffable):
# END message parsing
message = '\n'.join(message_lines)
- yield Commit(repo, id=id, parents=tuple(parents), tree=tree, author=author, authored_date=authored_date,
+ yield Commit(repo, id, parents=tuple(parents), tree=tree, author=author, authored_date=authored_date,
committer=committer, committed_date=committed_date, message=message)
# END for each line in stream
def __str__(self):
""" Convert commit to string which is SHA1 """
- return self.id
+ return self.sha
def __repr__(self):
- return '<git.Commit "%s">' % self.id
+ return '<git.Commit "%s">' % self.sha
diff --git a/lib/git/objects/tag.py b/lib/git/objects/tag.py
index b2140551..c329edf7 100644
--- a/lib/git/objects/tag.py
+++ b/lib/git/objects/tag.py
@@ -17,7 +17,7 @@ class TagObject(base.Object):
type = "tag"
__slots__ = ( "object", "tag", "tagger", "tagged_date", "message" )
- def __init__(self, repo, id, object=None, tag=None,
+ def __init__(self, repo, sha, object=None, tag=None,
tagger=None, tagged_date=None, message=None):
"""
Initialize a tag object with additional data
@@ -25,7 +25,7 @@ class TagObject(base.Object):
``repo``
repository this object is located in
- ``id``
+ ``sha``
SHA1 or ref suitable for git-rev-parse
``object``
@@ -41,7 +41,7 @@ class TagObject(base.Object):
is the DateTime of the tag creation - use time.gmtime to convert
it into a different format
"""
- super(TagObject, self).__init__(repo, id )
+ super(TagObject, self).__init__(repo, sha )
self._set_self_from_args_(locals())
def _set_cache_(self, attr):
diff --git a/lib/git/objects/tree.py b/lib/git/objects/tree.py
index 371c0dd3..413efdb8 100644
--- a/lib/git/objects/tree.py
+++ b/lib/git/objects/tree.py
@@ -43,8 +43,8 @@ class Tree(base.IndexObject, diff.Diffable):
tree_id = 040
- def __init__(self, repo, id, mode=0, path=None):
- super(Tree, self).__init__(repo, id, mode, path)
+ def __init__(self, repo, sha, mode=0, path=None):
+ super(Tree, self).__init__(repo, sha, mode, path)
def _set_cache_(self, attr):
if attr == "_cache":
@@ -150,7 +150,7 @@ class Tree(base.IndexObject, diff.Diffable):
def __repr__(self):
- return '<git.Tree "%s">' % self.id
+ return '<git.Tree "%s">' % self.sha
@classmethod
def _iter_recursive(cls, repo, tree, cur_depth, max_depth, predicate, prune ):
diff --git a/lib/git/refs.py b/lib/git/refs.py
index ddf98fc7..84347057 100644
--- a/lib/git/refs.py
+++ b/lib/git/refs.py
@@ -312,17 +312,17 @@ class SymbolicReference(object):
if isinstance(ref, Head):
write_value = "ref: %s" % ref.path
elif isinstance(ref, Commit):
- write_value = ref.id
+ write_value = ref.sha
else:
try:
- write_value = ref.commit.id
+ write_value = ref.commit.sha
except AttributeError:
sha = str(ref)
try:
obj = Object.new(self.repo, sha)
if obj.type != "commit":
raise TypeError("Invalid object type behind sha: %s" % sha)
- write_value = obj.id
+ write_value = obj.sha
except Exception:
raise ValueError("Could not extract object from %s" % ref)
# END end try string
@@ -428,7 +428,7 @@ class Head(Reference):
>>> head.commit
<git.Commit "1c09f116cbc2cb4100fb6935bb162daa4723f455">
- >>> head.commit.id
+ >>> head.commit.sha
'1c09f116cbc2cb4100fb6935bb162daa4723f455'
"""
_common_path_default = "refs/heads"
diff --git a/lib/git/repo.py b/lib/git/repo.py
index 9c3db055..41484aa0 100644
--- a/lib/git/repo.py
+++ b/lib/git/repo.py
@@ -622,7 +622,7 @@ class Repo(object):
sha = info['id']
c = commits.get(sha)
if c is None:
- c = Commit( self, id=sha,
+ c = Commit( self, sha,
author=Actor._from_string(info['author'] + ' ' + info['author_email']),
authored_date=info['author_date'],
committer=Actor._from_string(info['committer'] + ' ' + info['committer_email']),
diff --git a/test/git/test_base.py b/test/git/test_base.py
index 1b78786a..497f90fb 100644
--- a/test/git/test_base.py
+++ b/test/git/test_base.py
@@ -32,13 +32,13 @@ class TestBase(TestBase):
for obj_type, (typename, hexsha) in zip(types, self.type_tuples):
item = obj_type(self.rorepo,hexsha)
num_objs += 1
- assert item.id == hexsha
+ assert item.sha == hexsha
assert item.type == typename
assert item.size
assert item.data
assert item == item
assert not item != item
- assert str(item) == item.id
+ assert str(item) == item.sha
assert repr(item)
s.add(item)
diff --git a/test/git/test_blob.py b/test/git/test_blob.py
index 1b3b68f8..464cfd6b 100644
--- a/test/git/test_blob.py
+++ b/test/git/test_blob.py
@@ -18,13 +18,13 @@ class TestBlob(TestBase):
blob.size
def test_mime_type_should_return_mime_type_for_known_types(self):
- blob = Blob(self.rorepo, **{'id': 'abc', 'path': 'foo.png'})
+ blob = Blob(self.rorepo, **{'sha': 'abc', 'path': 'foo.png'})
assert_equal("image/png", blob.mime_type)
def test_mime_type_should_return_text_plain_for_unknown_types(self):
- blob = Blob(self.rorepo, **{'id': 'abc','path': 'something'})
+ blob = Blob(self.rorepo, **{'sha': 'abc','path': 'something'})
assert_equal("text/plain", blob.mime_type)
def test_should_return_appropriate_representation(self):
- blob = Blob(self.rorepo, **{'id': 'abc'})
+ blob = Blob(self.rorepo, **{'sha': 'abc'})
assert_equal('<git.Blob "abc">', repr(blob))
diff --git a/test/git/test_commit.py b/test/git/test_commit.py
index af952ed1..be6d1a28 100644
--- a/test/git/test_commit.py
+++ b/test/git/test_commit.py
@@ -11,7 +11,7 @@ class TestCommit(TestBase):
def test_bake(self):
- commit = Commit(self.rorepo, **{'id': '2454ae89983a4496a445ce347d7a41c0bb0ea7ae'})
+ commit = Commit(self.rorepo, **{'sha': '2454ae89983a4496a445ce347d7a41c0bb0ea7ae'})
commit.author # bake
assert_equal("Sebastian Thiel", commit.author.name)
@@ -22,7 +22,7 @@ class TestCommit(TestBase):
def test_stats(self):
- commit = Commit(self.rorepo, id='33ebe7acec14b25c5f84f35a664803fcab2f7781')
+ commit = Commit(self.rorepo, '33ebe7acec14b25c5f84f35a664803fcab2f7781')
stats = commit.stats
def check_entries(d):
@@ -72,7 +72,7 @@ class TestCommit(TestBase):
'c231551328faa864848bde6ff8127f59c9566e90',
)
for sha1, commit in zip(expected_ids, commits):
- assert_equal(sha1, commit.id)
+ assert_equal(sha1, commit.sha)
def test_count(self):
assert self.rorepo.tag('refs/tags/0.1.5').commit.count( ) == 141
@@ -81,17 +81,17 @@ class TestCommit(TestBase):
assert isinstance(Commit.list_items(self.rorepo, '0.1.5', max_count=5)['5117c9c8a4d3af19a9958677e45cda9269de1541'], Commit)
def test_str(self):
- commit = Commit(self.rorepo, id='abc')
+ commit = Commit(self.rorepo, 'abc')
assert_equal ("abc", str(commit))
def test_repr(self):
- commit = Commit(self.rorepo, id='abc')
+ commit = Commit(self.rorepo, 'abc')
assert_equal('<git.Commit "abc">', repr(commit))
def test_equality(self):
- commit1 = Commit(self.rorepo, id='abc')
- commit2 = Commit(self.rorepo, id='abc')
- commit3 = Commit(self.rorepo, id='zyx')
+ commit1 = Commit(self.rorepo, 'abc')
+ commit2 = Commit(self.rorepo, 'abc')
+ commit3 = Commit(self.rorepo, 'zyx')
assert_equal(commit1, commit2)
assert_not_equal(commit2, commit3)
diff --git a/test/git/test_index.py b/test/git/test_index.py
index 3345949b..e9541232 100644
--- a/test/git/test_index.py
+++ b/test/git/test_index.py
@@ -309,7 +309,7 @@ class TestTree(TestBase):
# blob from older revision overrides current index revision
old_blob = new_commit.parents[0].tree.blobs[0]
entries = index.reset(new_commit).add([old_blob])
- assert index.entries[(old_blob.path,0)].sha == old_blob.id and len(entries) == 1
+ assert index.entries[(old_blob.path,0)].sha == old_blob.sha and len(entries) == 1
# mode 0 not allowed
null_sha = "0"*40
diff --git a/test/git/test_repo.py b/test/git/test_repo.py
index 146cff1a..df495e71 100644
--- a/test/git/test_repo.py
+++ b/test/git/test_repo.py
@@ -46,9 +46,9 @@ class TestRepo(TestBase):
commits = list( self.rorepo.iter_commits('master', max_count=10) )
c = commits[0]
- assert_equal('4c8124ffcf4039d292442eeccabdeca5af5c5017', c.id)
- assert_equal(["634396b2f541a9f2d58b00be1a07f0c358b999b3"], [p.id for p in c.parents])
- assert_equal("672eca9b7f9e09c22dcb128c283e8c3c8d7697a4", c.tree.id)
+ assert_equal('4c8124ffcf4039d292442eeccabdeca5af5c5017', c.sha)
+ assert_equal(["634396b2f541a9f2d58b00be1a07f0c358b999b3"], [p.sha for p in c.parents])
+ assert_equal("672eca9b7f9e09c22dcb128c283e8c3c8d7697a4", c.tree.sha)
assert_equal("Tom Preston-Werner", c.author.name)
assert_equal("tom@mojombo.com", c.author.email)
assert_equal(1191999972, c.authored_date)
@@ -61,7 +61,7 @@ class TestRepo(TestBase):
assert_equal(tuple(), c.parents)
c = commits[2]
- assert_equal(["6e64c55896aabb9a7d8e9f8f296f426d21a78c2c", "7f874954efb9ba35210445be456c74e037ba6af2"], map(lambda p: p.id, c.parents))
+ assert_equal(["6e64c55896aabb9a7d8e9f8f296f426d21a78c2c", "7f874954efb9ba35210445be456c74e037ba6af2"], map(lambda p: p.sha, c.parents))
assert_equal("Merge branch 'site'", c.summary)
assert_true(git.called)
@@ -195,7 +195,7 @@ class TestRepo(TestBase):
assert_true(git.called)
assert_equal(git.call_args, (('blame', 'master', '--', 'lib/git.py'), {'p': True}))
- assert_equal('634396b2f541a9f2d58b00be1a07f0c358b999b3', c.id)
+ assert_equal('634396b2f541a9f2d58b00be1a07f0c358b999b3', c.sha)
assert_equal('Tom Preston-Werner', c.author.name)
assert_equal('tom@mojombo.com', c.author.email)
assert_equal(1191997100, c.authored_date)
diff --git a/test/git/test_tree.py b/test/git/test_tree.py
index b359e2d2..64a7900a 100644
--- a/test/git/test_tree.py
+++ b/test/git/test_tree.py
@@ -45,5 +45,5 @@ class TestTree(TestCase):
assert len(set(b for b in root if isinstance(b, Blob)) | set(root.blobs)) == len( root.blobs )
def test_repr(self):
- tree = Tree(self.repo, id='abc')
+ tree = Tree(self.repo, 'abc')
assert_equal('<git.Tree "abc">', repr(tree))