aboutsummaryrefslogtreecommitdiff
path: root/read-tree.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-09 15:36:41 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-09 15:36:41 -0700
commitf768846e34997fb847c9b875615867d4716d632f (patch)
tree5f3fcd81f68f4031cbcfcadd5c368104ca0969a0 /read-tree.c
parent16d4d1ba6c1de7a414a6826eb6f363d4b20345bf (diff)
downloadgit-f768846e34997fb847c9b875615867d4716d632f.tar.gz
git-f768846e34997fb847c9b875615867d4716d632f.tar.xz
Teach "fsck" and "read-tree" about recursive tree-nodes.
This is totally untested, since we can't actually _write_ things that way yet, but I'll get to that next, I hope. That should fix the huge wasted space for kernel-sized tree objects.
Diffstat (limited to 'read-tree.c')
-rw-r--r--read-tree.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/read-tree.c b/read-tree.c
index efd8d3614..6862d1012 100644
--- a/read-tree.c
+++ b/read-tree.c
@@ -5,22 +5,23 @@
*/
#include "cache.h"
-static int read_one_entry(unsigned char *sha1, const char *pathname, unsigned mode)
+static int read_one_entry(unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode)
{
int len = strlen(pathname);
- unsigned int size = cache_entry_size(len);
+ unsigned int size = cache_entry_size(baselen + len);
struct cache_entry *ce = malloc(size);
memset(ce, 0, size);
ce->st_mode = mode;
- ce->namelen = len;
- memcpy(ce->name, pathname, len+1);
+ ce->namelen = baselen + len;
+ memcpy(ce->name, base, baselen);
+ memcpy(ce->name + baselen, pathname, len+1);
memcpy(ce->sha1, sha1, 20);
return add_cache_entry(ce);
}
-static int read_tree(unsigned char *sha1)
+static int read_tree(unsigned char *sha1, const char *base, int baselen)
{
void *buffer;
unsigned long size;
@@ -43,7 +44,20 @@ static int read_tree(unsigned char *sha1)
buffer = sha1 + 20;
size -= len + 20;
- if (read_one_entry(sha1, path, mode) < 0)
+ if (S_ISDIR(mode)) {
+ int retval;
+ int pathlen = strlen(path);
+ char *newbase = malloc(baselen + 1 + pathlen);
+ memcpy(newbase, base, baselen);
+ memcpy(newbase + baselen, path, pathlen);
+ newbase[baselen + pathlen] = '/';
+ retval = read_tree(sha1, newbase, baselen + pathlen + 1);
+ free(newbase);
+ if (retval)
+ return -1;
+ continue;
+ }
+ if (read_one_entry(sha1, base, baselen, path, mode) < 0)
return -1;
}
return 0;
@@ -77,7 +91,7 @@ int main(int argc, char **argv)
fprintf(stderr, "read-tree [-m] <sha1>\n");
goto out;
}
- if (read_tree(sha1) < 0) {
+ if (read_tree(sha1, "", 0) < 0) {
fprintf(stderr, "failed to unpack tree object %s\n", arg);
goto out;
}