From f0be0db13dbd2d96d2240374e0e9cb106bf6a614 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 7 Jan 2019 03:34:40 -0500 Subject: http: use struct object_id instead of bare sha1 The dumb-http walker code still passes around and stores object ids as "unsigned char *sha1". Let's modernize it. There's probably still more work to be done to handle dumb-http fetches with a new, larger hash. But that can wait; this is enough that we can now convert some of the low-level object routines that we call into from here (and in fact, some of the "oid.hash" references added here will be further improved in the next patch). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- http-walker.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'http-walker.c') diff --git a/http-walker.c b/http-walker.c index 0a392c85b6..856716c63d 100644 --- a/http-walker.c +++ b/http-walker.c @@ -58,7 +58,7 @@ static void start_object_request(struct walker *walker, struct active_request_slot *slot; struct http_object_request *req; - req = new_http_object_request(obj_req->repo->base, obj_req->oid.hash); + req = new_http_object_request(obj_req->repo->base, &obj_req->oid); if (req == NULL) { obj_req->state = ABORTED; return; @@ -543,11 +543,11 @@ static int fetch_object(struct walker *walker, unsigned char *sha1) } else if (req->zret != Z_STREAM_END) { walker->corrupt_object_found++; ret = error("File %s (%s) corrupt", hex, req->url); - } else if (!hasheq(obj_req->oid.hash, req->real_sha1)) { + } else if (!oideq(&obj_req->oid, &req->real_oid)) { ret = error("File %s has bad hash", hex); } else if (req->rename < 0) { struct strbuf buf = STRBUF_INIT; - loose_object_path(the_repository, &buf, req->sha1); + loose_object_path(the_repository, &buf, req->oid.hash); ret = error("unable to write sha1 filename %s", buf.buf); strbuf_release(&buf); } -- cgit v1.2.3 From 514c5fdd03b914c72a91bb420e46bdc8886940cf Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 7 Jan 2019 03:35:42 -0500 Subject: sha1-file: modernize loose object file functions The loose object access code in sha1-file.c is some of the oldest in Git, and could use some modernizing. It mostly uses "unsigned char *" for object ids, which these days should be "struct object_id". It also uses the term "sha1_file" in many functions, which is confusing. The term "loose_objects" is much better. It clearly distinguishes them from packed objects (which didn't even exist back when the name "sha1_file" came into being). And it also distinguishes it from the checksummed-file concept in csum-file.c (which until recently was actually called "struct sha1file"!). This patch converts the functions {open,close,map,stat}_sha1_file() into open_loose_object(), etc, and switches their sha1 arguments for object_id structs. Similarly, path functions like fill_sha1_path() become fill_loose_path() and use object_ids. The function sha1_loose_object_info() already says "loose", so we can just drop the "sha1" (and teach it to use object_id). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- http-walker.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'http-walker.c') diff --git a/http-walker.c b/http-walker.c index 856716c63d..29b59e2fe0 100644 --- a/http-walker.c +++ b/http-walker.c @@ -547,7 +547,7 @@ static int fetch_object(struct walker *walker, unsigned char *sha1) ret = error("File %s has bad hash", hex); } else if (req->rename < 0) { struct strbuf buf = STRBUF_INIT; - loose_object_path(the_repository, &buf, req->oid.hash); + loose_object_path(the_repository, &buf, &req->oid); ret = error("unable to write sha1 filename %s", buf.buf); strbuf_release(&buf); } -- cgit v1.2.3 From 98374a07c98d1acc200c423b87495365a59cce0b Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 7 Jan 2019 03:37:54 -0500 Subject: convert has_sha1_file() callers to has_object_file() The only remaining callers of has_sha1_file() actually have an object_id already. They can use the "object" variant, rather than dereferencing the hash themselves. The code changes here were completely generated by the included coccinelle patch. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- http-walker.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'http-walker.c') diff --git a/http-walker.c b/http-walker.c index 29b59e2fe0..8ae5d76c6a 100644 --- a/http-walker.c +++ b/http-walker.c @@ -131,7 +131,7 @@ static int fill_active_slot(struct walker *walker) list_for_each_safe(pos, tmp, head) { obj_req = list_entry(pos, struct object_request, node); if (obj_req->state == WAITING) { - if (has_sha1_file(obj_req->oid.hash)) + if (has_object_file(&obj_req->oid)) obj_req->state = COMPLETE; else { start_object_request(walker, obj_req); @@ -489,7 +489,7 @@ static int fetch_object(struct walker *walker, unsigned char *sha1) if (obj_req == NULL) return error("Couldn't find request for %s in the queue", hex); - if (has_sha1_file(obj_req->oid.hash)) { + if (has_object_file(&obj_req->oid)) { if (obj_req->req != NULL) abort_http_object_request(obj_req->req); abort_object_request(obj_req); -- cgit v1.2.3