sha1_name: convert get_sha1* to get_oid*

Now that all the callers of get_sha1 directly or indirectly use struct object_id, rename the functions starting with get_sha1 to start with get_oid. Convert the internals in sha1_name.c to use struct object_id as well, and eliminate explicit length checks where possible. Convert a use of 40 in get_oid_basic to GIT_SHA1_HEXSZ. Outside of sha1_name.c and cache.h, this transition was made with the following semantic patch: @@ expression E1, E2; @@ - get_sha1(E1, E2.hash) + get_oid(E1, &E2) @@ expression E1, E2; @@ - get_sha1(E1, E2->hash) + get_oid(E1, E2) @@ expression E1, E2; @@ - get_sha1_committish(E1, E2.hash) + get_oid_committish(E1, &E2) @@ expression E1, E2; @@ - get_sha1_committish(E1, E2->hash) + get_oid_committish(E1, E2) @@ expression E1, E2; @@ - get_sha1_treeish(E1, E2.hash) + get_oid_treeish(E1, &E2) @@ expression E1, E2; @@ - get_sha1_treeish(E1, E2->hash) + get_oid_treeish(E1, E2) @@ expression E1, E2; @@ - get_sha1_commit(E1, E2.hash) + get_oid_commit(E1, &E2) @@ expression E1, E2; @@ - get_sha1_commit(E1, E2->hash) + get_oid_commit(E1, E2) @@ expression E1, E2; @@ - get_sha1_tree(E1, E2.hash) + get_oid_tree(E1, &E2) @@ expression E1, E2; @@ - get_sha1_tree(E1, E2->hash) + get_oid_tree(E1, E2) @@ expression E1, E2; @@ - get_sha1_blob(E1, E2.hash) + get_oid_blob(E1, &E2) @@ expression E1, E2; @@ - get_sha1_blob(E1, E2->hash) + get_oid_blob(E1, E2) @@ expression E1, E2, E3, E4; @@ - get_sha1_with_context(E1, E2, E3.hash, E4) + get_oid_with_context(E1, E2, &E3, E4) @@ expression E1, E2, E3, E4; @@ - get_sha1_with_context(E1, E2, E3->hash, E4) + get_oid_with_context(E1, E2, E3, E4) Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Jul 13, 2017 at 23:49 UTC e82caf384bb3c7f41ec5419de04e6493d7b0f4a5
20 files changed +144 -153
apply.c
+2 -2
@@ -3551,7 +3551,7 @@ static int try_threeway(struct apply_state *state,
3551 /* Preimage the patch was prepared for */
3552 if (patch->is_new)
3553 write_sha1_file("", 0, blob_type, pre_oid.hash);
3554 - else if (get_sha1(patch->old_sha1_prefix, pre_oid.hash) ||
3554 + else if (get_oid(patch->old_sha1_prefix, &pre_oid) ||
3555 read_blob_object(&buf, &pre_oid, patch->old_mode))
3556 return error(_("repository lacks the necessary blob to fall back on 3-way merge."));
3557
@@ -4075,7 +4075,7 @@ static int build_fake_ancestor(struct apply_state *state, struct patch *list)
4075 else
4076 return error(_("sha1 information is lacking or "
4077 "useless for submodule %s"), name);
4078 - } else if (!get_sha1_blob(patch->old_sha1_prefix, oid.hash)) {
4078 + } else if (!get_oid_blob(patch->old_sha1_prefix, &oid)) {
4079 ; /* ok */
4080 } else if (!patch->lines_added && !patch->lines_deleted) {
4081 /* mode-only change: update the current */
archive.c
+1 -1
@@ -358,7 +358,7 @@ static void parse_treeish_arg(const char **argv,
358 free(ref);
359 }
360
361 - if (get_sha1(name, oid.hash))
361 + if (get_oid(name, &oid))
362 die("Not a valid object name");
363
364 commit = lookup_commit_reference_gently(&oid, 1);
builtin/am.c
+3 -3
@@ -1131,7 +1131,7 @@ static int index_has_changes(struct strbuf *sb)
1131 struct object_id head;
1132 int i;
1133
1134 - if (!get_sha1_tree("HEAD", head.hash)) {
1134 + if (!get_oid_tree("HEAD", &head)) {
1135 struct diff_options opt;
1136
1137 diff_setup(&opt);
@@ -1432,7 +1432,7 @@ static void write_index_patch(const struct am_state *state)
1432 struct rev_info rev_info;
1433 FILE *fp;
1434
1435 - if (!get_sha1_tree("HEAD", head.hash))
1435 + if (!get_oid_tree("HEAD", &head))
1436 tree = lookup_tree(&head);
1437 else
1438 tree = lookup_tree(&empty_tree_oid);
@@ -1661,7 +1661,7 @@ static void do_commit(const struct am_state *state)
1661 if (write_cache_as_tree(tree.hash, 0, NULL))
1662 die(_("git write-tree failed to write a tree"));
1663
1664 - if (!get_sha1_commit("HEAD", parent.hash)) {
1664 + if (!get_oid_commit("HEAD", &parent)) {
1665 old_oid = &parent;
1666 commit_list_insert(lookup_commit(&parent), &parents);
1667 } else {
builtin/cat-file.c
+3 -3
@@ -63,8 +63,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
63 if (unknown_type)
64 flags |= OBJECT_INFO_ALLOW_UNKNOWN_TYPE;
65
66 - if (get_sha1_with_context(obj_name, GET_SHA1_RECORD_PATH,
67 - oid.hash, &obj_context))
66 + if (get_oid_with_context(obj_name, GET_SHA1_RECORD_PATH,
67 + &oid, &obj_context))
68 die("Not a valid object name %s", obj_name);
69
70 if (!path)
@@ -364,7 +364,7 @@ static void batch_one_object(const char *obj_name, struct batch_options *opt,
364 int flags = opt->follow_symlinks ? GET_SHA1_FOLLOW_SYMLINKS : 0;
365 enum follow_symlinks_result result;
366
367 - result = get_sha1_with_context(obj_name, flags, data->oid.hash, &ctx);
367 + result = get_oid_with_context(obj_name, flags, &data->oid, &ctx);
368 if (result != FOUND) {
369 switch (result) {
370 case MISSING_OBJECT:
builtin/commit-tree.c
+2 -2
@@ -56,7 +56,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
56 struct object_id oid;
57 if (argc <= ++i)
58 usage(commit_tree_usage);
59 - if (get_sha1_commit(argv[i], oid.hash))
59 + if (get_oid_commit(argv[i], &oid))
60 die("Not a valid object name %s", argv[i]);
61 assert_sha1_type(oid.hash, OBJ_COMMIT);
62 new_parent(lookup_commit(&oid), &parents);
@@ -106,7 +106,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
106 continue;
107 }
108
109 - if (get_sha1_tree(arg, tree_oid.hash))
109 + if (get_oid_tree(arg, &tree_oid))
110 die("Not a valid object name %s", arg);
111 if (got_tree)
112 die("Cannot give more than one trees");
builtin/commit.c
+4 -4
@@ -510,7 +510,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
510 s->index_file = index_file;
511 s->fp = fp;
512 s->nowarn = nowarn;
513 - s->is_initial = get_sha1(s->reference, oid.hash) ? 1 : 0;
513 + s->is_initial = get_oid(s->reference, &oid) ? 1 : 0;
514 if (!s->is_initial)
515 hashcpy(s->sha1_commit, oid.hash);
516 s->status_format = status_format;
@@ -891,7 +891,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
891 if (amend)
892 parent = "HEAD^1";
893
894 - if (get_sha1(parent, oid.hash)) {
894 + if (get_oid(parent, &oid)) {
895 int i, ita_nr = 0;
896
897 for (i = 0; i < active_nr; i++)
@@ -1387,7 +1387,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1387
1388 fd = hold_locked_index(&index_lock, 0);
1389
1390 - s.is_initial = get_sha1(s.reference, oid.hash) ? 1 : 0;
1390 + s.is_initial = get_oid(s.reference, &oid) ? 1 : 0;
1391 if (!s.is_initial)
1392 hashcpy(s.sha1_commit, oid.hash);
1393
@@ -1657,7 +1657,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1657 status_format = STATUS_FORMAT_NONE; /* Ignore status.short */
1658 s.colopts = 0;
1659
1660 - if (get_sha1("HEAD", oid.hash))
1660 + if (get_oid("HEAD", &oid))
1661 current_head = NULL;
1662 else {
1663 current_head = lookup_commit_or_die(&oid, "HEAD");
builtin/grep.c
+2 -2
@@ -1207,8 +1207,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
1207 break;
1208 }
1209
1210 - if (get_sha1_with_context(arg, GET_SHA1_RECORD_PATH,
1211 - oid.hash, &oc)) {
1210 + if (get_oid_with_context(arg, GET_SHA1_RECORD_PATH,
1211 + &oid, &oc)) {
1212 if (seen_dashdash)
1213 die(_("unable to resolve revision: %s"), arg);
1214 break;
builtin/log.c
+2 -2
@@ -484,8 +484,8 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c
484 !DIFF_OPT_TST(&rev->diffopt, ALLOW_TEXTCONV))
485 return stream_blob_to_fd(1, oid, NULL, 0);
486
487 - if (get_sha1_with_context(obj_name, GET_SHA1_RECORD_PATH,
488 - oidc.hash, &obj_context))
487 + if (get_oid_with_context(obj_name, GET_SHA1_RECORD_PATH,
488 + &oidc, &obj_context))
489 die(_("Not a valid object name %s"), obj_name);
490 if (!obj_context.path ||
491 !textconv_object(obj_context.path, obj_context.mode, &oidc, 1, &buf, &size)) {
builtin/replace.c
+2 -2
@@ -50,7 +50,7 @@ static int show_reference(const char *refname, const struct object_id *oid,
50 struct object_id object;
51 enum object_type obj_type, repl_type;
52
53 - if (get_sha1(refname, object.hash))
53 + if (get_oid(refname, &object))
54 return error("Failed to resolve '%s' as a valid ref.", refname);
55
56 obj_type = sha1_object_info(object.hash, NULL);
@@ -365,7 +365,7 @@ static void check_one_mergetag(struct commit *commit,
365 /* iterate over new parents */
366 for (i = 1; i < mergetag_data->argc; i++) {
367 struct object_id oid;
368 - if (get_sha1(mergetag_data->argv[i], oid.hash) < 0)
368 + if (get_oid(mergetag_data->argv[i], &oid) < 0)
369 die(_("Not a valid object name: '%s'"), mergetag_data->argv[i]);
370 if (!oidcmp(&tag->tagged->oid, &oid))
371 return; /* found */
builtin/reset.c
+5 -5
@@ -219,8 +219,8 @@ static void parse_args(struct pathspec *pathspec,
219 * has to be unambiguous. If there is a single argument, it
220 * can not be a tree
221 */
222 - else if ((!argv[1] && !get_sha1_committish(argv[0], unused.hash)) ||
223 - (argv[1] && !get_sha1_treeish(argv[0], unused.hash))) {
222 + else if ((!argv[1] && !get_oid_committish(argv[0], &unused)) ||
223 + (argv[1] && !get_oid_treeish(argv[0], &unused))) {
224 /*
225 * Ok, argv[0] looks like a commit/tree; it should not
226 * be a filename.
@@ -310,13 +310,13 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
310
311 load_submodule_cache();
312
313 - unborn = !strcmp(rev, "HEAD") && get_sha1("HEAD", oid.hash);
313 + unborn = !strcmp(rev, "HEAD") && get_oid("HEAD", &oid);
314 if (unborn) {
315 /* reset on unborn branch: treat as reset to empty tree */
316 hashcpy(oid.hash, EMPTY_TREE_SHA1_BIN);
317 } else if (!pathspec.nr) {
318 struct commit *commit;
319 - if (get_sha1_committish(rev, oid.hash))
319 + if (get_oid_committish(rev, &oid))
320 die(_("Failed to resolve '%s' as a valid revision."), rev);
321 commit = lookup_commit_reference(&oid);
322 if (!commit)
@@ -324,7 +324,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
324 oidcpy(&oid, &commit->object.oid);
325 } else {
326 struct tree *tree;
327 - if (get_sha1_treeish(rev, oid.hash))
327 + if (get_oid_treeish(rev, &oid))
328 die(_("Failed to resolve '%s' as a valid tree."), rev);
329 tree = parse_tree_indirect(&oid);
330 if (!tree)
builtin/rev-parse.c
+3 -3
@@ -274,7 +274,7 @@ static int try_difference(const char *arg)
274 return 0;
275 }
276
277 - if (!get_sha1_committish(this, oid.hash) && !get_sha1_committish(next, end.hash)) {
277 + if (!get_oid_committish(this, &oid) && !get_oid_committish(next, &end)) {
278 show_rev(NORMAL, &end, next);
279 show_rev(symmetric ? NORMAL : REVERSED, &oid, this);
280 if (symmetric) {
@@ -328,7 +328,7 @@ static int try_parent_shorthands(const char *arg)
328 return 0;
329
330 *dotdot = 0;
331 - if (get_sha1_committish(arg, oid.hash)) {
331 + if (get_oid_committish(arg, &oid)) {
332 *dotdot = '^';
333 return 0;
334 }
@@ -911,7 +911,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
911 name++;
912 type = REVERSED;
913 }
914 - if (!get_sha1_with_context(name, flags, oid.hash, &unused)) {
914 + if (!get_oid_with_context(name, flags, &oid, &unused)) {
915 if (verify)
916 revs_count++;
917 else
builtin/show-branch.c
+4 -4
@@ -393,7 +393,7 @@ static int append_head_ref(const char *refname, const struct object_id *oid,
393 /* If both heads/foo and tags/foo exists, get_sha1 would
394 * get confused.
395 */
396 - if (get_sha1(refname + ofs, tmp.hash) || oidcmp(&tmp, oid))
396 + if (get_oid(refname + ofs, &tmp) || oidcmp(&tmp, oid))
397 ofs = 5;
398 return append_ref(refname + ofs, oid, 0);
399 }
@@ -408,7 +408,7 @@ static int append_remote_ref(const char *refname, const struct object_id *oid,
408 /* If both heads/foo and tags/foo exists, get_sha1 would
409 * get confused.
410 */
411 - if (get_sha1(refname + ofs, tmp.hash) || oidcmp(&tmp, oid))
411 + if (get_oid(refname + ofs, &tmp) || oidcmp(&tmp, oid))
412 ofs = 5;
413 return append_ref(refname + ofs, oid, 0);
414 }
@@ -514,7 +514,7 @@ static int show_independent(struct commit **rev,
514 static void append_one_rev(const char *av)
515 {
516 struct object_id revkey;
517 - if (!get_sha1(av, revkey.hash)) {
517 + if (!get_oid(av, &revkey)) {
518 append_ref(av, &revkey, 0);
519 return;
520 }
@@ -808,7 +808,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
808 die(Q_("cannot handle more than %d rev.",
809 "cannot handle more than %d revs.",
810 MAX_REVS), MAX_REVS);
811 - if (get_sha1(ref_name[num_rev], revkey.hash))
811 + if (get_oid(ref_name[num_rev], &revkey))
812 die(_("'%s' is not a valid ref."), ref_name[num_rev]);
813 commit = lookup_commit_reference(&revkey);
814 if (!commit)
cache.h
+7 -8
@@ -1305,16 +1305,15 @@ struct object_context {
1305 GET_SHA1_TREE | GET_SHA1_TREEISH | \
1306 GET_SHA1_BLOB)
1307
1308 -extern int get_sha1(const char *str, unsigned char *sha1);
1309 -extern int get_sha1_commit(const char *str, unsigned char *sha1);
1310 -extern int get_sha1_committish(const char *str, unsigned char *sha1);
1311 -extern int get_sha1_tree(const char *str, unsigned char *sha1);
1312 -extern int get_sha1_treeish(const char *str, unsigned char *sha1);
1313 -extern int get_sha1_blob(const char *str, unsigned char *sha1);
1308 +extern int get_oid(const char *str, struct object_id *oid);
1309 +extern int get_oid_commit(const char *str, struct object_id *oid);
1310 +extern int get_oid_committish(const char *str, struct object_id *oid);
1311 +extern int get_oid_tree(const char *str, struct object_id *oid);
1312 +extern int get_oid_treeish(const char *str, struct object_id *oid);
1313 +extern int get_oid_blob(const char *str, struct object_id *oid);
1314 extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);
1315 -extern int get_sha1_with_context(const char *str, unsigned flags, unsigned char *sha1, struct object_context *oc);
1315 +extern int get_oid_with_context(const char *str, unsigned flags, struct object_id *oid, struct object_context *oc);
1316
1317 -extern int get_oid(const char *str, struct object_id *oid);
1317
1318 typedef int each_abbrev_fn(const struct object_id *oid, void *);
1319 extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);
commit.c
+2 -2
@@ -59,7 +59,7 @@ struct commit *lookup_commit_reference_by_name(const char *name)
59 struct object_id oid;
60 struct commit *commit;
61
62 - if (get_sha1_committish(name, oid.hash))
62 + if (get_oid_committish(name, &oid))
63 return NULL;
64 commit = lookup_commit_reference(&oid);
65 if (parse_commit(commit))
@@ -1587,7 +1587,7 @@ struct commit *get_merge_parent(const char *name)
1587 struct object *obj;
1588 struct commit *commit;
1589 struct object_id oid;
1590 - if (get_sha1(name, oid.hash))
1590 + if (get_oid(name, &oid))
1591 return NULL;
1592 obj = parse_object(&oid);
1593 commit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT);
notes.c
+1 -1
@@ -1026,7 +1026,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
1026 t->dirty = 0;
1027
1028 if (flags & NOTES_INIT_EMPTY || !notes_ref ||
1029 - get_sha1_treeish(notes_ref, object_oid.hash))
1029 + get_oid_treeish(notes_ref, &object_oid))
1030 return;
1031 if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, object_oid.hash))
1032 die("Cannot use notes ref %s", notes_ref);
remote.c
+1 -1
@@ -1078,7 +1078,7 @@ static int try_explicit_object_name(const char *name,
1078 return 0;
1079 }
1080
1081 - if (get_sha1(name, oid.hash))
1081 + if (get_oid(name, &oid))
1082 return -1;
1083
1084 if (match) {
revision.c
+5 -5
@@ -1303,7 +1303,7 @@ static int add_parents_only(struct rev_info *revs, const char *arg_, int flags,
1303 flags ^= UNINTERESTING | BOTTOM;
1304 arg++;
1305 }
1306 - if (get_sha1_committish(arg, oid.hash))
1306 + if (get_oid_committish(arg, &oid))
1307 return 0;
1308 while (1) {
1309 it = get_reference(revs, arg, &oid, 0);
@@ -1467,8 +1467,8 @@ static int handle_dotdot_1(const char *arg, char *dotdot,
1467 if (!*b_name)
1468 b_name = "HEAD";
1469
1470 - if (get_sha1_with_context(a_name, oc_flags, a_oid.hash, a_oc) ||
1471 - get_sha1_with_context(b_name, oc_flags, b_oid.hash, b_oc))
1470 + if (get_oid_with_context(a_name, oc_flags, &a_oid, a_oc) ||
1471 + get_oid_with_context(b_name, oc_flags, &b_oid, b_oc))
1472 return -1;
1473
1474 if (!cant_be_filename) {
@@ -1602,7 +1602,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
1602 if (revarg_opt & REVARG_COMMITTISH)
1603 get_sha1_flags |= GET_SHA1_COMMITTISH;
1604
1605 - if (get_sha1_with_context(arg, get_sha1_flags, oid.hash, &oc))
1605 + if (get_oid_with_context(arg, get_sha1_flags, &oid, &oc))
1606 return revs->ignore_missing ? 0 : -1;
1607 if (!cant_be_filename)
1608 verify_non_filename(revs->prefix, arg);
@@ -2321,7 +2321,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
2321 struct object_id oid;
2322 struct object *object;
2323 struct object_context oc;
2324 - if (get_sha1_with_context(revs->def, 0, oid.hash, &oc))
2324 + if (get_oid_with_context(revs->def, 0, &oid, &oc))
2325 diagnose_missing_default(revs->def);
2326 object = get_reference(revs, revs->def, &oid, 0);
2327 add_pending_object_with_mode(revs, object, revs->def, oc.mode);
sequencer.c
+3 -3
@@ -2130,8 +2130,8 @@ cleanup_head_ref:
2130 log_tree_opt.disable_stdin = 1;
2131
2132 if (read_oneliner(&buf, rebase_path_orig_head(), 0) &&
2133 - !get_sha1(buf.buf, orig.hash) &&
2134 - !get_sha1("HEAD", head.hash)) {
2133 + !get_oid(buf.buf, &orig) &&
2134 + !get_oid("HEAD", &head)) {
2135 diff_tree_oid(&orig, &head, "",
2136 &log_tree_opt.diffopt);
2137 log_tree_diff_flush(&log_tree_opt);
@@ -2267,7 +2267,7 @@ int sequencer_continue(struct replay_opts *opts)
2267 struct object_id oid;
2268
2269 if (read_oneliner(&buf, rebase_path_stopped_sha(), 1) &&
2270 - !get_sha1_committish(buf.buf, oid.hash))
2270 + !get_oid_committish(buf.buf, &oid))
2271 record_in_rewritten(&oid, peek_command(&todo_list, 0));
2272 strbuf_release(&buf);
2273 }
sha1_name.c
+91 -99
@@ -10,7 +10,7 @@
10 #include "dir.h"
11 #include "sha1-array.h"
12
13 -static int get_sha1_oneline(const char *, unsigned char *, struct commit_list *);
13 +static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);
14
15 typedef int (*disambiguate_hint_fn)(const struct object_id *, void *);
16
@@ -200,7 +200,7 @@ static void find_short_packed_object(struct disambiguate_state *ds)
200 #define SHORT_NAME_AMBIGUOUS (-2)
201
202 static int finish_object_disambiguation(struct disambiguate_state *ds,
203 - unsigned char *sha1)
203 + struct object_id *oid)
204 {
205 if (ds->ambiguous)
206 return SHORT_NAME_AMBIGUOUS;
@@ -229,7 +229,7 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,
229 if (!ds->candidate_ok)
230 return SHORT_NAME_AMBIGUOUS;
231
232 - hashcpy(sha1, ds->candidate.hash);
232 + oidcpy(oid, &ds->candidate);
233 return 0;
234 }
235
@@ -385,7 +385,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
385 return 0;
386 }
387
388 -static int get_short_sha1(const char *name, int len, unsigned char *sha1,
388 +static int get_short_oid(const char *name, int len, struct object_id *oid,
389 unsigned flags)
390 {
391 int status;
@@ -396,7 +396,7 @@ static int get_short_sha1(const char *name, int len, unsigned char *sha1,
396 return -1;
397
398 if (HAS_MULTI_BITS(flags & GET_SHA1_DISAMBIGUATORS))
399 - die("BUG: multiple get_short_sha1 disambiguator flags");
399 + die("BUG: multiple get_short_oid disambiguator flags");
400
401 if (flags & GET_SHA1_COMMIT)
402 ds.fn = disambiguate_commit_only;
@@ -413,7 +413,7 @@ static int get_short_sha1(const char *name, int len, unsigned char *sha1,
413
414 find_short_object_filename(&ds);
415 find_short_packed_object(&ds);
416 - status = finish_object_disambiguation(&ds, sha1);
416 + status = finish_object_disambiguation(&ds, oid);
417
418 if (!quietly && (status == SHORT_NAME_AMBIGUOUS)) {
419 error(_("short SHA1 %s is ambiguous"), ds.hex_pfx);
@@ -504,8 +504,8 @@ int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len)
504 return 40;
505 exists = has_sha1_file(sha1);
506 while (len < 40) {
507 - unsigned char sha1_ret[20];
508 - status = get_short_sha1(hex, len, sha1_ret, GET_SHA1_QUIETLY);
507 + struct object_id oid_ret;
508 + status = get_short_oid(hex, len, &oid_ret, GET_SHA1_QUIETLY);
509 if (exists
510 ? !status
511 : status == SHORT_NAME_NOT_FOUND) {
@@ -578,10 +578,10 @@ static inline int push_mark(const char *string, int len)
578 return at_mark(string, len, suffix, ARRAY_SIZE(suffix));
579 }
580
581 -static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned lookup_flags);
581 +static int get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);
582 static int interpret_nth_prior_checkout(const char *name, int namelen, struct strbuf *buf);
583
584 -static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
584 +static int get_oid_basic(const char *str, int len, struct object_id *oid,
585 unsigned int flags)
586 {
587 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,
595 "where \"$br\" is somehow empty and a 40-hex ref is created. Please\n"
596 "examine these refs and maybe delete them. Turn this message off by\n"
597 "running \"git config advice.objectNameWarning false\"");
598 - unsigned char tmp_sha1[20];
598 + struct object_id tmp_oid;
599 char *real_ref = NULL;
600 int refs_found = 0;
601 int at, reflog_len, nth_prior = 0;
602
603 - if (len == 40 && !get_sha1_hex(str, sha1)) {
603 + if (len == GIT_SHA1_HEXSZ && !get_oid_hex(str, oid)) {
604 if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {
605 - refs_found = dwim_ref(str, len, tmp_sha1, &real_ref);
605 + refs_found = dwim_ref(str, len, tmp_oid.hash, &real_ref);
606 if (refs_found > 0) {
607 warning(warn_msg, len, str);
608 if (advice_object_name_warning)
@@ -644,7 +644,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
644 int detached;
645
646 if (interpret_nth_prior_checkout(str, len, &buf) > 0) {
647 - detached = (buf.len == 40 && !get_sha1_hex(buf.buf, sha1));
647 + detached = (buf.len == GIT_SHA1_HEXSZ && !get_oid_hex(buf.buf, oid));
648 strbuf_release(&buf);
649 if (detached)
650 return 0;
@@ -653,18 +653,18 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
653
654 if (!len && reflog_len)
655 /* allow "@{...}" to mean the current branch reflog */
656 - refs_found = dwim_ref("HEAD", 4, sha1, &real_ref);
656 + refs_found = dwim_ref("HEAD", 4, oid->hash, &real_ref);
657 else if (reflog_len)
658 - refs_found = dwim_log(str, len, sha1, &real_ref);
658 + refs_found = dwim_log(str, len, oid->hash, &real_ref);
659 else
660 - refs_found = dwim_ref(str, len, sha1, &real_ref);
660 + refs_found = dwim_ref(str, len, oid->hash, &real_ref);
661
662 if (!refs_found)
663 return -1;
664
665 if (warn_ambiguous_refs && !(flags & GET_SHA1_QUIETLY) &&
666 (refs_found > 1 ||
667 - !get_short_sha1(str, len, tmp_sha1, GET_SHA1_QUIETLY)))
667 + !get_short_oid(str, len, &tmp_oid, GET_SHA1_QUIETLY)))
668 warning(warn_msg, len, str);
669
670 if (reflog_len) {
@@ -696,7 +696,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
696 return -1;
697 }
698 }
699 - if (read_ref_at(real_ref, flags, at_time, nth, sha1, NULL,
699 + if (read_ref_at(real_ref, flags, at_time, nth, oid->hash, NULL,
700 &co_time, &co_tz, &co_cnt)) {
701 if (!len) {
702 if (starts_with(real_ref, "refs/heads/")) {
@@ -729,10 +729,10 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
729 }
730
731 static int get_parent(const char *name, int len,
732 - unsigned char *result, int idx)
732 + struct object_id *result, int idx)
733 {
734 struct object_id oid;
735 - int ret = get_sha1_1(name, len, oid.hash, GET_SHA1_COMMITTISH);
735 + int ret = get_oid_1(name, len, &oid, GET_SHA1_COMMITTISH);
736 struct commit *commit;
737 struct commit_list *p;
738
@@ -742,13 +742,13 @@ static int get_parent(const char *name, int len,
742 if (parse_commit(commit))
743 return -1;
744 if (!idx) {
745 - hashcpy(result, commit->object.oid.hash);
745 + oidcpy(result, &commit->object.oid);
746 return 0;
747 }
748 p = commit->parents;
749 while (p) {
750 if (!--idx) {
751 - hashcpy(result, p->item->object.oid.hash);
751 + oidcpy(result, &p->item->object.oid);
752 return 0;
753 }
754 p = p->next;
@@ -757,13 +757,13 @@ static int get_parent(const char *name, int len,
757 }
758
759 static int get_nth_ancestor(const char *name, int len,
760 - unsigned char *result, int generation)
760 + struct object_id *result, int generation)
761 {
762 struct object_id oid;
763 struct commit *commit;
764 int ret;
765
766 - ret = get_sha1_1(name, len, oid.hash, GET_SHA1_COMMITTISH);
766 + ret = get_oid_1(name, len, &oid, GET_SHA1_COMMITTISH);
767 if (ret)
768 return ret;
769 commit = lookup_commit_reference(&oid);
@@ -775,7 +775,7 @@ static int get_nth_ancestor(const char *name, int len,
775 return -1;
776 commit = commit->parents->item;
777 }
778 - hashcpy(result, commit->object.oid.hash);
778 + oidcpy(result, &commit->object.oid);
779 return 0;
780 }
781
@@ -804,7 +804,7 @@ struct object *peel_to_type(const char *name, int namelen,
804 }
805 }
806
807 -static int peel_onion(const char *name, int len, unsigned char *sha1,
807 +static int peel_onion(const char *name, int len, struct object_id *oid,
808 unsigned lookup_flags)
809 {
810 struct object_id outer;
@@ -855,7 +855,7 @@ static int peel_onion(const char *name, int len, unsigned char *sha1,
855 else if (expected_type == OBJ_TREE)
856 lookup_flags |= GET_SHA1_TREEISH;
857
858 - if (get_sha1_1(name, sp - name - 2, outer.hash, lookup_flags))
858 + if (get_oid_1(name, sp - name - 2, &outer, lookup_flags))
859 return -1;
860
861 o = parse_object(&outer);
@@ -865,7 +865,7 @@ static int peel_onion(const char *name, int len, unsigned char *sha1,
865 o = deref_tag(o, name, sp - name - 2);
866 if (!o || (!o->parsed && !parse_object(&o->oid)))
867 return -1;
868 - hashcpy(sha1, o->oid.hash);
868 + oidcpy(oid, &o->oid);
869 return 0;
870 }
871
@@ -878,7 +878,7 @@ static int peel_onion(const char *name, int len, unsigned char *sha1,
878 if (!o)
879 return -1;
880
881 - hashcpy(sha1, o->oid.hash);
881 + oidcpy(oid, &o->oid);
882 if (sp[0] == '/') {
883 /* "$commit^{/foo}" */
884 char *prefix;
@@ -894,14 +894,14 @@ static int peel_onion(const char *name, int len, unsigned char *sha1,
894
895 prefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));
896 commit_list_insert((struct commit *)o, &list);
897 - ret = get_sha1_oneline(prefix, sha1, list);
897 + ret = get_oid_oneline(prefix, oid, list);
898 free(prefix);
899 return ret;
900 }
901 return 0;
902 }
903
904 -static int get_describe_name(const char *name, int len, unsigned char *sha1)
904 +static int get_describe_name(const char *name, int len, struct object_id *oid)
905 {
906 const char *cp;
907 unsigned flags = GET_SHA1_QUIETLY | GET_SHA1_COMMIT;
@@ -915,14 +915,14 @@ static int get_describe_name(const char *name, int len, unsigned char *sha1)
915 if (ch == 'g' && cp[-1] == '-') {
916 cp++;
917 len -= cp - name;
918 - return get_short_sha1(cp, len, sha1, flags);
918 + return get_short_oid(cp, len, oid, flags);
919 }
920 }
921 }
922 return -1;
923 }
924
925 -static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned lookup_flags)
925 +static int get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags)
926 {
927 int ret, has_suffix;
928 const char *cp;
@@ -949,25 +949,25 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned l
949 if (!num && len1 == len - 1)
950 num = 1;
951 if (has_suffix == '^')
952 - return get_parent(name, len1, sha1, num);
952 + return get_parent(name, len1, oid, num);
953 /* else if (has_suffix == '~') -- goes without saying */
954 - return get_nth_ancestor(name, len1, sha1, num);
954 + return get_nth_ancestor(name, len1, oid, num);
955 }
956
957 - ret = peel_onion(name, len, sha1, lookup_flags);
957 + ret = peel_onion(name, len, oid, lookup_flags);
958 if (!ret)
959 return 0;
960
961 - ret = get_sha1_basic(name, len, sha1, lookup_flags);
961 + ret = get_oid_basic(name, len, oid, lookup_flags);
962 if (!ret)
963 return 0;
964
965 /* It could be describe output that is "SOMETHING-gXXXX" */
966 - ret = get_describe_name(name, len, sha1);
966 + ret = get_describe_name(name, len, oid);
967 if (!ret)
968 return 0;
969
970 - return get_short_sha1(name, len, sha1, lookup_flags);
970 + return get_short_oid(name, len, oid, lookup_flags);
971 }
972
973 /*
@@ -1004,7 +1004,7 @@ static int handle_one_ref(const char *path, const struct object_id *oid,
1004 return 0;
1005 }
1006
1007 -static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
1007 +static int get_oid_oneline(const char *prefix, struct object_id *oid,
1008 struct commit_list *list)
1009 {
1010 struct commit_list *backup = NULL, *l;
@@ -1044,7 +1044,7 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
1044 unuse_commit_buffer(commit, buf);
1045
1046 if (matches) {
1047 - hashcpy(sha1, commit->object.oid.hash);
1047 + oidcpy(oid, &commit->object.oid);
1048 found = 1;
1049 break;
1050 }
@@ -1140,7 +1140,7 @@ int get_oid_mb(const char *name, struct object_id *oid)
1140 struct strbuf sb;
1141 strbuf_init(&sb, dots - name);
1142 strbuf_add(&sb, name, dots - name);
1143 - st = get_sha1_committish(sb.buf, oid_tmp.hash);
1143 + st = get_oid_committish(sb.buf, &oid_tmp);
1144 strbuf_release(&sb);
1145 }
1146 if (st)
@@ -1149,7 +1149,7 @@ int get_oid_mb(const char *name, struct object_id *oid)
1149 if (!one)
1150 return -1;
1151
1152 - if (get_sha1_committish(dots[3] ? (dots + 3) : "HEAD", oid_tmp.hash))
1152 + if (get_oid_committish(dots[3] ? (dots + 3) : "HEAD", &oid_tmp))
1153 return -1;
1154 two = lookup_commit_reference_gently(&oid_tmp, 0);
1155 if (!two)
@@ -1338,21 +1338,13 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
1338 }
1339
1340 /*
1341 - * This is like "get_sha1_basic()", except it allows "sha1 expressions",
1341 + * This is like "get_oid_basic()", except it allows "object ID expressions",
1342 * notably "xyz^" for "parent of xyz"
1343 */
1344 -int get_sha1(const char *name, unsigned char *sha1)
1345 -{
1346 - struct object_context unused;
1347 - return get_sha1_with_context(name, 0, sha1, &unused);
1348 -}
1349 -
1350 -/*
1351 - * This is like "get_sha1()", but for struct object_id.
1352 - */
1344 int get_oid(const char *name, struct object_id *oid)
1345 {
1355 - return get_sha1(name, oid->hash);
1346 + struct object_context unused;
1347 + return get_oid_with_context(name, 0, oid, &unused);
1348 }
1349
1350
@@ -1366,49 +1358,49 @@ int get_oid(const char *name, struct object_id *oid)
1358 * commit-ish. It is merely to give a hint to the disambiguation
1359 * machinery.
1360 */
1369 -int get_sha1_committish(const char *name, unsigned char *sha1)
1361 +int get_oid_committish(const char *name, struct object_id *oid)
1362 {
1363 struct object_context unused;
1372 - return get_sha1_with_context(name, GET_SHA1_COMMITTISH,
1373 - sha1, &unused);
1364 + return get_oid_with_context(name, GET_SHA1_COMMITTISH,
1365 + oid, &unused);
1366 }
1367
1376 -int get_sha1_treeish(const char *name, unsigned char *sha1)
1368 +int get_oid_treeish(const char *name, struct object_id *oid)
1369 {
1370 struct object_context unused;
1379 - return get_sha1_with_context(name, GET_SHA1_TREEISH,
1380 - sha1, &unused);
1371 + return get_oid_with_context(name, GET_SHA1_TREEISH,
1372 + oid, &unused);
1373 }
1374
1383 -int get_sha1_commit(const char *name, unsigned char *sha1)
1375 +int get_oid_commit(const char *name, struct object_id *oid)
1376 {
1377 struct object_context unused;
1386 - return get_sha1_with_context(name, GET_SHA1_COMMIT,
1387 - sha1, &unused);
1378 + return get_oid_with_context(name, GET_SHA1_COMMIT,
1379 + oid, &unused);
1380 }
1381
1390 -int get_sha1_tree(const char *name, unsigned char *sha1)
1382 +int get_oid_tree(const char *name, struct object_id *oid)
1383 {
1384 struct object_context unused;
1393 - return get_sha1_with_context(name, GET_SHA1_TREE,
1394 - sha1, &unused);
1385 + return get_oid_with_context(name, GET_SHA1_TREE,
1386 + oid, &unused);
1387 }
1388
1397 -int get_sha1_blob(const char *name, unsigned char *sha1)
1389 +int get_oid_blob(const char *name, struct object_id *oid)
1390 {
1391 struct object_context unused;
1400 - return get_sha1_with_context(name, GET_SHA1_BLOB,
1401 - sha1, &unused);
1392 + return get_oid_with_context(name, GET_SHA1_BLOB,
1393 + oid, &unused);
1394 }
1395
1396 /* Must be called only when object_name:filename doesn't exist. */
1405 -static void diagnose_invalid_sha1_path(const char *prefix,
1406 - const char *filename,
1407 - const unsigned char *tree_sha1,
1408 - const char *object_name,
1409 - int object_name_len)
1397 +static void diagnose_invalid_oid_path(const char *prefix,
1398 + const char *filename,
1399 + const struct object_id *tree_oid,
1400 + const char *object_name,
1401 + int object_name_len)
1402 {
1411 - unsigned char sha1[20];
1403 + struct object_id oid;
1404 unsigned mode;
1405
1406 if (!prefix)
@@ -1420,8 +1412,8 @@ static void diagnose_invalid_sha1_path(const char *prefix,
1412 if (is_missing_file_error(errno)) {
1413 char *fullname = xstrfmt("%s%s", prefix, filename);
1414
1423 - if (!get_tree_entry(tree_sha1, fullname,
1424 - sha1, &mode)) {
1415 + if (!get_tree_entry(tree_oid->hash, fullname,
1416 + oid.hash, &mode)) {
1417 die("Path '%s' exists, but not '%s'.\n"
1418 "Did you mean '%.*s:%s' aka '%.*s:./%s'?",
1419 fullname,
@@ -1504,11 +1496,11 @@ static char *resolve_relative_path(const char *rel)
1496 rel);
1497 }
1498
1507 -static int get_sha1_with_context_1(const char *name,
1508 - unsigned flags,
1509 - const char *prefix,
1510 - unsigned char *sha1,
1511 - struct object_context *oc)
1499 +static int get_oid_with_context_1(const char *name,
1500 + unsigned flags,
1501 + const char *prefix,
1502 + struct object_id *oid,
1503 + struct object_context *oc)
1504 {
1505 int ret, bracket_depth;
1506 int namelen = strlen(name);
@@ -1521,7 +1513,7 @@ static int get_sha1_with_context_1(const char *name,
1513 memset(oc, 0, sizeof(*oc));
1514 oc->mode = S_IFINVALID;
1515 strbuf_init(&oc->symlink_path, 0);
1524 - ret = get_sha1_1(name, namelen, sha1, flags);
1516 + ret = get_oid_1(name, namelen, oid, flags);
1517 if (!ret)
1518 return ret;
1519 /*
@@ -1541,7 +1533,7 @@ static int get_sha1_with_context_1(const char *name,
1533
1534 for_each_ref(handle_one_ref, &list);
1535 commit_list_sort_by_date(&list);
1544 - return get_sha1_oneline(name + 2, sha1, list);
1536 + return get_oid_oneline(name + 2, oid, list);
1537 }
1538 if (namelen < 3 ||
1539 name[2] != ':' ||
@@ -1573,7 +1565,7 @@ static int get_sha1_with_context_1(const char *name,
1565 memcmp(ce->name, cp, namelen))
1566 break;
1567 if (ce_stage(ce) == stage) {
1576 - hashcpy(sha1, ce->oid.hash);
1568 + oidcpy(oid, &ce->oid);
1569 oc->mode = ce->ce_mode;
1570 free(new_path);
1571 return 0;
@@ -1594,14 +1586,14 @@ static int get_sha1_with_context_1(const char *name,
1586 break;
1587 }
1588 if (*cp == ':') {
1597 - unsigned char tree_sha1[20];
1589 + struct object_id tree_oid;
1590 int len = cp - name;
1591 unsigned sub_flags = flags;
1592
1593 sub_flags &= ~GET_SHA1_DISAMBIGUATORS;
1594 sub_flags |= GET_SHA1_TREEISH;
1595
1604 - if (!get_sha1_1(name, len, tree_sha1, sub_flags)) {
1596 + if (!get_oid_1(name, len, &tree_oid, sub_flags)) {
1597 const char *filename = cp+1;
1598 char *new_filename = NULL;
1599
@@ -1609,20 +1601,20 @@ static int get_sha1_with_context_1(const char *name,
1601 if (new_filename)
1602 filename = new_filename;
1603 if (flags & GET_SHA1_FOLLOW_SYMLINKS) {
1612 - ret = get_tree_entry_follow_symlinks(tree_sha1,
1613 - filename, sha1, &oc->symlink_path,
1604 + ret = get_tree_entry_follow_symlinks(tree_oid.hash,
1605 + filename, oid->hash, &oc->symlink_path,
1606 &oc->mode);
1607 } else {
1616 - ret = get_tree_entry(tree_sha1, filename,
1617 - sha1, &oc->mode);
1608 + ret = get_tree_entry(tree_oid.hash, filename,
1609 + oid->hash, &oc->mode);
1610 if (ret && only_to_die) {
1619 - diagnose_invalid_sha1_path(prefix,
1611 + diagnose_invalid_oid_path(prefix,
1612 filename,
1621 - tree_sha1,
1613 + &tree_oid,
1614 name, len);
1615 }
1616 }
1625 - hashcpy(oc->tree, tree_sha1);
1617 + hashcpy(oc->tree, tree_oid.hash);
1618 if (flags & GET_SHA1_RECORD_PATH)
1619 oc->path = xstrdup(filename);
1620
@@ -1646,13 +1638,13 @@ static int get_sha1_with_context_1(const char *name,
1638 void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)
1639 {
1640 struct object_context oc;
1649 - unsigned char sha1[20];
1650 - get_sha1_with_context_1(name, GET_SHA1_ONLY_TO_DIE, prefix, sha1, &oc);
1641 + struct object_id oid;
1642 + get_oid_with_context_1(name, GET_SHA1_ONLY_TO_DIE, prefix, &oid, &oc);
1643 }
1644
1653 -int get_sha1_with_context(const char *str, unsigned flags, unsigned char *sha1, struct object_context *oc)
1645 +int get_oid_with_context(const char *str, unsigned flags, struct object_id *oid, struct object_context *oc)
1646 {
1647 if (flags & GET_SHA1_FOLLOW_SYMLINKS && flags & GET_SHA1_ONLY_TO_DIE)
1648 die("BUG: incompatible flags for get_sha1_with_context");
1657 - return get_sha1_with_context_1(str, flags, NULL, sha1, oc);
1649 + return get_oid_with_context_1(str, flags, NULL, oid, oc);
1650 }
transport-helper.c
+1 -1
@@ -927,7 +927,7 @@ static int push_refs_with_export(struct transport *transport,
927 struct object_id oid;
928
929 private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
930 - if (private && !get_sha1(private, oid.hash)) {
930 + if (private && !get_oid(private, &oid)) {
931 strbuf_addf(&buf, "^%s", private);
932 string_list_append(&revlist_args, strbuf_detach(&buf, NULL));
933 oidcpy(&ref->old_oid, &oid);