Rename '.sha' to '.hex'
This commit is contained in:
parent
9f2e61cd8f
commit
83642a6954
38
pygit2.c
38
pygit2.c
@ -971,7 +971,7 @@ Object_get_oid(Object *self)
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
Object_get_sha(Object *self)
|
||||
Object_get_hex(Object *self)
|
||||
{
|
||||
const git_oid *oid;
|
||||
|
||||
@ -994,7 +994,7 @@ Object_read_raw(Object *self)
|
||||
const git_oid *id;
|
||||
git_odb_object *obj;
|
||||
int err;
|
||||
PyObject *result = NULL, *py_sha = NULL;
|
||||
PyObject *result = NULL, *py_hex = NULL;
|
||||
|
||||
id = git_object_id(self->obj);
|
||||
if (!id)
|
||||
@ -1002,8 +1002,8 @@ Object_read_raw(Object *self)
|
||||
|
||||
err = Repository_read_raw(&obj, self->repo->repo, id);
|
||||
if (err < 0) {
|
||||
py_sha = Object_get_sha(self);
|
||||
Error_set_py_obj(err, py_sha);
|
||||
py_hex = Object_get_hex(self);
|
||||
Error_set_py_obj(err, py_hex);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@ -1014,13 +1014,13 @@ Object_read_raw(Object *self)
|
||||
git_odb_object_close(obj);
|
||||
|
||||
cleanup:
|
||||
Py_XDECREF(py_sha);
|
||||
Py_XDECREF(py_hex);
|
||||
return result;
|
||||
}
|
||||
|
||||
static PyGetSetDef Object_getseters[] = {
|
||||
{"oid", (getter)Object_get_oid, NULL, "object id", NULL},
|
||||
{"sha", (getter)Object_get_sha, NULL, "hex SHA", NULL},
|
||||
{"hex", (getter)Object_get_hex, NULL, "hex oid", NULL},
|
||||
{"type", (getter)Object_get_type, NULL, "type number", NULL},
|
||||
{NULL}
|
||||
};
|
||||
@ -1274,7 +1274,7 @@ TreeEntry_get_oid(TreeEntry *self)
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
TreeEntry_get_sha(TreeEntry *self)
|
||||
TreeEntry_get_hex(TreeEntry *self)
|
||||
{
|
||||
return git_oid_to_py_str(git_tree_entry_id(self->entry));
|
||||
}
|
||||
@ -1291,8 +1291,8 @@ TreeEntry_to_object(TreeEntry *self)
|
||||
static PyGetSetDef TreeEntry_getseters[] = {
|
||||
{"attributes", (getter)TreeEntry_get_attributes, NULL, "attributes", NULL},
|
||||
{"name", (getter)TreeEntry_get_name, NULL, "name", NULL},
|
||||
{"oid", (getter)TreeEntry_get_oid, NULL, "oid", NULL},
|
||||
{"sha", (getter)TreeEntry_get_sha, NULL, "sha", NULL},
|
||||
{"oid", (getter)TreeEntry_get_oid, NULL, "object id", NULL},
|
||||
{"hex", (getter)TreeEntry_get_hex, NULL, "hex oid", NULL},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
@ -2116,7 +2116,7 @@ IndexEntry_get_oid(IndexEntry *self)
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
IndexEntry_get_sha(IndexEntry *self)
|
||||
IndexEntry_get_hex(IndexEntry *self)
|
||||
{
|
||||
return git_oid_to_py_str(&self->entry->oid);
|
||||
}
|
||||
@ -2125,7 +2125,7 @@ static PyGetSetDef IndexEntry_getseters[] = {
|
||||
{"mode", (getter)IndexEntry_get_mode, NULL, "mode", NULL},
|
||||
{"path", (getter)IndexEntry_get_path, NULL, "path", NULL},
|
||||
{"oid", (getter)IndexEntry_get_oid, NULL, "object id", NULL},
|
||||
{"sha", (getter)IndexEntry_get_sha, NULL, "hex SHA", NULL},
|
||||
{"hex", (getter)IndexEntry_get_hex, NULL, "hex oid", NULL},
|
||||
{NULL},
|
||||
};
|
||||
|
||||
@ -2426,7 +2426,7 @@ Reference_get_oid(Reference *self)
|
||||
if (oid == NULL)
|
||||
{
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"sha is only available if the reference is direct "
|
||||
"oid is only available if the reference is direct "
|
||||
"(i.e. not symbolic)");
|
||||
return NULL;
|
||||
}
|
||||
@ -2436,17 +2436,17 @@ Reference_get_oid(Reference *self)
|
||||
}
|
||||
|
||||
static int
|
||||
Reference_set_oid(Reference *self, PyObject *py_sha)
|
||||
Reference_set_oid(Reference *self, PyObject *py_hex)
|
||||
{
|
||||
git_oid oid;
|
||||
int err;
|
||||
|
||||
/* 1- Get the oid from the py_sha */
|
||||
if (!py_str_to_git_oid(py_sha, &oid))
|
||||
/* 1- Get the oid */
|
||||
if (!py_str_to_git_oid(py_hex, &oid))
|
||||
return -1;
|
||||
|
||||
/* 2- Set the oid */
|
||||
err = git_reference_set_oid (self->reference, &oid);
|
||||
err = git_reference_set_oid(self->reference, &oid);
|
||||
if (err < 0) {
|
||||
Error_set(err);
|
||||
return -1;
|
||||
@ -2457,7 +2457,7 @@ Reference_set_oid(Reference *self, PyObject *py_sha)
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
Reference_get_sha(Reference *self)
|
||||
Reference_get_hex(Reference *self)
|
||||
{
|
||||
const git_oid *oid;
|
||||
|
||||
@ -2466,7 +2466,7 @@ Reference_get_sha(Reference *self)
|
||||
if (oid == NULL)
|
||||
{
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"sha is only available if the reference is direct "
|
||||
"oid is only available if the reference is direct "
|
||||
"(i.e. not symbolic)");
|
||||
return NULL;
|
||||
}
|
||||
@ -2499,7 +2499,7 @@ static PyGetSetDef Reference_getseters[] = {
|
||||
"The full name of a reference.", NULL},
|
||||
{"oid", (getter)Reference_get_oid, (setter)Reference_set_oid, "object id",
|
||||
NULL},
|
||||
{"sha", (getter)Reference_get_sha, NULL, "hex SHA", NULL},
|
||||
{"hex", (getter)Reference_get_hex, NULL, "hex oid", NULL},
|
||||
{"target", (getter)Reference_get_target, (setter)Reference_set_target,
|
||||
"target", NULL},
|
||||
{"type", (getter)Reference_get_type, NULL,
|
||||
|
@ -45,7 +45,7 @@ class BlobTest(utils.BareRepoTestCase):
|
||||
|
||||
def test_read_blob(self):
|
||||
blob = self.repo[BLOB_SHA]
|
||||
self.assertEqual(blob.sha, BLOB_SHA)
|
||||
self.assertEqual(blob.hex, BLOB_SHA)
|
||||
sha = b2a_hex(blob.oid).decode('ascii')
|
||||
self.assertEqual(sha, BLOB_SHA)
|
||||
self.assertTrue(isinstance(blob, pygit2.Blob))
|
||||
|
@ -44,11 +44,11 @@ class CommitTest(utils.BareRepoTestCase):
|
||||
|
||||
def test_read_commit(self):
|
||||
commit = self.repo[COMMIT_SHA]
|
||||
self.assertEqual(COMMIT_SHA, commit.sha)
|
||||
self.assertEqual(COMMIT_SHA, commit.hex)
|
||||
parents = commit.parents
|
||||
self.assertEqual(1, len(parents))
|
||||
self.assertEqual('c2792cfa289ae6321ecf2cd5806c2194b0fd070c',
|
||||
parents[0].sha)
|
||||
parents[0].hex)
|
||||
self.assertEqual(None, commit.message_encoding)
|
||||
#self.assertEqual('Second test data commit.', commit.message_short)
|
||||
self.assertEqual(('Second test data commit.\n\n'
|
||||
@ -63,7 +63,7 @@ class CommitTest(utils.BareRepoTestCase):
|
||||
('Dave Borowitz', 'dborowitz@google.com', 1288477363, -420),
|
||||
commit.author)
|
||||
self.assertEqual(
|
||||
'967fce8df97cc71722d3c2a5930ef3e6f1d27b12', commit.tree.sha)
|
||||
'967fce8df97cc71722d3c2a5930ef3e6f1d27b12', commit.tree.hex)
|
||||
|
||||
def test_new_commit(self):
|
||||
repo = self.repo
|
||||
@ -79,16 +79,16 @@ class CommitTest(utils.BareRepoTestCase):
|
||||
|
||||
self.assertEqual(GIT_OBJ_COMMIT, commit.type)
|
||||
self.assertEqual('98286caaab3f1fde5bf52c8369b2b0423bad743b',
|
||||
commit.sha)
|
||||
commit.hex)
|
||||
self.assertEqual(None, commit.message_encoding)
|
||||
self.assertEqual(message, commit.message)
|
||||
#self.assertEqual('New commit.', commit.message_short)
|
||||
self.assertEqual(12346, commit.commit_time)
|
||||
self.assertEqual(committer, commit.committer)
|
||||
self.assertEqual(author, commit.author)
|
||||
self.assertEqual(tree, commit.tree.sha)
|
||||
self.assertEqual(tree, commit.tree.hex)
|
||||
self.assertEqual(1, len(commit.parents))
|
||||
self.assertEqual(COMMIT_SHA, commit.parents[0].sha)
|
||||
self.assertEqual(COMMIT_SHA, commit.parents[0].hex)
|
||||
|
||||
def test_modify_commit(self):
|
||||
message = 'New commit.\n\nMessage.\n'
|
||||
|
@ -61,9 +61,9 @@ class IndexTest(utils.RepoTestCase):
|
||||
|
||||
sha = 'a520c24d85fbfc815d385957eed41406ca5a860b'
|
||||
self.assertTrue('hello.txt' in index)
|
||||
self.assertEqual(index['hello.txt'].sha, sha)
|
||||
self.assertEqual(index['hello.txt'].hex, sha)
|
||||
self.assertEqual(index['hello.txt'].path, 'hello.txt')
|
||||
self.assertEqual(index[1].sha, sha)
|
||||
self.assertEqual(index[1].hex, sha)
|
||||
|
||||
def test_add(self):
|
||||
index = self.repo.index
|
||||
@ -73,7 +73,7 @@ class IndexTest(utils.RepoTestCase):
|
||||
index.add('bye.txt')
|
||||
self.assertTrue('bye.txt' in index)
|
||||
self.assertEqual(len(index), 3)
|
||||
self.assertEqual(index['bye.txt'].sha, sha)
|
||||
self.assertEqual(index['bye.txt'].hex, sha)
|
||||
|
||||
def test_clear(self):
|
||||
index = self.repo.index
|
||||
@ -102,8 +102,8 @@ class IndexTest(utils.RepoTestCase):
|
||||
self.assertEqual(len(list(index)), n)
|
||||
|
||||
# Compare SHAs, not IndexEntry object identity
|
||||
entries = [index[x].sha for x in range(n)]
|
||||
self.assertEqual(list(x.sha for x in index), entries)
|
||||
entries = [index[x].hex for x in range(n)]
|
||||
self.assertEqual(list(x.hex for x in index), entries)
|
||||
|
||||
def test_mode(self):
|
||||
"""
|
||||
@ -116,8 +116,8 @@ class IndexTest(utils.RepoTestCase):
|
||||
|
||||
def test_bare_index(self):
|
||||
index = pygit2.Index(os.path.join(self.repo.path, 'index'))
|
||||
self.assertEqual([x.sha for x in index],
|
||||
[x.sha for x in self.repo.index])
|
||||
self.assertEqual([x.hex for x in index],
|
||||
[x.hex for x in self.repo.index])
|
||||
|
||||
self.assertRaises(pygit2.GitError, lambda: index.add('bye.txt', 0))
|
||||
|
||||
|
@ -75,14 +75,14 @@ class ReferencesTest(utils.RepoTestCase):
|
||||
|
||||
def test_reference_get_sha(self):
|
||||
reference = self.repo.lookup_reference('refs/heads/master')
|
||||
self.assertEqual(reference.sha, LAST_COMMIT)
|
||||
self.assertEqual(reference.hex, LAST_COMMIT)
|
||||
|
||||
|
||||
def test_reference_set_sha(self):
|
||||
NEW_COMMIT = '5ebeeebb320790caf276b9fc8b24546d63316533'
|
||||
reference = self.repo.lookup_reference('refs/heads/master')
|
||||
reference.oid = NEW_COMMIT
|
||||
self.assertEqual(reference.sha, NEW_COMMIT)
|
||||
self.assertEqual(reference.hex, NEW_COMMIT)
|
||||
|
||||
|
||||
def test_reference_get_type(self):
|
||||
@ -128,7 +128,7 @@ class ReferencesTest(utils.RepoTestCase):
|
||||
self.assertEqual(reference.type, GIT_REF_SYMBOLIC)
|
||||
reference = reference.resolve()
|
||||
self.assertEqual(reference.type, GIT_REF_OID)
|
||||
self.assertEqual(reference.sha, LAST_COMMIT)
|
||||
self.assertEqual(reference.hex, LAST_COMMIT)
|
||||
|
||||
|
||||
def test_create_reference(self):
|
||||
@ -138,7 +138,7 @@ class ReferencesTest(utils.RepoTestCase):
|
||||
refs = self.repo.listall_references()
|
||||
self.assertTrue('refs/tags/version1' in refs)
|
||||
reference = self.repo.lookup_reference('refs/tags/version1')
|
||||
self.assertEqual(reference.sha, LAST_COMMIT)
|
||||
self.assertEqual(reference.hex, LAST_COMMIT)
|
||||
|
||||
|
||||
def test_create_symbolic_reference(self):
|
||||
|
@ -76,16 +76,16 @@ class RepositoryTest(utils.BareRepoTestCase):
|
||||
|
||||
def test_lookup_blob(self):
|
||||
self.assertRaises(TypeError, lambda: self.repo[123])
|
||||
self.assertEqual(self.repo[A_BIN_SHA].sha, A_HEX_SHA)
|
||||
self.assertEqual(self.repo[A_BIN_SHA].hex, A_HEX_SHA)
|
||||
a = self.repo[A_HEX_SHA]
|
||||
self.assertEqual(b'a contents\n', a.read_raw())
|
||||
self.assertEqual(A_HEX_SHA, a.sha)
|
||||
self.assertEqual(A_HEX_SHA, a.hex)
|
||||
self.assertEqual(GIT_OBJ_BLOB, a.type)
|
||||
|
||||
def test_lookup_commit(self):
|
||||
commit_sha = '5fe808e8953c12735680c257f56600cb0de44b10'
|
||||
commit = self.repo[commit_sha]
|
||||
self.assertEqual(commit_sha, commit.sha)
|
||||
self.assertEqual(commit_sha, commit.hex)
|
||||
self.assertEqual(GIT_OBJ_COMMIT, commit.type)
|
||||
self.assertEqual(('Second test data commit.\n\n'
|
||||
'This commit has some additional text.\n'),
|
||||
|
@ -51,12 +51,12 @@ class WalkerTest(utils.RepoTestCase):
|
||||
|
||||
def test_walk(self):
|
||||
walker = self.repo.walk(log[0], GIT_SORT_TIME)
|
||||
out = [ x.sha for x in walker ]
|
||||
out = [ x.hex for x in walker ]
|
||||
self.assertEqual(out, log)
|
||||
|
||||
def test_reverse(self):
|
||||
walker = self.repo.walk(log[0], GIT_SORT_TIME | GIT_SORT_REVERSE)
|
||||
out = [ x.sha for x in walker ]
|
||||
out = [ x.hex for x in walker ]
|
||||
self.assertEqual(out, list(reversed(log)))
|
||||
|
||||
def test_hide(self):
|
||||
@ -67,22 +67,22 @@ class WalkerTest(utils.RepoTestCase):
|
||||
def test_reset(self):
|
||||
walker = self.repo.walk(log[0], GIT_SORT_TIME)
|
||||
walker.reset()
|
||||
out = [ x.sha for x in walker ]
|
||||
out = [ x.hex for x in walker ]
|
||||
self.assertEqual(out, [])
|
||||
|
||||
def test_push(self):
|
||||
walker = self.repo.walk(log[-1], GIT_SORT_TIME)
|
||||
out = [ x.sha for x in walker ]
|
||||
out = [ x.hex for x in walker ]
|
||||
self.assertEqual(out, log[-1:])
|
||||
walker.reset()
|
||||
walker.push(log[0])
|
||||
out = [ x.sha for x in walker ]
|
||||
out = [ x.hex for x in walker ]
|
||||
self.assertEqual(out, log)
|
||||
|
||||
def test_sort(self):
|
||||
walker = self.repo.walk(log[0], GIT_SORT_TIME)
|
||||
walker.sort(GIT_SORT_TIME | GIT_SORT_REVERSE)
|
||||
out = [ x.sha for x in walker ]
|
||||
out = [ x.hex for x in walker ]
|
||||
self.assertEqual(out, list(reversed(log)))
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -67,12 +67,12 @@ class TagTest(utils.BareRepoTestCase):
|
||||
message)
|
||||
tag = self.repo[sha]
|
||||
|
||||
self.assertEqual('3ee44658fd11660e828dfc96b9b5c5f38d5b49bb', tag.sha)
|
||||
self.assertEqual('3ee44658fd11660e828dfc96b9b5c5f38d5b49bb', tag.hex)
|
||||
self.assertEqual(name, tag.name)
|
||||
self.assertEqual(target, tag.target.sha)
|
||||
self.assertEqual(target, tag.target.hex)
|
||||
self.assertEqual(tagger, tag.tagger)
|
||||
self.assertEqual(message, tag.message)
|
||||
self.assertEqual(name, self.repo[tag.sha].name)
|
||||
self.assertEqual(name, self.repo[tag.hex].name)
|
||||
|
||||
def test_modify_tag(self):
|
||||
name = 'thetag'
|
||||
|
@ -45,7 +45,7 @@ SUBTREE_SHA = '614fd9a3094bf618ea938fffc00e7d1a54f89ad0'
|
||||
class TreeTest(utils.BareRepoTestCase):
|
||||
|
||||
def assertTreeEntryEqual(self, entry, sha, name, attributes):
|
||||
self.assertEqual(entry.sha, sha)
|
||||
self.assertEqual(entry.hex, sha)
|
||||
self.assertEqual(entry.name, name)
|
||||
self.assertEqual(entry.attributes, attributes,
|
||||
'0%o != 0%o' % (entry.attributes, attributes))
|
||||
@ -100,11 +100,11 @@ class TreeTest(utils.BareRepoTestCase):
|
||||
del tree[2]
|
||||
self.assertEqual(2, len(tree))
|
||||
|
||||
self.assertEqual(None, tree.sha)
|
||||
self.assertEqual(None, tree.hex)
|
||||
tree.write()
|
||||
contents = '100644 x\0%s100755 y\0%s' % ('\x11' * 20, '\x22' * 20)
|
||||
self.assertEqual((pygit2.GIT_OBJ_TREE, contents),
|
||||
self.repo.read(tree.sha))
|
||||
self.repo.read(tree.hex))
|
||||
|
||||
def test_modify_tree(self):
|
||||
tree = self.repo[TREE_SHA]
|
||||
@ -119,7 +119,7 @@ class TreeTest(utils.BareRepoTestCase):
|
||||
"""
|
||||
tree = self.repo[TREE_SHA]
|
||||
for tree_entry in tree:
|
||||
self.assertEqual(tree_entry.sha, tree[tree_entry.name].sha)
|
||||
self.assertEqual(tree_entry.hex, tree[tree_entry.name].hex)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
x
Reference in New Issue
Block a user