Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oid cleanups #322

Merged
merged 3 commits into from
Jan 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 10 additions & 4 deletions src/oid.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ Oid_richcompare(PyObject *o1, PyObject *o2, int op)
return res;
}

PyObject *
Oid__str__(Oid *self)
{
return git_oid_to_py_str(&self->oid);
}

PyDoc_STRVAR(Oid_raw__doc__, "Raw oid, a 20 bytes string.");

Expand All @@ -267,12 +272,13 @@ Oid_raw__get__(Oid *self)
}


PyDoc_STRVAR(Oid_hex__doc__, "Hex oid, a 40 chars long string (type str).");
PyDoc_STRVAR(Oid_hex__doc__, "Hex oid, a 40 chars long string (type str).\n"
"This attribute is deprecated, please use the built-int str() or unicode()\n");

PyObject *
Oid_hex__get__(Oid *self)
{
return git_oid_to_py_str(&self->oid);
return Oid__str__(self);
}

PyGetSetDef Oid_getseters[] = {
Expand All @@ -293,13 +299,13 @@ PyTypeObject OidType = {
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
(reprfunc)Oid__str__, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
(hashfunc)Oid_hash, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
(reprfunc)Oid__str__, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Expand Down
14 changes: 12 additions & 2 deletions src/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,26 @@ TreeEntry_name__get__(TreeEntry *self)
}


PyDoc_STRVAR(TreeEntry_oid__doc__, "Object id.");
PyDoc_STRVAR(TreeEntry_id__doc__, "Object id.");

PyObject *
TreeEntry_oid__get__(TreeEntry *self)
TreeEntry_id__get__(TreeEntry *self)
{
const git_oid *oid;

oid = git_tree_entry_id(self->entry);
return git_oid_to_python(oid);
}

PyDoc_STRVAR(TreeEntry_oid__doc__, "Object id.\n"
"This attribute is deprecated. Please use 'id'");

PyObject *
TreeEntry_oid__get__(TreeEntry *self)
{
return TreeEntry_id__get__(self);
}

PyObject *
TreeEntry_richcompare(PyObject *a, PyObject *b, int op)
{
Expand Down Expand Up @@ -133,6 +142,7 @@ PyGetSetDef TreeEntry_getseters[] = {
GETTER(TreeEntry, filemode),
GETTER(TreeEntry, name),
GETTER(TreeEntry, oid),
GETTER(TreeEntry, id),
GETTER(TreeEntry, hex),
{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
6 changes: 3 additions & 3 deletions test/test_oid.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ class OidTest(utils.BareRepoTestCase):
def test_raw(self):
oid = Oid(raw=RAW)
self.assertEqual(oid.raw, RAW)
self.assertEqual(oid.hex, HEX)
self.assertEqual(str(oid), HEX)

def test_hex(self):
oid = Oid(hex=HEX)
self.assertEqual(oid.raw, RAW)
self.assertEqual(oid.hex, HEX)
self.assertEqual(str(oid), HEX)

def test_hex_bytes(self):
if version_info[0] == 2:
hex = bytes(HEX)
oid = Oid(hex=hex)
self.assertEqual(oid.raw, RAW)
self.assertEqual(oid.hex, HEX)
self.assertEqual(str(oid), HEX)
else:
hex = bytes(HEX, "ascii")
self.assertRaises(TypeError, Oid, hex=hex)
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
6 changes: 3 additions & 3 deletions test/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_read_subtree(self):
subtree_entry = tree['c']
self.assertTreeEntryEqual(subtree_entry, SUBTREE_SHA, 'c', 0o0040000)

subtree = self.repo[subtree_entry.oid]
subtree = self.repo[subtree_entry.id]
self.assertEqual(1, len(subtree))
sha = '297efb891a47de80be0cfe9c639e4b8c9b450989'
self.assertTreeEntryEqual(subtree[0], sha, 'd', 0o0100644)
Expand All @@ -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.id].id, b0)
self.assertEqual(repo[y.id].id, b1)


def test_modify_tree(self):
Expand Down
8 changes: 4 additions & 4 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 @@ -68,11 +68,11 @@ def test_rebuild_treebuilder(self):
name = entry.name
self.assertTrue(bld.get(name) is None)
bld.insert(name, entry.hex, entry.filemode)
self.assertEqual(bld.get(name).oid, entry.oid)
self.assertEqual(bld.get(name).id, entry.id)
result = bld.write()

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


if __name__ == '__main__':
Expand Down