From a96d49474715220477d06a18be30e386d0e215eb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=2E=20David=20Ib=C3=A1=C3=B1ez?= <jdavid.ibp@gmail.com>
Date: Sat, 2 Mar 2013 11:40:42 +0100
Subject: [PATCH] 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: //
---
 docs/install.rst            |  7 ++--
 docs/objects.rst            | 11 +------
 include/pygit2/repository.h |  8 +++--
 include/pygit2/signature.h  |  5 ++-
 include/pygit2/types.h      |  4 ++-
 setup.py                    | 16 +++++----
 src/config.c                | 26 +++++++--------
 src/diff.c                  | 20 +++++-------
 src/error.c                 | 22 ++++++-------
 src/index.c                 |  4 +--
 src/pygit2.c                | 65 +++++++++++++++++++------------------
 src/reference.c             |  7 ++--
 src/remote.c                | 46 +++++++++++++-------------
 src/repository.c            | 27 ++++++++-------
 src/tree.c                  |  2 +-
 src/utils.c                 |  4 +--
 test/test_blob.py           |  2 --
 test/test_config.py         | 13 ++++----
 test/test_diff.py           | 56 +++++++++++++++++---------------
 test/test_refs.py           | 11 ++++---
 test/test_remote.py         |  4 +--
 test/test_repository.py     |  6 ++--
 test/test_revwalk.py        | 22 ++++++-------
 test/test_signature.py      |  4 +--
 test/test_status.py         | 44 ++++++++++++-------------
 test/utils.py               |  3 +-
 26 files changed, 223 insertions(+), 216 deletions(-)

diff --git a/docs/install.rst b/docs/install.rst
index 8bf6bcd..aacad2f 100644
--- a/docs/install.rst
+++ b/docs/install.rst
@@ -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::
 
diff --git a/docs/objects.rst b/docs/objects.rst
index fbbf960..3ceb317 100644
--- a/docs/objects.rst
+++ b/docs/objects.rst
@@ -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:
 
diff --git a/include/pygit2/repository.h b/include/pygit2/repository.h
index 0f6616a..2a35a43 100644
--- a/include/pygit2/repository.h
+++ b/include/pygit2/repository.h
@@ -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);
diff --git a/include/pygit2/signature.h b/include/pygit2/signature.h
index 10fbe7e..5c705b8 100644
--- a/include/pygit2/signature.h
+++ b/include/pygit2/signature.h
@@ -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
diff --git a/include/pygit2/types.h b/include/pygit2/types.h
index 834d6a8..735f5d8 100644
--- a/include/pygit2/types.h
+++ b/include/pygit2/types.h
@@ -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
diff --git a/setup.py b/setup.py
index 160d65d..214b9ce 100644
--- a/setup.py
+++ b/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:
-        #python setup.py test --args="-v -f"
-        #can be executed, and the parameter '-v -f' can be
-        #transfering to unittest properly.
+        # 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.
         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:
diff --git a/src/config.c b/src/config.c
index 687acbd..c4c2604 100644
--- a/src/config.c
+++ b/src/config.c
@@ -152,7 +152,7 @@ Config_contains(Config *self, PyObject *py_key) {
     const char *c_value;
     char *c_key;
 
-    c_key = py_str_to_c_str(py_key,NULL);
+    c_key = py_str_to_c_str(py_key, NULL);
     if (c_key == NULL)
         return -1;
 
@@ -177,7 +177,7 @@ Config_getitem(Config *self, PyObject *py_key)
     const char *c_charvalue;
     char *c_key;
 
-    if (!(c_key = py_str_to_c_str(py_key,NULL)))
+    if (!(c_key = py_str_to_c_str(py_key, NULL)))
         return NULL;
 
     err = git_config_get_int64(&c_intvalue, self->config, c_key);
@@ -212,7 +212,7 @@ Config_setitem(Config *self, PyObject *py_key, PyObject *py_value)
     char *c_key;
     char *py_str;
 
-    if (!(c_key = py_str_to_c_str(py_key,NULL)))
+    if (!(c_key = py_str_to_c_str(py_key, NULL)))
         return -1;
 
     if (!py_value) {
@@ -225,7 +225,7 @@ Config_setitem(Config *self, PyObject *py_key, PyObject *py_value)
                 (int64_t)PyInt_AsLong(py_value));
     } else {
         py_value = PyObject_Str(py_value);
-        py_str = py_str_to_c_str(py_value,NULL);
+        py_str = py_str_to_c_str(py_value, NULL);
         err = git_config_set_string(self->config, c_key, py_str);
         free(py_str);
     }
