object-store: rename and expand packed_git's sha1 member

This member is used to represent the pack checksum of the pack in question. Expand this member to be GIT_MAX_RAWSZ bytes in length so it works with longer hashes and rename it to be "hash" instead of "sha1". This transformation was made with a change to the definition and the following semantic patch: @@ struct packed_git *E1; @@ - E1->sha1 + E1->hash @@ struct packed_git E1; @@ - E1.sha1 + E1.hash Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Feb 19, 2019 at 00:05 UTC 538b1523246ba0845564a6b703c6e4ff1921c16a
7 files changed +24 -21
builtin/pack-redundant.c
+1 -1
@@ -641,7 +641,7 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix)
641 pl = red = pack_list_difference(local_packs, min);
642 while (pl) {
643 printf("%s\n%s\n",
644 - sha1_pack_index_name(pl->pack->sha1),
644 + sha1_pack_index_name(pl->pack->hash),
645 pl->pack->pack_name);
646 pl = pl->next;
647 }
fast-import.c
+9 -8
@@ -742,7 +742,8 @@ static const char *create_index(void)
742 if (c != last)
743 die("internal consistency error creating the index");
744
745 - tmpfile = write_idx_file(NULL, idx, object_count, &pack_idx_opts, pack_data->sha1);
745 + tmpfile = write_idx_file(NULL, idx, object_count, &pack_idx_opts,
746 + pack_data->hash);
747 free(idx);
748 return tmpfile;
749 }
@@ -753,7 +754,7 @@ static char *keep_pack(const char *curr_index_name)
754 struct strbuf name = STRBUF_INIT;
755 int keep_fd;
756
756 - odb_pack_name(&name, pack_data->sha1, "keep");
757 + odb_pack_name(&name, pack_data->hash, "keep");
758 keep_fd = odb_pack_keep(name.buf);
759 if (keep_fd < 0)
760 die_errno("cannot create keep file");
@@ -761,11 +762,11 @@ static char *keep_pack(const char *curr_index_name)
762 if (close(keep_fd))
763 die_errno("failed to write keep file");
764
764 - odb_pack_name(&name, pack_data->sha1, "pack");
765 + odb_pack_name(&name, pack_data->hash, "pack");
766 if (finalize_object_file(pack_data->pack_name, name.buf))
767 die("cannot store pack file");
768
768 - odb_pack_name(&name, pack_data->sha1, "idx");
769 + odb_pack_name(&name, pack_data->hash, "idx");
770 if (finalize_object_file(curr_index_name, name.buf))
771 die("cannot store index file");
772 free((void *)curr_index_name);
@@ -779,7 +780,7 @@ static void unkeep_all_packs(void)
780
781 for (k = 0; k < pack_id; k++) {
782 struct packed_git *p = all_packs[k];
782 - odb_pack_name(&name, p->sha1, "keep");
783 + odb_pack_name(&name, p->hash, "keep");
784 unlink_or_warn(name.buf);
785 }
786 strbuf_release(&name);
@@ -821,9 +822,9 @@ static void end_packfile(void)
822
823 close_pack_windows(pack_data);
824 finalize_hashfile(pack_file, cur_pack_oid.hash, 0);
824 - fixup_pack_header_footer(pack_data->pack_fd, pack_data->sha1,
825 - pack_data->pack_name, object_count,
826 - cur_pack_oid.hash, pack_size);
825 + fixup_pack_header_footer(pack_data->pack_fd, pack_data->hash,
826 + pack_data->pack_name, object_count,
827 + cur_pack_oid.hash, pack_size);
828
829 if (object_count <= unpack_limit) {
830 if (!loosen_small_pack(pack_data)) {
http-push.c
+2 -1
@@ -315,7 +315,8 @@ static void start_fetch_packed(struct transfer_request *request)
315 return;
316 }
317
318 - fprintf(stderr, "Fetching pack %s\n", sha1_to_hex(target->sha1));
318 + fprintf(stderr, "Fetching pack %s\n",
319 + sha1_to_hex(target->hash));
320 fprintf(stderr, " which contains %s\n", oid_to_hex(&request->obj->oid));
321
322 preq = new_http_pack_request(target, repo->url);
http-walker.c
+1 -1
@@ -434,7 +434,7 @@ static int http_fetch_pack(struct walker *walker, struct alt_base *repo, unsigne
434
435 if (walker->get_verbosely) {
436 fprintf(stderr, "Getting pack %s\n",
437 - sha1_to_hex(target->sha1));
437 + sha1_to_hex(target->hash));
438 fprintf(stderr, " which contains %s\n",
439 sha1_to_hex(sha1));
440 }
http.c
+7 -6
@@ -2236,10 +2236,10 @@ int finish_http_pack_request(struct http_pack_request *preq)
2236 return -1;
2237 }
2238
2239 - unlink(sha1_pack_index_name(p->sha1));
2239 + unlink(sha1_pack_index_name(p->hash));
2240
2241 - if (finalize_object_file(preq->tmpfile.buf, sha1_pack_name(p->sha1))
2242 - || finalize_object_file(tmp_idx, sha1_pack_index_name(p->sha1))) {
2241 + if (finalize_object_file(preq->tmpfile.buf, sha1_pack_name(p->hash))
2242 + || finalize_object_file(tmp_idx, sha1_pack_index_name(p->hash))) {
2243 free(tmp_idx);
2244 return -1;
2245 }
@@ -2262,10 +2262,10 @@ struct http_pack_request *new_http_pack_request(
2262
2263 end_url_with_slash(&buf, base_url);
2264 strbuf_addf(&buf, "objects/pack/pack-%s.pack",
2265 - sha1_to_hex(target->sha1));
2265 + sha1_to_hex(target->hash));
2266 preq->url = strbuf_detach(&buf, NULL);
2267
2268 - strbuf_addf(&preq->tmpfile, "%s.temp", sha1_pack_name(target->sha1));
2268 + strbuf_addf(&preq->tmpfile, "%s.temp", sha1_pack_name(target->hash));
2269 preq->packfile = fopen(preq->tmpfile.buf, "a");
2270 if (!preq->packfile) {
2271 error("Unable to open local file %s for pack",
@@ -2289,7 +2289,8 @@ struct http_pack_request *new_http_pack_request(
2289 if (http_is_verbose)
2290 fprintf(stderr,
2291 "Resuming fetch of pack %s at byte %"PRIuMAX"\n",
2292 - sha1_to_hex(target->sha1), (uintmax_t)prev_posn);
2292 + sha1_to_hex(target->hash),
2293 + (uintmax_t)prev_posn);
2294 http_opt_request_remainder(preq->slot->curl, prev_posn);
2295 }
2296
object-store.h
+1 -1
@@ -77,7 +77,7 @@ struct packed_git {
77 freshened:1,
78 do_not_close:1,
79 pack_promisor:1;
80 - unsigned char sha1[20];
80 + unsigned char hash[GIT_MAX_RAWSZ];
81 struct revindex_entry *revindex;
82 /* something like ".git/objects/pack/xxxxx.pack" */
83 char pack_name[FLEX_ARRAY]; /* more */
packfile.c
+3 -3
@@ -235,7 +235,7 @@ struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path)
235 struct packed_git *p = alloc_packed_git(alloc);
236
237 memcpy(p->pack_name, path, alloc); /* includes NUL */
238 - hashcpy(p->sha1, sha1);
238 + hashcpy(p->hash, sha1);
239 if (check_packed_git_idx(idx_path, p)) {
240 free(p);
241 return NULL;
@@ -722,8 +722,8 @@ struct packed_git *add_packed_git(const char *path, size_t path_len, int local)
722 p->pack_local = local;
723 p->mtime = st.st_mtime;
724 if (path_len < the_hash_algo->hexsz ||
725 - get_sha1_hex(path + path_len - the_hash_algo->hexsz, p->sha1))
726 - hashclr(p->sha1);
725 + get_sha1_hex(path + path_len - the_hash_algo->hexsz, p->hash))
726 + hashclr(p->hash);
727 return p;
728 }
729