[PATCH] Use read_object_with_reference() in tar-tree
This patch replaces the usage of read_tree_with_tree_or_commit_sha1() with read_object_with_reference() in tar-tree. As a result the code that tries to figure out the commit time doesn't need to open the commit object 'by hand' any more. Signed-off-by: Rene Scharfe <lsrfire.ath.cx> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:

committed by
Linus Torvalds

parent
40469ee9c6
commit
db413479f1
54
tar-tree.c
54
tar-tree.c
@ -291,35 +291,28 @@ static void traverse_tree(void *buffer, unsigned long size,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* get commit time from committer line of commit object */
|
/* get commit time from committer line of commit object */
|
||||||
time_t commit_time(const unsigned char *sha1)
|
time_t commit_time(void * buffer, unsigned long size)
|
||||||
{
|
{
|
||||||
char type[20];
|
|
||||||
void *buffer;
|
|
||||||
unsigned long size;
|
|
||||||
time_t result = 0;
|
time_t result = 0;
|
||||||
|
char *p = buffer;
|
||||||
|
|
||||||
buffer = read_sha1_file(sha1, type, &size);
|
while (size > 0) {
|
||||||
if (buffer) {
|
char *endp = memchr(p, '\n', size);
|
||||||
char *p = buffer;
|
if (!endp || endp == p)
|
||||||
while (size > 0) {
|
break;
|
||||||
char *endp = memchr(p, '\n', size);
|
*endp = '\0';
|
||||||
if (!endp || endp == p)
|
if (endp - p > 10 && !memcmp(p, "committer ", 10)) {
|
||||||
|
char *nump = strrchr(p, '>');
|
||||||
|
if (!nump)
|
||||||
break;
|
break;
|
||||||
*endp = '\0';
|
nump++;
|
||||||
if (endp - p > 10 && !memcmp(p, "committer ", 10)) {
|
result = strtoul(nump, &endp, 10);
|
||||||
char *nump = strrchr(p, '>');
|
if (*endp != ' ')
|
||||||
if (!nump)
|
result = 0;
|
||||||
break;
|
break;
|
||||||
nump++;
|
|
||||||
result = strtoul(nump, &endp, 10);
|
|
||||||
if (*endp != ' ')
|
|
||||||
result = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
size -= endp - p - 1;
|
|
||||||
p = endp + 1;
|
|
||||||
}
|
}
|
||||||
free(buffer);
|
size -= endp - p - 1;
|
||||||
|
p = endp + 1;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -329,7 +322,6 @@ int main(int argc, char **argv)
|
|||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
void *buffer;
|
void *buffer;
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
unsigned char tree_sha1[20];
|
|
||||||
|
|
||||||
switch (argc) {
|
switch (argc) {
|
||||||
case 3:
|
case 3:
|
||||||
@ -347,11 +339,15 @@ int main(int argc, char **argv)
|
|||||||
if (!sha1_file_directory)
|
if (!sha1_file_directory)
|
||||||
sha1_file_directory = DEFAULT_DB_ENVIRONMENT;
|
sha1_file_directory = DEFAULT_DB_ENVIRONMENT;
|
||||||
|
|
||||||
buffer = read_tree_with_tree_or_commit_sha1(sha1, &size, tree_sha1);
|
buffer = read_object_with_reference(sha1, "commit", &size, NULL);
|
||||||
|
if (buffer) {
|
||||||
|
archive_time = commit_time(buffer, size);
|
||||||
|
free(buffer);
|
||||||
|
}
|
||||||
|
buffer = read_object_with_reference(sha1, "tree", &size, NULL);
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
die("unable to read sha1 file");
|
die("not a reference to a tag, commit or tree object: %s",
|
||||||
if (memcmp(sha1, tree_sha1, 20)) /* is sha1 a commit object? */
|
sha1_to_hex(sha1));
|
||||||
archive_time = commit_time(sha1);
|
|
||||||
if (!archive_time)
|
if (!archive_time)
|
||||||
archive_time = time(NULL);
|
archive_time = time(NULL);
|
||||||
if (basedir)
|
if (basedir)
|
||||||
|
Reference in New Issue
Block a user