From: Junio C Hamano <gitster@pobox.com>
To: Brandon Williams <bmwill@google.com>
Cc: git@vger.kernel.org, sbeller@google.com, pclouds@gmail.com
Subject: Re: [PATCH 1/2] pathspec: allow querying for attributes
Date: Sun, 12 Mar 2017 19:43:41 -0700 [thread overview]
Message-ID: <xmqqo9x5uc9u.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20170309210756.105566-2-bmwill@google.com> (Brandon Williams's message of "Thu, 9 Mar 2017 13:07:55 -0800")
Brandon Williams <bmwill@google.com> writes:
> +struct attr_check *attr_check_dup(const struct attr_check *check)
> +{
> + struct attr_check *ret;
> +
> + if (!check)
> + return NULL;
> +
> + ret = attr_check_alloc();
> +
> + ret->nr = check->nr;
> + ret->alloc = check->alloc;
> + ALLOC_ARRAY(ret->items, ret->nr);
> + COPY_ARRAY(ret->items, check->items, ret->nr);
> +
> + return ret;
> +}
Because an attr_check instance cannot be shared and used by multiple
threads, we expect that the callers that go multi-thread to copy
pathspec to each worker, and preload_index(), which is an existing
example of such a caller, already does so with copy_pathspec().
Makes sense.
> @@ -565,26 +653,47 @@ void parse_pathspec(struct pathspec *pathspec,
>
> void copy_pathspec(struct pathspec *dst, const struct pathspec *src)
> {
> - int i;
> + int i, j;
>
> *dst = *src;
> ALLOC_ARRAY(dst->items, dst->nr);
> COPY_ARRAY(dst->items, src->items, dst->nr);
>
> for (i = 0; i < dst->nr; i++) {
> - dst->items[i].match = xstrdup(src->items[i].match);
> - dst->items[i].original = xstrdup(src->items[i].original);
> + struct pathspec_item *d = &dst->items[i];
> + struct pathspec_item *s = &src->items[i];
> +
> + d->match = xstrdup(s->match);
> + d->original = xstrdup(s->original);
> +
> + ALLOC_ARRAY(d->attr_match, d->attr_match_nr);
> + COPY_ARRAY(d->attr_match, s->attr_match, d->attr_match_nr);
> + for (j = 0; j < d->attr_match_nr; j++) {
> + const char *value = s->attr_match[j].value;
> + if (value)
> + d->attr_match[j].value = xstrdup(value);
We have xstrdup_or_null(), which may help here.
> + }
> +
> + d->attr_check = attr_check_dup(s->attr_check);
> }
> }
>
> void clear_pathspec(struct pathspec *pathspec)
> {
> - int i;
> + int i, j;
>
> for (i = 0; i < pathspec->nr; i++) {
> free(pathspec->items[i].match);
> free(pathspec->items[i].original);
> +
> + for (j = 0; j < pathspec->items[j].attr_match_nr; j++)
> + free(pathspec->items[i].attr_match[j].value);
> + free(pathspec->items[i].attr_match);
> +
> + if (pathspec->items[i].attr_check)
> + attr_check_free(pathspec->items[i].attr_check);
> }
> +
> free(pathspec->items);
> pathspec->items = NULL;
> pathspec->nr = 0;
OK, makes sense.
> diff --git a/t/t6135-pathspec-with-attrs.sh b/t/t6135-pathspec-with-attrs.sh
> new file mode 100755
> index 000000000..b5e5a0607
> --- /dev/null
> +++ b/t/t6135-pathspec-with-attrs.sh
> @@ -0,0 +1,181 @@
> +#!/bin/sh
> +
> +test_description='test labels in pathspecs'
> +. ./test-lib.sh
> +
> +test_expect_success 'setup a tree' '
> + cat <<-EOF >expect &&
Minor style nit. Quote the 'EOF' marker and you signal to readers
that what they'll see are literally the values, and they do not have
to worry about $variable_interpolation. I.e.
cat <<-\EOF >expect &&
> +test_expect_success 'fail if attr magic is used places not implemented' '
> + # The main purpose of this test is to check that we actually fail
> + # when you attempt to use attr magic in commands that do not implement
> + # attr magic. This test does not advocate git-add to stay that way,
> + # though, but git-add is convenient as it has its own internal pathspec
> + # parsing.
That's thought-provoking ;-) Would it help to add a test-pathspec
helper, similar to test-config helper, that serves as a vehicle to
test this?
> + test_must_fail git add ":(attr:labelB)" 2>actual &&
> + test_i18ngrep "unsupported magic" actual
> +'
Thanks.
next prev parent reply other threads:[~2017-03-13 2:43 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-09 21:07 [PATCH 0/2] bringing attributes to pathspecs Brandon Williams
2017-03-09 21:07 ` [PATCH 1/2] pathspec: allow querying for attributes Brandon Williams
2017-03-09 22:19 ` Jonathan Tan
2017-03-10 18:26 ` Brandon Williams
2017-03-13 2:43 ` Junio C Hamano [this message]
2017-03-13 18:30 ` Stefan Beller
2017-03-09 21:07 ` [PATCH 2/2] pathspec: allow escaped query values Brandon Williams
2017-03-09 22:31 ` Jonathan Tan
2017-03-10 18:53 ` Brandon Williams
2017-03-09 21:22 ` [PATCH 0/2] bringing attributes to pathspecs Stefan Beller
2017-03-10 18:59 ` [PATCH v2 " Brandon Williams
2017-03-10 18:59 ` [PATCH v2 1/2] pathspec: allow querying for attributes Brandon Williams
2017-03-10 19:56 ` Jonathan Tan
2017-03-11 0:28 ` Brandon Williams
2017-03-10 18:59 ` [PATCH v2 2/2] pathspec: allow escaped query values Brandon Williams
2017-03-13 18:23 ` [PATCH v3 0/2] bringing attributes to pathspecs Brandon Williams
2017-03-13 18:23 ` [PATCH v3 1/2] pathspec: allow querying for attributes Brandon Williams
2017-03-13 18:23 ` [PATCH v3 2/2] pathspec: allow escaped query values Brandon Williams
2017-03-13 22:30 ` [PATCH v3 0/2] bringing attributes to pathspecs Junio C Hamano
2017-03-13 22:38 ` Brandon Williams
2017-03-21 10:51 ` Duy Nguyen
2017-03-21 15:51 ` Junio C Hamano
2017-03-21 16:52 ` Brandon Williams
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqo9x5uc9u.fsf@gitster.mtv.corp.google.com \
--to=gitster@pobox.com \
--cc=bmwill@google.com \
--cc=git@vger.kernel.org \
--cc=pclouds@gmail.com \
--cc=sbeller@google.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).