Browse Source

Fix C implementation of parse_tree to return a dictionary.

Jelmer Vernooij 16 years ago
parent
commit
f2c2516fed
3 changed files with 16 additions and 6 deletions
  1. 3 0
      Makefile
  2. 11 5
      dulwich/_objects.c
  3. 2 1
      dulwich/objects.py

+ 3 - 0
Makefile

@@ -14,5 +14,8 @@ install::
 check:: build
 	PYTHONPATH=. $(TRIAL) dulwich
 
+check-noextensions:: clean
+	PYTHONPATH=. $(TRIAL) dulwich
+
 clean::
 	$(SETUP) clean

+ 11 - 5
dulwich/_objects.c

@@ -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;
     }

+ 2 - 1
dulwich/objects.py

@@ -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()):