delete_ref: accept a reflog message argument
authorKyle Meyer <kyle@kyleam.com>
Tue, 21 Feb 2017 01:10:32 +0000 (20:10 -0500)
committerJunio C Hamano <gitster@pobox.com>
Tue, 21 Feb 2017 06:04:47 +0000 (22:04 -0800)
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 <kyle@kyleam.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
14 files changed:
builtin/am.c
builtin/branch.c
builtin/notes.c
builtin/remote.c
builtin/replace.c
builtin/reset.c
builtin/symbolic-ref.c
builtin/tag.c
builtin/update-ref.c
fast-import.c
refs.c
refs.h
refs/files-backend.c
transport.c
index 31fb60578f6caacfb376fe84938dda9432dcfc5a..f7a7a971fbe762a4fb691e786e86f681f2bbd7c1 100644 (file)
@@ -1049,7 +1049,7 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
        } else {
                write_state_text(state, "abort-safety", "");
                if (!state->rebasing)
-                       delete_ref("ORIG_HEAD", NULL, 0);
+                       delete_ref(NULL, "ORIG_HEAD", NULL, 0);
        }
 
        /*
@@ -2172,7 +2172,7 @@ static void am_abort(struct am_state *state)
                                has_curr_head ? &curr_head : NULL, 0,
                                UPDATE_REFS_DIE_ON_ERR);
        else if (curr_branch)
-               delete_ref(curr_branch, NULL, REF_NODEREF);
+               delete_ref(NULL, curr_branch, NULL, REF_NODEREF);
 
        free(curr_branch);
        am_destroy(state);
index 9d30f55b0b83cfc09294e2cb7cabdc9aa72e2508..8f8242e07c8e109e58f203b88f5e40d57076ac4e 100644 (file)
@@ -251,7 +251,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
                        goto next;
                }
 
-               if (delete_ref(name, is_null_sha1(sha1) ? NULL : sha1,
+               if (delete_ref(NULL, name, is_null_sha1(sha1) ? NULL : sha1,
                               REF_NODEREF)) {
                        error(remote_branch
                              ? _("Error deleting remote-tracking branch '%s'")
index 5248a9bad8d4d18c8ff0f145e8049606baa8849a..4b492abd417e3520d7ab98725f359087e9fcddd7 100644 (file)
@@ -681,9 +681,9 @@ static int merge_abort(struct notes_merge_options *o)
         * notes_merge_abort() to remove .git/NOTES_MERGE_WORKTREE.
         */
 
-       if (delete_ref("NOTES_MERGE_PARTIAL", NULL, 0))
+       if (delete_ref(NULL, "NOTES_MERGE_PARTIAL", NULL, 0))
                ret += error(_("failed to delete ref NOTES_MERGE_PARTIAL"));
-       if (delete_ref("NOTES_MERGE_REF", NULL, REF_NODEREF))
+       if (delete_ref(NULL, "NOTES_MERGE_REF", NULL, REF_NODEREF))
                ret += error(_("failed to delete ref NOTES_MERGE_REF"));
        if (notes_merge_abort(o))
                ret += error(_("failed to remove 'git notes merge' worktree"));
index 5339ed6ad17bb0c83e05d3e60d654c4f0632ee50..2b415911bfbc3438c48f5ad645bf5d9cc4612943 100644 (file)
@@ -691,7 +691,7 @@ static int mv(int argc, const char **argv)
                read_ref_full(item->string, RESOLVE_REF_READING, oid.hash, &flag);
                if (!(flag & REF_ISSYMREF))
                        continue;
-               if (delete_ref(item->string, NULL, REF_NODEREF))
+               if (delete_ref(NULL, item->string, NULL, REF_NODEREF))
                        die(_("deleting '%s' failed"), item->string);
        }
        for (i = 0; i < remote_branches.nr; i++) {
@@ -1248,7 +1248,7 @@ static int set_head(int argc, const char **argv)
                        head_name = xstrdup(states.heads.items[0].string);
                free_remote_ref_states(&states);
        } else if (opt_d && !opt_a && argc == 1) {
-               if (delete_ref(buf.buf, NULL, REF_NODEREF))
+               if (delete_ref(NULL, buf.buf, NULL, REF_NODEREF))
                        result |= error(_("Could not delete %s"), buf.buf);
        } else
                usage_with_options(builtin_remote_sethead_usage, options);
