Skip to content

Commit 755b49a

Browse files
kyleamgitster
authored andcommitted
delete_ref: accept a reflog message argument
When the current branch is renamed with 'git branch -m/-M' or deleted with 'git update-ref -m<msg> -d', the event is recorded in HEAD's log with an empty message. In preparation for adding a more meaningful message to HEAD's log in these cases, update delete_ref() to take a message argument and pass it along to ref_transaction_delete(). Modify all callers to pass NULL for the new message argument; no change in behavior is intended. Note that this is relevant for HEAD's log but not for the deleted ref's log, which is currently deleted along with the ref. Even if it were not, an entry for the deletion wouldn't be present in the deleted ref's log. files_transaction_commit() writes to the log if REF_NEEDS_COMMIT or REF_LOG_ONLY are set, but lock_ref_for_update() doesn't set REF_NEEDS_COMMIT for the deleted ref because REF_DELETING is set. In contrast, the update for HEAD has REF_LOG_ONLY set by split_head_update(), resulting in the deletion being logged. Signed-off-by: Kyle Meyer <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2076907 commit 755b49a

File tree

14 files changed

+22
-22
lines changed

14 files changed

+22
-22
lines changed

builtin/am.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
10491049
} else {
10501050
write_state_text(state, "abort-safety", "");
10511051
if (!state->rebasing)
1052-
delete_ref("ORIG_HEAD", NULL, 0);
1052+
delete_ref(NULL, "ORIG_HEAD", NULL, 0);
10531053
}
10541054

10551055
/*
@@ -2172,7 +2172,7 @@ static void am_abort(struct am_state *state)
21722172
has_curr_head ? &curr_head : NULL, 0,
21732173
UPDATE_REFS_DIE_ON_ERR);
21742174
else if (curr_branch)
2175-
delete_ref(curr_branch, NULL, REF_NODEREF);
2175+
delete_ref(NULL, curr_branch, NULL, REF_NODEREF);
21762176

21772177
free(curr_branch);
21782178
am_destroy(state);

builtin/branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
251251
goto next;
252252
}
253253

254-
if (delete_ref(name, is_null_sha1(sha1) ? NULL : sha1,
254+
if (delete_ref(NULL, name, is_null_sha1(sha1) ? NULL : sha1,
255255
REF_NODEREF)) {
256256
error(remote_branch
257257
? _("Error deleting remote-tracking branch '%s'")

builtin/notes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,9 +681,9 @@ static int merge_abort(struct notes_merge_options *o)
681681
* notes_merge_abort() to remove .git/NOTES_MERGE_WORKTREE.
682682
*/
683683

684-
if (delete_ref("NOTES_MERGE_PARTIAL", NULL, 0))
684+
if (delete_ref(NULL, "NOTES_MERGE_PARTIAL", NULL, 0))
685685
ret += error(_("failed to delete ref NOTES_MERGE_PARTIAL"));
686-
if (delete_ref("NOTES_MERGE_REF", NULL, REF_NODEREF))
686+
if (delete_ref(NULL, "NOTES_MERGE_REF", NULL, REF_NODEREF))
687687
ret += error(_("failed to delete ref NOTES_MERGE_REF"));
688688
if (notes_merge_abort(o))
689689
ret += error(_("failed to remove 'git notes merge' worktree"));

builtin/remote.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ static int mv(int argc, const char **argv)
691691
read_ref_full(item->string, RESOLVE_REF_READING, oid.hash, &flag);
692692
if (!(flag & REF_ISSYMREF))
693693
continue;
694-
if (delete_ref(item->string, NULL, REF_NODEREF))
694+
if (delete_ref(NULL, item->string, NULL, REF_NODEREF))
695695
die(_("deleting '%s' failed"), item->string);
696696
}
697697
for (i = 0; i < remote_branches.nr; i++) {
@@ -1248,7 +1248,7 @@ static int set_head(int argc, const char **argv)
12481248
head_name = xstrdup(states.heads.items[0].string);
12491249
free_remote_ref_states(&states);
12501250
} else if (opt_d && !opt_a && argc == 1) {
1251-
if (delete_ref(buf.buf, NULL, REF_NODEREF))
1251+
if (delete_ref(NULL, buf.buf, NULL, REF_NODEREF))
12521252
result |= error(_("Could not delete %s"), buf.buf);
12531253
} else
12541254
usage_with_options(builtin_remote_sethead_usage, options);

builtin/replace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static int for_each_replace_name(const char **argv, each_replace_name_fn fn)
121121
static int delete_replace_ref(const char *name, const char *ref,
122122
const unsigned char *sha1)
123123
{
124-
if (delete_ref(ref, sha1, 0))
124+
if (delete_ref(NULL, ref, sha1, 0))
125125
return 1;
126126
printf("Deleted replace ref '%s'\n", name);
127127
return 0;

builtin/reset.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ static int reset_refs(const char *rev, const struct object_id *oid)
256256
update_ref_oid(msg.buf, "ORIG_HEAD", orig, old_orig, 0,
257257
UPDATE_REFS_MSG_ON_ERR);
258258
} else if (old_orig)
259-
delete_ref("ORIG_HEAD", old_orig->hash, 0);
259+
delete_ref(NULL, "ORIG_HEAD", old_orig->hash, 0);
260260
set_reflog_message(&msg, "updating HEAD", rev);
261261
update_ref_status = update_ref_oid(msg.buf, "HEAD", oid, orig, 0,
262262
UPDATE_REFS_MSG_ON_ERR);

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(argv[0], NULL, REF_NODEREF);
61+
return delete_ref(NULL, argv[0], NULL, REF_NODEREF);
6262
}
6363

6464
switch (argc) {

builtin/tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static int for_each_tag_name(const char **argv, each_tag_name_fn fn,
9797
static int delete_tag(const char *name, const char *ref,
9898
const unsigned char *sha1, const void *cb_data)
9999
{
100-
if (delete_ref(ref, sha1, 0))
100+
if (delete_ref(NULL, ref, sha1, 0))
101101
return 1;
102102
printf(_("Deleted tag '%s' (was %s)\n"), name, find_unique_abbrev(sha1, DEFAULT_ABBREV));
103103
return 0;

builtin/update-ref.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
433433
* For purposes of backwards compatibility, we treat
434434
* NULL_SHA1 as "don't care" here:
435435
*/
436-
return delete_ref(refname,
436+
return delete_ref(NULL, refname,
437437
(oldval && !is_null_sha1(oldsha1)) ? oldsha1 : NULL,
438438
flags);
439439
else

fast-import.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1752,7 +1752,7 @@ static int update_branch(struct branch *b)
17521752

17531753
if (is_null_sha1(b->sha1)) {
17541754
if (b->delete)
1755-
delete_ref(b->name, NULL, 0);
1755+
delete_ref(NULL, b->name, NULL, 0);
17561756
return 0;
17571757
}
17581758
if (read_ref(b->name, old_sha1))

0 commit comments

Comments
 (0)