refs: convert read_ref and read_ref_full to object_id

All but two of the call sites already have parameters using the hash parameter of struct object_id, so convert them to take a pointer to the struct directly. Also convert refs_read_refs_full, the underlying implementation. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Oct 15, 2017 at 22:06 UTC 34c290a6fc8b1f6705d2646d726df2260927da0f
19 files changed +46 -47
builtin/checkout.c
+3 -3
@@ -379,7 +379,7 @@ static int checkout_paths(const struct checkout_opts *opts,
379 if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
380 die(_("unable to write new index file"));
381
382 - read_ref_full("HEAD", 0, rev.hash, NULL);
382 + read_ref_full("HEAD", 0, &rev, NULL);
383 head = lookup_commit_reference_gently(&rev, 1);
384
385 errs |= post_checkout_hook(head, head, 0);
@@ -1038,7 +1038,7 @@ static int parse_branchname_arg(int argc, const char **argv,
1038 setup_branch_path(new);
1039
1040 if (!check_refname_format(new->path, 0) &&
1041 - !read_ref(new->path, branch_rev.hash))
1041 + !read_ref(new->path, &branch_rev))
1042 oidcpy(rev, &branch_rev);
1043 else
1044 new->path = NULL; /* not an existing branch */
@@ -1136,7 +1136,7 @@ static int checkout_branch(struct checkout_opts *opts,
1136 struct object_id rev;
1137 int flag;
1138
1139 - if (!read_ref_full("HEAD", 0, rev.hash, &flag) &&
1139 + if (!read_ref_full("HEAD", 0, &rev, &flag) &&
1140 (flag & REF_ISSYMREF) && is_null_oid(&rev))
1141 return switch_unborn_to_new_branch(opts);
1142 }
builtin/remote.c
+1 -1
@@ -690,7 +690,7 @@ static int mv(int argc, const char **argv)
690 int flag = 0;
691 struct object_id oid;
692
693 - read_ref_full(item->string, RESOLVE_REF_READING, oid.hash, &flag);
693 + read_ref_full(item->string, RESOLVE_REF_READING, &oid, &flag);
694 if (!(flag & REF_ISSYMREF))
695 continue;
696 if (delete_ref(NULL, item->string, NULL, REF_NODEREF))
builtin/replace.c
+2 -2
@@ -113,7 +113,7 @@ static int for_each_replace_name(const char **argv, each_replace_name_fn fn)
113 strbuf_addstr(&ref, oid_to_hex(&oid));
114 full_hex = ref.buf + base_len;
115
116 - if (read_ref(ref.buf, oid.hash)) {
116 + if (read_ref(ref.buf, &oid)) {
117 error("replace ref '%s' not found.", full_hex);
118 had_error = 1;
119 continue;
@@ -144,7 +144,7 @@ static void check_ref_valid(struct object_id *object,
144 if (check_refname_format(ref->buf, 0))
145 die("'%s' is not a valid ref name.", ref->buf);
146
147 - if (read_ref(ref->buf, prev->hash))
147 + if (read_ref(ref->buf, prev))
148 oidclr(prev);
149 else if (!force)
150 die("replace ref '%s' already exists", ref->buf);
builtin/show-ref.c
+1 -1
@@ -197,7 +197,7 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
197 struct object_id oid;
198
199 if ((starts_with(*pattern, "refs/") || !strcmp(*pattern, "HEAD")) &&
200 - !read_ref(*pattern, oid.hash)) {
200 + !read_ref(*pattern, &oid)) {
201 show_one(*pattern, &oid);
202 }
203 else if (!quiet)
builtin/tag.c
+2 -2
@@ -82,7 +82,7 @@ static int for_each_tag_name(const char **argv, each_tag_name_fn fn,
82 for (p = argv; *p; p++) {
83 strbuf_reset(&ref);
84 strbuf_addf(&ref, "refs/tags/%s", *p);
85 - if (read_ref(ref.buf, oid.hash)) {
85 + if (read_ref(ref.buf, &oid)) {
86 error(_("tag '%s' not found."), *p);
87 had_error = 1;
88 continue;
@@ -518,7 +518,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
518 if (strbuf_check_tag_ref(&ref, tag))
519 die(_("'%s' is not a valid tag name."), tag);
520
521 - if (read_ref(ref.buf, prev.hash))
521 + if (read_ref(ref.buf, &prev))
522 oidclr(&prev);
523 else if (!force)
524 die(_("tag '%s' already exists"), tag);
builtin/update-index.c
+3 -3
@@ -679,9 +679,9 @@ static int unresolve_one(const char *path)
679
680 static void read_head_pointers(void)
681 {
682 - if (read_ref("HEAD", head_oid.hash))
682 + if (read_ref("HEAD", &head_oid))
683 die("No HEAD -- no initial commit yet?");
684 - if (read_ref("MERGE_HEAD", merge_head_oid.hash)) {
684 + if (read_ref("MERGE_HEAD", &merge_head_oid)) {
685 fprintf(stderr, "Not in the middle of a merge.\n");
686 exit(0);
687 }
@@ -721,7 +721,7 @@ static int do_reupdate(int ac, const char **av,
721 PATHSPEC_PREFER_CWD,
722 prefix, av + 1);
723
724 - if (read_ref("HEAD", head_oid.hash))
724 + if (read_ref("HEAD", &head_oid))
725 /* If there is no HEAD, that means it is an initial
726 * commit. Update everything in the index.
727 */
bundle.c
+1 -1
@@ -340,7 +340,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
340 continue;
341 if (dwim_ref(e->name, strlen(e->name), oid.hash, &ref) != 1)
342 goto skip_write_ref;
343 - if (read_ref_full(e->name, RESOLVE_REF_READING, oid.hash, &flag))
343 + if (read_ref_full(e->name, RESOLVE_REF_READING, &oid, &flag))
344 flag = 0;
345 display_ref = (flag & REF_ISSYMREF) ? e->name : ref;
346
fast-import.c
+1 -1
@@ -1758,7 +1758,7 @@ static int update_branch(struct branch *b)
1758 delete_ref(NULL, b->name, NULL, 0);
1759 return 0;
1760 }
1761 - if (read_ref(b->name, old_oid.hash))
1761 + if (read_ref(b->name, &old_oid))
1762 oidclr(&old_oid);
1763 if (!force_update && !is_null_oid(&old_oid)) {
1764 struct commit *old_cmit, *new_cmit;
notes-cache.c
+1 -1
@@ -11,7 +11,7 @@ static int notes_cache_match_validity(const char *ref, const char *validity)
11 struct strbuf msg = STRBUF_INIT;
12 int ret;
13
14 - if (read_ref(ref, oid.hash) < 0)
14 + if (read_ref(ref, &oid) < 0)
15 return 0;
16
17 commit = lookup_commit_reference_gently(&oid, 1);
notes-merge.c
+1 -1
@@ -547,7 +547,7 @@ int notes_merge(struct notes_merge_options *o,
547 o->local_ref, o->remote_ref);
548
549 /* Dereference o->local_ref into local_sha1 */
550 - if (read_ref_full(o->local_ref, 0, local_oid.hash, NULL))
550 + if (read_ref_full(o->local_ref, 0, &local_oid, NULL))
551 die("Failed to resolve local notes ref '%s'", o->local_ref);
552 else if (!check_refname_format(o->local_ref, 0) &&
553 is_null_oid(&local_oid))
notes-utils.c
+1 -1
@@ -18,7 +18,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
18 if (!parents) {
19 /* Deduce parent commit from t->ref */
20 struct object_id parent_oid;
21 - if (!read_ref(t->ref, parent_oid.hash)) {
21 + if (!read_ref(t->ref, &parent_oid)) {
22 struct commit *parent = lookup_commit(&parent_oid);
23 if (parse_commit(parent))
24 die("Failed to find/parse commit %s", t->ref);
notes.c
+1 -1
@@ -1027,7 +1027,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
1027 if (flags & NOTES_INIT_EMPTY || !notes_ref ||
1028 get_oid_treeish(notes_ref, &object_oid))
1029 return;
1030 - if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, object_oid.hash))
1030 + if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, &object_oid))
1031 die("Cannot use notes ref %s", notes_ref);
1032 if (get_tree_entry(object_oid.hash, "", oid.hash, &mode))
1033 die("Failed to read notes tree referenced by %s (%s)",
refs.c
+13 -13
@@ -219,22 +219,22 @@ struct ref_filter {
219 };
220
221 int refs_read_ref_full(struct ref_store *refs, const char *refname,
222 - int resolve_flags, unsigned char *sha1, int *flags)
222 + int resolve_flags, struct object_id *oid, int *flags)
223 {
224 - if (refs_resolve_ref_unsafe(refs, refname, resolve_flags, sha1, flags))
224 + if (refs_resolve_ref_unsafe(refs, refname, resolve_flags, oid->hash, flags))
225 return 0;
226 return -1;
227 }
228
229 -int read_ref_full(const char *refname, int resolve_flags, unsigned char *sha1, int *flags)
229 +int read_ref_full(const char *refname, int resolve_flags, struct object_id *oid, int *flags)
230 {
231 return refs_read_ref_full(get_main_ref_store(), refname,
232 - resolve_flags, sha1, flags);
232 + resolve_flags, oid, flags);
233 }
234
235 -int read_ref(const char *refname, unsigned char *sha1)
235 +int read_ref(const char *refname, struct object_id *oid)
236 {
237 - return read_ref_full(refname, RESOLVE_REF_READING, sha1, NULL);
237 + return read_ref_full(refname, RESOLVE_REF_READING, oid, NULL);
238 }
239
240 int ref_exists(const char *refname)
@@ -362,7 +362,7 @@ int head_ref_namespaced(each_ref_fn fn, void *cb_data)
362 int flag;
363
364 strbuf_addf(&buf, "%sHEAD", get_git_namespace());
365 - if (!read_ref_full(buf.buf, RESOLVE_REF_READING, oid.hash, &flag))
365 + if (!read_ref_full(buf.buf, RESOLVE_REF_READING, &oid, &flag))
366 ret = fn(buf.buf, &oid, flag, cb_data);
367 strbuf_release(&buf);
368
@@ -601,7 +601,7 @@ static int write_pseudoref(const char *pseudoref, const struct object_id *oid,
601 if (old_oid) {
602 struct object_id actual_old_oid;
603
604 - if (read_ref(pseudoref, actual_old_oid.hash))
604 + if (read_ref(pseudoref, &actual_old_oid))
605 die("could not read ref '%s'", pseudoref);
606 if (oidcmp(&actual_old_oid, old_oid)) {
607 strbuf_addf(err, "unexpected sha1 when writing '%s'", pseudoref);
@@ -639,7 +639,7 @@ static int delete_pseudoref(const char *pseudoref, const struct object_id *old_o
639 get_files_ref_lock_timeout_ms());
640 if (fd < 0)
641 die_errno(_("Could not open '%s' for writing"), filename);
642 - if (read_ref(pseudoref, actual_old_oid.hash))
642 + if (read_ref(pseudoref, &actual_old_oid))
643 die("could not read ref '%s'", pseudoref);
644 if (oidcmp(&actual_old_oid, old_oid)) {
645 warning("Unexpected sha1 when deleting %s", pseudoref);
@@ -1249,7 +1249,7 @@ int refs_head_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
1249 int flag;
1250
1251 if (!refs_read_ref_full(refs, "HEAD", RESOLVE_REF_READING,
1252 - oid.hash, &flag))
1252 + &oid, &flag))
1253 return fn("HEAD", &oid, flag, cb_data);
1254
1255 return 0;
@@ -1699,7 +1699,7 @@ int refs_peel_ref(struct ref_store *refs, const char *refname,
1699 unsigned char *sha1)
1700 {
1701 int flag;
1702 - unsigned char base[20];
1702 + struct object_id base;
1703
1704 if (current_ref_iter && current_ref_iter->refname == refname) {
1705 struct object_id peeled;
@@ -1711,10 +1711,10 @@ int refs_peel_ref(struct ref_store *refs, const char *refname,
1711 }
1712
1713 if (refs_read_ref_full(refs, refname,
1714 - RESOLVE_REF_READING, base, &flag))
1714 + RESOLVE_REF_READING, &base, &flag))
1715 return -1;
1716
1717 - return peel_object(base, sha1);
1717 + return peel_object(base.hash, sha1);
1718 }
1719
1720 int peel_ref(const char *refname, unsigned char *sha1)
refs.h
+3 -3
@@ -74,10 +74,10 @@ char *resolve_refdup(const char *refname, int resolve_flags,
74 struct object_id *oid, int *flags);
75
76 int refs_read_ref_full(struct ref_store *refs, const char *refname,
77 - int resolve_flags, unsigned char *sha1, int *flags);
77 + int resolve_flags, struct object_id *oid, int *flags);
78 int read_ref_full(const char *refname, int resolve_flags,
79 - unsigned char *sha1, int *flags);
80 -int read_ref(const char *refname, unsigned char *sha1);
79 + struct object_id *oid, int *flags);
80 +int read_ref(const char *refname, struct object_id *oid);
81
82 /*
83 * Return 0 if a reference named refname could be created without
refs/files-backend.c
+5 -5
@@ -782,7 +782,7 @@ static int verify_lock(struct ref_store *ref_store, struct ref_lock *lock,
782
783 if (refs_read_ref_full(ref_store, lock->ref_name,
784 mustexist ? RESOLVE_REF_READING : 0,
785 - lock->old_oid.hash, NULL)) {
785 + &lock->old_oid, NULL)) {
786 if (old_sha1) {
787 int save_errno = errno;
788 strbuf_addf(err, "can't verify ref '%s'", lock->ref_name);
@@ -1297,7 +1297,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
1297 */
1298 if (!copy && !refs_read_ref_full(&refs->base, newrefname,
1299 RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
1300 - oid.hash, NULL) &&
1300 + &oid, NULL) &&
1301 refs_delete_ref(&refs->base, NULL, newrefname,
1302 NULL, REF_NODEREF)) {
1303 if (errno == EISDIR) {
@@ -1721,7 +1721,7 @@ static void update_symref_reflog(struct files_ref_store *refs,
1721 struct object_id new_oid;
1722 if (logmsg &&
1723 !refs_read_ref_full(&refs->base, target,
1724 - RESOLVE_REF_READING, new_oid.hash, NULL) &&
1724 + RESOLVE_REF_READING, &new_oid, NULL) &&
1725 files_log_ref_write(refs, refname, &lock->old_oid,
1726 &new_oid, logmsg, 0, &err)) {
1727 error("%s", err.buf);
@@ -2010,7 +2010,7 @@ static int files_reflog_iterator_advance(struct ref_iterator *ref_iterator)
2010
2011 if (refs_read_ref_full(iter->ref_store,
2012 diter->relative_path, 0,
2013 - iter->oid.hash, &flags)) {
2013 + &iter->oid, &flags)) {
2014 error("bad ref for %s", diter->path.buf);
2015 continue;
2016 }
@@ -2347,7 +2347,7 @@ static int lock_ref_for_update(struct files_ref_store *refs,
2347 */
2348 if (refs_read_ref_full(&refs->base,
2349 referent.buf, 0,
2350 - lock->old_oid.hash, NULL)) {
2350 + &lock->old_oid, NULL)) {
2351 if (update->flags & REF_HAVE_OLD) {
2352 strbuf_addf(err, "cannot lock ref '%s': "
2353 "error reading reference",
remote-testsvn.c
+1 -1
@@ -174,7 +174,7 @@ static int cmd_import(const char *line)
174 struct child_process svndump_proc = CHILD_PROCESS_INIT;
175 const char *command = "svnrdump";
176
177 - if (read_ref(private_ref, head_oid.hash))
177 + if (read_ref(private_ref, &head_oid))
178 startrev = 0;
179 else {
180 note_msg = read_ref_note(&head_oid);
remote.c
+3 -3
@@ -2002,13 +2002,13 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
2002 return -1;
2003
2004 /* Cannot stat if what we used to build on no longer exists */
2005 - if (read_ref(base, oid.hash))
2005 + if (read_ref(base, &oid))
2006 return -1;
2007 theirs = lookup_commit_reference(&oid);
2008 if (!theirs)
2009 return -1;
2010
2011 - if (read_ref(branch->refname, oid.hash))
2011 + if (read_ref(branch->refname, &oid))
2012 return -1;
2013 ours = lookup_commit_reference(&oid);
2014 if (!ours)
@@ -2327,7 +2327,7 @@ static int remote_tracking(struct remote *remote, const char *refname,
2327 dst = apply_refspecs(remote->fetch, remote->fetch_refspec_nr, refname);
2328 if (!dst)
2329 return -1; /* no tracking ref for refname at remote */
2330 - if (read_ref(dst, oid->hash))
2330 + if (read_ref(dst, oid))
2331 return -1; /* we know what the tracking ref is but we cannot read it */
2332 return 0;
2333 }
sequencer.c
+1 -1
@@ -1630,7 +1630,7 @@ static int rollback_single_pick(void)
1630 if (!file_exists(git_path_cherry_pick_head()) &&
1631 !file_exists(git_path_revert_head()))
1632 return error(_("no cherry-pick or revert in progress"));
1633 - if (read_ref_full("HEAD", 0, head_oid.hash, NULL))
1633 + if (read_ref_full("HEAD", 0, &head_oid, NULL))
1634 return error(_("cannot resolve HEAD"));
1635 if (is_null_oid(&head_oid))
1636 return error(_("cannot abort from a branch yet to be born"));
transport-helper.c
+2 -3
@@ -535,7 +535,7 @@ static int fetch_with_import(struct transport *transport,
535 else
536 private = xstrdup(name);
537 if (private) {
538 - if (read_ref(private, posn->old_oid.hash) < 0)
538 + if (read_ref(private, &posn->old_oid) < 0)
539 die("Could not read ref %s", private);
540 free(private);
541 }
@@ -1067,8 +1067,7 @@ static struct ref *get_refs_list(struct transport *transport, int for_push)
1067 if (eon) {
1068 if (has_attribute(eon + 1, "unchanged")) {
1069 (*tail)->status |= REF_STATUS_UPTODATE;
1070 - if (read_ref((*tail)->name,
1071 - (*tail)->old_oid.hash) < 0)
1070 + if (read_ref((*tail)->name, &(*tail)->old_oid) < 0)
1071 die(_("Could not read ref %s"),
1072 (*tail)->name);
1073 }