Merge branch 'bc/object-id' into bw/submodule-config-cleanup

* bc/object-id:
  sha1_name: convert uses of 40 to GIT_SHA1_HEXSZ
  sha1_name: convert GET_SHA1* flags to GET_OID*
  sha1_name: convert get_sha1* to get_oid*
  Convert remaining callers of get_sha1 to get_oid.
  builtin/unpack-file: convert to struct object_id
  bisect: convert bisect_checkout to struct object_id
  builtin/update_ref: convert to struct object_id
  sequencer: convert to struct object_id
  remote: convert struct push_cas to struct object_id
  submodule: convert submodule config lookup to use object_id
  builtin/merge-tree: convert remaining caller of get_sha1 to object_id
  builtin/fsck: convert remaining caller of get_sha1 to object_id
  tag: convert gpg_verify_tag to use struct object_id
  commit: convert lookup_commit_graft to struct object_id
This commit is contained in:
Junio C Hamano 2017-08-02 14:34:28 -07:00
commit a46ddc992b
45 changed files with 365 additions and 373 deletions

View File

@ -3551,7 +3551,7 @@ static int try_threeway(struct apply_state *state,
/* Preimage the patch was prepared for */ /* Preimage the patch was prepared for */
if (patch->is_new) if (patch->is_new)
write_sha1_file("", 0, blob_type, pre_oid.hash); write_sha1_file("", 0, blob_type, pre_oid.hash);
else if (get_sha1(patch->old_sha1_prefix, pre_oid.hash) || else if (get_oid(patch->old_sha1_prefix, &pre_oid) ||
read_blob_object(&buf, &pre_oid, patch->old_mode)) read_blob_object(&buf, &pre_oid, patch->old_mode))
return error(_("repository lacks the necessary blob to fall back on 3-way merge.")); return error(_("repository lacks the necessary blob to fall back on 3-way merge."));
@ -4075,7 +4075,7 @@ static int build_fake_ancestor(struct apply_state *state, struct patch *list)
else else
return error(_("sha1 information is lacking or " return error(_("sha1 information is lacking or "
"useless for submodule %s"), name); "useless for submodule %s"), name);
} else if (!get_sha1_blob(patch->old_sha1_prefix, oid.hash)) { } else if (!get_oid_blob(patch->old_sha1_prefix, &oid)) {
; /* ok */ ; /* ok */
} else if (!patch->lines_added && !patch->lines_deleted) { } else if (!patch->lines_added && !patch->lines_deleted) {
/* mode-only change: update the current */ /* mode-only change: update the current */

View File

@ -358,7 +358,7 @@ static void parse_treeish_arg(const char **argv,
free(ref); free(ref);
} }
if (get_sha1(name, oid.hash)) if (get_oid(name, &oid))
die("Not a valid object name"); die("Not a valid object name");
commit = lookup_commit_reference_gently(&oid, 1); commit = lookup_commit_reference_gently(&oid, 1);

View File

