Fix coding style
- do not use tabs - remove trailing white spaces - lines are 79 chars max.
This commit is contained in:
48
pygit2.c
48
pygit2.c
@@ -137,9 +137,9 @@ static PyObject *
|
|||||||
Error_set(int err) {
|
Error_set(int err) {
|
||||||
assert(err < 0);
|
assert(err < 0);
|
||||||
if (err == GIT_ENOTFOUND) {
|
if (err == GIT_ENOTFOUND) {
|
||||||
/* KeyError expects the arg to be the missing key. If the caller called
|
/* KeyError expects the arg to be the missing key. If the caller
|
||||||
* this instead of Error_set_py_obj, it means we don't know the key, but
|
* called this instead of Error_set_py_obj, it means we don't know
|
||||||
* nor should we use git_lasterror. */
|
* the key, but nor should we use git_lasterror. */
|
||||||
PyErr_SetNone(PyExc_KeyError);
|
PyErr_SetNone(PyExc_KeyError);
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (err == GIT_EOSERR) {
|
} else if (err == GIT_EOSERR) {
|
||||||
@@ -223,16 +223,16 @@ lookup_object(Repository *repo, const git_oid *oid, git_otype type) {
|
|||||||
return (PyObject*)py_obj;
|
return (PyObject*)py_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
static git_otype
|
static git_otype
|
||||||
int_to_loose_object_type(int type_id)
|
int_to_loose_object_type(int type_id)
|
||||||
{
|
{
|
||||||
switch((git_otype)type_id) {
|
switch((git_otype)type_id) {
|
||||||
case GIT_OBJ_COMMIT: return GIT_OBJ_COMMIT;
|
case GIT_OBJ_COMMIT: return GIT_OBJ_COMMIT;
|
||||||
case GIT_OBJ_TREE: return GIT_OBJ_TREE;
|
case GIT_OBJ_TREE: return GIT_OBJ_TREE;
|
||||||
case GIT_OBJ_BLOB: return GIT_OBJ_BLOB;
|
case GIT_OBJ_BLOB: return GIT_OBJ_BLOB;
|
||||||
case GIT_OBJ_TAG: return GIT_OBJ_TAG;
|
case GIT_OBJ_TAG: return GIT_OBJ_TAG;
|
||||||
default: return GIT_OBJ_BAD;
|
default: return GIT_OBJ_BAD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
@@ -279,7 +279,7 @@ git_oid_to_py_string(git_oid* oid)
|
|||||||
char buf[GIT_OID_HEXSZ+1];
|
char buf[GIT_OID_HEXSZ+1];
|
||||||
if (strlen(git_oid_to_string(buf, sizeof(buf), oid)) != GIT_OID_HEXSZ)
|
if (strlen(git_oid_to_string(buf, sizeof(buf), oid)) != GIT_OID_HEXSZ)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return PyString_FromStringAndSize(buf, GIT_OID_HEXSZ);
|
return PyString_FromStringAndSize(buf, GIT_OID_HEXSZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,7 +383,8 @@ Repository_write(Repository *self, PyObject *args)
|
|||||||
|
|
||||||
git_odb* odb = git_repository_database(self->repo);
|
git_odb* odb = git_repository_database(self->repo);
|
||||||
|
|
||||||
if ((err = git_odb_open_wstream(&stream, odb, buflen, type)) == GIT_SUCCESS) {
|
err = git_odb_open_wstream(&stream, odb, buflen, type);
|
||||||
|
if (err == GIT_SUCCESS) {
|
||||||
stream->write(stream, buffer, buflen);
|
stream->write(stream, buffer, buflen);
|
||||||
err = stream->finalize_write(&oid, stream);
|
err = stream->finalize_write(&oid, stream);
|
||||||
stream->free(stream);
|
stream->free(stream);
|
||||||
@@ -743,21 +744,21 @@ static PyMethodDef Repository_methods[] = {
|
|||||||
{"read", (PyCFunction)Repository_read, METH_O,
|
{"read", (PyCFunction)Repository_read, METH_O,
|
||||||
"Read raw object data from the repository."},
|
"Read raw object data from the repository."},
|
||||||
{"write", (PyCFunction)Repository_write, METH_VARARGS,
|
{"write", (PyCFunction)Repository_write, METH_VARARGS,
|
||||||
"Write raw object data into the repository. First arg is the object type number, \n\
|
"Write raw object data into the repository. First arg is the object\n"
|
||||||
the second one a buffer with data.\n\
|
"type, the second one a buffer with data. Return the hexadecimal sha\n"
|
||||||
Return the hexadecimal sha of the created object"},
|
"of the created object."},
|
||||||
{"listall_references", (PyCFunction)Repository_listall_references,
|
{"listall_references", (PyCFunction)Repository_listall_references,
|
||||||
METH_VARARGS,
|
METH_VARARGS,
|
||||||
"Return a list with all the references that can be found in a "
|
"Return a list with all the references in the repository."},
|
||||||
"repository."},
|
|
||||||
{"lookup_reference", (PyCFunction)Repository_lookup_reference, METH_O,
|
{"lookup_reference", (PyCFunction)Repository_lookup_reference, METH_O,
|
||||||
"Lookup a reference by its name in a repository."},
|
"Lookup a reference by its name in a repository."},
|
||||||
{"create_reference", (PyCFunction)Repository_create_reference, METH_VARARGS,
|
{"create_reference", (PyCFunction)Repository_create_reference,
|
||||||
|
METH_VARARGS,
|
||||||
"Create a new reference \"name\" that points to the object given by its "
|
"Create a new reference \"name\" that points to the object given by its "
|
||||||
"\"sha\"."},
|
"\"sha\"."},
|
||||||
{"create_symbolic_reference",
|
{"create_symbolic_reference",
|
||||||
(PyCFunction)Repository_create_symbolic_reference, METH_VARARGS,
|
(PyCFunction)Repository_create_symbolic_reference, METH_VARARGS,
|
||||||
"Create a new symbolic reference \"name\" that points to the reference "
|
"Create a new symbolic reference \"name\" that points to the reference\n"
|
||||||
"\"target\"."},
|
"\"target\"."},
|
||||||
{"packall_references", (PyCFunction)Repository_packall_references,
|
{"packall_references", (PyCFunction)Repository_packall_references,
|
||||||
METH_NOARGS, "Pack all the loose references in the repository."},
|
METH_NOARGS, "Pack all the loose references in the repository."},
|
||||||
@@ -1230,8 +1231,8 @@ Tree_fix_index(Tree *self, PyObject *py_index) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function is called via mp_subscript, which doesn't do negative index
|
/* This function is called via mp_subscript, which doesn't do negative
|
||||||
* rewriting, so we have to do it manually. */
|
* index rewriting, so we have to do it manually. */
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
index = len + index;
|
index = len + index;
|
||||||
return (int)index;
|
return (int)index;
|
||||||
@@ -2215,7 +2216,8 @@ Reference_get_sha(Reference *self) {
|
|||||||
if (oid == NULL)
|
if (oid == NULL)
|
||||||
{
|
{
|
||||||
PyErr_Format(PyExc_ValueError,
|
PyErr_Format(PyExc_ValueError,
|
||||||
"sha is only available if the reference is direct (i.e. not symbolic)");
|
"sha is only available if the reference is direct "
|
||||||
|
"(i.e. not symbolic)");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -33,7 +33,7 @@ import binascii
|
|||||||
import unittest
|
import unittest
|
||||||
from os.path import join, abspath
|
from os.path import join, abspath
|
||||||
|
|
||||||
import pygit2
|
from pygit2 import GitError, GIT_OBJ_ANY, GIT_OBJ_BLOB, GIT_OBJ_COMMIT
|
||||||
import utils
|
import utils
|
||||||
|
|
||||||
A_HEX_SHA = 'af431f20fc541ed6d5afede3e2dc7160f6f01f16'
|
A_HEX_SHA = 'af431f20fc541ed6d5afede3e2dc7160f6f01f16'
|
||||||
@@ -49,21 +49,21 @@ class RepositoryTest(utils.BareRepoTestCase):
|
|||||||
ab = self.repo.read(A_BIN_SHA)
|
ab = self.repo.read(A_BIN_SHA)
|
||||||
a = self.repo.read(A_HEX_SHA)
|
a = self.repo.read(A_HEX_SHA)
|
||||||
self.assertEqual(ab, a)
|
self.assertEqual(ab, a)
|
||||||
self.assertEqual((pygit2.GIT_OBJ_BLOB, 'a contents\n'), a)
|
self.assertEqual((GIT_OBJ_BLOB, 'a contents\n'), a)
|
||||||
|
|
||||||
a2 = self.repo.read('7f129fd57e31e935c6d60a0c794efe4e6927664b')
|
a2 = self.repo.read('7f129fd57e31e935c6d60a0c794efe4e6927664b')
|
||||||
self.assertEqual((pygit2.GIT_OBJ_BLOB, 'a contents 2\n'), a2)
|
self.assertEqual((GIT_OBJ_BLOB, 'a contents 2\n'), a2)
|
||||||
|
|
||||||
def test_write(self):
|
def test_write(self):
|
||||||
data = "hello world"
|
data = "hello world"
|
||||||
# invalid object type
|
# invalid object type
|
||||||
self.assertRaises(pygit2.GitError, self.repo.write, pygit2.GIT_OBJ_ANY, data)
|
self.assertRaises(GitError, self.repo.write, GIT_OBJ_ANY, data)
|
||||||
|
|
||||||
hex_sha = self.repo.write(pygit2.GIT_OBJ_BLOB, data)
|
hex_sha = self.repo.write(GIT_OBJ_BLOB, data)
|
||||||
self.assertEqual(len(hex_sha), 40)
|
self.assertEqual(len(hex_sha), 40)
|
||||||
|
|
||||||
# works as buffer as well
|
# works as buffer as well
|
||||||
self.assertEqual(hex_sha, self.repo.write(pygit2.GIT_OBJ_BLOB, buffer(data)))
|
self.assertEqual(hex_sha, self.repo.write(GIT_OBJ_BLOB, buffer(data)))
|
||||||
|
|
||||||
def test_contains(self):
|
def test_contains(self):
|
||||||
self.assertRaises(TypeError, lambda: 123 in self.repo)
|
self.assertRaises(TypeError, lambda: 123 in self.repo)
|
||||||
@@ -77,13 +77,13 @@ class RepositoryTest(utils.BareRepoTestCase):
|
|||||||
a = self.repo[A_HEX_SHA]
|
a = self.repo[A_HEX_SHA]
|
||||||
self.assertEqual('a contents\n', a.read_raw())
|
self.assertEqual('a contents\n', a.read_raw())
|
||||||
self.assertEqual(A_HEX_SHA, a.sha)
|
self.assertEqual(A_HEX_SHA, a.sha)
|
||||||
self.assertEqual(pygit2.GIT_OBJ_BLOB, a.type)
|
self.assertEqual(GIT_OBJ_BLOB, a.type)
|
||||||
|
|
||||||
def test_lookup_commit(self):
|
def test_lookup_commit(self):
|
||||||
commit_sha = '5fe808e8953c12735680c257f56600cb0de44b10'
|
commit_sha = '5fe808e8953c12735680c257f56600cb0de44b10'
|
||||||
commit = self.repo[commit_sha]
|
commit = self.repo[commit_sha]
|
||||||
self.assertEqual(commit_sha, commit.sha)
|
self.assertEqual(commit_sha, commit.sha)
|
||||||
self.assertEqual(pygit2.GIT_OBJ_COMMIT, commit.type)
|
self.assertEqual(GIT_OBJ_COMMIT, commit.type)
|
||||||
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'),
|
||||||
commit.message)
|
commit.message)
|
||||||
|
Reference in New Issue
Block a user