Make git-tar-tree use the tree_desc abstractions
Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Linus Torvalds committed
Jan 31, 2006 at 14:13 UTC
7ec57556b29c3ed42769c122228ee4621676b642
1 file changed
+24
-23
tar-tree.c
+24
-23
@@ -3,7 +3,7 @@
3
*/
4
#include <time.h>
5
#include "cache.h"
6
-#include "tree.h"
6
+#include "diff.h"
7
#include "commit.h"
8
9
#define RECORDSIZE (512)
@@ -336,37 +336,38 @@ static void write_header(const unsigned char *sha1, char typeflag, const char *b
336
write_if_needed();
337
}
338
339
-static void traverse_tree(struct tree *tree,
339
+static void traverse_tree(struct tree_desc *tree,
340
struct path_prefix *prefix)
341
{
342
struct path_prefix this_prefix;
343
- struct tree_entry_list *item;
343
this_prefix.prev = prefix;
344
346
- parse_tree(tree);
347
- item = tree->entries;
348
-
349
- while (item) {
345
+ while (tree->size) {
346
+ const char *name;
347
+ const unsigned char *sha1;
348
+ unsigned mode;
349
void *eltbuf;
350
char elttype[20];
351
unsigned long eltsize;
352
354
- eltbuf = read_sha1_file(item->item.any->sha1,
355
- elttype, &eltsize);
353
+ sha1 = tree_entry_extract(tree, &name, &mode);
354
+ update_tree_entry(tree);
355
+
356
+ eltbuf = read_sha1_file(sha1, elttype, &eltsize);
357
if (!eltbuf)
357
- die("cannot read %s",
358
- sha1_to_hex(item->item.any->sha1));
359
- write_header(item->item.any->sha1, TYPEFLAG_AUTO, basedir,
360
- prefix, item->name,
361
- item->mode, eltbuf, eltsize);
362
- if (item->directory) {
363
- this_prefix.name = item->name;
364
- traverse_tree(item->item.tree, &this_prefix);
365
- } else if (!item->symlink) {
358
+ die("cannot read %s", sha1_to_hex(sha1));
359
+ write_header(sha1, TYPEFLAG_AUTO, basedir,
360
+ prefix, name, mode, eltbuf, eltsize);
361
+ if (S_ISDIR(mode)) {
362
+ struct tree_desc subtree;
363
+ subtree.buf = eltbuf;
364
+ subtree.size = eltsize;
365
+ this_prefix.name = name;
366
+ traverse_tree(&subtree, &this_prefix);
367
+ } else if (!S_ISLNK(mode)) {
368
write_blocked(eltbuf, eltsize);
369
}
370
free(eltbuf);
369
- item = item->next;
371
}
372
}
373
@@ -374,7 +375,7 @@ int main(int argc, char **argv)
375
{
376
unsigned char sha1[20];
377
struct commit *commit;
377
- struct tree *tree;
378
+ struct tree_desc tree;
379
380
setup_git_directory();
381
@@ -395,8 +396,8 @@ int main(int argc, char **argv)
396
write_global_extended_header(commit->object.sha1);
397
archive_time = commit->date;
398
}
398
- tree = parse_tree_indirect(sha1);
399
- if (!tree)
399
+ tree.buf = read_object_with_reference(sha1, "tree", &tree.size, NULL);
400
+ if (!tree.buf)
401
die("not a reference to a tag, commit or tree object: %s",
402
sha1_to_hex(sha1));
403
if (!archive_time)
@@ -404,7 +405,7 @@ int main(int argc, char **argv)
405
if (basedir)
406
write_header((unsigned char *)"0", TYPEFLAG_DIR, NULL, NULL,
407
basedir, 040777, NULL, 0);
407
- traverse_tree(tree, NULL);
408
+ traverse_tree(&tree, NULL);
409
write_trailer();
410
return 0;
411
}