Skip to content

Commit ae07777

Browse files
bk2204gitster
authored andcommitted
refs: convert update_ref and refs_update_ref to use struct object_id
Convert update_ref, refs_update_ref, and write_pseudoref to use struct object_id. Update the existing callers as well. Remove update_ref_oid, as it is no longer needed. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 2616a5e commit ae07777

File tree

17 files changed

+65
-74
lines changed

17 files changed

+65
-74
lines changed

bisect.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,11 +685,12 @@ static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout)
685685
char bisect_rev_hex[GIT_MAX_HEXSZ + 1];
686686

687687
memcpy(bisect_rev_hex, oid_to_hex(bisect_rev), GIT_SHA1_HEXSZ + 1);
688-
update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev->hash, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
688+
update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
689689

690690
argv_checkout[2] = bisect_rev_hex;
691691
if (no_checkout) {
692-
update_ref(NULL, "BISECT_HEAD", bisect_rev->hash, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
692+
update_ref(NULL, "BISECT_HEAD", bisect_rev, NULL, 0,
693+
UPDATE_REFS_DIE_ON_ERR);
693694
} else {
694695
int res;
695696
res = run_command_v_opt(argv_checkout, RUN_GIT_CMD);

builtin/am.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,8 +1068,8 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
10681068
if (!get_oid("HEAD", &curr_head)) {
10691069
write_state_text(state, "abort-safety", oid_to_hex(&curr_head));
10701070
if (!state->rebasing)
1071-
update_ref_oid("am", "ORIG_HEAD", &curr_head, NULL, 0,
1072-
UPDATE_REFS_DIE_ON_ERR);
1071+
update_ref("am", "ORIG_HEAD", &curr_head, NULL, 0,
1072+
UPDATE_REFS_DIE_ON_ERR);
10731073
} else {
10741074
write_state_text(state, "abort-safety", "");
10751075
if (!state->rebasing)
@@ -1686,8 +1686,8 @@ static void do_commit(const struct am_state *state)
16861686
strbuf_addf(&sb, "%s: %.*s", reflog_msg, linelen(state->msg),
16871687
state->msg);
16881688

1689-
update_ref_oid(sb.buf, "HEAD", &commit, old_oid, 0,
1690-
UPDATE_REFS_DIE_ON_ERR);
1689+
update_ref(sb.buf, "HEAD", &commit, old_oid, 0,
1690+
UPDATE_REFS_DIE_ON_ERR);
16911691

16921692
if (state->rebasing) {
16931693
FILE *fp = xfopen(am_path(state, "rewritten"), "a");
@@ -2147,9 +2147,9 @@ static void am_abort(struct am_state *state)
21472147
clean_index(&curr_head, &orig_head);
21482148

21492149
if (has_orig_head)
2150-
update_ref_oid("am --abort", "HEAD", &orig_head,
2151-
has_curr_head ? &curr_head : NULL, 0,
2152-
UPDATE_REFS_DIE_ON_ERR);
2150+
update_ref("am --abort", "HEAD", &orig_head,
2151+
has_curr_head ? &curr_head : NULL, 0,
2152+
UPDATE_REFS_DIE_ON_ERR);
21532153
else if (curr_branch)
21542154
delete_ref(NULL, curr_branch, NULL, REF_NODEREF);
21552155

builtin/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
664664
if (!strcmp(new->name, "HEAD") && !new->path && !opts->force_detach) {
665665
/* Nothing to do. */
666666
} else if (opts->force_detach || !new->path) { /* No longer on any branch. */
667-
update_ref(msg.buf, "HEAD", new->commit->object.oid.hash, NULL,
667+
update_ref(msg.buf, "HEAD", &new->commit->object.oid, NULL,
668668
REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
669669
if (!opts->quiet) {
670670
if (old->path &&

builtin/clone.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,8 @@ static void write_followtags(const struct ref *refs, const char *msg)
610610
continue;
611611
if (!has_object_file(&ref->old_oid))
612612
continue;
613-
update_ref(msg, ref->name, ref->old_oid.hash,
614-
NULL, 0, UPDATE_REFS_DIE_ON_ERR);
613+
update_ref(msg, ref->name, &ref->old_oid, NULL, 0,
614+
UPDATE_REFS_DIE_ON_ERR);
615615
}
616616
}
617617

@@ -682,23 +682,23 @@ static void update_head(const struct ref *our, const struct ref *remote,
682682
if (create_symref("HEAD", our->name, NULL) < 0)
683683
die(_("unable to update HEAD"));
684684
if (!option_bare) {
685-
update_ref(msg, "HEAD", our->old_oid.hash, NULL, 0,
685+
update_ref(msg, "HEAD", &our->old_oid, NULL, 0,
686686
UPDATE_REFS_DIE_ON_ERR);
687687
install_branch_config(0, head, option_origin, our->name);
688688
}
689689
} else if (our) {
690690
struct commit *c = lookup_commit_reference(&our->old_oid);
691691
/* --branch specifies a non-branch (i.e. tags), detach HEAD */
692-
update_ref(msg, "HEAD", c->object.oid.hash,
693-
NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
692+
update_ref(msg, "HEAD", &c->object.oid, NULL, REF_NODEREF,
693+
UPDATE_REFS_DIE_ON_ERR);
694694
} else if (remote) {
695695
/*
696696
* We know remote HEAD points to a non-branch, or
697697
* HEAD points to a branch but we don't know which one.
698698
* Detach HEAD in all these cases.
699699
*/
700-
update_ref(msg, "HEAD", remote->old_oid.hash,
701-
NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
700+
update_ref(msg, "HEAD", &remote->old_oid, NULL, REF_NODEREF,
701+
UPDATE_REFS_DIE_ON_ERR);
702702
}
703703
}
704704

builtin/merge.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,8 @@ static void finish(struct commit *head_commit,
405405
printf(_("No merge message -- not updating HEAD\n"));
406406
else {
407407
const char *argv_gc_auto[] = { "gc", "--auto", NULL };
408-
update_ref(reflog_message.buf, "HEAD",
409-
new_head->hash, head->hash, 0,
410-
UPDATE_REFS_DIE_ON_ERR);
408+
update_ref(reflog_message.buf, "HEAD", new_head, head,
409+
0, UPDATE_REFS_DIE_ON_ERR);
411410
/*
412411
* We ignore errors in 'gc --auto', since the
413412
* user should see them.
@@ -1261,8 +1260,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
12611260
die(_("Can merge only exactly one commit into empty head"));
12621261
remote_head_oid = &remoteheads->item->object.oid;
12631262
read_empty(remote_head_oid->hash, 0);
1264-
update_ref("initial pull", "HEAD", remote_head_oid->hash,
1265-
NULL, 0, UPDATE_REFS_DIE_ON_ERR);
1263+
update_ref("initial pull", "HEAD", remote_head_oid, NULL, 0,
1264+
UPDATE_REFS_DIE_ON_ERR);
12661265
goto done;
12671266
}
12681267

@@ -1357,8 +1356,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
13571356
free(list);
13581357
}
13591358

1360-
update_ref("updating ORIG_HEAD", "ORIG_HEAD", head_commit->object.oid.hash,
1361-
NULL, 0, UPDATE_REFS_DIE_ON_ERR);
1359+
update_ref("updating ORIG_HEAD", "ORIG_HEAD",
1360+
&head_commit->object.oid, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
13621361

13631362
if (remoteheads && !common) {
13641363
/* No common ancestors found. */

builtin/notes.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,8 @@ static int merge_commit(struct notes_merge_options *o)
736736
format_commit_message(partial, "%s", &msg, &pretty_ctx);
737737
strbuf_trim(&msg);
738738
strbuf_insert(&msg, 0, "notes: ", 7);
739-
update_ref(msg.buf, o->local_ref, oid.hash,
740-
is_null_oid(&parent_oid) ? NULL : parent_oid.hash,
739+
update_ref(msg.buf, o->local_ref, &oid,
740+
is_null_oid(&parent_oid) ? NULL : &parent_oid,
741741
0, UPDATE_REFS_DIE_ON_ERR);
742742

743743
free_notes(t);
@@ -850,12 +850,12 @@ static int merge(int argc, const char **argv, const char *prefix)
850850

851851
if (result >= 0) /* Merge resulted (trivially) in result_oid */
852852
/* Update default notes ref with new commit */
853-
update_ref(msg.buf, default_notes_ref(), result_oid.hash, NULL,
854-
0, UPDATE_REFS_DIE_ON_ERR);
853+
update_ref(msg.buf, default_notes_ref(), &result_oid, NULL, 0,
854+
UPDATE_REFS_DIE_ON_ERR);
855855
else { /* Merge has unresolved conflicts */
856856
const struct worktree *wt;
857857
/* Update .git/NOTES_MERGE_PARTIAL with partial merge result */
858-
update_ref(msg.buf, "NOTES_MERGE_PARTIAL", result_oid.hash, NULL,
858+
update_ref(msg.buf, "NOTES_MERGE_PARTIAL", &result_oid, NULL,
859859
0, UPDATE_REFS_DIE_ON_ERR);
860860
/* Store ref-to-be-updated into .git/NOTES_MERGE_REF */
861861
wt = find_shared_symref("NOTES_MERGE_REF", default_notes_ref());

builtin/pull.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ static int pull_into_void(const struct object_id *merge_head,
544544
if (checkout_fast_forward(&empty_tree_oid, merge_head, 0))
545545
return 1;
546546

547-
if (update_ref("initial pull", "HEAD", merge_head->hash, curr_head->hash, 0, UPDATE_REFS_DIE_ON_ERR))
547+
if (update_ref("initial pull", "HEAD", merge_head, curr_head, 0, UPDATE_REFS_DIE_ON_ERR))
548548
return 1;
549549

550550
return 0;

builtin/reset.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,12 @@ static int reset_refs(const char *rev, const struct object_id *oid)
266266
if (!get_oid("HEAD", &oid_orig)) {
267267
orig = &oid_orig;
268268
set_reflog_message(&msg, "updating ORIG_HEAD", NULL);
269-
update_ref_oid(msg.buf, "ORIG_HEAD", orig, old_orig, 0,
269+
update_ref(msg.buf, "ORIG_HEAD", orig, old_orig, 0,
270270
UPDATE_REFS_MSG_ON_ERR);
271271
} else if (old_orig)
272272
delete_ref(NULL, "ORIG_HEAD", old_orig, 0);
273273
set_reflog_message(&msg, "updating HEAD", rev);
274-
update_ref_status = update_ref_oid(msg.buf, "HEAD", oid, orig, 0,
274+
update_ref_status = update_ref(msg.buf, "HEAD", oid, orig, 0,
275275
UPDATE_REFS_MSG_ON_ERR);
276276
strbuf_release(&msg);
277277
return update_ref_status;

builtin/update-ref.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
437437
(oldval && !is_null_oid(&oldoid)) ? &oldoid : NULL,
438438
flags);
439439
else
440-
return update_ref(msg, refname, oid.hash, oldval ? oldoid.hash : NULL,
440+
return update_ref(msg, refname, &oid, oldval ? &oldoid : NULL,
441441
flags | create_reflog_flag,
442442
UPDATE_REFS_DIE_ON_ERR);
443443
}

notes-cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int notes_cache_write(struct notes_cache *c)
5959
if (commit_tree(c->validity, strlen(c->validity), tree_oid.hash, NULL,
6060
commit_oid.hash, NULL, NULL) < 0)
6161
return -1;
62-
if (update_ref("update notes cache", c->tree.update_ref, commit_oid.hash,
62+
if (update_ref("update notes cache", c->tree.update_ref, &commit_oid,
6363
NULL, 0, UPDATE_REFS_QUIET_ON_ERR) < 0)
6464
return -1;
6565

0 commit comments

Comments
 (0)