diff mbox series

[23/31] remote-curl: make hash size independent

Message ID 20190212012256.1005924-24-sandals@crustytoothpaste.net (mailing list archive)
State New, archived
Headers show
Series Hash function transition part 16 | expand

Commit Message

brian m. carlson Feb. 12, 2019, 1:22 a.m. UTC
Change one hard-coded use of the constant 40 to a reference to
the_hash_algo.  In addition, switch a use of get_oid_hex to
parse_oid_hex to avoid the need to use a constant.

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

Comments

Ævar Arnfjörð Bjarmason Feb. 12, 2019, 11:11 a.m. UTC | #1
On Tue, Feb 12 2019, brian m. carlson wrote:

> Change one hard-coded use of the constant 40 to a reference to
> the_hash_algo.  In addition, switch a use of get_oid_hex to
> parse_oid_hex to avoid the need to use a constant.
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
>  remote-curl.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/remote-curl.c b/remote-curl.c
> index bb7421023b..8395b71bbb 100644
> --- a/remote-curl.c
> +++ b/remote-curl.c
> @@ -249,7 +249,7 @@ static struct ref *parse_info_refs(struct discovery *heads)
>  		if (data[i] == '\t')
>  			mid = &data[i];
>  		if (data[i] == '\n') {
> -			if (mid - start != 40)
> +			if (mid - start != the_hash_algo->hexsz)
>  				die("%sinfo/refs not valid: is this a git repository?",
>  				    url.buf);
>  			data[i] = 0;

Similar to my comment on 28/31 I may be missing something, but this is
the part where we're parsing the ref advertisement from a remote
repository, which may e.g. be SHA-1, and our local "the hash algo" may
be SHA-256, no?

So isn't this a point where we need to accept both, and parse it into
some structure where we mark it as either/or SHA-1 or SHA-256, and late
or consult SHA-1<->SHA-256 lookup tables etc.?
diff mbox series

Patch

diff --git a/remote-curl.c b/remote-curl.c
index bb7421023b..8395b71bbb 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -249,7 +249,7 @@  static struct ref *parse_info_refs(struct discovery *heads)
 		if (data[i] == '\t')
 			mid = &data[i];
 		if (data[i] == '\n') {
-			if (mid - start != 40)
+			if (mid - start != the_hash_algo->hexsz)
 				die("%sinfo/refs not valid: is this a git repository?",
 				    url.buf);
 			data[i] = 0;
@@ -1013,12 +1013,13 @@  static void parse_fetch(struct strbuf *buf)
 			const char *name;
 			struct ref *ref;
 			struct object_id old_oid;
+			const char *q;
 
-			if (get_oid_hex(p, &old_oid))
+			if (parse_oid_hex(p, &old_oid, &q))
 				die("protocol error: expected sha/ref, got %s'", p);
-			if (p[GIT_SHA1_HEXSZ] == ' ')
-				name = p + GIT_SHA1_HEXSZ + 1;
-			else if (!p[GIT_SHA1_HEXSZ])
+			if (*q == ' ')
+				name = q + 1;
+			else if (!*q)
 				name = "";
 			else
 				die("protocol error: expected sha/ref, got %s'", p);