summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 16d4d1b)
raw | patch | inline | side by side (parent: 16d4d1b)
author | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Sat, 9 Apr 2005 22:36:41 +0000 (15:36 -0700) | ||
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Sat, 9 Apr 2005 22:36:41 +0000 (15:36 -0700) |
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.
way yet, but I'll get to that next, I hope. That should fix the
huge wasted space for kernel-sized tree objects.
fsck-cache.c | patch | blob | history | |
read-tree.c | patch | blob | history |
diff --git a/fsck-cache.c b/fsck-cache.c
index ac348b7d5278e9d04e3a1cd417389379c32b014f..1123b6b7e4312a9ab47071479d071a5856fc8134 100644 (file)
--- a/fsck-cache.c
+++ b/fsck-cache.c
int len = 1+strlen(data);
unsigned char *file_sha1 = data + len;
char *path = strchr(data, ' ');
- if (size < len + 20 || !path)
+ unsigned int mode;
+ if (size < len + 20 || !path || sscanf(data, "%o", &mode) != 1)
return -1;
data += len + 20;
size -= len + 20;
- mark_needs_sha1(sha1, "blob", file_sha1);
+ mark_needs_sha1(sha1, S_ISDIR(mode) ? "tree" : "blob", file_sha1);
}
return 0;
}
diff --git a/read-tree.c b/read-tree.c
index efd8d36141fa10cba27f370ec3a66e1b05af8bc6..6862d1012681cd6812ab9bfe1a866446f92a7c91 100644 (file)
--- a/read-tree.c
+++ b/read-tree.c
*/
#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;
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;
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;
}