@matheusbsbs / matheus-bagliano / commits / c3f9281255
Fork 0

Use struct commit in tar-tree

It was open-coding getting the commit date from a commit. Signed-off-by: Daniel Barkalow <barkalow@iabervon> Signed-off-by: Junio C Hamano <junkio@cox.net>

Daniel Barkalow committed Jan 29, 2006 at 14:05 UTC c3f9281255a24afa47a5a8d8f25cd9f22c2da6da
1 file changed +6 -35
tar-tree.c
+6 -35
@@ -4,6 +4,7 @@
4 #include <time.h>
5 #include "cache.h"
6 #include "tree.h"
7 +#include "commit.h"
8
9 #define RECORDSIZE (512)
10 #define BLOCKSIZE (RECORDSIZE * 20)
@@ -369,39 +370,10 @@ static void traverse_tree(struct tree *tree,
370 }
371 }
372
372 -/* get commit time from committer line of commit object */
373 -static time_t commit_time(void * buffer, unsigned long size)
374 -{
375 - time_t result = 0;
376 - char *p = buffer;
377 -
378 - while (size > 0) {
379 - char *endp = memchr(p, '\n', size);
380 - if (!endp || endp == p)
381 - break;
382 - *endp = '\0';
383 - if (endp - p > 10 && !memcmp(p, "committer ", 10)) {
384 - char *nump = strrchr(p, '>');
385 - if (!nump)
386 - break;
387 - nump++;
388 - result = strtoul(nump, &endp, 10);
389 - if (*endp != ' ')
390 - result = 0;
391 - break;
392 - }
393 - size -= endp - p - 1;
394 - p = endp + 1;
395 - }
396 - return result;
397 -}
398 -
373 int main(int argc, char **argv)
374 {
375 unsigned char sha1[20];
402 - unsigned char commit_sha1[20];
403 - void *buffer;
404 - unsigned long size;
376 + struct commit *commit;
377 struct tree *tree;
378
379 setup_git_directory();
@@ -418,11 +390,10 @@ int main(int argc, char **argv)
390 usage(tar_tree_usage);
391 }
392
421 - buffer = read_object_with_reference(sha1, "commit", &size, commit_sha1);
422 - if (buffer) {
423 - write_global_extended_header(commit_sha1);
424 - archive_time = commit_time(buffer, size);
425 - free(buffer);
393 + commit = lookup_commit_reference(sha1);
394 + if (commit) {
395 + write_global_extended_header(commit->object.sha1);
396 + archive_time = commit->date;
397 }
398 tree = parse_tree_indirect(sha1);
399 if (!tree)