From: Stefan Beller <sbeller@google.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Duy Nguyen <pclouds@gmail.com>,
"git@vger.kernel.org" <git@vger.kernel.org>,
Jonathan Nieder <jrnieder@gmail.com>,
Jens Lehmann <Jens.Lehmann@web.de>
Subject: Re: [PATCH 4/4] pathspec: record labels
Date: Thu, 12 May 2016 22:41:13 -0700 [thread overview]
Message-ID: <CAGZ79kbaqw9UvYrCWcLtAXaiw5-aSev9gn858zz5Ju0MVfzepQ@mail.gmail.com> (raw)
In-Reply-To: <xmqqy47ea5ql.fsf@gitster.mtv.corp.google.com>
On Thu, May 12, 2016 at 10:26 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Stefan Beller <sbeller@google.com> writes:
>
>> +
>> +label:<white space separated list>;;
>> + Labels can be assigned to pathspecs in the .gitattributes file.
>> + By specifying a list of labels the pattern will match only
>> + files which have all of the listed labels.
>> +
>
> Attributes are given to paths, not pathspecs. You specify which paths
> the entry applies to by matching the pattern (which is at the beginning
> of the line) against each path, and take the matching entries.
>
> In any case, what the first sentence tries to explain applies to
> each and every attribute .gitattributes file can define, and
> explaining it should be better left for the first sentence in the
> DESCRIPTION section.
>
> As to the second sentence, I would say "When specifying the paths to
> work on to various Git commands, the :(label=<label>,...) magic
> pathspec can be used to select paths that have all the labels given
> by the 'label' attribute.", or something like that, to clarify where
> that "specifying" and "match" happens (they do not happen here, but
> happen when using magic pathspec).
Reminder for myself: add a test for
":(label=a) :(exclude,label=b)"
>
>> +void load_labels(const char *name, int namelen, struct string_list *list)
>
> This must be file scope static, no?
Yes. It seems like I forget these statics often. :(
>
>> +{
>> + static struct git_attr *attr;
>> + struct git_attr_check check;
>> + char *path = xmemdupz(name, namelen);
>> +
>> + if (!attr)
>> + attr = git_attr("label");
>> + check.attr = attr;
>> +
>> + if (git_check_attr(path, 1, &check))
>> + die("git_check_attr died");
>> +
>> + if (ATTR_CUSTOM(check.value)) {
>> + string_list_split(list, check.value, ',', -1);
>> + string_list_sort(list);
>> + }
>> +
>> + free(path);
>> +}
>
> I am wondering where we should sanity check (and die, pointing out
> an error in .gitattributes file). Is this function a good place to
> reject TRUE and FALSE?
Would it make sense to mark a file as
"follows the labeling system, but has no label" (TRUE)
"doesn't follow the labeling system at all" (FALSE)
This may be a useful addition later on to say
"I want to talk only about labeled files, but not label 'a'"
I would think.
>
> By the way, ATTR_CUSTOM() is probably a bad name. gitattributes.txt
> calls them Set, Unset, Set to a value and Unspecified, and this is
> trying to single out "Set to a value" case. ATTR_STRING() may be
> more appropriate.
Ok.
>
>> @@ -263,6 +285,15 @@ static int match_pathspec_item(const struct pathspec_item *item, int prefix,
>> strncmp(item->match, name - prefix, item->prefix))
>> return 0;
>>
>> + if (item->group) {
>> + struct string_list has_labels = STRING_LIST_INIT_DUP;
>> + struct string_list_item *si;
>> + load_labels(name, namelen, &has_labels);
>> + for_each_string_list_item(si, item->group)
>> + if (!string_list_has_string(&has_labels, si->string))
>> + return 0;
>> + }
>> +
>
> Is this the right place, before we even check if the prefix already
> covered everything?
>
> We are looking at one element in the pathspec here. If that element
> is known to be a "group", and the path has all the required labels,
> is it correct to fall through?
>
> Ahh, you are making ":(label=...)makefile" to say "paths must
> match the string 'makefile' in some way, and further the paths
> must have all these labels? Then falling through is correct.
This is how I understood your initial design idea.
:(label=C_code)contrib/
gives all the retired C programs.
> The placement before the "prefix covered" looks still a bit
> strange, but understandable.
>
> Is this code leaking has_labels every time it is called?
It does.
>
> By the way, we should pick one between label and group and stick to
> it, no? Perhaps call the new field "item->label"?
will do.
>
>> /* If the match was just the prefix, we matched */
>> if (!*match)
>> return MATCHED_RECURSIVELY;
>> diff --git a/pathspec.c b/pathspec.c
>> index 4dff252..c227c25 100644
>> --- a/pathspec.c
>> +++ b/pathspec.c
>> @@ -94,6 +94,7 @@ static void eat_long_magic(struct pathspec_item *item, const char *elt,
>> {
>> int i;
>> const char *copyfrom = *copyfrom_;
>> + const char *out;
>
> It probably is meant as "output", but it looks more like the "body" or
> the "contents" of the named magic to me.
ok.
>
>> /* longhand */
>> const char *nextat;
>> for (copyfrom = elt + 2;
>> @@ -117,6 +118,20 @@ static void eat_long_magic(struct pathspec_item *item, const char *elt,
>> continue;
>> }
>>
>> + if (skip_prefix(copyfrom, "label:", &out)) {
>
> This is good, but can you fix the "prefix:" one we see a few lines
> above, too, using this to lose "copyfrom + 7" there?
I can do that. Though I did not want to clutter this patch with it.
I wonder that you focus on the details already, but not on the grand
design of things. "Is it actually a sane thing I am proposing here?"
Though you may be biased as the the high level idea came from
you. :)
One of the things I switched last minute and tried to address in the
cover letter is the semantics of ORing or ANDing the labels given
within one pathspec item.
Thanks,
Stefan
next prev parent reply other threads:[~2016-05-13 5:41 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-13 0:19 [RFC PATCH 0/4] pathspec labels [WAS: submodule groups] Stefan Beller
2016-05-13 0:19 ` [PATCH 1/4] Documentation: correct typo in example for querying attributes Stefan Beller
2016-05-13 0:19 ` [PATCH 2/4] pathspec: move long magic parsing out of prefix_pathspec Stefan Beller
2016-05-13 0:19 ` [PATCH 3/4] pathspec: move prefix check out of the inner loop Stefan Beller
2016-05-13 4:43 ` Junio C Hamano
2016-05-13 0:19 ` [PATCH 4/4] pathspec: record labels Stefan Beller
2016-05-13 4:32 ` Junio C Hamano
2016-05-13 5:26 ` Stefan Beller
2016-05-13 5:26 ` Junio C Hamano
2016-05-13 5:41 ` Stefan Beller [this message]
2016-05-13 6:28 ` Junio C Hamano
2016-05-15 10:06 ` [RFC PATCH 0/4] pathspec labels [WAS: submodule groups] Duy Nguyen
2016-05-15 18:19 ` Junio C Hamano
2016-05-15 19:33 ` Junio C Hamano
2016-05-16 0:03 ` Duy Nguyen
2016-05-16 17:20 ` Stefan Beller
2016-05-16 17:39 ` Junio C Hamano
2016-05-16 17:48 ` Stefan Beller
2016-05-16 21:18 ` Junio C Hamano
2016-05-16 21:36 ` Stefan Beller
2016-05-16 21:50 ` Junio C Hamano
2016-05-16 22:00 ` Stefan Beller
2016-05-16 22:02 ` Junio C Hamano
2016-05-16 22:09 ` Stefan Beller
2016-05-16 22:19 ` 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=CAGZ79kbaqw9UvYrCWcLtAXaiw5-aSev9gn858zz5Ju0MVfzepQ@mail.gmail.com \
--to=sbeller@google.com \
--cc=Jens.Lehmann@web.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
--cc=pclouds@gmail.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).