From: Michael Haggerty <mhagger@alum.mit.edu>
To: David Turner <dturner@twopensource.com>, git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH v5 25/26] refs: break out ref conflict checks
Date: Mon, 02 Nov 2015 17:52:01 +0100 [thread overview]
Message-ID: <563794B1.5000002@alum.mit.edu> (raw)
In-Reply-To: <1445998467-11511-26-git-send-email-dturner@twopensource.com>
On 10/28/2015 03:14 AM, David Turner wrote:
> Create new function verify_no_descendants, to hold one of the ref
> conflict checks used in verify_refname_available. Multiple backends
> will need this function, so it goes in the common code.
>
> rename_ref_available also moves to the common code, because alternate
> backends might need it and it has no files-backend-specific code.
It is preferred that log messages be written in the imperative voice:
... so move it to the common code.
Also move rename_ref_available ...
> Signed-off-by: David Turner <dturner@twopensource.com>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
> ---
> refs-be-files.c | 49 ++++++++-----------------------------------------
> refs.c | 38 ++++++++++++++++++++++++++++++++++++++
> refs.h | 15 +++++++++++++++
> 3 files changed, 61 insertions(+), 41 deletions(-)
>
> diff --git a/refs-be-files.c b/refs-be-files.c
> index 0eabea9..97a5983 100644
> --- a/refs-be-files.c
> +++ b/refs-be-files.c
> @@ -729,6 +729,7 @@ static int verify_refname_available_dir(const char *refname,
> struct strbuf *err)
> {
> const char *slash;
> + const char *extra_refname;
> int pos;
> struct strbuf dirname = STRBUF_INIT;
> int ret = -1;
> @@ -834,33 +835,15 @@ static int verify_refname_available_dir(const char *refname,
> }
> }
>
> - if (extras) {
> - /*
> - * Check for entries in extras that start with
> - * "$refname/". We do that by looking for the place
> - * where "$refname/" would be inserted in extras. If
> - * there is an entry at that position that starts with
> - * "$refname/" and is not in skip, then we have a
> - * conflict.
> - */
In your version, the above comment is replaced with
/* Look for the place where dirname would be inserted in extras. */
which is pretty obvious, I think, from the following line. It's
debatable whether the long-winded old comment was worthwhile, but I
think the new comment is clearly not. I suggest either restoring a
longer explanation or eliminating the comment altogether.
> - for (pos = string_list_find_insert_index(extras, dirname.buf, 0);
> - pos < extras->nr; pos++) {
> - const char *extra_refname = extras->items[pos].string;
> -
> - if (!starts_with(extra_refname, dirname.buf))
> - break;
> -
> - if (!skip || !string_list_has_string(skip, extra_refname)) {
> - strbuf_addf(err, "cannot process '%s' and '%s' at the same time",
> - refname, extra_refname);
> - goto cleanup;
> - }
> - }
> + extra_refname = find_descendant_ref(dirname.buf, extras, skip);
> + if (extra_refname) {
> + strbuf_addf(err,
> + "cannot process '%s' and '%s' at the same time",
> + refname, extra_refname);
> + } else {
> + ret = 0;
> }
Project practice is to leave out unnecessary braces.
>
> - /* No conflicts were found */
> - ret = 0;
> -
> cleanup:
> strbuf_release(&dirname);
> return ret;
> @@ -2460,22 +2443,6 @@ out:
> [...]
> diff --git a/refs.c b/refs.c
> index 056c172..5d8b6ea 100644
> --- a/refs.c
> +++ b/refs.c
> [...]
> diff --git a/refs.h b/refs.h
> index f97a2e4..88fea3e 100644
> --- a/refs.h
> +++ b/refs.h
> [...]
> @@ -623,6 +625,19 @@ int files_log_ref_write(const char *refname, const unsigned char *old_sha1,
> const unsigned char *new_sha1, const char *msg,
> int flags, struct strbuf *err);
>
> +/*
> + * Check for entries in extras that are within the specified
> + * directory, where dirname is a reference directory name including
> + * the trailing slash (e.g., "refs/heads/master/"). Ignore any
> + * conflicting references that are found in skip. If there is a
> + * conflicting reference, return its name.
> + *
> + * extras and skip must be sorted lists of reference names. skip can
> + * be NULL; extras cannot.
The last sentence is incorrect; the function can handle extras == NULL.
> + */
> +const char *find_descendant_ref(const char *dirname,
> + const struct string_list *extras,
> + const struct string_list *skip);
>
> enum expire_reflog_flags {
> EXPIRE_REFLOGS_DRY_RUN = 1 << 0,
>
Michael
--
Michael Haggerty
mhagger@alum.mit.edu
next prev parent reply other threads:[~2015-11-02 16:59 UTC|newest]
Thread overview: 67+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-28 2:14 [PATCH v5 00/26] refs backend pre-vtable David Turner
2015-10-28 2:14 ` [PATCH v5 01/26] refs.c: create a public version of verify_refname_available David Turner
2015-10-28 2:14 ` [PATCH v5 02/26] refs: make is_branch public David Turner
2015-10-28 2:14 ` [PATCH v5 03/26] refs-be-files.c: rename refs to refs-be-files David Turner
2015-10-28 2:14 ` [PATCH v5 04/26] refs.c: add a new refs.c file to hold all common refs code David Turner
2015-10-28 2:14 ` [PATCH v5 05/26] refs.c: move update_ref to refs.c David Turner
2015-10-28 2:14 ` [PATCH v5 06/26] refs.c: move delete_pseudoref and delete_ref to the common code David Turner
2015-10-28 2:14 ` [PATCH v5 07/26] refs.c: move read_ref_at to the common refs file David Turner
2015-10-28 2:14 ` [PATCH v5 08/26] refs.c: move the hidden refs functions to the common code David Turner
2015-10-28 2:14 ` [PATCH v5 09/26] refs.c: move dwim and friend functions to the common refs code David Turner
2015-10-28 2:14 ` [PATCH v5 10/26] refs.c: move warn_if_dangling_symref* to the common code David Turner
2015-10-28 2:14 ` [PATCH v5 11/26] refs.c: move read_ref, read_ref_full and ref_exists " David Turner
2015-10-28 2:14 ` [PATCH v5 12/26] refs.c: move resolve_refdup to common David Turner
2015-10-28 2:14 ` [PATCH v5 13/26] refs.c: move check_refname_format to the common code David Turner
2015-10-28 2:14 ` [PATCH v5 14/26] refs.c: move is_branch " David Turner
2015-10-28 2:14 ` [PATCH v5 15/26] refs.c: move prettify_refname " David Turner
2015-10-28 2:14 ` [PATCH v5 16/26] refs.c: move ref iterators " David Turner
2015-11-01 4:39 ` Michael Haggerty
2015-10-28 2:14 ` [PATCH v5 17/26] refs.c: move head_ref_namespaced " David Turner
2015-10-28 2:14 ` [PATCH v5 18/26] refs: move transaction functions into " David Turner
2015-11-01 8:17 ` Michael Haggerty
2015-11-02 22:19 ` David Turner
2015-10-28 2:14 ` [PATCH v5 19/26] refs.c: move refname_is_safe to the " David Turner
2015-10-28 2:14 ` [PATCH v5 20/26] refs.c: move copy_msg " David Turner
2015-10-28 2:14 ` [PATCH v5 21/26] refs.c: move peel_object " David Turner
2015-10-28 2:14 ` [PATCH v5 22/26] refs.c: move should_autocreate_reflog to " David Turner
2015-10-28 2:14 ` [PATCH v5 23/26] initdb: move safe_create_dir into " David Turner
2015-10-28 2:14 ` [PATCH v5 24/26] refs: make files_log_ref_write functions public David Turner
2015-10-28 2:14 ` [PATCH v5 25/26] refs: break out ref conflict checks David Turner
2015-11-02 16:52 ` Michael Haggerty [this message]
2015-10-28 2:14 ` [PATCH v5 26/26] introduce "extensions" form of core.repositoryformatversion David Turner
2015-11-03 7:36 ` [PATCH v5 00/26] refs backend pre-vtable Michael Haggerty
2015-11-03 7:39 ` [PATCH v6 00/25] " Michael Haggerty
2015-11-03 7:39 ` [PATCH v6 01/25] refs: make is_branch public Michael Haggerty
2015-11-03 7:39 ` [PATCH v6 02/25] refs/files-backend.c: new file, renamed from refs.c Michael Haggerty
2015-11-03 7:39 ` [PATCH v6 03/25] refs: add a new file, refs/refs.c, to hold common refs code Michael Haggerty
2015-11-03 7:39 ` [PATCH v6 04/25] refs: move update_ref to refs/refs.c Michael Haggerty
2015-11-03 7:39 ` [PATCH v6 05/25] refs: move delete_pseudoref and delete_ref to the common code Michael Haggerty
2015-11-03 7:39 ` [PATCH v6 06/25] refs: move read_ref_at to the common refs file Michael Haggerty
2015-11-03 7:39 ` [PATCH v6 07/25] refs: move the hidden refs functions to the common code Michael Haggerty
2015-11-03 7:39 ` [PATCH v6 08/25] refs: move dwim and friend functions to the common refs code Michael Haggerty
2015-11-03 7:39 ` [PATCH v6 09/25] refs: move warn_if_dangling_symref* to the common code Michael Haggerty
2015-11-03 7:39 ` [PATCH v6 10/25] refs: move read_ref, read_ref_full and ref_exists " Michael Haggerty
2015-11-03 7:39 ` [PATCH v6 11/25] refs: move resolve_refdup to common Michael Haggerty
2015-11-03 7:39 ` [PATCH v6 12/25] refs: move check_refname_format to the common code Michael Haggerty
2015-11-03 7:39 ` [PATCH v6 13/25] refs: move is_branch " Michael Haggerty
2015-11-03 7:39 ` [PATCH v6 14/25] refs: move prettify_refname " Michael Haggerty
2015-11-03 7:39 ` [PATCH v6 15/25] refs: move ref iterators " Michael Haggerty
2015-11-03 7:40 ` [PATCH v6 16/25] refs: move head_ref_namespaced " Michael Haggerty
2015-11-03 7:40 ` [PATCH v6 17/25] refs: move transaction functions " Michael Haggerty
2015-11-03 7:40 ` [PATCH v6 18/25] refs: move refname_is_safe " Michael Haggerty
2015-11-03 7:40 ` [PATCH v6 19/25] refs: move copy_msg " Michael Haggerty
2015-11-03 7:40 ` [PATCH v6 20/25] refs: move peel_object " Michael Haggerty
2015-11-03 7:40 ` [PATCH v6 21/25] refs: move should_autocreate_reflog to " Michael Haggerty
2015-11-03 7:40 ` [PATCH v6 22/25] initdb: make safe_create_dir public Michael Haggerty
2015-11-03 7:40 ` [PATCH v6 23/25] files_log_ref_write: new function Michael Haggerty
2015-11-03 7:40 ` [PATCH v6 24/25] refs: create a shared version of verify_refname_available Michael Haggerty
2015-11-03 7:40 ` [PATCH v6 25/25] refs: break out ref conflict checks Michael Haggerty
2015-11-04 21:01 ` David Turner
2015-11-05 4:00 ` Michael Haggerty
2015-11-05 16:22 ` David Turner
2015-11-06 13:34 ` Michael Haggerty
2015-11-06 17:28 ` Junio C Hamano
2015-11-06 23:24 ` Junio C Hamano
2015-11-08 5:03 ` Michael Haggerty
2015-11-08 5:54 ` Michael Haggerty
2015-11-08 18:23 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=563794B1.5000002@alum.mit.edu \
--to=mhagger@alum.mit.edu \
--cc=dturner@twopensource.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).