Coding style
Including: - Lines longer than 79 chars - Spaces at the end of line - Wrong indentation - Comma not followed by an space - C++ style comments: //
This commit is contained in:
parent
a80e989377
commit
a96d494747
@ -6,12 +6,13 @@ How to Install
|
||||
.. contents::
|
||||
|
||||
|
||||
First you need to install the latest version of libgit2.
|
||||
You can find platform-specific instructions to build the library in the libgit2 website:
|
||||
First you need to install the latest version of libgit2. You can find
|
||||
platform-specific instructions to build the library in the libgit2 website:
|
||||
|
||||
http://libgit2.github.com
|
||||
|
||||
Also, make sure you have Python 2.6+ installed together with the Python development headers.
|
||||
Also, make sure you have Python 2.6+ installed together with the Python
|
||||
development headers.
|
||||
|
||||
When those are installed, you can install pygit2::
|
||||
|
||||
|
@ -118,22 +118,13 @@ interfaces::
|
||||
>>> blob
|
||||
<pygit2.Blob object at 0xcc12d0>
|
||||
|
||||
This is the interface of a tree entry::
|
||||
|
||||
TreeEntry.name -- name of the tree entry
|
||||
TreeEntry.oid -- the id of the git object
|
||||
TreeEntry.hex -- hexadecimal representation of the oid
|
||||
TreeEntry.filemode -- the Unix file attributes
|
||||
TreeEntry.to_object() -- returns the git object (equivalent to repo[entry.oid])
|
||||
|
||||
|
||||
.. autoclass:: pygit2.Tree
|
||||
:members:
|
||||
:show-inheritance:
|
||||
:undoc-members:
|
||||
|
||||
.. autoclass:: pygit2.TreeEntry
|
||||
:members:
|
||||
:members: name, oid, hex, filemode, to_object
|
||||
:show-inheritance:
|
||||
:undoc-members:
|
||||
|
||||
|
@ -38,7 +38,8 @@ int Repository_traverse(Repository *self, visitproc visit, void *arg);
|
||||
int Repository_clear(Repository *self);
|
||||
int Repository_contains(Repository *self, PyObject *value);
|
||||
|
||||
git_odb_object* Repository_read_raw(git_repository *repo, const git_oid *oid, size_t len);
|
||||
git_odb_object*
|
||||
Repository_read_raw(git_repository *repo, const git_oid *oid, size_t len);
|
||||
|
||||
PyObject* Repository_head(Repository *self);
|
||||
PyObject* Repository_getitem(Repository *self, PyObject *value);
|
||||
@ -55,7 +56,10 @@ PyObject* Repository_create_commit(Repository *self, PyObject *args);
|
||||
PyObject* Repository_create_tag(Repository *self, PyObject *args);
|
||||
PyObject* Repository_listall_references(Repository *self, PyObject *args);
|
||||
PyObject* Repository_lookup_reference(Repository *self, PyObject *py_name);
|
||||
PyObject* Repository_create_reference(Repository *self, PyObject *args, PyObject* keywds);
|
||||
|
||||
PyObject*
|
||||
Repository_create_reference(Repository *self, PyObject *args, PyObject* kw);
|
||||
|
||||
PyObject* Repository_packall_references(Repository *self, PyObject *args);
|
||||
PyObject* Repository_status(Repository *self, PyObject *args);
|
||||
PyObject* Repository_status_file(Repository *self, PyObject *value);
|
||||
|
@ -40,6 +40,9 @@ PyObject* Signature_get_name(Signature *self);
|
||||
PyObject* Signature_get_email(Signature *self);
|
||||
PyObject* Signature_get_time(Signature *self);
|
||||
PyObject* Signature_get_offset(Signature *self);
|
||||
PyObject* build_signature(Object *obj, const git_signature *signature, const char *encoding);
|
||||
|
||||
PyObject*
|
||||
build_signature(Object *obj, const git_signature *signature,
|
||||
const char *encoding);
|
||||
|
||||
#endif
|
||||
|
@ -137,8 +137,10 @@ typedef struct {
|
||||
} Signature;
|
||||
|
||||
|
||||
PyObject* lookup_object_prefix(Repository *repo, const git_oid *oid, size_t len,
|
||||
PyObject*
|
||||
lookup_object_prefix(Repository *repo, const git_oid *oid, size_t len,
|
||||
git_otype type);
|
||||
|
||||
PyObject* lookup_object(Repository *repo, const git_oid *oid, git_otype type);
|
||||
|
||||
#endif
|
||||
|
14
setup.py
14
setup.py
@ -90,13 +90,15 @@ class TestCommand(Command):
|
||||
import shlex
|
||||
import unittest
|
||||
test_argv0 = [sys.argv[0] + ' test --args=']
|
||||
#For transfering args to unittest, we have to split args
|
||||
#by ourself, so that command like:
|
||||
# For transfering args to unittest, we have to split args by ourself,
|
||||
# so that command like:
|
||||
#
|
||||
# python setup.py test --args="-v -f"
|
||||
#can be executed, and the parameter '-v -f' can be
|
||||
#transfering to unittest properly.
|
||||
#
|
||||
# can be executed, and the parameter '-v -f' can be transfering to
|
||||
# unittest properly.
|
||||
test_argv = test_argv0 + shlex.split(self.args)
|
||||
unittest.main(module=None, defaultTest='test.test_suite', argv=test_argv)
|
||||
unittest.main(None, defaultTest='test.test_suite', argv=test_argv)
|
||||
|
||||
|
||||
class BuildWithDLLs(build):
|
||||
@ -112,7 +114,7 @@ class BuildWithDLLs(build):
|
||||
libgit2_dlls.append('git2.dll')
|
||||
elif compiler_type == 'mingw32':
|
||||
libgit2_dlls.append('libgit2.dll')
|
||||
look_dirs = [libgit2_bin] + os.environ.get("PATH","").split(os.pathsep)
|
||||
look_dirs = [libgit2_bin] + os.getenv("PATH", "").split(os.pathsep)
|
||||
target = os.path.abspath(self.build_lib)
|
||||
for bin in libgit2_dlls:
|
||||
for look in look_dirs:
|
||||
|
@ -149,9 +149,8 @@ static int diff_hunk_cb(
|
||||
hunk->new_file = "";
|
||||
}
|
||||
|
||||
if (hunk->data == NULL) {
|
||||
if (hunk->data == NULL)
|
||||
hunk->data = PyList_New(0);
|
||||
}
|
||||
|
||||
if (PyList_Append(hunks, (PyObject *)hunk) == 0) {
|
||||
Py_DECREF(hunk);
|
||||
@ -184,11 +183,10 @@ diff_file_cb(const git_diff_delta *delta, float progress, void *cb_data)
|
||||
delta->similarity
|
||||
);
|
||||
|
||||
if (PyList_Append(files, file) == 0) {
|
||||
// If success
|
||||
/* If success */
|
||||
if (PyList_Append(files, file) == 0)
|
||||
Py_DECREF(file);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
20
src/error.c
20
src/error.c
@ -32,38 +32,38 @@ PyObject *GitError;
|
||||
PyObject * Error_type(int type)
|
||||
{
|
||||
const git_error* error;
|
||||
// Expected
|
||||
/* Expected */
|
||||
switch (type) {
|
||||
/** Input does not exist in the scope searched. */
|
||||
/* Input does not exist in the scope searched. */
|
||||
case GIT_ENOTFOUND:
|
||||
return PyExc_KeyError;
|
||||
|
||||
/** A reference with this name already exists */
|
||||
/* A reference with this name already exists */
|
||||
case GIT_EEXISTS:
|
||||
return PyExc_ValueError;
|
||||
|
||||
/** The given short oid is ambiguous */
|
||||
/* The given short oid is ambiguous */
|
||||
case GIT_EAMBIGUOUS:
|
||||
return PyExc_ValueError;
|
||||
|
||||
/** The buffer is too short to satisfy the request */
|
||||
/* The buffer is too short to satisfy the request */
|
||||
case GIT_EBUFS:
|
||||
return PyExc_ValueError;
|
||||
|
||||
/** Invalid input spec */
|
||||
/* Invalid input spec */
|
||||
case GIT_EINVALIDSPEC:
|
||||
return PyExc_ValueError;
|
||||
|
||||
/** Skip and passthrough the given ODB backend */
|
||||
/* Skip and passthrough the given ODB backend */
|
||||
case GIT_PASSTHROUGH:
|
||||
return GitError;
|
||||
|
||||
/** No entries left in ref walker */
|
||||
/* No entries left in ref walker */
|
||||
case GIT_ITEROVER:
|
||||
return PyExc_StopIteration;
|
||||
}
|
||||
|
||||
// Critical
|
||||
/* Critical */
|
||||
error = giterr_last();
|
||||
if (error != NULL) {
|
||||
switch (error->klass) {
|
||||
@ -107,7 +107,7 @@ PyObject* Error_set_str(int err, const char *str)
|
||||
}
|
||||
|
||||
error = giterr_last();
|
||||
if (error == NULL) //expected error - no error msg set
|
||||
if (error == NULL) /* Expected error - no error msg set */
|
||||
return PyErr_Format(Error_type(err), "%s", str);
|
||||
|
||||
return PyErr_Format(Error_type(err), "%s: %s", str, error->message);
|
||||
|
13
src/pygit2.c
13
src/pygit2.c
@ -168,7 +168,8 @@ hash(PyObject *self, PyObject *args)
|
||||
|
||||
|
||||
PyMethodDef module_methods[] = {
|
||||
{"init_repository", init_repository, METH_VARARGS|METH_KEYWORDS, init_repository__doc__},
|
||||
{"init_repository", init_repository, METH_VARARGS|METH_KEYWORDS,
|
||||
init_repository__doc__},
|
||||
{"discover_repository", discover_repository, METH_VARARGS,
|
||||
discover_repository__doc__},
|
||||
{"hashfile", hashfile, METH_VARARGS, hashfile__doc__},
|
||||
@ -337,19 +338,19 @@ moduleinit(PyObject* m)
|
||||
GIT_DIFF_RECURSE_UNTRACKED_DIRS);
|
||||
|
||||
/* Flags for diff find similar */
|
||||
// --find-renames
|
||||
/* --find-renames */
|
||||
PyModule_AddIntConstant(m, "GIT_DIFF_FIND_RENAMES",
|
||||
GIT_DIFF_FIND_RENAMES);
|
||||
// --break-rewrites=N
|
||||
/* --break-rewrites=N */
|
||||
PyModule_AddIntConstant(m, "GIT_DIFF_FIND_RENAMES_FROM_REWRITES",
|
||||
GIT_DIFF_FIND_RENAMES_FROM_REWRITES);
|
||||
// --find-copies
|
||||
/* --find-copies */
|
||||
PyModule_AddIntConstant(m, "GIT_DIFF_FIND_COPIES",
|
||||
GIT_DIFF_FIND_COPIES);
|
||||
// --find-copies-harder
|
||||
/* --find-copies-harder */
|
||||
PyModule_AddIntConstant(m, "GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED",
|
||||
GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED);
|
||||
// --break-rewrites=/M
|
||||
/* --break-rewrites=/M */
|
||||
PyModule_AddIntConstant(m, "GIT_DIFF_FIND_AND_BREAK_REWRITES",
|
||||
GIT_DIFF_FIND_AND_BREAK_REWRITES);
|
||||
|
||||
|
@ -76,8 +76,7 @@ PyObject* RefLogIter_iternext(PyObject *self)
|
||||
|
||||
if (signature != NULL)
|
||||
py_entry->committer = build_signature(
|
||||
(Object*)py_entry, signature, "utf-8"
|
||||
);
|
||||
(Object*)py_entry, signature, "utf-8");
|
||||
|
||||
++(p->i);
|
||||
|
||||
|
@ -156,7 +156,7 @@ Remote_fetchspec__set__(Remote *self, PyObject* py_tuple)
|
||||
if (!PyArg_ParseTuple(py_tuple, "ss", &src, &dst))
|
||||
return -1;
|
||||
|
||||
// length is strlen('+' + src + ':' + dst) and Null-Byte
|
||||
/* length is strlen('+' + src + ':' + dst) and Null-Byte */
|
||||
length = strlen(src) + strlen(dst) + 3;
|
||||
buf = (char*) calloc(length, sizeof(char));
|
||||
if (buf != NULL) {
|
||||
|
@ -858,11 +858,11 @@ Repository_create_reference(Repository *self, PyObject *args, PyObject *kw)
|
||||
|
||||
if (!symbolic) {
|
||||
err = py_str_to_git_oid_expand(self->repo, py_obj, &oid);
|
||||
if (err < 0) {
|
||||
if (err < 0)
|
||||
return Error_set(err);
|
||||
}
|
||||
|
||||
err = git_reference_create(&c_reference, self->repo, c_name, &oid, force);
|
||||
err = git_reference_create(&c_reference, self->repo, c_name, &oid,
|
||||
force);
|
||||
} else {
|
||||
#if PY_MAJOR_VERSION == 2
|
||||
c_target = PyString_AsString(py_obj);
|
||||
@ -981,7 +981,7 @@ Repository_TreeBuilder(Repository *self, PyObject *args)
|
||||
if (PyObject_TypeCheck(py_src, &TreeType)) {
|
||||
Tree *py_tree = (Tree *)py_src;
|
||||
if (py_tree->repo->repo != self->repo) {
|
||||
//return Error_set(GIT_EINVALIDARGS);
|
||||
/* return Error_set(GIT_EINVALIDARGS); */
|
||||
return Error_set(GIT_ERROR);
|
||||
}
|
||||
tree = py_tree->tree;
|
||||
@ -998,9 +998,8 @@ Repository_TreeBuilder(Repository *self, PyObject *args)
|
||||
}
|
||||
|
||||
err = git_treebuilder_create(&bld, tree);
|
||||
if (must_free != NULL) {
|
||||
if (must_free != NULL)
|
||||
git_tree_free(must_free);
|
||||
}
|
||||
|
||||
if (err < 0)
|
||||
return Error_set(err);
|
||||
@ -1090,7 +1089,7 @@ Repository_checkout(Repository *self, PyObject *args, PyObject *kw)
|
||||
&strategy, &ReferenceType, &ref, &head))
|
||||
return NULL;
|
||||
|
||||
if (ref != NULL) { // checkout from treeish
|
||||
if (ref != NULL) { /* checkout from treeish */
|
||||
id = git_reference_target(ref->reference);
|
||||
err = git_object_lookup(&object, self->repo, id, GIT_OBJ_COMMIT);
|
||||
if (err == GIT_OK) {
|
||||
@ -1101,7 +1100,7 @@ Repository_checkout(Repository *self, PyObject *args, PyObject *kw)
|
||||
git_reference_name(ref->reference));
|
||||
}
|
||||
}
|
||||
} else { // checkout from head / index
|
||||
} else { /* checkout from head / index */
|
||||
opts.checkout_strategy = strategy;
|
||||
err = (!head) ? git_checkout_index(self->repo, NULL, &opts) :
|
||||
git_checkout_head(self->repo, &opts);
|
||||
|
@ -282,7 +282,7 @@ Tree_getitem(Tree *self, PyObject *value)
|
||||
if (err < 0)
|
||||
return (TreeEntry*)Error_set(err);
|
||||
|
||||
// git_tree_entry_dup is already done in git_tree_entry_bypath
|
||||
/* git_tree_entry_dup is already done in git_tree_entry_bypath */
|
||||
return wrap_tree_entry(entry, self);
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,8 @@
|
||||
|
||||
extern PyTypeObject ReferenceType;
|
||||
|
||||
// py_str_to_c_str() returns a newly allocated C string holding
|
||||
// the string contained in the value argument.
|
||||
/* py_str_to_c_str() returns a newly allocated C string holding
|
||||
* the string contained in the value argument. */
|
||||
char * py_str_to_c_str(PyObject *value, const char *encoding)
|
||||
{
|
||||
/* Case 1: byte string */
|
||||
|
@ -30,8 +30,6 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
import unittest
|
||||
import tempfile
|
||||
import os
|
||||
|
||||
import pygit2
|
||||
from . import utils
|
||||
|
@ -98,9 +98,10 @@ class ConfigTest(utils.RepoTestCase):
|
||||
|
||||
self.assertRaises(TypeError, lambda: config[()])
|
||||
self.assertRaises(TypeError, lambda: config[-4])
|
||||
self.assertRaisesWithArg(ValueError,
|
||||
"Invalid config item name 'abc'", lambda: config['abc'])
|
||||
self.assertRaisesWithArg(KeyError, 'abc.def', lambda: config['abc.def'])
|
||||
self.assertRaisesWithArg(ValueError, "Invalid config item name 'abc'",
|
||||
lambda: config['abc'])
|
||||
self.assertRaisesWithArg(KeyError, 'abc.def',
|
||||
lambda: config['abc.def'])
|
||||
|
||||
self.assertTrue('core.bare' in config)
|
||||
self.assertFalse(config['core.bare'])
|
||||
|
@ -31,6 +31,7 @@ from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
import unittest
|
||||
import pygit2
|
||||
from pygit2 import GIT_DIFF_INCLUDE_UNMODIFIED
|
||||
from . import utils
|
||||
|
||||
|
||||
@ -201,8 +202,11 @@ class DiffTest(utils.BareRepoTestCase):
|
||||
commit_a = self.repo[COMMIT_SHA1_1]
|
||||
commit_b = self.repo[COMMIT_SHA1_2]
|
||||
diff = commit_a.tree.diff(commit_b.tree)
|
||||
self.assertEqual(diff.changes['hunks'][0].old_oid, '7f129fd57e31e935c6d60a0c794efe4e6927664b')
|
||||
self.assertEqual(diff.changes['hunks'][0].new_oid, 'af431f20fc541ed6d5afede3e2dc7160f6f01f16')
|
||||
hunk = diff.changes['hunks'][0]
|
||||
self.assertEqual(hunk.old_oid,
|
||||
'7f129fd57e31e935c6d60a0c794efe4e6927664b')
|
||||
self.assertEqual(hunk.new_oid,
|
||||
'af431f20fc541ed6d5afede3e2dc7160f6f01f16')
|
||||
|
||||
def test_find_similar(self):
|
||||
commit_a = self.repo[COMMIT_SHA1_4]
|
||||
@ -210,7 +214,7 @@ class DiffTest(utils.BareRepoTestCase):
|
||||
|
||||
#~ Must pass GIT_DIFF_INCLUDE_UNMODIFIED if you expect to emulate
|
||||
#~ --find-copies-harder during rename transformion...
|
||||
diff = commit_a.tree.diff(commit_b.tree, pygit2.GIT_DIFF_INCLUDE_UNMODIFIED)
|
||||
diff = commit_a.tree.diff(commit_b.tree, GIT_DIFF_INCLUDE_UNMODIFIED)
|
||||
self.assertFalse(('a', 'a.copy', 5, 100) in diff.changes['files'])
|
||||
diff.find_similar(pygit2.GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED)
|
||||
self.assertTrue(('a', 'a.copy', 5, 100) in diff.changes['files'])
|
||||
|
@ -49,7 +49,8 @@ class ReferencesTest(utils.RepoTestCase):
|
||||
['refs/heads/i18n', 'refs/heads/master'])
|
||||
|
||||
# We add a symbolic reference
|
||||
repo.create_reference('refs/tags/version1','refs/heads/master', symbolic=True)
|
||||
repo.create_reference('refs/tags/version1', 'refs/heads/master',
|
||||
symbolic=True)
|
||||
self.assertEqual(sorted(repo.listall_references()),
|
||||
['refs/heads/i18n', 'refs/heads/master',
|
||||
'refs/tags/version1'])
|
||||
@ -144,8 +145,9 @@ class ReferencesTest(utils.RepoTestCase):
|
||||
def test_reload(self):
|
||||
name = 'refs/tags/version1'
|
||||
|
||||
ref = self.repo.create_reference(name, "refs/heads/master", symbolic=True)
|
||||
ref2 = self.repo.lookup_reference(name)
|
||||
repo = self.repo
|
||||
ref = repo.create_reference(name, "refs/heads/master", symbolic=True)
|
||||
ref2 = repo.lookup_reference(name)
|
||||
ref.delete()
|
||||
self.assertEqual(ref2.name, name)
|
||||
self.assertRaises(KeyError, ref2.reload)
|
||||
@ -197,7 +199,8 @@ class ReferencesTest(utils.RepoTestCase):
|
||||
|
||||
# try to create existing symbolic reference
|
||||
self.assertRaises(ValueError, self.repo.create_reference,
|
||||
'refs/tags/beta','refs/heads/master', symbolic=True)
|
||||
'refs/tags/beta', 'refs/heads/master',
|
||||
symbolic=True)
|
||||
|
||||
# try to create existing symbolic reference with force
|
||||
reference = self.repo.create_reference('refs/tags/beta',
|
||||
|
@ -35,8 +35,8 @@ import tempfile
|
||||
import os
|
||||
from os.path import join, realpath
|
||||
|
||||
from pygit2 import GIT_OBJ_ANY, GIT_OBJ_BLOB, GIT_OBJ_COMMIT, init_repository, \
|
||||
discover_repository, Commit, hashfile
|
||||
from pygit2 import GIT_OBJ_ANY, GIT_OBJ_BLOB, GIT_OBJ_COMMIT
|
||||
from pygit2 import init_repository, discover_repository, Commit, hashfile
|
||||
import pygit2
|
||||
|
||||
from . import utils
|
||||
|
@ -45,8 +45,8 @@ class SignatureTest(NoRepoTestCase):
|
||||
self.assertEqual(signature.name.encode(encoding), signature._name)
|
||||
|
||||
def test_ascii(self):
|
||||
self.assertRaises(
|
||||
UnicodeEncodeError, Signature, 'Foo Ibáñez', 'foo@example.com')
|
||||
self.assertRaises(UnicodeEncodeError,
|
||||
Signature, 'Foo Ibáñez', 'foo@example.com')
|
||||
|
||||
def test_latin1(self):
|
||||
encoding = 'iso-8859-1'
|
||||
|
@ -63,7 +63,8 @@ def rmtree(path):
|
||||
So we implement our own version of rmtree to address this issue.
|
||||
"""
|
||||
if os.path.exists(path):
|
||||
shutil.rmtree(path, onerror=lambda func, path, e: force_rm_handle(func, path, e))
|
||||
onerror = lambda func, path, e: force_rm_handle(func, path, e)
|
||||
shutil.rmtree(path, onerror=onerror)
|
||||
|
||||
|
||||
class NoRepoTestCase(unittest.TestCase):
|
||||
|
Loading…
x
Reference in New Issue
Block a user