Skip to content

Commit

Permalink
Object: move to use an 'id' attribute instead of 'oid'
Browse files Browse the repository at this point in the history
This looks like a left-over from the libgit2 misnaming. The current
consensus is that 'oid' is the data type and 'id' is the name of the
attribute.
  • Loading branch information
carlosmn committed Jan 24, 2014
1 parent 3a83cb4 commit 500a679
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 28 deletions.
17 changes: 14 additions & 3 deletions src/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ Object_dealloc(Object* self)
}


PyDoc_STRVAR(Object_oid__doc__,
PyDoc_STRVAR(Object_id__doc__,
"The object id, an instance of the Oid type.");

PyObject *
Object_oid__get__(Object *self)
Object_id__get__(Object *self)
{
const git_oid *oid;

Expand All @@ -63,10 +63,20 @@ Object_oid__get__(Object *self)
return git_oid_to_python(oid);
}

PyDoc_STRVAR(Object_oid__doc__,
"The object id, an instance of the Oid type.\n"
"This attribute is deprecated, please use 'id'\n");

PyObject *
Object_oid__get__(Object *self)
{
return Object_id__get__(self);
}

PyDoc_STRVAR(Object_hex__doc__,
"Hexadecimal representation of the object id. This is a shortcut for\n"
"Object.oid.hex");
"Object.oid.hex\n"
"This attribute is deprecated, please use 'id'\n");

PyObject *
Object_hex__get__(Object *self)
Expand Down Expand Up @@ -119,6 +129,7 @@ Object_read_raw(Object *self)

PyGetSetDef Object_getseters[] = {
GETTER(Object, oid),
GETTER(Object, id),
GETTER(Object, hex),
GETTER(Object, type),
{NULL}
Expand Down
2 changes: 1 addition & 1 deletion test/test_blame.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_blame_newest(self):

for rev, num_commits in revs:
commit = repo.revparse_single(rev)
blame = repo.blame(PATH, newest_commit=commit.oid)
blame = repo.blame(PATH, newest_commit=commit.id)

self.assertEqual(len(blame), num_commits)

Expand Down
6 changes: 3 additions & 3 deletions test/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class BlobTest(utils.RepoTestCase):
def test_read_blob(self):
blob = self.repo[BLOB_SHA]
self.assertEqual(blob.hex, BLOB_SHA)
sha = blob.oid.hex
sha = blob.id.hex
self.assertEqual(sha, BLOB_SHA)
self.assertTrue(isinstance(blob, pygit2.Blob))
self.assertFalse(blob.is_binary)
Expand All @@ -66,7 +66,7 @@ def test_create_blob(self):
self.assertTrue(isinstance(blob, pygit2.Blob))
self.assertEqual(pygit2.GIT_OBJ_BLOB, blob.type)

self.assertEqual(blob_oid, blob.oid)
self.assertEqual(blob_oid, blob.id)
self.assertEqual(
utils.gen_blob_sha1(BLOB_NEW_CONTENT),
blob_oid.hex)
Expand All @@ -83,7 +83,7 @@ def test_create_blob_fromworkdir(self):
self.assertTrue(isinstance(blob, pygit2.Blob))
self.assertEqual(pygit2.GIT_OBJ_BLOB, blob.type)

self.assertEqual(blob_oid, blob.oid)
self.assertEqual(blob_oid, blob.id)
self.assertEqual(
utils.gen_blob_sha1(BLOB_FILE_CONTENT),
blob_oid.hex)
Expand Down
6 changes: 3 additions & 3 deletions test/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ class CommitTest(utils.BareRepoTestCase):

def test_read_commit(self):
commit = self.repo[COMMIT_SHA]
self.assertEqual(COMMIT_SHA, commit.hex)
self.assertEqual(COMMIT_SHA, str(commit.id))
parents = commit.parents
self.assertEqual(1, len(parents))
self.assertEqual('c2792cfa289ae6321ecf2cd5806c2194b0fd070c',
parents[0].hex)
str(parents[0].id))
self.assertEqual(None, commit.message_encoding)
self.assertEqual(('Second test data commit.\n\n'
'This commit has some additional text.\n'),
Expand All @@ -62,7 +62,7 @@ def test_read_commit(self):
Signature('Dave Borowitz', 'dborowitz@google.com', 1288477363,
-420))
self.assertEqual(
'967fce8df97cc71722d3c2a5930ef3e6f1d27b12', commit.tree.hex)
'967fce8df97cc71722d3c2a5930ef3e6f1d27b12', str(commit.tree.id))

def test_new_commit(self):
repo = self.repo
Expand Down
2 changes: 1 addition & 1 deletion test/test_refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def test_create_symbolic_reference(self):
def test_get_object(self):
repo = self.repo
ref = repo.lookup_reference('refs/heads/master')
self.assertEqual(repo[ref.target].oid, ref.get_object().oid)
self.assertEqual(repo[ref.target].id, ref.get_object().id)


if __name__ == '__main__':
Expand Down
12 changes: 6 additions & 6 deletions test/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,27 +199,27 @@ def test_push_fast_forward_commits_to_remote_succeeds(self):
tip = self.clone[self.clone.head.target]
oid = self.clone.create_commit(
'refs/heads/master', tip.author, tip.author, 'empty commit',
tip.tree.oid, [tip.oid]
tip.tree.id, [tip.id]
)
self.remote.push('refs/heads/master')
self.assertEqual(self.origin[self.origin.head.target].oid, oid)
self.assertEqual(self.origin[self.origin.head.target].id, oid)

