diff options
author | Junio C Hamano <junkio@cox.net> | 2005-04-20 18:06:50 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-20 18:06:50 -0700 |
commit | b12ec373b8ecf7de6ea37db392fde57f13c5b51c (patch) | |
tree | 9943f62d09ad2f09d855a53a8e8ab18330799810 /read-tree.c | |
parent | 23b127ed085cbe2f853ce63b53c732a7b9e6de74 (diff) | |
download | git-b12ec373b8ecf7de6ea37db392fde57f13c5b51c.tar.gz |
[PATCH] Teach read-tree about commit objects
Updates read-tree to use read_tree_with_tree_or_commit_sha1()
function. The command can take either tree or commit IDs with
this patch.
The change involves a slight modification of how it recurses down
the tree. Earlier the caller only supplied SHA1 and the recurser
read the object using it, but now it is the caller's responsibility
to read the object and give it to the recurser. This matches the
way recursive behaviour is done in other tree- related commands.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'read-tree.c')
-rw-r--r-- | read-tree.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/read-tree.c b/read-tree.c index 46747b5e99..2773ce0cf1 100644 --- a/read-tree.c +++ b/read-tree.c @@ -23,16 +23,11 @@ static int read_one_entry(unsigned char *sha1, const char *base, int baselen, co return add_cache_entry(ce, 1); } -static int read_tree(unsigned char *sha1, const char *base, int baselen) +static int read_tree_recursive(void *buffer, const char *type, + unsigned long size, + const char *base, int baselen) { - void *buffer; - unsigned long size; - char type[20]; - - buffer = read_sha1_file(sha1, type, &size); - if (!buffer) - return -1; - if (strcmp(type, "tree")) + if (!buffer || strcmp(type, "tree")) return -1; while (size) { int len = strlen(buffer)+1; @@ -50,10 +45,20 @@ static int read_tree(unsigned char *sha1, const char *base, int baselen) int retval; int pathlen = strlen(path); char *newbase = malloc(baselen + 1 + pathlen); + void *eltbuf; + char elttype[20]; + unsigned long eltsize; + + eltbuf = read_sha1_file(sha1, elttype, &eltsize); + if (!eltbuf) + return -1; memcpy(newbase, base, baselen); memcpy(newbase + baselen, path, pathlen); newbase[baselen + pathlen] = '/'; - retval = read_tree(sha1, newbase, baselen + pathlen + 1); + retval = read_tree_recursive(eltbuf, elttype, eltsize, + newbase, + baselen + pathlen + 1); + free(eltbuf); free(newbase); if (retval) return -1; @@ -65,6 +70,15 @@ static int read_tree(unsigned char *sha1, const char *base, int baselen) return 0; } +static int read_tree(unsigned char *sha1, const char *base, int baselen) +{ + void *buffer; + unsigned long size; + + buffer = read_tree_with_tree_or_commit_sha1(sha1, &size, 0); + return read_tree_recursive(buffer, "tree", size, base, baselen); +} + static int remove_lock = 0; static void remove_lock_file(void) |