git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] Use struct commit in tar-tree

From
Daniel Barkalow <barkalow@iabervon.org>
Date
Jan 29, 2006, 19:05 UTC
Message-ID
<Pine.LNX.4.64.0601291405030.25300@iabervon.org>
In-Reply-To
<Pine.LNX.4.64.0601291336420.25300@iabervon.org>
It was open-coding getting the commit date from a commit.
Signed-off-by: Daniel Barkalow <barkalow@iabervon>
---
 tar-tree.c |   41 ++++++-----------------------------------
 1 files changed, 6 insertions(+), 35 deletions(-)
ca523a725295fff6f1456cd7207f6b24f8c2e843
diff --git a/tar-tree.c b/tar-tree.c
index 6219754..d36baed 100644
--- a/tar-tree.c
+++ b/tar-tree.c
@@ -4,6 +4,7 @@
 #include <time.h>
 #include "cache.h"
 #include "tree.h"
+#include "commit.h"
 
 #define RECORDSIZE	(512)
 #define BLOCKSIZE	(RECORDSIZE * 20)
@@ -369,39 +370,10 @@ static void traverse_tree(struct tree *t
 	}
 }
 
-/* get commit time from committer line of commit object */
-static time_t commit_time(void * buffer, unsigned long size)
-{
-	time_t result = 0;
-	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;
-			break;
-		}
-		size -= endp - p - 1;
-		p = endp + 1;
-	}
-	return result;
-}
-
 int main(int argc, char **argv)
 {
 	unsigned char sha1[20];
-	unsigned char commit_sha1[20];
-	void *buffer;
-	unsigned long size;
+	struct commit *commit;
 	struct tree *tree;
 
 	setup_git_directory();
@@ -418,11 +390,10 @@ int main(int argc, char **argv)
 		usage(tar_tree_usage);
 	}
 
-	buffer = read_object_with_reference(sha1, "commit", &size, commit_sha1);
-	if (buffer) {
-		write_global_extended_header(commit_sha1);
-		archive_time = commit_time(buffer, size);
-		free(buffer);
+	commit = lookup_commit_reference(sha1);
+	if (commit) {
+		write_global_extended_header(commit->object.sha1);
+		archive_time = commit->date;
 	}
 	tree = parse_tree_indirect(sha1);
 	if (!tree)
-- 
1.0.GIT
Previous: Daniel BarkalowNext: Daniel Barkalow
Message 3 of 11 in “Remove more parsers”
  1. 0/3 Remove more parsersDaniel Barkalow, Jan 29, 2006
  2. 1/3 Use struct tree in tar-treeDaniel Barkalow, Jan 29, 2006
  3. 2/3 Use struct commit in tar-treeDaniel Barkalow, Jan 29, 2006
  4. 3/3 Use struct tree in diff-treeDaniel Barkalow, Jan 29, 2006
  5. Linus TorvaldsJan 31, 2006
  6. Junio C HamanoJan 31, 2006
  7. Daniel BarkalowJan 31, 2006
  8. Linus TorvaldsJan 31, 2006
  9. Junio C HamanoJan 29, 2006
  10. Daniel BarkalowJan 29, 2006
  11. Linus TorvaldsJan 31, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.