Git fork

Merge branch 'ps/object-wo-the-repository' into ps/object-file-cleanup

* ps/object-wo-the-repository:
hash: stop depending on `the_repository` in `null_oid()`
hash: fix "-Wsign-compare" warnings
object-file: split out logic regarding hash algorithms
delta-islands: stop depending on `the_repository`
object-file-convert: stop depending on `the_repository`
pack-bitmap-write: stop depending on `the_repository`
pack-revindex: stop depending on `the_repository`
pack-check: stop depending on `the_repository`
environment: move access to "core.bigFileThreshold" into repo settings
pack-write: stop depending on `the_repository` and `the_hash_algo`
object: stop depending on `the_repository`
csum-file: stop depending on `the_repository`

+677 -613
+1
Makefile
··· 1042 1042 LIB_OBJS += graph.o 1043 1043 LIB_OBJS += grep.o 1044 1044 LIB_OBJS += hash-lookup.o 1045 + LIB_OBJS += hash.o 1045 1046 LIB_OBJS += hashmap.o 1046 1047 LIB_OBJS += help.o 1047 1048 LIB_OBJS += hex.o
+2 -2
archive.c
··· 216 216 /* Stream it? */ 217 217 if (S_ISREG(mode) && !args->convert && 218 218 oid_object_info(args->repo, oid, &size) == OBJ_BLOB && 219 - size > big_file_threshold) 219 + size > repo_settings_get_big_file_threshold(the_repository)) 220 220 return write_entry(args, oid, path.buf, path.len, mode, NULL, size); 221 221 222 222 buffer = object_file_to_archive(args, path.buf, oid, mode, &type, &size); ··· 312 312 struct object_id fake_oid; 313 313 int i; 314 314 315 - oidcpy(&fake_oid, null_oid()); 315 + oidcpy(&fake_oid, null_oid(the_hash_algo)); 316 316 317 317 if (args->baselen > 0 && args->base[args->baselen - 1] == '/') { 318 318 size_t len = args->baselen;
+1 -1
blame.c
··· 255 255 switch (st.st_mode & S_IFMT) { 256 256 case S_IFREG: 257 257 if (opt->flags.allow_textconv && 258 - textconv_object(r, read_from, mode, null_oid(), 0, &buf_ptr, &buf_len)) 258 + textconv_object(r, read_from, mode, null_oid(the_hash_algo), 0, &buf_ptr, &buf_len)) 259 259 strbuf_attach(&buf, buf_ptr, buf_len, buf_len + 1); 260 260 else if (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size) 261 261 die_errno("cannot open or read '%s'", read_from);
+1 -1
branch.c
··· 633 633 0, &err); 634 634 if (!transaction || 635 635 ref_transaction_update(transaction, ref.buf, 636 - &oid, forcing ? NULL : null_oid(), 636 + &oid, forcing ? NULL : null_oid(the_hash_algo), 637 637 NULL, NULL, flags, msg, &err) || 638 638 ref_transaction_commit(transaction, &err)) 639 639 die("%s", err.buf);
+3 -3
builtin/checkout.c
··· 130 130 int changed) 131 131 { 132 132 return run_hooks_l(the_repository, "post-checkout", 133 - oid_to_hex(old_commit ? &old_commit->object.oid : null_oid()), 134 - oid_to_hex(new_commit ? &new_commit->object.oid : null_oid()), 133 + oid_to_hex(old_commit ? &old_commit->object.oid : null_oid(the_hash_algo)), 134 + oid_to_hex(new_commit ? &new_commit->object.oid : null_oid(the_hash_algo)), 135 135 changed ? "1" : "0", NULL); 136 136 /* "new_commit" can be NULL when checking out from the index before 137 137 a commit exists. */ ··· 710 710 opts.src_index = the_repository->index; 711 711 opts.dst_index = the_repository->index; 712 712 init_checkout_metadata(&opts.meta, info->refname, 713 - info->commit ? &info->commit->object.oid : null_oid(), 713 + info->commit ? &info->commit->object.oid : null_oid(the_hash_algo), 714 714 NULL); 715 715 if (parse_tree(tree) < 0) 716 716 return 128;
+1 -1
builtin/clone.c
··· 692 692 if (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK)) 693 693 die(_("unable to write new index file")); 694 694 695 - err |= run_hooks_l(the_repository, "post-checkout", oid_to_hex(null_oid()), 695 + err |= run_hooks_l(the_repository, "post-checkout", oid_to_hex(null_oid(the_hash_algo)), 696 696 oid_to_hex(&oid), "1", NULL); 697 697 698 698 if (!err && (option_recurse_submodules.nr > 0)) {
+1 -1
builtin/describe.c
··· 518 518 { 519 519 struct rev_info revs; 520 520 struct strvec args = STRVEC_INIT; 521 - struct process_commit_data pcd = { *null_oid(), oid, dst, &revs}; 521 + struct process_commit_data pcd = { *null_oid(the_hash_algo), oid, dst, &revs}; 522 522 523 523 strvec_pushl(&args, "internal: The first arg is not parsed", 524 524 "--objects", "--in-commit-order", "--reverse", "HEAD",
+3 -2
builtin/diff.c
··· 104 104 105 105 stuff_change(&revs->diffopt, 106 106 blob[0]->mode, canon_mode(st.st_mode), 107 - &blob[0]->item->oid, null_oid(), 107 + &blob[0]->item->oid, null_oid(the_hash_algo), 108 108 1, 0, 109 109 blob[0]->path ? blob[0]->path : path, 110 110 path); ··· 498 498 499 499 /* If this is a no-index diff, just run it and exit there. */ 500 500 if (no_index) 501 - exit(diff_no_index(&rev, no_index == DIFF_NO_INDEX_IMPLICIT, 501 + exit(diff_no_index(&rev, the_repository->hash_algo, 502 + no_index == DIFF_NO_INDEX_IMPLICIT, 502 503 argc, argv)); 503 504 504 505
+5 -5
builtin/fast-export.c
··· 949 949 p = rewrite_commit((struct commit *)tagged); 950 950 if (!p) { 951 951 printf("reset %s\nfrom %s\n\n", 952 - name, oid_to_hex(null_oid())); 952 + name, oid_to_hex(null_oid(the_hash_algo))); 953 953 free(buf); 954 954 return; 955 955 } ··· 963 963 964 964 if (tagged->type == OBJ_TAG) { 965 965 printf("reset %s\nfrom %s\n\n", 966 - name, oid_to_hex(null_oid())); 966 + name, oid_to_hex(null_oid(the_hash_algo))); 967 967 } 968 968 skip_prefix(name, "refs/tags/", &name); 969 969 printf("tag %s\n", name); ··· 1103 1103 * it. 1104 1104 */ 1105 1105 printf("reset %s\nfrom %s\n\n", 1106 - name, oid_to_hex(null_oid())); 1106 + name, oid_to_hex(null_oid(the_hash_algo))); 1107 1107 continue; 1108 1108 } 1109 1109 ··· 1122 1122 if (!reference_excluded_commits) { 1123 1123 /* delete the ref */ 1124 1124 printf("reset %s\nfrom %s\n\n", 1125 - name, oid_to_hex(null_oid())); 1125 + name, oid_to_hex(null_oid(the_hash_algo))); 1126 1126 continue; 1127 1127 } 1128 1128 /* set ref to commit using oid, not mark */ ··· 1233 1233 continue; 1234 1234 1235 1235 printf("reset %s\nfrom %s\n\n", 1236 - refspec->dst, oid_to_hex(null_oid())); 1236 + refspec->dst, oid_to_hex(null_oid(the_hash_algo))); 1237 1237 } 1238 1238 } 1239 1239
+4 -4
builtin/fast-import.c
··· 770 770 p->pack_fd = pack_fd; 771 771 p->do_not_close = 1; 772 772 p->repo = the_repository; 773 - pack_file = hashfd(pack_fd, p->pack_name); 773 + pack_file = hashfd(the_repository->hash_algo, pack_fd, p->pack_name); 774 774 775 775 pack_data = p; 776 776 pack_size = write_pack_header(pack_file, 0); ··· 798 798 if (c != last) 799 799 die("internal consistency error creating the index"); 800 800 801 - tmpfile = write_idx_file(the_hash_algo, NULL, idx, object_count, 801 + tmpfile = write_idx_file(the_repository, NULL, idx, object_count, 802 802 &pack_idx_opts, pack_data->hash); 803 803 free(idx); 804 804 return tmpfile; ··· 2021 2021 static struct strbuf buf = STRBUF_INIT; 2022 2022 uintmax_t len; 2023 2023 2024 - if (parse_data(&buf, big_file_threshold, &len)) 2024 + if (parse_data(&buf, repo_settings_get_big_file_threshold(the_repository), &len)) 2025 2025 store_object(OBJ_BLOB, &buf, last, oidout, mark); 2026 2026 else { 2027 2027 if (last) { ··· 3425 3425 unsigned long v; 3426 3426 if (!git_parse_ulong(option, &v)) 3427 3427 return 0; 3428 - big_file_threshold = v; 3428 + repo_settings_set_big_file_threshold(the_repository, v); 3429 3429 } else if (skip_prefix(option, "depth=", &option)) { 3430 3430 option_depth(option); 3431 3431 } else if (skip_prefix(option, "active-branches=", &option)) {
+3 -3
builtin/fsck.c
··· 400 400 } 401 401 402 402 /* Look up all the requirements, warn about missing objects.. */ 403 - max = get_max_object_index(); 403 + max = get_max_object_index(the_repository); 404 404 if (verbose) 405 405 fprintf_ln(stderr, _("Checking connectivity (%d objects)"), max); 406 406 407 407 for (i = 0; i < max; i++) { 408 - struct object *obj = get_indexed_object(i); 408 + struct object *obj = get_indexed_object(the_repository, i); 409 409 410 410 if (obj) 411 411 check_object(obj); ··· 626 626 void *contents = NULL; 627 627 int eaten; 628 628 struct object_info oi = OBJECT_INFO_INIT; 629 - struct object_id real_oid = *null_oid(); 629 + struct object_id real_oid = *null_oid(the_hash_algo); 630 630 int err = 0; 631 631 632 632 strbuf_reset(&cb_data->obj_type);
+2 -2
builtin/grep.c
··· 453 453 return 0; 454 454 455 455 subrepo = xmalloc(sizeof(*subrepo)); 456 - if (repo_submodule_init(subrepo, superproject, path, null_oid())) { 456 + if (repo_submodule_init(subrepo, superproject, path, null_oid(opt->repo->hash_algo))) { 457 457 free(subrepo); 458 458 return 0; 459 459 } ··· 1144 1144 break; 1145 1145 } 1146 1146 1147 - object = parse_object_or_die(&oid, arg); 1147 + object = parse_object_or_die(the_repository, &oid, arg); 1148 1148 if (!seen_dashdash) 1149 1149 verify_non_filename(prefix, arg); 1150 1150 add_object_array_with_path(object, arg, &list, oc.mode, oc.path);
+9 -7
builtin/index-pack.c
··· 279 279 { 280 280 unsigned i, max, foreign_nr = 0; 281 281 282 - max = get_max_object_index(); 282 + max = get_max_object_index(the_repository); 283 283 284 284 if (verbose) 285 285 progress = start_delayed_progress(the_repository, 286 286 _("Checking objects"), max); 287 287 288 288 for (i = 0; i < max; i++) { 289 - foreign_nr += check_object(get_indexed_object(i)); 289 + foreign_nr += check_object(get_indexed_object(the_repository, i)); 290 290 display_progress(progress, i + 1); 291 291 } 292 292 ··· 485 485 git_hash_update(&c, hdr, hdrlen); 486 486 } else 487 487 oid = NULL; 488 - if (type == OBJ_BLOB && size > big_file_threshold) 488 + if (type == OBJ_BLOB && 489 + size > repo_settings_get_big_file_threshold(the_repository)) 489 490 buf = fixed_buf; 490 491 else 491 492 buf = xmallocz(size); ··· 799 800 enum object_type type; 800 801 unsigned long size; 801 802 802 - if (entry->size <= big_file_threshold || entry->type != OBJ_BLOB) 803 + if (entry->size <= repo_settings_get_big_file_threshold(the_repository) || 804 + entry->type != OBJ_BLOB) 803 805 return -1; 804 806 805 807 memset(&data, 0, sizeof(data)); ··· 1382 1384 REALLOC_ARRAY(objects, nr_objects + nr_unresolved + 1); 1383 1385 memset(objects + nr_objects + 1, 0, 1384 1386 nr_unresolved * sizeof(*objects)); 1385 - f = hashfd(output_fd, curr_pack); 1387 + f = hashfd(the_repository->hash_algo, output_fd, curr_pack); 1386 1388 fix_unresolved_deltas(f); 1387 1389 strbuf_addf(&msg, Q_("completed with %d local object", 1388 1390 "completed with %d local objects", ··· 2089 2091 ALLOC_ARRAY(idx_objects, nr_objects); 2090 2092 for (i = 0; i < nr_objects; i++) 2091 2093 idx_objects[i] = &objects[i].idx; 2092 - curr_index = write_idx_file(the_hash_algo, index_name, idx_objects, 2094 + curr_index = write_idx_file(the_repository, index_name, idx_objects, 2093 2095 nr_objects, &opts, pack_hash); 2094 2096 if (rev_index) 2095 - curr_rev_index = write_rev_file(the_hash_algo, rev_index_name, 2097 + curr_rev_index = write_rev_file(the_repository, rev_index_name, 2096 2098 idx_objects, nr_objects, 2097 2099 pack_hash, opts.flags); 2098 2100 free(idx_objects);
+1 -1
builtin/log.c
··· 2468 2468 base = get_base_commit(&cfg, list, nr); 2469 2469 if (base) { 2470 2470 reset_revision_walk(); 2471 - clear_object_flags(UNINTERESTING); 2471 + clear_object_flags(the_repository, UNINTERESTING); 2472 2472 prepare_bases(&bases, base, list, nr); 2473 2473 } 2474 2474
+2 -1
builtin/ls-files.c
··· 233 233 { 234 234 struct repository subrepo; 235 235 236 - if (repo_submodule_init(&subrepo, superproject, path, null_oid())) 236 + if (repo_submodule_init(&subrepo, superproject, path, 237 + null_oid(superproject->hash_algo))) 237 238 return; 238 239 239 240 if (repo_read_index(&subrepo) < 0)
+2 -2
builtin/name-rev.c
··· 675 675 } else if (all) { 676 676 int i, max; 677 677 678 - max = get_max_object_index(); 678 + max = get_max_object_index(the_repository); 679 679 for (i = 0; i < max; i++) { 680 - struct object *obj = get_indexed_object(i); 680 + struct object *obj = get_indexed_object(the_repository, i); 681 681 if (!obj || obj->type != OBJ_COMMIT) 682 682 continue; 683 683 show_name(obj, NULL,
+10 -7
builtin/pack-objects.c
··· 500 500 501 501 if (!usable_delta) { 502 502 if (oe_type(entry) == OBJ_BLOB && 503 - oe_size_greater_than(&to_pack, entry, big_file_threshold) && 503 + oe_size_greater_than(&to_pack, entry, 504 + repo_settings_get_big_file_threshold(the_repository)) && 504 505 (st = open_istream(the_repository, &entry->idx.oid, &type, 505 506 &size, NULL)) != NULL) 506 507 buf = NULL; ··· 1312 1313 char *pack_tmp_name = NULL; 1313 1314 1314 1315 if (pack_to_stdout) 1315 - f = hashfd_throughput(1, "<stdout>", progress_state); 1316 + f = hashfd_throughput(the_repository->hash_algo, 1, 1317 + "<stdout>", progress_state); 1316 1318 else 1317 - f = create_tmp_packfile(&pack_tmp_name); 1319 + f = create_tmp_packfile(the_repository, &pack_tmp_name); 1318 1320 1319 1321 offset = write_pack_header(f, nr_remaining); 1320 1322 ··· 1407 1409 if (cruft) 1408 1410 pack_idx_opts.flags |= WRITE_MTIMES; 1409 1411 1410 - stage_tmp_packfiles(the_hash_algo, &tmpname, 1412 + stage_tmp_packfiles(the_repository, &tmpname, 1411 1413 pack_tmp_name, written_list, 1412 1414 nr_written, &to_pack, 1413 1415 &pack_idx_opts, hash, ··· 2535 2537 struct object_entry *entry = sorted_by_offset[i]; 2536 2538 check_object(entry, i); 2537 2539 if (entry->type_valid && 2538 - oe_size_greater_than(&to_pack, entry, big_file_threshold)) 2540 + oe_size_greater_than(&to_pack, entry, 2541 + repo_settings_get_big_file_threshold(the_repository))) 2539 2542 entry->no_try_delta = 1; 2540 2543 display_progress(progress_state, i + 1); 2541 2544 } ··· 3928 3931 index_commit_for_bitmap(commit); 3929 3932 3930 3933 if (use_delta_islands) 3931 - propagate_island_marks(commit); 3934 + propagate_island_marks(the_repository, commit); 3932 3935 } 3933 3936 3934 3937 static void show_object(struct object *obj, const char *name, ··· 4244 4247 if (!peel_iterated_oid(the_repository, oid, &peeled)) 4245 4248 oid = &peeled; 4246 4249 4247 - object = parse_object_or_die(oid, refname); 4250 + object = parse_object_or_die(the_repository, oid, refname); 4248 4251 if (object->type == OBJ_COMMIT) 4249 4252 object->flags |= NEEDS_BITMAP; 4250 4253
+1 -1
builtin/prune.c
··· 185 185 const char *name = *argv++; 186 186 187 187 if (!repo_get_oid(the_repository, name, &oid)) { 188 - struct object *object = parse_object_or_die(&oid, 188 + struct object *object = parse_object_or_die(the_repository, &oid, 189 189 name); 190 190 add_pending_object(&revs, object, ""); 191 191 }
+1 -1
builtin/rebase.c
··· 925 925 options->orig_head, &merge_bases) < 0) 926 926 exit(128); 927 927 if (!merge_bases || merge_bases->next) 928 - oidcpy(branch_base, null_oid()); 928 + oidcpy(branch_base, null_oid(the_hash_algo)); 929 929 else 930 930 oidcpy(branch_base, &merge_bases->item->object.oid); 931 931
+1 -1
builtin/receive-pack.c
··· 363 363 strvec_clear(&excludes_vector); 364 364 365 365 if (!sent_capabilities) 366 - show_ref("capabilities^{}", null_oid()); 366 + show_ref("capabilities^{}", null_oid(the_hash_algo)); 367 367 368 368 advertise_shallow_grafts(1); 369 369
+18 -18
builtin/submodule--helper.c
··· 78 78 int ret; 79 79 80 80 if (repo_submodule_init(&subrepo, the_repository, module_path, 81 - null_oid()) < 0) 81 + null_oid(the_hash_algo)) < 0) 82 82 return die_message(_("could not get a repository handle for submodule '%s'"), 83 83 module_path); 84 84 ret = repo_get_default_remote(&subrepo, default_remote); ··· 308 308 displaypath = get_submodule_displaypath(path, info->prefix, 309 309 info->super_prefix); 310 310 311 - sub = submodule_from_path(the_repository, null_oid(), path); 311 + sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path); 312 312 313 313 if (!sub) 314 314 die(_("No url found for submodule path '%s' in .gitmodules"), ··· 468 468 469 469 displaypath = get_submodule_displaypath(path, prefix, super_prefix); 470 470 471 - sub = submodule_from_path(the_repository, null_oid(), path); 471 + sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path); 472 472 473 473 if (!sub) 474 474 die(_("No url found for submodule path '%s' in .gitmodules"), ··· 645 645 if (validate_submodule_path(path) < 0) 646 646 exit(128); 647 647 648 - if (!submodule_from_path(the_repository, null_oid(), path)) 648 + if (!submodule_from_path(the_repository, null_oid(the_hash_algo), path)) 649 649 die(_("no submodule mapping found in .gitmodules for path '%s'"), 650 650 path); 651 651 652 652 displaypath = get_submodule_displaypath(path, prefix, super_prefix); 653 653 654 654 if ((CE_STAGEMASK & ce_flags) >> CE_STAGESHIFT) { 655 - print_status(flags, 'U', path, null_oid(), displaypath); 655 + print_status(flags, 'U', path, null_oid(the_hash_algo), displaypath); 656 656 goto cleanup; 657 657 } 658 658 ··· 912 912 struct strbuf errmsg = STRBUF_INIT; 913 913 int total_commits = -1; 914 914 915 - if (!info->cached && oideq(&p->oid_dst, null_oid())) { 915 + if (!info->cached && oideq(&p->oid_dst, null_oid(the_hash_algo))) { 916 916 if (S_ISGITLINK(p->mod_dst)) { 917 917 struct ref_store *refs = repo_get_submodule_ref_store(the_repository, 918 918 p->sm_path); ··· 1051 1051 1052 1052 if (info->for_status && p->status != 'A' && 1053 1053 (sub = submodule_from_path(the_repository, 1054 - null_oid(), p->sm_path))) { 1054 + null_oid(the_hash_algo), p->sm_path))) { 1055 1055 char *config_key = NULL; 1056 1056 const char *value; 1057 1057 int ignore_all = 0; ··· 1259 1259 if (validate_submodule_path(path) < 0) 1260 1260 exit(128); 1261 1261 1262 - sub = submodule_from_path(the_repository, null_oid(), path); 1262 + sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path); 1263 1263 1264 1264 if (sub && sub->url) { 1265 1265 if (starts_with_dot_dot_slash(sub->url) || ··· 1404 1404 if (validate_submodule_path(path) < 0) 1405 1405 exit(128); 1406 1406 1407 - sub = submodule_from_path(the_repository, null_oid(), path); 1407 + sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path); 1408 1408 1409 1409 if (!sub || !sub->name) 1410 1410 goto cleanup; ··· 1929 1929 enum submodule_update_type update, 1930 1930 struct submodule_update_strategy *out) 1931 1931 { 1932 - const struct submodule *sub = submodule_from_path(r, null_oid(), path); 1932 + const struct submodule *sub = submodule_from_path(r, null_oid(the_hash_algo), path); 1933 1933 char *key; 1934 1934 const char *val; 1935 1935 int ret; ··· 2089 2089 goto cleanup; 2090 2090 } 2091 2091 2092 - sub = submodule_from_path(the_repository, null_oid(), ce->name); 2092 + sub = submodule_from_path(the_repository, null_oid(the_hash_algo), ce->name); 2093 2093 2094 2094 if (!sub) { 2095 2095 next_submodule_warn_missing(suc, out, displaypath); ··· 2485 2485 char *key; 2486 2486 *branch = NULL; 2487 2487 2488 - sub = submodule_from_path(the_repository, null_oid(), path); 2488 + sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path); 2489 2489 if (!sub) 2490 2490 return die_message(_("could not initialize submodule at path '%s'"), 2491 2491 path); ··· 2531 2531 const char *cw; 2532 2532 struct repository subrepo; 2533 2533 2534 - if (repo_submodule_init(&subrepo, the_repository, path, null_oid())) 2534 + if (repo_submodule_init(&subrepo, the_repository, path, null_oid(the_hash_algo))) 2535 2535 return die_message(_("could not get a repository handle for submodule '%s'"), 2536 2536 path); 2537 2537 ··· 2644 2644 return ret; 2645 2645 2646 2646 if (update_data->just_cloned) 2647 - oidcpy(&update_data->suboid, null_oid()); 2647 + oidcpy(&update_data->suboid, null_oid(the_hash_algo)); 2648 2648 else if (repo_resolve_gitlink_ref(the_repository, update_data->sm_path, 2649 2649 "HEAD", &update_data->suboid)) 2650 2650 return die_message(_("Unable to find current revision in submodule path '%s'"), ··· 2697 2697 struct update_data next = *update_data; 2698 2698 2699 2699 next.prefix = NULL; 2700 - oidcpy(&next.oid, null_oid()); 2701 - oidcpy(&next.suboid, null_oid()); 2700 + oidcpy(&next.oid, null_oid(the_hash_algo)); 2701 + oidcpy(&next.suboid, null_oid(the_hash_algo)); 2702 2702 2703 2703 cp.dir = update_data->sm_path; 2704 2704 cp.git_cmd = 1; ··· 3057 3057 if (argc != 2 || !(path = argv[0]) || !(newurl = argv[1])) 3058 3058 usage_with_options(usage, options); 3059 3059 3060 - sub = submodule_from_path(the_repository, null_oid(), path); 3060 + sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path); 3061 3061 3062 3062 if (!sub) 3063 3063 die(_("no submodule mapping found in .gitmodules for path '%s'"), ··· 3113 3113 if (argc != 1 || !(path = argv[0])) 3114 3114 usage_with_options(usage, options); 3115 3115 3116 - sub = submodule_from_path(the_repository, null_oid(), path); 3116 + sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path); 3117 3117 3118 3118 if (!sub) 3119 3119 die(_("no submodule mapping found in .gitmodules for path '%s'"),
+1 -1
builtin/tag.c
··· 172 172 if (compat) { 173 173 const struct git_hash_algo *algo = the_repository->hash_algo; 174 174 175 - if (convert_object_file(&compat_buf, algo, compat, 175 + if (convert_object_file(the_repository ,&compat_buf, algo, compat, 176 176 buffer->buf, buffer->len, OBJ_TAG, 1)) 177 177 goto out; 178 178 if (sign_buffer(&compat_buf, &compat_sig, keyid))
+3 -2
builtin/unpack-objects.c
··· 505 505 * has not been resolved yet. 506 506 */ 507 507 oidclr(&obj_list[nr].oid, the_repository->hash_algo); 508 - add_delta_to_list(nr, null_oid(), base_offset, 508 + add_delta_to_list(nr, null_oid(the_hash_algo), base_offset, 509 509 delta_data, delta_size); 510 510 return; 511 511 } ··· 553 553 554 554 switch (type) { 555 555 case OBJ_BLOB: 556 - if (!dry_run && size > big_file_threshold) { 556 + if (!dry_run && 557 + size > repo_settings_get_big_file_threshold(the_repository)) { 557 558 stream_blob(size, nr); 558 559 return; 559 560 }
+1 -1
builtin/update-ref.c
··· 503 503 */ 504 504 old_target = parse_next_refname(&next); 505 505 if (!old_target) 506 - oidcpy(&old_oid, null_oid()); 506 + oidcpy(&old_oid, null_oid(the_hash_algo)); 507 507 508 508 if (*next != line_termination) 509 509 die("symref-verify %s: extra input: %s", refname, next);
+1 -1
builtin/worktree.c
··· 578 578 579 579 strvec_pushl(&opt.env, "GIT_DIR", "GIT_WORK_TREE", NULL); 580 580 strvec_pushl(&opt.args, 581 - oid_to_hex(null_oid()), 581 + oid_to_hex(null_oid(the_hash_algo)), 582 582 oid_to_hex(&commit->object.oid), 583 583 "1", 584 584 NULL);
+2 -2
bulk-checkin.c
··· 44 44 { 45 45 char *idx_tmp_name = NULL; 46 46 47 - stage_tmp_packfiles(the_hash_algo, basename, pack_tmp_name, 47 + stage_tmp_packfiles(the_repository, basename, pack_tmp_name, 48 48 written_list, nr_written, NULL, pack_idx_opts, hash, 49 49 &idx_tmp_name); 50 50 rename_tmp_packfile_idx(basename, &idx_tmp_name); ··· 244 244 if (!(flags & HASH_WRITE_OBJECT) || state->f) 245 245 return; 246 246 247 - state->f = create_tmp_packfile(&state->pack_tmp_name); 247 + state->f = create_tmp_packfile(the_repository, &state->pack_tmp_name); 248 248 reset_pack_idx_option(&state->pack_idx_opts); 249 249 250 250 /* Pretend we are going to write only one object */
+1 -1
combine-diff.c
··· 1066 1066 &result_size, NULL, NULL); 1067 1067 } else if (textconv) { 1068 1068 struct diff_filespec *df = alloc_filespec(elem->path); 1069 - fill_filespec(df, null_oid(), 0, st.st_mode); 1069 + fill_filespec(df, null_oid(the_hash_algo), 0, st.st_mode); 1070 1070 result_size = fill_textconv(opt->repo, textconv, df, &result); 1071 1071 free_filespec(df); 1072 1072 } else if (0 <= (fd = open(elem->path, O_RDONLY))) {
+6 -3
commit-graph.c
··· 2090 2090 return -1; 2091 2091 } 2092 2092 2093 - f = hashfd(get_tempfile_fd(graph_layer), get_tempfile_path(graph_layer)); 2093 + f = hashfd(the_repository->hash_algo, 2094 + get_tempfile_fd(graph_layer), get_tempfile_path(graph_layer)); 2094 2095 } else { 2095 2096 hold_lock_file_for_update_mode(&lk, ctx->graph_name, 2096 2097 LOCK_DIE_ON_ERROR, 0444); 2097 - f = hashfd(get_lock_file_fd(&lk), get_lock_file_path(&lk)); 2098 + f = hashfd(the_repository->hash_algo, 2099 + get_lock_file_fd(&lk), get_lock_file_path(&lk)); 2098 2100 } 2099 2101 2100 2102 cf = init_chunkfile(f); ··· 2716 2718 2717 2719 static int commit_graph_checksum_valid(struct commit_graph *g) 2718 2720 { 2719 - return hashfile_checksum_valid(g->data, g->data_len); 2721 + return hashfile_checksum_valid(the_repository->hash_algo, 2722 + g->data, g->data_len); 2720 2723 } 2721 2724 2722 2725 static int verify_one_commit_graph(struct repository *r,
+1 -1
commit.c
··· 1380 1380 struct commit_extra_header *new; 1381 1381 CALLOC_ARRAY(new, 1); 1382 1382 if (!strcmp(orig->key, "mergetag")) { 1383 - if (convert_object_file(&out, algo, compat, 1383 + if (convert_object_file(the_repository, &out, algo, compat, 1384 1384 orig->value, orig->len, 1385 1385 OBJ_TAG, 1)) { 1386 1386 free(new);
-5
config.c
··· 1490 1490 return 0; 1491 1491 } 1492 1492 1493 - if (!strcmp(var, "core.bigfilethreshold")) { 1494 - big_file_threshold = git_config_ulong(var, value, ctx->kvi); 1495 - return 0; 1496 - } 1497 - 1498 1493 if (!strcmp(var, "core.autocrlf")) { 1499 1494 if (value && !strcasecmp(value, "input")) { 1500 1495 auto_crlf = AUTO_CRLF_INPUT;
+16 -12
csum-file.c
··· 8 8 * able to verify hasn't been messed with afterwards. 9 9 */ 10 10 11 - #define USE_THE_REPOSITORY_VARIABLE 12 - 13 11 #include "git-compat-util.h" 14 12 #include "csum-file.h" 15 13 #include "git-zlib.h" ··· 148 146 } 149 147 } 150 148 151 - struct hashfile *hashfd_check(const char *name) 149 + struct hashfile *hashfd_check(const struct git_hash_algo *algop, 150 + const char *name) 152 151 { 153 152 int sink, check; 154 153 struct hashfile *f; 155 154 156 155 sink = xopen("/dev/null", O_WRONLY); 157 156 check = xopen(name, O_RDONLY); 158 - f = hashfd(sink, name); 157 + f = hashfd(algop, sink, name); 159 158 f->check_fd = check; 160 159 f->check_buffer = xmalloc(f->buffer_len); 161 160 162 161 return f; 163 162 } 164 163 165 - static struct hashfile *hashfd_internal(int fd, const char *name, 164 + static struct hashfile *hashfd_internal(const struct git_hash_algo *algop, 165 + int fd, const char *name, 166 166 struct progress *tp, 167 167 size_t buffer_len) 168 168 { ··· 176 176 f->do_crc = 0; 177 177 f->skip_hash = 0; 178 178 179 - f->algop = unsafe_hash_algo(the_hash_algo); 179 + f->algop = unsafe_hash_algo(algop); 180 180 f->algop->init_fn(&f->ctx); 181 181 182 182 f->buffer_len = buffer_len; ··· 186 186 return f; 187 187 } 188 188 189 - struct hashfile *hashfd(int fd, const char *name) 189 + struct hashfile *hashfd(const struct git_hash_algo *algop, 190 + int fd, const char *name) 190 191 { 191 192 /* 192 193 * Since we are not going to use a progress meter to 193 194 * measure the rate of data passing through this hashfile, 194 195 * use a larger buffer size to reduce fsync() calls. 195 196 */ 196 - return hashfd_internal(fd, name, NULL, 128 * 1024); 197 + return hashfd_internal(algop, fd, name, NULL, 128 * 1024); 197 198 } 198 199 199 - struct hashfile *hashfd_throughput(int fd, const char *name, struct progress *tp) 200 + struct hashfile *hashfd_throughput(const struct git_hash_algo *algop, 201 + int fd, const char *name, struct progress *tp) 200 202 { 201 203 /* 202 204 * Since we are expecting to report progress of the ··· 204 206 * size so the progress indicators arrive at a more 205 207 * frequent rate. 206 208 */ 207 - return hashfd_internal(fd, name, tp, 8 * 1024); 209 + return hashfd_internal(algop, fd, name, tp, 8 * 1024); 208 210 } 209 211 210 212 void hashfile_checkpoint_init(struct hashfile *f, ··· 246 248 return f->crc32; 247 249 } 248 250 249 - int hashfile_checksum_valid(const unsigned char *data, size_t total_len) 251 + int hashfile_checksum_valid(const struct git_hash_algo *algop, 252 + const unsigned char *data, size_t total_len) 250 253 { 251 254 unsigned char got[GIT_MAX_RAWSZ]; 252 255 struct git_hash_ctx ctx; 253 - const struct git_hash_algo *algop = unsafe_hash_algo(the_hash_algo); 254 256 size_t data_len = total_len - algop->rawsz; 257 + 258 + algop = unsafe_hash_algo(algop); 255 259 256 260 if (total_len < algop->rawsz) 257 261 return 0; /* say "too short"? */
+8 -4
csum-file.h
··· 45 45 #define CSUM_FSYNC 2 46 46 #define CSUM_HASH_IN_STREAM 4 47 47 48 - struct hashfile *hashfd(int fd, const char *name); 49 - struct hashfile *hashfd_check(const char *name); 50 - struct hashfile *hashfd_throughput(int fd, const char *name, struct progress *tp); 48 + struct hashfile *hashfd(const struct git_hash_algo *algop, 49 + int fd, const char *name); 50 + struct hashfile *hashfd_check(const struct git_hash_algo *algop, 51 + const char *name); 52 + struct hashfile *hashfd_throughput(const struct git_hash_algo *algop, 53 + int fd, const char *name, struct progress *tp); 51 54 52 55 /* 53 56 * Free the hashfile without flushing its contents to disk. This only ··· 66 69 uint32_t crc32_end(struct hashfile *); 67 70 68 71 /* Verify checksum validity while reading. Returns non-zero on success. */ 69 - int hashfile_checksum_valid(const unsigned char *data, size_t len); 72 + int hashfile_checksum_valid(const struct git_hash_algo *algop, 73 + const unsigned char *data, size_t len); 70 74 71 75 /* 72 76 * Returns the total number of bytes fed to the hashfile so far (including ones
+6 -8
delta-islands.c
··· 1 - #define USE_THE_REPOSITORY_VARIABLE 2 1 #define DISABLE_SIGN_COMPARE_WARNINGS 3 2 4 3 #include "git-compat-util.h" ··· 267 266 QSORT(todo, nr, tree_depth_compare); 268 267 269 268 if (progress) 270 - progress_state = start_progress(the_repository, 271 - _("Propagating island marks"), nr); 269 + progress_state = start_progress(r, _("Propagating island marks"), nr); 272 270 273 271 for (i = 0; i < nr; i++) { 274 272 struct object_entry *ent = todo[i].entry; ··· 490 488 491 489 island_marks = kh_init_oid_map(); 492 490 493 - git_config(island_config_callback, &ild); 491 + repo_config(r, island_config_callback, &ild); 494 492 ild.remote_islands = kh_init_str(); 495 - refs_for_each_ref(get_main_ref_store(the_repository), 493 + refs_for_each_ref(get_main_ref_store(r), 496 494 find_island_for_ref, &ild); 497 495 free_config_regexes(&ild); 498 496 deduplicate_islands(ild.remote_islands, r); ··· 502 500 fprintf(stderr, _("Marked %d islands, done.\n"), island_counter); 503 501 } 504 502 505 - void propagate_island_marks(struct commit *commit) 503 + void propagate_island_marks(struct repository *r, struct commit *commit) 506 504 { 507 505 khiter_t pos = kh_get_oid_map(island_marks, commit->object.oid); 508 506 ··· 510 508 struct commit_list *p; 511 509 struct island_bitmap *root_marks = kh_value(island_marks, pos); 512 510 513 - repo_parse_commit(the_repository, commit); 514 - set_island_marks(&repo_get_commit_tree(the_repository, commit)->object, 511 + repo_parse_commit(r, commit); 512 + set_island_marks(&repo_get_commit_tree(r, commit)->object, 515 513 root_marks); 516 514 for (p = commit->parents; p; p = p->next) 517 515 set_island_marks(&p->item->object, root_marks);
+1 -1
delta-islands.h
··· 12 12 int progress, 13 13 struct packing_data *to_pack); 14 14 void load_delta_islands(struct repository *r, int progress); 15 - void propagate_island_marks(struct commit *commit); 15 + void propagate_island_marks(struct repository *r, struct commit *commit); 16 16 int compute_pack_layers(struct packing_data *to_pack); 17 17 void free_island_marks(void); 18 18
+5 -5
diff-lib.c
··· 172 172 * these from (stage - 2). 173 173 */ 174 174 dpath = combine_diff_path_new(ce->name, ce_namelen(ce), 175 - wt_mode, null_oid(), 2); 175 + wt_mode, null_oid(the_hash_algo), 2); 176 176 177 177 while (i < entries) { 178 178 struct cache_entry *nce = istate->cache[i]; ··· 257 257 ce_intent_to_add(ce)) { 258 258 newmode = ce_mode_from_stat(ce, st.st_mode); 259 259 diff_addremove(&revs->diffopt, '+', newmode, 260 - null_oid(), 0, ce->name, 0); 260 + null_oid(the_hash_algo), 0, ce->name, 0); 261 261 continue; 262 262 } 263 263 ··· 274 274 } 275 275 oldmode = ce->ce_mode; 276 276 old_oid = &ce->oid; 277 - new_oid = changed ? null_oid() : &ce->oid; 277 + new_oid = changed ? null_oid(the_hash_algo) : &ce->oid; 278 278 diff_change(&revs->diffopt, oldmode, newmode, 279 279 old_oid, new_oid, 280 280 !is_null_oid(old_oid), ··· 330 330 0, dirty_submodule); 331 331 if (changed) { 332 332 mode = ce_mode_from_stat(ce, st.st_mode); 333 - oid = null_oid(); 333 + oid = null_oid(the_hash_algo); 334 334 } 335 335 } 336 336 ··· 402 402 403 403 p = combine_diff_path_new(new_entry->name, 404 404 ce_namelen(new_entry), 405 - mode, null_oid(), 2); 405 + mode, null_oid(the_hash_algo), 2); 406 406 p->parent[0].status = DIFF_STATUS_MODIFIED; 407 407 p->parent[0].mode = new_entry->ce_mode; 408 408 oidcpy(&p->parent[0].oid, &new_entry->oid);
+14 -14
diff-no-index.c
··· 113 113 populate_common(s, &buf); 114 114 } 115 115 116 - static struct diff_filespec *noindex_filespec(const char *name, int mode, 116 + static struct diff_filespec *noindex_filespec(const struct git_hash_algo *algop, 117 + const char *name, int mode, 117 118 enum special special) 118 119 { 119 120 struct diff_filespec *s; ··· 121 122 if (!name) 122 123 name = "/dev/null"; 123 124 s = alloc_filespec(name); 124 - fill_filespec(s, null_oid(), 0, mode); 125 + fill_filespec(s, null_oid(algop), 0, mode); 125 126 if (special == SPECIAL_STDIN) 126 127 populate_from_stdin(s); 127 128 else if (special == SPECIAL_PIPE) ··· 129 130 return s; 130 131 } 131 132 132 - static int queue_diff(struct diff_options *o, 133 + static int queue_diff(struct diff_options *o, const struct git_hash_algo *algop, 133 134 const char *name1, const char *name2, int recursing) 134 135 { 135 136 int mode1 = 0, mode2 = 0; ··· 145 146 146 147 if (S_ISDIR(mode1)) { 147 148 /* 2 is file that is created */ 148 - d1 = noindex_filespec(NULL, 0, SPECIAL_NONE); 149 - d2 = noindex_filespec(name2, mode2, special2); 149 + d1 = noindex_filespec(algop, NULL, 0, SPECIAL_NONE); 150 + d2 = noindex_filespec(algop, name2, mode2, special2); 150 151 name2 = NULL; 151 152 mode2 = 0; 152 153 } else { 153 154 /* 1 is file that is deleted */ 154 - d1 = noindex_filespec(name1, mode1, special1); 155 - d2 = noindex_filespec(NULL, 0, SPECIAL_NONE); 155 + d1 = noindex_filespec(algop, name1, mode1, special1); 156 + d2 = noindex_filespec(algop, NULL, 0, SPECIAL_NONE); 156 157 name1 = NULL; 157 158 mode1 = 0; 158 159 } ··· 217 218 n2 = buffer2.buf; 218 219 } 219 220 220 - ret = queue_diff(o, n1, n2, 1); 221 + ret = queue_diff(o, algop, n1, n2, 1); 221 222 } 222 223 string_list_clear(&p1, 0); 223 224 string_list_clear(&p2, 0); ··· 234 235 SWAP(special1, special2); 235 236 } 236 237 237 - d1 = noindex_filespec(name1, mode1, special1); 238 - d2 = noindex_filespec(name2, mode2, special2); 238 + d1 = noindex_filespec(algop, name1, mode1, special1); 239 + d2 = noindex_filespec(algop, name2, mode2, special2); 239 240 diff_queue(&diff_queued_diff, d1, d2); 240 241 return 0; 241 242 } ··· 297 298 NULL 298 299 }; 299 300 300 - int diff_no_index(struct rev_info *revs, 301 - int implicit_no_index, 302 - int argc, const char **argv) 301 + int diff_no_index(struct rev_info *revs, const struct git_hash_algo *algop, 302 + int implicit_no_index, int argc, const char **argv) 303 303 { 304 304 int i, no_index; 305 305 int ret = 1; ··· 354 354 setup_diff_pager(&revs->diffopt); 355 355 revs->diffopt.flags.exit_with_status = 1; 356 356 357 - if (queue_diff(&revs->diffopt, paths[0], paths[1], 0)) 357 + if (queue_diff(&revs->diffopt, algop, paths[0], paths[1], 0)) 358 358 goto out; 359 359 diff_set_mnemonic_prefix(&revs->diffopt, "1/", "2/"); 360 360 diffcore_std(&revs->diffopt);
+8 -6
diff.c
··· 4193 4193 * is probably fine. 4194 4194 */ 4195 4195 if (check_binary && 4196 - s->size > big_file_threshold && s->is_binary == -1) { 4196 + s->size > repo_settings_get_big_file_threshold(the_repository) && 4197 + s->is_binary == -1) { 4197 4198 s->is_binary = 1; 4198 4199 return 0; 4199 4200 } ··· 4243 4244 if (size_only || check_binary) { 4244 4245 if (size_only) 4245 4246 return 0; 4246 - if (s->size > big_file_threshold && s->is_binary == -1) { 4247 + if (s->size > repo_settings_get_big_file_threshold(the_repository) && 4248 + s->is_binary == -1) { 4247 4249 s->is_binary = 1; 4248 4250 return 0; 4249 4251 } ··· 4344 4346 die_errno("readlink(%s)", one->path); 4345 4347 prep_temp_blob(r->index, one->path, temp, sb.buf, sb.len, 4346 4348 (one->oid_valid ? 4347 - &one->oid : null_oid()), 4349 + &one->oid : null_oid(the_hash_algo)), 4348 4350 (one->oid_valid ? 4349 4351 one->mode : S_IFLNK)); 4350 4352 strbuf_release(&sb); ··· 4353 4355 /* we can borrow from the file in the work tree */ 4354 4356 temp->name = one->path; 4355 4357 if (!one->oid_valid) 4356 - oid_to_hex_r(temp->hex, null_oid()); 4358 + oid_to_hex_r(temp->hex, null_oid(the_hash_algo)); 4357 4359 else 4358 4360 oid_to_hex_r(temp->hex, &one->oid); 4359 4361 /* Even though we may sometimes borrow the ··· 6647 6649 6648 6650 one = alloc_filespec(e->key); 6649 6651 two = alloc_filespec(e->key); 6650 - fill_filespec(one, null_oid(), 0, 0); 6651 - fill_filespec(two, null_oid(), 0, 0); 6652 + fill_filespec(one, null_oid(the_hash_algo), 0, 0); 6653 + fill_filespec(two, null_oid(the_hash_algo), 0, 0); 6652 6654 p = diff_queue(q, one, two); 6653 6655 p->status = DIFF_STATUS_MODIFIED; 6654 6656 }
+1 -1
diff.h
··· 689 689 690 690 int diff_result_code(struct rev_info *); 691 691 692 - int diff_no_index(struct rev_info *, 692 + int diff_no_index(struct rev_info *, const struct git_hash_algo *algop, 693 693 int implicit_no_index, int, const char **); 694 694 695 695 int index_differs_from(struct repository *r, const char *def,
+1 -1
dir.c
··· 4035 4035 */ 4036 4036 i++; 4037 4037 4038 - sub = submodule_from_path(&subrepo, null_oid(), ce->name); 4038 + sub = submodule_from_path(&subrepo, null_oid(the_hash_algo), ce->name); 4039 4039 if (!sub || !is_submodule_active(&subrepo, ce->name)) 4040 4040 /* .gitmodules broken or inactive sub */ 4041 4041 continue;
-1
environment.c
··· 49 49 int use_fsync = -1; 50 50 enum fsync_method fsync_method = FSYNC_METHOD_DEFAULT; 51 51 enum fsync_component fsync_components = FSYNC_COMPONENTS_DEFAULT; 52 - unsigned long big_file_threshold = 512 * 1024 * 1024; 53 52 char *editor_program; 54 53 char *askpass_program; 55 54 char *excludes_file;
-1
environment.h
··· 154 154 extern int pack_compression_level; 155 155 extern size_t packed_git_window_size; 156 156 extern size_t packed_git_limit; 157 - extern unsigned long big_file_threshold; 158 157 extern unsigned long pack_size_limit_cfg; 159 158 extern int max_allowed_tree_depth; 160 159
+1 -1
grep.c
··· 1517 1517 fill_filespec(df, gs->identifier, 1, 0100644); 1518 1518 break; 1519 1519 case GREP_SOURCE_FILE: 1520 - fill_filespec(df, null_oid(), 0, 0100644); 1520 + fill_filespec(df, null_oid(r->hash_algo), 0, 0100644); 1521 1521 break; 1522 1522 default: 1523 1523 BUG("attempt to textconv something without a path?");
+277
hash.c
··· 1 + #include "git-compat-util.h" 2 + #include "hash.h" 3 + #include "hex.h" 4 + 5 + static const struct object_id empty_tree_oid = { 6 + .hash = { 7 + 0x4b, 0x82, 0x5d, 0xc6, 0x42, 0xcb, 0x6e, 0xb9, 0xa0, 0x60, 8 + 0xe5, 0x4b, 0xf8, 0xd6, 0x92, 0x88, 0xfb, 0xee, 0x49, 0x04 9 + }, 10 + .algo = GIT_HASH_SHA1, 11 + }; 12 + static const struct object_id empty_blob_oid = { 13 + .hash = { 14 + 0xe6, 0x9d, 0xe2, 0x9b, 0xb2, 0xd1, 0xd6, 0x43, 0x4b, 0x8b, 15 + 0x29, 0xae, 0x77, 0x5a, 0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91 16 + }, 17 + .algo = GIT_HASH_SHA1, 18 + }; 19 + static const struct object_id null_oid_sha1 = { 20 + .hash = {0}, 21 + .algo = GIT_HASH_SHA1, 22 + }; 23 + static const struct object_id empty_tree_oid_sha256 = { 24 + .hash = { 25 + 0x6e, 0xf1, 0x9b, 0x41, 0x22, 0x5c, 0x53, 0x69, 0xf1, 0xc1, 26 + 0x04, 0xd4, 0x5d, 0x8d, 0x85, 0xef, 0xa9, 0xb0, 0x57, 0xb5, 27 + 0x3b, 0x14, 0xb4, 0xb9, 0xb9, 0x39, 0xdd, 0x74, 0xde, 0xcc, 28 + 0x53, 0x21 29 + }, 30 + .algo = GIT_HASH_SHA256, 31 + }; 32 + static const struct object_id empty_blob_oid_sha256 = { 33 + .hash = { 34 + 0x47, 0x3a, 0x0f, 0x4c, 0x3b, 0xe8, 0xa9, 0x36, 0x81, 0xa2, 35 + 0x67, 0xe3, 0xb1, 0xe9, 0xa7, 0xdc, 0xda, 0x11, 0x85, 0x43, 36 + 0x6f, 0xe1, 0x41, 0xf7, 0x74, 0x91, 0x20, 0xa3, 0x03, 0x72, 37 + 0x18, 0x13 38 + }, 39 + .algo = GIT_HASH_SHA256, 40 + }; 41 + static const struct object_id null_oid_sha256 = { 42 + .hash = {0}, 43 + .algo = GIT_HASH_SHA256, 44 + }; 45 + 46 + static void git_hash_sha1_init(struct git_hash_ctx *ctx) 47 + { 48 + ctx->algop = &hash_algos[GIT_HASH_SHA1]; 49 + git_SHA1_Init(&ctx->state.sha1); 50 + } 51 + 52 + static void git_hash_sha1_clone(struct git_hash_ctx *dst, const struct git_hash_ctx *src) 53 + { 54 + dst->algop = src->algop; 55 + git_SHA1_Clone(&dst->state.sha1, &src->state.sha1); 56 + } 57 + 58 + static void git_hash_sha1_update(struct git_hash_ctx *ctx, const void *data, size_t len) 59 + { 60 + git_SHA1_Update(&ctx->state.sha1, data, len); 61 + } 62 + 63 + static void git_hash_sha1_final(unsigned char *hash, struct git_hash_ctx *ctx) 64 + { 65 + git_SHA1_Final(hash, &ctx->state.sha1); 66 + } 67 + 68 + static void git_hash_sha1_final_oid(struct object_id *oid, struct git_hash_ctx *ctx) 69 + { 70 + git_SHA1_Final(oid->hash, &ctx->state.sha1); 71 + memset(oid->hash + GIT_SHA1_RAWSZ, 0, GIT_MAX_RAWSZ - GIT_SHA1_RAWSZ); 72 + oid->algo = GIT_HASH_SHA1; 73 + } 74 + 75 + static void git_hash_sha1_init_unsafe(struct git_hash_ctx *ctx) 76 + { 77 + ctx->algop = unsafe_hash_algo(&hash_algos[GIT_HASH_SHA1]); 78 + git_SHA1_Init_unsafe(&ctx->state.sha1_unsafe); 79 + } 80 + 81 + static void git_hash_sha1_clone_unsafe(struct git_hash_ctx *dst, const struct git_hash_ctx *src) 82 + { 83 + dst->algop = src->algop; 84 + git_SHA1_Clone_unsafe(&dst->state.sha1_unsafe, &src->state.sha1_unsafe); 85 + } 86 + 87 + static void git_hash_sha1_update_unsafe(struct git_hash_ctx *ctx, const void *data, 88 + size_t len) 89 + { 90 + git_SHA1_Update_unsafe(&ctx->state.sha1_unsafe, data, len); 91 + } 92 + 93 + static void git_hash_sha1_final_unsafe(unsigned char *hash, struct git_hash_ctx *ctx) 94 + { 95 + git_SHA1_Final_unsafe(hash, &ctx->state.sha1_unsafe); 96 + } 97 + 98 + static void git_hash_sha1_final_oid_unsafe(struct object_id *oid, struct git_hash_ctx *ctx) 99 + { 100 + git_SHA1_Final_unsafe(oid->hash, &ctx->state.sha1_unsafe); 101 + memset(oid->hash + GIT_SHA1_RAWSZ, 0, GIT_MAX_RAWSZ - GIT_SHA1_RAWSZ); 102 + oid->algo = GIT_HASH_SHA1; 103 + } 104 + 105 + static void git_hash_sha256_init(struct git_hash_ctx *ctx) 106 + { 107 + ctx->algop = unsafe_hash_algo(&hash_algos[GIT_HASH_SHA256]); 108 + git_SHA256_Init(&ctx->state.sha256); 109 + } 110 + 111 + static void git_hash_sha256_clone(struct git_hash_ctx *dst, const struct git_hash_ctx *src) 112 + { 113 + dst->algop = src->algop; 114 + git_SHA256_Clone(&dst->state.sha256, &src->state.sha256); 115 + } 116 + 117 + static void git_hash_sha256_update(struct git_hash_ctx *ctx, const void *data, size_t len) 118 + { 119 + git_SHA256_Update(&ctx->state.sha256, data, len); 120 + } 121 + 122 + static void git_hash_sha256_final(unsigned char *hash, struct git_hash_ctx *ctx) 123 + { 124 + git_SHA256_Final(hash, &ctx->state.sha256); 125 + } 126 + 127 + static void git_hash_sha256_final_oid(struct object_id *oid, struct git_hash_ctx *ctx) 128 + { 129 + git_SHA256_Final(oid->hash, &ctx->state.sha256); 130 + /* 131 + * This currently does nothing, so the compiler should optimize it out, 132 + * but keep it in case we extend the hash size again. 133 + */ 134 + memset(oid->hash + GIT_SHA256_RAWSZ, 0, GIT_MAX_RAWSZ - GIT_SHA256_RAWSZ); 135 + oid->algo = GIT_HASH_SHA256; 136 + } 137 + 138 + static void git_hash_unknown_init(struct git_hash_ctx *ctx UNUSED) 139 + { 140 + BUG("trying to init unknown hash"); 141 + } 142 + 143 + static void git_hash_unknown_clone(struct git_hash_ctx *dst UNUSED, 144 + const struct git_hash_ctx *src UNUSED) 145 + { 146 + BUG("trying to clone unknown hash"); 147 + } 148 + 149 + static void git_hash_unknown_update(struct git_hash_ctx *ctx UNUSED, 150 + const void *data UNUSED, 151 + size_t len UNUSED) 152 + { 153 + BUG("trying to update unknown hash"); 154 + } 155 + 156 + static void git_hash_unknown_final(unsigned char *hash UNUSED, 157 + struct git_hash_ctx *ctx UNUSED) 158 + { 159 + BUG("trying to finalize unknown hash"); 160 + } 161 + 162 + static void git_hash_unknown_final_oid(struct object_id *oid UNUSED, 163 + struct git_hash_ctx *ctx UNUSED) 164 + { 165 + BUG("trying to finalize unknown hash"); 166 + } 167 + 168 + static const struct git_hash_algo sha1_unsafe_algo = { 169 + .name = "sha1", 170 + .format_id = GIT_SHA1_FORMAT_ID, 171 + .rawsz = GIT_SHA1_RAWSZ, 172 + .hexsz = GIT_SHA1_HEXSZ, 173 + .blksz = GIT_SHA1_BLKSZ, 174 + .init_fn = git_hash_sha1_init_unsafe, 175 + .clone_fn = git_hash_sha1_clone_unsafe, 176 + .update_fn = git_hash_sha1_update_unsafe, 177 + .final_fn = git_hash_sha1_final_unsafe, 178 + .final_oid_fn = git_hash_sha1_final_oid_unsafe, 179 + .empty_tree = &empty_tree_oid, 180 + .empty_blob = &empty_blob_oid, 181 + .null_oid = &null_oid_sha1, 182 + }; 183 + 184 + const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = { 185 + { 186 + .name = NULL, 187 + .format_id = 0x00000000, 188 + .rawsz = 0, 189 + .hexsz = 0, 190 + .blksz = 0, 191 + .init_fn = git_hash_unknown_init, 192 + .clone_fn = git_hash_unknown_clone, 193 + .update_fn = git_hash_unknown_update, 194 + .final_fn = git_hash_unknown_final, 195 + .final_oid_fn = git_hash_unknown_final_oid, 196 + .empty_tree = NULL, 197 + .empty_blob = NULL, 198 + .null_oid = NULL, 199 + }, 200 + { 201 + .name = "sha1", 202 + .format_id = GIT_SHA1_FORMAT_ID, 203 + .rawsz = GIT_SHA1_RAWSZ, 204 + .hexsz = GIT_SHA1_HEXSZ, 205 + .blksz = GIT_SHA1_BLKSZ, 206 + .init_fn = git_hash_sha1_init, 207 + .clone_fn = git_hash_sha1_clone, 208 + .update_fn = git_hash_sha1_update, 209 + .final_fn = git_hash_sha1_final, 210 + .final_oid_fn = git_hash_sha1_final_oid, 211 + .unsafe = &sha1_unsafe_algo, 212 + .empty_tree = &empty_tree_oid, 213 + .empty_blob = &empty_blob_oid, 214 + .null_oid = &null_oid_sha1, 215 + }, 216 + { 217 + .name = "sha256", 218 + .format_id = GIT_SHA256_FORMAT_ID, 219 + .rawsz = GIT_SHA256_RAWSZ, 220 + .hexsz = GIT_SHA256_HEXSZ, 221 + .blksz = GIT_SHA256_BLKSZ, 222 + .init_fn = git_hash_sha256_init, 223 + .clone_fn = git_hash_sha256_clone, 224 + .update_fn = git_hash_sha256_update, 225 + .final_fn = git_hash_sha256_final, 226 + .final_oid_fn = git_hash_sha256_final_oid, 227 + .empty_tree = &empty_tree_oid_sha256, 228 + .empty_blob = &empty_blob_oid_sha256, 229 + .null_oid = &null_oid_sha256, 230 + } 231 + }; 232 + 233 + const struct object_id *null_oid(const struct git_hash_algo *algop) 234 + { 235 + return algop->null_oid; 236 + } 237 + 238 + const char *empty_tree_oid_hex(const struct git_hash_algo *algop) 239 + { 240 + static char buf[GIT_MAX_HEXSZ + 1]; 241 + return oid_to_hex_r(buf, algop->empty_tree); 242 + } 243 + 244 + int hash_algo_by_name(const char *name) 245 + { 246 + if (!name) 247 + return GIT_HASH_UNKNOWN; 248 + for (size_t i = 1; i < GIT_HASH_NALGOS; i++) 249 + if (!strcmp(name, hash_algos[i].name)) 250 + return i; 251 + return GIT_HASH_UNKNOWN; 252 + } 253 + 254 + int hash_algo_by_id(uint32_t format_id) 255 + { 256 + for (size_t i = 1; i < GIT_HASH_NALGOS; i++) 257 + if (format_id == hash_algos[i].format_id) 258 + return i; 259 + return GIT_HASH_UNKNOWN; 260 + } 261 + 262 + int hash_algo_by_length(size_t len) 263 + { 264 + for (size_t i = 1; i < GIT_HASH_NALGOS; i++) 265 + if (len == hash_algos[i].rawsz) 266 + return i; 267 + return GIT_HASH_UNKNOWN; 268 + } 269 + 270 + const struct git_hash_algo *unsafe_hash_algo(const struct git_hash_algo *algop) 271 + { 272 + /* If we have a faster "unsafe" implementation, use that. */ 273 + if (algop->unsafe) 274 + return algop->unsafe; 275 + /* Otherwise use the default one. */ 276 + return algop; 277 + }
+2 -2
hash.h
··· 326 326 /* Identical, except based on the format ID. */ 327 327 int hash_algo_by_id(uint32_t format_id); 328 328 /* Identical, except based on the length. */ 329 - int hash_algo_by_length(int len); 329 + int hash_algo_by_length(size_t len); 330 330 /* Identical, except for a pointer to struct git_hash_algo. */ 331 331 static inline int hash_algo_by_ptr(const struct git_hash_algo *p) 332 332 { ··· 341 341 342 342 const struct git_hash_algo *unsafe_hash_algo(const struct git_hash_algo *algop); 343 343 344 - const struct object_id *null_oid(void); 344 + const struct object_id *null_oid(const struct git_hash_algo *algop); 345 345 346 346 static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop) 347 347 {
+1 -1
log-tree.c
··· 499 499 { 500 500 struct strbuf headers = STRBUF_INIT; 501 501 const char *name = oid_to_hex(opt->zero_commit ? 502 - null_oid() : &commit->object.oid); 502 + null_oid(the_hash_algo) : &commit->object.oid); 503 503 504 504 *need_8bit_cte_p = 0; /* unknown */ 505 505
+13 -13
merge-ort.c
··· 1817 1817 BUG("submodule deleted on one side; this should be handled outside of merge_submodule()"); 1818 1818 1819 1819 if ((sub_not_initialized = repo_submodule_init(&subrepo, 1820 - opt->repo, path, null_oid()))) { 1820 + opt->repo, path, null_oid(the_hash_algo)))) { 1821 1821 path_msg(opt, CONFLICT_SUBMODULE_NOT_INITIALIZED, 0, 1822 1822 path, NULL, NULL, NULL, 1823 1823 _("Failed to merge submodule %s (not checked out)"), ··· 2199 2199 two_way = ((S_IFMT & o->mode) != (S_IFMT & a->mode)); 2200 2200 2201 2201 merge_status = merge_3way(opt, path, 2202 - two_way ? null_oid() : &o->oid, 2202 + two_way ? null_oid(the_hash_algo) : &o->oid, 2203 2203 &a->oid, &b->oid, 2204 2204 pathnames, extra_marker_size, 2205 2205 &result_buf); ··· 2231 2231 } else if (S_ISGITLINK(a->mode)) { 2232 2232 int two_way = ((S_IFMT & o->mode) != (S_IFMT & a->mode)); 2233 2233 clean = merge_submodule(opt, pathnames[0], 2234 - two_way ? null_oid() : &o->oid, 2234 + two_way ? null_oid(the_hash_algo) : &o->oid, 2235 2235 &a->oid, &b->oid, &result->oid); 2236 2236 if (clean < 0) 2237 2237 return -1; ··· 2739 2739 assert(!new_ci->match_mask); 2740 2740 new_ci->dirmask = 0; 2741 2741 new_ci->stages[1].mode = 0; 2742 - oidcpy(&new_ci->stages[1].oid, null_oid()); 2742 + oidcpy(&new_ci->stages[1].oid, null_oid(the_hash_algo)); 2743 2743 2744 2744 /* 2745 2745 * Now that we have the file information in new_ci, make sure ··· 2752 2752 continue; 2753 2753 /* zero out any entries related to files */ 2754 2754 ci->stages[i].mode = 0; 2755 - oidcpy(&ci->stages[i].oid, null_oid()); 2755 + oidcpy(&ci->stages[i].oid, null_oid(the_hash_algo)); 2756 2756 } 2757 2757 2758 2758 /* Now we want to focus on new_ci, so reassign ci to it. */ ··· 3123 3123 if (type_changed) { 3124 3124 /* rename vs. typechange */ 3125 3125 /* Mark the original as resolved by removal */ 3126 - memcpy(&oldinfo->stages[0].oid, null_oid(), 3126 + memcpy(&oldinfo->stages[0].oid, null_oid(the_hash_algo), 3127 3127 sizeof(oldinfo->stages[0].oid)); 3128 3128 oldinfo->stages[0].mode = 0; 3129 3129 oldinfo->filemask &= 0x06; ··· 4006 4006 if (ci->filemask & (1 << i)) 4007 4007 continue; 4008 4008 ci->stages[i].mode = 0; 4009 - oidcpy(&ci->stages[i].oid, null_oid()); 4009 + oidcpy(&ci->stages[i].oid, null_oid(the_hash_algo)); 4010 4010 } 4011 4011 } else if (ci->df_conflict && ci->merged.result.mode != 0) { 4012 4012 /* ··· 4053 4053 continue; 4054 4054 /* zero out any entries related to directories */ 4055 4055 new_ci->stages[i].mode = 0; 4056 - oidcpy(&new_ci->stages[i].oid, null_oid()); 4056 + oidcpy(&new_ci->stages[i].oid, null_oid(the_hash_algo)); 4057 4057 } 4058 4058 4059 4059 /* ··· 4175 4175 new_ci->merged.result.mode = ci->stages[2].mode; 4176 4176 oidcpy(&new_ci->merged.result.oid, &ci->stages[2].oid); 4177 4177 new_ci->stages[1].mode = 0; 4178 - oidcpy(&new_ci->stages[1].oid, null_oid()); 4178 + oidcpy(&new_ci->stages[1].oid, null_oid(the_hash_algo)); 4179 4179 new_ci->filemask = 5; 4180 4180 if ((S_IFMT & b_mode) != (S_IFMT & o_mode)) { 4181 4181 new_ci->stages[0].mode = 0; 4182 - oidcpy(&new_ci->stages[0].oid, null_oid()); 4182 + oidcpy(&new_ci->stages[0].oid, null_oid(the_hash_algo)); 4183 4183 new_ci->filemask = 4; 4184 4184 } 4185 4185 ··· 4187 4187 ci->merged.result.mode = ci->stages[1].mode; 4188 4188 oidcpy(&ci->merged.result.oid, &ci->stages[1].oid); 4189 4189 ci->stages[2].mode = 0; 4190 - oidcpy(&ci->stages[2].oid, null_oid()); 4190 + oidcpy(&ci->stages[2].oid, null_oid(the_hash_algo)); 4191 4191 ci->filemask = 3; 4192 4192 if ((S_IFMT & a_mode) != (S_IFMT & o_mode)) { 4193 4193 ci->stages[0].mode = 0; 4194 - oidcpy(&ci->stages[0].oid, null_oid()); 4194 + oidcpy(&ci->stages[0].oid, null_oid(the_hash_algo)); 4195 4195 ci->filemask = 2; 4196 4196 } 4197 4197 ··· 4316 4316 /* Deleted on both sides */ 4317 4317 ci->merged.is_null = 1; 4318 4318 ci->merged.result.mode = 0; 4319 - oidcpy(&ci->merged.result.oid, null_oid()); 4319 + oidcpy(&ci->merged.result.oid, null_oid(the_hash_algo)); 4320 4320 assert(!ci->df_conflict); 4321 4321 ci->merged.clean = !ci->path_conflict; 4322 4322 }
+6 -6
merge-recursive.c
··· 502 502 503 503 ret = get_tree_entry(r, tree, path, &dfs->oid, &dfs->mode); 504 504 if (S_ISDIR(dfs->mode)) { 505 - oidcpy(&dfs->oid, null_oid()); 505 + oidcpy(&dfs->oid, null_oid(the_hash_algo)); 506 506 dfs->mode = 0; 507 507 } 508 508 return ret; ··· 1238 1238 if (is_null_oid(b)) 1239 1239 return 0; 1240 1240 1241 - if (repo_submodule_init(&subrepo, opt->repo, path, null_oid())) { 1241 + if (repo_submodule_init(&subrepo, opt->repo, path, null_oid(the_hash_algo))) { 1242 1242 output(opt, 1, _("Failed to merge submodule %s (not checked out)"), path); 1243 1243 return 0; 1244 1244 } ··· 1698 1698 1699 1699 /* Store things in diff_filespecs for functions that need it */ 1700 1700 null.path = (char *)collide_path; 1701 - oidcpy(&null.oid, null_oid()); 1701 + oidcpy(&null.oid, null_oid(the_hash_algo)); 1702 1702 null.mode = 0; 1703 1703 1704 1704 if (merge_mode_and_contents(opt, &null, a, b, collide_path, ··· 2897 2897 dst_other.mode = ren1->dst_entry->stages[other_stage].mode; 2898 2898 try_merge = 0; 2899 2899 2900 - if (oideq(&src_other.oid, null_oid()) && 2900 + if (oideq(&src_other.oid, null_oid(the_hash_algo)) && 2901 2901 ren1->dir_rename_original_type == 'A') { 2902 2902 setup_rename_conflict_info(RENAME_VIA_DIR, 2903 2903 opt, ren1, NULL); 2904 2904 } else if (renamed_to_self) { 2905 2905 setup_rename_conflict_info(RENAME_NORMAL, 2906 2906 opt, ren1, NULL); 2907 - } else if (oideq(&src_other.oid, null_oid())) { 2907 + } else if (oideq(&src_other.oid, null_oid(the_hash_algo))) { 2908 2908 setup_rename_conflict_info(RENAME_DELETE, 2909 2909 opt, ren1, NULL); 2910 2910 } else if ((dst_other.mode == ren1->pair->two->mode) && ··· 2923 2923 1, /* update_cache */ 2924 2924 0 /* update_wd */)) 2925 2925 clean_merge = -1; 2926 - } else if (!oideq(&dst_other.oid, null_oid())) { 2926 + } else if (!oideq(&dst_other.oid, null_oid(the_hash_algo))) { 2927 2927 /* 2928 2928 * Probably not a clean merge, but it's 2929 2929 * premature to set clean_merge to 0 here,
+1
meson.build
··· 311 311 'graph.c', 312 312 'grep.c', 313 313 'hash-lookup.c', 314 + 'hash.c', 314 315 'hashmap.c', 315 316 'help.c', 316 317 'hex.c',
+7 -5
midx-write.c
··· 658 658 strbuf_addf(&buf, "%s-%s.rev", midx_name, hash_to_hex_algop(midx_hash, 659 659 ctx->repo->hash_algo)); 660 660 661 - tmp_file = write_rev_file_order(ctx->repo->hash_algo, NULL, ctx->pack_order, 661 + tmp_file = write_rev_file_order(ctx->repo, NULL, ctx->pack_order, 662 662 ctx->entries_nr, midx_hash, WRITE_REV); 663 663 664 664 if (finalize_object_file(tmp_file, buf.buf)) ··· 708 708 if (!peel_iterated_oid(revs->repo, oid, &peeled)) 709 709 oid = &peeled; 710 710 711 - object = parse_object_or_die(oid, refname); 711 + object = parse_object_or_die(revs->repo, oid, refname); 712 712 if (object->type != OBJ_COMMIT) 713 713 return 0; 714 714 ··· 768 768 if (*end) 769 769 die(_("malformed line: %s"), buf.buf); 770 770 771 - object = parse_object_or_die(&oid, NULL); 771 + object = parse_object_or_die(revs->repo, &oid, NULL); 772 772 if (preferred) 773 773 object->flags |= NEEDS_BITMAP; 774 774 ··· 1342 1342 return -1; 1343 1343 } 1344 1344 1345 - f = hashfd(get_tempfile_fd(incr), get_tempfile_path(incr)); 1345 + f = hashfd(r->hash_algo, get_tempfile_fd(incr), 1346 + get_tempfile_path(incr)); 1346 1347 } else { 1347 1348 hold_lock_file_for_update(&lk, midx_name.buf, LOCK_DIE_ON_ERROR); 1348 - f = hashfd(get_lock_file_fd(&lk), get_lock_file_path(&lk)); 1349 + f = hashfd(r->hash_algo, get_lock_file_fd(&lk), 1350 + get_lock_file_path(&lk)); 1349 1351 } 1350 1352 1351 1353 cf = init_chunkfile(f);
+2 -1
midx.c
··· 747 747 748 748 int midx_checksum_valid(struct multi_pack_index *m) 749 749 { 750 - return hashfile_checksum_valid(m->data, m->data_len); 750 + return hashfile_checksum_valid(m->repo->hash_algo, 751 + m->data, m->data_len); 751 752 } 752 753 753 754 struct clear_midx_data {
+1 -1
notes-merge.c
··· 617 617 if (repo_get_merge_bases(the_repository, local, remote, &bases) < 0) 618 618 exit(128); 619 619 if (!bases) { 620 - base_oid = null_oid(); 620 + base_oid = null_oid(the_hash_algo); 621 621 base_tree_oid = the_hash_algo->empty_tree; 622 622 if (o->verbosity >= 4) 623 623 printf("No merge base found; doing history-less merge\n");
+1 -1
notes.c
··· 1353 1353 if (note) 1354 1354 return add_note(t, to_obj, note, combine_notes); 1355 1355 else if (existing_note) 1356 - return add_note(t, to_obj, null_oid(), combine_notes); 1356 + return add_note(t, to_obj, null_oid(the_hash_algo), combine_notes); 1357 1357 1358 1358 return 0; 1359 1359 }
+16 -13
object-file-convert.c
··· 1 - #define USE_THE_REPOSITORY_VARIABLE 2 1 #define DISABLE_SIGN_COMPARE_WARNINGS 3 2 4 3 #include "git-compat-util.h" ··· 63 62 return 0; 64 63 } 65 64 66 - static int convert_tree_object(struct strbuf *out, 65 + static int convert_tree_object(struct repository *repo, 66 + struct strbuf *out, 67 67 const struct git_hash_algo *from, 68 68 const struct git_hash_algo *to, 69 69 const char *buffer, size_t size) ··· 78 78 if (decode_tree_entry_raw(&entry_oid, &path, &pathlen, from, p, 79 79 end - p)) 80 80 return error(_("failed to decode tree entry")); 81 - if (repo_oid_to_algop(the_repository, &entry_oid, to, &mapped_oid)) 81 + if (repo_oid_to_algop(repo, &entry_oid, to, &mapped_oid)) 82 82 return error(_("failed to map tree entry for %s"), oid_to_hex(&entry_oid)); 83 83 strbuf_add(out, p, path - p); 84 84 strbuf_add(out, path, pathlen); ··· 88 88 return 0; 89 89 } 90 90 91 - static int convert_tag_object(struct strbuf *out, 91 + static int convert_tag_object(struct repository *repo, 92 + struct strbuf *out, 92 93 const struct git_hash_algo *from, 93 94 const struct git_hash_algo *to, 94 95 const char *buffer, size_t size) ··· 105 106 return error("bogus tag object"); 106 107 if (parse_oid_hex_algop(buffer + 7, &oid, &p, from) < 0) 107 108 return error("bad tag object ID"); 108 - if (repo_oid_to_algop(the_repository, &oid, to, &mapped_oid)) 109 + if (repo_oid_to_algop(repo, &oid, to, &mapped_oid)) 109 110 return error("unable to map tree %s in tag object", 110 111 oid_to_hex(&oid)); 111 112 size -= ((p + 1) - buffer); ··· 139 140 return 0; 140 141 } 141 142 142 - static int convert_commit_object(struct strbuf *out, 143 + static int convert_commit_object(struct repository *repo, 144 + struct strbuf *out, 143 145 const struct git_hash_algo *from, 144 146 const struct git_hash_algo *to, 145 147 const char *buffer, size_t size) ··· 165 167 (p != eol)) 166 168 return error(_("bad %s in commit"), "tree"); 167 169 168 - if (repo_oid_to_algop(the_repository, &oid, to, &mapped_oid)) 170 + if (repo_oid_to_algop(repo, &oid, to, &mapped_oid)) 169 171 return error(_("unable to map %s %s in commit object"), 170 172 "tree", oid_to_hex(&oid)); 171 173 strbuf_addf(out, "tree %s\n", oid_to_hex(&mapped_oid)); ··· 177 179 (p != eol)) 178 180 return error(_("bad %s in commit"), "parent"); 179 181 180 - if (repo_oid_to_algop(the_repository, &oid, to, &mapped_oid)) 182 + if (repo_oid_to_algop(repo, &oid, to, &mapped_oid)) 181 183 return error(_("unable to map %s %s in commit object"), 182 184 "parent", oid_to_hex(&oid)); 183 185 ··· 202 204 } 203 205 204 206 /* Compute the new tag object */ 205 - if (convert_tag_object(&new_tag, from, to, tag.buf, tag.len)) { 207 + if (convert_tag_object(repo, &new_tag, from, to, tag.buf, tag.len)) { 206 208 strbuf_release(&tag); 207 209 strbuf_release(&new_tag); 208 210 return -1; ··· 241 243 return 0; 242 244 } 243 245 244 - int convert_object_file(struct strbuf *outbuf, 246 + int convert_object_file(struct repository *repo, 247 + struct strbuf *outbuf, 245 248 const struct git_hash_algo *from, 246 249 const struct git_hash_algo *to, 247 250 const void *buf, size_t len, ··· 256 259 257 260 switch (type) { 258 261 case OBJ_COMMIT: 259 - ret = convert_commit_object(outbuf, from, to, buf, len); 262 + ret = convert_commit_object(repo, outbuf, from, to, buf, len); 260 263 break; 261 264 case OBJ_TREE: 262 - ret = convert_tree_object(outbuf, from, to, buf, len); 265 + ret = convert_tree_object(repo, outbuf, from, to, buf, len); 263 266 break; 264 267 case OBJ_TAG: 265 - ret = convert_tag_object(outbuf, from, to, buf, len); 268 + ret = convert_tag_object(repo, outbuf, from, to, buf, len); 266 269 break; 267 270 default: 268 271 /* Not implemented yet, so fail. */
+2 -1
object-file-convert.h
··· 14 14 * Convert an object file from one hash algorithm to another algorithm. 15 15 * Return -1 on failure, 0 on success. 16 16 */ 17 - int convert_object_file(struct strbuf *outbuf, 17 + int convert_object_file(struct repository *repo, 18 + struct strbuf *outbuf, 18 19 const struct git_hash_algo *from, 19 20 const struct git_hash_algo *to, 20 21 const void *buf, size_t len,
+9 -283
object-file.c
··· 45 45 /* The maximum size for an object header. */ 46 46 #define MAX_HEADER_LEN 32 47 47 48 - static const struct object_id empty_tree_oid = { 49 - .hash = { 50 - 0x4b, 0x82, 0x5d, 0xc6, 0x42, 0xcb, 0x6e, 0xb9, 0xa0, 0x60, 51 - 0xe5, 0x4b, 0xf8, 0xd6, 0x92, 0x88, 0xfb, 0xee, 0x49, 0x04 52 - }, 53 - .algo = GIT_HASH_SHA1, 54 - }; 55 - static const struct object_id empty_blob_oid = { 56 - .hash = { 57 - 0xe6, 0x9d, 0xe2, 0x9b, 0xb2, 0xd1, 0xd6, 0x43, 0x4b, 0x8b, 58 - 0x29, 0xae, 0x77, 0x5a, 0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91 59 - }, 60 - .algo = GIT_HASH_SHA1, 61 - }; 62 - static const struct object_id null_oid_sha1 = { 63 - .hash = {0}, 64 - .algo = GIT_HASH_SHA1, 65 - }; 66 - static const struct object_id empty_tree_oid_sha256 = { 67 - .hash = { 68 - 0x6e, 0xf1, 0x9b, 0x41, 0x22, 0x5c, 0x53, 0x69, 0xf1, 0xc1, 69 - 0x04, 0xd4, 0x5d, 0x8d, 0x85, 0xef, 0xa9, 0xb0, 0x57, 0xb5, 70 - 0x3b, 0x14, 0xb4, 0xb9, 0xb9, 0x39, 0xdd, 0x74, 0xde, 0xcc, 71 - 0x53, 0x21 72 - }, 73 - .algo = GIT_HASH_SHA256, 74 - }; 75 - static const struct object_id empty_blob_oid_sha256 = { 76 - .hash = { 77 - 0x47, 0x3a, 0x0f, 0x4c, 0x3b, 0xe8, 0xa9, 0x36, 0x81, 0xa2, 78 - 0x67, 0xe3, 0xb1, 0xe9, 0xa7, 0xdc, 0xda, 0x11, 0x85, 0x43, 79 - 0x6f, 0xe1, 0x41, 0xf7, 0x74, 0x91, 0x20, 0xa3, 0x03, 0x72, 80 - 0x18, 0x13 81 - }, 82 - .algo = GIT_HASH_SHA256, 83 - }; 84 - static const struct object_id null_oid_sha256 = { 85 - .hash = {0}, 86 - .algo = GIT_HASH_SHA256, 87 - }; 88 - 89 - static void git_hash_sha1_init(struct git_hash_ctx *ctx) 90 - { 91 - ctx->algop = &hash_algos[GIT_HASH_SHA1]; 92 - git_SHA1_Init(&ctx->state.sha1); 93 - } 94 - 95 - static void git_hash_sha1_clone(struct git_hash_ctx *dst, const struct git_hash_ctx *src) 96 - { 97 - dst->algop = src->algop; 98 - git_SHA1_Clone(&dst->state.sha1, &src->state.sha1); 99 - } 100 - 101 - static void git_hash_sha1_update(struct git_hash_ctx *ctx, const void *data, size_t len) 102 - { 103 - git_SHA1_Update(&ctx->state.sha1, data, len); 104 - } 105 - 106 - static void git_hash_sha1_final(unsigned char *hash, struct git_hash_ctx *ctx) 107 - { 108 - git_SHA1_Final(hash, &ctx->state.sha1); 109 - } 110 - 111 - static void git_hash_sha1_final_oid(struct object_id *oid, struct git_hash_ctx *ctx) 112 - { 113 - git_SHA1_Final(oid->hash, &ctx->state.sha1); 114 - memset(oid->hash + GIT_SHA1_RAWSZ, 0, GIT_MAX_RAWSZ - GIT_SHA1_RAWSZ); 115 - oid->algo = GIT_HASH_SHA1; 116 - } 117 - 118 - static void git_hash_sha1_init_unsafe(struct git_hash_ctx *ctx) 119 - { 120 - ctx->algop = unsafe_hash_algo(&hash_algos[GIT_HASH_SHA1]); 121 - git_SHA1_Init_unsafe(&ctx->state.sha1_unsafe); 122 - } 123 - 124 - static void git_hash_sha1_clone_unsafe(struct git_hash_ctx *dst, const struct git_hash_ctx *src) 125 - { 126 - dst->algop = src->algop; 127 - git_SHA1_Clone_unsafe(&dst->state.sha1_unsafe, &src->state.sha1_unsafe); 128 - } 129 - 130 - static void git_hash_sha1_update_unsafe(struct git_hash_ctx *ctx, const void *data, 131 - size_t len) 132 - { 133 - git_SHA1_Update_unsafe(&ctx->state.sha1_unsafe, data, len); 134 - } 135 - 136 - static void git_hash_sha1_final_unsafe(unsigned char *hash, struct git_hash_ctx *ctx) 137 - { 138 - git_SHA1_Final_unsafe(hash, &ctx->state.sha1_unsafe); 139 - } 140 - 141 - static void git_hash_sha1_final_oid_unsafe(struct object_id *oid, struct git_hash_ctx *ctx) 142 - { 143 - git_SHA1_Final_unsafe(oid->hash, &ctx->state.sha1_unsafe); 144 - memset(oid->hash + GIT_SHA1_RAWSZ, 0, GIT_MAX_RAWSZ - GIT_SHA1_RAWSZ); 145 - oid->algo = GIT_HASH_SHA1; 146 - } 147 - 148 - static void git_hash_sha256_init(struct git_hash_ctx *ctx) 149 - { 150 - ctx->algop = unsafe_hash_algo(&hash_algos[GIT_HASH_SHA256]); 151 - git_SHA256_Init(&ctx->state.sha256); 152 - } 153 - 154 - static void git_hash_sha256_clone(struct git_hash_ctx *dst, const struct git_hash_ctx *src) 155 - { 156 - dst->algop = src->algop; 157 - git_SHA256_Clone(&dst->state.sha256, &src->state.sha256); 158 - } 159 - 160 - static void git_hash_sha256_update(struct git_hash_ctx *ctx, const void *data, size_t len) 161 - { 162 - git_SHA256_Update(&ctx->state.sha256, data, len); 163 - } 164 - 165 - static void git_hash_sha256_final(unsigned char *hash, struct git_hash_ctx *ctx) 166 - { 167 - git_SHA256_Final(hash, &ctx->state.sha256); 168 - } 169 - 170 - static void git_hash_sha256_final_oid(struct object_id *oid, struct git_hash_ctx *ctx) 171 - { 172 - git_SHA256_Final(oid->hash, &ctx->state.sha256); 173 - /* 174 - * This currently does nothing, so the compiler should optimize it out, 175 - * but keep it in case we extend the hash size again. 176 - */ 177 - memset(oid->hash + GIT_SHA256_RAWSZ, 0, GIT_MAX_RAWSZ - GIT_SHA256_RAWSZ); 178 - oid->algo = GIT_HASH_SHA256; 179 - } 180 - 181 - static void git_hash_unknown_init(struct git_hash_ctx *ctx UNUSED) 182 - { 183 - BUG("trying to init unknown hash"); 184 - } 185 - 186 - static void git_hash_unknown_clone(struct git_hash_ctx *dst UNUSED, 187 - const struct git_hash_ctx *src UNUSED) 188 - { 189 - BUG("trying to clone unknown hash"); 190 - } 191 - 192 - static void git_hash_unknown_update(struct git_hash_ctx *ctx UNUSED, 193 - const void *data UNUSED, 194 - size_t len UNUSED) 195 - { 196 - BUG("trying to update unknown hash"); 197 - } 198 - 199 - static void git_hash_unknown_final(unsigned char *hash UNUSED, 200 - struct git_hash_ctx *ctx UNUSED) 201 - { 202 - BUG("trying to finalize unknown hash"); 203 - } 204 - 205 - static void git_hash_unknown_final_oid(struct object_id *oid UNUSED, 206 - struct git_hash_ctx *ctx UNUSED) 207 - { 208 - BUG("trying to finalize unknown hash"); 209 - } 210 - 211 - static const struct git_hash_algo sha1_unsafe_algo = { 212 - .name = "sha1", 213 - .format_id = GIT_SHA1_FORMAT_ID, 214 - .rawsz = GIT_SHA1_RAWSZ, 215 - .hexsz = GIT_SHA1_HEXSZ, 216 - .blksz = GIT_SHA1_BLKSZ, 217 - .init_fn = git_hash_sha1_init_unsafe, 218 - .clone_fn = git_hash_sha1_clone_unsafe, 219 - .update_fn = git_hash_sha1_update_unsafe, 220 - .final_fn = git_hash_sha1_final_unsafe, 221 - .final_oid_fn = git_hash_sha1_final_oid_unsafe, 222 - .empty_tree = &empty_tree_oid, 223 - .empty_blob = &empty_blob_oid, 224 - .null_oid = &null_oid_sha1, 225 - }; 226 - 227 - const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = { 228 - { 229 - .name = NULL, 230 - .format_id = 0x00000000, 231 - .rawsz = 0, 232 - .hexsz = 0, 233 - .blksz = 0, 234 - .init_fn = git_hash_unknown_init, 235 - .clone_fn = git_hash_unknown_clone, 236 - .update_fn = git_hash_unknown_update, 237 - .final_fn = git_hash_unknown_final, 238 - .final_oid_fn = git_hash_unknown_final_oid, 239 - .empty_tree = NULL, 240 - .empty_blob = NULL, 241 - .null_oid = NULL, 242 - }, 243 - { 244 - .name = "sha1", 245 - .format_id = GIT_SHA1_FORMAT_ID, 246 - .rawsz = GIT_SHA1_RAWSZ, 247 - .hexsz = GIT_SHA1_HEXSZ, 248 - .blksz = GIT_SHA1_BLKSZ, 249 - .init_fn = git_hash_sha1_init, 250 - .clone_fn = git_hash_sha1_clone, 251 - .update_fn = git_hash_sha1_update, 252 - .final_fn = git_hash_sha1_final, 253 - .final_oid_fn = git_hash_sha1_final_oid, 254 - .unsafe = &sha1_unsafe_algo, 255 - .empty_tree = &empty_tree_oid, 256 - .empty_blob = &empty_blob_oid, 257 - .null_oid = &null_oid_sha1, 258 - }, 259 - { 260 - .name = "sha256", 261 - .format_id = GIT_SHA256_FORMAT_ID, 262 - .rawsz = GIT_SHA256_RAWSZ, 263 - .hexsz = GIT_SHA256_HEXSZ, 264 - .blksz = GIT_SHA256_BLKSZ, 265 - .init_fn = git_hash_sha256_init, 266 - .clone_fn = git_hash_sha256_clone, 267 - .update_fn = git_hash_sha256_update, 268 - .final_fn = git_hash_sha256_final, 269 - .final_oid_fn = git_hash_sha256_final_oid, 270 - .empty_tree = &empty_tree_oid_sha256, 271 - .empty_blob = &empty_blob_oid_sha256, 272 - .null_oid = &null_oid_sha256, 273 - } 274 - }; 275 - 276 - const struct object_id *null_oid(void) 277 - { 278 - return the_hash_algo->null_oid; 279 - } 280 - 281 - const char *empty_tree_oid_hex(const struct git_hash_algo *algop) 282 - { 283 - static char buf[GIT_MAX_HEXSZ + 1]; 284 - return oid_to_hex_r(buf, algop->empty_tree); 285 - } 286 - 287 - int hash_algo_by_name(const char *name) 288 - { 289 - int i; 290 - if (!name) 291 - return GIT_HASH_UNKNOWN; 292 - for (i = 1; i < GIT_HASH_NALGOS; i++) 293 - if (!strcmp(name, hash_algos[i].name)) 294 - return i; 295 - return GIT_HASH_UNKNOWN; 296 - } 297 - 298 - int hash_algo_by_id(uint32_t format_id) 299 - { 300 - int i; 301 - for (i = 1; i < GIT_HASH_NALGOS; i++) 302 - if (format_id == hash_algos[i].format_id) 303 - return i; 304 - return GIT_HASH_UNKNOWN; 305 - } 306 - 307 - int hash_algo_by_length(int len) 308 - { 309 - int i; 310 - for (i = 1; i < GIT_HASH_NALGOS; i++) 311 - if (len == hash_algos[i].rawsz) 312 - return i; 313 - return GIT_HASH_UNKNOWN; 314 - } 315 - 316 - const struct git_hash_algo *unsafe_hash_algo(const struct git_hash_algo *algop) 317 - { 318 - /* If we have a faster "unsafe" implementation, use that. */ 319 - if (algop->unsafe) 320 - return algop->unsafe; 321 - /* Otherwise use the default one. */ 322 - return algop; 323 - } 324 - 325 48 /* 326 49 * This is meant to hold a *small* number of objects that you would 327 50 * want repo_read_object_file() to be able to return, but yet you do not want ··· 1793 1516 if (type == -1) 1794 1517 return -1; 1795 1518 if (type != OBJ_BLOB) { 1796 - ret = convert_object_file(&outbuf, 1519 + ret = convert_object_file(the_repository, &outbuf, 1797 1520 the_hash_algo, input_algo, 1798 1521 content, size, type, !do_die); 1799 1522 free(content); ··· 2510 2233 hash_object_file(compat, buf, len, type, &compat_oid); 2511 2234 else { 2512 2235 struct strbuf converted = STRBUF_INIT; 2513 - convert_object_file(&converted, algo, compat, 2236 + convert_object_file(the_repository, &converted, algo, compat, 2514 2237 buf, len, type, 0); 2515 2238 hash_object_file(compat, converted.buf, converted.len, 2516 2239 type, &compat_oid); ··· 2550 2273 &compat_oid); 2551 2274 else if (compat_type != -1) { 2552 2275 struct strbuf converted = STRBUF_INIT; 2553 - convert_object_file(&converted, algo, compat, 2276 + convert_object_file(the_repository, 2277 + &converted, algo, compat, 2554 2278 buf, len, compat_type, 0); 2555 2279 hash_object_file(compat, converted.buf, converted.len, 2556 2280 compat_type, &compat_oid); ··· 2681 2405 2682 2406 opts.strict = 1; 2683 2407 opts.error_func = hash_format_check_report; 2684 - if (fsck_buffer(null_oid(), type, buf, size, &opts)) 2408 + if (fsck_buffer(null_oid(the_hash_algo), type, buf, size, &opts)) 2685 2409 die(_("refusing to create malformed object")); 2686 2410 fsck_finish(&opts); 2687 2411 } ··· 2803 2527 ret = index_stream_convert_blob(istate, oid, fd, path, flags); 2804 2528 else if (!S_ISREG(st->st_mode)) 2805 2529 ret = index_pipe(istate, oid, fd, type, path, flags); 2806 - else if (st->st_size <= big_file_threshold || type != OBJ_BLOB || 2530 + else if (st->st_size <= repo_settings_get_big_file_threshold(the_repository) || 2531 + type != OBJ_BLOB || 2807 2532 (path && would_convert_to_git(istate, path))) 2808 2533 ret = index_core(istate, oid, fd, xsize_t(st->st_size), 2809 2534 type, path, flags); ··· 3137 2862 goto out; 3138 2863 } 3139 2864 3140 - if (*oi->typep == OBJ_BLOB && *size > big_file_threshold) { 2865 + if (*oi->typep == OBJ_BLOB && 2866 + *size > repo_settings_get_big_file_threshold(the_repository)) { 3141 2867 if (check_stream_oid(&stream, hdr, *size, path, expected_oid) < 0) 3142 2868 goto out; 3143 2869 } else {
+11 -10
object.c
··· 1 - #define USE_THE_REPOSITORY_VARIABLE 2 1 #define DISABLE_SIGN_COMPARE_WARNINGS 3 2 4 3 #include "git-compat-util.h" ··· 18 17 #include "commit-graph.h" 19 18 #include "loose.h" 20 19 21 - unsigned int get_max_object_index(void) 20 + unsigned int get_max_object_index(const struct repository *repo) 22 21 { 23 - return the_repository->parsed_objects->obj_hash_size; 22 + return repo->parsed_objects->obj_hash_size; 24 23 } 25 24 26 - struct object *get_indexed_object(unsigned int idx) 25 + struct object *get_indexed_object(const struct repository *repo, 26 + unsigned int idx) 27 27 { 28 - return the_repository->parsed_objects->obj_hash[idx]; 28 + return repo->parsed_objects->obj_hash[idx]; 29 29 } 30 30 31 31 static const char *object_type_strings[] = { ··· 283 283 return obj; 284 284 } 285 285 286 - struct object *parse_object_or_die(const struct object_id *oid, 286 + struct object *parse_object_or_die(struct repository *repo, 287 + const struct object_id *oid, 287 288 const char *name) 288 289 { 289 - struct object *o = parse_object(the_repository, oid); 290 + struct object *o = parse_object(repo, oid); 290 291 if (o) 291 292 return o; 292 293 ··· 524 525 } 525 526 } 526 527 527 - void clear_object_flags(unsigned flags) 528 + void clear_object_flags(struct repository *repo, unsigned flags) 528 529 { 529 530 int i; 530 531 531 - for (i=0; i < the_repository->parsed_objects->obj_hash_size; i++) { 532 - struct object *obj = the_repository->parsed_objects->obj_hash[i]; 532 + for (i=0; i < repo->parsed_objects->obj_hash_size; i++) { 533 + struct object *obj = repo->parsed_objects->obj_hash[i]; 533 534 if (obj) 534 535 obj->flags &= ~flags; 535 536 }
+6 -4
object.h
··· 169 169 /* 170 170 * Return the current number of buckets in the object hashmap. 171 171 */ 172 - unsigned int get_max_object_index(void); 172 + unsigned int get_max_object_index(const struct repository *repo); 173 173 174 174 /* 175 175 * Return the object from the specified bucket in the object hashmap. 176 176 */ 177 - struct object *get_indexed_object(unsigned int); 177 + struct object *get_indexed_object(const struct repository *repo, 178 + unsigned int); 178 179 179 180 /* 180 181 * This can be used to see if we have heard of the object before, but ··· 231 232 * "name" parameter is not NULL, it is included in the error message 232 233 * (otherwise, the hex object ID is given). 233 234 */ 234 - struct object *parse_object_or_die(const struct object_id *oid, const char *name); 235 + struct object *parse_object_or_die(struct repository *repo, const struct object_id *oid, 236 + const char *name); 235 237 236 238 /* Given the result of read_sha1_file(), returns the object after 237 239 * parsing it. eaten_p indicates if the object has a borrowed copy ··· 336 338 */ 337 339 void object_array_clear(struct object_array *array); 338 340 339 - void clear_object_flags(unsigned flags); 341 + void clear_object_flags(struct repository *repo, unsigned flags); 340 342 341 343 /* 342 344 * Clear the specified object flags from all in-core commit objects from
+18 -18
pack-bitmap-write.c
··· 1 - #define USE_THE_REPOSITORY_VARIABLE 2 1 #define DISABLE_SIGN_COMPARE_WARNINGS 3 2 4 3 #include "git-compat-util.h" ··· 48 47 memset(writer, 0, sizeof(struct bitmap_writer)); 49 48 if (writer->bitmaps) 50 49 BUG("bitmap writer already initialized"); 50 + writer->repo = r; 51 51 writer->bitmaps = kh_init_oid_map(); 52 52 writer->pseudo_merge_commits = kh_init_oid_map(); 53 53 writer->to_pack = pdata; ··· 415 415 bb->commits[bb->commits_nr++] = r->item; 416 416 } 417 417 418 - trace2_data_intmax("pack-bitmap-write", the_repository, 418 + trace2_data_intmax("pack-bitmap-write", writer->repo, 419 419 "num_selected_commits", writer->selected_nr); 420 - trace2_data_intmax("pack-bitmap-write", the_repository, 420 + trace2_data_intmax("pack-bitmap-write", writer->repo, 421 421 "num_maximal_commits", num_maximal); 422 422 423 423 release_revisions(&revs); ··· 460 460 switch (object_type(entry.mode)) { 461 461 case OBJ_TREE: 462 462 if (fill_bitmap_tree(writer, bitmap, 463 - lookup_tree(the_repository, &entry.oid)) < 0) 463 + lookup_tree(writer->repo, &entry.oid)) < 0) 464 464 return -1; 465 465 break; 466 466 case OBJ_BLOB: ··· 536 536 return -1; 537 537 bitmap_set(ent->bitmap, pos); 538 538 prio_queue_put(tree_queue, 539 - repo_get_commit_tree(the_repository, c)); 539 + repo_get_commit_tree(writer->repo, c)); 540 540 } 541 541 542 542 for (p = c->parents; p; p = p->next) { ··· 590 590 int closed = 1; /* until proven otherwise */ 591 591 592 592 if (writer->show_progress) 593 - writer->progress = start_progress(the_repository, 593 + writer->progress = start_progress(writer->repo, 594 594 "Building bitmaps", 595 595 writer->selected_nr); 596 596 trace2_region_enter("pack-bitmap-write", "building_bitmaps_total", 597 - the_repository); 597 + writer->repo); 598 598 599 599 old_bitmap = prepare_bitmap_git(writer->to_pack->repo); 600 600 if (old_bitmap) ··· 645 645 free(mapping); 646 646 647 647 trace2_region_leave("pack-bitmap-write", "building_bitmaps_total", 648 - the_repository); 649 - trace2_data_intmax("pack-bitmap-write", the_repository, 648 + writer->repo); 649 + trace2_data_intmax("pack-bitmap-write", writer->repo, 650 650 "building_bitmaps_reused", reused_bitmaps_nr); 651 - trace2_data_intmax("pack-bitmap-write", the_repository, 651 + trace2_data_intmax("pack-bitmap-write", writer->repo, 652 652 "building_bitmaps_pseudo_merge_reused", 653 653 reused_pseudo_merge_bitmaps_nr); 654 654 ··· 711 711 } 712 712 713 713 if (writer->show_progress) 714 - writer->progress = start_progress(the_repository, 714 + writer->progress = start_progress(writer->repo, 715 715 "Selecting bitmap commits", 0); 716 716 717 717 for (;;) { ··· 960 960 for (i = 0; i < bitmap_writer_nr_selected_commits(writer); i++) 961 961 table_inv[table[i]] = i; 962 962 963 - trace2_region_enter("pack-bitmap-write", "writing_lookup_table", the_repository); 963 + trace2_region_enter("pack-bitmap-write", "writing_lookup_table", writer->repo); 964 964 for (i = 0; i < bitmap_writer_nr_selected_commits(writer); i++) { 965 965 struct bitmapped_commit *selected = &writer->selected[table[i]]; 966 966 uint32_t xor_offset = selected->xor_offset; ··· 987 987 hashwrite_be64(f, (uint64_t)offsets[table[i]]); 988 988 hashwrite_be32(f, xor_row); 989 989 } 990 - trace2_region_leave("pack-bitmap-write", "writing_lookup_table", the_repository); 990 + trace2_region_leave("pack-bitmap-write", "writing_lookup_table", writer->repo); 991 991 992 992 free(table); 993 993 free(table_inv); ··· 1008 1008 void bitmap_writer_set_checksum(struct bitmap_writer *writer, 1009 1009 const unsigned char *sha1) 1010 1010 { 1011 - hashcpy(writer->pack_checksum, sha1, the_repository->hash_algo); 1011 + hashcpy(writer->pack_checksum, sha1, writer->repo->hash_algo); 1012 1012 } 1013 1013 1014 1014 void bitmap_writer_finish(struct bitmap_writer *writer, ··· 1030 1030 if (writer->pseudo_merges_nr) 1031 1031 options |= BITMAP_OPT_PSEUDO_MERGES; 1032 1032 1033 - f = hashfd(fd, tmp_file.buf); 1033 + f = hashfd(writer->repo->hash_algo, fd, tmp_file.buf); 1034 1034 1035 1035 memcpy(header.magic, BITMAP_IDX_SIGNATURE, sizeof(BITMAP_IDX_SIGNATURE)); 1036 1036 header.version = htons(default_version); 1037 1037 header.options = htons(flags | options); 1038 1038 header.entry_count = htonl(bitmap_writer_nr_selected_commits(writer)); 1039 - hashcpy(header.checksum, writer->pack_checksum, the_repository->hash_algo); 1039 + hashcpy(header.checksum, writer->pack_checksum, writer->repo->hash_algo); 1040 1040 1041 - hashwrite(f, &header, sizeof(header) - GIT_MAX_RAWSZ + the_hash_algo->rawsz); 1041 + hashwrite(f, &header, sizeof(header) - GIT_MAX_RAWSZ + writer->repo->hash_algo->rawsz); 1042 1042 dump_bitmap(f, writer->commits); 1043 1043 dump_bitmap(f, writer->trees); 1044 1044 dump_bitmap(f, writer->blobs); ··· 1072 1072 finalize_hashfile(f, NULL, FSYNC_COMPONENT_PACK_METADATA, 1073 1073 CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE); 1074 1074 1075 - if (adjust_shared_perm(the_repository, tmp_file.buf)) 1075 + if (adjust_shared_perm(writer->repo, tmp_file.buf)) 1076 1076 die_errno("unable to make temporary bitmap file readable"); 1077 1077 1078 1078 if (rename(tmp_file.buf, filename))
+8 -7
pack-bitmap.c
··· 1301 1301 revs->tag_objects = tmp_tags; 1302 1302 1303 1303 reset_revision_walk(); 1304 - clear_object_flags(UNINTERESTING); 1304 + clear_object_flags(repo, UNINTERESTING); 1305 1305 1306 1306 /* 1307 1307 * Then add the boundary commit(s) as fill-in traversal tips. ··· 1935 1935 struct object *object = revs->pending.objects[i].item; 1936 1936 1937 1937 if (object->type == OBJ_NONE) 1938 - parse_object_or_die(&object->oid, NULL); 1938 + parse_object_or_die(revs->repo, &object->oid, NULL); 1939 1939 1940 1940 while (object->type == OBJ_TAG) { 1941 1941 struct tag *tag = (struct tag *) object; ··· 1945 1945 else 1946 1946 object_list_insert(object, &wants); 1947 1947 1948 - object = parse_object_or_die(get_tagged_oid(tag), NULL); 1948 + object = parse_object_or_die(revs->repo, get_tagged_oid(tag), NULL); 1949 1949 object->flags |= (tag->object.flags & UNINTERESTING); 1950 1950 } 1951 1951 ··· 3024 3024 return 0; 3025 3025 } 3026 3026 3027 - static int verify_bitmap_file(const char *name) 3027 + static int verify_bitmap_file(const struct git_hash_algo *algop, 3028 + const char *name) 3028 3029 { 3029 3030 struct stat st; 3030 3031 unsigned char *data; ··· 3040 3041 3041 3042 data = xmmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); 3042 3043 close(fd); 3043 - if (!hashfile_checksum_valid(data, st.st_size)) 3044 + if (!hashfile_checksum_valid(algop, data, st.st_size)) 3044 3045 res = error(_("bitmap file '%s' has invalid checksum"), 3045 3046 name); 3046 3047 ··· 3055 3056 for (struct multi_pack_index *m = get_multi_pack_index(r); 3056 3057 m; m = m->next) { 3057 3058 char *midx_bitmap_name = midx_bitmap_filename(m); 3058 - res |= verify_bitmap_file(midx_bitmap_name); 3059 + res |= verify_bitmap_file(r->hash_algo, midx_bitmap_name); 3059 3060 free(midx_bitmap_name); 3060 3061 } 3061 3062 3062 3063 for (struct packed_git *p = get_all_packs(r); 3063 3064 p; p = p->next) { 3064 3065 char *pack_bitmap_name = pack_bitmap_filename(p); 3065 - res |= verify_bitmap_file(pack_bitmap_name); 3066 + res |= verify_bitmap_file(r->hash_algo, pack_bitmap_name); 3066 3067 free(pack_bitmap_name); 3067 3068 } 3068 3069
+1
pack-bitmap.h
··· 104 104 off_t get_disk_usage_from_bitmap(struct bitmap_index *, struct rev_info *); 105 105 106 106 struct bitmap_writer { 107 + struct repository *repo; 107 108 struct ewah_bitmap *commits; 108 109 struct ewah_bitmap *trees; 109 110 struct ewah_bitmap *blobs;
+6 -6
pack-check.c
··· 1 - #define USE_THE_REPOSITORY_VARIABLE 2 1 #define DISABLE_SIGN_COMPARE_WARNINGS 3 2 4 3 #include "git-compat-util.h" ··· 44 43 } while (len); 45 44 46 45 index_crc = p->index_data; 47 - index_crc += 2 + 256 + (size_t)p->num_objects * (the_hash_algo->rawsz/4) + nr; 46 + index_crc += 2 + 256 + (size_t)p->num_objects * (p->repo->hash_algo->rawsz/4) + nr; 48 47 49 48 return data_crc != ntohl(*index_crc); 50 49 } ··· 81 80 } while (offset < pack_sig_ofs); 82 81 git_hash_final(hash, &ctx); 83 82 pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL); 84 - if (!hasheq(hash, pack_sig, the_repository->hash_algo)) 83 + if (!hasheq(hash, pack_sig, r->hash_algo)) 85 84 err = error("%s pack checksum mismatch", 86 85 p->pack_name); 87 86 if (!hasheq(index_base + index_size - r->hash_algo->hexsz, pack_sig, 88 - the_repository->hash_algo)) 87 + r->hash_algo)) 89 88 err = error("%s pack checksum does not match its index", 90 89 p->pack_name); 91 90 unuse_pack(w_curs); ··· 131 130 type = unpack_object_header(p, w_curs, &curpos, &size); 132 131 unuse_pack(w_curs); 133 132 134 - if (type == OBJ_BLOB && big_file_threshold <= size) { 133 + if (type == OBJ_BLOB && 134 + repo_settings_get_big_file_threshold(r) <= size) { 135 135 /* 136 136 * Let stream_object_signature() check it with 137 137 * the streaming interface; no point slurping ··· 180 180 return error("packfile %s index not opened", p->pack_name); 181 181 182 182 /* Verify SHA1 sum of the index file */ 183 - if (!hashfile_checksum_valid(p->index_data, p->index_size)) 183 + if (!hashfile_checksum_valid(p->repo->hash_algo, p->index_data, p->index_size)) 184 184 err = error("Packfile index for %s hash mismatch", 185 185 p->pack_name); 186 186 return err;
+21 -14
pack-revindex.c
··· 1 - #define USE_THE_REPOSITORY_VARIABLE 2 - 3 1 #include "git-compat-util.h" 4 2 #include "gettext.h" 5 3 #include "pack-revindex.h" ··· 9 7 #include "strbuf.h" 10 8 #include "trace2.h" 11 9 #include "parse.h" 10 + #include "repository.h" 12 11 #include "midx.h" 13 12 #include "csum-file.h" 14 13 ··· 137 136 const unsigned num_ent = p->num_objects; 138 137 unsigned i; 139 138 const char *index = p->index_data; 140 - const unsigned hashsz = the_hash_algo->rawsz; 139 + const unsigned hashsz = p->repo->hash_algo->rawsz; 141 140 142 141 ALLOC_ARRAY(p->revindex, num_ent + 1); 143 142 index += 4 * 256; ··· 193 192 } 194 193 195 194 #define RIDX_HEADER_SIZE (12) 196 - #define RIDX_MIN_SIZE (RIDX_HEADER_SIZE + (2 * the_hash_algo->rawsz)) 195 + 196 + static size_t ridx_min_size(const struct git_hash_algo *algo) 197 + { 198 + return RIDX_HEADER_SIZE + (2 * algo->rawsz); 199 + } 197 200 198 201 struct revindex_header { 199 202 uint32_t signature; ··· 201 204 uint32_t hash_id; 202 205 }; 203 206 204 - static int load_revindex_from_disk(char *revindex_name, 207 + static int load_revindex_from_disk(const struct git_hash_algo *algo, 208 + char *revindex_name, 205 209 uint32_t num_objects, 206 210 const uint32_t **data_p, size_t *len_p) 207 211 { ··· 228 232 229 233 revindex_size = xsize_t(st.st_size); 230 234 231 - if (revindex_size < RIDX_MIN_SIZE) { 235 + if (revindex_size < ridx_min_size(algo)) { 232 236 ret = error(_("reverse-index file %s is too small"), revindex_name); 233 237 goto cleanup; 234 238 } 235 239 236 - if (revindex_size - RIDX_MIN_SIZE != st_mult(sizeof(uint32_t), num_objects)) { 240 + if (revindex_size - ridx_min_size(algo) != st_mult(sizeof(uint32_t), num_objects)) { 237 241 ret = error(_("reverse-index file %s is corrupt"), revindex_name); 238 242 goto cleanup; 239 243 } ··· 279 283 280 284 revindex_name = pack_revindex_filename(p); 281 285 282 - ret = load_revindex_from_disk(revindex_name, 286 + ret = load_revindex_from_disk(p->repo->hash_algo, 287 + revindex_name, 283 288 p->num_objects, 284 289 &p->revindex_map, 285 290 &p->revindex_size); ··· 322 327 if (!p->revindex_map || !p->revindex_data) 323 328 return res; 324 329 325 - if (!hashfile_checksum_valid((const unsigned char *)p->revindex_map, p->revindex_size)) { 330 + if (!hashfile_checksum_valid(p->repo->hash_algo, 331 + (const unsigned char *)p->revindex_map, p->revindex_size)) { 326 332 error(_("invalid checksum")); 327 333 res = -1; 328 334 } ··· 374 380 * not want to accidentally call munmap() in the middle of the 375 381 * MIDX. 376 382 */ 377 - trace2_data_string("load_midx_revindex", the_repository, 383 + trace2_data_string("load_midx_revindex", m->repo, 378 384 "source", "midx"); 379 385 m->revindex_data = (const uint32_t *)m->chunk_revindex; 380 386 return 0; 381 387 } 382 388 383 - trace2_data_string("load_midx_revindex", the_repository, 389 + trace2_data_string("load_midx_revindex", m->repo, 384 390 "source", "rev"); 385 391 386 392 get_midx_filename_ext(m->repo->hash_algo, &revindex_name, m->object_dir, 387 393 get_midx_checksum(m), MIDX_EXT_REV); 388 394 389 - ret = load_revindex_from_disk(revindex_name.buf, 395 + ret = load_revindex_from_disk(m->repo->hash_algo, 396 + revindex_name.buf, 390 397 m->num_objects, 391 398 &m->revindex_map, 392 399 &m->revindex_len); ··· 418 425 { 419 426 unsigned lo, hi; 420 427 421 - if (load_pack_revindex(the_repository, p) < 0) 428 + if (load_pack_revindex(p->repo, p) < 0) 422 429 return -1; 423 430 424 431 lo = 0; ··· 464 471 if (p->revindex) 465 472 return p->revindex[pos].offset; 466 473 else if (pos == p->num_objects) 467 - return p->pack_size - the_hash_algo->rawsz; 474 + return p->pack_size - p->repo->hash_algo->rawsz; 468 475 else 469 476 return nth_packed_object_offset(p, pack_pos_to_index(p, pos)); 470 477 }
+27 -28
pack-write.c
··· 1 - #define USE_THE_REPOSITORY_VARIABLE 2 - 3 1 #include "git-compat-util.h" 4 2 #include "environment.h" 5 3 #include "gettext.h" ··· 56 54 * The *sha1 contains the pack content SHA1 hash. 57 55 * The objects array passed in will be sorted by SHA1 on exit. 58 56 */ 59 - const char *write_idx_file(const struct git_hash_algo *hash_algo, 57 + const char *write_idx_file(struct repository *repo, 60 58 const char *index_name, struct pack_idx_entry **objects, 61 59 int nr_objects, const struct pack_idx_option *opts, 62 60 const unsigned char *sha1) ··· 82 80 83 81 if (opts->flags & WRITE_IDX_VERIFY) { 84 82 assert(index_name); 85 - f = hashfd_check(index_name); 83 + f = hashfd_check(repo->hash_algo, index_name); 86 84 } else { 87 85 if (!index_name) { 88 86 struct strbuf tmp_file = STRBUF_INIT; ··· 92 90 unlink(index_name); 93 91 fd = xopen(index_name, O_CREAT|O_EXCL|O_WRONLY, 0600); 94 92 } 95 - f = hashfd(fd, index_name); 93 + f = hashfd(repo->hash_algo, fd, index_name); 96 94 } 97 95 98 96 /* if last object's offset is >= 2^31 we should use index V2 */ ··· 131 129 struct pack_idx_entry *obj = *list++; 132 130 if (index_version < 2) 133 131 hashwrite_be32(f, obj->offset); 134 - hashwrite(f, obj->oid.hash, hash_algo->rawsz); 132 + hashwrite(f, obj->oid.hash, repo->hash_algo->rawsz); 135 133 if ((opts->flags & WRITE_IDX_STRICT) && 136 134 (i && oideq(&list[-2]->oid, &obj->oid))) 137 135 die("The same object %s appears twice in the pack", ··· 173 171 } 174 172 } 175 173 176 - hashwrite(f, sha1, hash_algo->rawsz); 174 + hashwrite(f, sha1, repo->hash_algo->rawsz); 177 175 finalize_hashfile(f, NULL, FSYNC_COMPONENT_PACK_METADATA, 178 176 CSUM_HASH_IN_STREAM | CSUM_CLOSE | 179 177 ((opts->flags & WRITE_IDX_VERIFY) ? 0 : CSUM_FSYNC)); ··· 217 215 hashwrite(f, hash, hash_algo->rawsz); 218 216 } 219 217 220 - char *write_rev_file(const struct git_hash_algo *hash_algo, 218 + char *write_rev_file(struct repository *repo, 221 219 const char *rev_name, 222 220 struct pack_idx_entry **objects, 223 221 uint32_t nr_objects, ··· 236 234 pack_order[i] = i; 237 235 QSORT_S(pack_order, nr_objects, pack_order_cmp, objects); 238 236 239 - ret = write_rev_file_order(hash_algo, rev_name, pack_order, nr_objects, 237 + ret = write_rev_file_order(repo, rev_name, pack_order, nr_objects, 240 238 hash, flags); 241 239 242 240 free(pack_order); ··· 244 242 return ret; 245 243 } 246 244 247 - char *write_rev_file_order(const struct git_hash_algo *hash_algo, 245 + char *write_rev_file_order(struct repository *repo, 248 246 const char *rev_name, 249 247 uint32_t *pack_order, 250 248 uint32_t nr_objects, ··· 268 266 fd = xopen(rev_name, O_CREAT|O_EXCL|O_WRONLY, 0600); 269 267 path = xstrdup(rev_name); 270 268 } 271 - f = hashfd(fd, path); 269 + f = hashfd(repo->hash_algo, fd, path); 272 270 } else if (flags & WRITE_REV_VERIFY) { 273 271 struct stat statbuf; 274 272 if (stat(rev_name, &statbuf)) { ··· 278 276 } else 279 277 die_errno(_("could not stat: %s"), rev_name); 280 278 } 281 - f = hashfd_check(rev_name); 279 + f = hashfd_check(repo->hash_algo, rev_name); 282 280 path = xstrdup(rev_name); 283 281 } else { 284 282 return NULL; 285 283 } 286 284 287 - write_rev_header(hash_algo, f); 285 + write_rev_header(repo->hash_algo, f); 288 286 289 287 write_rev_index_positions(f, pack_order, nr_objects); 290 - write_rev_trailer(hash_algo, f, hash); 288 + write_rev_trailer(repo->hash_algo, f, hash); 291 289 292 - if (adjust_shared_perm(the_repository, path) < 0) 290 + if (adjust_shared_perm(repo, path) < 0) 293 291 die(_("failed to make %s readable"), path); 294 292 295 293 finalize_hashfile(f, NULL, FSYNC_COMPONENT_PACK_METADATA, ··· 330 328 hashwrite(f, hash, hash_algo->rawsz); 331 329 } 332 330 333 - static char *write_mtimes_file(const struct git_hash_algo *hash_algo, 331 + static char *write_mtimes_file(struct repository *repo, 334 332 struct packing_data *to_pack, 335 333 struct pack_idx_entry **objects, 336 334 uint32_t nr_objects, ··· 346 344 347 345 fd = odb_mkstemp(&tmp_file, "pack/tmp_mtimes_XXXXXX"); 348 346 mtimes_name = strbuf_detach(&tmp_file, NULL); 349 - f = hashfd(fd, mtimes_name); 347 + f = hashfd(repo->hash_algo, fd, mtimes_name); 350 348 351 - write_mtimes_header(hash_algo, f); 349 + write_mtimes_header(repo->hash_algo, f); 352 350 write_mtimes_objects(f, to_pack, objects, nr_objects); 353 - write_mtimes_trailer(hash_algo, f, hash); 351 + write_mtimes_trailer(repo->hash_algo, f, hash); 354 352 355 - if (adjust_shared_perm(the_repository, mtimes_name) < 0) 353 + if (adjust_shared_perm(repo, mtimes_name) < 0) 356 354 die(_("failed to make %s readable"), mtimes_name); 357 355 358 356 finalize_hashfile(f, NULL, FSYNC_COMPONENT_PACK_METADATA, ··· 527 525 return n; 528 526 } 529 527 530 - struct hashfile *create_tmp_packfile(char **pack_tmp_name) 528 + struct hashfile *create_tmp_packfile(struct repository *repo, 529 + char **pack_tmp_name) 531 530 { 532 531 struct strbuf tmpname = STRBUF_INIT; 533 532 int fd; 534 533 535 534 fd = odb_mkstemp(&tmpname, "pack/tmp_pack_XXXXXX"); 536 535 *pack_tmp_name = strbuf_detach(&tmpname, NULL); 537 - return hashfd(fd, *pack_tmp_name); 536 + return hashfd(repo->hash_algo, fd, *pack_tmp_name); 538 537 } 539 538 540 539 static void rename_tmp_packfile(struct strbuf *name_prefix, const char *source, ··· 555 554 rename_tmp_packfile(name_buffer, *idx_tmp_name, "idx"); 556 555 } 557 556 558 - void stage_tmp_packfiles(const struct git_hash_algo *hash_algo, 557 + void stage_tmp_packfiles(struct repository *repo, 559 558 struct strbuf *name_buffer, 560 559 const char *pack_tmp_name, 561 560 struct pack_idx_entry **written_list, ··· 568 567 char *rev_tmp_name = NULL; 569 568 char *mtimes_tmp_name = NULL; 570 569 571 - if (adjust_shared_perm(the_repository, pack_tmp_name)) 570 + if (adjust_shared_perm(repo, pack_tmp_name)) 572 571 die_errno("unable to make temporary pack file readable"); 573 572 574 - *idx_tmp_name = (char *)write_idx_file(hash_algo, NULL, written_list, 573 + *idx_tmp_name = (char *)write_idx_file(repo, NULL, written_list, 575 574 nr_written, pack_idx_opts, hash); 576 - if (adjust_shared_perm(the_repository, *idx_tmp_name)) 575 + if (adjust_shared_perm(repo, *idx_tmp_name)) 577 576 die_errno("unable to make temporary index file readable"); 578 577 579 - rev_tmp_name = write_rev_file(hash_algo, NULL, written_list, nr_written, 578 + rev_tmp_name = write_rev_file(repo, NULL, written_list, nr_written, 580 579 hash, pack_idx_opts->flags); 581 580 582 581 if (pack_idx_opts->flags & WRITE_MTIMES) { 583 - mtimes_tmp_name = write_mtimes_file(hash_algo, to_pack, 582 + mtimes_tmp_name = write_mtimes_file(repo, to_pack, 584 583 written_list, nr_written, 585 584 hash); 586 585 }
+6 -5
pack.h
··· 87 87 /* Note, the data argument could be NULL if object type is blob */ 88 88 typedef int (*verify_fn)(const struct object_id *, enum object_type, unsigned long, void*, int*); 89 89 90 - const char *write_idx_file(const struct git_hash_algo *hash_algo, 90 + const char *write_idx_file(struct repository *repo, 91 91 const char *index_name, 92 92 struct pack_idx_entry **objects, 93 93 int nr_objects, ··· 106 106 107 107 void write_promisor_file(const char *promisor_name, struct ref **sought, int nr_sought); 108 108 109 - char *write_rev_file(const struct git_hash_algo *hash_algo, 109 + char *write_rev_file(struct repository *repo, 110 110 const char *rev_name, 111 111 struct pack_idx_entry **objects, 112 112 uint32_t nr_objects, 113 113 const unsigned char *hash, 114 114 unsigned flags); 115 - char *write_rev_file_order(const struct git_hash_algo *hash_algo, 115 + char *write_rev_file_order(struct repository *repo, 116 116 const char *rev_name, 117 117 uint32_t *pack_order, 118 118 uint32_t nr_objects, ··· 134 134 135 135 struct packing_data; 136 136 137 - struct hashfile *create_tmp_packfile(char **pack_tmp_name); 138 - void stage_tmp_packfiles(const struct git_hash_algo *hash_algo, 137 + struct hashfile *create_tmp_packfile(struct repository *repo, 138 + char **pack_tmp_name); 139 + void stage_tmp_packfiles(struct repository *repo, 139 140 struct strbuf *name_buffer, 140 141 const char *pack_tmp_name, 141 142 struct pack_idx_entry **written_list,
+1 -1
parse-options-cb.c
··· 145 145 struct object_id *target = opt->value; 146 146 147 147 if (unset) { 148 - oidcpy(target, null_oid()); 148 + oidcpy(target, null_oid(the_hash_algo)); 149 149 return 0; 150 150 } 151 151 if (!arg)
+1 -1
range-diff.c
··· 467 467 { 468 468 struct diff_filespec *spec = alloc_filespec(name); 469 469 470 - fill_filespec(spec, null_oid(), 0, 0100644); 470 + fill_filespec(spec, null_oid(the_hash_algo), 0, 0100644); 471 471 spec->data = (char *)p; 472 472 spec->size = strlen(p); 473 473 spec->should_munmap = 0;
+3 -3
reachable.c
··· 45 45 } 46 46 strbuf_trim(&buf); 47 47 if (!get_oid_hex(buf.buf, &oid)) { 48 - object = parse_object_or_die(&oid, buf.buf); 48 + object = parse_object_or_die(the_repository, &oid, buf.buf); 49 49 add_pending_object(revs, object, ""); 50 50 } 51 51 strbuf_release(&buf); ··· 94 94 return 0; 95 95 } 96 96 97 - object = parse_object_or_die(oid, path); 97 + object = parse_object_or_die(the_repository, oid, path); 98 98 add_pending_object(revs, object, ""); 99 99 100 100 return 0; ··· 218 218 switch (type) { 219 219 case OBJ_TAG: 220 220 case OBJ_COMMIT: 221 - obj = parse_object_or_die(oid, NULL); 221 + obj = parse_object_or_die(the_repository, oid, NULL); 222 222 break; 223 223 case OBJ_TREE: 224 224 obj = (struct object *)lookup_tree(the_repository, oid);
+2 -2
read-cache.c
··· 1735 1735 end = (unsigned char *)hdr + size; 1736 1736 start = end - the_hash_algo->rawsz; 1737 1737 oidread(&oid, start, the_repository->hash_algo); 1738 - if (oideq(&oid, null_oid())) 1738 + if (oideq(&oid, null_oid(the_hash_algo))) 1739 1739 return 0; 1740 1740 1741 1741 the_hash_algo->init_fn(&c); ··· 2848 2848 struct strbuf sb = STRBUF_INIT; 2849 2849 int nr, nr_threads, ret; 2850 2850 2851 - f = hashfd(tempfile->fd, tempfile->filename.buf); 2851 + f = hashfd(the_repository->hash_algo, tempfile->fd, tempfile->filename.buf); 2852 2852 2853 2853 prepare_repo_settings(r); 2854 2854 f->skip_hash = r->settings.index_skip_hash;
+6 -6
refs.c
··· 1377 1377 return 1; 1378 1378 } 1379 1379 return ref_transaction_update(transaction, refname, new_oid, 1380 - null_oid(), new_target, NULL, flags, 1380 + null_oid(the_hash_algo), new_target, NULL, flags, 1381 1381 msg, err); 1382 1382 } 1383 1383 ··· 1396 1396 if (old_target && !(flags & REF_NO_DEREF)) 1397 1397 BUG("delete cannot operate on symrefs with deref mode"); 1398 1398 return ref_transaction_update(transaction, refname, 1399 - null_oid(), old_oid, 1399 + null_oid(the_hash_algo), old_oid, 1400 1400 NULL, old_target, flags, 1401 1401 msg, err); 1402 1402 } ··· 2180 2180 subrepo = xmalloc(sizeof(*subrepo)); 2181 2181 2182 2182 if (repo_submodule_init(subrepo, repo, submodule, 2183 - null_oid())) { 2183 + null_oid(the_hash_algo))) { 2184 2184 free(subrepo); 2185 2185 goto done; 2186 2186 } ··· 2365 2365 strbuf_reset(&buf); 2366 2366 2367 2367 if (!(update->flags & REF_HAVE_OLD)) 2368 - strbuf_addf(&buf, "%s ", oid_to_hex(null_oid())); 2368 + strbuf_addf(&buf, "%s ", oid_to_hex(null_oid(the_hash_algo))); 2369 2369 else if (update->old_target) 2370 2370 strbuf_addf(&buf, "ref:%s ", update->old_target); 2371 2371 else 2372 2372 strbuf_addf(&buf, "%s ", oid_to_hex(&update->old_oid)); 2373 2373 2374 2374 if (!(update->flags & REF_HAVE_NEW)) 2375 - strbuf_addf(&buf, "%s ", oid_to_hex(null_oid())); 2375 + strbuf_addf(&buf, "%s ", oid_to_hex(null_oid(the_hash_algo))); 2376 2376 else if (update->new_target) 2377 2377 strbuf_addf(&buf, "ref:%s ", update->new_target); 2378 2378 else ··· 2857 2857 if (ret < 0) 2858 2858 goto done; 2859 2859 2860 - ret = ref_transaction_update(data->transaction, refname, NULL, null_oid(), 2860 + ret = ref_transaction_update(data->transaction, refname, NULL, null_oid(the_hash_algo), 2861 2861 symref_target.buf, NULL, 2862 2862 REF_SKIP_CREATE_REFLOG | REF_NO_DEREF, NULL, data->errbuf); 2863 2863 if (ret < 0)
+1 -1
refs/debug.c
··· 227 227 struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store; 228 228 int res = 0; 229 229 230 - oidcpy(oid, null_oid()); 230 + oidcpy(oid, null_oid(ref_store->repo->hash_algo)); 231 231 res = drefs->refs->be->read_raw_ref(drefs->refs, refname, oid, referent, 232 232 type, failure_errno); 233 233
+1 -1
refs/files-backend.c
··· 1265 1265 ref_transaction_add_update( 1266 1266 transaction, r->name, 1267 1267 REF_NO_DEREF | REF_HAVE_NEW | REF_HAVE_OLD | REF_IS_PRUNING, 1268 - null_oid(), &r->oid, NULL, NULL, NULL, NULL); 1268 + null_oid(the_hash_algo), &r->oid, NULL, NULL, NULL, NULL); 1269 1269 if (ref_transaction_commit(transaction, &err)) 1270 1270 goto cleanup; 1271 1271
+20
repo-settings.c
··· 20 20 *dest = def; 21 21 } 22 22 23 + static void repo_cfg_ulong(struct repository *r, const char *key, unsigned long *dest, 24 + unsigned long def) 25 + { 26 + if (repo_config_get_ulong(r, key, dest)) 27 + *dest = def; 28 + } 29 + 23 30 void prepare_repo_settings(struct repository *r) 24 31 { 25 32 int experimental; ··· 149 156 FREE_AND_NULL(r->settings.fsmonitor); 150 157 FREE_AND_NULL(r->settings.hooks_path); 151 158 r->settings = empty; 159 + } 160 + 161 + unsigned long repo_settings_get_big_file_threshold(struct repository *repo) 162 + { 163 + if (!repo->settings.big_file_threshold) 164 + repo_cfg_ulong(repo, "core.bigfilethreshold", 165 + &repo->settings.big_file_threshold, 512 * 1024 * 1024); 166 + return repo->settings.big_file_threshold; 167 + } 168 + 169 + void repo_settings_set_big_file_threshold(struct repository *repo, unsigned long value) 170 + { 171 + repo->settings.big_file_threshold = value; 152 172 } 153 173 154 174 enum log_refs_config repo_settings_get_log_all_ref_updates(struct repository *repo)
+5
repo-settings.h
··· 64 64 size_t delta_base_cache_limit; 65 65 size_t packed_git_window_size; 66 66 size_t packed_git_limit; 67 + unsigned long big_file_threshold; 67 68 68 69 char *hooks_path; 69 70 }; ··· 87 88 int repo_settings_get_warn_ambiguous_refs(struct repository *repo); 88 89 /* Read the value for "core.hooksPath". */ 89 90 const char *repo_settings_get_hooks_path(struct repository *repo); 91 + 92 + /* Read and set the value for "core.bigFileThreshold". */ 93 + unsigned long repo_settings_get_big_file_threshold(struct repository *repo); 94 + void repo_settings_set_big_file_threshold(struct repository *repo, unsigned long value); 90 95 91 96 /* Read, set or reset the value for "core.sharedRepository". */ 92 97 int repo_settings_get_shared_repository(struct repository *repo);
+1 -1
reset.c
··· 80 80 } 81 81 if (!ret && run_hook) 82 82 run_hooks_l(the_repository, "post-checkout", 83 - oid_to_hex(head ? head : null_oid()), 83 + oid_to_hex(head ? head : null_oid(the_hash_algo)), 84 84 oid_to_hex(oid), "1", NULL); 85 85 strbuf_release(&msg); 86 86 return ret;
+2 -1
revision.c
··· 3612 3612 3613 3613 void reset_revision_walk(void) 3614 3614 { 3615 - clear_object_flags(SEEN | ADDED | SHOWN | TOPO_WALK_EXPLORED | TOPO_WALK_INDEGREE); 3615 + clear_object_flags(the_repository, 3616 + SEEN | ADDED | SHOWN | TOPO_WALK_EXPLORED | TOPO_WALK_INDEGREE); 3616 3617 } 3617 3618 3618 3619 static int mark_uninteresting(const struct object_id *oid,
+5 -5
sequencer.c
··· 265 265 266 266 CALLOC_ARRAY(rec, 1); 267 267 268 - oidcpy(&rec->before, null_oid()); 269 - oidcpy(&rec->after, null_oid()); 268 + oidcpy(&rec->before, null_oid(the_hash_algo)); 269 + oidcpy(&rec->after, null_oid(the_hash_algo)); 270 270 271 271 /* This may fail, but that's fine, we will keep the null OID. */ 272 272 refs_read_ref(get_main_ref_store(the_repository), ref, &rec->before); ··· 667 667 if (!transaction || 668 668 ref_transaction_update(transaction, "HEAD", 669 669 to, unborn && !is_rebase_i(opts) ? 670 - null_oid() : from, NULL, NULL, 670 + null_oid(the_hash_algo) : from, NULL, NULL, 671 671 0, sb.buf, &err) || 672 672 ref_transaction_commit(transaction, &err)) { 673 673 ref_transaction_free(transaction); ··· 1301 1301 0, err); 1302 1302 if (!transaction || 1303 1303 ref_transaction_update(transaction, "HEAD", new_head, 1304 - old_head ? &old_head->object.oid : null_oid(), 1304 + old_head ? &old_head->object.oid : null_oid(the_hash_algo), 1305 1305 NULL, NULL, 0, sb.buf, err) || 1306 1306 ref_transaction_commit(transaction, err)) { 1307 1307 ret = -1; ··· 4683 4683 write_file(path, "%s", oid_to_hex(&oid)); 4684 4684 } else { 4685 4685 refs_update_ref(get_main_ref_store(r), "", refname, 4686 - &oid, null_oid(), 0, UPDATE_REFS_DIE_ON_ERR); 4686 + &oid, null_oid(the_hash_algo), 0, UPDATE_REFS_DIE_ON_ERR); 4687 4687 } 4688 4688 4689 4689 printf(_("Created autostash: %s\n"), buf.buf);
+5 -5
shallow.c
··· 226 226 * SHALLOW (excluded) and NOT_SHALLOW (included) should not be 227 227 * set at this point. But better be safe than sorry. 228 228 */ 229 - clear_object_flags(both_flags); 229 + clear_object_flags(the_repository, both_flags); 230 230 231 231 is_repository_shallow(the_repository); /* make sure shallows are read */ 232 232 ··· 613 613 } 614 614 } 615 615 616 - nr = get_max_object_index(); 616 + nr = get_max_object_index(the_repository); 617 617 for (i = 0; i < nr; i++) { 618 - struct object *o = get_indexed_object(i); 618 + struct object *o = get_indexed_object(the_repository, i); 619 619 if (o && o->type == OBJ_COMMIT) 620 620 o->flags &= ~SEEN; 621 621 } ··· 675 675 * Prepare the commit graph to track what refs can reach what 676 676 * (new) shallow commits. 677 677 */ 678 - nr = get_max_object_index(); 678 + nr = get_max_object_index(the_repository); 679 679 for (i = 0; i < nr; i++) { 680 - struct object *o = get_indexed_object(i); 680 + struct object *o = get_indexed_object(the_repository, i); 681 681 if (!o || o->type != OBJ_COMMIT) 682 682 continue; 683 683
+2 -1
streaming.c
··· 431 431 st->open = open_istream_loose; 432 432 return 0; 433 433 case OI_PACKED: 434 - if (!oi.u.packed.is_delta && big_file_threshold < size) { 434 + if (!oi.u.packed.is_delta && 435 + repo_settings_get_big_file_threshold(the_repository) < size) { 435 436 st->u.in_pack.pack = oi.u.packed.pack; 436 437 st->u.in_pack.pos = oi.u.packed.offset; 437 438 st->open = open_istream_pack_non_delta;
+1 -1
submodule-config.c
··· 831 831 832 832 parameter.cache = repo->submodule_cache; 833 833 parameter.treeish_name = NULL; 834 - parameter.gitmodules_oid = null_oid(); 834 + parameter.gitmodules_oid = null_oid(the_hash_algo); 835 835 parameter.overwrite = 1; 836 836 837 837 return parse_config(var, value, ctx, &parameter);
+14 -14
submodule.c
··· 124 124 if (is_gitmodules_unmerged(the_repository->index)) 125 125 die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first")); 126 126 127 - submodule = submodule_from_path(the_repository, null_oid(), oldpath); 127 + submodule = submodule_from_path(the_repository, null_oid(the_hash_algo), oldpath); 128 128 if (!submodule || !submodule->name) { 129 129 warning(_("Could not find section in .gitmodules where path=%s"), oldpath); 130 130 return -1; ··· 153 153 if (is_gitmodules_unmerged(the_repository->index)) 154 154 die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first")); 155 155 156 - submodule = submodule_from_path(the_repository, null_oid(), path); 156 + submodule = submodule_from_path(the_repository, null_oid(the_hash_algo), path); 157 157 if (!submodule || !submodule->name) { 158 158 warning(_("Could not find section in .gitmodules where path=%s"), path); 159 159 return -1; ··· 204 204 const char *path) 205 205 { 206 206 const struct submodule *submodule = submodule_from_path(the_repository, 207 - null_oid(), 207 + null_oid(the_hash_algo), 208 208 path); 209 209 if (submodule) { 210 210 const char *ignore; ··· 312 312 313 313 int is_submodule_active(struct repository *repo, const char *path) 314 314 { 315 - return is_tree_submodule_active(repo, null_oid(), path); 315 + return is_tree_submodule_active(repo, null_oid(the_hash_algo), path); 316 316 } 317 317 318 318 int is_submodule_populated_gently(const char *path, int *return_error_code) ··· 778 778 if (!should_update_submodules()) 779 779 return NULL; 780 780 781 - return submodule_from_path(the_repository, null_oid(), ce->name); 781 + return submodule_from_path(the_repository, null_oid(the_hash_algo), ce->name); 782 782 } 783 783 784 784 ··· 1062 1062 const char *path, 1063 1063 struct oid_array *commits) 1064 1064 { 1065 - if (!submodule_has_commits(r, path, null_oid(), commits)) 1065 + if (!submodule_has_commits(r, path, null_oid(the_hash_algo), commits)) 1066 1066 /* 1067 1067 * NOTE: We do consider it safe to return "no" here. The 1068 1068 * correct answer would be "We do not know" instead of ··· 1126 1126 const struct submodule *submodule; 1127 1127 const char *path = NULL; 1128 1128 1129 - submodule = submodule_from_name(r, null_oid(), name->string); 1129 + submodule = submodule_from_name(r, null_oid(the_hash_algo), name->string); 1130 1130 if (submodule) 1131 1131 path = submodule->path; 1132 1132 else ··· 1351 1351 const struct submodule *submodule; 1352 1352 const char *path = NULL; 1353 1353 1354 - submodule = submodule_from_name(r, null_oid(), name->string); 1354 + submodule = submodule_from_name(r, null_oid(the_hash_algo), name->string); 1355 1355 if (submodule) 1356 1356 path = submodule->path; 1357 1357 else ··· 1360 1360 if (!path) 1361 1361 continue; 1362 1362 1363 - if (submodule_has_commits(r, path, null_oid(), &cs_data->new_commits)) { 1363 + if (submodule_has_commits(r, path, null_oid(the_hash_algo), &cs_data->new_commits)) { 1364 1364 changed_submodule_data_clear(cs_data); 1365 1365 *name->string = '\0'; 1366 1366 } ··· 1602 1602 if (!S_ISGITLINK(ce->ce_mode)) 1603 1603 continue; 1604 1604 1605 - task = fetch_task_create(spf, ce->name, null_oid()); 1605 + task = fetch_task_create(spf, ce->name, null_oid(the_hash_algo)); 1606 1606 if (!task) 1607 1607 continue; 1608 1608 ··· 2166 2166 if (old_head && !is_submodule_populated_gently(path, error_code_ptr)) 2167 2167 return 0; 2168 2168 2169 - sub = submodule_from_path(the_repository, null_oid(), path); 2169 + sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path); 2170 2170 2171 2171 if (!sub) 2172 2172 BUG("could not get submodule information for '%s'", path); ··· 2376 2376 2377 2377 real_old_git_dir = real_pathdup(old_git_dir, 1); 2378 2378 2379 - sub = submodule_from_path(the_repository, null_oid(), path); 2379 + sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path); 2380 2380 if (!sub) 2381 2381 die(_("could not lookup name for submodule '%s'"), path); 2382 2382 ··· 2462 2462 * superproject did not rewrite the git file links yet, 2463 2463 * fix it now. 2464 2464 */ 2465 - sub = submodule_from_path(the_repository, null_oid(), path); 2465 + sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path); 2466 2466 if (!sub) 2467 2467 die(_("could not lookup name for submodule '%s'"), path); 2468 2468 submodule_name_to_gitdir(&sub_gitdir, the_repository, sub->name); ··· 2594 2594 strbuf_addstr(buf, git_dir); 2595 2595 } 2596 2596 if (!is_git_directory(buf->buf)) { 2597 - sub = submodule_from_path(repo, null_oid(), submodule); 2597 + sub = submodule_from_path(repo, null_oid(the_hash_algo), submodule); 2598 2598 if (!sub) { 2599 2599 ret = -1; 2600 2600 goto cleanup;
+1 -1
t/helper/test-ref-store.c
··· 179 179 180 180 static int cmd_resolve_ref(struct ref_store *refs, const char **argv) 181 181 { 182 - struct object_id oid = *null_oid(); 182 + struct object_id oid = *null_oid(the_hash_algo); 183 183 const char *refname = notnull(*argv++, "refname"); 184 184 int resolve_flags = arg_flags(*argv++, "resolve-flags", empty_flags); 185 185 int flags;
+1 -1
t/helper/test-submodule-nested-repo-config.c
··· 21 21 22 22 setup_git_directory(); 23 23 24 - if (repo_submodule_init(&subrepo, the_repository, argv[1], null_oid())) { 24 + if (repo_submodule_init(&subrepo, the_repository, argv[1], null_oid(the_hash_algo))) { 25 25 die_usage(argv, "Submodule not found."); 26 26 } 27 27
+2 -1
t/t1050-large.sh
··· 6 6 . ./test-lib.sh 7 7 8 8 test_expect_success 'core.bigFileThreshold must be non-negative' ' 9 - test_must_fail git -c core.bigFileThreshold=-1 rev-parse >out 2>err && 9 + : >input && 10 + test_must_fail git -c core.bigFileThreshold=-1 hash-object input >out 2>err && 10 11 grep "bad numeric config value" err && 11 12 test_must_be_empty out 12 13 '
+2 -2
tree-diff.c
··· 181 181 182 182 strbuf_add(base, path, pathlen); 183 183 p = combine_diff_path_new(base->buf, base->len, mode, 184 - oid ? oid : null_oid(), 184 + oid ? oid : null_oid(the_hash_algo), 185 185 nparent); 186 186 strbuf_setlen(base, old_baselen); 187 187 ··· 206 206 mode_i = tp[i].entry.mode; 207 207 } 208 208 else { 209 - oid_i = null_oid(); 209 + oid_i = null_oid(the_hash_algo); 210 210 mode_i = 0; 211 211 } 212 212
+7 -7
upload-pack.c
··· 665 665 666 666 cmd_in = xfdopen(cmd->in, "w"); 667 667 668 - for (i = get_max_object_index(); 0 < i; ) { 669 - o = get_indexed_object(--i); 668 + for (i = get_max_object_index(the_repository); 0 < i; ) { 669 + o = get_indexed_object(the_repository, --i); 670 670 if (!o) 671 671 continue; 672 672 if (reachable && o->type == OBJ_COMMIT) ··· 734 734 o->flags &= ~TMP_MARK; 735 735 } 736 736 } 737 - for (i = get_max_object_index(); 0 < i; i--) { 738 - o = get_indexed_object(i - 1); 737 + for (i = get_max_object_index(the_repository); 0 < i; i--) { 738 + o = get_indexed_object(the_repository, i - 1); 739 739 if (o && o->type == OBJ_COMMIT && 740 740 (o->flags & TMP_MARK)) { 741 741 add_object_array(o, NULL, reachable); ··· 1449 1449 for_each_namespaced_ref_1(send_ref, &data); 1450 1450 if (!data.sent_capabilities) { 1451 1451 const char *refname = "capabilities^{}"; 1452 - write_v0_ref(&data, refname, refname, null_oid()); 1452 + write_v0_ref(&data, refname, refname, null_oid(the_hash_algo)); 1453 1453 } 1454 1454 /* 1455 1455 * fflush stdout before calling advertise_shallow_grafts because send_ref ··· 1557 1557 } 1558 1558 1559 1559 if (!o) 1560 - o = parse_object_or_die(&oid, refname_nons); 1560 + o = parse_object_or_die(the_repository, &oid, refname_nons); 1561 1561 1562 1562 if (!(o->flags & WANTED)) { 1563 1563 o->flags |= WANTED; ··· 1793 1793 enum fetch_state state = FETCH_PROCESS_ARGS; 1794 1794 struct upload_pack_data data; 1795 1795 1796 - clear_object_flags(ALL_FLAGS); 1796 + clear_object_flags(the_repository, ALL_FLAGS); 1797 1797 1798 1798 upload_pack_data_init(&data); 1799 1799 data.use_sideband = LARGE_PACKET_MAX;
+2 -2
wt-status.c
··· 1824 1824 if (!sequencer_get_last_command(r, &action)) { 1825 1825 if (action == REPLAY_PICK && !state->cherry_pick_in_progress) { 1826 1826 state->cherry_pick_in_progress = 1; 1827 - oidcpy(&state->cherry_pick_head_oid, null_oid()); 1827 + oidcpy(&state->cherry_pick_head_oid, null_oid(the_hash_algo)); 1828 1828 } else if (action == REPLAY_REVERT && !state->revert_in_progress) { 1829 1829 state->revert_in_progress = 1; 1830 - oidcpy(&state->revert_head_oid, null_oid()); 1830 + oidcpy(&state->revert_head_oid, null_oid(the_hash_algo)); 1831 1831 } 1832 1832 } 1833 1833 if (get_detached_from)
+1 -1
xdiff-interface.c
··· 181 181 unsigned long size; 182 182 enum object_type type; 183 183 184 - if (oideq(oid, null_oid())) { 184 + if (oideq(oid, null_oid(the_hash_algo))) { 185 185 ptr->ptr = xstrdup(""); 186 186 ptr->size = 0; 187 187 return;