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>
This commit is contained in:
parent
43a2dfde76
commit
64da41993a
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
11
refs.c
11
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,
|
||||
|
12
refs.h
12
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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
@ -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 --
|
||||
'
|
||||
|
@ -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' '
|
||||
|
Loading…
Reference in New Issue
Block a user