index b58c714cb8935efd08c81c8ebfd8922e1704c8f4..226d0f95236f299a1506beefb5babf1cf52574f0 100644 (file)
@@ -121,7 +121,7 @@ static int for_each_replace_name(const char **argv, each_replace_name_fn fn)
 static int delete_replace_ref(const char *name, const char *ref,
                              const unsigned char *sha1)
 {
-       if (delete_ref(ref, sha1, 0))
+       if (delete_ref(NULL, ref, sha1, 0))
                return 1;
        printf("Deleted replace ref '%s'\n", name);
        return 0;
index 8ab915bfcb71ae5d5f4bd1bebe7fd3c8725780b2..fc3b906c47bbcbefdc35b178016c031e46c06691 100644 (file)
@@ -256,7 +256,7 @@ static int reset_refs(const char *rev, const struct object_id *oid)
                update_ref_oid(msg.buf, "ORIG_HEAD", orig, old_orig, 0,
                           UPDATE_REFS_MSG_ON_ERR);
        } else if (old_orig)
-               delete_ref("ORIG_HEAD", old_orig->hash, 0);
+               delete_ref(NULL, "ORIG_HEAD", old_orig->hash, 0);
        set_reflog_message(&msg, "updating HEAD", rev);
        update_ref_status = update_ref_oid(msg.buf, "HEAD", oid, orig, 0,
                                       UPDATE_REFS_MSG_ON_ERR);
index 96eed944683a45c33fa5d4a05414ae56406fafca..70addef158b347488366f6c5787d326c3657adcd 100644 (file)
@@ -58,7 +58,7 @@ int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
                        die("Cannot delete %s, not a symbolic ref", argv[0]);
                if (!strcmp(argv[0], "HEAD"))
                        die("deleting '%s' is not allowed", argv[0]);
