Object: move to use an 'id' attribute instead of 'oid'

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.
This commit is contained in:
Carlos Martín Nieto
2014-01-24 10:46:55 +01:00
parent 3a83cb44b6
commit 500a6793c4
10 changed files with 39 additions and 28 deletions

View File

@@ -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."); "The object id, an instance of the Oid type.");
PyObject * PyObject *
Object_oid__get__(Object *self) Object_id__get__(Object *self)
{ {
const git_oid *oid; const git_oid *oid;
@@ -63,10 +63,20 @@ Object_oid__get__(Object *self)
return git_oid_to_python(oid); 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__, PyDoc_STRVAR(Object_hex__doc__,
"Hexadecimal representation of the object id. This is a shortcut for\n" "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 * PyObject *
Object_hex__get__(Object *self) Object_hex__get__(Object *self)
@@ -119,6 +129,7 @@ Object_read_raw(Object *self)
PyGetSetDef Object_getseters[] = { PyGetSetDef Object_getseters[] = {
GETTER(Object, oid), GETTER(Object, oid),
GETTER(Object, id),
GETTER(Object, hex), GETTER(Object, hex),
GETTER(Object, type), GETTER(Object, type),
{NULL} {NULL}

View File

@@ -122,7 +122,7 @@ class BlameTest(utils.RepoTestCase):
for rev, num_commits in revs: for rev, num_commits in revs:
commit = repo.revparse_single(rev) 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) self.assertEqual(len(blame), num_commits)

View File

@@ -50,7 +50,7 @@ class BlobTest(utils.RepoTestCase):
def test_read_blob(self): def test_read_blob(self):
blob = self.repo[BLOB_SHA] blob = self.repo[BLOB_SHA]
self.assertEqual(blob.hex, BLOB_SHA) self.assertEqual(blob.hex, BLOB_SHA)
sha = blob.oid.hex sha = blob.id.hex
self.assertEqual(sha, BLOB_SHA) self.assertEqual(sha, BLOB_SHA)
self.assertTrue(isinstance(blob, pygit2.Blob)) self.assertTrue(isinstance(blob, pygit2.Blob))
self.assertFalse(blob.is_binary) self.assertFalse(blob.is_binary)
@@ -66,7 +66,7 @@ class BlobTest(utils.RepoTestCase):
self.assertTrue(isinstance(blob, pygit2.Blob)) self.assertTrue(isinstance(blob, pygit2.Blob))
self.assertEqual(pygit2.GIT_OBJ_BLOB, blob.type) self.assertEqual(pygit2.GIT_OBJ_BLOB, blob.type)
self.assertEqual(blob_oid, blob.oid) self.assertEqual(blob_oid, blob.id)
self.assertEqual( self.assertEqual(
utils.gen_blob_sha1(BLOB_NEW_CONTENT), utils.gen_blob_sha1(BLOB_NEW_CONTENT),
blob_oid.hex) blob_oid.hex)
@@ -83,7 +83,7 @@ class BlobTest(utils.RepoTestCase):
self.assertTrue(isinstance(blob, pygit2.Blob)) self.assertTrue(isinstance(blob, pygit2.Blob))
self.assertEqual(pygit2.GIT_OBJ_BLOB, blob.type) self.assertEqual(pygit2.GIT_OBJ_BLOB, blob.type)
self.assertEqual(blob_oid, blob.oid) self.assertEqual(blob_oid, blob.id)
self.assertEqual( self.assertEqual(
utils.gen_blob_sha1(BLOB_FILE_CONTENT), utils.gen_blob_sha1(BLOB_FILE_CONTENT),
blob_oid.hex) blob_oid.hex)

View File

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

View File

@@ -213,7 +213,7 @@ class ReferencesTest(utils.RepoTestCase):
def test_get_object(self): def test_get_object(self):
repo = self.repo repo = self.repo
ref = repo.lookup_reference('refs/heads/master') 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__': if __name__ == '__main__':

View File

@@ -199,27 +199,27 @@ class PushTestCase(unittest.TestCase):
tip = self.clone[self.clone.head.target] tip = self.clone[self.clone.head.target]
oid = self.clone.create_commit( oid = self.clone.create_commit(
'refs/heads/master', tip.author, tip.author, 'empty 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.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): def test_push_when_up_to_date_succeeds(self):
self.remote.push('refs/heads/master') self.remote.push('refs/heads/master')
origin_tip = self.origin[self.origin.head.target].oid origin_tip = self.origin[self.origin.head.target].id
clone_tip = self.clone[self.clone.head.target].oid clone_tip = self.clone[self.clone.head.target].id
self.assertEqual(origin_tip, clone_tip) self.assertEqual(origin_tip, clone_tip)
def test_push_non_fast_forward_commits_to_remote_fails(self): def test_push_non_fast_forward_commits_to_remote_fails(self):
tip = self.origin[self.origin.head.target] tip = self.origin[self.origin.head.target]
oid = self.origin.create_commit( oid = self.origin.create_commit(
'refs/heads/master', tip.author, tip.author, 'some 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] tip = self.clone[self.clone.head.target]
oid = self.clone.create_commit( oid = self.clone.create_commit(
'refs/heads/master', tip.author, tip.author, 'other 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') self.assertRaises(pygit2.GitError, self.remote.push, 'refs/heads/master')

View File

@@ -309,7 +309,7 @@ class RepositoryTest_III(utils.RepoTestCaseForMerging):
def test_merge_uptodate(self): def test_merge_uptodate(self):
branch_head_hex = '5ebeeebb320790caf276b9fc8b24546d63316533' 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) merge_result = self.repo.merge(branch_oid)
self.assertTrue(merge_result.is_uptodate) self.assertTrue(merge_result.is_uptodate)
self.assertFalse(merge_result.is_fastforward) self.assertFalse(merge_result.is_fastforward)
@@ -318,7 +318,7 @@ class RepositoryTest_III(utils.RepoTestCaseForMerging):
def test_merge_fastforward(self): def test_merge_fastforward(self):
branch_head_hex = 'e97b4cfd5db0fb4ebabf4f203979ca4e5d1c7c87' 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) merge_result = self.repo.merge(branch_oid)
self.assertFalse(merge_result.is_uptodate) self.assertFalse(merge_result.is_uptodate)
self.assertTrue(merge_result.is_fastforward) self.assertTrue(merge_result.is_fastforward)
@@ -329,7 +329,7 @@ class RepositoryTest_III(utils.RepoTestCaseForMerging):
def test_merge_no_fastforward_no_conflicts(self): def test_merge_no_fastforward_no_conflicts(self):
branch_head_hex = '03490f16b15a09913edb3a067a3dc67fbb8d41f1' 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) merge_result = self.repo.merge(branch_oid)
self.assertFalse(merge_result.is_uptodate) self.assertFalse(merge_result.is_uptodate)
self.assertFalse(merge_result.is_fastforward) self.assertFalse(merge_result.is_fastforward)
@@ -345,7 +345,7 @@ class RepositoryTest_III(utils.RepoTestCaseForMerging):
def test_merge_no_fastforward_conflicts(self): def test_merge_no_fastforward_conflicts(self):
branch_head_hex = '1b2bae55ac95a4be3f8983b86cd579226d0eb247' 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) merge_result = self.repo.merge(branch_oid)
self.assertFalse(merge_result.is_uptodate) self.assertFalse(merge_result.is_uptodate)
self.assertFalse(merge_result.is_fastforward) self.assertFalse(merge_result.is_fastforward)
@@ -365,7 +365,7 @@ class RepositoryTest_III(utils.RepoTestCaseForMerging):
def test_merge_already_something_in_index(self): def test_merge_already_something_in_index(self):
branch_head_hex = '03490f16b15a09913edb3a067a3dc67fbb8d41f1' 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: with open(os.path.join(self.repo.workdir, 'inindex.txt'), 'w') as f:
f.write('new content') f.write('new content')
self.repo.index.add('inindex.txt') self.repo.index.add('inindex.txt')

View File

@@ -92,7 +92,7 @@ class TagTest(utils.BareRepoTestCase):
def test_get_object(self): def test_get_object(self):
repo = self.repo repo = self.repo
tag = repo[TAG_SHA] 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__': if __name__ == '__main__':

View File

@@ -100,8 +100,8 @@ class TreeTest(utils.BareRepoTestCase):
self.assertEqual(x.filemode, 0o0100644) self.assertEqual(x.filemode, 0o0100644)
self.assertEqual(y.filemode, 0o0100755) self.assertEqual(y.filemode, 0o0100755)
self.assertEqual(repo[x.oid].oid, b0) self.assertEqual(repo[x.oid].id, b0)
self.assertEqual(repo[y.oid].oid, b1) self.assertEqual(repo[y.oid].id, b1)
def test_modify_tree(self): def test_modify_tree(self):

View File

@@ -49,7 +49,7 @@ class TreeBuilderTest(utils.BareRepoTestCase):
result = bld.write() result = bld.write()
self.assertEqual(len(bld), len(tree)) self.assertEqual(len(bld), len(tree))
self.assertEqual(tree.oid, result) self.assertEqual(tree.id, result)
def test_noop_treebuilder_from_tree(self): def test_noop_treebuilder_from_tree(self):
@@ -58,7 +58,7 @@ class TreeBuilderTest(utils.BareRepoTestCase):
result = bld.write() result = bld.write()
self.assertEqual(len(bld), len(tree)) self.assertEqual(len(bld), len(tree))
self.assertEqual(tree.oid, result) self.assertEqual(tree.id, result)
def test_rebuild_treebuilder(self): def test_rebuild_treebuilder(self):
@@ -72,7 +72,7 @@ class TreeBuilderTest(utils.BareRepoTestCase):
result = bld.write() result = bld.write()
self.assertEqual(len(bld), len(tree)) self.assertEqual(len(bld), len(tree))
self.assertEqual(tree.oid, result) self.assertEqual(tree.id, result)
if __name__ == '__main__': if __name__ == '__main__':