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

[PATCH 1/6] builtin/hash-object: convert to struct object_id

From
Patryk Obara <patryk.obara@gmail.com>
Date
Aug 20, 2017, 20:09 UTC
Message-ID
<0eab0c65a0c80f4b367fbf560f51b4dacb556ba9.1503258223.git.patryk.obara@gmail.com>
In-Reply-To
<cover.1503258223.git.patryk.obara@gmail.com>
Signed-off-by: Patryk Obara <patryk.obara@gmail.com>
---
 builtin/hash-object.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index d04baf9..1c0f0f3 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -16,7 +16,7 @@
  * needs to bypass the data conversion performed by, and the type
  * limitation imposed by, index_fd() and its callees.
  */
-static int hash_literally(unsigned char *sha1, int fd, const char *type, unsigned flags)
+static int hash_literally(struct object_id *oid, int fd, const char *type, unsigned flags)
 {
 	struct strbuf buf = STRBUF_INIT;
 	int ret;
@@ -24,7 +24,7 @@ static int hash_literally(unsigned char *sha1, int fd, const char *type, unsigne
 	if (strbuf_read(&buf, fd, 4096) < 0)
 		ret = -1;
 	else
-		ret = hash_sha1_file_literally(buf.buf, buf.len, type, sha1, flags);
+		ret = hash_sha1_file_literally(buf.buf, buf.len, type, oid->hash, flags);
 	strbuf_release(&buf);
 	return ret;
 }
@@ -33,16 +33,16 @@ static void hash_fd(int fd, const char *type, const char *path, unsigned flags,
 		    int literally)
 {
 	struct stat st;
-	unsigned char sha1[20];
+	struct object_id oid;
 
 	if (fstat(fd, &st) < 0 ||
 	    (literally
-	     ? hash_literally(sha1, fd, type, flags)
-	     : index_fd(sha1, fd, &st, type_from_string(type), path, flags)))
+	     ? hash_literally(&oid, fd, type, flags)
+	     : index_fd(oid.hash, fd, &st, type_from_string(type), path, flags)))
 		die((flags & HASH_WRITE_OBJECT)
 		    ? "Unable to add %s to database"
 		    : "Unable to hash %s", path);
-	printf("%s\n", sha1_to_hex(sha1));
+	printf("%s\n", oid_to_hex(&oid));
 	maybe_flush_or_die(stdout, "hash to stdout");
 }
 
-- 
2.9.5
Previous: Patryk ObaraNext: Patryk Obara
Message 2 of 10 in “Convert hash-object to struct object_id”
  1. 0/6 Convert hash-object to struct object_idPatryk Obara, Aug 20, 2017
  2. 1/6 builtin/hash-object: convert to struct object_idPatryk Obara, Aug 20, 2017
  3. 3/6 sha1_file: convert index_path to struct object_idPatryk Obara, Aug 20, 2017
  4. 6/6 sha1_file: convert index_stream to struct object_idPatryk Obara, Aug 20, 2017
  5. 5/6 sha1_file: convert hash_sha1_file_literally to struct object_idPatryk Obara, Aug 20, 2017
  6. brian m. carlsonAug 20, 2017
  7. 2/6 read-cache: convert to struct object_idPatryk Obara, Aug 20, 2017
  8. 4/6 sha1_file: convert index_fd to struct object_idPatryk Obara, Aug 20, 2017
  9. brian m. carlsonAug 20, 2017
  10. Junio C HamanoAug 21, 2017

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.