Commits

David Ibáñez committed 8d4c841

Use file system encoding to decode/encode paths

Instead of UTF-8. This is done for better interoperability with Git.

Comments (0)

Files changed (1)

 #define c_str_to_py_str(c_str) \
         PyUnicode_DecodeUTF8(c_str, strlen(c_str), "strict")
 
+#define py_path_to_c_str(py_path) \
+        py_str_to_c_str(py_path, Py_FileSystemDefaultEncoding)
+
+#define c_str_to_py_path(c_str) \
+        PyUnicode_Decode(c_str, strlen(c_str), \
+                         Py_FileSystemDefaultEncoding, "strict")
+
+
 static int
 Repository_init(Repository *self, PyObject *args, PyObject *kwds)
 {
     const char *c_path;
 
     c_path = git_repository_path(self->repo, GIT_REPO_PATH);
-    return c_str_to_py_str(c_path);
+    return c_str_to_py_path(c_path);
 }
 
 static PyObject *
     if (c_path == NULL)
         Py_RETURN_NONE;
 
-    return c_str_to_py_str(c_path);
+    return c_str_to_py_path(c_path);
 }
 
 static PyObject *
 
     /* 4- Fill it */
     for (index=0; index < c_result.count; index++) {
-        py_string = c_str_to_py_str((c_result.strings)[index]);
+        py_string = c_str_to_py_path((c_result.strings)[index]);
         if (py_string == NULL) {
             Py_XDECREF(py_result);
             git_strarray_free(&c_result);
     int err;
 
     /* 1- Get the C name */
-    c_name = py_str_to_c_str(py_name, NULL);
+    c_name = py_path_to_c_str(py_name);
     if (c_name == NULL)
         return NULL;
 
 static PyObject *
 TreeEntry_get_name(TreeEntry *self)
 {
-    return c_str_to_py_str(git_tree_entry_name(self->entry));
+    return c_str_to_py_path(git_tree_entry_name(self->entry));
 }
 
 static PyObject *
 {
     char *name;
 
-    name = py_str_to_c_str(py_name, NULL);
+    name = py_path_to_c_str(py_name);
     if (name == NULL)
         return -1;
 
         return Tree_getitem_by_index(self, value);
 
     /* Case 2: byte or text string */
-    name = py_str_to_c_str(value, NULL);
+    name = py_path_to_c_str(value);
     if (name == NULL)
         return NULL;
     entry = git_tree_entry_byname(self->tree, name);
     }
 
     /* Case 2: byte or text string */
-    path = py_str_to_c_str(value, NULL);
+    path = py_path_to_c_str(value);
     if (!path)
         return -1;
     idx = git_index_find(self->index, path);
     char *path;
     int idx;
 
-    path = py_str_to_c_str(value, NULL);
+    path = py_path_to_c_str(value);
     if (!path)
         return -1;
     idx = git_index_find(self->index, path);
 static PyObject *
 IndexEntry_get_path(IndexEntry *self)
 {
-    return c_str_to_py_str(self->entry->path);
+    return c_str_to_py_path(self->entry->path);
 }
 
 static PyObject *
     int err;
 
     /* 1- Get the C name */
-    c_name = py_str_to_c_str(py_name, NULL);
+    c_name = py_path_to_c_str(py_name);
     if (c_name == NULL)
         return NULL;
 
     }
 
     /* 2- Make a PyString and return it */
-    return c_str_to_py_str(c_name);
+    return c_str_to_py_path(c_name);
 }
 
 static int
     int err;
 
     /* 1- Get the C name */
-    c_name = py_str_to_c_str(py_name, NULL);
+    c_name = py_path_to_c_str(py_name);
     if (c_name == NULL)
         return -1;
 
     const char *c_name;
 
     c_name = git_reference_name(self->reference);
-    return c_str_to_py_str(c_name);
+    return c_str_to_py_path(c_name);
 }
 
 static PyObject *