Commit ae077771 authored by brian m. carlson's avatar brian m. carlson Committed by Junio C Hamano

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's avatarbrian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
parent 2616a5e5
......@@ -685,11 +685,12 @@ static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout)
char bisect_rev_hex[GIT_MAX_HEXSZ + 1];
memcpy(bisect_rev_hex, oid_to_hex(bisect_rev), GIT_SHA1_HEXSZ + 1);
update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev->hash, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
argv_checkout[2] = bisect_rev_hex;
if (no_checkout) {
update_ref(NULL, "BISECT_HEAD", bisect_rev->hash, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
update_ref(NULL, "BISECT_HEAD", bisect_rev, NULL, 0,
UPDATE_REFS_DIE_ON_ERR);
} else {
int res;
res = run_command_v_opt(argv_checkout, RUN_GIT_CMD);
......
......@@ -1068,8 +1068,8 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
if (!get_oid("HEAD", &curr_head)) {
write_state_text(state, "abort-safety", oid_to_hex(&curr_head));
if (!state->rebasing)
update_ref_oid("am", "ORIG_HEAD", &curr_head, NULL, 0,
UPDATE_REFS_DIE_ON_ERR);
update_ref("am", "ORIG_HEAD", &curr_head, NULL, 0,
UPDATE_REFS_DIE_ON_ERR);
} else {
write_state_text(state, "abort-safety", "");
if (!state->rebasing)
......@@ -1686,8 +1686,8 @@ static void do_commit(const struct am_state *state)
strbuf_addf(&sb, "%s: %.*s", reflog_msg, linelen(state->msg),
state->msg);
update_ref_oid(sb.buf, "HEAD", &commit, old_oid, 0,
UPDATE_REFS_DIE_ON_ERR);
update_ref(sb.buf, "HEAD", &commit, old_oid, 0,
UPDATE_REFS_DIE_ON_ERR);
if (state->rebasing) {
FILE *fp = xfopen(am_path(state, "rewritten"), "a");
......@@ -2147,9 +2147,9 @@ static void am_abort(struct am_state *state)
clean_index(&curr_head, &orig_head);
if (has_orig_head)
update_ref_oid("am --abort", "HEAD", &orig_head,
has_curr_head ? &curr_head : NULL, 0,
UPDATE_REFS_DIE_ON_ERR);
update_ref("am --abort", "HEAD", &orig_head,
has_curr_head ? &curr_head : NULL, 0,
UPDATE_REFS_DIE_ON_ERR);
else if (curr_branch)
delete_ref(NULL, curr_branch, NULL, REF_NODEREF);
......
......@@ -664,7 +664,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
if (!strcmp(new->name, "HEAD") && !new->path && !opts->force_detach) {
/* Nothing to do. */
} else if (opts->force_detach || !new->path) { /* No longer on any branch. */
update_ref(msg.buf, "HEAD", new->commit->object.oid.hash, NULL,
update_ref(msg.buf, "HEAD", &new->commit->object.oid, NULL,
REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
if (!opts->quiet) {
if (old->path &&
......
......@@ -610,8 +610,8 @@ static void write_followtags(const struct ref *refs, const char *msg)
continue;
if (!has_object_file(&ref->old_oid))
continue;
update_ref(msg, ref->name, ref->old_oid.hash,
NULL, 0, UPDATE_REFS_DIE_ON_ERR);
update_ref(msg, ref->name, &ref->old_oid, NULL, 0,
UPDATE_REFS_DIE_ON_ERR);
}
}
......@@ -682,23 +682,23 @@ static void update_head(const struct ref *our, const struct ref *remote,
if (create_symref("HEAD", our->name, NULL) < 0)
die(_("unable to update HEAD"));
if (!option_bare) {
update_ref(msg, "HEAD", our->old_oid.hash, NULL, 0,
update_ref(msg, "HEAD", &our->old_oid, NULL, 0,
UPDATE_REFS_DIE_ON_ERR);
install_branch_config(0, head, option_origin, our->name);
}
} else if (our) {
struct commit *c = lookup_commit_reference(&our->old_oid);
/* --branch specifies a non-branch (i.e. tags), detach HEAD */
update_ref(msg, "HEAD", c->object.oid.hash,
NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
update_ref(msg, "HEAD", &c->object.oid, NULL, REF_NODEREF,
UPDATE_REFS_DIE_ON_ERR);
} else if (remote) {
/*
* We know remote HEAD points to a non-branch, or
* HEAD points to a branch but we don't know which one.
* Detach HEAD in all these cases.
*/
update_ref(msg, "HEAD", remote->old_oid.hash,
NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
update_ref(msg, "HEAD", &remote->old_oid, NULL, REF_NODEREF,
UPDATE_REFS_DIE_ON_ERR);
}
}
......
......@@ -405,9 +405,8 @@ static void finish(struct commit *head_commit,
printf(_("No merge message -- not updating HEAD\n"));
else {
const char *argv_gc_auto[] = { "gc", "--auto", NULL };
update_ref(reflog_message.buf, "HEAD",
new_head->hash, head->hash, 0,
UPDATE_REFS_DIE_ON_ERR);
update_ref(reflog_message.buf, "HEAD", new_head, head,
0, UPDATE_REFS_DIE_ON_ERR);
/*
* We ignore errors in 'gc --auto', since the
* user should see them.
......@@ -1261,8 +1260,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
die(_("Can merge only exactly one commit into empty head"));
remote_head_oid = &remoteheads->item->object.oid;
read_empty(remote_head_oid->hash, 0);
update_ref("initial pull", "HEAD", remote_head_oid->hash,
NULL, 0, UPDATE_REFS_DIE_ON_ERR);
update_ref("initial pull", "HEAD", remote_head_oid, NULL, 0,
UPDATE_REFS_DIE_ON_ERR);
goto done;
}
......@@ -1357,8 +1356,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
free(list);
}
update_ref("updating ORIG_HEAD", "ORIG_HEAD", head_commit->object.oid.hash,
NULL, 0, UPDATE_REFS_DIE_ON_ERR);
update_ref("updating ORIG_HEAD", "ORIG_HEAD",
&head_commit->object.oid, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
if (remoteheads && !common) {
/* No common ancestors found. */
......
......@@ -736,8 +736,8 @@ static int merge_commit(struct notes_merge_options *o)
format_commit_message(partial, "%s", &msg, &pretty_ctx);
strbuf_trim(&msg);
strbuf_insert(&msg, 0, "notes: ", 7);
update_ref(msg.buf, o->local_ref, oid.hash,
is_null_oid(&parent_oid) ? NULL : parent_oid.hash,
update_ref(msg.buf, o->local_ref, &oid,
is_null_oid(&parent_oid) ? NULL : &parent_oid,
0, UPDATE_REFS_DIE_ON_ERR);
free_notes(t);
......@@ -850,12 +850,12 @@ static int merge(int argc, const char **argv, const char *prefix)
if (result >= 0) /* Merge resulted (trivially) in result_oid */
/* Update default notes ref with new commit */
update_ref(msg.buf, default_notes_ref(), result_oid.hash, NULL,
0, UPDATE_REFS_DIE_ON_ERR);
update_ref(msg.buf, default_notes_ref(), &result_oid, NULL, 0,
UPDATE_REFS_DIE_ON_ERR);
else { /* Merge has unresolved conflicts */
const struct worktree *wt;
/* Update .git/NOTES_MERGE_PARTIAL with partial merge result */
update_ref(msg.buf, "NOTES_MERGE_PARTIAL", result_oid.hash, NULL,
update_ref(msg.buf, "NOTES_MERGE_PARTIAL", &result_oid, NULL,
0, UPDATE_REFS_DIE_ON_ERR);
/* Store ref-to-be-updated into .git/NOTES_MERGE_REF */
wt = find_shared_symref("NOTES_MERGE_REF", default_notes_ref());
......
......@@ -544,7 +544,7 @@ static int pull_into_void(const struct object_id *merge_head,
if (checkout_fast_forward(&empty_tree_oid, merge_head, 0))
return 1;
if (update_ref("initial pull", "HEAD", merge_head->hash, curr_head->hash, 0, UPDATE_REFS_DIE_ON_ERR))
if (update_ref("initial pull", "HEAD", merge_head, curr_head, 0, UPDATE_REFS_DIE_ON_ERR))
return 1;
return 0;
......
......@@ -266,12 +266,12 @@ static int reset_refs(const char *rev, const struct object_id *oid)
if (!get_oid("HEAD", &oid_orig)) {
orig = &oid_orig;
set_reflog_message(&msg, "updating ORIG_HEAD", NULL);
update_ref_oid(msg.buf, "ORIG_HEAD", orig, old_orig, 0,
update_ref(msg.buf, "ORIG_HEAD", orig, old_orig, 0,
UPDATE_REFS_MSG_ON_ERR);
} else if (old_orig)
delete_ref(NULL, "ORIG_HEAD", old_orig, 0);
set_reflog_message(&msg, "updating HEAD", rev);
update_ref_status = update_ref_oid(msg.buf, "HEAD", oid, orig, 0,
update_ref_status = update_ref(msg.buf, "HEAD", oid, orig, 0,
UPDATE_REFS_MSG_ON_ERR);
strbuf_release(&msg);
return update_ref_status;
......
......@@ -437,7 +437,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
(oldval && !is_null_oid(&oldoid)) ? &oldoid : NULL,
flags);
else
return update_ref(msg, refname, oid.hash, oldval ? oldoid.hash : NULL,
return update_ref(msg, refname, &oid, oldval ? &oldoid : NULL,
flags | create_reflog_flag,
UPDATE_REFS_DIE_ON_ERR);
}
......@@ -59,7 +59,7 @@ int notes_cache_write(struct notes_cache *c)
if (commit_tree(c->validity, strlen(c->validity), tree_oid.hash, NULL,
commit_oid.hash, NULL, NULL) < 0)
return -1;
if (update_ref("update notes cache", c->tree.update_ref, commit_oid.hash,
if (update_ref("update notes cache", c->tree.update_ref, &commit_oid,
NULL, 0, UPDATE_REFS_QUIET_ON_ERR) < 0)
return -1;
......
......@@ -49,7 +49,7 @@ void commit_notes(struct notes_tree *t, const char *msg)
create_notes_commit(t, NULL, buf.buf, buf.len, commit_oid.hash);
strbuf_insert(&buf, 0, "notes: ", 7); /* commit message starts at index 7 */
update_ref(buf.buf, t->update_ref, commit_oid.hash, NULL, 0,
update_ref(buf.buf, t->update_ref, &commit_oid, NULL, 0,
UPDATE_REFS_DIE_ON_ERR);
strbuf_release(&buf);
......
......@@ -574,8 +574,8 @@ long get_files_ref_lock_timeout_ms(void)
return timeout_ms;
}
static int write_pseudoref(const char *pseudoref, const unsigned char *sha1,
const unsigned char *old_sha1, struct strbuf *err)
static int write_pseudoref(const char *pseudoref, const struct object_id *oid,
const struct object_id *old_oid, struct strbuf *err)
{
const char *filename;
int fd;
......@@ -583,7 +583,7 @@ static int write_pseudoref(const char *pseudoref, const unsigned char *sha1,
struct strbuf buf = STRBUF_INIT;
int ret = -1;
strbuf_addf(&buf, "%s\n", sha1_to_hex(sha1));
strbuf_addf(&buf, "%s\n", oid_to_hex(oid));
filename = git_path("%s", pseudoref);
fd = hold_lock_file_for_update_timeout(&lock, filename,
......@@ -595,12 +595,12 @@ static int write_pseudoref(const char *pseudoref, const unsigned char *sha1,
goto done;
}
if (old_sha1) {
unsigned char actual_old_sha1[20];
if (old_oid) {
struct object_id actual_old_oid;
if (read_ref(pseudoref, actual_old_sha1))
if (read_ref(pseudoref, actual_old_oid.hash))
die("could not read ref '%s'", pseudoref);
if (hashcmp(actual_old_sha1, old_sha1)) {
if (oidcmp(&actual_old_oid, old_oid)) {
strbuf_addf(err, "unexpected sha1 when writing '%s'", pseudoref);
rollback_lock_file(&lock);
goto done;
......@@ -985,17 +985,9 @@ int ref_transaction_verify(struct ref_transaction *transaction,
flags, NULL, err);
}
int update_ref_oid(const char *msg, const char *refname,
const struct object_id *new_oid, const struct object_id *old_oid,
unsigned int flags, enum action_on_err onerr)
{
return update_ref(msg, refname, new_oid ? new_oid->hash : NULL,
old_oid ? old_oid->hash : NULL, flags, onerr);
}
int refs_update_ref(struct ref_store *refs, const char *msg,
const char *refname, const unsigned char *new_sha1,
const unsigned char *old_sha1, unsigned int flags,
const char *refname, const struct object_id *new_oid,
const struct object_id *old_oid, unsigned int flags,
enum action_on_err onerr)
{
struct ref_transaction *t = NULL;
......@@ -1004,11 +996,12 @@ int refs_update_ref(struct ref_store *refs, const char *msg,
if (ref_type(refname) == REF_TYPE_PSEUDOREF) {
assert(refs == get_main_ref_store());
ret = write_pseudoref(refname, new_sha1, old_sha1, &err);
ret = write_pseudoref(refname, new_oid, old_oid, &err);
} else {
t = ref_store_transaction_begin(refs, &err);
if (!t ||
ref_transaction_update(t, refname, new_sha1, old_sha1,
ref_transaction_update(t, refname, new_oid ? new_oid->hash : NULL,
old_oid ? old_oid->hash : NULL,
flags, msg, &err) ||
ref_transaction_commit(t, &err)) {
ret = 1;
......@@ -1038,12 +1031,12 @@ int refs_update_ref(struct ref_store *refs, const char *msg,
}
int update_ref(const char *msg, const char *refname,
const unsigned char *new_sha1,
const unsigned char *old_sha1,
const struct object_id *new_oid,
const struct object_id *old_oid,
unsigned int flags, enum action_on_err onerr)
{
return refs_update_ref(get_main_ref_store(), msg, refname, new_sha1,
old_sha1, flags, onerr);
return refs_update_ref(get_main_ref_store(), msg, refname, new_oid,
old_oid, flags, onerr);
}
char *shorten_unambiguous_ref(const char *refname, int strict)
......
......@@ -643,12 +643,9 @@ void ref_transaction_free(struct ref_transaction *transaction);
* argument.
*/
int refs_update_ref(struct ref_store *refs, const char *msg, const char *refname,
const unsigned char *new_sha1, const unsigned char *old_sha1,
const struct object_id *new_oid, const struct object_id *old_oid,
unsigned int flags, enum action_on_err onerr);
int update_ref(const char *msg, const char *refname,
const unsigned char *new_sha1, const unsigned char *old_sha1,
unsigned int flags, enum action_on_err onerr);
int update_ref_oid(const char *msg, const char *refname,
const struct object_id *new_oid, const struct object_id *old_oid,
unsigned int flags, enum action_on_err onerr);
......
......@@ -1115,11 +1115,11 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
* write it at all.
*/
if (command == TODO_PICK && !opts->no_commit && (res == 0 || res == 1) &&
update_ref(NULL, "CHERRY_PICK_HEAD", commit->object.oid.hash, NULL,
update_ref(NULL, "CHERRY_PICK_HEAD", &commit->object.oid, NULL,
REF_NODEREF, UPDATE_REFS_MSG_ON_ERR))
res = -1;
if (command == TODO_REVERT && ((opts->no_commit && res == 0) || res == 1) &&
update_ref(NULL, "REVERT_HEAD", commit->object.oid.hash, NULL,
update_ref(NULL, "REVERT_HEAD", &commit->object.oid, NULL,
REF_NODEREF, UPDATE_REFS_MSG_ON_ERR))
res = -1;
......@@ -2124,8 +2124,8 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
}
msg = reflog_message(opts, "finish", "%s onto %s",
head_ref.buf, buf.buf);
if (update_ref(msg, head_ref.buf, head.hash, orig.hash,
REF_NODEREF, UPDATE_REFS_MSG_ON_ERR)) {
if (update_ref(msg, head_ref.buf, &head, &orig,
REF_NODEREF, UPDATE_REFS_MSG_ON_ERR)) {
res = error(_("could not update %s"),
head_ref.buf);
goto cleanup_head_ref;
......
......@@ -233,15 +233,15 @@ static int cmd_update_ref(struct ref_store *refs, const char **argv)
const char *new_sha1_buf = notnull(*argv++, "old-sha1");
const char *old_sha1_buf = notnull(*argv++, "old-sha1");
unsigned int flags = arg_flags(*argv++, "flags");
unsigned char old_sha1[20];
unsigned char new_sha1[20];
struct object_id old_oid;
struct object_id new_oid;
if (get_sha1_hex(old_sha1_buf, old_sha1) ||
get_sha1_hex(new_sha1_buf, new_sha1))
if (get_oid_hex(old_sha1_buf, &old_oid) ||
get_oid_hex(new_sha1_buf, &new_oid))
die("not sha-1");
return refs_update_ref(refs, msg, refname,
new_sha1, old_sha1,
&new_oid, &old_oid,
flags, UPDATE_REFS_DIE_ON_ERR);
}
......
......@@ -795,7 +795,8 @@ static int push_update_refs_status(struct helper_data *data,
private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
if (!private)
continue;
update_ref("update by helper", private, ref->new_oid.hash, NULL, 0, 0);
update_ref("update by helper", private, &ref->new_oid, NULL,
0, 0);
free(private);
}
strbuf_release(&buf);
......
......@@ -305,8 +305,8 @@ void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int v
if (ref->deletion) {
delete_ref(NULL, rs.dst, NULL, 0);
} else
update_ref("update by push", rs.dst,
ref->new_oid.hash, NULL, 0, 0);
update_ref("update by push", rs.dst, &ref->new_oid,
NULL, 0, 0);
free(rs.dst);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment