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

[PATCH v2 01/16] cache: update object ID functions for the_hash_algo

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Jul 16, 2018, 01:27 UTC
Message-ID
<20180716012808.961328-2-sandals@crustytoothpaste.net>
In-Reply-To
<20180716012808.961328-1-sandals@crustytoothpaste.net>

Most of our code has been converted to use struct object_id for object IDs. However, there are some places that still have not, and there are a variety of places that compare equivalently sized hashes that are not object IDs. All of these hashes are artifacts of the internal hash algorithm in use, and when we switch to NewHash for object storage, all of these uses will also switch.

Update the hashcpy, hashclr, and hashcmp functions to use the_hash_algo, since they are used in a variety of places to copy and manipulate buffers that need to move data into or out of struct object_id. This has the effect of making the corresponding oid* functions use the_hash_algo as well.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 cache.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/cache.h b/cache.h
index d49092d94d..f00cc810bc 100644
--- a/cache.h
+++ b/cache.h
@@ -972,7 +972,7 @@ extern const struct object_id null_oid;
 
 static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
 {
-	return memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
+	return memcmp(sha1, sha2, the_hash_algo->rawsz);
 }
 
 static inline int oidcmp(const struct object_id *oid1, const struct object_id *oid2)
@@ -992,7 +992,7 @@ static inline int is_null_oid(const struct object_id *oid)
 
 static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)
 {
-	memcpy(sha_dst, sha_src, GIT_SHA1_RAWSZ);
+	memcpy(sha_dst, sha_src, the_hash_algo->rawsz);
 }
 
 static inline void oidcpy(struct object_id *dst, const struct object_id *src)
@@ -1009,7 +1009,7 @@ static inline struct object_id *oiddup(const struct object_id *src)
 
 static inline void hashclr(unsigned char *hash)
 {
-	memset(hash, 0, GIT_SHA1_RAWSZ);
+	memset(hash, 0, the_hash_algo->rawsz);
 }
 
 static inline void oidclr(struct object_id *oid)
Previous: brian m. carlsonNext: brian m. carlson
Message 2 of 20 in “object_id part 14”
  1. 00/16 object_id part 14brian m. carlson, Jul 16, 2018
  2. 01/16 cache: update object ID functions for the_hash_algobrian m. carlson, Jul 16, 2018
  3. 02/16 tree-walk: replace hard-coded constants with the_hash_algobrian m. carlson, Jul 16, 2018
  4. 03/16 hex: switch to using the_hash_algobrian m. carlson, Jul 16, 2018
  5. 05/16 strbuf: allocate space with GIT_MAX_HEXSZbrian m. carlson, Jul 16, 2018
  6. 04/16 commit: express tree entry constants in terms of the_hash_algobrian m. carlson, Jul 16, 2018
  7. 07/16 refs/files-backend: use the_hash_algo for writing refsbrian m. carlson, Jul 16, 2018
  8. 08/16 builtin/update-index: convert to using the_hash_algobrian m. carlson, Jul 16, 2018
  9. 09/16 builtin/update-index: simplify parsing of cacheinfobrian m. carlson, Jul 16, 2018
  10. 06/16 sha1-name: use the_hash_algo when parsing object namesbrian m. carlson, Jul 16, 2018
  11. 10/16 builtin/fmt-merge-msg: make hash independentbrian m. carlson, Jul 16, 2018
  12. 11/16 builtin/merge: switch to use the_hash_algobrian m. carlson, Jul 16, 2018
  13. 12/16 builtin/merge-recursive: make hash independentbrian m. carlson, Jul 16, 2018
  14. 13/16 diff: switch GIT_SHA1_HEXSZ to use the_hash_algobrian m. carlson, Jul 16, 2018
  15. 14/16 log-tree: switch GIT_SHA1_HEXSZ to the_hash_algo->hexszbrian m. carlson, Jul 16, 2018
  16. 15/16 sha1-file: convert constants to uses of the_hash_algobrian m. carlson, Jul 16, 2018
  17. 16/16 pretty: switch hard-coded constants to the_hash_algobrian m. carlson, Jul 16, 2018
  18. Derrick StoleeJul 16, 2018
  19. Taylor BlauJul 16, 2018
  20. Stefan BellerJul 16, 2018

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.