git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 00/26] object_id part 17
@ 2019-08-18 20:04 brian m. carlson
  2019-08-18 20:04 ` [PATCH 01/26] builtin/replace: make hash size independent brian m. carlson
                   ` (25 more replies)
  0 siblings, 26 replies; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

This is the seventeenth and final object_id series. The patches mostly
switch sha1_to_hex to hash_to_hex, remove null_sha1 in favor of
null_oid, and replace some hard-coded constants (along with
GIT_SHA1_HEXSZ) to use the_hash_algo.

This series may downloaded from the normal places as "object-id-part17".

Additional patches for test fixes will be required, but beyond that, the
next series of actual code changes will involve introducing the
`extensions.objectFormat` flag and the ability to create repositories
and run the testsuite with SHA-256.  A preview of this work may be seen
in the "transition-stage-4" branch.

brian m. carlson (26):
  builtin/replace: make hash size independent
  patch-id: convert to use the_hash_algo
  fetch-pack: use parse_oid_hex
  builtin/receive-pack: switch to use the_hash_algo
  builtin/blame: switch uses of GIT_SHA1_HEXSZ to the_hash_algo
  builtin/rev-parse: switch to use the_hash_algo
  blame: remove needless comparison with GIT_SHA1_HEXSZ
  show-index: switch hard-coded constants to the_hash_algo
  connected: switch GIT_SHA1_HEXSZ to the_hash_algo
  bundle: switch to use the_hash_algo
  combine-diff: replace GIT_SHA1_HEXSZ with the_hash_algo
  config: use the_hash_algo in abbrev comparison
  sha1-lookup: switch hard-coded constants to the_hash_algo
  bisect: switch to using the_hash_algo
  sequencer: convert to use the_hash_algo
  pack-write: use hash_to_hex when writing checksums
  builtin/repack: write object IDs of the proper length
  builtin/worktree: switch null_sha1 to null_oid
  cache: remove null_sha1
  wt-status: convert struct wt_status to object_id
  packfile: replace sha1_to_hex
  builtin/index-pack: replace sha1_to_hex
  builtin/receive-pack: replace sha1_to_hex
  rerere: replace sha1_to_hex
  builtin/show-index: replace sha1_to_hex
  midx: switch to using the_hash_algo

 bisect.c                    |  2 +-
 blame.c                     |  2 +-
 builtin/blame.c             |  7 +++---
 builtin/clone.c             |  2 +-
 builtin/commit.c            |  4 +--
 builtin/index-pack.c        |  4 +--
 builtin/patch-id.c          | 11 ++++----
 builtin/receive-pack.c      | 50 ++++++++++++++++++-------------------
 builtin/repack.c            |  2 +-
 builtin/replace.c           |  7 +++---
 builtin/rev-parse.c         |  5 ++--
 builtin/show-index.c        | 13 +++++-----
 builtin/submodule--helper.c |  2 +-
 builtin/worktree.c          |  2 +-
 bundle.c                    |  4 +--
 cache.h                     |  8 +-----
 combine-diff.c              |  2 +-
 config.c                    |  2 +-
 connected.c                 |  7 +++---
 diff.c                      | 46 +++++++++++++++++-----------------
 diff.h                      |  2 +-
 fetch-pack.c                | 12 ++++-----
 midx.c                      | 11 ++++----
 pack-write.c                |  8 +++---
 packfile.c                  |  4 +--
 rerere.c                    |  8 +++---
 sequencer.c                 |  6 ++---
 sha1-file.c                 |  1 -
 sha1-lookup.c               |  8 +++---
 wt-status.c                 |  2 +-
 wt-status.h                 |  2 +-
 31 files changed, 121 insertions(+), 125 deletions(-)


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 01/26] builtin/replace: make hash size independent
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-18 20:04 ` [PATCH 02/26] patch-id: convert to use the_hash_algo brian m. carlson
                   ` (24 subsequent siblings)
  25 siblings, 0 replies; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

Instead of using GIT_SHA1_HEXSZ and hard-coded constants, switch to
using the_hash_algo.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/replace.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/builtin/replace.c b/builtin/replace.c
index 644b21ca8d..4b00f1d84e 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -272,7 +272,7 @@ static int import_object(struct object_id *oid, enum object_type type,
 			return error(_("unable to spawn mktree"));
 		}
 
