ref_store: take a `msg` parameter when deleting references

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>

Michael Haggerty committed May 22, 2017 at 16:17 UTC 64da41993a2c33e9187858808d5a6c87e6d6d101
9 files changed +23 -19
builtin/fetch.c
+1 -1
@@ -941,7 +941,7 @@ static int prune_refs(struct refspec *refs, int ref_count, struct ref *ref_map,
941 for (ref = stale_refs; ref; ref = ref->next)
942 string_list_append(&refnames, ref->name);
943
944 - result = delete_refs(&refnames, 0);
944 + result = delete_refs("fetch: prune", &refnames, 0);
945 string_list_clear(&refnames, 0);
946 }
947
builtin/remote.c
+2 -2
@@ -786,7 +786,7 @@ static int rm(int argc, const char **argv)
786 strbuf_release(&buf);
787
788 if (!result)
789 - result = delete_refs(&branches, REF_NODEREF);
789 + result = delete_refs("remote: remove", &branches, REF_NODEREF);
790 string_list_clear(&branches, 0);
791
792 if (skipped.nr) {
@@ -1301,7 +1301,7 @@ static int prune_remote(const char *remote, int dry_run)
1301 string_list_sort(&refs_to_prune);
1302
1303 if (!dry_run)
1304 - result |= delete_refs(&refs_to_prune, 0);
1304 + result |= delete_refs("remote: prune", &refs_to_prune, 0);
1305
1306 for_each_string_list_item(item, &states.stale) {
1307 const char *refname = item->util;
refs.c
+6 -5
@@ -1902,15 +1902,16 @@ int initial_ref_transaction_commit(struct ref_transaction *transaction,
1902 return refs->be->initial_transaction_commit(refs, transaction, err);
1903 }
1904
1905 -int refs_delete_refs(struct ref_store *refs, struct string_list *refnames,
1906 - unsigned int flags)
1905 +int refs_delete_refs(struct ref_store *refs, const char *msg,
1906 + struct string_list *refnames, unsigned int flags)
1907 {
1908 - return refs->be->delete_refs(refs, refnames, flags);
1908 + return refs->be->delete_refs(refs, msg, refnames, flags);
1909 }
1910
1911 -int delete_refs(struct string_list *refnames, unsigned int flags)
1911 +int delete_refs(const char *msg, struct string_list *refnames,
1912 + unsigned int flags)
1913 {
1913 - return refs_delete_refs(get_main_ref_store(), refnames, flags);
1914 + return refs_delete_refs(get_main_ref_store(), msg, refnames, flags);
1915 }
1916
1917 int refs_rename_ref(struct ref_store *refs, const char *oldref,
refs.h
+7 -5
@@ -331,7 +331,8 @@ int reflog_exists(const char *refname);
331 * verify that the current value of the reference is old_sha1 before
332 * deleting it. If old_sha1 is NULL, delete the reference if it
333 * exists, regardless of its old value. It is an error for old_sha1 to
334 - * be NULL_SHA1. flags is passed through to ref_transaction_delete().
334 + * be NULL_SHA1. msg and flags are passed through to
335 + * ref_transaction_delete().
336 */
337 int refs_delete_ref(struct ref_store *refs, const char *msg,
338 const char *refname,
@@ -343,12 +344,13 @@ int delete_ref(const char *msg, const char *refname,
344 /*
345 * Delete the specified references. If there are any problems, emit
346 * errors but attempt to keep going (i.e., the deletes are not done in
346 - * an all-or-nothing transaction). flags is passed through to
347 + * an all-or-nothing transaction). msg and flags are passed through to
348 * ref_transaction_delete().
349 */
349 -int refs_delete_refs(struct ref_store *refs, struct string_list *refnames,
350 - unsigned int flags);
351 -int delete_refs(struct string_list *refnames, unsigned int flags);
350 +int refs_delete_refs(struct ref_store *refs, const char *msg,
351 + struct string_list *refnames, unsigned int flags);
352 +int delete_refs(const char *msg, struct string_list *refnames,
353 + unsigned int flags);
354
355 /** Delete a reflog */
356 int refs_delete_reflog(struct ref_store *refs, const char *refname);
refs/files-backend.c
+2 -2
@@ -1595,7 +1595,7 @@ static int repack_without_refs(struct files_ref_store *refs,
1595 return ret;
1596 }
1597
1598 -static int files_delete_refs(struct ref_store *ref_store,
1598 +static int files_delete_refs(struct ref_store *ref_store, const char *msg,
1599 struct string_list *refnames, unsigned int flags)
1600 {
1601 struct files_ref_store *refs =
@@ -1627,7 +1627,7 @@ static int files_delete_refs(struct ref_store *ref_store,
1627 for (i = 0; i < refnames->nr; i++) {
1628 const char *refname = refnames->items[i].string;
1629
1630 - if (refs_delete_ref(&refs->base, NULL, refname, NULL, flags))
1630 + if (refs_delete_ref(&refs->base, msg, refname, NULL, flags))
1631 result |= error(_("could not remove reference %s"), refname);
1632 }
1633
refs/refs-internal.h
+1 -1
@@ -508,7 +508,7 @@ typedef int create_symref_fn(struct ref_store *ref_store,
508 const char *ref_target,
509 const char *refs_heads_master,
510 const char *logmsg);
511 -typedef int delete_refs_fn(struct ref_store *ref_store,
511 +typedef int delete_refs_fn(struct ref_store *ref_store, const char *msg,
512 struct string_list *refnames, unsigned int flags);
513 typedef int rename_ref_fn(struct ref_store *ref_store,
514 const char *oldref, const char *newref,
t/helper/test-ref-store.c
+2 -1
@@ -93,12 +93,13 @@ static int cmd_create_symref(struct ref_store *refs, const char **argv)
93 static int cmd_delete_refs(struct ref_store *refs, const char **argv)
94 {
95 unsigned int flags = arg_flags(*argv++, "flags");
96 + const char *msg = *argv++;
97 struct string_list refnames = STRING_LIST_INIT_NODUP;
98
99 while (*argv)
100 string_list_append(&refnames, *argv++);
101
101 - return refs_delete_refs(refs, &refnames, flags);
102 + return refs_delete_refs(refs, msg, &refnames, flags);
103 }
104
105 static int cmd_rename_ref(struct ref_store *refs, const char **argv)
t/t1405-main-ref-store.sh
+1 -1
@@ -31,7 +31,7 @@ test_expect_success 'create_symref(FOO, refs/heads/master)' '
31 test_expect_success 'delete_refs(FOO, refs/tags/new-tag)' '
32 git rev-parse FOO -- &&
33 git rev-parse refs/tags/new-tag -- &&
34 - $RUN delete-refs 0 FOO refs/tags/new-tag &&
34 + $RUN delete-refs 0 nothing FOO refs/tags/new-tag &&
35 test_must_fail git rev-parse FOO -- &&
36 test_must_fail git rev-parse refs/tags/new-tag --
37 '
t/t1406-submodule-ref-store.sh
+1 -1
@@ -31,7 +31,7 @@ test_expect_success 'create_symref() not allowed' '
31 '
32
33 test_expect_success 'delete_refs() not allowed' '
34 - test_must_fail $RUN delete-refs 0 FOO refs/tags/new-tag
34 + test_must_fail $RUN delete-refs 0 nothing FOO refs/tags/new-tag
35 '
36
37 test_expect_success 'rename_refs() not allowed' '