@@ -257,7 +257,7 @@ Config_foreach_callback_wrapper(const git_config_entry *entry, void *c_payload)
     if (!args)
         return -1;
 
-    if (!(py_result = PyObject_CallObject(py_callback,args)))
+    if (!(py_result = PyObject_CallObject(py_callback, args)))
         return -1;
 
     if ((c_result = PyLong_AsLong(py_result) == -1))
@@ -415,14 +415,14 @@ PyMethodDef Config_methods[] = {
 };
 
 PySequenceMethods Config_as_sequence = {
-    0,                          /* sq_length */
-    0,                          /* sq_concat */
-    0,                          /* sq_repeat */
-    0,                          /* sq_item */
-    0,                          /* sq_slice */
-    0,                          /* sq_ass_item */
-    0,                          /* sq_ass_slice */
-    (objobjproc)Config_contains,/* sq_contains */
+    0,                               /* sq_length */
+    0,                               /* sq_concat */
+    0,                               /* sq_repeat */
+    0,                               /* sq_item */
+    0,                               /* sq_slice */
+    0,                               /* sq_ass_item */
+    0,                               /* sq_ass_slice */
+    (objobjproc)Config_contains,     /* sq_contains */
 };
 
 PyMappingMethods Config_as_mapping = {
diff --git a/src/diff.c b/src/diff.c
index 581388e..4b3732e 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -54,12 +54,12 @@ static int diff_data_cb(
 
     hunks = PyDict_GetItemString(cb_data, "hunks");
     if (hunks == NULL)
-      return -1;
+        return -1;
 
     size = PyList_Size(hunks);
     hunk = (Hunk *)PyList_GetItem(hunks, size - 1);
     if (hunk == NULL)
-      return -1;
+        return -1;
 
     data = Py_BuildValue("(s#,i)",
         content, content_len,
@@ -149,11 +149,10 @@ static int diff_hunk_cb(
         hunk->new_file = "";
     }
 
-    if (hunk->data == NULL) {
-      hunk->data = PyList_New(0);
-    }
+    if (hunk->data == NULL)
+        hunk->data = PyList_New(0);
 
-    if(PyList_Append(hunks, (PyObject *)hunk) == 0) {
+    if (PyList_Append(hunks, (PyObject *)hunk) == 0) {
         Py_DECREF(hunk);
     }
     else {
@@ -168,10 +167,10 @@ diff_file_cb(const git_diff_delta *delta, float progress, void *cb_data)
 {
     PyObject *files, *file;
 
-    if(delta->old_file.path != NULL && delta->new_file.path != NULL) {
+    if (delta->old_file.path != NULL && delta->new_file.path != NULL) {
         files = PyDict_GetItemString(cb_data, "files");
 
-        if(files == NULL) {
+        if (files == NULL) {
             files = PyList_New(0);
             PyDict_SetItemString(cb_data, "files", files);
             Py_DECREF(files);
@@ -184,10 +183,9 @@ 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;
diff --git a/src/error.c b/src/error.c
index 6514b6a..ce1a053 100644
--- a/src/error.c
+++ b/src/error.c
@@ -32,40 +32,40 @@ 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) {
+    if (error != NULL) {
         switch (error->klass) {
             case GITERR_NOMEMORY:
                 return PyExc_MemoryError;
@@ -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);
diff --git a/src/index.c b/src/index.c
index 1a6d3ac..410c460 100644
--- a/src/index.c
+++ b/src/index.c
@@ -371,8 +371,8 @@ Index_setitem(Index *self, PyObject *key, PyObject *value)
         return -1;
     }
 
-    if(Index_remove(self, Py_BuildValue("(N)", key)) == NULL)
-      return -1;
+    if (Index_remove(self, Py_BuildValue("(N)", key)) == NULL)
+        return -1;
 
     return 0;
 }
diff --git a/src/pygit2.c b/src/pygit2.c
index 54860b9..dee0e64 100644
--- a/src/pygit2.c
+++ b/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);
 
@@ -427,32 +428,32 @@ moduleinit(PyObject* m)
 
 
 #if PY_MAJOR_VERSION < 3
-  PyMODINIT_FUNC
-  init_pygit2(void)
-  {
-      PyObject* m;
-      m = Py_InitModule3("_pygit2", module_methods,
-                         "Python bindings for libgit2.");
-      moduleinit(m);
-  }
+    PyMODINIT_FUNC
+    init_pygit2(void)
+    {
+        PyObject* m;
+        m = Py_InitModule3("_pygit2", module_methods,
+                           "Python bindings for libgit2.");
+        moduleinit(m);
+    }
 #else
-  struct PyModuleDef moduledef = {
-      PyModuleDef_HEAD_INIT,
-      "_pygit2",                        /* m_name */
-      "Python bindings for libgit2.",  /* m_doc */
-      -1,                              /* m_size */
-      module_methods,                  /* m_methods */
-      NULL,                            /* m_reload */
-      NULL,                            /* m_traverse */
-      NULL,                            /* m_clear */
-      NULL,                            /* m_free */
-  };
+    struct PyModuleDef moduledef = {
+        PyModuleDef_HEAD_INIT,
+        "_pygit2",                       /* m_name */
+        "Python bindings for libgit2.",  /* m_doc */
+        -1,                              /* m_size */
+        module_methods,                  /* m_methods */
+        NULL,                            /* m_reload */
+        NULL,                            /* m_traverse */
+        NULL,                            /* m_clear */
+        NULL,                            /* m_free */
+    };
 
-  PyMODINIT_FUNC
-  PyInit__pygit2(void)
-  {
-      PyObject* m;
-      m = PyModule_Create(&moduledef);
-      return moduleinit(m);
-  }
+    PyMODINIT_FUNC
+    PyInit__pygit2(void)
+    {
+        PyObject* m;
+        m = PyModule_Create(&moduledef);
+        return moduleinit(m);
+    }
 #endif
diff --git a/src/reference.c b/src/reference.c
index 7695540..a1d9ca9 100644
--- a/src/reference.c
+++ b/src/reference.c
@@ -74,10 +74,9 @@ PyObject* RefLogIter_iternext(PyObject *self)
               git_reflog_entry_committer(entry)
             );
 
-        if(signature != NULL)
-          py_entry->committer = build_signature(
-                (Object*)py_entry, signature, "utf-8"
-              );
+        if (signature != NULL)
+            py_entry->committer = build_signature(
+                (Object*)py_entry, signature, "utf-8");
 
         ++(p->i);
 
diff --git a/src/remote.c b/src/remote.c
index b7a6f08..0baae3e 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -156,8 +156,8 @@ 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 = strlen(src) + strlen(dst) + 3; 
+    /* length is strlen('+' + src + ':' + dst) and Null-Byte */
+    length = strlen(src) + strlen(dst) + 3;
     buf = (char*) calloc(length, sizeof(char));
     if (buf != NULL) {
         sprintf(buf, "+%s:%s", src, dst);
@@ -165,7 +165,7 @@ Remote_fetchspec__set__(Remote *self, PyObject* py_tuple)
         free(buf);
 
         if (err == GIT_OK)
-          return 0;
+            return 0;
 
         Error_set_exc(PyExc_ValueError);
     }
@@ -184,29 +184,29 @@ PyDoc_STRVAR(Remote_fetch__doc__,
 PyObject *
 Remote_fetch(Remote *self, PyObject *args)
 {
-  PyObject* py_stats = NULL;
-  const git_transfer_progress *stats;
-  int err;
+    PyObject* py_stats = NULL;
+    const git_transfer_progress *stats;
+    int err;
 
-  err = git_remote_connect(self->remote, GIT_DIRECTION_FETCH);
-  if (err == GIT_OK) {
-      err = git_remote_download(self->remote, NULL, NULL);
-      if (err == GIT_OK) {
-          stats = git_remote_stats(self->remote);
-          py_stats = Py_BuildValue("{s:I,s:I,s:n}",
-              "indexed_objects", stats->indexed_objects,
-              "received_objects", stats->received_objects,
-              "received_bytes", stats->received_bytes);
+    err = git_remote_connect(self->remote, GIT_DIRECTION_FETCH);
+    if (err == GIT_OK) {
+        err = git_remote_download(self->remote, NULL, NULL);
+        if (err == GIT_OK) {
+            stats = git_remote_stats(self->remote);
+            py_stats = Py_BuildValue("{s:I,s:I,s:n}",
+                "indexed_objects", stats->indexed_objects,
+                "received_objects", stats->received_objects,
+                "received_bytes", stats->received_bytes);
 
-          err = git_remote_update_tips(self->remote);
-      }
-      git_remote_disconnect(self->remote);
-  }
+            err = git_remote_update_tips(self->remote);
+        }
+        git_remote_disconnect(self->remote);
+    }
 
-  if (err < 0)
-    return Error_set(err);
+    if (err < 0)
+        return Error_set(err);
 
-  return (PyObject*) py_stats;
+    return (PyObject*) py_stats;
 }
 
 
@@ -239,7 +239,7 @@ PyTypeObject RemoteType = {
     0,                                         /* tp_as_sequence    */
     0,                                         /* tp_as_mapping     */
     0,                                         /* tp_hash           */
-    (ternaryfunc) Remote_call,                               /* tp_call           */
+    (ternaryfunc) Remote_call,                 /* tp_call           */
     0,                                         /* tp_str            */
     0,                                         /* tp_getattro       */
     0,                                         /* tp_setattro       */
diff --git a/src/repository.c b/src/repository.c
index b187ab6..7c2784b 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -209,8 +209,8 @@ Repository_head__get__(Repository *self)
     int err;
 
     err = git_repository_head(&head, self->repo);
-    if(err < 0) {
-        if(err == GIT_ENOTFOUND)
+    if (err < 0) {
+        if (err == GIT_ENOTFOUND)
             PyErr_SetString(GitError, "head reference does not exist");
         else
             Error_set(err);
@@ -856,20 +856,20 @@ Repository_create_reference(Repository *self,  PyObject *args, PyObject *kw)
                                      &c_name, &py_obj, &force, &symbolic))
         return NULL;
 
-    if(!symbolic) {
+    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);
         #else
         c_target = PyString_AsString(PyUnicode_AsASCIIString(py_obj));
         #endif
-        if(c_target == NULL)
+        if (c_target == NULL)
             return NULL;
 
         err = git_reference_symbolic_create(&c_reference, self->repo, c_name,
@@ -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,10 +1089,10 @@ 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) {
+        if (err == GIT_OK) {
             opts.checkout_strategy = strategy;
             err = git_checkout_tree(self->repo, object, &opts);
             if (err == GIT_OK) {
@@ -1101,13 +1100,13 @@ 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);
     }
 
-    if(err < 0)
+    if (err < 0)
         return Error_set(err);
 
     Py_RETURN_NONE;
diff --git a/src/tree.c b/src/tree.c
index 6514ecd..7e1bc0d 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -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);
 }
 
diff --git a/src/utils.c b/src/utils.c
index 9aa46ef..8ce23cb 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -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 */
diff --git a/test/test_blob.py b/test/test_blob.py
index 133ea7b..c6ded53 100644
--- a/test/test_blob.py
+++ b/test/test_blob.py
@@ -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
diff --git a/test/test_config.py b/test/test_config.py
index d5981ae..e5b5acc 100644
--- a/test/test_config.py
+++ b/test/test_config.py
@@ -78,7 +78,7 @@ class ConfigTest(utils.RepoTestCase):
         self.assertFalse(config_read['core.bare'])
         self.assertTrue('core.editor' in config_read)
         self.assertEqual(config_read['core.editor'], 'ed')
-        
+
     def test_add(self):
         config = pygit2.Config()
 
@@ -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'])
@@ -117,7 +118,7 @@ class ConfigTest(utils.RepoTestCase):
         self.assertTrue('this.that' in config)
         self.assertEqual(len(config.get_multivar('this.that')), 2)
         l = config.get_multivar('this.that', 'bar')
-        self.assertEqual(len(l),1)
+        self.assertEqual(len(l), 1)
         self.assertEqual(l[0], 'foobar')
 
     def test_write(self):
@@ -156,7 +157,7 @@ class ConfigTest(utils.RepoTestCase):
         self.assertTrue('this.that' in config)
         config.set_multivar('this.that', '^.*beer', 'fool')
         l = config.get_multivar('this.that', 'fool')
-        self.assertEqual(len(l),1)
+        self.assertEqual(len(l), 1)
         self.assertEqual(l[0], 'fool')
         config.set_multivar('this.that', 'foo.*', '123456')
         l = config.get_multivar('this.that', 'foo.*')
diff --git a/test/test_diff.py b/test/test_diff.py
index e79ddf2..106ac62 100644
--- a/test/test_diff.py
+++ b/test/test_diff.py
@@ -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
 
 
@@ -57,26 +58,26 @@ index 297efb8..0000000
 """
 
 DIFF_INDEX_EXPECTED = [
-  'staged_changes',
-  'staged_changes_file_deleted',
-  'staged_changes_file_modified',
-  'staged_delete',
-  'staged_delete_file_modified',
-  'staged_new',
-  'staged_new_file_deleted',
-  'staged_new_file_modified'
+    'staged_changes',
+    'staged_changes_file_deleted',
+    'staged_changes_file_modified',
+    'staged_delete',
+    'staged_delete_file_modified',
+    'staged_new',
+    'staged_new_file_deleted',
+    'staged_new_file_modified'
 ]
 
 DIFF_WORKDIR_EXPECTED = [
-  'file_deleted',
-  'modified_file',
-  'staged_changes',
-  'staged_changes_file_deleted',
-  'staged_changes_file_modified',
-  'staged_delete',
-  'staged_delete_file_modified',
-  'subdir/deleted_file',
-  'subdir/modified_file'
+    'file_deleted',
+    'modified_file',
+    'staged_changes',
+    'staged_changes_file_deleted',
+    'staged_changes_file_modified',
+    'staged_delete',
+    'staged_delete_file_modified',
+    'subdir/deleted_file',
+    'subdir/modified_file'
 ]
 
 class DiffDirtyTest(utils.DirtyRepoTestCase):
@@ -120,7 +121,7 @@ class DiffTest(utils.BareRepoTestCase):
         # self.assertIsNotNone is 2.7 only
         self.assertTrue(diff is not None)
         # self.assertIn is 2.7 only
-        self.assertTrue(('a','a', 3, 0) in diff.changes['files'])
+        self.assertTrue(('a', 'a', 3, 0) in diff.changes['files'])
         self.assertEqual(2, len(diff.changes['hunks']))
 
         hunk = diff.changes['hunks'][0]
@@ -140,7 +141,7 @@ class DiffTest(utils.BareRepoTestCase):
         commit_d = self.repo[COMMIT_SHA1_4]
 
         for opt in [pygit2.GIT_DIFF_IGNORE_WHITESPACE,
-                pygit2.GIT_DIFF_IGNORE_WHITESPACE_EOL]:
+                    pygit2.GIT_DIFF_IGNORE_WHITESPACE_EOL]:
             diff = commit_c.tree.diff(commit_d.tree, opt)
             self.assertTrue(diff is not None)
             self.assertEqual(0, len(diff.changes.get('hunks', list())))
@@ -163,13 +164,13 @@ class DiffTest(utils.BareRepoTestCase):
         self.assertTrue(diff_c is not None)
 
         # assertIn / assertNotIn are 2.7 only
-        self.assertTrue(('b','b', 3, 0) not in diff_b.changes['files'])
-        self.assertTrue(('b','b', 3, 0) in diff_c.changes['files'])
+        self.assertTrue(('b', 'b', 3, 0) not in diff_b.changes['files'])
+        self.assertTrue(('b', 'b', 3, 0) in diff_c.changes['files'])
 
         diff_b.merge(diff_c)
 
         # assertIn is 2.7 only
-        self.assertTrue(('b','b', 3, 0) in diff_b.changes['files'])
+        self.assertTrue(('b', 'b', 3, 0) in diff_b.changes['files'])
 
         hunk = diff_b.changes['hunks'][1]
         self.assertEqual(hunk.old_start, 1)
@@ -201,16 +202,19 @@ 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]
         commit_b = self.repo[COMMIT_SHA1_5]
-        
+
         #~ 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'])
diff --git a/test/test_refs.py b/test/test_refs.py
index 082e53d..803a901 100644
--- a/test/test_refs.py
+++ b/test/test_refs.py
@@ -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',
diff --git a/test/test_remote.py b/test/test_remote.py
index 0a156c4..6c66ea1 100644
--- a/test/test_remote.py
+++ b/test/test_remote.py
@@ -49,7 +49,7 @@ class RepositoryTest(utils.RepoTestCase):
         self.assertEqual(name, remote.name)
         self.assertEqual(url, remote.url)
 
-        self.assertRaises(ValueError,self.repo.create_remote, *(name, url))
+        self.assertRaises(ValueError, self.repo.create_remote, *(name, url))
 
 
     def test_remote_rename(self):
@@ -79,7 +79,7 @@ class RepositoryTest(utils.RepoTestCase):
         self.assertEqual(REMOTE_FETCHSPEC_SRC, remote.fetchspec[0])
         self.assertEqual(REMOTE_FETCHSPEC_DST, remote.fetchspec[1])
 
-        new_fetchspec = ('refs/foo/*','refs/remotes/foo/*')
+        new_fetchspec = ('refs/foo/*', 'refs/remotes/foo/*')
         remote.fetchspec = new_fetchspec
         self.assertEqual(new_fetchspec[0], remote.fetchspec[0])
         self.assertEqual(new_fetchspec[1], remote.fetchspec[1])
diff --git a/test/test_repository.py b/test/test_repository.py
index c874a00..484c531 100644
--- a/test/test_repository.py
+++ b/test/test_repository.py
@@ -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
@@ -260,7 +260,7 @@ class InitRepositoryTest(utils.NoRepoTestCase):
 class DiscoverRepositoryTest(utils.NoRepoTestCase):
     def test_discover_repo(self):
         repo = init_repository(self._temp_dir, False)
-        subdir = os.path.join(self._temp_dir, "test1","test2")
+        subdir = os.path.join(self._temp_dir, "test1", "test2")
         os.makedirs(subdir)
         self.assertEqual(repo.path, discover_repository(subdir))
 
diff --git a/test/test_revwalk.py b/test/test_revwalk.py
index 1b6a083..caab356 100644
--- a/test/test_revwalk.py
+++ b/test/test_revwalk.py
@@ -44,23 +44,23 @@ log = [
     'acecd5ea2924a4b900e7e149496e1f4b57976e51']
 
 REVLOGS = [
-  ('Nico von Geyso','checkout: moving from i18n to master'),
-  ('Nico von Geyso','commit: added bye.txt and new'),
-  ('Nico von Geyso','checkout: moving from master to i18n'),
-  ('J. David Ibañez', 'merge i18n: Merge made by recursive.'),
-  ('J. David Ibañez', 'commit: Add .gitignore file'),
-  ('J. David Ibañez', 'checkout: moving from i18n to master'),
-  ('J. David Ibañez', 'commit: Say hello in French'),
-  ('J. David Ibañez', 'commit: Say hello in Spanish'),
-  ('J. David Ibañez', 'checkout: moving from master to i18n'),
-  ('J. David Ibañez', 'commit (initial): First commit')
+    ('Nico von Geyso', 'checkout: moving from i18n to master'),
+    ('Nico von Geyso', 'commit: added bye.txt and new'),
+    ('Nico von Geyso', 'checkout: moving from master to i18n'),
+    ('J. David Ibañez', 'merge i18n: Merge made by recursive.'),
+    ('J. David Ibañez', 'commit: Add .gitignore file'),
+    ('J. David Ibañez', 'checkout: moving from i18n to master'),
+    ('J. David Ibañez', 'commit: Say hello in French'),
+    ('J. David Ibañez', 'commit: Say hello in Spanish'),
+    ('J. David Ibañez', 'checkout: moving from master to i18n'),
+    ('J. David Ibañez', 'commit (initial): First commit')
 ]
 
 
 class RevlogTestTest(utils.RepoTestCase):
     def test_log(self):
         ref = self.repo.lookup_reference('HEAD')
-        for i,entry in enumerate(ref.log()):
+        for i, entry in enumerate(ref.log()):
             self.assertEqual(entry.committer.name, REVLOGS[i][0])
             self.assertEqual(entry.message, REVLOGS[i][1])
 
diff --git a/test/test_signature.py b/test/test_signature.py
index 2917a49..9ee80a8 100644
--- a/test/test_signature.py
+++ b/test/test_signature.py
@@ -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'
diff --git a/test/test_status.py b/test/test_status.py
index e6780a4..73a8127 100644
--- a/test/test_status.py
+++ b/test/test_status.py
@@ -36,38 +36,38 @@ from . import utils
 
 
 EXPECTED = {
- "current_file":                    pygit2.GIT_STATUS_CURRENT,
- "file_deleted":                    pygit2.GIT_STATUS_WT_DELETED,
- "modified_file":                   pygit2.GIT_STATUS_WT_MODIFIED,
- "new_file":                        pygit2.GIT_STATUS_WT_NEW,
+    "current_file":                    pygit2.GIT_STATUS_CURRENT,
+    "file_deleted":                    pygit2.GIT_STATUS_WT_DELETED,
+    "modified_file":                   pygit2.GIT_STATUS_WT_MODIFIED,
+    "new_file":                        pygit2.GIT_STATUS_WT_NEW,
 
- "staged_changes":                  pygit2.GIT_STATUS_INDEX_MODIFIED,
- "staged_changes_file_deleted":     pygit2.GIT_STATUS_INDEX_MODIFIED |
-                                    pygit2.GIT_STATUS_WT_DELETED,
- "staged_changes_file_modified":    pygit2.GIT_STATUS_INDEX_MODIFIED |
-                                    pygit2.GIT_STATUS_WT_MODIFIED,
+    "staged_changes":                  pygit2.GIT_STATUS_INDEX_MODIFIED,
+    "staged_changes_file_deleted":     pygit2.GIT_STATUS_INDEX_MODIFIED |
+                                       pygit2.GIT_STATUS_WT_DELETED,
+    "staged_changes_file_modified":    pygit2.GIT_STATUS_INDEX_MODIFIED |
+                                       pygit2.GIT_STATUS_WT_MODIFIED,
 
- "staged_delete":                   pygit2.GIT_STATUS_INDEX_DELETED,
- "staged_delete_file_modified":     pygit2.GIT_STATUS_INDEX_DELETED |
-                                    pygit2.GIT_STATUS_WT_NEW,
- "staged_new":                      pygit2.GIT_STATUS_INDEX_NEW,
+    "staged_delete":                   pygit2.GIT_STATUS_INDEX_DELETED,
+    "staged_delete_file_modified":     pygit2.GIT_STATUS_INDEX_DELETED |
+                                       pygit2.GIT_STATUS_WT_NEW,
+    "staged_new":                      pygit2.GIT_STATUS_INDEX_NEW,
 
- "staged_new_file_deleted":         pygit2.GIT_STATUS_INDEX_NEW |
-                                    pygit2.GIT_STATUS_WT_DELETED,
- "staged_new_file_modified":        pygit2.GIT_STATUS_INDEX_NEW |
-                                    pygit2.GIT_STATUS_WT_MODIFIED,
+    "staged_new_file_deleted":         pygit2.GIT_STATUS_INDEX_NEW |
+                                       pygit2.GIT_STATUS_WT_DELETED,
+    "staged_new_file_modified":        pygit2.GIT_STATUS_INDEX_NEW |
+                                       pygit2.GIT_STATUS_WT_MODIFIED,
 
- "subdir/current_file":             pygit2.GIT_STATUS_CURRENT,
- "subdir/deleted_file":             pygit2.GIT_STATUS_WT_DELETED,
- "subdir/modified_file":            pygit2.GIT_STATUS_WT_MODIFIED,
- "subdir/new_file":                 pygit2.GIT_STATUS_WT_NEW,
+    "subdir/current_file":             pygit2.GIT_STATUS_CURRENT,
+    "subdir/deleted_file":             pygit2.GIT_STATUS_WT_DELETED,
+    "subdir/modified_file":            pygit2.GIT_STATUS_WT_MODIFIED,
+    "subdir/new_file":                 pygit2.GIT_STATUS_WT_NEW,
 }
 
 class StatusTest(utils.DirtyRepoTestCase):
 
     def test_status(self):
         """
-            For every file in the status, check that the flags are correct.
+        For every file in the status, check that the flags are correct.
         """
         git_status = self.repo.status()
         for filepath, status in git_status.items():
diff --git a/test/utils.py b/test/utils.py
index 760930d..c3595b7 100644
--- a/test/utils.py
+++ b/test/utils.py
@@ -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):