Re: [PATCH v16 02/14] Make refs_ref_exists public
- From
- Phillip Wood <phillip.wood123@gmail.com>
- Date
- Jun 9, 2020, 10:36 UTC
- Message-ID
- <9a5c0243-115e-ce50-dd80-2be4c889f4ba@gmail.com>
- In-Reply-To
- <a4a67ce9635197d759a12a617711764c1df16b65.1591380199.git.gitgitgadget@gmail.com>
On 05/06/2020 19:03, Han-Wen Nienhuys via GitGitGadget wrote:
Show 21 quoted lines
> From: Han-Wen Nienhuys <hanwen@google.com>
>
> Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
> ---
> refs.c | 2 +-
> refs.h | 2 ++
> 2 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/refs.c b/refs.c
> index 12908066b13..812fee47108 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -311,7 +311,7 @@ int read_ref(const char *refname, struct object_id *oid)
> return read_ref_full(refname, RESOLVE_REF_READING, oid, NULL);
> }
>
> -static int refs_ref_exists(struct ref_store *refs, const char *refname)
> +int refs_ref_exists(struct ref_store *refs, const char *refname)
> {
> return !!refs_resolve_ref_unsafe(refs, refname, RESOLVE_REF_READING, NULL, NULL);
> }It is a shame that ref_exists() does not take a struct repository. The
code in the following patches would be pleasanter if we could write
ref_exists(r, ref)
rather than
refs_ref_exists(get_main_ref_store(r), ref)
all the timeMaybe we should think about updating the existing callers to ref_exists() to pass a struct repository.
The existing code is inconsistent about its repository handling - we create the refs with update_ref() which operates on the main repository but when checking their existence and deleting them we use a path which depends on the repository. I've realized now the answer to my question about using delete_ref() in my reply to the previous patch - it does not take a repository - maybe it should along with update_ref() but that might be more work than you want to do though.
Best Wishes
Phillip
Show 14 quoted lines
> diff --git a/refs.h b/refs.h > index 4dad8f24914..7aaa1226551 100644 > --- a/refs.h > +++ b/refs.h > @@ -105,6 +105,8 @@ int refs_verify_refname_available(struct ref_store *refs, > const struct string_list *skip, > struct strbuf *err); > > +int refs_ref_exists(struct ref_store *refs, const char *refname); > + > int ref_exists(const char *refname); > > int should_autocreate_reflog(const char *refname); >