refs: drop force_create argument of create_reflog API

There is only one caller, builtin/checkout.c, and it hardcodes
force_create=1.

This argument was introduced in abd0cd3a30 (refs: new public ref function:
safe_create_reflog, 2015-07-21), which promised to immediately use it in a
follow-on commit, but that never happened.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Han-Wen Nienhuys 2021-11-22 14:19:08 +00:00 committed by Junio C Hamano
parent cd3e606211
commit 7b089120d9
10 changed files with 18 additions and 23 deletions

View File

@ -874,7 +874,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
int ret; int ret;
struct strbuf err = STRBUF_INIT; struct strbuf err = STRBUF_INIT;
ret = safe_create_reflog(refname, 1, &err); ret = safe_create_reflog(refname, &err);
if (ret) { if (ret) {
fprintf(stderr, _("Can not do reflog for '%s': %s\n"), fprintf(stderr, _("Can not do reflog for '%s': %s\n"),
opts->new_orphan_branch, err.buf); opts->new_orphan_branch, err.buf);

13
refs.c
View File

@ -2358,16 +2358,15 @@ int reflog_exists(const char *refname)
} }
int refs_create_reflog(struct ref_store *refs, const char *refname, int refs_create_reflog(struct ref_store *refs, const char *refname,
int force_create, struct strbuf *err)
{
return refs->be->create_reflog(refs, refname, force_create, err);
}
int safe_create_reflog(const char *refname, int force_create,
struct strbuf *err) struct strbuf *err)
{
return refs->be->create_reflog(refs, refname, err);
}
int safe_create_reflog(const char *refname, struct strbuf *err)
{ {
return refs_create_reflog(get_main_ref_store(the_repository), refname, return refs_create_reflog(get_main_ref_store(the_repository), refname,
force_create, err); err);
} }
int refs_delete_reflog(struct ref_store *refs, const char *refname) int refs_delete_reflog(struct ref_store *refs, const char *refname)

4
refs.h
View File

@ -413,8 +413,8 @@ int refs_pack_refs(struct ref_store *refs, unsigned int flags);
* Setup reflog before using. Fill in err and return -1 on failure. * Setup reflog before using. Fill in err and return -1 on failure.
*/ */
int refs_create_reflog(struct ref_store *refs, const char *refname, int refs_create_reflog(struct ref_store *refs, const char *refname,
int force_create, struct strbuf *err); struct strbuf *err);
int safe_create_reflog(const char *refname, int force_create, struct strbuf *err); int safe_create_reflog(const char *refname, struct strbuf *err);
/** Reads log for the value of ref during at_time. **/ /** Reads log for the value of ref during at_time. **/
int read_ref_at(struct ref_store *refs, int read_ref_at(struct ref_store *refs,

View File

@ -339,11 +339,10 @@ static int debug_reflog_exists(struct ref_store *ref_store, const char *refname)
} }
static int debug_create_reflog(struct ref_store *ref_store, const char *refname, static int debug_create_reflog(struct ref_store *ref_store, const char *refname,
int force_create, struct strbuf *err) struct strbuf *err)
{ {
struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store; struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store;
int res = drefs->refs->be->create_reflog(drefs->refs, refname, int res = drefs->refs->be->create_reflog(drefs->refs, refname, err);
force_create, err);
trace_printf_key(&trace_refs, "create_reflog: %s: %d\n", refname, res); trace_printf_key(&trace_refs, "create_reflog: %s: %d\n", refname, res);
return res; return res;
} }

View File

@ -1639,15 +1639,14 @@ error:
return -1; return -1;
} }
static int files_create_reflog(struct ref_store *ref_store, static int files_create_reflog(struct ref_store *ref_store, const char *refname,
const char *refname, int force_create,
struct strbuf *err) struct strbuf *err)
{ {
struct files_ref_store *refs = struct files_ref_store *refs =
files_downcast(ref_store, REF_STORE_WRITE, "create_reflog"); files_downcast(ref_store, REF_STORE_WRITE, "create_reflog");
int fd; int fd;
if (log_ref_setup(refs, refname, force_create, &fd, err)) if (log_ref_setup(refs, refname, 1, &fd, err))
return -1; return -1;
if (fd >= 0) if (fd >= 0)

View File

@ -1628,8 +1628,7 @@ static int packed_reflog_exists(struct ref_store *ref_store,
} }
static int packed_create_reflog(struct ref_store *ref_store, static int packed_create_reflog(struct ref_store *ref_store,
const char *refname, int force_create, const char *refname, struct strbuf *err)
struct strbuf *err)
{ {
BUG("packed reference store does not support reflogs"); BUG("packed reference store does not support reflogs");
} }

View File

@ -606,7 +606,7 @@ typedef int for_each_reflog_ent_reverse_fn(struct ref_store *ref_store,
void *cb_data); void *cb_data);
typedef int reflog_exists_fn(struct ref_store *ref_store, const char *refname); typedef int reflog_exists_fn(struct ref_store *ref_store, const char *refname);
typedef int create_reflog_fn(struct ref_store *ref_store, const char *refname, typedef int create_reflog_fn(struct ref_store *ref_store, const char *refname,
int force_create, struct strbuf *err); struct strbuf *err);
typedef int delete_reflog_fn(struct ref_store *ref_store, const char *refname); typedef int delete_reflog_fn(struct ref_store *ref_store, const char *refname);
typedef int reflog_expire_fn(struct ref_store *ref_store, typedef int reflog_expire_fn(struct ref_store *ref_store,
const char *refname, const char *refname,

View File

@ -181,11 +181,10 @@ static int cmd_reflog_exists(struct ref_store *refs, const char **argv)
static int cmd_create_reflog(struct ref_store *refs, const char **argv) static int cmd_create_reflog(struct ref_store *refs, const char **argv)
{ {
const char *refname = notnull(*argv++, "refname"); const char *refname = notnull(*argv++, "refname");
int force_create = arg_flags(*argv++, "force-create");
struct strbuf err = STRBUF_INIT; struct strbuf err = STRBUF_INIT;
int ret; int ret;
ret = refs_create_reflog(refs, refname, force_create, &err); ret = refs_create_reflog(refs, refname, &err);
if (err.len) if (err.len)
puts(err.buf); puts(err.buf);
return ret; return ret;

View File

@ -108,7 +108,7 @@ test_expect_success 'delete_reflog(HEAD)' '
' '
test_expect_success 'create-reflog(HEAD)' ' test_expect_success 'create-reflog(HEAD)' '
$RUN create-reflog HEAD 1 && $RUN create-reflog HEAD &&
git reflog exists HEAD git reflog exists HEAD
' '

View File

@ -92,7 +92,7 @@ test_expect_success 'delete_reflog() not allowed' '
' '
test_expect_success 'create-reflog() not allowed' ' test_expect_success 'create-reflog() not allowed' '
test_must_fail $RUN create-reflog HEAD 1 test_must_fail $RUN create-reflog HEAD
' '
test_done test_done