def test_push_when_up_to_date_succeeds(self):
self.remote.push('refs/heads/master')
origin_tip = self.origin[self.origin.head.target].oid
clone_tip = self.clone[self.clone.head.target].oid
origin_tip = self.origin[self.origin.head.target].id
clone_tip = self.clone[self.clone.head.target].id
self.assertEqual(origin_tip, clone_tip)

def test_push_non_fast_forward_commits_to_remote_fails(self):
tip = self.origin[self.origin.head.target]
oid = self.origin.create_commit(
'refs/heads/master', tip.author, tip.author, 'some commit',
tip.tree.oid, [tip.oid]
tip.tree.id, [tip.id]
)
tip = self.clone[self.clone.head.target]
oid = self.clone.create_commit(
'refs/heads/master', tip.author, tip.author, 'other commit',
tip.tree.oid, [tip.oid]
tip.tree.id, [tip.id]
)
self.assertRaises(pygit2.GitError, self.remote.push, 'refs/heads/master')

Expand Down
10 changes: 5 additions & 5 deletions test/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def test_merge_none(self):

def test_merge_uptodate(self):
branch_head_hex = '5ebeeebb320790caf276b9fc8b24546d63316533'
branch_oid = self.repo.get(branch_head_hex).oid
branch_oid = self.repo.get(branch_head_hex).id
merge_result = self.repo.merge(branch_oid)
self.assertTrue(merge_result.is_uptodate)
self.assertFalse(merge_result.is_fastforward)
Expand All @@ -318,7 +318,7 @@ def test_merge_uptodate(self):

def test_merge_fastforward(self):
branch_head_hex = 'e97b4cfd5db0fb4ebabf4f203979ca4e5d1c7c87'
branch_oid = self.repo.get(branch_head_hex).oid
branch_oid = self.repo.get(branch_head_hex).id
merge_result = self.repo.merge(branch_oid)
self.assertFalse(merge_result.is_uptodate)
self.assertTrue(merge_result.is_fastforward)
Expand All @@ -329,7 +329,7 @@ def test_merge_fastforward(self):

def test_merge_no_fastforward_no_conflicts(self):
branch_head_hex = '03490f16b15a09913edb3a067a3dc67fbb8d41f1'
branch_oid = self.repo.get(branch_head_hex).oid
branch_oid = self.repo.get(branch_head_hex).id
merge_result = self.repo.merge(branch_oid)
self.assertFalse(merge_result.is_uptodate)
self.assertFalse(merge_result.is_fastforward)
Expand All @@ -345,7 +345,7 @@ def test_merge_no_fastforward_no_conflicts(self):

def test_merge_no_fastforward_conflicts(self):
branch_head_hex = '1b2bae55ac95a4be3f8983b86cd579226d0eb247'
branch_oid = self.repo.get(branch_head_hex).oid
branch_oid = self.repo.get(branch_head_hex).id
merge_result = self.repo.merge(branch_oid)
self.assertFalse(merge_result.is_uptodate)
self.assertFalse(merge_result.is_fastforward)
Expand All @@ -365,7 +365,7 @@ def test_merge_invalid_hex(self):

def test_merge_already_something_in_index(self):
branch_head_hex = '03490f16b15a09913edb3a067a3dc67fbb8d41f1'
branch_oid = self.repo.get(branch_head_hex).oid
branch_oid = self.repo.get(branch_head_hex).id
with open(os.path.join(self.repo.workdir, 'inindex.txt'), 'w') as f:
f.write('new content')
self.repo.index.add('inindex.txt')
Expand Down
2 changes: 1 addition & 1 deletion test/test_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_modify_tag(self):
def test_get_object(self):
repo = self.repo
tag = repo[TAG_SHA]
self.assertEqual(repo[tag.target].oid, tag.get_object().oid)
self.assertEqual(repo[tag.target].id, tag.get_object().id)


if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions test/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def test_new_tree(self):
self.assertEqual(x.filemode, 0o0100644)
self.assertEqual(y.filemode, 0o0100755)

self.assertEqual(repo[x.oid].oid, b0)
self.assertEqual(repo[y.oid].oid, b1)
self.assertEqual(repo[x.oid].id, b0)
self.assertEqual(repo[y.oid].id, b1)


def test_modify_tree(self):
Expand Down
6 changes: 3 additions & 3 deletions test/test_treebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_noop_treebuilder(self):
result = bld.write()

self.assertEqual(len(bld), len(tree))
self.assertEqual(tree.oid, result)
self.assertEqual(tree.id, result)


def test_noop_treebuilder_from_tree(self):
Expand All @@ -58,7 +58,7 @@ def test_noop_treebuilder_from_tree(self):
result = bld.write()

self.assertEqual(len(bld), len(tree))
self.assertEqual(tree.oid, result)
self.assertEqual(tree.id, result)


def test_rebuild_treebuilder(self):
Expand All @@ -72,7 +72,7 @@ def test_rebuild_treebuilder(self):
result = bld.write()

self.assertEqual(len(bld), len(tree))
self.assertEqual(tree.oid, result)
self.assertEqual(tree.id, result)


if __name__ == '__main__':
Expand Down

0 comments on commit 500a679

Please sign in to comment.