subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmpil...@apache.org
Subject svn commit: r1465046 - /subversion/trunk/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
Date Fri, 05 Apr 2013 17:05:41 GMT
Author: cmpilato
Date: Fri Apr  5 17:05:40 2013
New Revision: 1465046

URL: http://svn.apache.org/r1465046
Log:
Abstract some common code into a helper function.

* subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
  (cstring_to_pystring): New helper function.
  (convert_svn_client_commit_item3_t): Use cstring_to_pystring() to
    avoid repetitious code.

Modified:
    subversion/trunk/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c

Modified: subversion/trunk/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c?rev=1465046&r1=1465045&r2=1465046&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c (original)
+++ subversion/trunk/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c Fri Apr
 5 17:05:40 2013
@@ -548,6 +548,19 @@ static PyObject *convert_svn_string_t(vo
   return PyString_FromStringAndSize((void *)s->data, s->len);
 }
 
+/* Convert a C string into a Python String object (or a reference to
+   Py_None if CSTRING is NULL). */
+static PyObject *cstring_to_pystring(const char *cstring)
+{
+  if (! cstring)
+    {
+      PyObject *retval = Py_None;
+      Py_INCREF(Py_None);
+      return retval;
+    }
+  return PyString_FromString(cstring);
+}
+
 static PyObject *convert_svn_client_commit_item3_t(void *value, void *ctx)
 {
   PyObject *list;
@@ -559,30 +572,9 @@ static PyObject *convert_svn_client_comm
 
   list = PyList_New(9);
 
-  if (item->path)
-    path = PyString_FromString(item->path);
-  else
-    {
-      path = Py_None;
-      Py_INCREF(Py_None);
-    }
-
-  if (item->url)
-    url = PyString_FromString(item->url);
-  else
-    {
-      url = Py_None;
-      Py_INCREF(Py_None);
-    }
-
-  if (item->copyfrom_url)
-    cf_url = PyString_FromString(item->copyfrom_url);
-  else
-    {
-      cf_url = Py_None;
-      Py_INCREF(Py_None);
-    }
-
+  path = cstring_to_pystring(item->path);
+  url = cstring_to_pystring(item->url);
+  cf_url = cstring_to_pystring(item->copyfrom_url);
   kind = PyInt_FromLong(item->kind);
   rev = PyInt_FromLong(item->revision);
   cf_rev = PyInt_FromLong(item->copyfrom_rev);



Mime
View raw message