1
0
mirror of https://github.com/git/git.git synced 2024-09-08 03:50:44 +02:00

Merge branch 'ps/use-the-repository' into next

A CPP macro USE_THE_REPOSITORY_VARIABLE is introduced to help
transition the codebase to rely less on the availability of the
singleton the_repository instance.

* ps/use-the-repository:
  hex: guard declarations with `USE_THE_REPOSITORY_VARIABLE`
  t/helper: remove dependency on `the_repository` in "proc-receive"
  t/helper: fix segfault in "oid-array" command without repository
  t/helper: use correct object hash in partial-clone helper
  compat/fsmonitor: fix socket path in networked SHA256 repos
  replace-object: use hash algorithm from passed-in repository
  protocol-caps: use hash algorithm from passed-in repository
  oidset: pass hash algorithm when parsing file
  http-fetch: don't crash when parsing packfile without a repo
  hash-ll: merge with "hash.h"
  refs: avoid include cycle with "repository.h"
  global: introduce `USE_THE_REPOSITORY_VARIABLE` macro
  hash: require hash algorithm in `empty_tree_oid_hex()`
  hash: require hash algorithm in `is_empty_{blob,tree}_oid()`
  hash: make `is_null_oid()` independent of `the_repository`
  hash: convert `oidcmp()` and `oideq()` to compare whole hash
  global: ensure that object IDs are always padded
  hash: require hash algorithm in `oidread()` and `oidclr()`
  hash: require hash algorithm in `hasheq()`, `hashcmp()` and `hashclr()`
  hash: drop (mostly) unused `is_empty_{blob,tree}_sha1()` functions
This commit is contained in:
Junio C Hamano 2024-06-24 16:41:35 -07:00
commit ca97784ba8
228 changed files with 1032 additions and 645 deletions

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "add-interactive.h"
#include "color.h"
@ -557,7 +559,7 @@ static int get_modified_files(struct repository *r,
s.skip_unseen = filter && i;
opt.def = is_initial ?
empty_tree_oid_hex() : oid_to_hex(&head_oid);
empty_tree_oid_hex(the_repository->hash_algo) : oid_to_hex(&head_oid);
repo_init_revisions(r, &rev, NULL);
setup_revisions(0, NULL, &rev, &opt);

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "add-interactive.h"
#include "advice.h"
@ -421,7 +423,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
/* could be on an unborn branch */
!strcmp("HEAD", s->revision) &&
repo_get_oid(the_repository, "HEAD", &oid) ?
empty_tree_oid_hex() : s->revision);
empty_tree_oid_hex(the_repository->hash_algo) : s->revision);
}
color_arg_index = args.nr;
/* Use `--no-color` explicitly, just in case `diff.color = always`. */

View File

