Skip to content

Commit 64da419

Browse files
mhaggergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 43a2dfd commit 64da419

File tree

9 files changed

+23
-19
lines changed

9 files changed

+23
-19
lines changed

builtin/fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ static int prune_refs(struct refspec *refs, int ref_count, struct ref *ref_map,
941941
for (ref = stale_refs; ref; ref = ref->next)
942942
string_list_append(&refnames, ref->name);
943943

944-
result = delete_refs(&refnames, 0);
944+
result = delete_refs("fetch: prune", &refnames, 0);
945945
string_list_clear(&refnames, 0);
946946
}
947947

builtin/remote.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ static int rm(int argc, const char **argv)
786786
strbuf_release(&buf);
787787

788788
if (!result)
789-
result = delete_refs(&branches, REF_NODEREF);
789+
result = delete_refs("remote: remove", &branches, REF_NODEREF);
790790
string_list_clear(&branches, 0);
791791

792792
if (skipped.nr) {
@@ -1301,7 +1301,7 @@ static int prune_remote(const char *remote, int dry_run)
13011301
string_list_sort(&refs_to_prune);
13021302

13031303
if (!dry_run)
1304-
result |= delete_refs(&refs_to_prune, 0);
1304+
result |= delete_refs("remote: prune", &refs_to_prune, 0);
13051305

13061306
for_each_string_list_item(item, &states.stale) {
13071307
const char *refname = item->util;

refs.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,15 +1902,16 @@ int initial_ref_transaction_commit(struct ref_transaction *transaction,
19021902
return refs->be->initial_transaction_commit(refs, transaction, err);
19031903
}
19041904

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)
19071907
{
1908-
return refs->be->delete_refs(refs, refnames, flags);
1908+
return refs->be->delete_refs(refs, msg, refnames, flags);
19091909
}
19101910

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)
19121913
{
1913-
return refs_delete_refs(get_main_ref_store(), refnames, flags);
1914+
return refs_delete_refs(get_main_ref_store(), msg, refnames, flags);
19141915
}
19151916

19161917
int refs_rename_ref(struct ref_store *refs, const char *oldref,

refs.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ int reflog_exists(const char *refname);
331331
* verify that the current value of the reference is old_sha1 before
332332
* deleting it. If old_sha1 is NULL, delete the reference if it
333333
* 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().
335336
*/
336337
int refs_delete_ref(struct ref_store *refs, const char *msg,
337338
const char *refname,
@@ -343,12 +344,13 @@ int delete_ref(const char *msg, const char *refname,
343344
/*
344345
* Delete the specified references. If there are any problems, emit
345346
* 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
347348
* ref_transaction_delete().
348349
*/
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);
352354

353355
/** Delete a reflog */
354356
int refs_delete_reflog(struct ref_store *refs, const char *refname);

refs/files-backend.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ static int repack_without_refs(struct files_ref_store *refs,
15951595
return ret;
15961596
}
15971597

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,
15991599
struct string_list *refnames, unsigned int flags)
16001600
{
16011601
struct files_ref_store *refs =
@@ -1627,7 +1627,7 @@ static int files_delete_refs(struct ref_store *ref_store,
16271627
for (i = 0; i < refnames->nr; i++) {
16281628
const char *refname = refnames->items[i].string;
16291629

1630-
if (refs_delete_ref(&refs->base, NULL, refname, NULL, flags))
1630+
if (refs_delete_ref(&refs->base, msg, refname, NULL, flags))
16311631
result |= error(_("could not remove reference %s"), refname);
16321632
}
16331633

refs/refs-internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ typedef int create_symref_fn(struct ref_store *ref_store,
508508
const char *ref_target,
509509
const char *refs_heads_master,
510510
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,
512512
struct string_list *refnames, unsigned int flags);
513513
typedef int rename_ref_fn(struct ref_store *ref_store,
514514
const char *oldref, const char *newref,

t/helper/test-ref-store.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,13 @@ static int cmd_create_symref(struct ref_store *refs, const char **argv)
9393
static int cmd_delete_refs(struct ref_store *refs, const char **argv)
9494
{
9595
unsigned int flags = arg_flags(*argv++, "flags");
96+
const char *msg = *argv++;
9697
struct string_list refnames = STRING_LIST_INIT_NODUP;
9798

9899
while (*argv)
99100
string_list_append(&refnames, *argv++);
100101

101-
return refs_delete_refs(refs, &refnames, flags);
102+
return refs_delete_refs(refs, msg, &refnames, flags);
102103
}
103104

104105
static int cmd_rename_ref(struct ref_store *refs, const char **argv)

t/t1405-main-ref-store.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ test_expect_success 'create_symref(FOO, refs/heads/master)' '
3131
test_expect_success 'delete_refs(FOO, refs/tags/new-tag)' '
3232
git rev-parse FOO -- &&
3333
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 &&
3535
test_must_fail git rev-parse FOO -- &&
3636
test_must_fail git rev-parse refs/tags/new-tag --
3737
'

t/t1406-submodule-ref-store.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ test_expect_success 'create_symref() not allowed' '
3131
'
3232

3333
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
3535
'
3636

3737
test_expect_success 'rename_refs() not allowed' '

0 commit comments

Comments
 (0)