@ -680,16 +680,16 @@ static int is_expected_rev(const struct object_id *oid)
return res; return res;
} }
static int bisect_checkout(const unsigned char *bisect_rev, int no_checkout) static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout)
{ {
char bisect_rev_hex[GIT_MAX_HEXSZ + 1]; char bisect_rev_hex[GIT_MAX_HEXSZ + 1];
memcpy(bisect_rev_hex, sha1_to_hex(bisect_rev), GIT_SHA1_HEXSZ + 1); memcpy(bisect_rev_hex, oid_to_hex(bisect_rev), GIT_SHA1_HEXSZ + 1);
update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR); update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev->hash, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
argv_checkout[2] = bisect_rev_hex; argv_checkout[2] = bisect_rev_hex;
if (no_checkout) { if (no_checkout) {
update_ref(NULL, "BISECT_HEAD", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR); update_ref(NULL, "BISECT_HEAD", bisect_rev->hash, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
} else { } else {
int res; int res;
res = run_command_v_opt(argv_checkout, RUN_GIT_CMD); res = run_command_v_opt(argv_checkout, RUN_GIT_CMD);
@ -796,7 +796,7 @@ static void check_merge_bases(int no_checkout)
handle_skipped_merge_base(mb); handle_skipped_merge_base(mb);
} else { } else {
printf(_("Bisecting: a merge base must be tested\n")); printf(_("Bisecting: a merge base must be tested\n"));
exit(bisect_checkout(mb->hash, no_checkout)); exit(bisect_checkout(mb, no_checkout));
} }
} }
@ -939,7 +939,7 @@ int bisect_next_all(const char *prefix, int no_checkout)
struct rev_info revs; struct rev_info revs;
struct commit_list *tried; struct commit_list *tried;
int reaches = 0, all = 0, nr, steps; int reaches = 0, all = 0, nr, steps;
const unsigned char *bisect_rev; struct object_id *bisect_rev;
char *steps_msg; char *steps_msg;
read_bisect_terms(&term_bad, &term_good); read_bisect_terms(&term_bad, &term_good);
@ -977,11 +977,11 @@ int bisect_next_all(const char *prefix, int no_checkout)
exit(4); exit(4);
} }
bisect_rev = revs.commits->item->object.oid.hash; bisect_rev = &revs.commits->item->object.oid;
if (!hashcmp(bisect_rev, current_bad_oid->hash)) { if (!oidcmp(bisect_rev, current_bad_oid)) {
exit_if_skipped_commits(tried, current_bad_oid); exit_if_skipped_commits(tried, current_bad_oid);
printf("%s is the first %s commit\n", sha1_to_hex(bisect_rev), printf("%s is the first %s commit\n", oid_to_hex(bisect_rev),
term_bad); term_bad);
show_diff_tree(prefix, revs.commits->item); show_diff_tree(prefix, revs.commits->item);
/* This means the bisection process succeeded. */ /* This means the bisection process succeeded. */

View File

@ -1131,7 +1131,7 @@ static int index_has_changes(struct strbuf *sb)
struct object_id head; struct object_id head;
int i; int i;
if (!get_sha1_tree("HEAD", head.hash)) { if (!get_oid_tree("HEAD", &head)) {
struct diff_options opt; struct diff_options opt;
diff_setup(&opt); diff_setup(&opt);
@ -1432,7 +1432,7 @@ static void write_index_patch(const struct am_state *state)
struct rev_info rev_info; struct rev_info rev_info;
FILE *fp; FILE *fp;
if (!get_sha1_tree("HEAD", head.hash)) if (!get_oid_tree("HEAD", &head))
tree = lookup_tree(&head); tree = lookup_tree(&head);
else else
tree = lookup_tree(&empty_tree_oid); tree = lookup_tree(&empty_tree_oid);
@ -1661,7 +1661,7 @@ static void do_commit(const struct am_state *state)
if (write_cache_as_tree(tree.hash, 0, NULL)) if (write_cache_as_tree(tree.hash, 0, NULL))
die(_("git write-tree failed to write a tree")); die(_("git write-tree failed to write a tree"));
if (!get_sha1_commit("HEAD", parent.hash)) { if (!get_oid_commit("HEAD", &parent)) {
old_oid = &parent; old_oid = &parent;
commit_list_insert(lookup_commit(&parent), &parents); commit_list_insert(lookup_commit(&parent), &parents);
} else { } else {

View File

@ -63,8 +63,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
if (unknown_type) if (unknown_type)
flags |= OBJECT_INFO_ALLOW_UNKNOWN_TYPE; flags |= OBJECT_INFO_ALLOW_UNKNOWN_TYPE;
if (get_sha1_with_context(obj_name, GET_SHA1_RECORD_PATH, if (get_oid_with_context(obj_name, GET_OID_RECORD_PATH,
oid.hash, &obj_context)) &oid, &obj_context))
die("Not a valid object name %s", obj_name); die("Not a valid object name %s", obj_name);
if (!path) if (!path)
@ -361,10 +361,10 @@ static void batch_one_object(const char *obj_name, struct batch_options *opt,
struct expand_data *data) struct expand_data *data)
{ {
struct object_context ctx; struct object_context ctx;
int flags = opt->follow_symlinks ? GET_SHA1_FOLLOW_SYMLINKS : 0; int flags = opt->follow_symlinks ? GET_OID_FOLLOW_SYMLINKS : 0;
enum follow_symlinks_result result; enum follow_symlinks_result result;
result = get_sha1_with_context(obj_name, flags, data->oid.hash, &ctx); result = get_oid_with_context(obj_name, flags, &data->oid, &ctx);
if (result != FOUND) { if (result != FOUND) {
switch (result) { switch (result) {
case MISSING_OBJECT: case MISSING_OBJECT:

View File

@ -56,7 +56,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
struct object_id oid; struct object_id oid;
if (argc <= ++i) if (argc <= ++i)
usage(commit_tree_usage); usage(commit_tree_usage);
if (get_sha1_commit(argv[i], oid.hash)) if (get_oid_commit(argv[i], &oid))
die("Not a valid object name %s", argv[i]); die("Not a valid object name %s", argv[i]);
assert_sha1_type(oid.hash, OBJ_COMMIT); assert_sha1_type(oid.hash, OBJ_COMMIT);
new_parent(lookup_commit(&oid), &parents); new_parent(lookup_commit(&oid), &parents);
@ -106,7 +106,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
continue; continue;
} }
if (get_sha1_tree(arg, tree_oid.hash)) if (get_oid_tree(arg, &tree_oid))
die("Not a valid object name %s", arg); die("Not a valid object name %s", arg);
if (got_tree) if (got_tree)
die("Cannot give more than one trees"); die("Cannot give more than one trees");

View File

@ -510,7 +510,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
s->index_file = index_file; s->index_file = index_file;
s->fp = fp; s->fp = fp;
s->nowarn = nowarn; s->nowarn = nowarn;
s->is_initial = get_sha1(s->reference, oid.hash) ? 1 : 0; s->is_initial = get_oid(s->reference, &oid) ? 1 : 0;
if (!s->is_initial) if (!s->is_initial)
hashcpy(s->sha1_commit, oid.hash); hashcpy(s->sha1_commit, oid.hash);
s->status_format = status_format; s->status_format = status_format;
@ -891,7 +891,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
if (amend) if (amend)
parent = "HEAD^1"; parent = "HEAD^1";
if (get_sha1(parent, oid.hash)) { if (get_oid(parent, &oid)) {
int i, ita_nr = 0; int i, ita_nr = 0;
for (i = 0; i < active_nr; i++) for (i = 0; i < active_nr; i++)
@ -1387,7 +1387,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
fd = hold_locked_index(&index_lock, 0); fd = hold_locked_index(&index_lock, 0);
s.is_initial = get_sha1(s.reference, oid.hash) ? 1 : 0; s.is_initial = get_oid(s.reference, &oid) ? 1 : 0;
if (!s.is_initial) if (!s.is_initial)
hashcpy(s.sha1_commit, oid.hash); hashcpy(s.sha1_commit, oid.hash);
@ -1657,7 +1657,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
status_format = STATUS_FORMAT_NONE; /* Ignore status.short */ status_format = STATUS_FORMAT_NONE; /* Ignore status.short */
s.colopts = 0; s.colopts = 0;
if (get_sha1("HEAD", oid.hash)) if (get_oid("HEAD", &oid))
current_head = NULL; current_head = NULL;
else { else {
current_head = lookup_commit_or_die(&oid, "HEAD"); current_head = lookup_commit_or_die(&oid, "HEAD");

View File

@ -738,12 +738,12 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
heads = 0; heads = 0;
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
const char *arg = argv[i]; const char *arg = argv[i];
unsigned char sha1[20]; struct object_id oid;
if (!get_sha1(arg, sha1)) { if (!get_oid(arg, &oid)) {
struct object *obj = lookup_object(sha1); struct object *obj = lookup_object(oid.hash);
if (!obj || !(obj->flags & HAS_OBJ)) { if (!obj || !(obj->flags & HAS_OBJ)) {
error("%s: object missing", sha1_to_hex(sha1)); error("%s: object missing", oid_to_hex(&oid));
errors_found |= ERROR_OBJECT; errors_found |= ERROR_OBJECT;
continue; continue;
} }

View File

@ -643,7 +643,7 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,
/* load the gitmodules file for this rev */ /* load the gitmodules file for this rev */
if (recurse_submodules) { if (recurse_submodules) {
submodule_free(); submodule_free();
gitmodules_config_sha1(real_obj->oid.hash); gitmodules_config_oid(&real_obj->oid);
} }
if (grep_object(opt, pathspec, real_obj, list->objects[i].name, list->objects[i].path, if (grep_object(opt, pathspec, real_obj, list->objects[i].name, list->objects[i].path,
repo)) { repo)) {
@ -983,8 +983,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
break; break;
} }
if (get_sha1_with_context(arg, GET_SHA1_RECORD_PATH, if (get_oid_with_context(arg, GET_OID_RECORD_PATH,
oid.hash, &oc)) { &oid, &oc)) {
if (seen_dashdash) if (seen_dashdash)
die(_("unable to resolve revision: %s"), arg); die(_("unable to resolve revision: %s"), arg);
break; break;

View File

@ -484,8 +484,8 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c
!DIFF_OPT_TST(&rev->diffopt, ALLOW_TEXTCONV)) !DIFF_OPT_TST(&rev->diffopt, ALLOW_TEXTCONV))
return stream_blob_to_fd(1, oid, NULL, 0); return stream_blob_to_fd(1, oid, NULL, 0);
if (get_sha1_with_context(obj_name, GET_SHA1_RECORD_PATH, if (get_oid_with_context(obj_name, GET_OID_RECORD_PATH,
oidc.hash, &obj_context)) &oidc, &obj_context))
die(_("Not a valid object name %s"), obj_name); die(_("Not a valid object name %s"), obj_name);
if (!obj_context.path || if (!obj_context.path ||
!textconv_object(obj_context.path, obj_context.mode, &oidc, 1, &buf, &size)) { !textconv_object(obj_context.path, obj_context.mode, &oidc, 1, &buf, &size)) {

View File

@ -347,12 +347,12 @@ static void merge_trees(struct tree_desc t[3], const char *base)
static void *get_tree_descriptor(struct tree_desc *desc, const char *rev) static void *get_tree_descriptor(struct tree_desc *desc, const char *rev)
{ {
unsigned char sha1[20]; struct object_id oid;
void *buf; void *buf;
if (get_sha1(rev, sha1)) if (get_oid(rev, &oid))
die("unknown rev %s", rev); die("unknown rev %s", rev);
buf = fill_tree_descriptor(desc, sha1); buf = fill_tree_descriptor(desc, oid.hash);
if (!buf) if (!buf)
die("%s is not a tree", rev); die("%s is not a tree", rev);
return buf; return buf;

View File

@ -919,9 +919,9 @@ static int update_shallow_ref(struct command *cmd, struct shallow_info *si)
*/ */
static int head_has_history(void) static int head_has_history(void)
{ {
unsigned char sha1[20]; struct object_id oid;
return !get_sha1("HEAD", sha1); return !get_oid("HEAD", &oid);
} }
static const char *push_to_deploy(unsigned char *sha1, static const char *push_to_deploy(unsigned char *sha1,

View File

@ -50,7 +50,7 @@ static int show_reference(const char *refname, const struct object_id *oid,
struct object_id object; struct object_id object;
enum object_type obj_type, repl_type; enum object_type obj_type, repl_type;
if (get_sha1(refname, object.hash)) if (get_oid(refname, &object))
return error("Failed to resolve '%s' as a valid ref.", refname); return error("Failed to resolve '%s' as a valid ref.", refname);
obj_type = sha1_object_info(object.hash, NULL); obj_type = sha1_object_info(object.hash, NULL);
@ -365,7 +365,7 @@ static void check_one_mergetag(struct commit *commit,
/* iterate over new parents */ /* iterate over new parents */
for (i = 1; i < mergetag_data->argc; i++) { for (i = 1; i < mergetag_data->argc; i++) {
struct object_id oid; struct object_id oid;
if (get_sha1(mergetag_data->argv[i], oid.hash) < 0) if (get_oid(mergetag_data->argv[i], &oid) < 0)
die(_("Not a valid object name: '%s'"), mergetag_data->argv[i]); die(_("Not a valid object name: '%s'"), mergetag_data->argv[i]);
if (!oidcmp(&tag->tagged->oid, &oid)) if (!oidcmp(&tag->tagged->oid, &oid))
return; /* found */ return; /* found */

View File

@ -219,8 +219,8 @@ static void parse_args(struct pathspec *pathspec,
* has to be unambiguous. If there is a single argument, it * has to be unambiguous. If there is a single argument, it
* can not be a tree * can not be a tree
*/ */
else if ((!argv[1] && !get_sha1_committish(argv[0], unused.hash)) || else if ((!argv[1] && !get_oid_committish(argv[0], &unused)) ||
(argv[1] && !get_sha1_treeish(argv[0], unused.hash))) { (argv[1] && !get_oid_treeish(argv[0], &unused))) {
/* /*
* Ok, argv[0] looks like a commit/tree; it should not * Ok, argv[0] looks like a commit/tree; it should not
* be a filename. * be a filename.
@ -310,13 +310,13 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
load_submodule_cache(); load_submodule_cache();
unborn = !strcmp(rev, "HEAD") && get_sha1("HEAD", oid.hash); unborn = !strcmp(rev, "HEAD") && get_oid("HEAD", &oid);
if (unborn) { if (unborn) {
/* reset on unborn branch: treat as reset to empty tree */ /* reset on unborn branch: treat as reset to empty tree */
hashcpy(oid.hash, EMPTY_TREE_SHA1_BIN); hashcpy(oid.hash, EMPTY_TREE_SHA1_BIN);
} else if (!pathspec.nr) { } else if (!pathspec.nr) {
struct commit *commit; struct commit *commit;
if (get_sha1_committish(rev, oid.hash)) if (get_oid_committish(rev, &oid))
die(_("Failed to resolve '%s' as a valid revision."), rev); die(_("Failed to resolve '%s' as a valid revision."), rev);
commit = lookup_commit_reference(&oid); commit = lookup_commit_reference(&oid);
if (!commit) if (!commit)
@ -324,7 +324,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
oidcpy(&oid, &commit->object.oid); oidcpy(&oid, &commit->object.oid);
} else { } else {
struct tree *tree; struct tree *tree;
if (get_sha1_treeish(rev, oid.hash)) if (get_oid_treeish(rev, &oid))
die(_("Failed to resolve '%s' as a valid tree."), rev); die(_("Failed to resolve '%s' as a valid tree."), rev);
tree = parse_tree_indirect(&oid); tree = parse_tree_indirect(&oid);
if (!tree) if (!tree)

View File

@ -274,7 +274,7 @@ static int try_difference(const char *arg)
return 0; return 0;
} }
if (!get_sha1_committish(this, oid.hash) && !get_sha1_committish(next, end.hash)) { if (!get_oid_committish(this, &oid) && !get_oid_committish(next, &end)) {
show_rev(NORMAL, &end, next); show_rev(NORMAL, &end, next);
show_rev(symmetric ? NORMAL : REVERSED, &oid, this); show_rev(symmetric ? NORMAL : REVERSED, &oid, this);
if (symmetric) { if (symmetric) {
@ -328,7 +328,7 @@ static int try_parent_shorthands(const char *arg)
return 0; return 0;
*dotdot = 0; *dotdot = 0;
if (get_sha1_committish(arg, oid.hash)) { if (get_oid_committish(arg, &oid)) {
*dotdot = '^'; *dotdot = '^';
return 0; return 0;
} }
@ -702,7 +702,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
} }
if (!strcmp(arg, "--quiet") || !strcmp(arg, "-q")) { if (!strcmp(arg, "--quiet") || !strcmp(arg, "-q")) {
quiet = 1; quiet = 1;
flags |= GET_SHA1_QUIETLY; flags |= GET_OID_QUIETLY;
continue; continue;
} }
if (opt_with_value(arg, "--short", &arg)) { if (opt_with_value(arg, "--short", &arg)) {
@ -911,7 +911,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
name++; name++;
type = REVERSED; type = REVERSED;
} }
if (!get_sha1_with_context(name, flags, oid.hash, &unused)) { if (!get_oid_with_context(name, flags, &oid, &unused)) {
if (verify) if (verify)
revs_count++; revs_count++;
else else

View File

@ -393,7 +393,7 @@ static int append_head_ref(const char *refname, const struct object_id *oid,
/* If both heads/foo and tags/foo exists, get_sha1 would /* If both heads/foo and tags/foo exists, get_sha1 would
* get confused. * get confused.
*/ */
if (get_sha1(refname + ofs, tmp.hash) || oidcmp(&tmp, oid)) if (get_oid(refname + ofs, &tmp) || oidcmp(&tmp, oid))
ofs = 5; ofs = 5;
return append_ref(refname + ofs, oid, 0); return append_ref(refname + ofs, oid, 0);
} }
@ -408,7 +408,7 @@ static int append_remote_ref(const char *refname, const struct object_id *oid,
/* If both heads/foo and tags/foo exists, get_sha1 would /* If both heads/foo and tags/foo exists, get_sha1 would
* get confused. * get confused.
*/ */
if (get_sha1(refname + ofs, tmp.hash) || oidcmp(&tmp, oid)) if (get_oid(refname + ofs, &tmp) || oidcmp(&tmp, oid))
ofs = 5; ofs = 5;
return append_ref(refname + ofs, oid, 0); return append_ref(refname + ofs, oid, 0);
} }
@ -514,7 +514,7 @@ static int show_independent(struct commit **rev,
static void append_one_rev(const char *av) static void append_one_rev(const char *av)
{ {
struct object_id revkey; struct object_id revkey;
if (!get_sha1(av, revkey.hash)) { if (!get_oid(av, &revkey)) {
append_ref(av, &revkey, 0); append_ref(av, &revkey, 0);
return; return;
} }
@ -808,7 +808,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
die(Q_("cannot handle more than %d rev.", die(Q_("cannot handle more than %d rev.",
"cannot handle more than %d revs.", "cannot handle more than %d revs.",
MAX_REVS), MAX_REVS); MAX_REVS), MAX_REVS);
if (get_sha1(ref_name[num_rev], revkey.hash)) if (get_oid(ref_name[num_rev], &revkey))
die(_("'%s' is not a valid ref."), ref_name[num_rev]); die(_("'%s' is not a valid ref."), ref_name[num_rev]);
commit = lookup_commit_reference(&revkey); commit = lookup_commit_reference(&revkey);
if (!commit) if (!commit)

View File

@ -350,7 +350,7 @@ static void init_submodule(const char *path, const char *prefix, int quiet)
} else } else
displaypath = xstrdup(path); displaypath = xstrdup(path);
sub = submodule_from_path(null_sha1, path); sub = submodule_from_path(&null_oid, path);
if (!sub) if (!sub)
die(_("No url found for submodule path '%s' in .gitmodules"), die(_("No url found for submodule path '%s' in .gitmodules"),
@ -476,7 +476,7 @@ static int module_name(int argc, const char **argv, const char *prefix)
usage(_("git submodule--helper name <path>")); usage(_("git submodule--helper name <path>"));
gitmodules_config(); gitmodules_config();
sub = submodule_from_path(null_sha1, argv[1]); sub = submodule_from_path(&null_oid, argv[1]);
if (!sub) if (!sub)
die(_("no submodule mapping found in .gitmodules for path '%s'"), die(_("no submodule mapping found in .gitmodules for path '%s'"),
@ -795,7 +795,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
goto cleanup; goto cleanup;
} }
sub = submodule_from_path(null_sha1, ce->name); sub = submodule_from_path(&null_oid, ce->name);
if (suc->recursive_prefix) if (suc->recursive_prefix)
displaypath = relative_path(suc->recursive_prefix, displaypath = relative_path(suc->recursive_prefix,
@ -1069,7 +1069,7 @@ static const char *remote_submodule_branch(const char *path)
gitmodules_config(); gitmodules_config();
git_config(submodule_config, NULL); git_config(submodule_config, NULL);
sub = submodule_from_path(null_sha1, path); sub = submodule_from_path(&null_oid, path);
if (!sub) if (!sub)
return NULL; return NULL;

View File

@ -111,7 +111,7 @@ static int verify_tag(const char *name, const char *ref,
if (fmt_pretty) if (fmt_pretty)
flags = GPG_VERIFY_OMIT_STATUS; flags = GPG_VERIFY_OMIT_STATUS;
if (gpg_verify_tag(oid->hash, name, flags)) if (gpg_verify_tag(oid, name, flags))
return -1; return -1;
if (fmt_pretty) if (fmt_pretty)

View File

@ -1,7 +1,7 @@
#include "builtin.h" #include "builtin.h"
#include "config.h" #include "config.h"
static char *create_temp_file(unsigned char *sha1) static char *create_temp_file(struct object_id *oid)
{ {
static char path[50]; static char path[50];
void *buf; void *buf;
@ -9,9 +9,9 @@ static char *create_temp_file(unsigned char *sha1)
unsigned long size; unsigned long size;
int fd; int fd;
buf = read_sha1_file(sha1, &type, &size); buf = read_sha1_file(oid->hash, &type, &size);
if (!buf || type != OBJ_BLOB) if (!buf || type != OBJ_BLOB)
die("unable to read blob object %s", sha1_to_hex(sha1)); die("unable to read blob object %s", oid_to_hex(oid));
xsnprintf(path, sizeof(path), ".merge_file_XXXXXX"); xsnprintf(path, sizeof(path), ".merge_file_XXXXXX");
fd = xmkstemp(path); fd = xmkstemp(path);
@ -23,15 +23,15 @@ static char *create_temp_file(unsigned char *sha1)
int cmd_unpack_file(int argc, const char **argv, const char *prefix) int cmd_unpack_file(int argc, const char **argv, const char *prefix)
{ {
unsigned char sha1[20]; struct object_id oid;
if (argc != 2 || !strcmp(argv[1], "-h")) if (argc != 2 || !strcmp(argv[1], "-h"))
usage("git unpack-file <sha1>"); usage("git unpack-file <sha1>");
if (get_sha1(argv[1], sha1)) if (get_oid(argv[1], &oid))
die("Not a valid object name %s", argv[1]); die("Not a valid object name %s", argv[1]);
git_config(git_default_config, NULL); git_config(git_default_config, NULL);
puts(create_temp_file(sha1)); puts(create_temp_file(&oid));
return 0; return 0;
} }

View File

@ -94,10 +94,10 @@ static char *parse_refname(struct strbuf *input, const char **next)
* provided but cannot be converted to a SHA-1, die. flags can * provided but cannot be converted to a SHA-1, die. flags can
* include PARSE_SHA1_OLD and/or PARSE_SHA1_ALLOW_EMPTY. * include PARSE_SHA1_OLD and/or PARSE_SHA1_ALLOW_EMPTY.
*/ */
static int parse_next_sha1(struct strbuf *input, const char **next, static int parse_next_oid(struct strbuf *input, const char **next,
unsigned char *sha1, struct object_id *oid,
const char *command, const char *refname, const char *command, const char *refname,
int flags) int flags)
{ {
struct strbuf arg = STRBUF_INIT; struct strbuf arg = STRBUF_INIT;
int ret = 0; int ret = 0;
@ -115,11 +115,11 @@ static int parse_next_sha1(struct strbuf *input, const char **next,
(*next)++; (*next)++;
*next = parse_arg(*next, &arg); *next = parse_arg(*next, &arg);
if (arg.len) { if (arg.len) {
if (get_sha1(arg.buf, sha1)) if (get_oid(arg.buf, oid))
goto invalid; goto invalid;
} else { } else {
/* Without -z, an empty value means all zeros: */ /* Without -z, an empty value means all zeros: */
hashclr(sha1); oidclr(oid);
} }
} else { } else {
/* With -z, read the next NUL-terminated line */ /* With -z, read the next NUL-terminated line */
@ -133,13 +133,13 @@ static int parse_next_sha1(struct strbuf *input, const char **next,
*next += arg.len; *next += arg.len;
if (arg.len) { if (arg.len) {
if (get_sha1(arg.buf, sha1)) if (get_oid(arg.buf, oid))
goto invalid; goto invalid;
} else if (flags & PARSE_SHA1_ALLOW_EMPTY) { } else if (flags & PARSE_SHA1_ALLOW_EMPTY) {
/* With -z, treat an empty value as all zeros: */ /* With -z, treat an empty value as all zeros: */
warning("%s %s: missing <newvalue>, treating as zero", warning("%s %s: missing <newvalue>, treating as zero",
command, refname); command, refname);
hashclr(sha1); oidclr(oid);
} else { } else {
/* /*
* With -z, an empty non-required value means * With -z, an empty non-required value means
@ -182,26 +182,25 @@ static const char *parse_cmd_update(struct ref_transaction *transaction,
{ {
struct strbuf err = STRBUF_INIT; struct strbuf err = STRBUF_INIT;
char *refname; char *refname;
unsigned char new_sha1[20]; struct object_id new_oid, old_oid;
unsigned char old_sha1[20];
int have_old; int have_old;
refname = parse_refname(input, &next); refname = parse_refname(input, &next);
if (!refname) if (!refname)
die("update: missing <ref>"); die("update: missing <ref>");
if (parse_next_sha1(input, &next, new_sha1, "update", refname, if (parse_next_oid(input, &next, &new_oid, "update", refname,
PARSE_SHA1_ALLOW_EMPTY)) PARSE_SHA1_ALLOW_EMPTY))
die("update %s: missing <newvalue>", refname); die("update %s: missing <newvalue>", refname);
have_old = !parse_next_sha1(input, &next, old_sha1, "update", refname, have_old = !parse_next_oid(input, &next, &old_oid, "update", refname,
PARSE_SHA1_OLD); PARSE_SHA1_OLD);
if (*next != line_termination) if (*next != line_termination)
die("update %s: extra input: %s", refname, next); die("update %s: extra input: %s", refname, next);
if (ref_transaction_update(transaction, refname, if (ref_transaction_update(transaction, refname,
new_sha1, have_old ? old_sha1 : NULL, new_oid.hash, have_old ? old_oid.hash : NULL,
update_flags | create_reflog_flag, update_flags | create_reflog_flag,
msg, &err)) msg, &err))
die("%s", err.buf); die("%s", err.buf);
@ -218,22 +217,22 @@ static const char *parse_cmd_create(struct ref_transaction *transaction,
{ {
struct strbuf err = STRBUF_INIT; struct strbuf err = STRBUF_INIT;
char *refname; char *refname;
unsigned char new_sha1[20]; struct object_id new_oid;
refname = parse_refname(input, &next); refname = parse_refname(input, &next);
if (!refname) if (!refname)
die("create: missing <ref>"); die("create: missing <ref>");
if (parse_next_sha1(input, &next, new_sha1, "create", refname, 0)) if (parse_next_oid(input, &next, &new_oid, "create", refname, 0))
die("create %s: missing <newvalue>", refname); die("create %s: missing <newvalue>", refname);
if (is_null_sha1(new_sha1)) if (is_null_oid(&new_oid))
die("create %s: zero <newvalue>", refname); die("create %s: zero <newvalue>", refname);
if (*next != line_termination) if (*next != line_termination)
die("create %s: extra input: %s", refname, next); die("create %s: extra input: %s", refname, next);
if (ref_transaction_create(transaction, refname, new_sha1, if (ref_transaction_create(transaction, refname, new_oid.hash,
update_flags | create_reflog_flag, update_flags | create_reflog_flag,
msg, &err)) msg, &err))
die("%s", err.buf); die("%s", err.buf);
@ -250,18 +249,18 @@ static const char *parse_cmd_delete(struct ref_transaction *transaction,
{ {
struct strbuf err = STRBUF_INIT; struct strbuf err = STRBUF_INIT;
char *refname; char *refname;
unsigned char old_sha1[20]; struct object_id old_oid;
int have_old; int have_old;
refname = parse_refname(input, &next); refname = parse_refname(input, &next);
if (!refname) if (!refname)
die("delete: missing <ref>"); die("delete: missing <ref>");
if (parse_next_sha1(input, &next, old_sha1, "delete", refname, if (parse_next_oid(input, &next, &old_oid, "delete", refname,
PARSE_SHA1_OLD)) { PARSE_SHA1_OLD)) {
have_old = 0; have_old = 0;
} else { } else {
if (is_null_sha1(old_sha1)) if (is_null_oid(&old_oid))
die("delete %s: zero <oldvalue>", refname); die("delete %s: zero <oldvalue>", refname);
have_old = 1; have_old = 1;
} }
@ -270,7 +269,7 @@ static const char *parse_cmd_delete(struct ref_transaction *transaction,
die("delete %s: extra input: %s", refname, next); die("delete %s: extra input: %s", refname, next);
if (ref_transaction_delete(transaction, refname, if (ref_transaction_delete(transaction, refname,
have_old ? old_sha1 : NULL, have_old ? old_oid.hash : NULL,
update_flags, msg, &err)) update_flags, msg, &err))
die("%s", err.buf); die("%s", err.buf);
@ -286,20 +285,20 @@ static const char *parse_cmd_verify(struct ref_transaction *transaction,
{ {
struct strbuf err = STRBUF_INIT; struct strbuf err = STRBUF_INIT;
char *refname; char *refname;
unsigned char old_sha1[20]; struct object_id old_oid;
refname = parse_refname(input, &next); refname = parse_refname(input, &next);
if (!refname) if (!refname)
die("verify: missing <ref>"); die("verify: missing <ref>");
if (parse_next_sha1(input, &next, old_sha1, "verify", refname, if (parse_next_oid(input, &next, &old_oid, "verify", refname,
PARSE_SHA1_OLD)) PARSE_SHA1_OLD))
hashclr(old_sha1); oidclr(&old_oid);
if (*next != line_termination) if (*next != line_termination)
die("verify %s: extra input: %s", refname, next); die("verify %s: extra input: %s", refname, next);
if (ref_transaction_verify(transaction, refname, old_sha1, if (ref_transaction_verify(transaction, refname, old_oid.hash,
update_flags, &err)) update_flags, &err))
die("%s", err.buf); die("%s", err.buf);
@ -355,7 +354,7 @@ static void update_refs_stdin(struct ref_transaction *transaction)
int cmd_update_ref(int argc, const char **argv, const char *prefix) int cmd_update_ref(int argc, const char **argv, const char *prefix)
{ {
const char *refname, *oldval; const char *refname, *oldval;
unsigned char sha1[20], oldsha1[20]; struct object_id oid, oldoid;
int delete = 0, no_deref = 0, read_stdin = 0, end_null = 0; int delete = 0, no_deref = 0, read_stdin = 0, end_null = 0;
unsigned int flags = 0; unsigned int flags = 0;
int create_reflog = 0; int create_reflog = 0;
@ -412,7 +411,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
refname = argv[0]; refname = argv[0];
value = argv[1]; value = argv[1];
oldval = argv[2]; oldval = argv[2];
if (get_sha1(value, sha1)) if (get_oid(value, &oid))
die("%s: not a valid SHA1", value); die("%s: not a valid SHA1", value);
} }
@ -422,8 +421,8 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
* The empty string implies that the reference * The empty string implies that the reference
* must not already exist: * must not already exist:
*/ */
hashclr(oldsha1); oidclr(&oldoid);
else if (get_sha1(oldval, oldsha1)) else if (get_oid(oldval, &oldoid))
die("%s: not a valid old SHA1", oldval); die("%s: not a valid old SHA1", oldval);
} }
@ -435,10 +434,10 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
* NULL_SHA1 as "don't care" here: * NULL_SHA1 as "don't care" here:
*/ */
return delete_ref(msg, refname, return delete_ref(msg, refname,
(oldval && !is_null_sha1(oldsha1)) ? oldsha1 : NULL, (oldval && !is_null_oid(&oldoid)) ? oldoid.hash : NULL,
flags); flags);
else else
return update_ref(msg, refname, sha1, oldval ? oldsha1 : NULL, return update_ref(msg, refname, oid.hash, oldval ? oldoid.hash : NULL,
flags | create_reflog_flag, flags | create_reflog_flag,
UPDATE_REFS_DIE_ON_ERR); UPDATE_REFS_DIE_ON_ERR);
} }

View File

@ -56,20 +56,21 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
} }
while (i < argc) { while (i < argc) {
unsigned char sha1[20]; struct object_id oid;
const char *name = argv[i++]; const char *name = argv[i++];
if (get_sha1(name, sha1)) {
if (get_oid(name, &oid)) {
had_error = !!error("tag '%s' not found.", name); had_error = !!error("tag '%s' not found.", name);
continue; continue;
} }
if (gpg_verify_tag(sha1, name, flags)) { if (gpg_verify_tag(&oid, name, flags)) {
had_error = 1; had_error = 1;
continue; continue;
} }
if (fmt_pretty) if (fmt_pretty)
pretty_print_ref(name, sha1, fmt_pretty); pretty_print_ref(name, oid.hash, fmt_pretty);
} }
return had_error; return had_error;
} }

45
cache.h
View File

@ -1283,38 +1283,37 @@ struct object_context {
*/ */
struct strbuf symlink_path; struct strbuf symlink_path;
/* /*
* If GET_SHA1_RECORD_PATH is set, this will record path (if any) * If GET_OID_RECORD_PATH is set, this will record path (if any)
* found when resolving the name. The caller is responsible for * found when resolving the name. The caller is responsible for
* releasing the memory. * releasing the memory.
*/ */
char *path; char *path;
}; };
#define GET_SHA1_QUIETLY 01 #define GET_OID_QUIETLY 01
#define GET_SHA1_COMMIT 02 #define GET_OID_COMMIT 02
#define GET_SHA1_COMMITTISH 04 #define GET_OID_COMMITTISH 04
#define GET_SHA1_TREE 010 #define GET_OID_TREE 010
#define GET_SHA1_TREEISH 020 #define GET_OID_TREEISH 020
#define GET_SHA1_BLOB 040 #define GET_OID_BLOB 040
#define GET_SHA1_FOLLOW_SYMLINKS 0100 #define GET_OID_FOLLOW_SYMLINKS 0100
#define GET_SHA1_RECORD_PATH 0200 #define GET_OID_RECORD_PATH 0200
#define GET_SHA1_ONLY_TO_DIE 04000 #define GET_OID_ONLY_TO_DIE 04000
#define GET_SHA1_DISAMBIGUATORS \ #define GET_OID_DISAMBIGUATORS \
(GET_SHA1_COMMIT | GET_SHA1_COMMITTISH | \ (GET_OID_COMMIT | GET_OID_COMMITTISH | \
GET_SHA1_TREE | GET_SHA1_TREEISH | \ GET_OID_TREE | GET_OID_TREEISH | \
GET_SHA1_BLOB) GET_OID_BLOB)
extern int get_sha1(const char *str, unsigned char *sha1);
extern int get_sha1_commit(const char *str, unsigned char *sha1);
extern int get_sha1_committish(const char *str, unsigned char *sha1);
extern int get_sha1_tree(const char *str, unsigned char *sha1);
extern int get_sha1_treeish(const char *str, unsigned char *sha1);
extern int get_sha1_blob(const char *str, unsigned char *sha1);
extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);
extern int get_sha1_with_context(const char *str, unsigned flags, unsigned char *sha1, struct object_context *oc);
extern int get_oid(const char *str, struct object_id *oid); extern int get_oid(const char *str, struct object_id *oid);
extern int get_oid_commit(const char *str, struct object_id *oid);
extern int get_oid_committish(const char *str, struct object_id *oid);
extern int get_oid_tree(const char *str, struct object_id *oid);
extern int get_oid_treeish(const char *str, struct object_id *oid);
extern int get_oid_blob(const char *str, struct object_id *oid);
extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);
extern int get_oid_with_context(const char *str, unsigned flags, struct object_id *oid, struct object_context *oc);
typedef int each_abbrev_fn(const struct object_id *oid, void *); typedef int each_abbrev_fn(const struct object_id *oid, void *);
extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *); extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);

View File

@ -59,7 +59,7 @@ struct commit *lookup_commit_reference_by_name(const char *name)
struct object_id oid; struct object_id oid;
struct commit *commit; struct commit *commit;
if (get_sha1_committish(name, oid.hash)) if (get_oid_committish(name, &oid))
return NULL; return NULL;
commit = lookup_commit_reference(&oid); commit = lookup_commit_reference(&oid);
if (parse_commit(commit)) if (parse_commit(commit))
@ -199,11 +199,11 @@ static void prepare_commit_graft(void)
commit_graft_prepared = 1; commit_graft_prepared = 1;
} }
struct commit_graft *lookup_commit_graft(const unsigned char *sha1) struct commit_graft *lookup_commit_graft(const struct object_id *oid)
{ {
int pos; int pos;
prepare_commit_graft(); prepare_commit_graft();
pos = commit_graft_pos(sha1); pos = commit_graft_pos(oid->hash);
if (pos < 0) if (pos < 0)
return NULL; return NULL;
return commit_graft[pos]; return commit_graft[pos];
@ -335,7 +335,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */ bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
pptr = &item->parents; pptr = &item->parents;
graft = lookup_commit_graft(item->object.oid.hash); graft = lookup_commit_graft(&item->object.oid);
while (bufptr + parent_entry_len < tail && !memcmp(bufptr, "parent ", 7)) { while (bufptr + parent_entry_len < tail && !memcmp(bufptr, "parent ", 7)) {
struct commit *new_parent; struct commit *new_parent;
@ -1587,7 +1587,7 @@ struct commit *get_merge_parent(const char *name)
struct object *obj; struct object *obj;
struct commit *commit; struct commit *commit;
struct object_id oid; struct object_id oid;
if (get_sha1(name, oid.hash)) if (get_oid(name, &oid))
return NULL; return NULL;
obj = parse_object(&oid); obj = parse_object(&oid);
commit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT); commit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT);

View File

@ -249,7 +249,7 @@ typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);
struct commit_graft *read_graft_line(char *buf, int len); struct commit_graft *read_graft_line(char *buf, int len);
int register_commit_graft(struct commit_graft *, int); int register_commit_graft(struct commit_graft *, int);
struct commit_graft *lookup_commit_graft(const unsigned char *sha1); struct commit_graft *lookup_commit_graft(const struct object_id *oid);
extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2); extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2);
extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos); extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos);

View File

@ -1460,9 +1460,9 @@ int git_config_from_mem(config_fn_t fn, const enum config_origin_type origin_typ
return do_config_from(&top, fn, data); return do_config_from(&top, fn, data);
} }
int git_config_from_blob_sha1(config_fn_t fn, int git_config_from_blob_oid(config_fn_t fn,
const char *name, const char *name,
const unsigned char *sha1, const struct object_id *oid,
void *data) void *data)
{ {
enum object_type type; enum object_type type;
@ -1470,7 +1470,7 @@ int git_config_from_blob_sha1(config_fn_t fn,
unsigned long size; unsigned long size;
int ret; int ret;
buf = read_sha1_file(sha1, &type, &size); buf = read_sha1_file(oid->hash, &type, &size);
if (!buf) if (!buf)
return error("unable to load config blob object '%s'", name); return error("unable to load config blob object '%s'", name);
if (type != OBJ_BLOB) { if (type != OBJ_BLOB) {
@ -1488,11 +1488,11 @@ static int git_config_from_blob_ref(config_fn_t fn,
const char *name, const char *name,
void *data) void *data)
{ {
unsigned char sha1[20]; struct object_id oid;
if (get_sha1(name, sha1) < 0) if (get_oid(name, &oid) < 0)
return error("unable to resolve config blob '%s'", name); return error("unable to resolve config blob '%s'", name);
return git_config_from_blob_sha1(fn, name, sha1, data); return git_config_from_blob_oid(fn, name, &oid, data);
} }
const char *git_etc_gitconfig(void) const char *git_etc_gitconfig(void)

View File

@ -39,8 +39,8 @@ extern int git_default_config(const char *, const char *, void *);
extern int git_config_from_file(config_fn_t fn, const char *, void *); extern int git_config_from_file(config_fn_t fn, const char *, void *);
extern int git_config_from_mem(config_fn_t fn, const enum config_origin_type, extern int git_config_from_mem(config_fn_t fn, const enum config_origin_type,
const char *name, const char *buf, size_t len, void *data); const char *name, const char *buf, size_t len, void *data);
extern int git_config_from_blob_sha1(config_fn_t fn, const char *name, extern int git_config_from_blob_oid(config_fn_t fn, const char *name,
const unsigned char *sha1, void *data); const struct object_id *oid, void *data);
extern void git_config_push_parameter(const char *text); extern void git_config_push_parameter(const char *text);
extern int git_config_from_parameters(config_fn_t fn, void *data); extern int git_config_from_parameters(config_fn_t fn, void *data);
extern void read_early_config(config_fn_t cb, void *data); extern void read_early_config(config_fn_t cb, void *data);

2
fsck.c
View File

@ -736,7 +736,7 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
buffer += 41; buffer += 41;
parent_line_count++; parent_line_count++;
} }
graft = lookup_commit_graft(commit->object.oid.hash); graft = lookup_commit_graft(&commit->object.oid);
parent_count = commit_list_count(commit->parents); parent_count = commit_list_count(commit->parents);
if (graft) { if (graft) {
if (graft->nr_parent == -1 && !parent_count) if (graft->nr_parent == -1 && !parent_count)

View File

@ -214,17 +214,17 @@ static int read_mailmap_blob(struct string_list *map,
const char *name, const char *name,
char **repo_abbrev) char **repo_abbrev)
{ {
unsigned char sha1[20]; struct object_id oid;
char *buf; char *buf;
unsigned long size; unsigned long size;
enum object_type type; enum object_type type;
if (!name) if (!name)
return 0; return 0;
if (get_sha1(name, sha1) < 0) if (get_oid(name, &oid) < 0)
return 0; return 0;
buf = read_sha1_file(sha1, &type, &size); buf = read_sha1_file(oid.hash, &type, &size);
if (!buf) if (!buf)
return error("unable to read mailmap object at %s", name); return error("unable to read mailmap object at %s", name);
if (type != OBJ_BLOB) if (type != OBJ_BLOB)

View File

@ -1026,7 +1026,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
t->dirty = 0; t->dirty = 0;
if (flags & NOTES_INIT_EMPTY || !notes_ref || if (flags & NOTES_INIT_EMPTY || !notes_ref ||
get_sha1_treeish(notes_ref, object_oid.hash)) get_oid_treeish(notes_ref, &object_oid))
return; return;
if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, object_oid.hash)) if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, object_oid.hash))
die("Cannot use notes ref %s", notes_ref); die("Cannot use notes ref %s", notes_ref);

2
refs.c
View File

@ -818,7 +818,7 @@ int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, in
for_each_reflog_ent_reverse(refname, read_ref_at_ent, &cb); for_each_reflog_ent_reverse(refname, read_ref_at_ent, &cb);
if (!cb.reccnt) { if (!cb.reccnt) {
if (flags & GET_SHA1_QUIETLY) if (flags & GET_OID_QUIETLY)
exit(128); exit(128);
else else
die("Log for %s is empty.", refname); die("Log for %s is empty.", refname);

View File

@ -1081,7 +1081,7 @@ static int try_explicit_object_name(const char *name,
return 0; return 0;
} }
if (get_sha1(name, oid.hash)) if (get_oid(name, &oid))
return -1; return -1;
if (match) { if (match) {
@ -2297,8 +2297,8 @@ static int parse_push_cas_option(struct push_cas_option *cas, const char *arg, i
if (!*colon) if (!*colon)
entry->use_tracking = 1; entry->use_tracking = 1;
else if (!colon[1]) else if (!colon[1])
hashclr(entry->expect); oidclr(&entry->expect);
else if (get_sha1(colon + 1, entry->expect)) else if (get_oid(colon + 1, &entry->expect))
return error("cannot parse expected object name '%s'", colon + 1); return error("cannot parse expected object name '%s'", colon + 1);
return 0; return 0;
} }
@ -2345,7 +2345,7 @@ static void apply_cas(struct push_cas_option *cas,
continue; continue;
ref->expect_old_sha1 = 1; ref->expect_old_sha1 = 1;
if (!entry->use_tracking) if (!entry->use_tracking)
hashcpy(ref->old_oid_expect.hash, cas->entry[i].expect); oidcpy(&ref->old_oid_expect, &entry->expect);
else if (remote_tracking(remote, ref->name, &ref->old_oid_expect)) else if (remote_tracking(remote, ref->name, &ref->old_oid_expect))
oidclr(&ref->old_oid_expect); oidclr(&ref->old_oid_expect);
return; return;

View File

@ -282,7 +282,7 @@ struct ref *get_stale_heads(struct refspec *refs, int ref_count, struct ref *fet
struct push_cas_option { struct push_cas_option {
unsigned use_tracking_for_rest:1; unsigned use_tracking_for_rest:1;
struct push_cas { struct push_cas {
unsigned char expect[20]; struct object_id expect;
unsigned use_tracking:1; unsigned use_tracking:1;
char *refname; char *refname;
} *entry; } *entry;

View File

@ -160,7 +160,7 @@ int repo_submodule_init(struct repository *submodule,
struct strbuf worktree = STRBUF_INIT; struct strbuf worktree = STRBUF_INIT;
int ret = 0; int ret = 0;
sub = submodule_from_cache(superproject, null_sha1, path); sub = submodule_from_cache(superproject, &null_oid, path);
if (!sub) { if (!sub) {
ret = -1; ret = -1;
goto out; goto out;

View File

@ -1303,7 +1303,7 @@ static int add_parents_only(struct rev_info *revs, const char *arg_, int flags,
flags ^= UNINTERESTING | BOTTOM; flags ^= UNINTERESTING | BOTTOM;
arg++; arg++;
} }
if (get_sha1_committish(arg, oid.hash)) if (get_oid_committish(arg, &oid))
return 0; return 0;
while (1) { while (1) {
it = get_reference(revs, arg, &oid, 0); it = get_reference(revs, arg, &oid, 0);
@ -1452,7 +1452,7 @@ static int handle_dotdot_1(const char *arg, char *dotdot,
unsigned int a_flags, b_flags; unsigned int a_flags, b_flags;
int symmetric = 0; int symmetric = 0;
unsigned int flags_exclude = flags ^ (UNINTERESTING | BOTTOM); unsigned int flags_exclude = flags ^ (UNINTERESTING | BOTTOM);
unsigned int oc_flags = GET_SHA1_COMMITTISH | GET_SHA1_RECORD_PATH; unsigned int oc_flags = GET_OID_COMMITTISH | GET_OID_RECORD_PATH;
a_name = arg; a_name = arg;
if (!*a_name) if (!*a_name)
@ -1466,8 +1466,8 @@ static int handle_dotdot_1(const char *arg, char *dotdot,
if (!*b_name) if (!*b_name)
b_name = "HEAD"; b_name = "HEAD";
if (get_sha1_with_context(a_name, oc_flags, a_oid.hash, a_oc) || if (get_oid_with_context(a_name, oc_flags, &a_oid, a_oc) ||
get_sha1_with_context(b_name, oc_flags, b_oid.hash, b_oc)) get_oid_with_context(b_name, oc_flags, &b_oid, b_oc))
return -1; return -1;
if (!cant_be_filename) { if (!cant_be_filename) {
@ -1548,7 +1548,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
int local_flags; int local_flags;
const char *arg = arg_; const char *arg = arg_;
int cant_be_filename = revarg_opt & REVARG_CANNOT_BE_FILENAME; int cant_be_filename = revarg_opt & REVARG_CANNOT_BE_FILENAME;
unsigned get_sha1_flags = GET_SHA1_RECORD_PATH; unsigned get_sha1_flags = GET_OID_RECORD_PATH;
flags = flags & UNINTERESTING ? flags | BOTTOM : flags & ~BOTTOM; flags = flags & UNINTERESTING ? flags | BOTTOM : flags & ~BOTTOM;
@ -1599,9 +1599,9 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
} }
if (revarg_opt & REVARG_COMMITTISH) if (revarg_opt & REVARG_COMMITTISH)
get_sha1_flags |= GET_SHA1_COMMITTISH; get_sha1_flags |= GET_OID_COMMITTISH;
if (get_sha1_with_context(arg, get_sha1_flags, oid.hash, &oc)) if (get_oid_with_context(arg, get_sha1_flags, &oid, &oc))
return revs->ignore_missing ? 0 : -1; return revs->ignore_missing ? 0 : -1;
if (!cant_be_filename) if (!cant_be_filename)
verify_non_filename(revs->prefix, arg); verify_non_filename(revs->prefix, arg);
@ -2319,7 +2319,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
struct object_id oid; struct object_id oid;
struct object *object; struct object *object;
struct object_context oc; struct object_context oc;
if (get_sha1_with_context(revs->def, 0, oid.hash, &oc)) if (get_oid_with_context(revs->def, 0, &oid, &oc))
diagnose_missing_default(revs->def); diagnose_missing_default(revs->def);
object = get_reference(revs, revs->def, &oid, 0); object = get_reference(revs, revs->def, &oid, 0);
add_pending_object_with_mode(revs, object, revs->def, oc.mode); add_pending_object_with_mode(revs, object, revs->def, oc.mode);

View File

@ -691,7 +691,7 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts,
static int is_original_commit_empty(struct commit *commit) static int is_original_commit_empty(struct commit *commit)
{ {
const unsigned char *ptree_sha1; const struct object_id *ptree_oid;
if (parse_commit(commit)) if (parse_commit(commit))
return error(_("could not parse commit %s\n"), return error(_("could not parse commit %s\n"),
@ -701,12 +701,12 @@ static int is_original_commit_empty(struct commit *commit)
if (parse_commit(parent)) if (parse_commit(parent))
return error(_("could not parse parent commit %s\n"), return error(_("could not parse parent commit %s\n"),
oid_to_hex(&parent->object.oid)); oid_to_hex(&parent->object.oid));
ptree_sha1 = parent->tree->object.oid.hash; ptree_oid = &parent->tree->object.oid;
} else { } else {
ptree_sha1 = EMPTY_TREE_SHA1_BIN; /* commit is root */ ptree_oid = &empty_tree_oid; /* commit is root */
} }
return !hashcmp(ptree_sha1, commit->tree->object.oid.hash); return !oidcmp(ptree_oid, &commit->tree->object.oid);
} }
/* /*
@ -896,18 +896,18 @@ static int update_squash_messages(enum todo_command command,
static void flush_rewritten_pending(void) { static void flush_rewritten_pending(void) {
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
unsigned char newsha1[20]; struct object_id newoid;
FILE *out; FILE *out;
if (strbuf_read_file(&buf, rebase_path_rewritten_pending(), 82) > 0 && if (strbuf_read_file(&buf, rebase_path_rewritten_pending(), (GIT_MAX_HEXSZ + 1) * 2) > 0 &&
!get_sha1("HEAD", newsha1) && !get_oid("HEAD", &newoid) &&
(out = fopen_or_warn(rebase_path_rewritten_list(), "a"))) { (out = fopen_or_warn(rebase_path_rewritten_list(), "a"))) {
char *bol = buf.buf, *eol; char *bol = buf.buf, *eol;
while (*bol) { while (*bol) {
eol = strchrnul(bol, '\n'); eol = strchrnul(bol, '\n');
fprintf(out, "%.*s %s\n", (int)(eol - bol), fprintf(out, "%.*s %s\n", (int)(eol - bol),
bol, sha1_to_hex(newsha1)); bol, oid_to_hex(&newoid));
if (!*eol) if (!*eol)
break; break;
bol = eol + 1; bol = eol + 1;
@ -1594,36 +1594,37 @@ static int rollback_is_safe(void)
return !oidcmp(&actual_head, &expected_head); return !oidcmp(&actual_head, &expected_head);
} }
static int reset_for_rollback(const unsigned char *sha1) static int reset_for_rollback(const struct object_id *oid)
{ {
const char *argv[4]; /* reset --merge <arg> + NULL */ const char *argv[4]; /* reset --merge <arg> + NULL */
argv[0] = "reset"; argv[0] = "reset";
argv[1] = "--merge"; argv[1] = "--merge";
argv[2] = sha1_to_hex(sha1); argv[2] = oid_to_hex(oid);
argv[3] = NULL; argv[3] = NULL;
return run_command_v_opt(argv, RUN_GIT_CMD); return run_command_v_opt(argv, RUN_GIT_CMD);
} }
static int rollback_single_pick(void) static int rollback_single_pick(void)
{ {
unsigned char head_sha1[20]; struct object_id head_oid;
if (!file_exists(git_path_cherry_pick_head()) && if (!file_exists(git_path_cherry_pick_head()) &&
!file_exists(git_path_revert_head())) !file_exists(git_path_revert_head()))
return error(_("no cherry-pick or revert in progress")); return error(_("no cherry-pick or revert in progress"));
if (read_ref_full("HEAD", 0, head_sha1, NULL)) if (read_ref_full("HEAD", 0, head_oid.hash, NULL))
return error(_("cannot resolve HEAD")); return error(_("cannot resolve HEAD"));
if (is_null_sha1(head_sha1)) if (is_null_oid(&head_oid))
return error(_("cannot abort from a branch yet to be born")); return error(_("cannot abort from a branch yet to be born"));
return reset_for_rollback(head_sha1); return reset_for_rollback(&head_oid);
} }
int sequencer_rollback(struct replay_opts *opts) int sequencer_rollback(struct replay_opts *opts)
{ {
FILE *f; FILE *f;
unsigned char sha1[20]; struct object_id oid;
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
const char *p;
f = fopen(git_path_head_file(), "r"); f = fopen(git_path_head_file(), "r");
if (!f && errno == ENOENT) { if (!f && errno == ENOENT) {
@ -1643,12 +1644,12 @@ int sequencer_rollback(struct replay_opts *opts)
goto fail; goto fail;
} }
fclose(f); fclose(f);
if (get_sha1_hex(buf.buf, sha1) || buf.buf[40] != '\0') { if (parse_oid_hex(buf.buf, &oid, &p) || *p != '\0') {
error(_("stored pre-cherry-pick HEAD file '%s' is corrupt"), error(_("stored pre-cherry-pick HEAD file '%s' is corrupt"),
git_path_head_file()); git_path_head_file());
goto fail; goto fail;
} }
if (is_null_sha1(sha1)) { if (is_null_oid(&oid)) {
error(_("cannot abort from a branch yet to be born")); error(_("cannot abort from a branch yet to be born"));
goto fail; goto fail;
} }
@ -1658,7 +1659,7 @@ int sequencer_rollback(struct replay_opts *opts)
warning(_("You seem to have moved HEAD. " warning(_("You seem to have moved HEAD. "
"Not rewinding, check your HEAD!")); "Not rewinding, check your HEAD!"));
} else } else
if (reset_for_rollback(sha1)) if (reset_for_rollback(&oid))
goto fail; goto fail;
strbuf_release(&buf); strbuf_release(&buf);
return sequencer_remove_state(opts); return sequencer_remove_state(opts);
@ -1788,13 +1789,13 @@ static int make_patch(struct commit *commit, struct replay_opts *opts)
static int intend_to_amend(void) static int intend_to_amend(void)
{ {
unsigned char head[20]; struct object_id head;
char *p; char *p;
if (get_sha1("HEAD", head)) if (get_oid("HEAD", &head))
return error(_("cannot read HEAD")); return error(_("cannot read HEAD"));
p = sha1_to_hex(head); p = oid_to_hex(&head);
return write_message(p, strlen(p), rebase_path_amend(), 1); return write_message(p, strlen(p), rebase_path_amend(), 1);
} }
@ -2079,10 +2080,10 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
if (read_oneliner(&head_ref, rebase_path_head_name(), 0) && if (read_oneliner(&head_ref, rebase_path_head_name(), 0) &&
starts_with(head_ref.buf, "refs/")) { starts_with(head_ref.buf, "refs/")) {
const char *msg; const char *msg;
unsigned char head[20], orig[20]; struct object_id head, orig;
int res; int res;
if (get_sha1("HEAD", head)) { if (get_oid("HEAD", &head)) {
res = error(_("cannot read HEAD")); res = error(_("cannot read HEAD"));
cleanup_head_ref: cleanup_head_ref:
strbuf_release(&head_ref); strbuf_release(&head_ref);
@ -2090,7 +2091,7 @@ cleanup_head_ref:
return res; return res;
} }
if (!read_oneliner(&buf, rebase_path_orig_head(), 0) || if (!read_oneliner(&buf, rebase_path_orig_head(), 0) ||
get_sha1_hex(buf.buf, orig)) { get_oid_hex(buf.buf, &orig)) {
res = error(_("could not read orig-head")); res = error(_("could not read orig-head"));
goto cleanup_head_ref; goto cleanup_head_ref;
} }
@ -2101,7 +2102,7 @@ cleanup_head_ref:
} }
msg = reflog_message(opts, "finish", "%s onto %s", msg = reflog_message(opts, "finish", "%s onto %s",
head_ref.buf, buf.buf); head_ref.buf, buf.buf);
if (update_ref(msg, head_ref.buf, head, orig, if (update_ref(msg, head_ref.buf, head.hash, orig.hash,
REF_NODEREF, UPDATE_REFS_MSG_ON_ERR)) { REF_NODEREF, UPDATE_REFS_MSG_ON_ERR)) {
res = error(_("could not update %s"), res = error(_("could not update %s"),
head_ref.buf); head_ref.buf);
@ -2129,8 +2130,8 @@ cleanup_head_ref:
log_tree_opt.disable_stdin = 1; log_tree_opt.disable_stdin = 1;
if (read_oneliner(&buf, rebase_path_orig_head(), 0) && if (read_oneliner(&buf, rebase_path_orig_head(), 0) &&
!get_sha1(buf.buf, orig.hash) && !get_oid(buf.buf, &orig) &&
!get_sha1("HEAD", head.hash)) { !get_oid("HEAD", &head)) {
diff_tree_oid(&orig, &head, "", diff_tree_oid(&orig, &head, "",
&log_tree_opt.diffopt); &log_tree_opt.diffopt);
log_tree_diff_flush(&log_tree_opt); log_tree_diff_flush(&log_tree_opt);
@ -2205,16 +2206,16 @@ static int commit_staged_changes(struct replay_opts *opts)
if (file_exists(rebase_path_amend())) { if (file_exists(rebase_path_amend())) {
struct strbuf rev = STRBUF_INIT; struct strbuf rev = STRBUF_INIT;
unsigned char head[20], to_amend[20]; struct object_id head, to_amend;
if (get_sha1("HEAD", head)) if (get_oid("HEAD", &head))
return error(_("cannot amend non-existing commit")); return error(_("cannot amend non-existing commit"));
if (!read_oneliner(&rev, rebase_path_amend(), 0)) if (!read_oneliner(&rev, rebase_path_amend(), 0))
return error(_("invalid file: '%s'"), rebase_path_amend()); return error(_("invalid file: '%s'"), rebase_path_amend());
if (get_sha1_hex(rev.buf, to_amend)) if (get_oid_hex(rev.buf, &to_amend))
return error(_("invalid contents: '%s'"), return error(_("invalid contents: '%s'"),
rebase_path_amend()); rebase_path_amend());
if (hashcmp(head, to_amend)) if (oidcmp(&head, &to_amend))
return error(_("\nYou have uncommitted changes in your " return error(_("\nYou have uncommitted changes in your "
"working tree. Please, commit them\n" "working tree. Please, commit them\n"
"first and then run 'git rebase " "first and then run 'git rebase "
@ -2266,7 +2267,7 @@ int sequencer_continue(struct replay_opts *opts)
struct object_id oid; struct object_id oid;
if (read_oneliner(&buf, rebase_path_stopped_sha(), 1) && if (read_oneliner(&buf, rebase_path_stopped_sha(), 1) &&
!get_sha1_committish(buf.buf, oid.hash)) !get_oid_committish(buf.buf, &oid))
record_in_rewritten(&oid, peek_command(&todo_list, 0)); record_in_rewritten(&oid, peek_command(&todo_list, 0));
strbuf_release(&buf); strbuf_release(&buf);
} }

View File

@ -10,7 +10,7 @@
#include "dir.h" #include "dir.h"
#include "sha1-array.h" #include "sha1-array.h"
static int get_sha1_oneline(const char *, unsigned char *, struct commit_list *); static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);
typedef int (*disambiguate_hint_fn)(const struct object_id *, void *); typedef int (*disambiguate_hint_fn)(const struct object_id *, void *);
@ -200,7 +200,7 @@ static void find_short_packed_object(struct disambiguate_state *ds)
#define SHORT_NAME_AMBIGUOUS (-2) #define SHORT_NAME_AMBIGUOUS (-2)
static int finish_object_disambiguation(struct disambiguate_state *ds, static int finish_object_disambiguation(struct disambiguate_state *ds,
unsigned char *sha1) struct object_id *oid)
{ {
if (ds->ambiguous) if (ds->ambiguous)
return SHORT_NAME_AMBIGUOUS; return SHORT_NAME_AMBIGUOUS;
@ -229,7 +229,7 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,
if (!ds->candidate_ok) if (!ds->candidate_ok)
return SHORT_NAME_AMBIGUOUS; return SHORT_NAME_AMBIGUOUS;
hashcpy(sha1, ds->candidate.hash); oidcpy(oid, &ds->candidate);
return 0; return 0;
} }
@ -385,35 +385,35 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
return 0; return 0;
} }
static int get_short_sha1(const char *name, int len, unsigned char *sha1, static int get_short_oid(const char *name, int len, struct object_id *oid,
unsigned flags) unsigned flags)
{ {
int status; int status;
struct disambiguate_state ds; struct disambiguate_state ds;
int quietly = !!(flags & GET_SHA1_QUIETLY); int quietly = !!(flags & GET_OID_QUIETLY);
if (init_object_disambiguation(name, len, &ds) < 0) if (init_object_disambiguation(name, len, &ds) < 0)
return -1; return -1;
if (HAS_MULTI_BITS(flags & GET_SHA1_DISAMBIGUATORS)) if (HAS_MULTI_BITS(flags & GET_OID_DISAMBIGUATORS))
die("BUG: multiple get_short_sha1 disambiguator flags"); die("BUG: multiple get_short_oid disambiguator flags");
if (flags & GET_SHA1_COMMIT) if (flags & GET_OID_COMMIT)
ds.fn = disambiguate_commit_only; ds.fn = disambiguate_commit_only;
else if (flags & GET_SHA1_COMMITTISH) else if (flags & GET_OID_COMMITTISH)
ds.fn = disambiguate_committish_only; ds.fn = disambiguate_committish_only;
else if (flags & GET_SHA1_TREE) else if (flags & GET_OID_TREE)
ds.fn = disambiguate_tree_only; ds.fn = disambiguate_tree_only;
else if (flags & GET_SHA1_TREEISH) else if (flags & GET_OID_TREEISH)
ds.fn = disambiguate_treeish_only; ds.fn = disambiguate_treeish_only;
else if (flags & GET_SHA1_BLOB) else if (flags & GET_OID_BLOB)
ds.fn = disambiguate_blob_only; ds.fn = disambiguate_blob_only;
else else
ds.fn = default_disambiguate_hint; ds.fn = default_disambiguate_hint;
find_short_object_filename(&ds); find_short_object_filename(&ds);
find_short_packed_object(&ds); find_short_packed_object(&ds);
status = finish_object_disambiguation(&ds, sha1); status = finish_object_disambiguation(&ds, oid);
if (!quietly && (status == SHORT_NAME_AMBIGUOUS)) { if (!quietly && (status == SHORT_NAME_AMBIGUOUS)) {
error(_("short SHA1 %s is ambiguous"), ds.hex_pfx); error(_("short SHA1 %s is ambiguous"), ds.hex_pfx);
@ -500,12 +500,12 @@ int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len)
} }
sha1_to_hex_r(hex, sha1); sha1_to_hex_r(hex, sha1);
if (len == 40 || !len) if (len == GIT_SHA1_HEXSZ || !len)
return 40; return GIT_SHA1_HEXSZ;
exists = has_sha1_file(sha1); exists = has_sha1_file(sha1);
while (len < 40) { while (len < GIT_SHA1_HEXSZ) {
unsigned char sha1_ret[20]; struct object_id oid_ret;
status = get_short_sha1(hex, len, sha1_ret, GET_SHA1_QUIETLY); status = get_short_oid(hex, len, &oid_ret, GET_OID_QUIETLY);
if (exists if (exists
? !status ? !status
: status == SHORT_NAME_NOT_FOUND) { : status == SHORT_NAME_NOT_FOUND) {
@ -578,10 +578,10 @@ static inline int push_mark(const char *string, int len)
return at_mark(string, len, suffix, ARRAY_SIZE(suffix)); return at_mark(string, len, suffix, ARRAY_SIZE(suffix));
} }
static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned lookup_flags); static int get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);
static int interpret_nth_prior_checkout(const char *name, int namelen, struct strbuf *buf); static int interpret_nth_prior_checkout(const char *name, int namelen, struct strbuf *buf);
static int get_sha1_basic(const char *str, int len, unsigned char *sha1, static int get_oid_basic(const char *str, int len, struct object_id *oid,
unsigned int flags) unsigned int flags)
{ {
static const char *warn_msg = "refname '%.*s' is ambiguous."; static const char *warn_msg = "refname '%.*s' is ambiguous.";
@ -595,14 +595,14 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
"where \"$br\" is somehow empty and a 40-hex ref is created. Please\n" "where \"$br\" is somehow empty and a 40-hex ref is created. Please\n"
"examine these refs and maybe delete them. Turn this message off by\n" "examine these refs and maybe delete them. Turn this message off by\n"
"running \"git config advice.objectNameWarning false\""); "running \"git config advice.objectNameWarning false\"");
unsigned char tmp_sha1[20]; struct object_id tmp_oid;
char *real_ref = NULL; char *real_ref = NULL;
int refs_found = 0; int refs_found = 0;
int at, reflog_len, nth_prior = 0; int at, reflog_len, nth_prior = 0;
if (len == 40 && !get_sha1_hex(str, sha1)) { if (len == GIT_SHA1_HEXSZ && !get_oid_hex(str, oid)) {
if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) { if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {
refs_found = dwim_ref(str, len, tmp_sha1, &real_ref); refs_found = dwim_ref(str, len, tmp_oid.hash, &real_ref);
if (refs_found > 0) { if (refs_found > 0) {
warning(warn_msg, len, str); warning(warn_msg, len, str);
if (advice_object_name_warning) if (advice_object_name_warning)
@ -644,7 +644,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
int detached; int detached;
if (interpret_nth_prior_checkout(str, len, &buf) > 0) { if (interpret_nth_prior_checkout(str, len, &buf) > 0) {
detached = (buf.len == 40 && !get_sha1_hex(buf.buf, sha1)); detached = (buf.len == GIT_SHA1_HEXSZ && !get_oid_hex(buf.buf, oid));
strbuf_release(&buf); strbuf_release(&buf);
if (detached) if (detached)
return 0; return 0;
@ -653,18 +653,18 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
if (!len && reflog_len) if (!len && reflog_len)
/* allow "@{...}" to mean the current branch reflog */ /* allow "@{...}" to mean the current branch reflog */
refs_found = dwim_ref("HEAD", 4, sha1, &real_ref); refs_found = dwim_ref("HEAD", 4, oid->hash, &real_ref);
else if (reflog_len) else if (reflog_len)
refs_found = dwim_log(str, len, sha1, &real_ref); refs_found = dwim_log(str, len, oid->hash, &real_ref);
else else
refs_found = dwim_ref(str, len, sha1, &real_ref); refs_found = dwim_ref(str, len, oid->hash, &real_ref);
if (!refs_found) if (!refs_found)
return -1; return -1;
if (warn_ambiguous_refs && !(flags & GET_SHA1_QUIETLY) && if (warn_ambiguous_refs && !(flags & GET_OID_QUIETLY) &&
(refs_found > 1 || (refs_found > 1 ||
!get_short_sha1(str, len, tmp_sha1, GET_SHA1_QUIETLY))) !get_short_oid(str, len, &tmp_oid, GET_OID_QUIETLY)))
warning(warn_msg, len, str); warning(warn_msg, len, str);
if (reflog_len) { if (reflog_len) {
@ -696,7 +696,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
return -1; return -1;
} }
} }
if (read_ref_at(real_ref, flags, at_time, nth, sha1, NULL, if (read_ref_at(real_ref, flags, at_time, nth, oid->hash, NULL,
&co_time, &co_tz, &co_cnt)) { &co_time, &co_tz, &co_cnt)) {
if (!len) { if (!len) {
if (starts_with(real_ref, "refs/heads/")) { if (starts_with(real_ref, "refs/heads/")) {
@ -709,13 +709,13 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
} }
} }
if (at_time) { if (at_time) {
if (!(flags & GET_SHA1_QUIETLY)) { if (!(flags & GET_OID_QUIETLY)) {
warning("Log for '%.*s' only goes " warning("Log for '%.*s' only goes "
"back to %s.", len, str, "back to %s.", len, str,
show_date(co_time, co_tz, DATE_MODE(RFC2822))); show_date(co_time, co_tz, DATE_MODE(RFC2822)));
} }
} else { } else {
if (flags & GET_SHA1_QUIETLY) { if (flags & GET_OID_QUIETLY) {
exit(128); exit(128);
} }
die("Log for '%.*s' only has %d entries.", die("Log for '%.*s' only has %d entries.",
@ -729,10 +729,10 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
} }
static int get_parent(const char *name, int len, static int get_parent(const char *name, int len,
unsigned char *result, int idx) struct object_id *result, int idx)
{ {
struct object_id oid; struct object_id oid;
int ret = get_sha1_1(name, len, oid.hash, GET_SHA1_COMMITTISH); int ret = get_oid_1(name, len, &oid, GET_OID_COMMITTISH);
struct commit *commit; struct commit *commit;
struct commit_list *p; struct commit_list *p;
@ -742,13 +742,13 @@ static int get_parent(const char *name, int len,
if (parse_commit(commit)) if (parse_commit(commit))
return -1; return -1;
if (!idx) { if (!idx) {
hashcpy(result, commit->object.oid.hash); oidcpy(result, &commit->object.oid);
return 0; return 0;
} }
p = commit->parents; p = commit->parents;
while (p) { while (p) {
if (!--idx) { if (!--idx) {
hashcpy(result, p->item->object.oid.hash); oidcpy(result, &p->item->object.oid);
return 0; return 0;
} }
p = p->next; p = p->next;
@ -757,13 +757,13 @@ static int get_parent(const char *name, int len,
} }
static int get_nth_ancestor(const char *name, int len, static int get_nth_ancestor(const char *name, int len,
unsigned char *result, int generation) struct object_id *result, int generation)
{ {
struct object_id oid; struct object_id oid;
struct commit *commit; struct commit *commit;
int ret; int ret;
ret = get_sha1_1(name, len, oid.hash, GET_SHA1_COMMITTISH); ret = get_oid_1(name, len, &oid, GET_OID_COMMITTISH);
if (ret) if (ret)
return ret; return ret;
commit = lookup_commit_reference(&oid); commit = lookup_commit_reference(&oid);
@ -775,7 +775,7 @@ static int get_nth_ancestor(const char *name, int len,
return -1; return -1;
commit = commit->parents->item; commit = commit->parents->item;
} }
hashcpy(result, commit->object.oid.hash); oidcpy(result, &commit->object.oid);
return 0; return 0;
} }
@ -804,7 +804,7 @@ struct object *peel_to_type(const char *name, int namelen,
} }
} }
static int peel_onion(const char *name, int len, unsigned char *sha1, static int peel_onion(const char *name, int len, struct object_id *oid,
unsigned lookup_flags) unsigned lookup_flags)
{ {
struct object_id outer; struct object_id outer;
@ -849,13 +849,13 @@ static int peel_onion(const char *name, int len, unsigned char *sha1,
else else
return -1; return -1;
lookup_flags &= ~GET_SHA1_DISAMBIGUATORS; lookup_flags &= ~GET_OID_DISAMBIGUATORS;
if (expected_type == OBJ_COMMIT) if (expected_type == OBJ_COMMIT)
lookup_flags |= GET_SHA1_COMMITTISH; lookup_flags |= GET_OID_COMMITTISH;
else if (expected_type == OBJ_TREE) else if (expected_type == OBJ_TREE)
lookup_flags |= GET_SHA1_TREEISH; lookup_flags |= GET_OID_TREEISH;
if (get_sha1_1(name, sp - name - 2, outer.hash, lookup_flags)) if (get_oid_1(name, sp - name - 2, &outer, lookup_flags))
return -1; return -1;
o = parse_object(&outer); o = parse_object(&outer);
@ -865,7 +865,7 @@ static int peel_onion(const char *name, int len, unsigned char *sha1,
o = deref_tag(o, name, sp - name - 2); o = deref_tag(o, name, sp - name - 2);
if (!o || (!o->parsed && !parse_object(&o->oid))) if (!o || (!o->parsed && !parse_object(&o->oid)))
return -1; return -1;
hashcpy(sha1, o->oid.hash); oidcpy(oid, &o->oid);
return 0; return 0;
} }
@ -878,7 +878,7 @@ static int peel_onion(const char *name, int len, unsigned char *sha1,
if (!o) if (!o)
return -1; return -1;
hashcpy(sha1, o->oid.hash); oidcpy(oid, &o->oid);
if (sp[0] == '/') { if (sp[0] == '/') {
/* "$commit^{/foo}" */ /* "$commit^{/foo}" */
char *prefix; char *prefix;
@ -894,17 +894,17 @@ static int peel_onion(const char *name, int len, unsigned char *sha1,
prefix = xstrndup(sp + 1, name + len - 1 - (sp + 1)); prefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));
commit_list_insert((struct commit *)o, &list); commit_list_insert((struct commit *)o, &list);
ret = get_sha1_oneline(prefix, sha1, list); ret = get_oid_oneline(prefix, oid, list);
free(prefix); free(prefix);
return ret; return ret;
} }
return 0; return 0;
} }
static int get_describe_name(const char *name, int len, unsigned char *sha1) static int get_describe_name(const char *name, int len, struct object_id *oid)
{ {
const char *cp; const char *cp;
unsigned flags = GET_SHA1_QUIETLY | GET_SHA1_COMMIT; unsigned flags = GET_OID_QUIETLY | GET_OID_COMMIT;
for (cp = name + len - 1; name + 2 <= cp; cp--) { for (cp = name + len - 1; name + 2 <= cp; cp--) {
char ch = *cp; char ch = *cp;
@ -915,14 +915,14 @@ static int get_describe_name(const char *name, int len, unsigned char *sha1)
if (ch == 'g' && cp[-1] == '-') { if (ch == 'g' && cp[-1] == '-') {
cp++; cp++;
len -= cp - name; len -= cp - name;
return get_short_sha1(cp, len, sha1, flags); return get_short_oid(cp, len, oid, flags);
} }
} }
} }
return -1; return -1;
} }
static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned lookup_flags) static int get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags)
{ {
int ret, has_suffix; int ret, has_suffix;
const char *cp; const char *cp;
@ -949,25 +949,25 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned l
if (!num && len1 == len - 1) if (!num && len1 == len - 1)
num = 1; num = 1;
if (has_suffix == '^') if (has_suffix == '^')
return get_parent(name, len1, sha1, num); return get_parent(name, len1, oid, num);
/* else if (has_suffix == '~') -- goes without saying */ /* else if (has_suffix == '~') -- goes without saying */
return get_nth_ancestor(name, len1, sha1, num); return get_nth_ancestor(name, len1, oid, num);
} }
ret = peel_onion(name, len, sha1, lookup_flags); ret = peel_onion(name, len, oid, lookup_flags);
if (!ret) if (!ret)
return 0; return 0;
ret = get_sha1_basic(name, len, sha1, lookup_flags); ret = get_oid_basic(name, len, oid, lookup_flags);
if (!ret) if (!ret)
return 0; return 0;
/* It could be describe output that is "SOMETHING-gXXXX" */ /* It could be describe output that is "SOMETHING-gXXXX" */
ret = get_describe_name(name, len, sha1); ret = get_describe_name(name, len, oid);
if (!ret) if (!ret)
return 0; return 0;
return get_short_sha1(name, len, sha1, lookup_flags); return get_short_oid(name, len, oid, lookup_flags);
} }
/* /*
@ -1004,7 +1004,7 @@ static int handle_one_ref(const char *path, const struct object_id *oid,
return 0; return 0;
} }
static int get_sha1_oneline(const char *prefix, unsigned char *sha1, static int get_oid_oneline(const char *prefix, struct object_id *oid,
struct commit_list *list) struct commit_list *list)
{ {
struct commit_list *backup = NULL, *l; struct commit_list *backup = NULL, *l;
@ -1044,7 +1044,7 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
unuse_commit_buffer(commit, buf); unuse_commit_buffer(commit, buf);
if (matches) { if (matches) {
hashcpy(sha1, commit->object.oid.hash); oidcpy(oid, &commit->object.oid);
found = 1; found = 1;
break; break;
} }
@ -1140,7 +1140,7 @@ int get_oid_mb(const char *name, struct object_id *oid)
struct strbuf sb; struct strbuf sb;
strbuf_init(&sb, dots - name); strbuf_init(&sb, dots - name);
strbuf_add(&sb, name, dots - name); strbuf_add(&sb, name, dots - name);
st = get_sha1_committish(sb.buf, oid_tmp.hash); st = get_oid_committish(sb.buf, &oid_tmp);
strbuf_release(&sb); strbuf_release(&sb);
} }
if (st) if (st)
@ -1149,7 +1149,7 @@ int get_oid_mb(const char *name, struct object_id *oid)
if (!one) if (!one)
return -1; return -1;
if (get_sha1_committish(dots[3] ? (dots + 3) : "HEAD", oid_tmp.hash)) if (get_oid_committish(dots[3] ? (dots + 3) : "HEAD", &oid_tmp))
return -1; return -1;
two = lookup_commit_reference_gently(&oid_tmp, 0); two = lookup_commit_reference_gently(&oid_tmp, 0);
if (!two) if (!two)
@ -1338,21 +1338,13 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
} }
/* /*
* This is like "get_sha1_basic()", except it allows "sha1 expressions", * This is like "get_oid_basic()", except it allows "object ID expressions",
* notably "xyz^" for "parent of xyz" * notably "xyz^" for "parent of xyz"
*/ */
int get_sha1(const char *name, unsigned char *sha1)
{
struct object_context unused;
return get_sha1_with_context(name, 0, sha1, &unused);
}
/*
* This is like "get_sha1()", but for struct object_id.
*/
int get_oid(const char *name, struct object_id *oid) int get_oid(const char *name, struct object_id *oid)
{ {
return get_sha1(name, oid->hash); struct object_context unused;
return get_oid_with_context(name, 0, oid, &unused);
} }
@ -1366,49 +1358,49 @@ int get_oid(const char *name, struct object_id *oid)
* commit-ish. It is merely to give a hint to the disambiguation * commit-ish. It is merely to give a hint to the disambiguation
* machinery. * machinery.
*/ */
int get_sha1_committish(const char *name, unsigned char *sha1) int get_oid_committish(const char *name, struct object_id *oid)
{ {
struct object_context unused; struct object_context unused;
return get_sha1_with_context(name, GET_SHA1_COMMITTISH, return get_oid_with_context(name, GET_OID_COMMITTISH,
sha1, &unused); oid, &unused);
} }
int get_sha1_treeish(const char *name, unsigned char *sha1) int get_oid_treeish(const char *name, struct object_id *oid)
{ {
struct object_context unused; struct object_context unused;
return get_sha1_with_context(name, GET_SHA1_TREEISH, return get_oid_with_context(name, GET_OID_TREEISH,
sha1, &unused); oid, &unused);
} }
int get_sha1_commit(const char *name, unsigned char *sha1) int get_oid_commit(const char *name, struct object_id *oid)
{ {
struct object_context unused; struct object_context unused;
return get_sha1_with_context(name, GET_SHA1_COMMIT, return get_oid_with_context(name, GET_OID_COMMIT,
sha1, &unused); oid, &unused);
} }
int get_sha1_tree(const char *name, unsigned char *sha1) int get_oid_tree(const char *name, struct object_id *oid)
{ {
struct object_context unused; struct object_context unused;
return get_sha1_with_context(name, GET_SHA1_TREE, return get_oid_with_context(name, GET_OID_TREE,
sha1, &unused); oid, &unused);
} }
int get_sha1_blob(const char *name, unsigned char *sha1) int get_oid_blob(const char *name, struct object_id *oid)
{ {
struct object_context unused; struct object_context unused;
return get_sha1_with_context(name, GET_SHA1_BLOB, return get_oid_with_context(name, GET_OID_BLOB,
sha1, &unused); oid, &unused);
} }
/* Must be called only when object_name:filename doesn't exist. */ /* Must be called only when object_name:filename doesn't exist. */
static void diagnose_invalid_sha1_path(const char *prefix, static void diagnose_invalid_oid_path(const char *prefix,
const char *filename, const char *filename,
const unsigned char *tree_sha1, const struct object_id *tree_oid,
const char *object_name, const char *object_name,
int object_name_len) int object_name_len)
{ {
unsigned char sha1[20]; struct object_id oid;
unsigned mode; unsigned mode;
if (!prefix) if (!prefix)
@ -1420,8 +1412,8 @@ static void diagnose_invalid_sha1_path(const char *prefix,
if (is_missing_file_error(errno)) { if (is_missing_file_error(errno)) {
char *fullname = xstrfmt("%s%s", prefix, filename); char *fullname = xstrfmt("%s%s", prefix, filename);
if (!get_tree_entry(tree_sha1, fullname, if (!get_tree_entry(tree_oid->hash, fullname,
sha1, &mode)) { oid.hash, &mode)) {
die("Path '%s' exists, but not '%s'.\n" die("Path '%s' exists, but not '%s'.\n"
"Did you mean '%.*s:%s' aka '%.*s:./%s'?", "Did you mean '%.*s:%s' aka '%.*s:./%s'?",
fullname, fullname,
@ -1504,24 +1496,24 @@ static char *resolve_relative_path(const char *rel)
rel); rel);
} }
static int get_sha1_with_context_1(const char *name, static int get_oid_with_context_1(const char *name,
unsigned flags, unsigned flags,
const char *prefix, const char *prefix,
unsigned char *sha1, struct object_id *oid,
struct object_context *oc) struct object_context *oc)
{ {
int ret, bracket_depth; int ret, bracket_depth;
int namelen = strlen(name); int namelen = strlen(name);
const char *cp; const char *cp;
int only_to_die = flags & GET_SHA1_ONLY_TO_DIE; int only_to_die = flags & GET_OID_ONLY_TO_DIE;
if (only_to_die) if (only_to_die)
flags |= GET_SHA1_QUIETLY; flags |= GET_OID_QUIETLY;
memset(oc, 0, sizeof(*oc)); memset(oc, 0, sizeof(*oc));
oc->mode = S_IFINVALID; oc->mode = S_IFINVALID;
strbuf_init(&oc->symlink_path, 0); strbuf_init(&oc->symlink_path, 0);
ret = get_sha1_1(name, namelen, sha1, flags); ret = get_oid_1(name, namelen, oid, flags);
if (!ret) if (!ret)
return ret; return ret;
/* /*
@ -1541,7 +1533,7 @@ static int get_sha1_with_context_1(const char *name,
for_each_ref(handle_one_ref, &list); for_each_ref(handle_one_ref, &list);
commit_list_sort_by_date(&list); commit_list_sort_by_date(&list);
return get_sha1_oneline(name + 2, sha1, list); return get_oid_oneline(name + 2, oid, list);
} }
if (namelen < 3 || if (namelen < 3 ||
name[2] != ':' || name[2] != ':' ||
@ -1559,7 +1551,7 @@ static int get_sha1_with_context_1(const char *name,
namelen = strlen(cp); namelen = strlen(cp);
} }
if (flags & GET_SHA1_RECORD_PATH) if (flags & GET_OID_RECORD_PATH)
oc->path = xstrdup(cp); oc->path = xstrdup(cp);
if (!active_cache) if (!active_cache)
@ -1573,7 +1565,7 @@ static int get_sha1_with_context_1(const char *name,
memcmp(ce->name, cp, namelen)) memcmp(ce->name, cp, namelen))
break; break;
if (ce_stage(ce) == stage) { if (ce_stage(ce) == stage) {
hashcpy(sha1, ce->oid.hash); oidcpy(oid, &ce->oid);
oc->mode = ce->ce_mode; oc->mode = ce->ce_mode;
free(new_path); free(new_path);
return 0; return 0;
@ -1594,36 +1586,36 @@ static int get_sha1_with_context_1(const char *name,
break; break;
} }
if (*cp == ':') { if (*cp == ':') {
unsigned char tree_sha1[20]; struct object_id tree_oid;
int len = cp - name; int len = cp - name;
unsigned sub_flags = flags; unsigned sub_flags = flags;
sub_flags &= ~GET_SHA1_DISAMBIGUATORS; sub_flags &= ~GET_OID_DISAMBIGUATORS;
sub_flags |= GET_SHA1_TREEISH; sub_flags |= GET_OID_TREEISH;
if (!get_sha1_1(name, len, tree_sha1, sub_flags)) { if (!get_oid_1(name, len, &tree_oid, sub_flags)) {
const char *filename = cp+1; const char *filename = cp+1;
char *new_filename = NULL; char *new_filename = NULL;
new_filename = resolve_relative_path(filename); new_filename = resolve_relative_path(filename);
if (new_filename) if (new_filename)
filename = new_filename; filename = new_filename;
if (flags & GET_SHA1_FOLLOW_SYMLINKS) { if (flags & GET_OID_FOLLOW_SYMLINKS) {
ret = get_tree_entry_follow_symlinks(tree_sha1, ret = get_tree_entry_follow_symlinks(tree_oid.hash,
filename, sha1, &oc->symlink_path, filename, oid->hash, &oc->symlink_path,
&oc->mode); &oc->mode);
} else { } else {
ret = get_tree_entry(tree_sha1, filename, ret = get_tree_entry(tree_oid.hash, filename,
sha1, &oc->mode); oid->hash, &oc->mode);
if (ret && only_to_die) { if (ret && only_to_die) {
diagnose_invalid_sha1_path(prefix, diagnose_invalid_oid_path(prefix,
filename, filename,
tree_sha1, &tree_oid,
name, len); name, len);
} }
} }
hashcpy(oc->tree, tree_sha1); hashcpy(oc->tree, tree_oid.hash);
if (flags & GET_SHA1_RECORD_PATH) if (flags & GET_OID_RECORD_PATH)
oc->path = xstrdup(filename); oc->path = xstrdup(filename);
free(new_filename); free(new_filename);
@ -1646,13 +1638,13 @@ static int get_sha1_with_context_1(const char *name,
void maybe_die_on_misspelt_object_name(const char *name, const char *prefix) void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)
{ {
struct object_context oc; struct object_context oc;
unsigned char sha1[20]; struct object_id oid;
get_sha1_with_context_1(name, GET_SHA1_ONLY_TO_DIE, prefix, sha1, &oc); get_oid_with_context_1(name, GET_OID_ONLY_TO_DIE, prefix, &oid, &oc);
} }
int get_sha1_with_context(const char *str, unsigned flags, unsigned char *sha1, struct object_context *oc) int get_oid_with_context(const char *str, unsigned flags, struct object_id *oid, struct object_context *oc)
{ {
if (flags & GET_SHA1_FOLLOW_SYMLINKS && flags & GET_SHA1_ONLY_TO_DIE) if (flags & GET_OID_FOLLOW_SYMLINKS && flags & GET_OID_ONLY_TO_DIE)
die("BUG: incompatible flags for get_sha1_with_context"); die("BUG: incompatible flags for get_sha1_with_context");
return get_sha1_with_context_1(str, flags, NULL, sha1, oc); return get_oid_with_context_1(str, flags, NULL, oid, oc);
} }

View File

@ -107,7 +107,7 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
cur_depth++; cur_depth++;
if ((depth != INFINITE_DEPTH && cur_depth >= depth) || if ((depth != INFINITE_DEPTH && cur_depth >= depth) ||
(is_repository_shallow() && !commit->parents && (is_repository_shallow() && !commit->parents &&
(graft = lookup_commit_graft(commit->object.oid.hash)) != NULL && (graft = lookup_commit_graft(&commit->object.oid)) != NULL &&
graft->nr_parent < 0)) { graft->nr_parent < 0)) {
commit_list_insert(commit, &result); commit_list_insert(commit, &result);
commit->object.flags |= shallow_flag; commit->object.flags |= shallow_flag;
@ -398,7 +398,7 @@ void prepare_shallow_info(struct shallow_info *info, struct oid_array *sa)
for (i = 0; i < sa->nr; i++) { for (i = 0; i < sa->nr; i++) {
if (has_object_file(sa->oid + i)) { if (has_object_file(sa->oid + i)) {
struct commit_graft *graft; struct commit_graft *graft;
graft = lookup_commit_graft(sa->oid[i].hash); graft = lookup_commit_graft(&sa->oid[i]);
if (graft && graft->nr_parent < 0) if (graft && graft->nr_parent < 0)
continue; continue;
info->ours[info->nr_ours++] = i; info->ours[info->nr_ours++] = i;

View File

@ -449,19 +449,19 @@ static int parse_config(const char *var, const char *value, void *data)
return ret; return ret;
} }
int gitmodule_sha1_from_commit(const unsigned char *treeish_name, int gitmodule_oid_from_commit(const struct object_id *treeish_name,
unsigned char *gitmodules_sha1, struct object_id *gitmodules_oid,
struct strbuf *rev) struct strbuf *rev)
{ {
int ret = 0; int ret = 0;
if (is_null_sha1(treeish_name)) { if (is_null_oid(treeish_name)) {
hashclr(gitmodules_sha1); oidclr(gitmodules_oid);
return 1; return 1;
} }
strbuf_addf(rev, "%s:.gitmodules", sha1_to_hex(treeish_name)); strbuf_addf(rev, "%s:.gitmodules", oid_to_hex(treeish_name));
if (get_sha1(rev->buf, gitmodules_sha1) >= 0) if (get_oid(rev->buf, gitmodules_oid) >= 0)
ret = 1; ret = 1;
return ret; return ret;
@ -472,13 +472,13 @@ int gitmodule_sha1_from_commit(const unsigned char *treeish_name,
* revisions. * revisions.
*/ */
static const struct submodule *config_from(struct submodule_cache *cache, static const struct submodule *config_from(struct submodule_cache *cache,
const unsigned char *treeish_name, const char *key, const struct object_id *treeish_name, const char *key,
enum lookup_type lookup_type) enum lookup_type lookup_type)
{ {
struct strbuf rev = STRBUF_INIT; struct strbuf rev = STRBUF_INIT;
unsigned long config_size; unsigned long config_size;
char *config = NULL; char *config = NULL;
unsigned char sha1[20]; struct object_id oid;
enum object_type type; enum object_type type;
const struct submodule *submodule = NULL; const struct submodule *submodule = NULL;
struct parse_config_parameter parameter; struct parse_config_parameter parameter;
@ -498,28 +498,28 @@ static const struct submodule *config_from(struct submodule_cache *cache,
return entry->config; return entry->config;
} }
if (!gitmodule_sha1_from_commit(treeish_name, sha1, &rev)) if (!gitmodule_oid_from_commit(treeish_name, &oid, &rev))
goto out; goto out;
switch (lookup_type) { switch (lookup_type) {
case lookup_name: case lookup_name:
submodule = cache_lookup_name(cache, sha1, key); submodule = cache_lookup_name(cache, oid.hash, key);
break; break;
case lookup_path: case lookup_path:
submodule = cache_lookup_path(cache, sha1, key); submodule = cache_lookup_path(cache, oid.hash, key);
break; break;
} }
if (submodule) if (submodule)
goto out; goto out;
config = read_sha1_file(sha1, &type, &config_size); config = read_sha1_file(oid.hash, &type, &config_size);
if (!config || type != OBJ_BLOB) if (!config || type != OBJ_BLOB)
goto out; goto out;
/* fill the submodule config into the cache */ /* fill the submodule config into the cache */
parameter.cache = cache; parameter.cache = cache;
parameter.treeish_name = treeish_name; parameter.treeish_name = treeish_name->hash;
parameter.gitmodules_sha1 = sha1; parameter.gitmodules_sha1 = oid.hash;
parameter.overwrite = 0; parameter.overwrite = 0;
git_config_from_mem(parse_config, CONFIG_ORIGIN_SUBMODULE_BLOB, rev.buf, git_config_from_mem(parse_config, CONFIG_ORIGIN_SUBMODULE_BLOB, rev.buf,
config, config_size, &parameter); config, config_size, &parameter);
@ -528,9 +528,9 @@ static const struct submodule *config_from(struct submodule_cache *cache,
switch (lookup_type) { switch (lookup_type) {
case lookup_name: case lookup_name:
return cache_lookup_name(cache, sha1, key); return cache_lookup_name(cache, oid.hash, key);
case lookup_path: case lookup_path:
return cache_lookup_path(cache, sha1, key); return cache_lookup_path(cache, oid.hash, key);
default: default:
return NULL; return NULL;
} }
@ -572,14 +572,14 @@ int parse_submodule_config_option(const char *var, const char *value)
return submodule_config_option(the_repository, var, value); return submodule_config_option(the_repository, var, value);
} }
const struct submodule *submodule_from_name(const unsigned char *treeish_name, const struct submodule *submodule_from_name(const struct object_id *treeish_name,
const char *name) const char *name)
{ {
submodule_cache_check_init(the_repository); submodule_cache_check_init(the_repository);
return config_from(the_repository->submodule_cache, treeish_name, name, lookup_name); return config_from(the_repository->submodule_cache, treeish_name, name, lookup_name);
} }
const struct submodule *submodule_from_path(const unsigned char *treeish_name, const struct submodule *submodule_from_path(const struct object_id *treeish_name,
const char *path) const char *path)
{ {
submodule_cache_check_init(the_repository); submodule_cache_check_init(the_repository);
@ -587,7 +587,7 @@ const struct submodule *submodule_from_path(const unsigned char *treeish_name,
} }
const struct submodule *submodule_from_cache(struct repository *repo, const struct submodule *submodule_from_cache(struct repository *repo,
const unsigned char *treeish_name, const struct object_id *treeish_name,
const char *key) const char *key)
{ {
submodule_cache_check_init(repo); submodule_cache_check_init(repo);

View File

@ -38,15 +38,15 @@ extern int parse_submodule_config_option(const char *var, const char *value);
extern int submodule_config_option(struct repository *repo, extern int submodule_config_option(struct repository *repo,
const char *var, const char *value); const char *var, const char *value);
extern const struct submodule *submodule_from_name( extern const struct submodule *submodule_from_name(
const unsigned char *commit_or_tree, const char *name); const struct object_id *commit_or_tree, const char *name);
extern const struct submodule *submodule_from_path( extern const struct submodule *submodule_from_path(
const unsigned char *commit_or_tree, const char *path); const struct object_id *commit_or_tree, const char *path);
extern const struct submodule *submodule_from_cache(struct repository *repo, extern const struct submodule *submodule_from_cache(struct repository *repo,
const unsigned char *treeish_name, const struct object_id *treeish_name,
const char *key); const char *key);
extern int gitmodule_sha1_from_commit(const unsigned char *commit_sha1, extern int gitmodule_oid_from_commit(const struct object_id *commit_oid,
unsigned char *gitmodules_sha1, struct object_id *gitmodules_oid,
struct strbuf *rev); struct strbuf *rev);
extern void submodule_free(void); extern void submodule_free(void);
#endif /* SUBMODULE_CONFIG_H */ #endif /* SUBMODULE_CONFIG_H */

View File

@ -85,7 +85,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
if (is_gitmodules_unmerged(&the_index)) if (is_gitmodules_unmerged(&the_index))
die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first")); die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first"));
submodule = submodule_from_path(null_sha1, oldpath); submodule = submodule_from_path(&null_oid, oldpath);
if (!submodule || !submodule->name) { if (!submodule || !submodule->name) {
warning(_("Could not find section in .gitmodules where path=%s"), oldpath); warning(_("Could not find section in .gitmodules where path=%s"), oldpath);
return -1; return -1;
@ -119,7 +119,7 @@ int remove_path_from_gitmodules(const char *path)
if (is_gitmodules_unmerged(&the_index)) if (is_gitmodules_unmerged(&the_index))
die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first")); die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first"));
submodule = submodule_from_path(null_sha1, path); submodule = submodule_from_path(&null_oid, path);
if (!submodule || !submodule->name) { if (!submodule || !submodule->name) {
warning(_("Could not find section in .gitmodules where path=%s"), path); warning(_("Could not find section in .gitmodules where path=%s"), path);
return -1; return -1;
@ -163,7 +163,7 @@ done:
void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt, void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
const char *path) const char *path)
{ {
const struct submodule *submodule = submodule_from_path(null_sha1, path); const struct submodule *submodule = submodule_from_path(&null_oid, path);
if (submodule) { if (submodule) {
if (submodule->ignore) if (submodule->ignore)
handle_ignore_submodules_arg(diffopt, submodule->ignore); handle_ignore_submodules_arg(diffopt, submodule->ignore);
@ -258,14 +258,14 @@ void gitmodules_config(void)
repo_read_gitmodules(the_repository); repo_read_gitmodules(the_repository);
} }
void gitmodules_config_sha1(const unsigned char *commit_sha1) void gitmodules_config_oid(const struct object_id *commit_oid)
{ {
struct strbuf rev = STRBUF_INIT; struct strbuf rev = STRBUF_INIT;
unsigned char sha1[20]; struct object_id oid;
if (gitmodule_sha1_from_commit(commit_sha1, sha1, &rev)) { if (gitmodule_oid_from_commit(commit_oid, &oid, &rev)) {
git_config_from_blob_sha1(git_modules_config, rev.buf, git_config_from_blob_oid(submodule_config, rev.buf,
sha1, NULL); &oid, NULL);
} }
strbuf_release(&rev); strbuf_release(&rev);
} }
@ -281,7 +281,7 @@ int is_submodule_active(struct repository *repo, const char *path)
const struct string_list *sl; const struct string_list *sl;
const struct submodule *module; const struct submodule *module;
module = submodule_from_cache(repo, null_sha1, path); module = submodule_from_cache(repo, &null_oid, path);
/* early return if there isn't a path->module mapping */ /* early return if there isn't a path->module mapping */
if (!module) if (!module)
@ -721,7 +721,7 @@ const struct submodule *submodule_from_ce(const struct cache_entry *ce)
if (!should_update_submodules()) if (!should_update_submodules())
return NULL; return NULL;
return submodule_from_path(null_sha1, ce->name); return submodule_from_path(&null_oid, ce->name);
} }
static struct oid_array *submodule_commits(struct string_list *submodules, static struct oid_array *submodule_commits(struct string_list *submodules,
@ -1176,9 +1176,9 @@ static int get_next_submodule(struct child_process *cp,
if (!S_ISGITLINK(ce->ce_mode)) if (!S_ISGITLINK(ce->ce_mode))
continue; continue;
submodule = submodule_from_path(null_sha1, ce->name); submodule = submodule_from_path(&null_oid, ce->name);
if (!submodule) if (!submodule)
submodule = submodule_from_name(null_sha1, ce->name); submodule = submodule_from_name(&null_oid, ce->name);
default_argv = "yes"; default_argv = "yes";
if (spf->command_line_option == RECURSE_SUBMODULES_DEFAULT) { if (spf->command_line_option == RECURSE_SUBMODULES_DEFAULT) {
@ -1552,7 +1552,7 @@ int submodule_move_head(const char *path,
if (old && !is_submodule_populated_gently(path, error_code_ptr)) if (old && !is_submodule_populated_gently(path, error_code_ptr))
return 0; return 0;
sub = submodule_from_path(null_sha1, path); sub = submodule_from_path(&null_oid, path);
if (!sub) if (!sub)
die("BUG: could not get submodule information for '%s'", path); die("BUG: could not get submodule information for '%s'", path);
@ -1829,7 +1829,7 @@ static void relocate_single_git_dir_into_superproject(const char *prefix,
real_old_git_dir = real_pathdup(old_git_dir, 1); real_old_git_dir = real_pathdup(old_git_dir, 1);
sub = submodule_from_path(null_sha1, path); sub = submodule_from_path(&null_oid, path);
if (!sub) if (!sub)
die(_("could not lookup name for submodule '%s'"), path); die(_("could not lookup name for submodule '%s'"), path);
@ -1885,7 +1885,7 @@ void absorb_git_dir_into_superproject(const char *prefix,
* superproject did not rewrite the git file links yet, * superproject did not rewrite the git file links yet,
* fix it now. * fix it now.
*/ */
sub = submodule_from_path(null_sha1, path); sub = submodule_from_path(&null_oid, path);
if (!sub) if (!sub)
die(_("could not lookup name for submodule '%s'"), path); die(_("could not lookup name for submodule '%s'"), path);
connect_work_tree_and_git_dir(path, connect_work_tree_and_git_dir(path,
@ -2028,7 +2028,7 @@ int submodule_to_gitdir(struct strbuf *buf, const char *submodule)
} }
if (!is_git_directory(buf->buf)) { if (!is_git_directory(buf->buf)) {
gitmodules_config(); gitmodules_config();
sub = submodule_from_path(null_sha1, submodule); sub = submodule_from_path(&null_oid, submodule);
if (!sub) { if (!sub) {
ret = -1; ret = -1;
goto cleanup; goto cleanup;

View File

@ -49,7 +49,7 @@ int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
void load_submodule_cache(void); void load_submodule_cache(void);
extern void gitmodules_config(void); extern void gitmodules_config(void);
extern void repo_read_gitmodules(struct repository *repo); extern void repo_read_gitmodules(struct repository *repo);
extern void gitmodules_config_sha1(const unsigned char *commit_sha1); extern void gitmodules_config_oid(const struct object_id *commit_oid);
extern int is_submodule_active(struct repository *repo, const char *path); extern int is_submodule_active(struct repository *repo, const char *path);
/* /*
* Determine if a submodule has been populated at a given 'path' by checking if * Determine if a submodule has been populated at a given 'path' by checking if

View File

@ -41,7 +41,7 @@ int cmd_main(int argc, const char **argv)
git_config(git_test_config, NULL); git_config(git_test_config, NULL);
while (*arg) { while (*arg) {
unsigned char commit_sha1[20]; struct object_id commit_oid;
const struct submodule *submodule; const struct submodule *submodule;
const char *commit; const char *commit;
const char *path_or_name; const char *path_or_name;
@ -50,14 +50,14 @@ int cmd_main(int argc, const char **argv)
path_or_name = arg[1]; path_or_name = arg[1];
if (commit[0] == '\0') if (commit[0] == '\0')
hashclr(commit_sha1); oidclr(&commit_oid);
else if (get_sha1(commit, commit_sha1) < 0) else if (get_oid(commit, &commit_oid) < 0)
die_usage(argc, argv, "Commit not found."); die_usage(argc, argv, "Commit not found.");
if (lookup_name) { if (lookup_name) {
submodule = submodule_from_name(commit_sha1, path_or_name); submodule = submodule_from_name(&commit_oid, path_or_name);
} else } else
submodule = submodule_from_path(commit_sha1, path_or_name); submodule = submodule_from_path(&commit_oid, path_or_name);
if (!submodule) if (!submodule)
die_usage(argc, argv, "Submodule not found."); die_usage(argc, argv, "Submodule not found.");

10
tag.c
View File

@ -33,7 +33,7 @@ static int run_gpg_verify(const char *buf, unsigned long size, unsigned flags)
return ret; return ret;
} }
int gpg_verify_tag(const unsigned char *sha1, const char *name_to_report, int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
unsigned flags) unsigned flags)
{ {
enum object_type type; enum object_type type;
@ -41,20 +41,20 @@ int gpg_verify_tag(const unsigned char *sha1, const char *name_to_report,
unsigned long size; unsigned long size;
int ret; int ret;
type = sha1_object_info(sha1, NULL); type = sha1_object_info(oid->hash, NULL);
if (type != OBJ_TAG) if (type != OBJ_TAG)
return error("%s: cannot verify a non-tag object of type %s.", return error("%s: cannot verify a non-tag object of type %s.",
name_to_report ? name_to_report ?
name_to_report : name_to_report :
find_unique_abbrev(sha1, DEFAULT_ABBREV), find_unique_abbrev(oid->hash, DEFAULT_ABBREV),
typename(type)); typename(type));
buf = read_sha1_file(sha1, &type, &size); buf = read_sha1_file(oid->hash, &type, &size);
if (!buf) if (!buf)
return error("%s: unable to read file.", return error("%s: unable to read file.",
name_to_report ? name_to_report ?
name_to_report : name_to_report :
find_unique_abbrev(sha1, DEFAULT_ABBREV)); find_unique_abbrev(oid->hash, DEFAULT_ABBREV));
ret = run_gpg_verify(buf, size, flags); ret = run_gpg_verify(buf, size, flags);

2
tag.h
View File

@ -17,7 +17,7 @@ extern int parse_tag_buffer(struct tag *item, const void *data, unsigned long si
extern int parse_tag(struct tag *item); extern int parse_tag(struct tag *item);
extern struct object *deref_tag(struct object *, const char *, int); extern struct object *deref_tag(struct object *, const char *, int);
extern struct object *deref_tag_noverify(struct object *); extern struct object *deref_tag_noverify(struct object *);
extern int gpg_verify_tag(const unsigned char *sha1, extern int gpg_verify_tag(const struct object_id *oid,
const char *name_to_report, unsigned flags); const char *name_to_report, unsigned flags);
#endif /* TAG_H */ #endif /* TAG_H */

View File

@ -927,7 +927,7 @@ static int push_refs_with_export(struct transport *transport,
struct object_id oid; struct object_id oid;
private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name); private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
if (private && !get_sha1(private, oid.hash)) { if (private && !get_oid(private, &oid)) {
strbuf_addf(&buf, "^%s", private); strbuf_addf(&buf, "^%s", private);
string_list_append(&revlist_args, strbuf_detach(&buf, NULL)); string_list_append(&revlist_args, strbuf_detach(&buf, NULL));
oidcpy(&ref->old_oid, &oid); oidcpy(&ref->old_oid, &oid);