Skip to content

Commit a972229

Browse files
committed
Merge branch 'mh/tidy-ref-update-flags'
Code clean-up in refs API implementation. * mh/tidy-ref-update-flags: refs: update some more docs to use "oid" rather than "sha1" write_packed_entry(): take `object_id` arguments refs: rename constant `REF_ISPRUNING` to `REF_IS_PRUNING` refs: rename constant `REF_NODEREF` to `REF_NO_DEREF` refs: tidy up and adjust visibility of the `ref_update` flags ref_transaction_add_update(): remove a check ref_transaction_update(): die on disallowed flags prune_ref(): call `ref_transaction_add_update()` directly files_transaction_prepare(): don't leak flags to packed transaction
2 parents 61f68f6 + 78fb457 commit a972229

16 files changed

+189
-163
lines changed

bisect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ int bisect_clean_state(void)
10731073
struct string_list refs_for_removal = STRING_LIST_INIT_NODUP;
10741074
for_each_ref_in("refs/bisect", mark_for_removal, (void *) &refs_for_removal);
10751075
string_list_append(&refs_for_removal, xstrdup("BISECT_HEAD"));
1076-
result = delete_refs("bisect: remove", &refs_for_removal, REF_NODEREF);
1076+
result = delete_refs("bisect: remove", &refs_for_removal, REF_NO_DEREF);
10771077
refs_for_removal.strdup_strings = 1;
10781078
string_list_clear(&refs_for_removal, 0);
10791079
unlink_or_warn(git_path_bisect_expected_rev());

builtin/am.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2148,7 +2148,7 @@ static void am_abort(struct am_state *state)
21482148
has_curr_head ? &curr_head : NULL, 0,
21492149
UPDATE_REFS_DIE_ON_ERR);
21502150
else if (curr_branch)
2151-
delete_ref(NULL, curr_branch, NULL, REF_NODEREF);
2151+
delete_ref(NULL, curr_branch, NULL, REF_NO_DEREF);
21522152

21532153
free(curr_branch);
21542154
am_destroy(state);

builtin/branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
258258
}
259259

