Commits

Dave Borowitz  committed fe39b53

Factor out a helper function for initializing Objects.

Change-Id: Ibf1585bbd4fd5adfb835e34d02fc6186a97d1cd9

  • Participants
  • Parent commits 3fa91b9

Comments (0)

Files changed (1)

 };
 
 static int
-Commit_init(Commit *py_commit, PyObject *args, PyObject **kwds) {
-    Repository *repo = NULL;
-    git_commit *commit;
-
+object_init_check(const char *type_name, PyObject *args, PyObject *kwds,
+                  Repository **repo) {
     if (kwds) {
-        PyErr_SetString(PyExc_TypeError, "Commit takes no keyword arugments");
-        return -1;
+        PyErr_Format(PyExc_TypeError, "%s takes no keyword arugments",
+                     type_name);
+        return 0;
     }
 
-    if (!PyArg_ParseTuple(args, "O", &repo))
-        return -1;
+    if (!PyArg_ParseTuple(args, "O", repo))
+        return 0;
 
-    if (!PyObject_TypeCheck(repo, &RepositoryType)) {
+    if (!PyObject_TypeCheck(*repo, &RepositoryType)) {
         PyErr_SetString(PyExc_TypeError, "Expected Repository for repo");
-        return -1;
+        return 0;
     }
+    return 1;
+}
+
+static int
+Commit_init(Commit *py_commit, PyObject *args, PyObject *kwds) {
+    Repository *repo = NULL;
+    git_commit *commit;
+
+    if (!object_init_check("Commit", args, kwds, &repo))
+        return -1;
 
     commit = git_commit_new(repo->repo);
     if (!commit) {