[WIP Patch 01/12] Don't expect verify_pack() callers to set pack_size

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Mike Hommey
Date: Sunday, January 18, 2009 - 1:04 am

Since use_pack() will end up populating pack_size if it is not already set,
we can just adapt the code in verify_packfile() such that it doesn't require
pack_size to be set beforehand.

This allows callers not to have to set pack_size themselves, and we can thus
revert changes from 1c23d794 (Don't die in git-http-fetch when fetching packs).

Signed-off-by: Mike Hommey <mh@glandium.org>
---
 http-push.c   |    3 ---
 http-walker.c |    1 -
 pack-check.c  |    8 +++++---
 3 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/http-push.c b/http-push.c
index a4b7d08..e69179b 100644
--- a/http-push.c
+++ b/http-push.c
@@ -771,14 +771,11 @@ static void finish_request(struct transfer_request *request)
 				request->url, curl_errorstr);
 			remote->can_update_info_refs = 0;
 		} else {
-			off_t pack_size = ftell(request->local_stream);
-
 			fclose(request->local_stream);
 			request->local_stream = NULL;
 			if (!move_temp_to_file(request->tmpfile,
 					       request->filename)) {
 				target = (struct packed_git *)request->userData;
-				target->pack_size = pack_size;
 				lst = &remote->packs;
 				while (*lst != target)
 					lst = &((*lst)->next);
diff --git a/http-walker.c b/http-walker.c
index 7271c7d..0139d1e 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -785,7 +785,6 @@ static int fetch_pack(struct walker *walker, struct alt_base *repo, unsigned cha
 		return error("Unable to start request");
 	}
 
-	target->pack_size = ftell(packfile);
 	fclose(packfile);
 
 	ret = move_temp_to_file(tmpfile, filename);
diff --git a/pack-check.c b/pack-check.c
index 90c33b1..166ca70 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -49,7 +49,7 @@ static int verify_packfile(struct packed_git *p,
 	const unsigned char *index_base = p->index_data;
 	git_SHA_CTX ctx;
 	unsigned char sha1[20], *pack_sig;
-	off_t offset = 0, pack_sig_ofs = p->pack_size - 20;
+	off_t offset = 0, pack_sig_ofs = 0;
 	uint32_t nr_objects, i;
 	int err = 0;
 	struct idx_entry *entries;
@@ -61,14 +61,16 @@ static int verify_packfile(struct packed_git *p,
 	 */
 
 	git_SHA1_Init(&ctx);
-	while (offset < pack_sig_ofs) {
+	do {
 		unsigned int remaining;
 		unsigned char *in = use_pack(p, w_curs, offset, &remaining);
 		offset += remaining;
+		if (!pack_sig_ofs)
+			pack_sig_ofs = p->pack_size - 20;
 		if (offset > pack_sig_ofs)
 			remaining -= (unsigned int)(offset - pack_sig_ofs);
 		git_SHA1_Update(&ctx, in, remaining);
-	}
+	} while (offset < pack_sig_ofs);
 	git_SHA1_Final(sha1, &ctx);
 	pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL);
 	if (hashcmp(sha1, pack_sig))
-- 
1.6.1.141.gb32a

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] http-push: fix off-by-path_len, Johannes Schindelin, (Sat Jan 17, 8:36 am)
Where's Nick?, was Re: [PATCH] http-push: fix off-by-path_len, Johannes Schindelin, (Sat Jan 17, 8:40 am)
[PATCH] t5540: clarify that http-push does not handle pack ..., Johannes Schindelin, (Sat Jan 17, 8:41 am)
Re: [PATCH] http-push: fix off-by-path_len, Mike Hommey, (Sun Jan 18, 12:49 am)
[WIP Patch 00/12] Refactoring the http API, Mike Hommey, (Sun Jan 18, 1:04 am)
[WIP Patch 01/12] Don't expect verify_pack() callers to se ..., Mike Hommey, (Sun Jan 18, 1:04 am)
[WIP Patch 02/12] Some cleanup in get_refs_via_curl(), Mike Hommey, (Sun Jan 18, 1:04 am)
[WIP Patch 03/12] Two new functions for the http API, Mike Hommey, (Sun Jan 18, 1:04 am)
Re: [WIP Patch 00/12] Refactoring the http API, Junio C Hamano, (Sun Jan 18, 1:30 am)
Re: [WIP Patch 00/12] Refactoring the http API, Mike Hommey, (Sun Jan 18, 2:12 am)
Re: [WIP Patch 00/12] Refactoring the http API, Boyd Stephen Smith Jr., (Sun Jan 18, 4:29 am)
Re: [WIP Patch 03/12] Two new functions for the http API, Johannes Schindelin, (Sun Jan 18, 8:03 am)
Re: [WIP Patch 04/12] Use the new http API in http_fetch_ref(), Johannes Schindelin, (Sun Jan 18, 8:10 am)
Re: [WIP Patch 05/12] Use the new http API in get_refs_via ..., Johannes Schindelin, (Sun Jan 18, 8:12 am)
Re: [WIP Patch 07/12] Use the new http API in http-push.c: ..., Johannes Schindelin, (Sun Jan 18, 8:14 am)
Re: [WIP Patch 08/12] Use the new http API in update_remot ..., Johannes Schindelin, (Sun Jan 18, 8:18 am)
Re: [WIP Patch 02/12] Some cleanup in get_refs_via_curl(), Johannes Schindelin, (Sun Jan 18, 12:06 pm)
Re: [WIP Patch 02/12] Some cleanup in get_refs_via_curl(), Johannes Schindelin, (Sun Jan 18, 12:11 pm)
Re: [WIP Patch 02/12] Some cleanup in get_refs_via_curl(), Johannes Schindelin, (Sun Jan 18, 2:09 pm)
Re: [WIP Patch 02/12] Some cleanup in get_refs_via_curl(), Johannes Schindelin, (Sun Jan 18, 2:10 pm)