Fix C implementation of parse_tree to return a dictionary.
authorJelmer Vernooij <jelmer@samba.org>
Thu, 30 Apr 2009 10:06:25 +0000 (10:08 +0002)
committerJelmer Vernooij <jelmer@samba.org>
Thu, 30 Apr 2009 10:06:25 +0000 (10:08 +0002)
Makefile
dulwich/_objects.c
dulwich/objects.py

index a65b20439d79c00d25fa5540e78ce002aaac79ea..516e41c3f30d6380f73f50fca422041ceb84bf2a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -14,5 +14,8 @@ install::
 check:: build
        PYTHONPATH=. $(TRIAL) dulwich
 
+check-noextensions:: clean
+       PYTHONPATH=. $(TRIAL) dulwich
+
 clean::
        $(SETUP) clean
index 121cec9fc33d9771c3216bb55b2e877dfad9a844..5689d56dc25ca37194e3182d893d7ede2c0017e6 100644 (file)
@@ -78,12 +78,12 @@ static PyObject *py_parse_tree(PyObject *self, PyObject *args)
 {
        char *text, *end;
        int len, namelen;
-       PyObject *ret, *item;
+       PyObject *ret, *item, *name;
 
        if (!PyArg_ParseTuple(args, "s#", &text, &len))
                return NULL;
 
-       ret = PyList_New(0);
+       ret = PyDict_New();
        if (ret == NULL) {
                return NULL;
        }
@@ -104,13 +104,19 @@ static PyObject *py_parse_tree(PyObject *self, PyObject *args)
 
         namelen = strlen(text);
 
-        item = Py_BuildValue("(ls#N)", mode, text, namelen, 
-                                                        sha_to_pyhex(text+namelen+1));
+               name = PyString_FromStringAndSize(text, namelen);
+               if (name == NULL) {
+                       Py_DECREF(ret);
+                       return NULL;
+               }
+
+        item = Py_BuildValue("(lN)", mode, sha_to_pyhex((unsigned char *)text+namelen+1));
         if (item == NULL) {
             Py_DECREF(ret);
+                       Py_DECREF(name);
             return NULL;
         }
-        PyList_Append(ret, item);
+               PyDict_SetItem(ret, name, item);
 
                text += namelen+21;
     }
index 3657029035db975c20b41b6699eee0c13a7b6da6..4f270a8fb9446cedaba6900e7196f25e56a72b46 100644 (file)
@@ -387,7 +387,8 @@ class Tree(ShaFile):
 
     def entries(self):
         """Return a list of tuples describing the tree entries"""
-        return [(mode, name, hexsha) for (name, (mode, hexsha)) in self._entries.iteritems()]
+        # The order of this is different from iteritems() for historical reasons
+        return [(mode, name, hexsha) for (name, mode, hexsha) in self.iteritems()]
 
     def iteritems(self):
         for name in sorted(self._entries.keys()):