260260
if (delete_ref(NULL, name, is_null_oid(&oid) ? NULL : &oid,
261-
REF_NODEREF)) {
261+
REF_NO_DEREF)) {
262262
error(remote_branch
263263
? _("Error deleting remote-tracking branch '%s'")
264264
: _("Error deleting branch '%s'"),

builtin/checkout.c

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

builtin/clone.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,15 +689,15 @@ static void update_head(const struct ref *our, const struct ref *remote,
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, NULL, REF_NODEREF,
692+
update_ref(msg, "HEAD", &c->object.oid, NULL, REF_NO_DEREF,
693693
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, NULL, REF_NODEREF,
700+
update_ref(msg, "HEAD", &remote->old_oid, NULL, REF_NO_DEREF,
701701
UPDATE_REFS_DIE_ON_ERR);
702702
}
703703
}

builtin/notes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ static int merge_abort(struct notes_merge_options *o)
686686

687687
if (delete_ref(NULL, "NOTES_MERGE_PARTIAL", NULL, 0))
688688
ret += error(_("failed to delete ref NOTES_MERGE_PARTIAL"));
689-
if (delete_ref(NULL, "NOTES_MERGE_REF", NULL, REF_NODEREF))
689+
if (delete_ref(NULL, "NOTES_MERGE_REF", NULL, REF_NO_DEREF))
690690
ret += error(_("failed to delete ref NOTES_MERGE_REF"));
691691
if (notes_merge_abort(o))
692692
ret += error(_("failed to remove 'git notes merge' worktree"));

builtin/remote.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ static int mv(int argc, const char **argv)
693693
read_ref_full(item->string, RESOLVE_REF_READING, &oid, &flag);
694694
if (!(flag & REF_ISSYMREF))
695695
continue;
696-
if (delete_ref(NULL, item->string, NULL, REF_NODEREF))
696+
if (delete_ref(NULL, item->string, NULL, REF_NO_DEREF))
697697
die(_("deleting '%s' failed"), item->string);
698698
}
699699
for (i = 0; i < remote_branches.nr; i++) {
@@ -788,7 +788,7 @@ static int rm(int argc, const char **argv)
788788
strbuf_release(&buf);
789789

790790
if (!result)
791-
result = delete_refs("remote: remove", &branches, REF_NODEREF);
791+
result = delete_refs("remote: remove", &branches, REF_NO_DEREF);
792792
string_list_clear(&branches, 0);
793793

794794
if (skipped.nr) {
@@ -1255,7 +1255,7 @@ static int set_head(int argc, const char **argv)
12551255
head_name = xstrdup(states.heads.items[0].string);
12561256
free_remote_ref_states(&states);
12571257
} else if (opt_d && !opt_a && argc == 1) {
1258-
if (delete_ref(NULL, buf.buf, NULL, REF_NODEREF))
1258+
if (delete_ref(NULL, buf.buf, NULL, REF_NO_DEREF))
12591259
result |= error(_("Could not delete %s"), buf.buf);
12601260
} else
12611261
usage_with_options(builtin_remote_sethead_usage, options);

builtin/symbolic-ref.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
5858
die("Cannot delete %s, not a symbolic ref", argv[0]);
5959
if (!strcmp(argv[0], "HEAD"))
6060
die("deleting '%s' is not allowed", argv[0]);
61-
return delete_ref(NULL, argv[0], NULL, REF_NODEREF);
61+
return delete_ref(NULL, argv[0], NULL, REF_NO_DEREF);
6262
}
6363

6464
switch (argc) {

builtin/update-ref.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ static const char *parse_cmd_verify(struct ref_transaction *transaction,
312312
static const char *parse_cmd_option(struct strbuf *input, const char *next)
313313
{
314314
if (!strncmp(next, "no-deref", 8) && next[8] == line_termination)
315-
update_flags |= REF_NODEREF;
315+
update_flags |= REF_NO_DEREF;
316316
else
317317
die("option unknown: %s", next);
318318
return next + 8;
@@ -427,7 +427,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
427427
}
428428

429429
if (no_deref)
430-
flags = REF_NODEREF;
430+
flags = REF_NO_DEREF;
431431
if (delete)
432432
/*
433433
* For purposes of backwards compatibility, we treat

refs.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
770770
if (cb->cutoff_cnt)
771771
*cb->cutoff_cnt = cb->reccnt - 1;
772772
/*
773-
* we have not yet updated cb->[n|o]sha1 so they still
773+
* we have not yet updated cb->[n|o]oid so they still
774774
* hold the values for the previous record.
775775
*/
776776
if (!is_null_oid(&cb->ooid)) {
@@ -906,9 +906,6 @@ struct ref_update *ref_transaction_add_update(
906906
if (transaction->state != REF_TRANSACTION_OPEN)
907907
die("BUG: update called for transaction that is not open");
908908

909-
if ((flags & REF_ISPRUNING) && !(flags & REF_NODEREF))
910-
die("BUG: REF_ISPRUNING set without REF_NODEREF");
911-
912909
FLEX_ALLOC_STR(update, refname, refname);
913910
ALLOC_GROW(transaction->updates, transaction->nr + 1, transaction->alloc);
914911
transaction->updates[transaction->nr++] = update;
@@ -940,7 +937,8 @@ int ref_transaction_update(struct ref_transaction *transaction,
940937
return -1;
941938
}
942939

943-
flags &= REF_TRANSACTION_UPDATE_ALLOWED_FLAGS;
940+
if (flags & ~REF_TRANSACTION_UPDATE_ALLOWED_FLAGS)
941+
BUG("illegal flags 0x%x passed to ref_transaction_update()", flags);
944942

945943
flags |= (new_oid ? REF_HAVE_NEW : 0) | (old_oid ? REF_HAVE_OLD : 0);
946944

0 commit comments

Comments
 (0)