@ -7,6 +7,8 @@
*
*/
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "abspath.h"
#include "base85.h"
@ -3680,7 +3682,7 @@ static int try_threeway(struct apply_state *state,
if (status) {
patch->conflicted_threeway = 1;
if (patch->is_new)
oidclr(&patch->threeway_stage[0]);
oidclr(&patch->threeway_stage[0], the_repository->hash_algo);
else
oidcpy(&patch->threeway_stage[0], &pre_oid);
oidcpy(&patch->threeway_stage[1], &our_oid);

View File

@ -1,7 +1,7 @@
#ifndef APPLY_H
#define APPLY_H
#include "hash-ll.h"
#include "hash.h"
#include "lockfile.h"
#include "string-list.h"
#include "strmap.h"

View File

@ -1,6 +1,9 @@
/*
* Copyright (c) 2005, 2006 Rene Scharfe
*/
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "config.h"
#include "gettext.h"

View File

@ -1,6 +1,9 @@
/*
* Copyright (c) 2006 Rene Scharfe
*/
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "config.h"
#include "archive.h"

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "abspath.h"
#include "config.h"

2
attr.c
View File

@ -6,6 +6,8 @@
* an insanely large number of attributes.
*/
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "config.h"
#include "environment.h"

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "config.h"
#include "commit.h"

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "refs.h"
#include "object-store-ll.h"
@ -1246,7 +1248,7 @@ static int fill_blob_sha1_and_mode(struct repository *r,
goto error_out;
return 0;
error_out:
oidclr(&origin->blob_oid);
oidclr(&origin->blob_oid, the_repository->hash_algo);
origin->mode = S_IFINVALID;
return -1;
}

View File

@ -6,6 +6,7 @@
#include "commit-graph.h"
#include "commit.h"
#include "commit-slab.h"
#include "repository.h"
define_commit_slab(bloom_filter_slab, struct bloom_filter);

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "advice.h"
#include "config.h"

View File

@ -1,6 +1,14 @@
#ifndef BUILTIN_H
#define BUILTIN_H
/*
* TODO: Almost all of our builtins access `the_repository` by necessity
* because they do not get passed a pointer to it. We should adapt the function
* signature of those main functions to accept a `struct repository *` and then
* remove the macro here.
*/
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
/*

View File

@ -408,7 +408,7 @@ static void am_load(struct am_state *state)
read_commit_msg(state);
if (read_state_file(&sb, state, "original-commit", 1) < 0)
oidclr(&state->orig_commit);
oidclr(&state->orig_commit, the_repository->hash_algo);
else if (get_oid_hex(sb.buf, &state->orig_commit) < 0)
die(_("could not parse %s"), am_path(state, "original-commit"));
@ -1121,7 +1121,7 @@ static void am_next(struct am_state *state)
unlink(am_path(state, "author-script"));
unlink(am_path(state, "final-commit"));
oidclr(&state->orig_commit);
oidclr(&state->orig_commit, the_repository->hash_algo);
unlink(am_path(state, "original-commit"));
refs_delete_ref(get_main_ref_store(the_repository), NULL,
"REBASE_HEAD", NULL, REF_NO_DEREF);
@ -2151,11 +2151,11 @@ static int safe_to_abort(const struct am_state *state)
if (get_oid_hex(sb.buf, &abort_safety))
die(_("could not parse %s"), am_path(state, "abort-safety"));
} else
oidclr(&abort_safety);
oidclr(&abort_safety, the_repository->hash_algo);
strbuf_release(&sb);
if (repo_get_oid(the_repository, "HEAD", &head))
oidclr(&head);
oidclr(&head, the_repository->hash_algo);
if (oideq(&head, &abort_safety))
return 1;

View File

@ -5,7 +5,7 @@
* See COPYING for licensing conditions
*/
#include "git-compat-util.h"
#include "builtin.h"
#include "config.h"
#include "color.h"
#include "builtin.h"
@ -852,6 +852,7 @@ static void build_ignorelist(struct blame_scoreboard *sb,
oidset_clear(&sb->ignore_list);
else
oidset_parse_file_carefully(&sb->ignore_list, i->string,
the_repository->hash_algo,
peel_to_commit_oid, sb);
}
for_each_string_list_item(i, ignore_rev_list) {

View File

@ -415,7 +415,7 @@ static char *generate_fake_oid(void)
struct object_id oid;
char *hex = xmallocz(GIT_MAX_HEXSZ);
oidclr(&oid);
oidclr(&oid, the_repository->hash_algo);
put_be32(oid.hash + hashsz - 4, counter++);
return oid_to_hex_r(hex, &oid);
}

View File

@ -1279,8 +1279,10 @@ static void load_tree(struct tree_entry *root)
e->versions[0].mode = e->versions[1].mode;
e->name = to_atom(c, strlen(c));
c += e->name->str_len + 1;
oidread(&e->versions[0].oid, (unsigned char *)c);
oidread(&e->versions[1].oid, (unsigned char *)c);
oidread(&e->versions[0].oid, (unsigned char *)c,
the_repository->hash_algo);
oidread(&e->versions[1].oid, (unsigned char *)c,
the_repository->hash_algo);
c += the_hash_algo->rawsz;
}
free(buf);
@ -1386,7 +1388,7 @@ static void tree_content_replace(
{
if (!S_ISDIR(mode))
die("Root cannot be a non-directory");
oidclr(&root->versions[0].oid);
oidclr(&root->versions[0].oid, the_repository->hash_algo);
oidcpy(&root->versions[1].oid, oid);
if (root->tree)
release_tree_content_recursive(root->tree);
@ -1445,7 +1447,7 @@ static int tree_content_set(
if (S_ISDIR(e->versions[0].mode))
e->versions[0].mode |= NO_DELTA;
oidclr(&root->versions[1].oid);
oidclr(&root->versions[1].oid, the_repository->hash_algo);
return 1;
}
if (!S_ISDIR(e->versions[1].mode)) {
@ -1455,7 +1457,7 @@ static int tree_content_set(
if (!e->tree)
load_tree(e);
if (tree_content_set(e, slash1 + 1, oid, mode, subtree)) {
oidclr(&root->versions[1].oid);
oidclr(&root->versions[1].oid, the_repository->hash_algo);
return 1;
}
return 0;
@ -1467,7 +1469,7 @@ static int tree_content_set(
e = new_tree_entry();
e->name = to_atom(p, n);
e->versions[0].mode = 0;
oidclr(&e->versions[0].oid);
oidclr(&e->versions[0].oid, the_repository->hash_algo);
t->entries[t->entry_count++] = e;
if (*slash1) {
e->tree = new_tree_content(8);
@ -1478,7 +1480,7 @@ static int tree_content_set(
e->versions[1].mode = mode;
oidcpy(&e->versions[1].oid, oid);
}
oidclr(&root->versions[1].oid);
oidclr(&root->versions[1].oid, the_repository->hash_algo);
return 1;
}
@ -1523,7 +1525,8 @@ static int tree_content_remove(
if (tree_content_remove(e, slash1 + 1, backup_leaf, 0)) {
for (n = 0; n < e->tree->entry_count; n++) {
if (e->tree->entries[n]->versions[1].mode) {
oidclr(&root->versions[1].oid);
oidclr(&root->versions[1].oid,
the_repository->hash_algo);
return 1;
}
}
@ -1542,8 +1545,8 @@ del_entry:
release_tree_content_recursive(e->tree);
e->tree = NULL;
e->versions[1].mode = 0;
oidclr(&e->versions[1].oid);
oidclr(&root->versions[1].oid);
oidclr(&e->versions[1].oid, the_repository->hash_algo);
oidclr(&root->versions[1].oid, the_repository->hash_algo);
return 1;
}
@ -1609,7 +1612,7 @@ static int update_branch(struct branch *b)
return 0;
}
if (refs_read_ref(get_main_ref_store(the_repository), b->name, &old_oid))
oidclr(&old_oid);
oidclr(&old_oid, the_repository->hash_algo);
if (!force_update && !is_null_oid(&old_oid)) {
struct commit *old_cmit, *new_cmit;
int ret;
@ -2358,7 +2361,9 @@ static void file_change_m(const char *p, struct branch *b)
parse_path_eol(&path, p, "path");
/* Git does not track empty, non-toplevel directories. */
if (S_ISDIR(mode) && is_empty_tree_oid(&oid) && *path.buf) {
if (S_ISDIR(mode) &&
is_empty_tree_oid(&oid, the_repository->hash_algo) &&
*path.buf) {
tree_content_remove(&b->branch_tree, path.buf, NULL, 0);
return;
}
@ -2550,8 +2555,8 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
static void file_change_deleteall(struct branch *b)
{
release_tree_content_recursive(b->branch_tree.tree);
oidclr(&b->branch_tree.versions[0].oid);
oidclr(&b->branch_tree.versions[1].oid);
oidclr(&b->branch_tree.versions[0].oid, the_repository->hash_algo);
oidclr(&b->branch_tree.versions[1].oid, the_repository->hash_algo);
load_tree(&b->branch_tree);
b->num_notes = 0;
}
@ -2570,8 +2575,8 @@ static void parse_from_commit(struct branch *b, char *buf, unsigned long size)
static void parse_from_existing(struct branch *b)
{
if (is_null_oid(&b->oid)) {
oidclr(&b->branch_tree.versions[0].oid);
oidclr(&b->branch_tree.versions[1].oid);
oidclr(&b->branch_tree.versions[0].oid, the_repository->hash_algo);
oidclr(&b->branch_tree.versions[1].oid, the_repository->hash_algo);
} else {
unsigned long size;
char *buf;
@ -2894,9 +2899,9 @@ static void parse_reset_branch(const char *arg)
b = lookup_branch(arg);
if (b) {
oidclr(&b->oid);
oidclr(&b->branch_tree.versions[0].oid);
oidclr(&b->branch_tree.versions[1].oid);
oidclr(&b->oid, the_repository->hash_algo);
oidclr(&b->branch_tree.versions[0].oid, the_repository->hash_algo);
oidclr(&b->branch_tree.versions[1].oid, the_repository->hash_algo);
if (b->branch_tree.tree) {
release_tree_content_recursive(b->branch_tree.tree);
b->branch_tree.tree = NULL;

View File

@ -29,11 +29,11 @@ static void add_sought_entry(struct ref ***sought, int *nr, int *alloc,
; /* <oid>, leave oid as name */
} else {
/* <ref>, clear cruft from oid */
oidclr(&oid);
oidclr(&oid, the_repository->hash_algo);
}
} else {
/* <ref>, clear cruft from get_oid_hex */
oidclr(&oid);
oidclr(&oid, the_repository->hash_algo);
}
ref = alloc_ref(name);

View File

@ -528,7 +528,8 @@ static void *unpack_raw_entry(struct object_entry *obj,
switch (obj->type) {
case OBJ_REF_DELTA:
oidread(ref_oid, fill(the_hash_algo->rawsz));
oidread(ref_oid, fill(the_hash_algo->rawsz),
the_repository->hash_algo);
use(the_hash_algo->rawsz);
break;
case OBJ_OFS_DELTA:
@ -1204,7 +1205,7 @@ static void parse_pack_objects(unsigned char *hash)
the_hash_algo->init_fn(&tmp_ctx);
the_hash_algo->clone_fn(&tmp_ctx, &input_ctx);
the_hash_algo->final_fn(hash, &tmp_ctx);
if (!hasheq(fill(the_hash_algo->rawsz), hash))
if (!hasheq(fill(the_hash_algo->rawsz), hash, the_repository->hash_algo))
die(_("pack is corrupted (SHA1 mismatch)"));
use(the_hash_algo->rawsz);
@ -1307,11 +1308,11 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha
stop_progress_msg(&progress, msg.buf);
strbuf_release(&msg);
finalize_hashfile(f, tail_hash, FSYNC_COMPONENT_PACK, 0);
hashcpy(read_hash, pack_hash);
hashcpy(read_hash, pack_hash, the_repository->hash_algo);
fixup_pack_header_footer(output_fd, pack_hash,
curr_pack, nr_objects,
read_hash, consumed_bytes-the_hash_algo->rawsz);
if (!hasheq(read_hash, tail_hash))
if (!hasheq(read_hash, tail_hash, the_repository->hash_algo))
die(_("Unexpected tail checksum for %s "
"(disk corruption?)"), curr_pack);
}
@ -1372,7 +1373,7 @@ static struct object_entry *append_obj_to_pack(struct hashfile *f,
obj[1].idx.offset += write_compressed(f, buf, size);
obj[0].idx.crc32 = crc32_end(f);
hashflush(f);
oidread(&obj->idx.oid, sha1);
oidread(&obj->idx.oid, sha1, the_repository->hash_algo);
return obj;
}

View File

@ -4,7 +4,7 @@
* (C) Copyright 2006 Linus Torvalds
* 2006 Junio Hamano
*/
#include "git-compat-util.h"
#include "builtin.h"
#include "abspath.h"
#include "config.h"
#include "environment.h"
@ -1938,7 +1938,7 @@ static void print_bases(struct base_tree_info *bases, FILE *file)
free(bases->patch_id);
bases->nr_patch_id = 0;
bases->alloc_patch_id = 0;
oidclr(&bases->base_commit);
oidclr(&bases->base_commit, the_repository->hash_algo);
}
static const char *diff_title(struct strbuf *sb,

View File

@ -330,7 +330,8 @@ static void read_empty(const struct object_id *oid)
{
struct child_process cmd = CHILD_PROCESS_INIT;
strvec_pushl(&cmd.args, "read-tree", "-m", "-u", empty_tree_oid_hex(),
strvec_pushl(&cmd.args, "read-tree", "-m", "-u",
empty_tree_oid_hex(the_repository->hash_algo),
oid_to_hex(oid), NULL);
cmd.git_cmd = 1;
@ -494,7 +495,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
strbuf_branchname(&bname, remote, 0);
remote = bname.buf;
oidclr(&branch_head);
oidclr(&branch_head, the_repository->hash_algo);
remote_head = get_merge_parent(remote);
if (!remote_head)
die(_("'%s' does not point to a commit"), remote);
@ -1692,7 +1693,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
* index and working tree polluted.
*/
if (save_state(&stash))
oidclr(&stash);
oidclr(&stash, the_repository->hash_algo);
for (i = 0; i < use_strategies_nr; i++) {
int ret, cnt;

View File

@ -828,7 +828,7 @@ static int merge_commit(struct notes_merge_options *o)
if (partial->parents)
oidcpy(&parent_oid, &partial->parents->item->object.oid);
else
oidclr(&parent_oid);
oidclr(&parent_oid, the_repository->hash_algo);
CALLOC_ARRAY(t, 1);
init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);

View File

@ -2079,7 +2079,8 @@ static void check_object(struct object_entry *entry, uint32_t object_index)
oidread(&base_ref,
use_pack(p, &w_curs,
entry->in_pack_offset + used,
NULL));
NULL),
the_repository->hash_algo);
have_base = 1;
}
entry->in_pack_header_size = used + the_hash_algo->rawsz;

View File

@ -100,7 +100,7 @@ static inline struct llist_item *llist_insert(struct llist *list,
const unsigned char *oid)
{
struct llist_item *new_item = llist_item_get();
oidread(&new_item->oid, oid);
oidread(&new_item->oid, oid, the_repository->hash_algo);
new_item->next = NULL;
if (after) {
@ -155,7 +155,7 @@ redo_from_start:
l = (hint == NULL) ? list->front : hint;
prev = NULL;
while (l) {
const int cmp = hashcmp(l->oid.hash, oid);
const int cmp = hashcmp(l->oid.hash, oid, the_repository->hash_algo);
if (cmp > 0) /* not in list, since sorted */
return prev;
if (!cmp) { /* found */
@ -258,7 +258,8 @@ static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
while (p1_off < p1->pack->num_objects * p1_step &&
p2_off < p2->pack->num_objects * p2_step)
{
const int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off);
const int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off,
the_repository->hash_algo);
/* cmp ~ p1 - p2 */
if (cmp == 0) {
p1_hint = llist_sorted_remove(p1->unique_objects,
@ -296,7 +297,8 @@ static size_t sizeof_union(struct packed_git *p1, struct packed_git *p2)
while (p1_off < p1->num_objects * p1_step &&
p2_off < p2->num_objects * p2_step)
{
int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off);
int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off,
the_repository->hash_algo);
/* cmp ~ p1 - p2 */
if (cmp == 0) {
ret++;

View File

@ -70,7 +70,7 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
git_hash_ctx ctx;
the_hash_algo->init_fn(&ctx);
oidclr(result);
oidclr(result, the_repository->hash_algo);
while (strbuf_getwholeline(line_buf, stdin, '\n') != EOF) {
char *line = line_buf->buf;
@ -166,7 +166,7 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
}
if (!found_next)
oidclr(next_oid);
oidclr(next_oid, the_repository->hash_algo);
flush_one_hunk(result, &ctx);
@ -179,7 +179,7 @@ static void generate_id_list(int stable, int verbatim)
int patchlen;
struct strbuf line_buf = STRBUF_INIT;
oidclr(&oid);
oidclr(&oid, the_repository->hash_algo);
while (!feof(stdin)) {
patchlen = get_one_patchid(&n, &result, &line_buf, stable, verbatim);
flush_current_id(patchlen, &oid, &result);

View File

@ -1038,7 +1038,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
die_conclude_merge();
if (repo_get_oid(the_repository, "HEAD", &orig_head))
oidclr(&orig_head);
oidclr(&orig_head, the_repository->hash_algo);
if (opt_rebase) {
if (opt_autostash == -1)
@ -1053,7 +1053,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
_("Please commit or stash them."), 1, 0);
if (get_rebase_fork_point(&rebase_fork_point, repo, *refspecs))
oidclr(&rebase_fork_point);
oidclr(&rebase_fork_point, the_repository->hash_algo);
}
if (run_fetch(repo, refspecs))
@ -1063,7 +1063,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
return 0;
if (repo_get_oid(the_repository, "HEAD", &curr_head))
oidclr(&curr_head);
oidclr(&curr_head, the_repository->hash_algo);
if (!is_null_oid(&orig_head) && !is_null_oid(&curr_head) &&
!oideq(&orig_head, &curr_head)) {

View File

@ -741,7 +741,7 @@ static void prepare_push_cert_sha1(struct child_process *proc)
already_done = 1;
if (write_object_file(push_cert.buf, push_cert.len, OBJ_BLOB,
&push_cert_oid))
oidclr(&push_cert_oid);
oidclr(&push_cert_oid, the_repository->hash_algo);
memset(&sigcheck, '\0', sizeof(sigcheck));
@ -1371,7 +1371,7 @@ static const char *push_to_deploy(unsigned char *sha1,
strvec_pushl(&child.args, "diff-index", "--quiet", "--cached",
"--ignore-submodules",
/* diff-index with either HEAD or an empty tree */
head_has_history() ? "HEAD" : empty_tree_oid_hex(),
head_has_history() ? "HEAD" : empty_tree_oid_hex(the_repository->hash_algo),
"--", NULL);
strvec_pushv(&child.env, env->v);
child.no_stdin = 1;

View File

@ -167,7 +167,7 @@ static int check_ref_valid(struct object_id *object,
return error(_("'%s' is not a valid ref name"), ref->buf);
if (refs_read_ref(get_main_ref_store(the_repository), ref->buf, prev))
oidclr(prev);
oidclr(prev, the_repository->hash_algo);
else if (!force)
return error(_("replace ref '%s' already exists"), ref->buf);
return 0;

View File

@ -377,7 +377,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
if (!force) {
struct object_id oid;
if (repo_get_oid(the_repository, "HEAD", &oid))
oidclr(&oid);
oidclr(&oid, the_repository->hash_algo);
if (check_local_mod(&oid, index_only))
exit(1);
}

View File

@ -650,7 +650,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
die(_("'%s' is not a valid tag name."), tag);
if (refs_read_ref(get_main_ref_store(the_repository), ref.buf, &prev))
oidclr(&prev);
oidclr(&prev, the_repository->hash_algo);
else if (!force)
die(_("tag '%s' already exists"), tag);

View File

@ -439,7 +439,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
struct object_id base_oid;
if (type == OBJ_REF_DELTA) {
oidread(&base_oid, fill(the_hash_algo->rawsz));
oidread(&base_oid, fill(the_hash_algo->rawsz), the_repository->hash_algo);
use(the_hash_algo->rawsz);
delta_data = get_data(delta_size);
if (!delta_data)
@ -451,7 +451,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
return; /* we are done */
else {
/* cannot resolve yet --- queue it */
oidclr(&obj_list[nr].oid);
oidclr(&obj_list[nr].oid, the_repository->hash_algo);
add_delta_to_list(nr, &base_oid, 0, delta_data, delta_size);
return;
}
@ -500,7 +500,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
* The delta base object is itself a delta that
* has not been resolved yet.
*/
oidclr(&obj_list[nr].oid);
oidclr(&obj_list[nr].oid, the_repository->hash_algo);
add_delta_to_list(nr, null_oid(), base_offset,
delta_data, delta_size);
return;
@ -674,7 +674,8 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix UNUSED)
if (fsck_finish(&fsck_options))
die(_("fsck error in pack objects"));
}
if (!hasheq(fill(the_hash_algo->rawsz), oid.hash))
if (!hasheq(fill(the_hash_algo->rawsz), oid.hash,
the_repository->hash_algo))
die("final sha1 did not match");
use(the_hash_algo->rawsz);

View File

@ -181,7 +181,7 @@ static int parse_next_oid(const char **next, const char *end,
goto invalid;
} else {
/* Without -z, an empty value means all zeros: */
oidclr(oid);
oidclr(oid, the_repository->hash_algo);
}
} else {
/* With -z, read the next NUL-terminated line */
@ -201,7 +201,7 @@ static int parse_next_oid(const char **next, const char *end,
/* With -z, treat an empty value as all zeros: */
warning("%s %s: missing <new-oid>, treating as zero",
command, refname);
oidclr(oid);
oidclr(oid, the_repository->hash_algo);
} else {
/*
* With -z, an empty non-required value means
@ -464,7 +464,7 @@ static void parse_cmd_verify(struct ref_transaction *transaction,
if (parse_next_oid(&next, end, &old_oid, "verify", refname,
PARSE_SHA1_OLD))
oidclr(&old_oid);
oidclr(&old_oid, the_repository->hash_algo);
if (*next != line_termination)
die("verify %s: extra input: %s", refname, next);
@ -777,7 +777,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
* The empty string implies that the reference
* must not already exist:
*/
oidclr(&oldoid);
oidclr(&oldoid, the_repository->hash_algo);
else if (repo_get_oid(the_repository, oldval, &oldoid))
die("%s: not a valid old SHA1", oldval);
}

View File

@ -1,6 +1,9 @@
/*
* Copyright (c) 2011, Google Inc.
*/
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "bulk-checkin.h"
#include "environment.h"

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "bundle-uri.h"
#include "bundle.h"

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "lockfile.h"
#include "bundle.h"

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "environment.h"
#include "hex.h"
@ -422,7 +424,7 @@ static int update_one(struct cache_tree *it,
/*
* "sub" can be an empty tree if all subentries are i-t-a.
*/
if (contains_ita && is_empty_tree_oid(oid))
if (contains_ita && is_empty_tree_oid(oid, the_repository->hash_algo))
continue;
strbuf_grow(&buffer, entlen + 100);
@ -578,7 +580,8 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
if (0 <= it->entry_count) {
if (size < rawsz)
goto free_return;
oidread(&it->oid, (const unsigned char *)buf);
oidread(&it->oid, (const unsigned char *)buf,
the_repository->hash_algo);
buf += rawsz;
size -= rawsz;
}

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "object-name.h"
#include "remote.h"

View File

@ -1,7 +1,7 @@
#ifndef CHECKOUT_H
#define CHECKOUT_H
#include "hash-ll.h"
#include "hash.h"
/*
* Check if the branch name uniquely matches a branch name on a remote

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "chunk-format.h"
#include "csum-file.h"

View File

@ -1,7 +1,7 @@
#ifndef CHUNK_FORMAT_H
#define CHUNK_FORMAT_H
#include "hash-ll.h"
#include "hash.h"
struct hashfile;
struct chunkfile;

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "object-store-ll.h"
#include "commit.h"

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "config.h"
#include "csum-file.h"
@ -475,7 +477,8 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s,
FREE_AND_NULL(graph->bloom_filter_settings);
}
oidread(&graph->oid, graph->data + graph->data_len - graph->hash_len);
oidread(&graph->oid, graph->data + graph->data_len - graph->hash_len,
the_repository->hash_algo);
free_chunkfile(cf);
return graph;
@ -565,7 +568,8 @@ static int add_graph_to_chain(struct commit_graph *g,
if (!cur_g ||
!oideq(&oids[n], &cur_g->oid) ||
!hasheq(oids[n].hash, g->chunk_base_graphs + st_mult(g->hash_len, n))) {
!hasheq(oids[n].hash, g->chunk_base_graphs + st_mult(g->hash_len, n),
the_repository->hash_algo)) {
warning(_("commit-graph chain does not match"));
return 0;
}
@ -837,7 +841,8 @@ static void load_oid_from_graph(struct commit_graph *g,
lex_index = pos - g->num_commits_in_base;
oidread(oid, g->chunk_oid_lookup + st_mult(g->hash_len, lex_index));
oidread(oid, g->chunk_oid_lookup + st_mult(g->hash_len, lex_index),
the_repository->hash_algo);
}
static struct commit_list **insert_parent_or_die(struct repository *r,
@ -1079,7 +1084,7 @@ static struct tree *load_tree_for_commit(struct repository *r,
commit_data = g->chunk_commit_data +
st_mult(GRAPH_DATA_WIDTH, graph_pos - g->num_commits_in_base);
oidread(&oid, commit_data);
oidread(&oid, commit_data, the_repository->hash_algo);
set_commit_tree(c, lookup_tree(r, &oid));
return c->maybe_tree;
@ -2552,7 +2557,8 @@ int write_commit_graph(struct object_directory *odb,
struct commit_graph *g = ctx->r->objects->commit_graph;
for (i = 0; i < g->num_commits; i++) {
struct object_id oid;
oidread(&oid, g->chunk_oid_lookup + st_mult(g->hash_len, i));
oidread(&oid, g->chunk_oid_lookup + st_mult(g->hash_len, i),
the_repository->hash_algo);
oid_array_append(&ctx->oids, &oid);
}
}
@ -2671,7 +2677,8 @@ static int verify_one_commit_graph(struct repository *r,
for (i = 0; i < g->num_commits; i++) {
struct commit *graph_commit;
oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i));
oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i),
the_repository->hash_algo);
if (i && oidcmp(&prev_oid, &cur_oid) >= 0)
graph_report(_("commit-graph has incorrect OID order: %s then %s"),
@ -2715,7 +2722,8 @@ static int verify_one_commit_graph(struct repository *r,
timestamp_t generation;
display_progress(progress, ++(*seen));
oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i));
oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i),
the_repository->hash_algo);
graph_commit = lookup_commit(r, &cur_oid);
odb_commit = (struct commit *)create_object(r, &cur_oid, alloc_commit_node(r));

View File

@ -122,6 +122,8 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
struct commit_graph *read_commit_graph_one(struct repository *r,
struct object_directory *odb);
struct repo_settings;
/*
* Callers should initialize the repo_settings with prepare_repo_settings()
* prior to calling parse_commit_graph().

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "commit.h"
#include "commit-graph.h"

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "tag.h"
#include "commit.h"

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "exec-cmd.h"
#include "gettext.h"

View File

@ -17,7 +17,7 @@ const char *fsmonitor_ipc__get_path(struct repository *r)
git_SHA_CTX sha1ctx;
char *sock_dir = NULL;
struct strbuf ipc_file = STRBUF_INIT;
unsigned char hash[GIT_MAX_RAWSZ];
unsigned char hash[GIT_SHA1_RAWSZ];
if (!r)
BUG("No repository passed into fsmonitor_ipc__get_path");
@ -41,9 +41,10 @@ const char *fsmonitor_ipc__get_path(struct repository *r)
/* Create the socket file in either socketDir or $HOME */
if (sock_dir && *sock_dir) {
strbuf_addf(&ipc_file, "%s/.git-fsmonitor-%s",
sock_dir, hash_to_hex(hash));
sock_dir, hash_to_hex_algop(hash, &hash_algos[GIT_HASH_SHA1]));
} else {
strbuf_addf(&ipc_file, "~/.git-fsmonitor-%s", hash_to_hex(hash));
strbuf_addf(&ipc_file, "~/.git-fsmonitor-%s",
hash_to_hex_algop(hash, &hash_algos[GIT_HASH_SHA1]));
}
free(sock_dir);

View File

@ -1,5 +1,5 @@
#include "git-compat-util.h"
#include "hash-ll.h"
#include "hash.h"
int git_SHA1_Update_Chunked(platform_SHA_CTX *c, const void *data, size_t len)
{

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "../../git-compat-util.h"
#include "../../json-writer.h"
#include "../../repository.h"

View File

@ -5,6 +5,9 @@
* Copyright (C) Johannes Schindelin, 2005
*
*/
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "abspath.h"
#include "advice.h"

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "advice.h"
#include "config.h"

View File

@ -4,7 +4,7 @@
#ifndef CONVERT_H
#define CONVERT_H
#include "hash-ll.h"
#include "hash.h"
#include "string-list.h"
struct index_state;

View File

@ -7,6 +7,9 @@
* files. Useful when you write a file that you want to be
* able to verify hasn't been messed with afterwards.
*/
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "progress.h"
#include "csum-file.h"
@ -68,12 +71,12 @@ int finalize_hashfile(struct hashfile *f, unsigned char *result,
hashflush(f);
if (f->skip_hash)
hashclr(f->buffer);
hashclr(f->buffer, the_repository->hash_algo);
else
the_hash_algo->final_fn(f->buffer, &f->ctx);
if (result)
hashcpy(result, f->buffer);
hashcpy(result, f->buffer, the_repository->hash_algo);
if (flags & CSUM_HASH_IN_STREAM)
flush(f, f->buffer, the_hash_algo->rawsz);
if (flags & CSUM_FSYNC)
@ -237,5 +240,5 @@ int hashfile_checksum_valid(const unsigned char *data, size_t total_len)
the_hash_algo->update_fn(&ctx, data, data_len);
the_hash_algo->final_fn(got, &ctx);
return hasheq(got, data + data_len);
return hasheq(got, data + data_len, the_repository->hash_algo);
}

View File

@ -1,7 +1,7 @@
#ifndef CSUM_FILE_H
#define CSUM_FILE_H
#include "hash-ll.h"
#include "hash.h"
#include "write-or-die.h"
struct progress;

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "object.h"
#include "commit.h"

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "diagnose.h"
#include "compat/disk.h"

View File

@ -1,6 +1,9 @@
/*
* Copyright (C) 2005 Junio C Hamano
*/
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "commit.h"
#include "diff.h"
@ -160,7 +163,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
dpath->next = NULL;
memcpy(dpath->path, ce->name, path_len);
dpath->path[path_len] = '\0';
oidclr(&dpath->oid);
oidclr(&dpath->oid, the_repository->hash_algo);
memset(&(dpath->parent[0]), 0,
sizeof(struct combine_diff_parent)*5);
@ -412,7 +415,7 @@ static int show_modified(struct rev_info *revs,
memcpy(p->path, new_entry->name, pathlen);
p->path[pathlen] = 0;
p->mode = mode;
oidclr(&p->oid);
oidclr(&p->oid, the_repository->hash_algo);
memset(p->parent, 0, 2 * sizeof(struct combine_diff_parent));
p->parent[0].status = DIFF_STATUS_MODIFIED;
p->parent[0].mode = new_entry->ce_mode;

9
diff.c
View File

@ -1,6 +1,9 @@
/*
* Copyright (C) 2005 Junio C Hamano
*/
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "abspath.h"
#include "base85.h"
@ -4596,7 +4599,7 @@ static void diff_fill_oid_info(struct diff_filespec *one, struct index_state *is
if (!one->oid_valid) {
struct stat st;
if (one->is_stdin) {
oidclr(&one->oid);
oidclr(&one->oid, the_repository->hash_algo);
return;
}
if (lstat(one->path, &st) < 0)
@ -4606,7 +4609,7 @@ static void diff_fill_oid_info(struct diff_filespec *one, struct index_state *is
}
}
else
oidclr(&one->oid);
oidclr(&one->oid, the_repository->hash_algo);
}
static void strip_prefix(int prefix_length, const char **namep, const char **otherp)
@ -6440,7 +6443,7 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
the_hash_algo->init_fn(&ctx);
memset(&data, 0, sizeof(struct patch_id_t));
data.ctx = &ctx;
oidclr(oid);
oidclr(oid, the_repository->hash_algo);
for (i = 0; i < q->nr; i++) {
xpparam_t xpp;

2
diff.h
View File

@ -4,7 +4,7 @@
#ifndef DIFF_H
#define DIFF_H
#include "hash-ll.h"
#include "hash.h"
#include "pathspec.h"
#include "strbuf.h"

View File

@ -1,6 +1,9 @@
/*
* Copyright (C) 2005 Junio C Hamano
*/
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "diffcore.h"
#include "hash.h"

View File

@ -2,6 +2,9 @@
*
* Copyright (C) 2005 Junio C Hamano
*/
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "diff.h"
#include "diffcore.h"
@ -1422,7 +1425,7 @@ void diffcore_rename_extended(struct diff_options *options,
strcmp(options->single_follow, p->two->path))
continue; /* not interested */
else if (!options->flags.rename_empty &&
is_empty_blob_oid(&p->two->oid))
is_empty_blob_oid(&p->two->oid, the_repository->hash_algo))
continue;
else if (add_rename_dst(p) < 0) {
warning("skipping rename detection, detected"
@ -1432,7 +1435,7 @@ void diffcore_rename_extended(struct diff_options *options,
}
}
else if (!options->flags.rename_empty &&
is_empty_blob_oid(&p->one->oid))
is_empty_blob_oid(&p->one->oid, the_repository->hash_algo))
continue;
else if (!DIFF_PAIR_UNMERGED(p) && !DIFF_FILE_VALID(p->two)) {
/*

View File

@ -4,7 +4,7 @@
#ifndef DIFFCORE_H
#define DIFFCORE_H
#include "hash-ll.h"
#include "hash.h"
struct diff_options;
struct mem_pool;

9
dir.c
View File

@ -5,6 +5,9 @@
* Copyright (C) Linus Torvalds, 2005-2006
* Junio Hamano, 2005-2006
*/
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "abspath.h"
#include "config.h"
@ -1687,7 +1690,7 @@ static void prep_exclude(struct dir_struct *dir,
}
/* Try to read per-directory file */
oidclr(&oid_stat.oid);
oidclr(&oid_stat.oid, the_repository->hash_algo);
oid_stat.valid = 0;
if (dir->exclude_per_dir &&
/*
@ -3794,7 +3797,7 @@ static void read_oid(size_t pos, void *cb)
rd->data = rd->end + 1;
return;
}
oidread(&ud->exclude_oid, rd->data);
oidread(&ud->exclude_oid, rd->data, the_repository->hash_algo);
rd->data += the_hash_algo->rawsz;
}
@ -3802,7 +3805,7 @@ static void load_oid_stat(struct oid_stat *oid_stat, const unsigned char *data,
const unsigned char *sha1)
{
stat_data_from_disk(&oid_stat->stat, data);
oidread(&oid_stat->oid, sha1);
oidread(&oid_stat->oid, sha1, the_repository->hash_algo);
oid_stat->valid = 1;
}

2
dir.h
View File

@ -1,7 +1,7 @@
#ifndef DIR_H
#define DIR_H
#include "hash-ll.h"
#include "hash.h"
#include "hashmap.h"
#include "pathspec.h"
#include "statinfo.h"

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "object-store-ll.h"
#include "dir.h"

View File

@ -7,6 +7,9 @@
* even if you might want to know where the git directory etc
* are.
*/
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "abspath.h"
#include "branch.h"

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "repository.h"
#include "config.h"

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "config.h"
#include "environment.h"

5
fsck.c
View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "date.h"
#include "dir.h"
@ -203,7 +205,8 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
if (!strcmp(buf, "skiplist")) {
if (equal == len)
die("skiplist requires a path");
oidset_parse_file(&options->skiplist, buf + equal + 1);
oidset_parse_file(&options->skiplist, buf + equal + 1,
the_repository->hash_algo);
buf += len + 1;
continue;
}

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "gettext.h"
#include "simple-ipc.h"

2
git.c
View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "builtin.h"
#include "config.h"
#include "environment.h"

310
hash-ll.h
View File

@ -1,310 +0,0 @@
#ifndef HASH_LL_H
#define HASH_LL_H
#if defined(SHA1_APPLE)
#include <CommonCrypto/CommonDigest.h>
#elif defined(SHA1_OPENSSL)
# include <openssl/sha.h>
# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
# define SHA1_NEEDS_CLONE_HELPER
# include "sha1/openssl.h"
# endif
#elif defined(SHA1_DC)
#include "sha1dc_git.h"
#else /* SHA1_BLK */
#include "block-sha1/sha1.h"
#endif
#if defined(SHA256_NETTLE)
#include "sha256/nettle.h"
#elif defined(SHA256_GCRYPT)
#define SHA256_NEEDS_CLONE_HELPER
#include "sha256/gcrypt.h"
#elif defined(SHA256_OPENSSL)
# include <openssl/sha.h>
# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
# define SHA256_NEEDS_CLONE_HELPER
# include "sha256/openssl.h"
# endif
#else
#include "sha256/block/sha256.h"
#endif
#ifndef platform_SHA_CTX
/*
* platform's underlying implementation of SHA-1; could be OpenSSL,
* blk_SHA, Apple CommonCrypto, etc... Note that the relevant
* SHA-1 header may have already defined platform_SHA_CTX for our
* own implementations like block-sha1, so we list
* the default for OpenSSL compatible SHA-1 implementations here.
*/
#define platform_SHA_CTX SHA_CTX
#define platform_SHA1_Init SHA1_Init
#define platform_SHA1_Update SHA1_Update
#define platform_SHA1_Final SHA1_Final
#endif
#define git_SHA_CTX platform_SHA_CTX
#define git_SHA1_Init platform_SHA1_Init
#define git_SHA1_Update platform_SHA1_Update
#define git_SHA1_Final platform_SHA1_Final
#ifdef platform_SHA1_Clone
#define git_SHA1_Clone platform_SHA1_Clone
#endif
#ifndef platform_SHA256_CTX
#define platform_SHA256_CTX SHA256_CTX
#define platform_SHA256_Init SHA256_Init
#define platform_SHA256_Update SHA256_Update
#define platform_SHA256_Final SHA256_Final
#endif
#define git_SHA256_CTX platform_SHA256_CTX
#define git_SHA256_Init platform_SHA256_Init
#define git_SHA256_Update platform_SHA256_Update
#define git_SHA256_Final platform_SHA256_Final
#ifdef platform_SHA256_Clone
#define git_SHA256_Clone platform_SHA256_Clone
#endif
#ifdef SHA1_MAX_BLOCK_SIZE
#include "compat/sha1-chunked.h"
#undef git_SHA1_Update
#define git_SHA1_Update git_SHA1_Update_Chunked
#endif
#ifndef SHA1_NEEDS_CLONE_HELPER
static inline void git_SHA1_Clone(git_SHA_CTX *dst, const git_SHA_CTX *src)
{
memcpy(dst, src, sizeof(*dst));
}
#endif
#ifndef SHA256_NEEDS_CLONE_HELPER
static inline void git_SHA256_Clone(git_SHA256_CTX *dst, const git_SHA256_CTX *src)
{
memcpy(dst, src, sizeof(*dst));
}
#endif
/*
* Note that these constants are suitable for indexing the hash_algos array and
* comparing against each other, but are otherwise arbitrary, so they should not
* be exposed to the user or serialized to disk. To know whether a
* git_hash_algo struct points to some usable hash function, test the format_id
* field for being non-zero. Use the name field for user-visible situations and
* the format_id field for fixed-length fields on disk.
*/
/* An unknown hash function. */
#define GIT_HASH_UNKNOWN 0
/* SHA-1 */
#define GIT_HASH_SHA1 1
/* SHA-256 */
#define GIT_HASH_SHA256 2
/* Number of algorithms supported (including unknown). */
#define GIT_HASH_NALGOS (GIT_HASH_SHA256 + 1)
/* "sha1", big-endian */
#define GIT_SHA1_FORMAT_ID 0x73686131
/* The length in bytes and in hex digits of an object name (SHA-1 value). */
#define GIT_SHA1_RAWSZ 20
#define GIT_SHA1_HEXSZ (2 * GIT_SHA1_RAWSZ)
/* The block size of SHA-1. */
#define GIT_SHA1_BLKSZ 64
/* "s256", big-endian */
#define GIT_SHA256_FORMAT_ID 0x73323536
/* The length in bytes and in hex digits of an object name (SHA-256 value). */
#define GIT_SHA256_RAWSZ 32
#define GIT_SHA256_HEXSZ (2 * GIT_SHA256_RAWSZ)
/* The block size of SHA-256. */
#define GIT_SHA256_BLKSZ 64
/* The length in byte and in hex digits of the largest possible hash value. */
#define GIT_MAX_RAWSZ GIT_SHA256_RAWSZ
#define GIT_MAX_HEXSZ GIT_SHA256_HEXSZ
/* The largest possible block size for any supported hash. */
#define GIT_MAX_BLKSZ GIT_SHA256_BLKSZ
struct object_id {
unsigned char hash[GIT_MAX_RAWSZ];
int algo; /* XXX requires 4-byte alignment */
};
#define GET_OID_QUIETLY 01
#define GET_OID_COMMIT 02
#define GET_OID_COMMITTISH 04
#define GET_OID_TREE 010
#define GET_OID_TREEISH 020
#define GET_OID_BLOB 040
#define GET_OID_FOLLOW_SYMLINKS 0100
#define GET_OID_RECORD_PATH 0200
#define GET_OID_ONLY_TO_DIE 04000
#define GET_OID_REQUIRE_PATH 010000
#define GET_OID_HASH_ANY 020000
#define GET_OID_DISAMBIGUATORS \
(GET_OID_COMMIT | GET_OID_COMMITTISH | \
GET_OID_TREE | GET_OID_TREEISH | \
GET_OID_BLOB)
enum get_oid_result {
FOUND = 0,
MISSING_OBJECT = -1, /* The requested object is missing */
SHORT_NAME_AMBIGUOUS = -2,
/* The following only apply when symlinks are followed */
DANGLING_SYMLINK = -4, /*
* The initial symlink is there, but
* (transitively) points to a missing
* in-tree file
*/
SYMLINK_LOOP = -5,
NOT_DIR = -6, /*
* Somewhere along the symlink chain, a path is
* requested which contains a file as a
* non-final element.
*/
};
/* A suitably aligned type for stack allocations of hash contexts. */
union git_hash_ctx {
git_SHA_CTX sha1;
git_SHA256_CTX sha256;
};
typedef union git_hash_ctx git_hash_ctx;
typedef void (*git_hash_init_fn)(git_hash_ctx *ctx);
typedef void (*git_hash_clone_fn)(git_hash_ctx *dst, const git_hash_ctx *src);
typedef void (*git_hash_update_fn)(git_hash_ctx *ctx, const void *in, size_t len);
typedef void (*git_hash_final_fn)(unsigned char *hash, git_hash_ctx *ctx);
typedef void (*git_hash_final_oid_fn)(struct object_id *oid, git_hash_ctx *ctx);
struct git_hash_algo {
/*
* The name of the algorithm, as appears in the config file and in
* messages.
*/
const char *name;
/* A four-byte version identifier, used in pack indices. */
uint32_t format_id;
/* The length of the hash in binary. */
size_t rawsz;
/* The length of the hash in hex characters. */
size_t hexsz;
/* The block size of the hash. */
size_t blksz;
/* The hash initialization function. */
git_hash_init_fn init_fn;
/* The hash context cloning function. */
git_hash_clone_fn clone_fn;
/* The hash update function. */
git_hash_update_fn update_fn;
/* The hash finalization function. */
git_hash_final_fn final_fn;
/* The hash finalization function for object IDs. */
git_hash_final_oid_fn final_oid_fn;
/* The OID of the empty tree. */
const struct object_id *empty_tree;
/* The OID of the empty blob. */
const struct object_id *empty_blob;
/* The all-zeros OID. */
const struct object_id *null_oid;
};
extern const struct git_hash_algo hash_algos[GIT_HASH_NALGOS];
/*
* Return a GIT_HASH_* constant based on the name. Returns GIT_HASH_UNKNOWN if
* the name doesn't match a known algorithm.
*/
int hash_algo_by_name(const char *name);
/* Identical, except based on the format ID. */
int hash_algo_by_id(uint32_t format_id);
/* Identical, except based on the length. */
int hash_algo_by_length(int len);
/* Identical, except for a pointer to struct git_hash_algo. */
static inline int hash_algo_by_ptr(const struct git_hash_algo *p)
{
return p - hash_algos;
}
const struct object_id *null_oid(void);
static inline int hashcmp_algop(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
{
/*
* Teach the compiler that there are only two possibilities of hash size
* here, so that it can optimize for this case as much as possible.
*/
if (algop->rawsz == GIT_MAX_RAWSZ)
return memcmp(sha1, sha2, GIT_MAX_RAWSZ);
return memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
}
static inline int hasheq_algop(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
{
/*
* We write this here instead of deferring to hashcmp so that the
* compiler can properly inline it and avoid calling memcmp.
*/
if (algop->rawsz == GIT_MAX_RAWSZ)
return !memcmp(sha1, sha2, GIT_MAX_RAWSZ);
return !memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
}
static inline void oidcpy(struct object_id *dst, const struct object_id *src)
{
memcpy(dst->hash, src->hash, GIT_MAX_RAWSZ);
dst->algo = src->algo;
}
static inline struct object_id *oiddup(const struct object_id *src)
{
struct object_id *dst = xmalloc(sizeof(struct object_id));
oidcpy(dst, src);
return dst;
}
static inline void oid_set_algo(struct object_id *oid, const struct git_hash_algo *algop)
{
oid->algo = hash_algo_by_ptr(algop);
}
/*
* Converts a cryptographic hash (e.g. SHA-1) into an int-sized hash code
* for use in hash tables. Cryptographic hashes are supposed to have
* uniform distribution, so in contrast to `memhash()`, this just copies
* the first `sizeof(int)` bytes without shuffling any bits. Note that
* the results will be different on big-endian and little-endian
* platforms, so they should not be stored or transferred over the net.
*/
static inline unsigned int oidhash(const struct object_id *oid)
{
/*
* Equivalent to 'return *(unsigned int *)oid->hash;', but safe on
* platforms that don't support unaligned reads.
*/
unsigned int hash;
memcpy(&hash, oid->hash, sizeof(hash));
return hash;
}
const char *empty_tree_oid_hex(void);
const char *empty_blob_oid_hex(void);
#endif

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "hash.h"
#include "hash-lookup.h"
@ -112,7 +114,8 @@ int bsearch_hash(const unsigned char *hash, const uint32_t *fanout_nbo,
while (lo < hi) {
unsigned mi = lo + (hi - lo) / 2;
int cmp = hashcmp(table + mi * stride, hash);
int cmp = hashcmp(table + mi * stride, hash,
the_repository->hash_algo);
if (!cmp) {
if (result)

422
hash.h
View File

@ -1,107 +1,369 @@
#ifndef HASH_H
#define HASH_H
#include "hash-ll.h"
#include "repository.h"
#if defined(SHA1_APPLE)
#include <CommonCrypto/CommonDigest.h>
#elif defined(SHA1_OPENSSL)
# include <openssl/sha.h>
# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
# define SHA1_NEEDS_CLONE_HELPER
# include "sha1/openssl.h"
# endif
#elif defined(SHA1_DC)
#include "sha1dc_git.h"
#else /* SHA1_BLK */
#include "block-sha1/sha1.h"
#endif
#define the_hash_algo the_repository->hash_algo
#if defined(SHA256_NETTLE)
#include "sha256/nettle.h"
#elif defined(SHA256_GCRYPT)
#define SHA256_NEEDS_CLONE_HELPER
#include "sha256/gcrypt.h"
#elif defined(SHA256_OPENSSL)
# include <openssl/sha.h>
# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
# define SHA256_NEEDS_CLONE_HELPER
# include "sha256/openssl.h"
# endif
#else
#include "sha256/block/sha256.h"
#endif
static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
#ifndef platform_SHA_CTX
/*
* platform's underlying implementation of SHA-1; could be OpenSSL,
* blk_SHA, Apple CommonCrypto, etc... Note that the relevant
* SHA-1 header may have already defined platform_SHA_CTX for our
* own implementations like block-sha1, so we list
* the default for OpenSSL compatible SHA-1 implementations here.
*/
#define platform_SHA_CTX SHA_CTX
#define platform_SHA1_Init SHA1_Init
#define platform_SHA1_Update SHA1_Update
#define platform_SHA1_Final SHA1_Final
#endif
#define git_SHA_CTX platform_SHA_CTX
#define git_SHA1_Init platform_SHA1_Init
#define git_SHA1_Update platform_SHA1_Update
#define git_SHA1_Final platform_SHA1_Final
#ifdef platform_SHA1_Clone
#define git_SHA1_Clone platform_SHA1_Clone
#endif
#ifndef platform_SHA256_CTX
#define platform_SHA256_CTX SHA256_CTX
#define platform_SHA256_Init SHA256_Init
#define platform_SHA256_Update SHA256_Update
#define platform_SHA256_Final SHA256_Final
#endif
#define git_SHA256_CTX platform_SHA256_CTX
#define git_SHA256_Init platform_SHA256_Init
#define git_SHA256_Update platform_SHA256_Update
#define git_SHA256_Final platform_SHA256_Final
#ifdef platform_SHA256_Clone
#define git_SHA256_Clone platform_SHA256_Clone
#endif
#ifdef SHA1_MAX_BLOCK_SIZE
#include "compat/sha1-chunked.h"
#undef git_SHA1_Update
#define git_SHA1_Update git_SHA1_Update_Chunked
#endif
#ifndef SHA1_NEEDS_CLONE_HELPER
static inline void git_SHA1_Clone(git_SHA_CTX *dst, const git_SHA_CTX *src)
{
return hashcmp_algop(sha1, sha2, the_hash_algo);
memcpy(dst, src, sizeof(*dst));
}
#endif
#ifndef SHA256_NEEDS_CLONE_HELPER
static inline void git_SHA256_Clone(git_SHA256_CTX *dst, const git_SHA256_CTX *src)
{
memcpy(dst, src, sizeof(*dst));
}
#endif
/*
* Note that these constants are suitable for indexing the hash_algos array and
* comparing against each other, but are otherwise arbitrary, so they should not
* be exposed to the user or serialized to disk. To know whether a
* git_hash_algo struct points to some usable hash function, test the format_id
* field for being non-zero. Use the name field for user-visible situations and
* the format_id field for fixed-length fields on disk.
*/
/* An unknown hash function. */
#define GIT_HASH_UNKNOWN 0
/* SHA-1 */
#define GIT_HASH_SHA1 1
/* SHA-256 */
#define GIT_HASH_SHA256 2
/* Number of algorithms supported (including unknown). */
#define GIT_HASH_NALGOS (GIT_HASH_SHA256 + 1)
/* "sha1", big-endian */
#define GIT_SHA1_FORMAT_ID 0x73686131
/* The length in bytes and in hex digits of an object name (SHA-1 value). */
#define GIT_SHA1_RAWSZ 20
#define GIT_SHA1_HEXSZ (2 * GIT_SHA1_RAWSZ)
/* The block size of SHA-1. */
#define GIT_SHA1_BLKSZ 64
/* "s256", big-endian */
#define GIT_SHA256_FORMAT_ID 0x73323536
/* The length in bytes and in hex digits of an object name (SHA-256 value). */
#define GIT_SHA256_RAWSZ 32
#define GIT_SHA256_HEXSZ (2 * GIT_SHA256_RAWSZ)
/* The block size of SHA-256. */
#define GIT_SHA256_BLKSZ 64
/* The length in byte and in hex digits of the largest possible hash value. */
#define GIT_MAX_RAWSZ GIT_SHA256_RAWSZ
#define GIT_MAX_HEXSZ GIT_SHA256_HEXSZ
/* The largest possible block size for any supported hash. */
#define GIT_MAX_BLKSZ GIT_SHA256_BLKSZ
struct object_id {
unsigned char hash[GIT_MAX_RAWSZ];
int algo; /* XXX requires 4-byte alignment */
};
#define GET_OID_QUIETLY 01
#define GET_OID_COMMIT 02
#define GET_OID_COMMITTISH 04
#define GET_OID_TREE 010
#define GET_OID_TREEISH 020
#define GET_OID_BLOB 040
#define GET_OID_FOLLOW_SYMLINKS 0100
#define GET_OID_RECORD_PATH 0200
#define GET_OID_ONLY_TO_DIE 04000
#define GET_OID_REQUIRE_PATH 010000
#define GET_OID_HASH_ANY 020000
#define GET_OID_DISAMBIGUATORS \
(GET_OID_COMMIT | GET_OID_COMMITTISH | \
GET_OID_TREE | GET_OID_TREEISH | \
GET_OID_BLOB)
enum get_oid_result {
FOUND = 0,
MISSING_OBJECT = -1, /* The requested object is missing */
SHORT_NAME_AMBIGUOUS = -2,
/* The following only apply when symlinks are followed */
DANGLING_SYMLINK = -4, /*
* The initial symlink is there, but
* (transitively) points to a missing
* in-tree file
*/
SYMLINK_LOOP = -5,
NOT_DIR = -6, /*
* Somewhere along the symlink chain, a path is
* requested which contains a file as a
* non-final element.
*/
};
#ifdef USE_THE_REPOSITORY_VARIABLE
# include "repository.h"
# define the_hash_algo the_repository->hash_algo
#endif
/* A suitably aligned type for stack allocations of hash contexts. */
union git_hash_ctx {
git_SHA_CTX sha1;
git_SHA256_CTX sha256;
};
typedef union git_hash_ctx git_hash_ctx;
typedef void (*git_hash_init_fn)(git_hash_ctx *ctx);
typedef void (*git_hash_clone_fn)(git_hash_ctx *dst, const git_hash_ctx *src);
typedef void (*git_hash_update_fn)(git_hash_ctx *ctx, const void *in, size_t len);
typedef void (*git_hash_final_fn)(unsigned char *hash, git_hash_ctx *ctx);
typedef void (*git_hash_final_oid_fn)(struct object_id *oid, git_hash_ctx *ctx);
struct git_hash_algo {
/*
* The name of the algorithm, as appears in the config file and in
* messages.
*/
const char *name;
/* A four-byte version identifier, used in pack indices. */
uint32_t format_id;
/* The length of the hash in binary. */
size_t rawsz;
/* The length of the hash in hex characters. */
size_t hexsz;
/* The block size of the hash. */
size_t blksz;
/* The hash initialization function. */
git_hash_init_fn init_fn;
/* The hash context cloning function. */
git_hash_clone_fn clone_fn;
/* The hash update function. */
git_hash_update_fn update_fn;
/* The hash finalization function. */
git_hash_final_fn final_fn;
/* The hash finalization function for object IDs. */
git_hash_final_oid_fn final_oid_fn;
/* The OID of the empty tree. */
const struct object_id *empty_tree;
/* The OID of the empty blob. */
const struct object_id *empty_blob;
/* The all-zeros OID. */
const struct object_id *null_oid;
};
extern const struct git_hash_algo hash_algos[GIT_HASH_NALGOS];
/*
* Return a GIT_HASH_* constant based on the name. Returns GIT_HASH_UNKNOWN if
* the name doesn't match a known algorithm.
*/
int hash_algo_by_name(const char *name);
/* Identical, except based on the format ID. */
int hash_algo_by_id(uint32_t format_id);
/* Identical, except based on the length. */
int hash_algo_by_length(int len);
/* Identical, except for a pointer to struct git_hash_algo. */
static inline int hash_algo_by_ptr(const struct git_hash_algo *p)
{
return p - hash_algos;
}
const struct object_id *null_oid(void);
static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
{
/*
* Teach the compiler that there are only two possibilities of hash size
* here, so that it can optimize for this case as much as possible.
*/
if (algop->rawsz == GIT_MAX_RAWSZ)
return memcmp(sha1, sha2, GIT_MAX_RAWSZ);
return memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
}
static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
{
/*
* We write this here instead of deferring to hashcmp so that the
* compiler can properly inline it and avoid calling memcmp.
*/
if (algop->rawsz == GIT_MAX_RAWSZ)
return !memcmp(sha1, sha2, GIT_MAX_RAWSZ);
return !memcmp(sha1, sha2, GIT_SHA1_RAWSZ);
}
static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src,
const struct git_hash_algo *algop)
{
memcpy(sha_dst, sha_src, algop->rawsz);
}
static inline void hashclr(unsigned char *hash, const struct git_hash_algo *algop)
{
memset(hash, 0, algop->rawsz);
}
static inline int oidcmp(const struct object_id *oid1, const struct object_id *oid2)
{
const struct git_hash_algo *algop;
if (!oid1->algo)
algop = the_hash_algo;
else
algop = &hash_algos[oid1->algo];
return hashcmp_algop(oid1->hash, oid2->hash, algop);
}
static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2)
{
return hasheq_algop(sha1, sha2, the_hash_algo);
return memcmp(oid1->hash, oid2->hash, GIT_MAX_RAWSZ);
}
static inline int oideq(const struct object_id *oid1, const struct object_id *oid2)
{
const struct git_hash_algo *algop;
if (!oid1->algo)
algop = the_hash_algo;
else
algop = &hash_algos[oid1->algo];
return hasheq_algop(oid1->hash, oid2->hash, algop);
return !memcmp(oid1->hash, oid2->hash, GIT_MAX_RAWSZ);
}
static inline void oidcpy(struct object_id *dst, const struct object_id *src)
{
memcpy(dst->hash, src->hash, GIT_MAX_RAWSZ);
dst->algo = src->algo;
}
static inline void oidread(struct object_id *oid, const unsigned char *hash,
const struct git_hash_algo *algop)
{
memcpy(oid->hash, hash, algop->rawsz);
if (algop->rawsz < GIT_MAX_RAWSZ)
memset(oid->hash + algop->rawsz, 0, GIT_MAX_RAWSZ - algop->rawsz);
oid->algo = hash_algo_by_ptr(algop);
}
static inline void oidclr(struct object_id *oid,
const struct git_hash_algo *algop)
{
memset(oid->hash, 0, GIT_MAX_RAWSZ);
oid->algo = hash_algo_by_ptr(algop);
}
static inline struct object_id *oiddup(const struct object_id *src)
{
struct object_id *dst = xmalloc(sizeof(struct object_id));
oidcpy(dst, src);
return dst;
}
static inline void oid_set_algo(struct object_id *oid, const struct git_hash_algo *algop)
{
oid->algo = hash_algo_by_ptr(algop);
}
/*
* Converts a cryptographic hash (e.g. SHA-1) into an int-sized hash code
* for use in hash tables. Cryptographic hashes are supposed to have
* uniform distribution, so in contrast to `memhash()`, this just copies
* the first `sizeof(int)` bytes without shuffling any bits. Note that
* the results will be different on big-endian and little-endian
* platforms, so they should not be stored or transferred over the net.
*/
static inline unsigned int oidhash(const struct object_id *oid)
{
/*
* Equivalent to 'return *(unsigned int *)oid->hash;', but safe on
* platforms that don't support unaligned reads.
*/
unsigned int hash;
memcpy(&hash, oid->hash, sizeof(hash));
return hash;
}
static inline int is_null_oid(const struct object_id *oid)
{
return oideq(oid, null_oid());
static const unsigned char null_hash[GIT_MAX_RAWSZ];
return !memcmp(oid->hash, null_hash, GIT_MAX_RAWSZ);
}
static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)
const char *empty_tree_oid_hex(const struct git_hash_algo *algop);
static inline int is_empty_blob_oid(const struct object_id *oid,
const struct git_hash_algo *algop)
{
memcpy(sha_dst, sha_src, the_hash_algo->rawsz);
return oideq(oid, algop->empty_blob);
}
/* Like oidcpy() but zero-pads the unused bytes in dst's hash array. */
static inline void oidcpy_with_padding(struct object_id *dst,
const struct object_id *src)
static inline int is_empty_tree_oid(const struct object_id *oid,
const struct git_hash_algo *algop)
{
size_t hashsz;
if (!src->algo)
hashsz = the_hash_algo->rawsz;
else
hashsz = hash_algos[src->algo].rawsz;
memcpy(dst->hash, src->hash, hashsz);
memset(dst->hash + hashsz, 0, GIT_MAX_RAWSZ - hashsz);
dst->algo = src->algo;
}
static inline void hashclr(unsigned char *hash)
{
memset(hash, 0, the_hash_algo->rawsz);
}
static inline void oidclr(struct object_id *oid)
{
memset(oid->hash, 0, GIT_MAX_RAWSZ);
oid->algo = hash_algo_by_ptr(the_hash_algo);
}
static inline void oidread_algop(struct object_id *oid, const unsigned char *hash, const struct git_hash_algo *algop)
{
memcpy(oid->hash, hash, algop->rawsz);
oid->algo = hash_algo_by_ptr(algop);
}
static inline void oidread(struct object_id *oid, const unsigned char *hash)
{
oidread_algop(oid, hash, the_hash_algo);
}
static inline int is_empty_blob_sha1(const unsigned char *sha1)
{
return hasheq(sha1, the_hash_algo->empty_blob->hash);
}
static inline int is_empty_blob_oid(const struct object_id *oid)
{
return oideq(oid, the_hash_algo->empty_blob);
}
static inline int is_empty_tree_sha1(const unsigned char *sha1)
{
return hasheq(sha1, the_hash_algo->empty_tree->hash);
}
static inline int is_empty_tree_oid(const struct object_id *oid)
{
return oideq(oid, the_hash_algo->empty_tree);
return oideq(oid, algop->empty_tree);
}
#endif

2
help.c
View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "config.h"
#include "builtin.h"

8
hex.c
View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "hash.h"
#include "hex.h"
@ -25,8 +27,12 @@ int get_oid_hex_algop(const char *hex, struct object_id *oid,
const struct git_hash_algo *algop)
{
int ret = get_hash_hex_algop(hex, oid->hash, algop);
if (!ret)
if (!ret) {
oid_set_algo(oid, algop);
if (algop->rawsz != GIT_MAX_RAWSZ)
memset(oid->hash + algop->rawsz, 0,
GIT_MAX_RAWSZ - algop->rawsz);
}
return ret;
}

28
hex.h
View File

@ -1,7 +1,7 @@
#ifndef HEX_H
#define HEX_H
#include "hash-ll.h"
#include "hash.h"
#include "hex-ll.h"
/*
@ -13,10 +13,6 @@
* input, so it is safe to pass this function an arbitrary
* null-terminated string.
*/
int get_hash_hex(const char *hex, unsigned char *hash);
int get_oid_hex(const char *hex, struct object_id *oid);
/* Like get_oid_hex, but for an arbitrary hash algorithm. */
int get_oid_hex_algop(const char *hex, struct object_id *oid, const struct git_hash_algo *algop);
/*
@ -35,7 +31,6 @@ int get_oid_hex_algop(const char *hex, struct object_id *oid, const struct git_h
char *hash_to_hex_algop_r(char *buffer, const unsigned char *hash, const struct git_hash_algo *);
char *oid_to_hex_r(char *out, const struct object_id *oid);
char *hash_to_hex_algop(const unsigned char *hash, const struct git_hash_algo *); /* static buffer result! */
char *hash_to_hex(const unsigned char *hash); /* same static buffer */
char *oid_to_hex(const struct object_id *oid); /* same static buffer */
/*
@ -45,13 +40,9 @@ char *oid_to_hex(const struct object_id *oid); /* same static buffer */
* other invalid character. end is only updated on success; otherwise, it is
* unmodified.
*/
int parse_oid_hex(const char *hex, struct object_id *oid, const char **end);
/* Like parse_oid_hex, but for an arbitrary hash algorithm. */
int parse_oid_hex_algop(const char *hex, struct object_id *oid, const char **end,
const struct git_hash_algo *algo);
/*
* These functions work like get_oid_hex and parse_oid_hex, but they will parse
* a hex value for any algorithm. The algorithm is detected based on the length
@ -61,4 +52,19 @@ int parse_oid_hex_algop(const char *hex, struct object_id *oid, const char **end
int get_oid_hex_any(const char *hex, struct object_id *oid);
int parse_oid_hex_any(const char *hex, struct object_id *oid, const char **end);
#endif
#ifdef USE_THE_REPOSITORY_VARIABLE
/* Like get_oid_hex_algop, but for `the_hash_algo`. */
int get_hash_hex(const char *hex, unsigned char *hash);
int get_oid_hex(const char *hex, struct object_id *oid);
/* Like parse_oid_hex_algop, but uses `the_hash_algo`. */
int parse_oid_hex(const char *hex, struct object_id *oid, const char **end);
/*
* Same as `hash_to_hex_algop()`, but uses `the_hash_algo`.
*/
char *hash_to_hex(const unsigned char *hash);
#endif /* USE_THE_REPOSITORY_VARIABLE */
#endif /* HEX_H */

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "config.h"
#include "environment.h"

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "config.h"
#include "gettext.h"
@ -127,8 +129,12 @@ int cmd_main(int argc, const char **argv)
} else if (skip_prefix(argv[arg], "--packfile=", &p)) {
const char *end;
if (nongit)
die(_("not a git repository"));
packfile = 1;
if (parse_oid_hex(p, &packfile_hash, &end) || *end)
if (parse_oid_hex_algop(p, &packfile_hash, &end,
the_repository->hash_algo) || *end)
die(_("argument to --packfile must be a valid hash (got '%s')"), p);
} else if (skip_prefix(argv[arg], "--index-pack-arg=", &p)) {
strvec_push(&index_pack_args, p);

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "environment.h"
#include "hex.h"
@ -1016,6 +1018,7 @@ static void remote_ls(const char *path, int flags,
/* extract hex from sharded "xx/x{38}" filename */
static int get_oid_hex_from_objpath(const char *path, struct object_id *oid)
{
memset(oid->hash, 0, GIT_MAX_RAWSZ);
oid->algo = hash_algo_by_ptr(the_hash_algo);
if (strlen(path) != the_hash_algo->hexsz + 1)
@ -1552,7 +1555,7 @@ static void fetch_symref(const char *path, char **symref, struct object_id *oid)
free(url);
FREE_AND_NULL(*symref);
oidclr(oid);
oidclr(oid, the_repository->hash_algo);
if (buffer.len == 0)
return;

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "repository.h"
#include "hex.h"
@ -152,7 +154,7 @@ static void prefetch(struct walker *walker, unsigned char *sha1)
newreq = xmalloc(sizeof(*newreq));
newreq->walker = walker;
oidread(&newreq->oid, sha1);
oidread(&newreq->oid, sha1, the_repository->hash_algo);
newreq->repo = data->alt;
newreq->state = WAITING;
newreq->req = NULL;
@ -485,7 +487,7 @@ static int fetch_object(struct walker *walker, unsigned char *hash)
list_for_each(pos, head) {
obj_req = list_entry(pos, struct object_request, node);
if (hasheq(obj_req->oid.hash, hash))
if (hasheq(obj_req->oid.hash, hash, the_repository->hash_algo))
break;
}
if (!obj_req)

2
http.c
View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "git-curl-compat.h"
#include "hex.h"

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "config.h"
#include "gettext.h"

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "dir.h"
#include "gettext.h"

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "tag.h"
#include "commit.h"

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "commit-reach.h"
#include "config.h"

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "hash.h"
#include "path.h"

View File

@ -3,6 +3,8 @@
#include "khash.h"
struct repository;
struct loose_object_map {
kh_oid_map_t *to_compat;
kh_oid_map_t *to_storage;

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "environment.h"
#include "string-list.h"

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "hex.h"
#include "match-trees.h"
@ -229,7 +231,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
oid_to_hex(oid1));
if (*subpath) {
struct object_id tree_oid;
oidread(&tree_oid, rewrite_here);
oidread(&tree_oid, rewrite_here, the_repository->hash_algo);
status = splice_tree(&tree_oid, subpath, oid2, &subtree);
if (status)
return status;
@ -237,7 +239,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
} else {
rewrite_with = oid2;
}
hashcpy(rewrite_here, rewrite_with->hash);
hashcpy(rewrite_here, rewrite_with->hash, the_repository->hash_algo);
status = write_object_file(buf, sz, OBJ_TREE, result);
free(buf);
return status;

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "merge-ll.h"
#include "blob.h"

View File

@ -14,6 +14,8 @@
* "cale", "peedy", or "ins" instead of "ort"?)
*/
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "merge-ort.h"

View File

@ -2,7 +2,7 @@
#define MERGE_ORT_H
#include "merge-recursive.h"
#include "hash-ll.h"
#include "hash.h"
struct commit;
struct tree;

View File

@ -3,6 +3,9 @@
* Fredrik Kuivinen.
* The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006
*/
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "merge-recursive.h"

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "gettext.h"
#include "hash.h"

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "abspath.h"
#include "config.h"

5
midx.c
View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "config.h"
#include "dir.h"
@ -304,7 +306,8 @@ struct object_id *nth_midxed_object_oid(struct object_id *oid,
if (n >= m->num_objects)
return NULL;
oidread(oid, m->chunk_oid_lookup + st_mult(m->hash_len, n));
oidread(oid, m->chunk_oid_lookup + st_mult(m->hash_len, n),
the_repository->hash_algo);
return oid;
}

View File

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "default.h"
#include "../commit.h"

Some files were not shown because too many files have changed in this diff Show More