{"thread":{"id":"56957","subject":"[PATCH] refs: drop force_create argument of create_reflog API","startedAt":"2021-11-22T14:19:15Z","lastAt":"2021-11-22T19:01:02Z","messageCount":2,"participants":["Han-Wen Nienhuys via GitGitGadget","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"441948","messageId":"pull.1144.git.git.1637590749342.gitgitgadget@gmail.com","threadId":"56957","inReplyTo":null,"subject":"[PATCH] refs: drop force_create argument of create_reflog API","fromName":"Han-Wen Nienhuys via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2021-11-22T14:19:08Z","receivedAt":"2021-11-22T14:19:15Z","isPatch":true,"sender":{"key":"hanwen@google.com","avatar":"https://avatars.githubusercontent.com/u/31547?v=4"},"body":"From: Han-Wen Nienhuys <hanwen@google.com>\n\nThere is only one caller, builtin/checkout.c, and it hardcodes\nforce_create=1.\n\nThis argument was introduced in abd0cd3a301 (refs: new public ref function:\nsafe_create_reflog, 2015-07-21), which promised to immediately use it in a\nfollow-on commit, but that never happened.\n\nSigned-off-by: Han-Wen Nienhuys <hanwen@google.com>\n---\n    refs: drop force_create argument of create_reflog API\n    \n    There is only one caller, builtin/checkout.c, and it hardcodes\n    force_create=1.\n    \n    This argument was introduced in abd0cd3a301 (refs: new public ref\n    function: safe_create_reflog, 2015-07-21), which promised to immediately\n    use it in a follow-on commit, but that never happened.\n    \n    Signed-off-by: Han-Wen Nienhuys hanwen@google.com\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1144%2Fhanwen%2Freflog-create-arg-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1144/hanwen/reflog-create-arg-v1\nPull-Request: https://github.com/git/git/pull/1144\n\n builtin/checkout.c             | 2 +-\n refs.c                         | 9 ++++-----\n refs.h                         | 4 ++--\n refs/debug.c                   | 5 ++---\n refs/files-backend.c           | 5 ++---\n refs/packed-backend.c          | 3 +--\n refs/refs-internal.h           | 2 +-\n t/helper/test-ref-store.c      | 3 +--\n t/t1405-main-ref-store.sh      | 2 +-\n t/t1406-submodule-ref-store.sh | 2 +-\n 10 files changed, 16 insertions(+), 21 deletions(-)\n\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex cbf73b8c9f6..19d752847f8 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -874,7 +874,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,\n \t\t\t\tint ret;\n \t\t\t\tstruct strbuf err = STRBUF_INIT;\n \n-\t\t\t\tret = safe_create_reflog(refname, 1, &err);\n+\t\t\t\tret = safe_create_reflog(refname, &err);\n \t\t\t\tif (ret) {\n \t\t\t\t\tfprintf(stderr, _(\"Can not do reflog for '%s': %s\\n\"),\n \t\t\t\t\t\topts->new_orphan_branch, err.buf);\ndiff --git a/refs.c b/refs.c\nindex d7cc0a23a3b..cc291ee49fc 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -2358,16 +2358,15 @@ int reflog_exists(const char *refname)\n }\n \n int refs_create_reflog(struct ref_store *refs, const char *refname,\n-\t\t       int force_create, struct strbuf *err)\n+\t\t       struct strbuf *err)\n {\n-\treturn refs->be->create_reflog(refs, refname, force_create, err);\n+\treturn refs->be->create_reflog(refs, refname, err);\n }\n \n-int safe_create_reflog(const char *refname, int force_create,\n-\t\t       struct strbuf *err)\n+int safe_create_reflog(const char *refname, struct strbuf *err)\n {\n \treturn refs_create_reflog(get_main_ref_store(the_repository), refname,\n-\t\t\t\t  force_create, err);\n+\t\t\t\t  err);\n }\n \n int refs_delete_reflog(struct ref_store *refs, const char *refname)\ndiff --git a/refs.h b/refs.h\nindex d5099d4984e..bd3836c97ef 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -413,8 +413,8 @@ int refs_pack_refs(struct ref_store *refs, unsigned int flags);\n  * Setup reflog before using. Fill in err and return -1 on failure.\n  */\n int refs_create_reflog(struct ref_store *refs, const char *refname,\n-\t\t       int force_create, struct strbuf *err);\n-int safe_create_reflog(const char *refname, int force_create, struct strbuf *err);\n+\t\t       struct strbuf *err);\n+int safe_create_reflog(const char *refname, struct strbuf *err);\n \n /** Reads log for the value of ref during at_time. **/\n int read_ref_at(struct ref_store *refs,\ndiff --git a/refs/debug.c b/refs/debug.c\nindex 8667c640237..756d07c7247 100644\n--- a/refs/debug.c\n+++ b/refs/debug.c\n@@ -339,11 +339,10 @@ static int debug_reflog_exists(struct ref_store *ref_store, const char *refname)\n }\n \n static int debug_create_reflog(struct ref_store *ref_store, const char *refname,\n-\t\t\t       int force_create, struct strbuf *err)\n+\t\t\t       struct strbuf *err)\n {\n \tstruct debug_ref_store *drefs = (struct debug_ref_store *)ref_store;\n-\tint res = drefs->refs->be->create_reflog(drefs->refs, refname,\n-\t\t\t\t\t\t force_create, err);\n+\tint res = drefs->refs->be->create_reflog(drefs->refs, refname, err);\n \ttrace_printf_key(&trace_refs, \"create_reflog: %s: %d\\n\", refname, res);\n \treturn res;\n }\ndiff --git a/refs/files-backend.c b/refs/files-backend.c\nindex 151b0056fe5..00f596dd68c 100644\n--- a/refs/files-backend.c\n+++ b/refs/files-backend.c\n@@ -1639,15 +1639,14 @@ error:\n \treturn -1;\n }\n \n-static int files_create_reflog(struct ref_store *ref_store,\n-\t\t\t       const char *refname, int force_create,\n+static int files_create_reflog(struct ref_store *ref_store, const char *refname,\n \t\t\t       struct strbuf *err)\n {\n \tstruct files_ref_store *refs =\n \t\tfiles_downcast(ref_store, REF_STORE_WRITE, \"create_reflog\");\n \tint fd;\n \n-\tif (log_ref_setup(refs, refname, force_create, &fd, err))\n+\tif (log_ref_setup(refs, refname, 1, &fd, err))\n \t\treturn -1;\n \n \tif (fd >= 0)\ndiff --git a/refs/packed-backend.c b/refs/packed-backend.c\nindex 1c5211b03e4..472458b844e 100644\n--- a/refs/packed-backend.c\n+++ b/refs/packed-backend.c\n@@ -1628,8 +1628,7 @@ static int packed_reflog_exists(struct ref_store *ref_store,\n }\n \n static int packed_create_reflog(struct ref_store *ref_store,\n-\t\t\t       const char *refname, int force_create,\n-\t\t\t       struct strbuf *err)\n+\t\t\t\tconst char *refname, struct strbuf *err)\n {\n \tBUG(\"packed reference store does not support reflogs\");\n }\ndiff --git a/refs/refs-internal.h b/refs/refs-internal.h\nindex 12224742ede..5b40b3bbbf8 100644\n--- a/refs/refs-internal.h\n+++ b/refs/refs-internal.h\n@@ -606,7 +606,7 @@ typedef int for_each_reflog_ent_reverse_fn(struct ref_store *ref_store,\n \t\t\t\t\t   void *cb_data);\n typedef int reflog_exists_fn(struct ref_store *ref_store, const char *refname);\n typedef int create_reflog_fn(struct ref_store *ref_store, const char *refname,\n-\t\t\t     int force_create, struct strbuf *err);\n+\t\t\t     struct strbuf *err);\n typedef int delete_reflog_fn(struct ref_store *ref_store, const char *refname);\n typedef int reflog_expire_fn(struct ref_store *ref_store,\n \t\t\t     const char *refname,\ndiff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c\nindex b314b81a45b..98f827edfb7 100644\n--- a/t/helper/test-ref-store.c\n+++ b/t/helper/test-ref-store.c\n@@ -181,11 +181,10 @@ static int cmd_reflog_exists(struct ref_store *refs, const char **argv)\n static int cmd_create_reflog(struct ref_store *refs, const char **argv)\n {\n \tconst char *refname = notnull(*argv++, \"refname\");\n-\tint force_create = arg_flags(*argv++, \"force-create\");\n \tstruct strbuf err = STRBUF_INIT;\n \tint ret;\n \n-\tret = refs_create_reflog(refs, refname, force_create, &err);\n+\tret = refs_create_reflog(refs, refname, &err);\n \tif (err.len)\n \t\tputs(err.buf);\n \treturn ret;\ndiff --git a/t/t1405-main-ref-store.sh b/t/t1405-main-ref-store.sh\nindex 49718b7ea7f..c89cef2d26b 100755\n--- a/t/t1405-main-ref-store.sh\n+++ b/t/t1405-main-ref-store.sh\n@@ -108,7 +108,7 @@ test_expect_success 'delete_reflog(HEAD)' '\n '\n \n test_expect_success 'create-reflog(HEAD)' '\n-\t$RUN create-reflog HEAD 1 &&\n+\t$RUN create-reflog HEAD &&\n \tgit reflog exists HEAD\n '\n \ndiff --git a/t/t1406-submodule-ref-store.sh b/t/t1406-submodule-ref-store.sh\nindex 0a87058971e..f1e57a9c051 100755\n--- a/t/t1406-submodule-ref-store.sh\n+++ b/t/t1406-submodule-ref-store.sh\n@@ -92,7 +92,7 @@ test_expect_success 'delete_reflog() not allowed' '\n '\n \n test_expect_success 'create-reflog() not allowed' '\n-\ttest_must_fail $RUN create-reflog HEAD 1\n+\ttest_must_fail $RUN create-reflog HEAD\n '\n \n test_done\n\nbase-commit: cd3e606211bb1cf8bc57f7d76bab98cc17a150bc\n-- \ngitgitgadget\n"},{"id":"442012","messageId":"xmqq4k84f21i.fsf@gitster.g","threadId":"56957","inReplyTo":"pull.1144.git.git.1637590749342.gitgitgadget@gmail.com","subject":"Re: [PATCH] refs: drop force_create argument of create_reflog API","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-11-22T19:00:57Z","receivedAt":"2021-11-22T19:01:02Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Han-Wen Nienhuys via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> From: Han-Wen Nienhuys <hanwen@google.com>\n>\n> There is only one caller, builtin/checkout.c, and it hardcodes\n> force_create=1.\n>\n> This argument was introduced in abd0cd3a301 (refs: new public ref function:\n> safe_create_reflog, 2015-07-21), which promised to immediately use it in a\n> follow-on commit, but that never happened.\n>\n> Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>\n> ---\n\nThanks.  It's an obvious simplification.  I wish all our changes were\nlike this ;-)\n\n> diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c\n> index b314b81a45b..98f827edfb7 100644\n> --- a/t/helper/test-ref-store.c\n> +++ b/t/helper/test-ref-store.c\n> @@ -181,11 +181,10 @@ static int cmd_reflog_exists(struct ref_store *refs, const char **argv)\n>  static int cmd_create_reflog(struct ref_store *refs, const char **argv)\n>  {\n>  \tconst char *refname = notnull(*argv++, \"refname\");\n> -\tint force_create = arg_flags(*argv++, \"force-create\");\n>  \tstruct strbuf err = STRBUF_INIT;\n>  \tint ret;\n>  \n> -\tret = refs_create_reflog(refs, refname, force_create, &err);\n> +\tret = refs_create_reflog(refs, refname, &err);\n>  \tif (err.len)\n>  \t\tputs(err.buf);\n>  \treturn ret;\n> diff --git a/t/t1405-main-ref-store.sh b/t/t1405-main-ref-store.sh\n> index 49718b7ea7f..c89cef2d26b 100755\n> --- a/t/t1405-main-ref-store.sh\n> +++ b/t/t1405-main-ref-store.sh\n> @@ -108,7 +108,7 @@ test_expect_success 'delete_reflog(HEAD)' '\n>  '\n>  \n>  test_expect_success 'create-reflog(HEAD)' '\n> -\t$RUN create-reflog HEAD 1 &&\n> +\t$RUN create-reflog HEAD &&\n>  \tgit reflog exists HEAD\n>  '\n>  \n> diff --git a/t/t1406-submodule-ref-store.sh b/t/t1406-submodule-ref-store.sh\n> index 0a87058971e..f1e57a9c051 100755\n> --- a/t/t1406-submodule-ref-store.sh\n> +++ b/t/t1406-submodule-ref-store.sh\n> @@ -92,7 +92,7 @@ test_expect_success 'delete_reflog() not allowed' '\n>  '\n>  \n>  test_expect_success 'create-reflog() not allowed' '\n> -\ttest_must_fail $RUN create-reflog HEAD 1\n> +\ttest_must_fail $RUN create-reflog HEAD\n>  '\n>  \n>  test_done\n>\n> base-commit: cd3e606211bb1cf8bc57f7d76bab98cc17a150bc\n"}]}