From: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
To: Linus Torvalds <torvalds@osdl.org>
Cc: git@vger.kernel.org
Subject: [PATCH] Use read_object_with_reference() in tar-tree
Date: Fri, 29 Apr 2005 05:21:27 +0200 [thread overview]
Message-ID: <20050429032127.GA12160@lsrfire.ath.cx> (raw)
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>
Index: tar-tree.c
===================================================================
--- dc0b54b68c90574a689fef23c5ab26d165f3ee2e/tar-tree.c (mode:100644 sha1:d078cb5a8d4ab5bc2c774b889b602d179bde39b1)
+++ 1e2168c7d554a4fbd25a09bb591ae0f82dac6513/tar-tree.c (mode:100644 sha1:5cc7cfef6db1269d81589b82255537fb64ba02fa)
@@ -291,35 +291,28 @@
}
/* 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;
+ char *p = buffer;
- buffer = read_sha1_file(sha1, type, &size);
- if (buffer) {
- char *p = buffer;
- while (size > 0) {
- char *endp = memchr(p, '\n', size);
- if (!endp || endp == p)
- break;
- *endp = '\0';
- if (endp - p > 10 && !memcmp(p, "committer ", 10)) {
- char *nump = strrchr(p, '>');
- if (!nump)
- break;
- nump++;
- result = strtoul(nump, &endp, 10);
- if (*endp != ' ')
- result = 0;
+ while (size > 0) {
+ char *endp = memchr(p, '\n', size);
+ if (!endp || endp == p)
+ break;
+ *endp = '\0';
+ if (endp - p > 10 && !memcmp(p, "committer ", 10)) {
+ char *nump = strrchr(p, '>');
+ if (!nump)
break;
- }
- size -= endp - p - 1;
- p = endp + 1;
+ nump++;
+ result = strtoul(nump, &endp, 10);
+ if (*endp != ' ')
+ result = 0;
+ break;
}
- free(buffer);
+ size -= endp - p - 1;
+ p = endp + 1;
}
return result;
}
@@ -329,7 +322,6 @@
unsigned char sha1[20];
void *buffer;
unsigned long size;
- unsigned char tree_sha1[20];
switch (argc) {
case 3:
@@ -347,11 +339,15 @@
if (!sha1_file_directory)
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)
- die("unable to read sha1 file");
- if (memcmp(sha1, tree_sha1, 20)) /* is sha1 a commit object? */
- archive_time = commit_time(sha1);
+ die("not a reference to a tag, commit or tree object: %s",
+ sha1_to_hex(sha1));
if (!archive_time)
archive_time = time(NULL);
if (basedir)
reply other threads:[~2005-04-29 3:15 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050429032127.GA12160@lsrfire.ath.cx \
--to=rene.scharfe@lsrfire.ath.cx \
--cc=git@vger.kernel.org \
--cc=torvalds@osdl.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).