-               return delete_ref(argv[0], NULL, REF_NODEREF);
+               return delete_ref(NULL, argv[0], NULL, REF_NODEREF);
        }
 
        switch (argc) {
index e40c4a96763a371b104a5bf47e6d839ed93e8ef5..c23d6d4bc7d0dd65fa44ed6748209446bd0dd104 100644 (file)
@@ -97,7 +97,7 @@ static int for_each_tag_name(const char **argv, each_tag_name_fn fn,
 static int delete_tag(const char *name, const char *ref,
                      const unsigned char *sha1, const void *cb_data)
 {
-       if (delete_ref(ref, sha1, 0))
+       if (delete_ref(NULL, ref, sha1, 0))
                return 1;
        printf(_("Deleted tag '%s' (was %s)\n"), name, find_unique_abbrev(sha1, DEFAULT_ABBREV));
        return 0;
index 7f30d3a76f69e58ae3cdbbe05c5ebdce6c8a120d..86d006d36335a5ce896b0cd76a2dec7cc4465f50 100644 (file)
@@ -433,7 +433,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
                 * For purposes of backwards compatibility, we treat
                 * NULL_SHA1 as "don't care" here:
                 */
-               return delete_ref(refname,
+               return delete_ref(NULL, refname,
                                  (oldval && !is_null_sha1(oldsha1)) ? oldsha1 : NULL,
                                  flags);
        else
index 64fe602f0bb62c4848798d1bdb43a7be9ab5f523..6c13472c42257a47b07058156a7070cf427a038d 100644 (file)
@@ -1752,7 +1752,7 @@ static int update_branch(struct branch *b)
 
        if (is_null_sha1(b->sha1)) {
                if (b->delete)
-                       delete_ref(b->name, NULL, 0);
+                       delete_ref(NULL, b->name, NULL, 0);
                return 0;
        }
        if (read_ref(b->name, old_sha1))
diff --git a/refs.c b/refs.c
index cd36b64ed93f821936fd7ffb68e60ce384119898..053d23a90df023bc43fb00b0489f161d220d904e 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -591,8 +591,8 @@ static int delete_pseudoref(const char *pseudoref, const unsigned char *old_sha1
        return 0;
 }
 
-int delete_ref(const char *refname, const unsigned char *old_sha1,
-              unsigned int flags)
+int delete_ref(const char *msg, const char *refname,
+              const unsigned char *old_sha1, unsigned int flags)
 {
        struct ref_transaction *transaction;
        struct strbuf err = STRBUF_INIT;
@@ -603,7 +603,7 @@ int delete_ref(const char *refname, const unsigned char *old_sha1,
        transaction = ref_transaction_begin(&err);
        if (!transaction ||
            ref_transaction_delete(transaction, refname, old_sha1,
-                                  flags, NULL, &err) ||
+                                  flags, msg, &err) ||
            ref_transaction_commit(transaction, &err)) {
                error("%s", err.buf);
                ref_transaction_free(transaction);
diff --git a/refs.h b/refs.h
index 9fbff90e79bfc45fada65651cd01765b17376249..5880886a7c06f0f6a6f8617fbc8e5edae9977cb2 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -276,8 +276,8 @@ int reflog_exists(const char *refname);
  * exists, regardless of its old value. It is an error for old_sha1 to
  * be NULL_SHA1. flags is passed through to ref_transaction_delete().
  */
-int delete_ref(const char *refname, const unsigned char *old_sha1,
-              unsigned int flags);
+int delete_ref(const char *msg, const char *refname,
+              const unsigned char *old_sha1, unsigned int flags);
 
 /*
  * Delete the specified references. If there are any problems, emit
index c041d4ba21a8fe70eb6d8277358e7e3f29a69bfb..299eb4d8afccde850a18e1755bc99e4e6cbf005d 100644 (file)
@@ -2489,7 +2489,7 @@ static int files_delete_refs(struct ref_store *ref_store,
        for (i = 0; i < refnames->nr; i++) {
                const char *refname = refnames->items[i].string;
 
-               if (delete_ref(refname, NULL, flags))
+               if (delete_ref(NULL, refname, NULL, flags))
                        result |= error(_("could not remove reference %s"), refname);
        }
 
@@ -2616,7 +2616,7 @@ static int files_rename_ref(struct ref_store *ref_store,
                return error("unable to move logfile logs/%s to "TMP_RENAMED_LOG": %s",
                        oldrefname, strerror(errno));
 
-       if (delete_ref(oldrefname, orig_sha1, REF_NODEREF)) {
+       if (delete_ref(NULL, oldrefname, orig_sha1, REF_NODEREF)) {
                error("unable to delete old %s", oldrefname);
                goto rollback;
        }
@@ -2630,7 +2630,7 @@ static int files_rename_ref(struct ref_store *ref_store,
         */
        if (!read_ref_full(newrefname, RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
                           sha1, NULL) &&
-           delete_ref(newrefname, NULL, REF_NODEREF)) {
+           delete_ref(NULL, newrefname, NULL, REF_NODEREF)) {
                if (errno==EISDIR) {
                        struct strbuf path = STRBUF_INIT;
                        int result;
index d72e0894840fc384d67339b549a9a6bce7ba03ec..269352b22396ce722408fe46f65139046f056b80 100644 (file)
@@ -299,7 +299,7 @@ void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int v
                if (verbose)
                        fprintf(stderr, "updating local tracking ref '%s'\n", rs.dst);
                if (ref->deletion) {
-                       delete_ref(rs.dst, NULL, 0);
+                       delete_ref(NULL, rs.dst, NULL, 0);
                } else
                        update_ref("update by push", rs.dst,
                                        ref->new_oid.hash, NULL, 0, 0);