Clean up and simplify read-tree a bit.
authorLinus Torvalds <torvalds@ppc970.osdl.org>
Fri, 22 Apr 2005 23:35:06 +0000 (16:35 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Fri, 22 Apr 2005 23:35:06 +0000 (16:35 -0700)
This is preparation for moving parts of it into "tree.c" to be used
as a library function.

read-tree.c

index 8121e30..345d576 100644 (file)
@@ -23,12 +23,9 @@ static int read_one_entry(unsigned char *sha1, const char *base, int baselen, co
        return add_cache_entry(ce, 1);
 }
 
        return add_cache_entry(ce, 1);
 }
 
-static int read_tree_recursive(void *buffer, const char *type,
-                              unsigned long size,
+static int read_tree_recursive(void *buffer, unsigned long size,
                               const char *base, int baselen)
 {
                               const char *base, int baselen)
 {
-       if (!buffer || strcmp(type, "tree"))
-               return -1;
        while (size) {
                int len = strlen(buffer)+1;
                unsigned char *sha1 = buffer + len;
        while (size) {
                int len = strlen(buffer)+1;
                unsigned char *sha1 = buffer + len;
@@ -50,12 +47,12 @@ static int read_tree_recursive(void *buffer, const char *type,
                        unsigned long eltsize;
 
                        eltbuf = read_sha1_file(sha1, elttype, &eltsize);
                        unsigned long eltsize;
 
                        eltbuf = read_sha1_file(sha1, elttype, &eltsize);
-                       if (!eltbuf)
+                       if (!eltbuf || strcmp(elttype, "tree"))
                                return -1;
                        memcpy(newbase, base, baselen);
                        memcpy(newbase + baselen, path, pathlen);
                        newbase[baselen + pathlen] = '/';
                                return -1;
                        memcpy(newbase, base, baselen);
                        memcpy(newbase + baselen, path, pathlen);
                        newbase[baselen + pathlen] = '/';
-                       retval = read_tree_recursive(eltbuf, elttype, eltsize,
+                       retval = read_tree_recursive(eltbuf, eltsize,
                                                     newbase,
                                                     baselen + pathlen + 1);
                        free(eltbuf);
                                                     newbase,
                                                     baselen + pathlen + 1);
                        free(eltbuf);
@@ -76,7 +73,9 @@ static int read_tree(unsigned char *sha1, const char *base, int baselen)
        unsigned long size;
 
        buffer = read_tree_with_tree_or_commit_sha1(sha1, &size, 0);
        unsigned long size;
 
        buffer = read_tree_with_tree_or_commit_sha1(sha1, &size, 0);
-       return read_tree_recursive(buffer, "tree", size, base, baselen);
+       if (!buffer)
+               return -1;
+       return read_tree_recursive(buffer, size, base, baselen);
 }
 
 static char *lockfile_name;
 }
 
 static char *lockfile_name;