]> git.ipfire.org Git - thirdparty/git.git/commitdiff
ref_store: take a `msg` parameter when deleting references
authorMichael Haggerty <mhagger@alum.mit.edu>
Mon, 22 May 2017 14:17:38 +0000 (16:17 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 23 May 2017 05:29:53 +0000 (14:29 +0900)
Just because the files backend can't retain reflogs for deleted
references is no reason that they shouldn't be supported by the
virtual method interface. Also, `delete_ref()` and `refs_delete_ref()`
have already gained `msg` parameters. Now let's add them to
`delete_refs()` and `refs_delete_refs()`.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fetch.c
builtin/remote.c
refs.c
refs.h
refs/files-backend.c
refs/refs-internal.h
t/helper/test-ref-store.c
t/t1405-main-ref-store.sh
t/t1406-submodule-ref-store.sh

index d4d573b98585b5780f9b2e52df42cc6594e3dc54..47708451bc5e124f9c6da4de60cc476a5d2c1f10 100644 (file)
@@ -941,7 +941,7 @@ static int prune_refs(struct refspec *refs, int ref_count, struct ref *ref_map,
                for (ref = stale_refs; ref; ref = ref->next)
                        string_list_append(&refnames, ref->name);
 
-               result = delete_refs(&refnames, 0);
+               result = delete_refs("fetch: prune", &refnames, 0);
                string_list_clear(&refnames, 0);
        }
 
index addf97ad29343b2328adce2c27ccea92aee6af7a..5f52c5a6d6dfdb2202b9e86991b64bd1a5bd552d 100644 (file)
@@ -786,7 +786,7 @@ static int rm(int argc, const char **argv)
        strbuf_release(&buf);
 
        if (!result)
-               result = delete_refs(&branches, REF_NODEREF);
+               result = delete_refs("remote: remove", &branches, REF_NODEREF);
        string_list_clear(&branches, 0);
 
        if (skipped.nr) {
@@ -1301,7 +1301,7 @@ static int prune_remote(const char *remote, int dry_run)
        string_list_sort(&refs_to_prune);
 
        if (!dry_run)
-               result |= delete_refs(&refs_to_prune, 0);
+               result |= delete_refs("remote: prune", &refs_to_prune, 0);
 
        for_each_string_list_item(item, &states.stale) {
                const char *refname = item->util;
diff --git a/refs.c b/refs.c
index 71139ba74e6d56d014a0f0cc85591c96da3bf7de..989462c972582026a942a875b330a9d640cc2929 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -1902,15 +1902,16 @@ int initial_ref_transaction_commit(struct ref_transaction *transaction,
        return refs->be->initial_transaction_commit(refs, transaction, err);
 }
 
-int refs_delete_refs(struct ref_store *refs, struct string_list *refnames,
-                    unsigned int flags)
+int refs_delete_refs(struct ref_store *refs, const char *msg,
+                    struct string_list *refnames, unsigned int flags)
 {
-       return refs->be->delete_refs(refs, refnames, flags);
+       return refs->be->delete_refs(refs, msg, refnames, flags);
 }
 
-int delete_refs(struct string_list *refnames, unsigned int flags)
+int delete_refs(const char *msg, struct string_list *refnames,
+               unsigned int flags)
 {
-       return refs_delete_refs(get_main_ref_store(), refnames, flags);
+       return refs_delete_refs(get_main_ref_store(), msg, refnames, flags);
 }
 
 int refs_rename_ref(struct ref_store *refs, const char *oldref,
diff --git a/refs.h b/refs.h
index ec8c6bfbbb5cb9bfec7f5f8f1fb43c82d11e969c..b62722fb817db6b83e630c031655eb7c8d8c056a 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -331,7 +331,8 @@ int reflog_exists(const char *refname);
  * verify that the current value of the reference is old_sha1 before
  * deleting it. If old_sha1 is NULL, delete the reference if it
  * 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().
+ * be NULL_SHA1. msg and flags are passed through to
+ * ref_transaction_delete().
  */
 int refs_delete_ref(struct ref_store *refs, const char *msg,
                    const char *refname,
@@ -343,12 +344,13 @@ int delete_ref(const char *msg, const char *refname,
 /*
  * Delete the specified references. If there are any problems, emit
  * errors but attempt to keep going (i.e., the deletes are not done in
- * an all-or-nothing transaction). flags is passed through to
+ * an all-or-nothing transaction). msg and flags are passed through to
  * ref_transaction_delete().
  */
-int refs_delete_refs(struct ref_store *refs, struct string_list *refnames,
-                    unsigned int flags);
-int delete_refs(struct string_list *refnames, unsigned int flags);
+int refs_delete_refs(struct ref_store *refs, const char *msg,
+                    struct string_list *refnames, unsigned int flags);
+int delete_refs(const char *msg, struct string_list *refnames,
+               unsigned int flags);
 
 /** Delete a reflog */
 int refs_delete_reflog(struct ref_store *refs, const char *refname);
index b2559b558556cadb7215c4cb366f6a3b8c2cb422..fce8265aa730d0ff80e46d44f8e7a4f2f7b7d30d 100644 (file)
@@ -1595,7 +1595,7 @@ static int repack_without_refs(struct files_ref_store *refs,
        return ret;
 }
 
-static int files_delete_refs(struct ref_store *ref_store,
+static int files_delete_refs(struct ref_store *ref_store, const char *msg,
                             struct string_list *refnames, unsigned int flags)
 {
        struct files_ref_store *refs =
@@ -1627,7 +1627,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 (refs_delete_ref(&refs->base, NULL, refname, NULL, flags))
+               if (refs_delete_ref(&refs->base, msg, refname, NULL, flags))
                        result |= error(_("could not remove reference %s"), refname);
        }
 
index 7020e51cb7c0a321e28591f6c397cfc3d15e0398..95edf6f234e42f5b341e439b73c1aa18be65d25f 100644 (file)
@@ -508,7 +508,7 @@ typedef int create_symref_fn(struct ref_store *ref_store,
                             const char *ref_target,
                             const char *refs_heads_master,
                             const char *logmsg);
-typedef int delete_refs_fn(struct ref_store *ref_store,
+typedef int delete_refs_fn(struct ref_store *ref_store, const char *msg,
                           struct string_list *refnames, unsigned int flags);
 typedef int rename_ref_fn(struct ref_store *ref_store,
                          const char *oldref, const char *newref,
index fba85e7da58fb124b409de502e9bb4f9a7d8f5b5..05d8c4d8af093ad42d855b17d243fe07b8893bfb 100644 (file)
@@ -93,12 +93,13 @@ static int cmd_create_symref(struct ref_store *refs, const char **argv)
 static int cmd_delete_refs(struct ref_store *refs, const char **argv)
 {
        unsigned int flags = arg_flags(*argv++, "flags");
+       const char *msg = *argv++;
        struct string_list refnames = STRING_LIST_INIT_NODUP;
 
        while (*argv)
                string_list_append(&refnames, *argv++);
 
-       return refs_delete_refs(refs, &refnames, flags);
+       return refs_delete_refs(refs, msg, &refnames, flags);
 }
 
 static int cmd_rename_ref(struct ref_store *refs, const char **argv)
index 490521f8cbd5eb28607b38860fb19a3ee20fdd56..e8115df5bad8d9ef46542cfd3c96c32da0bfa4ad 100755 (executable)
@@ -31,7 +31,7 @@ test_expect_success 'create_symref(FOO, refs/heads/master)' '
 test_expect_success 'delete_refs(FOO, refs/tags/new-tag)' '
        git rev-parse FOO -- &&
        git rev-parse refs/tags/new-tag -- &&
-       $RUN delete-refs 0 FOO refs/tags/new-tag &&
+       $RUN delete-refs 0 nothing FOO refs/tags/new-tag &&
        test_must_fail git rev-parse FOO -- &&
        test_must_fail git rev-parse refs/tags/new-tag --
 '
index 13b5454c5642f2f21786bb8bd3d06a2d27f1cf15..c32d4cc4652a4496ce8fa6aa1c10c797ae7d760a 100755 (executable)
@@ -31,7 +31,7 @@ test_expect_success 'create_symref() not allowed' '
 '
 
 test_expect_success 'delete_refs() not allowed' '
-       test_must_fail $RUN delete-refs 0 FOO refs/tags/new-tag
+       test_must_fail $RUN delete-refs 0 nothing FOO refs/tags/new-tag
 '
 
 test_expect_success 'rename_refs() not allowed' '