-		if (strbuf_read(&result, cmd.out, 41) < 0) {
+		if (strbuf_read(&result, cmd.out, the_hash_algo->hexsz + 1) < 0) {
 			error_errno(_("unable to read from mktree"));
 			close(fd);
 			close(cmd.out);
@@ -358,14 +358,15 @@ static int replace_parents(struct strbuf *buf, int argc, const char **argv)
 	struct strbuf new_parents = STRBUF_INIT;
 	const char *parent_start, *parent_end;
 	int i;
+	const unsigned hexsz = the_hash_algo->hexsz;
 
 	/* find existing parents */
 	parent_start = buf->buf;
-	parent_start += GIT_SHA1_HEXSZ + 6; /* "tree " + "hex sha1" + "\n" */
+	parent_start += hexsz + 6; /* "tree " + "hex sha1" + "\n" */
 	parent_end = parent_start;
 
 	while (starts_with(parent_end, "parent "))
-		parent_end += 48; /* "parent " + "hex sha1" + "\n" */
+		parent_end += hexsz + 8; /* "parent " + "hex sha1" + "\n" */
 
 	/* prepare new parents */
 	for (i = 0; i < argc; i++) {

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 02/26] patch-id: convert to use the_hash_algo
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
  2019-08-18 20:04 ` [PATCH 01/26] builtin/replace: make hash size independent brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-20 21:12   ` René Scharfe
  2019-08-18 20:04 ` [PATCH 03/26] fetch-pack: use parse_oid_hex brian m. carlson
                   ` (23 subsequent siblings)
  25 siblings, 1 reply; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

Convert the two separate patch-id implementations to use the_hash_algo
in their implementation.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/patch-id.c | 11 ++++++-----
 diff.c             | 46 +++++++++++++++++++++++-----------------------
 diff.h             |  2 +-
 3 files changed, 30 insertions(+), 29 deletions(-)

diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index bd28b80b2d..3059e525b8 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -1,15 +1,16 @@
+#include "cache.h"
 #include "builtin.h"
 #include "config.h"
 #include "diff.h"
 
 static void flush_current_id(int patchlen, struct object_id *id, struct object_id *result)
 {
-	char name[50];
+	char name[GIT_MAX_HEXSZ + 1];
 
 	if (!patchlen)
 		return;
 
-	memcpy(name, oid_to_hex(id), GIT_SHA1_HEXSZ + 1);
+	memcpy(name, oid_to_hex(id), the_hash_algo->hexsz + 1);
 	printf("%s %s\n", oid_to_hex(result), name);
 }
 
@@ -60,9 +61,9 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
 {
 	int patchlen = 0, found_next = 0;
 	int before = -1, after = -1;
-	git_SHA_CTX ctx;
+	git_hash_ctx ctx;
 
-	git_SHA1_Init(&ctx);
+	the_hash_algo->init_fn(&ctx);
 	oidclr(result);
 
 	while (strbuf_getwholeline(line_buf, stdin, '\n') != EOF) {
@@ -122,7 +123,7 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
 		/* Compute the sha without whitespace */
 		len = remove_space(line);
 		patchlen += len;
-		git_SHA1_Update(&ctx, line, len);
+		the_hash_algo->update_fn(&ctx, line, len);
 	}
 
 	if (!found_next)
diff --git a/diff.c b/diff.c
index efe42b341a..bf51c94804 100644
--- a/diff.c
+++ b/diff.c
@@ -5978,7 +5978,7 @@ static void diff_summary(struct diff_options *opt, struct diff_filepair *p)
 }
 
 struct patch_id_t {
-	git_SHA_CTX *ctx;
+	git_hash_ctx *ctx;
 	int patchlen;
 };
 
@@ -5995,16 +5995,16 @@ static int remove_space(char *line, int len)
 	return dst - line;
 }
 
-void flush_one_hunk(struct object_id *result, git_SHA_CTX *ctx)
+void flush_one_hunk(struct object_id *result, git_hash_ctx *ctx)
 {
 	unsigned char hash[GIT_MAX_RAWSZ];
 	unsigned short carry = 0;
 	int i;
 
-	git_SHA1_Final(hash, ctx);
-	git_SHA1_Init(ctx);
+	the_hash_algo->final_fn(hash, ctx);
+	the_hash_algo->init_fn(ctx);
 	/* 20-byte sum, with carry */
-	for (i = 0; i < GIT_SHA1_RAWSZ; ++i) {
+	for (i = 0; i < the_hash_algo->rawsz; ++i) {
 		carry += result->hash[i] + hash[i];
 		result->hash[i] = carry;
 		carry >>= 8;
@@ -6018,21 +6018,21 @@ static void patch_id_consume(void *priv, char *line, unsigned long len)
 
 	new_len = remove_space(line, len);
 
-	git_SHA1_Update(data->ctx, line, new_len);
+	the_hash_algo->update_fn(data->ctx, line, new_len);
 	data->patchlen += new_len;
 }
 
-static void patch_id_add_string(git_SHA_CTX *ctx, const char *str)
+static void patch_id_add_string(git_hash_ctx *ctx, const char *str)
 {
-	git_SHA1_Update(ctx, str, strlen(str));
+	the_hash_algo->update_fn(ctx, str, strlen(str));
 }
 
-static void patch_id_add_mode(git_SHA_CTX *ctx, unsigned mode)
+static void patch_id_add_mode(git_hash_ctx *ctx, unsigned mode)
 {
 	/* large enough for 2^32 in octal */
 	char buf[12];
 	int len = xsnprintf(buf, sizeof(buf), "%06o", mode);
-	git_SHA1_Update(ctx, buf, len);
+	the_hash_algo->update_fn(ctx, buf, len);
 }
 
 /* returns 0 upon success, and writes result into oid */
@@ -6040,10 +6040,10 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
 {
 	struct diff_queue_struct *q = &diff_queued_diff;
 	int i;
-	git_SHA_CTX ctx;
+	git_hash_ctx ctx;
 	struct patch_id_t data;
 
-	git_SHA1_Init(&ctx);
+	the_hash_algo->init_fn(&ctx);
 	memset(&data, 0, sizeof(struct patch_id_t));
 	data.ctx = &ctx;
 	oidclr(oid);
@@ -6076,27 +6076,27 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
 		len2 = remove_space(p->two->path, strlen(p->two->path));
 		patch_id_add_string(&ctx, "diff--git");
 		patch_id_add_string(&ctx, "a/");
-		git_SHA1_Update(&ctx, p->one->path, len1);
+		the_hash_algo->update_fn(&ctx, p->one->path, len1);
 		patch_id_add_string(&ctx, "b/");
-		git_SHA1_Update(&ctx, p->two->path, len2);
+		the_hash_algo->update_fn(&ctx, p->two->path, len2);
 
 		if (p->one->mode == 0) {
 			patch_id_add_string(&ctx, "newfilemode");
 			patch_id_add_mode(&ctx, p->two->mode);
 			patch_id_add_string(&ctx, "---/dev/null");
 			patch_id_add_string(&ctx, "+++b/");
-			git_SHA1_Update(&ctx, p->two->path, len2);
+			the_hash_algo->update_fn(&ctx, p->two->path, len2);
 		} else if (p->two->mode == 0) {
 			patch_id_add_string(&ctx, "deletedfilemode");
 			patch_id_add_mode(&ctx, p->one->mode);
 			patch_id_add_string(&ctx, "---a/");
-			git_SHA1_Update(&ctx, p->one->path, len1);
+			the_hash_algo->update_fn(&ctx, p->one->path, len1);
 			patch_id_add_string(&ctx, "+++/dev/null");
 		} else {
 			patch_id_add_string(&ctx, "---a/");
-			git_SHA1_Update(&ctx, p->one->path, len1);
+			the_hash_algo->update_fn(&ctx, p->one->path, len1);
 			patch_id_add_string(&ctx, "+++b/");
-			git_SHA1_Update(&ctx, p->two->path, len2);
+			the_hash_algo->update_fn(&ctx, p->two->path, len2);
 		}
 
 		if (diff_header_only)
@@ -6108,10 +6108,10 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
 
 		if (diff_filespec_is_binary(options->repo, p->one) ||
 		    diff_filespec_is_binary(options->repo, p->two)) {
-			git_SHA1_Update(&ctx, oid_to_hex(&p->one->oid),
-					GIT_SHA1_HEXSZ);
-			git_SHA1_Update(&ctx, oid_to_hex(&p->two->oid),
-					GIT_SHA1_HEXSZ);
+			the_hash_algo->update_fn(&ctx, oid_to_hex(&p->one->oid),
+					the_hash_algo->hexsz);
+			the_hash_algo->update_fn(&ctx, oid_to_hex(&p->two->oid),
+					the_hash_algo->hexsz);
 			continue;
 		}
 
@@ -6128,7 +6128,7 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
 	}
 
 	if (!stable)
-		git_SHA1_Final(oid->hash, &ctx);
+		the_hash_algo->final_fn(oid->hash, &ctx);
 
 	return 0;
 }
diff --git a/diff.h b/diff.h
index c2c3056810..7f8f024feb 100644
--- a/diff.h
+++ b/diff.h
@@ -438,7 +438,7 @@ int run_diff_index(struct rev_info *revs, int cached);
 
 int do_diff_cache(const struct object_id *, struct diff_options *);
 int diff_flush_patch_id(struct diff_options *, struct object_id *, int, int);
-void flush_one_hunk(struct object_id *, git_SHA_CTX *);
+void flush_one_hunk(struct object_id *result, git_hash_ctx *ctx);
 
 int diff_result_code(struct diff_options *, int);
 

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 03/26] fetch-pack: use parse_oid_hex
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
  2019-08-18 20:04 ` [PATCH 01/26] builtin/replace: make hash size independent brian m. carlson
  2019-08-18 20:04 ` [PATCH 02/26] patch-id: convert to use the_hash_algo brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-18 20:04 ` [PATCH 04/26] builtin/receive-pack: switch to use the_hash_algo brian m. carlson
                   ` (22 subsequent siblings)
  25 siblings, 0 replies; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

Instead of hard-coding constants, use parse_oid_hex to compute a pointer
and use it in further parsing operations.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 fetch-pack.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/fetch-pack.c b/fetch-pack.c
index 65be043f2a..1f56b8a6d7 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -168,16 +168,16 @@ static enum ack_type get_ack(struct packet_reader *reader,
 	if (!strcmp(reader->line, "NAK"))
 		return NAK;
 	if (skip_prefix(reader->line, "ACK ", &arg)) {
-		if (!get_oid_hex(arg, result_oid)) {
-			arg += 40;
-			len -= arg - reader->line;
+		const char *p;
+		if (!parse_oid_hex(arg, result_oid, &p)) {
+			len -= p - reader->line;
 			if (len < 1)
 				return ACK;
-			if (strstr(arg, "continue"))
+			if (strstr(p, "continue"))
 				return ACK_continue;
-			if (strstr(arg, "common"))
+			if (strstr(p, "common"))
 				return ACK_common;
-			if (strstr(arg, "ready"))
+			if (strstr(p, "ready"))
 				return ACK_ready;
 			return ACK;
 		}

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 04/26] builtin/receive-pack: switch to use the_hash_algo
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
                   ` (2 preceding siblings ...)
  2019-08-18 20:04 ` [PATCH 03/26] fetch-pack: use parse_oid_hex brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-18 20:04 ` [PATCH 05/26] builtin/blame: switch uses of GIT_SHA1_HEXSZ to the_hash_algo brian m. carlson
                   ` (21 subsequent siblings)
  25 siblings, 0 replies; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

The push cert code uses HMAC-SHA-1 to create a nonce.  This is a secure
use of SHA-1 which is not affected by its collision resistance (or lack
thereof).  However, it makes sense for us to use a better algorithm if
one is available, one which may even be more performant.  Futhermore,
until we have specialized functions for computing the hex value of an
arbitrary function, it simplifies the code greatly to use the same hash
algorithm everywhere.

Switch this code to use GIT_MAX_BLKSZ and the_hash_algo for computing
the push cert nonce, and rename the hmac_sha1 function to simply "hmac".

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/receive-pack.c | 44 ++++++++++++++++++++----------------------
 1 file changed, 21 insertions(+), 23 deletions(-)

diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index dcf385511f..402edf34d8 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -417,24 +417,22 @@ static int copy_to_sideband(int in, int out, void *arg)
 	return 0;
 }
 
-#define HMAC_BLOCK_SIZE 64
-
-static void hmac_sha1(unsigned char *out,
+static void hmac(unsigned char *out,
 		      const char *key_in, size_t key_len,
 		      const char *text, size_t text_len)
 {
-	unsigned char key[HMAC_BLOCK_SIZE];
-	unsigned char k_ipad[HMAC_BLOCK_SIZE];
-	unsigned char k_opad[HMAC_BLOCK_SIZE];
+	unsigned char key[GIT_MAX_BLKSZ];
+	unsigned char k_ipad[GIT_MAX_BLKSZ];
+	unsigned char k_opad[GIT_MAX_BLKSZ];
 	int i;
-	git_SHA_CTX ctx;
+	git_hash_ctx ctx;
 
 	/* RFC 2104 2. (1) */
-	memset(key, '\0', HMAC_BLOCK_SIZE);
-	if (HMAC_BLOCK_SIZE < key_len) {
-		git_SHA1_Init(&ctx);
-		git_SHA1_Update(&ctx, key_in, key_len);
-		git_SHA1_Final(key, &ctx);
+	memset(key, '\0', GIT_MAX_BLKSZ);
+	if (the_hash_algo->blksz < key_len) {
+		the_hash_algo->init_fn(&ctx);
+		the_hash_algo->update_fn(&ctx, key_in, key_len);
+		the_hash_algo->final_fn(key, &ctx);
 	} else {
 		memcpy(key, key_in, key_len);
 	}
@@ -446,29 +444,29 @@ static void hmac_sha1(unsigned char *out,
 	}
 
 	/* RFC 2104 2. (3) & (4) */
-	git_SHA1_Init(&ctx);
-	git_SHA1_Update(&ctx, k_ipad, sizeof(k_ipad));
-	git_SHA1_Update(&ctx, text, text_len);
-	git_SHA1_Final(out, &ctx);
+	the_hash_algo->init_fn(&ctx);
+	the_hash_algo->update_fn(&ctx, k_ipad, sizeof(k_ipad));
+	the_hash_algo->update_fn(&ctx, text, text_len);
+	the_hash_algo->final_fn(out, &ctx);
 
 	/* RFC 2104 2. (6) & (7) */
-	git_SHA1_Init(&ctx);
-	git_SHA1_Update(&ctx, k_opad, sizeof(k_opad));
-	git_SHA1_Update(&ctx, out, GIT_SHA1_RAWSZ);
-	git_SHA1_Final(out, &ctx);
+	the_hash_algo->init_fn(&ctx);
+	the_hash_algo->update_fn(&ctx, k_opad, sizeof(k_opad));
+	the_hash_algo->update_fn(&ctx, out, the_hash_algo->rawsz);
+	the_hash_algo->final_fn(out, &ctx);
 }
 
 static char *prepare_push_cert_nonce(const char *path, timestamp_t stamp)
 {
 	struct strbuf buf = STRBUF_INIT;
-	unsigned char sha1[GIT_SHA1_RAWSZ];
+	unsigned char hash[GIT_MAX_RAWSZ];
 
 	strbuf_addf(&buf, "%s:%"PRItime, path, stamp);
-	hmac_sha1(sha1, buf.buf, buf.len, cert_nonce_seed, strlen(cert_nonce_seed));
+	hmac(hash, buf.buf, buf.len, cert_nonce_seed, strlen(cert_nonce_seed));
 	strbuf_release(&buf);
 
 	/* RFC 2104 5. HMAC-SHA1-80 */
-	strbuf_addf(&buf, "%"PRItime"-%.*s", stamp, GIT_SHA1_HEXSZ, sha1_to_hex(sha1));
+	strbuf_addf(&buf, "%"PRItime"-%.*s", stamp, (int)the_hash_algo->hexsz, sha1_to_hex(hash));
 	return strbuf_detach(&buf, NULL);
 }
 

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 05/26] builtin/blame: switch uses of GIT_SHA1_HEXSZ to the_hash_algo
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
                   ` (3 preceding siblings ...)
  2019-08-18 20:04 ` [PATCH 04/26] builtin/receive-pack: switch to use the_hash_algo brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-18 20:04 ` [PATCH 06/26] builtin/rev-parse: switch to use the_hash_algo brian m. carlson
                   ` (20 subsequent siblings)
  25 siblings, 0 replies; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

Switch several uses of GIT_SHA1_HEXSZ to the_hash_algo.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/blame.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/builtin/blame.c b/builtin/blame.c
index b6534d4dea..5a0c0c2312 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -460,7 +460,7 @@ static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent, int
 
 	for (cnt = 0; cnt < ent->num_lines; cnt++) {
 		char ch;
-		int length = (opt & OUTPUT_LONG_OBJECT_NAME) ? GIT_SHA1_HEXSZ : abbrev;
+		int length = (opt & OUTPUT_LONG_OBJECT_NAME) ? the_hash_algo->hexsz : abbrev;
 
 		if (opt & OUTPUT_COLOR_LINE) {
 			if (cnt > 0) {
@@ -885,6 +885,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
 	struct range_set ranges;
 	unsigned int range_i;
 	long anchor;
+	const int hexsz = the_hash_algo->hexsz;
 
 	setup_default_color_by_age();
 	git_config(git_blame_config, &output_option);
@@ -931,11 +932,11 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
 	} else if (show_progress < 0)
 		show_progress = isatty(2);
 
-	if (0 < abbrev && abbrev < GIT_SHA1_HEXSZ)
+	if (0 < abbrev && abbrev < hexsz)
 		/* one more abbrev length is needed for the boundary commit */
 		abbrev++;
 	else if (!abbrev)
-		abbrev = GIT_SHA1_HEXSZ;
+		abbrev = hexsz;
 
 	if (revs_file && read_ancestry(revs_file))
 		die_errno("reading graft file '%s' failed", revs_file);

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 06/26] builtin/rev-parse: switch to use the_hash_algo
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
                   ` (4 preceding siblings ...)
  2019-08-18 20:04 ` [PATCH 05/26] builtin/blame: switch uses of GIT_SHA1_HEXSZ to the_hash_algo brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-18 20:04 ` [PATCH 07/26] blame: remove needless comparison with GIT_SHA1_HEXSZ brian m. carlson
                   ` (19 subsequent siblings)
  25 siblings, 0 replies; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

Switch several hard-coded uses of the constant 40 to references to
the_hash_algo.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/rev-parse.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index f8bbe6d47e..308c67e4fc 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -593,6 +593,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 	const char *name = NULL;
 	struct object_context unused;
 	struct strbuf buf = STRBUF_INIT;
+	const int hexsz = the_hash_algo->hexsz;
 
 	if (argc > 1 && !strcmp("--parseopt", argv[1]))
 		return cmd_parseopt(argc - 1, argv + 1, prefix);
@@ -730,8 +731,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 				abbrev = strtoul(arg, NULL, 10);
 				if (abbrev < MINIMUM_ABBREV)
 					abbrev = MINIMUM_ABBREV;
-				else if (40 <= abbrev)
-					abbrev = 40;
+				else if (hexsz <= abbrev)
+					abbrev = hexsz;
 				continue;
 			}
 			if (!strcmp(arg, "--sq")) {

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 07/26] blame: remove needless comparison with GIT_SHA1_HEXSZ
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
                   ` (5 preceding siblings ...)
  2019-08-18 20:04 ` [PATCH 06/26] builtin/rev-parse: switch to use the_hash_algo brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-18 20:04 ` [PATCH 08/26] show-index: switch hard-coded constants to the_hash_algo brian m. carlson
                   ` (18 subsequent siblings)
  25 siblings, 0 replies; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

When faking a working tree commit, we read in lines from MERGE_HEAD into
a strbuf.  Because the strbuf is NUL-terminated and get_oid_hex will
fail if it unexpectedly encounters a NUL, the check for the length of
the line is unnecessary.  There is no optimization benefit from this
case, either, since on failure we call die.  Remove this check, since it
is no longer needed.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 blame.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/blame.c b/blame.c
index 36a2e7ef11..6596d8de88 100644
--- a/blame.c
+++ b/blame.c
@@ -144,7 +144,7 @@ static void append_merge_parents(struct repository *r,
 
 	while (!strbuf_getwholeline_fd(&line, merge_head, '\n')) {
 		struct object_id oid;
-		if (line.len < GIT_SHA1_HEXSZ || get_oid_hex(line.buf, &oid))
+		if (get_oid_hex(line.buf, &oid))
 			die("unknown line in '%s': %s",
 			    git_path_merge_head(r), line.buf);
 		tail = append_parent(r, tail, &oid);

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 08/26] show-index: switch hard-coded constants to the_hash_algo
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
                   ` (6 preceding siblings ...)
  2019-08-18 20:04 ` [PATCH 07/26] blame: remove needless comparison with GIT_SHA1_HEXSZ brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-18 20:04 ` [PATCH 09/26] connected: switch GIT_SHA1_HEXSZ " brian m. carlson
                   ` (17 subsequent siblings)
  25 siblings, 0 replies; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

show-index uses a variety of hard-coded constants to enumerate the
values in pack indices.  Switch these hard-coded constants to use
the_hash_algo or GIT_MAX_RAWSZ, as appropriate, and convert one instance
of an unsigned char array to struct object_id.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/show-index.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/builtin/show-index.c b/builtin/show-index.c
index a6e678809e..e95b84e8eb 100644
--- a/builtin/show-index.c
+++ b/builtin/show-index.c
@@ -11,6 +11,7 @@ int cmd_show_index(int argc, const char **argv, const char *prefix)
 	unsigned nr;
 	unsigned int version;
 	static unsigned int top_index[256];
+	const unsigned hashsz = the_hash_algo->rawsz;
 
 	if (argc != 1)
 		usage(show_index_usage);
@@ -36,9 +37,9 @@ int cmd_show_index(int argc, const char **argv, const char *prefix)
 	}
 	if (version == 1) {
 		for (i = 0; i < nr; i++) {
-			unsigned int offset, entry[6];
+			unsigned int offset, entry[(GIT_MAX_RAWSZ + 4) / sizeof(unsigned int)];
 
-			if (fread(entry, 4 + 20, 1, stdin) != 1)
+			if (fread(entry, 4 + hashsz, 1, stdin) != 1)
 				die("unable to read entry %u/%u", i, nr);
 			offset = ntohl(entry[0]);
 			printf("%u %s\n", offset, sha1_to_hex((void *)(entry+1)));
@@ -46,13 +47,13 @@ int cmd_show_index(int argc, const char **argv, const char *prefix)
 	} else {
 		unsigned off64_nr = 0;
 		struct {
-			unsigned char sha1[20];
+			struct object_id oid;
 			uint32_t crc;
 			uint32_t off;
 		} *entries;
 		ALLOC_ARRAY(entries, nr);
 		for (i = 0; i < nr; i++)
-			if (fread(entries[i].sha1, 20, 1, stdin) != 1)
+			if (fread(entries[i].oid.hash, hashsz, 1, stdin) != 1)
 				die("unable to read sha1 %u/%u", i, nr);
 		for (i = 0; i < nr; i++)
 			if (fread(&entries[i].crc, 4, 1, stdin) != 1)
@@ -77,7 +78,7 @@ int cmd_show_index(int argc, const char **argv, const char *prefix)
 			}
 			printf("%" PRIuMAX " %s (%08"PRIx32")\n",
 			       (uintmax_t) offset,
-			       sha1_to_hex(entries[i].sha1),
+			       oid_to_hex(&entries[i].oid),
 			       ntohl(entries[i].crc));
 		}
 		free(entries);

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 09/26] connected: switch GIT_SHA1_HEXSZ to the_hash_algo
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
                   ` (7 preceding siblings ...)
  2019-08-18 20:04 ` [PATCH 08/26] show-index: switch hard-coded constants to the_hash_algo brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-18 20:04 ` [PATCH 10/26] bundle: switch to use the_hash_algo brian m. carlson
                   ` (16 subsequent siblings)
  25 siblings, 0 replies; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

Switch various uses of GIT_SHA1_HEXSZ to reference the_hash_algo
instead.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 connected.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/connected.c b/connected.c
index cd9b324afa..7cd3bc9979 100644
--- a/connected.c
+++ b/connected.c
@@ -28,6 +28,7 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
 	struct packed_git *new_pack = NULL;
 	struct transport *transport;
 	size_t base_len;
+	const unsigned hexsz = the_hash_algo->hexsz;
 
 	if (!opt)
 		opt = &defaults;
@@ -99,7 +100,7 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
 
 	sigchain_push(SIGPIPE, SIG_IGN);
 
-	commit[GIT_SHA1_HEXSZ] = '\n';
+	commit[hexsz] = '\n';
 	do {
 		/*
 		 * If index-pack already checked that:
@@ -112,8 +113,8 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
 		if (new_pack && find_pack_entry_one(oid.hash, new_pack))
 			continue;
 
-		memcpy(commit, oid_to_hex(&oid), GIT_SHA1_HEXSZ);
-		if (write_in_full(rev_list.in, commit, GIT_SHA1_HEXSZ + 1) < 0) {
+		memcpy(commit, oid_to_hex(&oid), hexsz);
+		if (write_in_full(rev_list.in, commit, hexsz + 1) < 0) {
 			if (errno != EPIPE && errno != EINVAL)
 				error_errno(_("failed write to rev-list"));
 			err = -1;

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 10/26] bundle: switch to use the_hash_algo
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
                   ` (8 preceding siblings ...)
  2019-08-18 20:04 ` [PATCH 09/26] connected: switch GIT_SHA1_HEXSZ " brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-18 20:04 ` [PATCH 11/26] combine-diff: replace GIT_SHA1_HEXSZ with the_hash_algo brian m. carlson
                   ` (15 subsequent siblings)
  25 siblings, 0 replies; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

Switch a use of the constant 40 and a use of GIT_SHA1_HEXSZ to use
the_hash_algo instead.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 bundle.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bundle.c b/bundle.c
index b5d21cd80f..a85ed3f7bc 100644
--- a/bundle.c
+++ b/bundle.c
@@ -282,7 +282,7 @@ static int write_pack_data(int bundle_fd, struct rev_info *revs)
 		struct object *object = revs->pending.objects[i].item;
 		if (object->flags & UNINTERESTING)
 			write_or_die(pack_objects.in, "^", 1);
-		write_or_die(pack_objects.in, oid_to_hex(&object->oid), GIT_SHA1_HEXSZ);
+		write_or_die(pack_objects.in, oid_to_hex(&object->oid), the_hash_algo->hexsz);
 		write_or_die(pack_objects.in, "\n", 1);
 	}
 	close(pack_objects.in);
@@ -414,7 +414,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
 		}
 
 		ref_count++;
-		write_or_die(bundle_fd, oid_to_hex(&e->item->oid), 40);
+		write_or_die(bundle_fd, oid_to_hex(&e->item->oid), the_hash_algo->hexsz);
 		write_or_die(bundle_fd, " ", 1);
 		write_or_die(bundle_fd, display_ref, strlen(display_ref));
 		write_or_die(bundle_fd, "\n", 1);

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 11/26] combine-diff: replace GIT_SHA1_HEXSZ with the_hash_algo
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
                   ` (9 preceding siblings ...)
  2019-08-18 20:04 ` [PATCH 10/26] bundle: switch to use the_hash_algo brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-18 20:04 ` [PATCH 12/26] config: use the_hash_algo in abbrev comparison brian m. carlson
                   ` (14 subsequent siblings)
  25 siblings, 0 replies; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 combine-diff.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/combine-diff.c b/combine-diff.c
index 3e49f3bda8..d5c4d839dc 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -930,7 +930,7 @@ static void show_combined_header(struct combine_diff_path *elem,
 				 int show_file_header)
 {
 	struct diff_options *opt = &rev->diffopt;
-	int abbrev = opt->flags.full_index ? GIT_SHA1_HEXSZ : DEFAULT_ABBREV;
+	int abbrev = opt->flags.full_index ? the_hash_algo->hexsz : DEFAULT_ABBREV;
 	const char *a_prefix = opt->a_prefix ? opt->a_prefix : "a/";
 	const char *b_prefix = opt->b_prefix ? opt->b_prefix : "b/";
 	const char *c_meta = diff_get_color_opt(opt, DIFF_METAINFO);

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 12/26] config: use the_hash_algo in abbrev comparison
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
                   ` (10 preceding siblings ...)
  2019-08-18 20:04 ` [PATCH 11/26] combine-diff: replace GIT_SHA1_HEXSZ with the_hash_algo brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-18 20:04 ` [PATCH 13/26] sha1-lookup: switch hard-coded constants to the_hash_algo brian m. carlson
                   ` (13 subsequent siblings)
  25 siblings, 0 replies; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

Switch one use of a hard-coded 40 constant to use the_hash_algo.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 config.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/config.c b/config.c
index 3900e4947b..b0f79aab21 100644
--- a/config.c
+++ b/config.c
@@ -1204,7 +1204,7 @@ static int git_default_core_config(const char *var, const char *value, void *cb)
 			default_abbrev = -1;
 		else {
 			int abbrev = git_config_int(var, value);
-			if (abbrev < minimum_abbrev || abbrev > 40)
+			if (abbrev < minimum_abbrev || abbrev > the_hash_algo->hexsz)
 				return error(_("abbrev length out of range: %d"), abbrev);
 			default_abbrev = abbrev;
 		}

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 13/26] sha1-lookup: switch hard-coded constants to the_hash_algo
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
                   ` (11 preceding siblings ...)
  2019-08-18 20:04 ` [PATCH 12/26] config: use the_hash_algo in abbrev comparison brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-18 20:04 ` [PATCH 14/26] bisect: switch to using the_hash_algo brian m. carlson
                   ` (12 subsequent siblings)
  25 siblings, 0 replies; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

Switch a hard-coded 18 to be a reference to the_hash_algo.  Rename the
sha1 parameter to be called hash instead.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 sha1-lookup.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/sha1-lookup.c b/sha1-lookup.c
index 796ab68da8..93d9af0805 100644
--- a/sha1-lookup.c
+++ b/sha1-lookup.c
@@ -50,7 +50,7 @@ static uint32_t take2(const unsigned char *sha1)
  * The sha1 of element i (between 0 and nr - 1) should be returned
  * by "fn(i, table)".
  */
-int sha1_pos(const unsigned char *sha1, void *table, size_t nr,
+int sha1_pos(const unsigned char *hash, void *table, size_t nr,
 	     sha1_access_fn fn)
 {
 	size_t hi = nr;
@@ -63,10 +63,10 @@ int sha1_pos(const unsigned char *sha1, void *table, size_t nr,
 	if (nr != 1) {
 		size_t lov, hiv, miv, ofs;
 
-		for (ofs = 0; ofs < 18; ofs += 2) {
+		for (ofs = 0; ofs < the_hash_algo->rawsz - 2; ofs += 2) {
 			lov = take2(fn(0, table) + ofs);
 			hiv = take2(fn(nr - 1, table) + ofs);
-			miv = take2(sha1 + ofs);
+			miv = take2(hash + ofs);
 			if (miv < lov)
 				return -1;
 			if (hiv < miv)
@@ -88,7 +88,7 @@ int sha1_pos(const unsigned char *sha1, void *table, size_t nr,
 
 	do {
 		int cmp;
-		cmp = hashcmp(fn(mi, table), sha1);
+		cmp = hashcmp(fn(mi, table), hash);
 		if (!cmp)
 			return mi;
 		if (cmp > 0)

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 14/26] bisect: switch to using the_hash_algo
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
                   ` (12 preceding siblings ...)
  2019-08-18 20:04 ` [PATCH 13/26] sha1-lookup: switch hard-coded constants to the_hash_algo brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-18 20:04 ` [PATCH 15/26] sequencer: convert to use the_hash_algo brian m. carlson
                   ` (11 subsequent siblings)
  25 siblings, 0 replies; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

Instead of using GIT_SHA1_HEXSZ, use the_hash_algo so that the code is
hash size independent.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 bisect.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bisect.c b/bisect.c
index e87ac29a51..e81c91d02c 100644
--- a/bisect.c
+++ b/bisect.c
@@ -707,7 +707,7 @@ static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout)
 {
 	char bisect_rev_hex[GIT_MAX_HEXSZ + 1];
 
-	memcpy(bisect_rev_hex, oid_to_hex(bisect_rev), GIT_SHA1_HEXSZ + 1);
+	memcpy(bisect_rev_hex, oid_to_hex(bisect_rev), the_hash_algo->hexsz + 1);
 	update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
 
 	argv_checkout[2] = bisect_rev_hex;

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 15/26] sequencer: convert to use the_hash_algo
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
                   ` (13 preceding siblings ...)
  2019-08-18 20:04 ` [PATCH 14/26] bisect: switch to using the_hash_algo brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-18 20:04 ` [PATCH 16/26] pack-write: use hash_to_hex when writing checksums brian m. carlson
                   ` (10 subsequent siblings)
  25 siblings, 0 replies; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

Convert several uses of GIT_SHA1_HEXSZ constants to be references to
the_hash_algo.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 sequencer.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/sequencer.c b/sequencer.c
index 34ebf8ed94..4d25e79137 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -3568,7 +3568,7 @@ static int do_merge(struct repository *r,
 		goto leave_merge;
 	}
 
-	write_message(oid_to_hex(&merge_commit->object.oid), GIT_SHA1_HEXSZ,
+	write_message(oid_to_hex(&merge_commit->object.oid), the_hash_algo->hexsz,
 		      git_path_merge_head(r), 0);
 	write_message("no-ff", 5, git_path_merge_mode(r), 0);
 
@@ -4487,7 +4487,7 @@ static const char *label_oid(struct object_id *oid, const char *label,
 		char *p;
 
 		strbuf_reset(&state->buf);
-		strbuf_grow(&state->buf, GIT_SHA1_HEXSZ);
+		strbuf_grow(&state->buf, GIT_MAX_HEXSZ);
 		label = p = state->buf.buf;
 
 		find_unique_abbrev_r(p, oid, default_abbrev);
@@ -4500,7 +4500,7 @@ static const char *label_oid(struct object_id *oid, const char *label,
 			size_t i = strlen(p) + 1;
 
 			oid_to_hex_r(p, oid);
-			for (; i < GIT_SHA1_HEXSZ; i++) {
+			for (; i < the_hash_algo->hexsz; i++) {
 				char save = p[i];
 				p[i] = '\0';
 				if (!hashmap_get_from_hash(&state->labels,

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 16/26] pack-write: use hash_to_hex when writing checksums
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
                   ` (14 preceding siblings ...)
  2019-08-18 20:04 ` [PATCH 15/26] sequencer: convert to use the_hash_algo brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-18 20:04 ` [PATCH 17/26] builtin/repack: write object IDs of the proper length brian m. carlson
                   ` (9 subsequent siblings)
  25 siblings, 0 replies; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

Pack checksums always use the current hash algorithm in use, so switch
from sha1_to_hex to hash_to_hex.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 pack-write.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pack-write.c b/pack-write.c
index 29d17a9bec..f0017beb9d 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -349,7 +349,7 @@ void finish_tmp_packfile(struct strbuf *name_buffer,
 			 struct pack_idx_entry **written_list,
 			 uint32_t nr_written,
 			 struct pack_idx_option *pack_idx_opts,
-			 unsigned char sha1[])
+			 unsigned char hash[])
 {
 	const char *idx_tmp_name;
 	int basename_len = name_buffer->len;
@@ -358,18 +358,18 @@ void finish_tmp_packfile(struct strbuf *name_buffer,
 		die_errno("unable to make temporary pack file readable");
 
 	idx_tmp_name = write_idx_file(NULL, written_list, nr_written,
-				      pack_idx_opts, sha1);
+				      pack_idx_opts, hash);
 	if (adjust_shared_perm(idx_tmp_name))
 		die_errno("unable to make temporary index file readable");
 
-	strbuf_addf(name_buffer, "%s.pack", sha1_to_hex(sha1));
+	strbuf_addf(name_buffer, "%s.pack", hash_to_hex(hash));
 
 	if (rename(pack_tmp_name, name_buffer->buf))
 		die_errno("unable to rename temporary pack file");
 
 	strbuf_setlen(name_buffer, basename_len);
 
-	strbuf_addf(name_buffer, "%s.idx", sha1_to_hex(sha1));
+	strbuf_addf(name_buffer, "%s.idx", hash_to_hex(hash));
 	if (rename(idx_tmp_name, name_buffer->buf))
 		die_errno("unable to rename temporary index file");
 

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 17/26] builtin/repack: write object IDs of the proper length
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
                   ` (15 preceding siblings ...)
  2019-08-18 20:04 ` [PATCH 16/26] pack-write: use hash_to_hex when writing checksums brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-18 20:04 ` [PATCH 18/26] builtin/worktree: switch null_sha1 to null_oid brian m. carlson
                   ` (8 subsequent siblings)
  25 siblings, 0 replies; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

Use the_hash_algo when calling xwrite with a hex object ID so that the
proper amount of data is written.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/repack.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/repack.c b/builtin/repack.c
index 632c0c0a79..5830f796e0 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -190,7 +190,7 @@ static int write_oid(const struct object_id *oid, struct packed_git *pack,
 			die(_("could not start pack-objects to repack promisor objects"));
 	}
 
-	xwrite(cmd->in, oid_to_hex(oid), GIT_SHA1_HEXSZ);
+	xwrite(cmd->in, oid_to_hex(oid), the_hash_algo->hexsz);
 	xwrite(cmd->in, "\n", 1);
 	return 0;
 }

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 18/26] builtin/worktree: switch null_sha1 to null_oid
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
                   ` (16 preceding siblings ...)
  2019-08-18 20:04 ` [PATCH 17/26] builtin/repack: write object IDs of the proper length brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-18 20:04 ` [PATCH 19/26] cache: remove null_sha1 brian m. carlson
                   ` (7 subsequent siblings)
  25 siblings, 0 replies; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

Switch the remaining use of null_sha1 to null_oid.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/worktree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/worktree.c b/builtin/worktree.c
index a5bb02b207..0c0df3b0b8 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -350,7 +350,7 @@ static int add_worktree(const char *path, const char *refname,
 	 */
 	strbuf_reset(&sb);
 	strbuf_addf(&sb, "%s/HEAD", sb_repo.buf);
-	write_file(sb.buf, "%s", sha1_to_hex(null_sha1));
+	write_file(sb.buf, "%s", oid_to_hex(&null_oid));
 	strbuf_reset(&sb);
 	strbuf_addf(&sb, "%s/commondir", sb_repo.buf);
 	write_file(sb.buf, "../..");

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 19/26] cache: remove null_sha1
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
                   ` (17 preceding siblings ...)
  2019-08-18 20:04 ` [PATCH 18/26] builtin/worktree: switch null_sha1 to null_oid brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-18 20:04 ` [PATCH 20/26] wt-status: convert struct wt_status to object_id brian m. carlson
                   ` (6 subsequent siblings)
  25 siblings, 0 replies; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

All of the existing uses of null_sha1 can be converted into uses of
null_oid, so do so.  Remove null_sha1 and is_null_sha1, and define
is_null_oid in terms of null_oid.  This also has the additional benefit
of removing several uses of sha1_to_hex.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/clone.c             | 2 +-
 builtin/submodule--helper.c | 2 +-
 cache.h                     | 8 +-------
 sha1-file.c                 | 1 -
 4 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/builtin/clone.c b/builtin/clone.c
index f665b28ccc..eabd02846a 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -785,7 +785,7 @@ static int checkout(int submodule_progress)
 	if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
 		die(_("unable to write new index file"));
 
-	err |= run_hook_le(NULL, "post-checkout", sha1_to_hex(null_sha1),
+	err |= run_hook_le(NULL, "post-checkout", oid_to_hex(&null_oid),
 			   oid_to_hex(&oid), "1", NULL);
 
 	if (!err && (option_recurse_submodules.nr > 0)) {
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 909e77e802..8a6f2abce4 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -424,7 +424,7 @@ static int module_list(int argc, const char **argv, const char *prefix)
 		const struct cache_entry *ce = list.entries[i];
 
 		if (ce_stage(ce))
-			printf("%06o %s U\t", ce->ce_mode, sha1_to_hex(null_sha1));
+			printf("%06o %s U\t", ce->ce_mode, oid_to_hex(&null_oid));
 		else
 			printf("%06o %s %d\t", ce->ce_mode,
 			       oid_to_hex(&ce->oid), ce_stage(ce));
diff --git a/cache.h b/cache.h
index b1da1ab08f..79efd2168f 100644
--- a/cache.h
+++ b/cache.h
@@ -1029,7 +1029,6 @@ const char *repo_find_unique_abbrev(struct repository *r, const struct object_id
 int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len);
 #define find_unique_abbrev_r(hex, oid, len) repo_find_unique_abbrev_r(the_repository, hex, oid, len)
 
-extern const unsigned char null_sha1[GIT_MAX_RAWSZ];
 extern const struct object_id null_oid;
 
 static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
@@ -1064,14 +1063,9 @@ static inline int oideq(const struct object_id *oid1, const struct object_id *oi
 	return hasheq(oid1->hash, oid2->hash);
 }
 
-static inline int is_null_sha1(const unsigned char *sha1)
-{
-	return hasheq(sha1, null_sha1);
-}
-
 static inline int is_null_oid(const struct object_id *oid)
 {
-	return hasheq(oid->hash, null_sha1);
+	return oideq(oid, &null_oid);
 }
 
 static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)
diff --git a/sha1-file.c b/sha1-file.c
index 487ea35d2d..0ea28f7da3 100644
--- a/sha1-file.c
+++ b/sha1-file.c
@@ -55,7 +55,6 @@
 	"\x6f\xe1\x41\xf7\x74\x91\x20\xa3\x03\x72" \
 	"\x18\x13"
 
-const unsigned char null_sha1[GIT_MAX_RAWSZ];
 const struct object_id null_oid;
 static const struct object_id empty_tree_oid = {
 	EMPTY_TREE_SHA1_BIN_LITERAL

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 20/26] wt-status: convert struct wt_status to object_id
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
                   ` (18 preceding siblings ...)
  2019-08-18 20:04 ` [PATCH 19/26] cache: remove null_sha1 brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-18 20:04 ` [PATCH 21/26] packfile: replace sha1_to_hex brian m. carlson
                   ` (5 subsequent siblings)
  25 siblings, 0 replies; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

Change struct wt_status to use struct object_id instead of an array of
unsigned char.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/commit.c | 4 ++--
 wt-status.c      | 2 +-
 wt-status.h      | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index ae7aaf6dc6..e588bc6ad3 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -510,7 +510,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
 	s->nowarn = nowarn;
 	s->is_initial = get_oid(s->reference, &oid) ? 1 : 0;
 	if (!s->is_initial)
-		hashcpy(s->sha1_commit, oid.hash);
+		oidcpy(&s->oid_commit, &oid);
 	s->status_format = status_format;
 	s->ignore_submodule_arg = ignore_submodule_arg;
 
@@ -1406,7 +1406,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 
 	s.is_initial = get_oid(s.reference, &oid) ? 1 : 0;
 	if (!s.is_initial)
-		hashcpy(s.sha1_commit, oid.hash);
+		oidcpy(&s.oid_commit, &oid);
 
 	s.ignore_submodule_arg = ignore_submodule_arg;
 	s.status_format = status_format;
diff --git a/wt-status.c b/wt-status.c
index 9f6c65a580..7cf220fed4 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -2025,7 +2025,7 @@ static void wt_porcelain_v2_print_tracking(struct wt_status *s)
 	char eol = s->null_termination ? '\0' : '\n';
 
 	fprintf(s->fp, "# branch.oid %s%c",
-			(s->is_initial ? "(initial)" : sha1_to_hex(s->sha1_commit)),
+			(s->is_initial ? "(initial)" : oid_to_hex(&s->oid_commit)),
 			eol);
 
 	if (!s->branch)
diff --git a/wt-status.h b/wt-status.h
index 77dad5b920..71c3f25f43 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -116,7 +116,7 @@ struct wt_status {
 	int rename_limit;
 	enum wt_status_format status_format;
 	struct wt_status_state state;
-	unsigned char sha1_commit[GIT_MAX_RAWSZ]; /* when not Initial */
+	struct object_id oid_commit; /* when not Initial */
 
 	/* These are computed during processing of the individual sections */
 	int committable;

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 21/26] packfile: replace sha1_to_hex
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
                   ` (19 preceding siblings ...)
  2019-08-18 20:04 ` [PATCH 20/26] wt-status: convert struct wt_status to object_id brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-18 20:04 ` [PATCH 22/26] builtin/index-pack: " brian m. carlson
                   ` (4 subsequent siblings)
  25 siblings, 0 replies; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

Replace a use of sha1_to_hex with hash_to_hex so that this code works
with a hash algorithm other than SHA-1.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 packfile.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/packfile.c b/packfile.c
index fc43a6c52c..52dea88997 100644
--- a/packfile.c
+++ b/packfile.c
@@ -19,12 +19,12 @@
 #include "commit-graph.h"
 
 char *odb_pack_name(struct strbuf *buf,
-		    const unsigned char *sha1,
+		    const unsigned char *hash,
 		    const char *ext)
 {
 	strbuf_reset(buf);
 	strbuf_addf(buf, "%s/pack/pack-%s.%s", get_object_directory(),
-		    sha1_to_hex(sha1), ext);
+		    hash_to_hex(hash), ext);
 	return buf->buf;
 }
 

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 22/26] builtin/index-pack: replace sha1_to_hex
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
                   ` (20 preceding siblings ...)
  2019-08-18 20:04 ` [PATCH 21/26] packfile: replace sha1_to_hex brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-18 20:04 ` [PATCH 23/26] builtin/receive-pack: " brian m. carlson
                   ` (3 subsequent siblings)
  25 siblings, 0 replies; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

Since sha1_to_hex is limited to SHA-1, replace it with hash_to_hex so
this code works with other algorithms.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/index-pack.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 0d55f73b0b..2abd550ce2 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1490,11 +1490,11 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
 	}
 
 	if (!from_stdin) {
-		printf("%s\n", sha1_to_hex(hash));
+		printf("%s\n", hash_to_hex(hash));
 	} else {
 		struct strbuf buf = STRBUF_INIT;
 
-		strbuf_addf(&buf, "%s\t%s\n", report, sha1_to_hex(hash));
+		strbuf_addf(&buf, "%s\t%s\n", report, hash_to_hex(hash));
 		write_or_die(1, buf.buf, buf.len);
 		strbuf_release(&buf);
 

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 23/26] builtin/receive-pack: replace sha1_to_hex
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
                   ` (21 preceding siblings ...)
  2019-08-18 20:04 ` [PATCH 22/26] builtin/index-pack: " brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-18 20:04 ` [PATCH 24/26] rerere: " brian m. carlson
                   ` (2 subsequent siblings)
  25 siblings, 0 replies; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

Since sha1_to_hex is limited to SHA-1, replace it with hash_to_hex.
Rename several variables to indicate that they can contain any hash.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/receive-pack.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 402edf34d8..411e0b4d99 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -466,7 +466,7 @@ static char *prepare_push_cert_nonce(const char *path, timestamp_t stamp)
 	strbuf_release(&buf);
 
 	/* RFC 2104 5. HMAC-SHA1-80 */
-	strbuf_addf(&buf, "%"PRItime"-%.*s", stamp, (int)the_hash_algo->hexsz, sha1_to_hex(hash));
+	strbuf_addf(&buf, "%"PRItime"-%.*s", stamp, (int)the_hash_algo->hexsz, hash_to_hex(hash));
 	return strbuf_detach(&buf, NULL);
 }
 
@@ -968,7 +968,7 @@ static const char *push_to_deploy(unsigned char *sha1,
 	if (run_command(&child))
 		return "Working directory has staged changes";
 
-	read_tree[3] = sha1_to_hex(sha1);
+	read_tree[3] = hash_to_hex(sha1);
 	child_process_init(&child);
 	child.argv = read_tree;
 	child.env = env->argv;
@@ -985,13 +985,13 @@ static const char *push_to_deploy(unsigned char *sha1,
 
 static const char *push_to_checkout_hook = "push-to-checkout";
 
-static const char *push_to_checkout(unsigned char *sha1,
+static const char *push_to_checkout(unsigned char *hash,
 				    struct argv_array *env,
 				    const char *work_tree)
 {
 	argv_array_pushf(env, "GIT_WORK_TREE=%s", absolute_path(work_tree));
 	if (run_hook_le(env->argv, push_to_checkout_hook,
-			sha1_to_hex(sha1), NULL))
+			hash_to_hex(hash), NULL))
 		return "push-to-checkout hook declined";
 	else
 		return NULL;

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 24/26] rerere: replace sha1_to_hex
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
                   ` (22 preceding siblings ...)
  2019-08-18 20:04 ` [PATCH 23/26] builtin/receive-pack: " brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-18 20:04 ` [PATCH 25/26] builtin/show-index: " brian m. carlson
  2019-08-18 20:04 ` [PATCH 26/26] midx: switch to using the_hash_algo brian m. carlson
  25 siblings, 0 replies; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

Replace the uses of sha1_to_hex in this function with hash_to_hex to
allow the use of SHA-256 as well.  Rename a variable since it is no
longer limited to SHA-1.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 rerere.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/rerere.c b/rerere.c
index 17abb47321..3e51fdfe58 100644
--- a/rerere.c
+++ b/rerere.c
@@ -52,7 +52,7 @@ static void free_rerere_id(struct string_list_item *item)
 
 static const char *rerere_id_hex(const struct rerere_id *id)
 {
-	return sha1_to_hex(id->collection->hash);
+	return hash_to_hex(id->collection->hash);
 }
 
 static void fit_variant(struct rerere_dir *rr_dir, int variant)
@@ -115,7 +115,7 @@ static int is_rr_file(const char *name, const char *filename, int *variant)
 static void scan_rerere_dir(struct rerere_dir *rr_dir)
 {
 	struct dirent *de;
-	DIR *dir = opendir(git_path("rr-cache/%s", sha1_to_hex(rr_dir->hash)));
+	DIR *dir = opendir(git_path("rr-cache/%s", hash_to_hex(rr_dir->hash)));
 
 	if (!dir)
 		return;
@@ -186,9 +186,9 @@ static struct rerere_id *new_rerere_id_hex(char *hex)
 	return id;
 }
 
-static struct rerere_id *new_rerere_id(unsigned char *sha1)
+static struct rerere_id *new_rerere_id(unsigned char *hash)
 {
-	return new_rerere_id_hex(sha1_to_hex(sha1));
+	return new_rerere_id_hex(hash_to_hex(hash));
 }
 
 /*

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 25/26] builtin/show-index: replace sha1_to_hex
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
                   ` (23 preceding siblings ...)
  2019-08-18 20:04 ` [PATCH 24/26] rerere: " brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-18 20:04 ` [PATCH 26/26] midx: switch to using the_hash_algo brian m. carlson
  25 siblings, 0 replies; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

In this code path, we use sha1_to_hex to display the contents of a v1
pack index.  While we plan to switch to v3 indices for SHA-256, the v1
pack indices still function, so to support both algorithms, switch
sha1_to_hex to hash_to_hex.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/show-index.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/show-index.c b/builtin/show-index.c
index e95b84e8eb..0826f6a5a2 100644
--- a/builtin/show-index.c
+++ b/builtin/show-index.c
@@ -42,7 +42,7 @@ int cmd_show_index(int argc, const char **argv, const char *prefix)
 			if (fread(entry, 4 + hashsz, 1, stdin) != 1)
 				die("unable to read entry %u/%u", i, nr);
 			offset = ntohl(entry[0]);
-			printf("%u %s\n", offset, sha1_to_hex((void *)(entry+1)));
+			printf("%u %s\n", offset, hash_to_hex((void *)(entry+1)));
 		}
 	} else {
 		unsigned off64_nr = 0;

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 26/26] midx: switch to using the_hash_algo
  2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
                   ` (24 preceding siblings ...)
  2019-08-18 20:04 ` [PATCH 25/26] builtin/show-index: " brian m. carlson
@ 2019-08-18 20:04 ` brian m. carlson
  2019-08-22 14:04   ` Derrick Stolee
  25 siblings, 1 reply; 33+ messages in thread
From: brian m. carlson @ 2019-08-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Derrick Stolee

Instead of hard-coding the hash size, use the_hash_algo to look up the
hash size at runtime.  Remove the #define constant which was used to
hold the hash length, since writing the expression with the_hash_algo
provide enough documentary value on its own.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 midx.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/midx.c b/midx.c
index d649644420..f29afc0d2d 100644
--- a/midx.c
+++ b/midx.c
@@ -19,8 +19,7 @@
 #define MIDX_BYTE_NUM_PACKS 8
 #define MIDX_HASH_VERSION 1
 #define MIDX_HEADER_SIZE 12
-#define MIDX_HASH_LEN 20
-#define MIDX_MIN_SIZE (MIDX_HEADER_SIZE + MIDX_HASH_LEN)
+#define MIDX_MIN_SIZE (MIDX_HEADER_SIZE + the_hash_algo->rawsz)
 
 #define MIDX_MAX_CHUNKS 5
 #define MIDX_CHUNK_ALIGNMENT 4
@@ -93,7 +92,7 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local
 	hash_version = m->data[MIDX_BYTE_HASH_VERSION];
 	if (hash_version != MIDX_HASH_VERSION)
 		die(_("hash version %u does not match"), hash_version);
-	m->hash_len = MIDX_HASH_LEN;
+	m->hash_len = the_hash_algo->rawsz;
 
 	m->num_chunks = m->data[MIDX_BYTE_NUM_CHUNKS];
 
@@ -234,7 +233,7 @@ int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t
 int bsearch_midx(const struct object_id *oid, struct multi_pack_index *m, uint32_t *result)
 {
 	return bsearch_hash(oid->hash, m->chunk_oid_fanout, m->chunk_oid_lookup,
-			    MIDX_HASH_LEN, result);
+			    the_hash_algo->rawsz, result);
 }
 
 struct object_id *nth_midxed_object_oid(struct object_id *oid,
@@ -928,7 +927,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
 
 	cur_chunk++;
 	chunk_ids[cur_chunk] = MIDX_CHUNKID_OBJECTOFFSETS;
-	chunk_offsets[cur_chunk] = chunk_offsets[cur_chunk - 1] + nr_entries * MIDX_HASH_LEN;
+	chunk_offsets[cur_chunk] = chunk_offsets[cur_chunk - 1] + nr_entries * the_hash_algo->rawsz;
 
 	cur_chunk++;
 	chunk_offsets[cur_chunk] = chunk_offsets[cur_chunk - 1] + nr_entries * MIDX_CHUNK_OFFSET_WIDTH;
@@ -976,7 +975,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
 				break;
 
 			case MIDX_CHUNKID_OIDLOOKUP:
-				written += write_midx_oid_lookup(f, MIDX_HASH_LEN, entries, nr_entries);
+				written += write_midx_oid_lookup(f, the_hash_algo->rawsz, entries, nr_entries);
 				break;
 
 			case MIDX_CHUNKID_OBJECTOFFSETS:

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* Re: [PATCH 02/26] patch-id: convert to use the_hash_algo
  2019-08-18 20:04 ` [PATCH 02/26] patch-id: convert to use the_hash_algo brian m. carlson
@ 2019-08-20 21:12   ` René Scharfe
  2019-08-20 22:36     ` brian m. carlson
  0 siblings, 1 reply; 33+ messages in thread
From: René Scharfe @ 2019-08-20 21:12 UTC (permalink / raw)
  To: brian m. carlson, git; +Cc: Taylor Blau, Derrick Stolee

Am 18.08.19 um 22:04 schrieb brian m. carlson:
> diff --git a/builtin/patch-id.c b/builtin/patch-id.c
> index bd28b80b2d..3059e525b8 100644
> --- a/builtin/patch-id.c
> +++ b/builtin/patch-id.c
> @@ -1,15 +1,16 @@
> +#include "cache.h"
>  #include "builtin.h"
>  #include "config.h"
>  #include "diff.h"
>
>  static void flush_current_id(int patchlen, struct object_id *id, struct object_id *result)
>  {
> -	char name[50];
> +	char name[GIT_MAX_HEXSZ + 1];
>
>  	if (!patchlen)
>  		return;
>
> -	memcpy(name, oid_to_hex(id), GIT_SHA1_HEXSZ + 1);
> +	memcpy(name, oid_to_hex(id), the_hash_algo->hexsz + 1);
>  	printf("%s %s\n", oid_to_hex(result), name);
>  }

OK.  But why do we need our own buffer?  oid_to_hex() provides four of
them for us, so the body could become just:

	if (patchlen)
		printf("%s %s\n", oid_to_hex(result), oid_to_hex(id));


Right?  Well, this buffer comes from f97672225b («Add "git-patch-id"
program to generate patch ID's.», 2005-06-23), which predates the
introduction of the four-buffer feature in dcb3450fd8 («sha1_to_hex()
usage cleanup», 2006-05-03).

And with 30e12b924b («patch-id: make it stable against hunk reordering»,
2014-04-27) the function's name became a bit misleading, because it
stopped being responsible for flushing the hash calculation.

So perhaps this on top?  (Or squash it in, if you like, but it's
certainly not worth a re-roll.)

-- >8 --
Subject: [PATCH] patch-id: inline flush_current_id()

The function hasn't been flushing the hash calculation since 30e12b924b
("patch-id: make it stable against hunk reordering", 2014-04-27), and
there is no need for a private copy of the second hexadecimal hash value
since dcb3450fd8 ("sha1_to_hex() usage cleanup", 2006-05-03) added
support for up to four sha1_to_hex() results to be used in the same
printf(3) call, which oid_to_hex() inherited.  So print both hash values
directly and get rid of the function with the outdated name.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 builtin/patch-id.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 3059e525b8..d328714af7 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -3,17 +3,6 @@
 #include "config.h"
 #include "diff.h"

-static void flush_current_id(int patchlen, struct object_id *id, struct object_id *result)
-{
-	char name[GIT_MAX_HEXSZ + 1];
-
-	if (!patchlen)
-		return;
-
-	memcpy(name, oid_to_hex(id), the_hash_algo->hexsz + 1);
-	printf("%s %s\n", oid_to_hex(result), name);
-}
-
 static int remove_space(char *line)
 {
 	char *src = line;
@@ -137,13 +126,12 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
 static void generate_id_list(int stable)
 {
 	struct object_id oid, n, result;
-	int patchlen;
 	struct strbuf line_buf = STRBUF_INIT;

 	oidclr(&oid);
 	while (!feof(stdin)) {
-		patchlen = get_one_patchid(&n, &result, &line_buf, stable);
-		flush_current_id(patchlen, &oid, &result);
+		if (get_one_patchid(&n, &result, &line_buf, stable))
+			printf("%s %s\n", oid_to_hex(&result), oid_to_hex(&oid));
 		oidcpy(&oid, &n);
 	}
 	strbuf_release(&line_buf);
--
2.23.0

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* Re: [PATCH 02/26] patch-id: convert to use the_hash_algo
  2019-08-20 21:12   ` René Scharfe
@ 2019-08-20 22:36     ` brian m. carlson
  2019-08-22 15:53       ` Junio C Hamano
  0 siblings, 1 reply; 33+ messages in thread
From: brian m. carlson @ 2019-08-20 22:36 UTC (permalink / raw)
  To: René Scharfe; +Cc: git, Taylor Blau, Derrick Stolee

[-- Attachment #1: Type: text/plain, Size: 297 bytes --]

On 2019-08-20 at 21:12:00, René Scharfe wrote:
> So perhaps this on top?  (Or squash it in, if you like, but it's
> certainly not worth a re-roll.)

Yeah, this seems sensible.  I'll include it if I do a re-roll.
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 868 bytes --]

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH 26/26] midx: switch to using the_hash_algo
  2019-08-18 20:04 ` [PATCH 26/26] midx: switch to using the_hash_algo brian m. carlson
@ 2019-08-22 14:04   ` Derrick Stolee
  2019-08-23  2:17     ` brian m. carlson
  0 siblings, 1 reply; 33+ messages in thread
From: Derrick Stolee @ 2019-08-22 14:04 UTC (permalink / raw)
  To: brian m. carlson, git; +Cc: Taylor Blau, Derrick Stolee

On 8/18/2019 4:04 PM, brian m. carlson wrote:
> Instead of hard-coding the hash size, use the_hash_algo to look up the
> hash size at runtime.  Remove the #define constant which was used to
> hold the hash length, since writing the expression with the_hash_algo
> provide enough documentary value on its own.

Thanks for this change! It seems to be very similar to the one
included in the commit-graph, barring one small issue below
(that we can follow-up on later).

> diff --git a/midx.c b/midx.c
> index d649644420..f29afc0d2d 100644
> --- a/midx.c
> +++ b/midx.c
> @@ -19,8 +19,7 @@
>  #define MIDX_BYTE_NUM_PACKS 8
>  #define MIDX_HASH_VERSION 1

This hash version "1" is the same as we used in the commit-graph. It's
a byte value from the file format, and we've already discussed how it
would have been better to use the 4-byte identifier, but that ship has
sailed. I'm just pointing this out to say that we are not done in this
file yet, but we can get to that when we want to test the midx with
multiple hash lengths.

>  #define MIDX_HEADER_SIZE 12
> -#define MIDX_HASH_LEN 20

The replacements of MIDX_HASH_LEN make sense. Thanks!

-Stolee

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH 02/26] patch-id: convert to use the_hash_algo
  2019-08-20 22:36     ` brian m. carlson
@ 2019-08-22 15:53       ` Junio C Hamano
  0 siblings, 0 replies; 33+ messages in thread
From: Junio C Hamano @ 2019-08-22 15:53 UTC (permalink / raw)
  To: brian m. carlson; +Cc: René Scharfe, git, Taylor Blau, Derrick Stolee

"brian m. carlson" <sandals@crustytoothpaste.net> writes:

> On 2019-08-20 at 21:12:00, René Scharfe wrote:
>> So perhaps this on top?  (Or squash it in, if you like, but it's
>> certainly not worth a re-roll.)
>
> Yeah, this seems sensible.  I'll include it if I do a re-roll.

Thanks.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH 26/26] midx: switch to using the_hash_algo
  2019-08-22 14:04   ` Derrick Stolee
@ 2019-08-23  2:17     ` brian m. carlson
  2019-08-23 11:53       ` Derrick Stolee
  0 siblings, 1 reply; 33+ messages in thread
From: brian m. carlson @ 2019-08-23  2:17 UTC (permalink / raw)
  To: Derrick Stolee; +Cc: git, Taylor Blau, Derrick Stolee

[-- Attachment #1: Type: text/plain, Size: 1557 bytes --]

On 2019-08-22 at 14:04:16, Derrick Stolee wrote:
> On 8/18/2019 4:04 PM, brian m. carlson wrote:
> > diff --git a/midx.c b/midx.c
> > index d649644420..f29afc0d2d 100644
> > --- a/midx.c
> > +++ b/midx.c
> > @@ -19,8 +19,7 @@
> >  #define MIDX_BYTE_NUM_PACKS 8
> >  #define MIDX_HASH_VERSION 1
> 
> This hash version "1" is the same as we used in the commit-graph. It's
> a byte value from the file format, and we've already discussed how it
> would have been better to use the 4-byte identifier, but that ship has
> sailed. I'm just pointing this out to say that we are not done in this
> file yet, but we can get to that when we want to test the midx with
> multiple hash lengths.

My approach so far has been to assume everything in the .git directory
is in the same hash except for the translation functionality. Therefore,
it doesn't make sense to distinguish between hashes in the midx files,
because we'll never have files that differ in hash.  So essentially the
MIDX_HASH_VERSION being 1 is "whatever hash is being used in the .git
directory", not just SHA-1.

In addition, the current multi-pack index format isn't capable (from my
reading of the documentation, at least) of handling multiple hash
algorithms at once.  So we'd need a midx v2 format for folks who are
using SHA-256 with SHA-1 compatibility and we could then write separate
sets of object chunks with an appropriate format identifier, much like
the proposed pack index v3.
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 868 bytes --]

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH 26/26] midx: switch to using the_hash_algo
  2019-08-23  2:17     ` brian m. carlson
@ 2019-08-23 11:53       ` Derrick Stolee
  0 siblings, 0 replies; 33+ messages in thread
From: Derrick Stolee @ 2019-08-23 11:53 UTC (permalink / raw)
  To: brian m. carlson, git, Taylor Blau, Derrick Stolee

On 8/22/2019 10:17 PM, brian m. carlson wrote:
> On 2019-08-22 at 14:04:16, Derrick Stolee wrote:
>> On 8/18/2019 4:04 PM, brian m. carlson wrote:
>>> diff --git a/midx.c b/midx.c
>>> index d649644420..f29afc0d2d 100644
>>> --- a/midx.c
>>> +++ b/midx.c
>>> @@ -19,8 +19,7 @@
>>>  #define MIDX_BYTE_NUM_PACKS 8
>>>  #define MIDX_HASH_VERSION 1
>>
>> This hash version "1" is the same as we used in the commit-graph. It's
>> a byte value from the file format, and we've already discussed how it
>> would have been better to use the 4-byte identifier, but that ship has
>> sailed. I'm just pointing this out to say that we are not done in this
>> file yet, but we can get to that when we want to test the midx with
>> multiple hash lengths.
> 
> My approach so far has been to assume everything in the .git directory
> is in the same hash except for the translation functionality. Therefore,
> it doesn't make sense to distinguish between hashes in the midx files,
> because we'll never have files that differ in hash.  So essentially the
> MIDX_HASH_VERSION being 1 is "whatever hash is being used in the .git
> directory", not just SHA-1.
> 
> In addition, the current multi-pack index format isn't capable (from my
> reading of the documentation, at least) of handling multiple hash
> algorithms at once.  So we'd need a midx v2 format for folks who are
> using SHA-256 with SHA-1 compatibility and we could then write separate
> sets of object chunks with an appropriate format identifier, much like
> the proposed pack index v3.

Absolutely, it is not. It would be a great place to store a transition
table, when that is needed.

If we _never_ allow both hashes in the .git folder, then maybe we won't
ever need this and can rely on config options. I imagine that will be
tricky, and updating this byte should only help. We are not ready for
that, anyway.

Thanks,
-Stolee

^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2019-08-23 11:53 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
2019-08-18 20:04 ` [PATCH 01/26] builtin/replace: make hash size independent brian m. carlson
2019-08-18 20:04 ` [PATCH 02/26] patch-id: convert to use the_hash_algo brian m. carlson
2019-08-20 21:12   ` René Scharfe
2019-08-20 22:36     ` brian m. carlson
2019-08-22 15:53       ` Junio C Hamano
2019-08-18 20:04 ` [PATCH 03/26] fetch-pack: use parse_oid_hex brian m. carlson
2019-08-18 20:04 ` [PATCH 04/26] builtin/receive-pack: switch to use the_hash_algo brian m. carlson
2019-08-18 20:04 ` [PATCH 05/26] builtin/blame: switch uses of GIT_SHA1_HEXSZ to the_hash_algo brian m. carlson
2019-08-18 20:04 ` [PATCH 06/26] builtin/rev-parse: switch to use the_hash_algo brian m. carlson
2019-08-18 20:04 ` [PATCH 07/26] blame: remove needless comparison with GIT_SHA1_HEXSZ brian m. carlson
2019-08-18 20:04 ` [PATCH 08/26] show-index: switch hard-coded constants to the_hash_algo brian m. carlson
2019-08-18 20:04 ` [PATCH 09/26] connected: switch GIT_SHA1_HEXSZ " brian m. carlson
2019-08-18 20:04 ` [PATCH 10/26] bundle: switch to use the_hash_algo brian m. carlson
2019-08-18 20:04 ` [PATCH 11/26] combine-diff: replace GIT_SHA1_HEXSZ with the_hash_algo brian m. carlson
2019-08-18 20:04 ` [PATCH 12/26] config: use the_hash_algo in abbrev comparison brian m. carlson
2019-08-18 20:04 ` [PATCH 13/26] sha1-lookup: switch hard-coded constants to the_hash_algo brian m. carlson
2019-08-18 20:04 ` [PATCH 14/26] bisect: switch to using the_hash_algo brian m. carlson
2019-08-18 20:04 ` [PATCH 15/26] sequencer: convert to use the_hash_algo brian m. carlson
2019-08-18 20:04 ` [PATCH 16/26] pack-write: use hash_to_hex when writing checksums brian m. carlson
2019-08-18 20:04 ` [PATCH 17/26] builtin/repack: write object IDs of the proper length brian m. carlson
2019-08-18 20:04 ` [PATCH 18/26] builtin/worktree: switch null_sha1 to null_oid brian m. carlson
2019-08-18 20:04 ` [PATCH 19/26] cache: remove null_sha1 brian m. carlson
2019-08-18 20:04 ` [PATCH 20/26] wt-status: convert struct wt_status to object_id brian m. carlson
2019-08-18 20:04 ` [PATCH 21/26] packfile: replace sha1_to_hex brian m. carlson
2019-08-18 20:04 ` [PATCH 22/26] builtin/index-pack: " brian m. carlson
2019-08-18 20:04 ` [PATCH 23/26] builtin/receive-pack: " brian m. carlson
2019-08-18 20:04 ` [PATCH 24/26] rerere: " brian m. carlson
2019-08-18 20:04 ` [PATCH 25/26] builtin/show-index: " brian m. carlson
2019-08-18 20:04 ` [PATCH 26/26] midx: switch to using the_hash_algo brian m. carlson
2019-08-22 14:04   ` Derrick Stolee
2019-08-23  2:17     ` brian m. carlson
2019-08-23 11:53       ` Derrick Stolee

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).