Fix coding style

- do not use tabs
- remove trailing white spaces
- lines are 79 chars max.
This commit is contained in:
J. David Ibáñez 2011-07-20 14:50:19 +02:00
parent cd83372230
commit dafe4b11b2
2 changed files with 34 additions and 32 deletions

@ -137,9 +137,9 @@ static PyObject *
Error_set(int err) {
assert(err < 0);
if (err == GIT_ENOTFOUND) {
/* KeyError expects the arg to be the missing key. If the caller called
* this instead of Error_set_py_obj, it means we don't know the key, but
* nor should we use git_lasterror. */
/* KeyError expects the arg to be the missing key. If the caller
* called this instead of Error_set_py_obj, it means we don't know
* the key, but nor should we use git_lasterror. */
PyErr_SetNone(PyExc_KeyError);
return NULL;
} else if (err == GIT_EOSERR) {
@ -223,16 +223,16 @@ lookup_object(Repository *repo, const git_oid *oid, git_otype type) {
return (PyObject*)py_obj;
}
static git_otype
static git_otype
int_to_loose_object_type(int type_id)
{
switch((git_otype)type_id) {
case GIT_OBJ_COMMIT: return GIT_OBJ_COMMIT;
case GIT_OBJ_TREE: return GIT_OBJ_TREE;
case GIT_OBJ_BLOB: return GIT_OBJ_BLOB;
case GIT_OBJ_TAG: return GIT_OBJ_TAG;
default: return GIT_OBJ_BAD;
}
switch((git_otype)type_id) {
case GIT_OBJ_COMMIT: return GIT_OBJ_COMMIT;
case GIT_OBJ_TREE: return GIT_OBJ_TREE;
case GIT_OBJ_BLOB: return GIT_OBJ_BLOB;
case GIT_OBJ_TAG: return GIT_OBJ_TAG;
default: return GIT_OBJ_BAD;
}
}
static PyObject *
@ -279,7 +279,7 @@ git_oid_to_py_string(git_oid* oid)
char buf[GIT_OID_HEXSZ+1];
if (strlen(git_oid_to_string(buf, sizeof(buf), oid)) != GIT_OID_HEXSZ)
return NULL;
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);
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);
err = stream->finalize_write(&oid, stream);
stream->free(stream);
@ -743,21 +744,21 @@ static PyMethodDef Repository_methods[] = {
{"read", (PyCFunction)Repository_read, METH_O,
"Read raw object data from the repository."},
{"write", (PyCFunction)Repository_write, METH_VARARGS,
"Write raw object data into the repository. First arg is the object type number, \n\
the second one a buffer with data.\n\
Return the hexadecimal sha of the created object"},
"Write raw object data into the repository. First arg is the object\n"
"type, the second one a buffer with data. Return the hexadecimal sha\n"
"of the created object."},
{"listall_references", (PyCFunction)Repository_listall_references,
METH_VARARGS,
"Return a list with all the references that can be found in a "
"repository."},
"Return a list with all the references in the repository."},
{"lookup_reference", (PyCFunction)Repository_lookup_reference, METH_O,
"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 "
"\"sha\"."},
{"create_symbolic_reference",
(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\"."},
{"packall_references", (PyCFunction)Repository_packall_references,
METH_NOARGS, "Pack all the loose references in the repository."},
@ -1230,8 +1231,8 @@ Tree_fix_index(Tree *self, PyObject *py_index) {
return -1;
}
/* This function is called via mp_subscript, which doesn't do negative index
* rewriting, so we have to do it manually. */
/* This function is called via mp_subscript, which doesn't do negative
* index rewriting, so we have to do it manually. */
if (index < 0)
index = len + index;
return (int)index;
@ -2215,7 +2216,8 @@ Reference_get_sha(Reference *self) {
if (oid == NULL)
{
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;
}

@ -33,7 +33,7 @@ import binascii
import unittest
from os.path import join, abspath
import pygit2
from pygit2 import GitError, GIT_OBJ_ANY, GIT_OBJ_BLOB, GIT_OBJ_COMMIT
import utils
A_HEX_SHA = 'af431f20fc541ed6d5afede3e2dc7160f6f01f16'
@ -49,21 +49,21 @@ class RepositoryTest(utils.BareRepoTestCase):
ab = self.repo.read(A_BIN_SHA)
a = self.repo.read(A_HEX_SHA)
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')
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):
data = "hello world"
# 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)
# 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):
self.assertRaises(TypeError, lambda: 123 in self.repo)
@ -77,13 +77,13 @@ class RepositoryTest(utils.BareRepoTestCase):
a = self.repo[A_HEX_SHA]
self.assertEqual('a contents\n', a.read_raw())
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):
commit_sha = '5fe808e8953c12735680c257f56600cb0de44b10'
commit = self.repo[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'
'This commit has some additional text.\n'),
commit.message)