From: Jeff King <peff@peff.net>
To: Jan Larres <jan@majutsushi.net>
Cc: git@vger.kernel.org
Subject: Re: check-attr doesn't respect recursive definitions
Date: Tue, 2 Apr 2013 10:48:14 -0400 [thread overview]
Message-ID: <20130402144814.GD23828@sigill.intra.peff.net> (raw)
In-Reply-To: <20130402143130.GC23828@sigill.intra.peff.net>
On Tue, Apr 02, 2013 at 10:31:30AM -0400, Jeff King wrote:
> On Sat, Mar 30, 2013 at 09:45:51AM +0000, Jan Larres wrote:
>
> > I am trying to write a custom archiving script that checks the
> > export-ignore attribute to know which files from an ls-files output it
> > should skip. Through this I noticed that for files in directories for
> > which the export-ignore (or any other) attribute is set, check-attr
> > still reports 'unspecified'. More precisely:
> >
> > $ git init test
> > Initialized empty Git repository in /home/jan/test/.git/
> > $ cd test
> > $ mkdir foo
> > $ touch foo/bar
> > $ echo "foo export-ignore" > .gitattributes
> > $ git check-attr export-ignore foo
> > foo: export-ignore: set
> > $ git check-attr export-ignore foo/bar
> > foo/bar: export-ignore: unspecified
> >
> > I would expect the last command to also report 'set'. I've also tried
> > other patterns like 'foo/' and 'foo*', but it didn't make any
> > difference. Is this expected behaviour? It does make checking the
> > attributes of single files somewhat more difficult.
>
> Yes, it is the expected behavior, though I cannot offhand think of
> anything that would break if we did apply it recursively.
Naively, such a patch might look something like this:
diff --git a/attr.c b/attr.c
index de170ff..ac04188 100644
--- a/attr.c
+++ b/attr.c
@@ -791,8 +791,18 @@ static void collect_all_attrs(const char *path)
check_all_attr[i].value = ATTR__UNKNOWN;
rem = attr_nr;
- for (stk = attr_stack; 0 < rem && stk; stk = stk->prev)
+ for (stk = attr_stack; 0 < rem && stk; stk = stk->prev) {
+ last_slash = path;
+ for (cp = path; *cp; cp++) {
+ if (*cp == '/') {
+ rem = fill(path, cp - path + 1,
+ last_slash - path,
+ stk, rem);
+ last_slash = cp;
+ }
+ }
rem = fill(path, pathlen, basename_offset, stk, rem);
+ }
}
int git_check_attr(const char *path, int num, struct git_attr_check *check)
which is based on current "next" (because it has some other related
fixes for handling directories). It seems to work for me, but I suspect
we could do it more optimally. If you have N files in "foo/", this will
check "foo/" against the attribute stack N times, and we should be able
to amortize that work.
Hmm. Actually, thinking on it more, I'm not sure this is even going to
give the right answer anyway, as it will check "foo" against the
"foo/.gitattributes", which is not right. I think we'd need to collect
attributes as we walk the stack in prepare_attr_stack.
So take this as a "this is not how to do it" patch. :)
-Peff
next prev parent reply other threads:[~2013-04-02 14:48 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-30 9:45 check-attr doesn't respect recursive definitions Jan Larres
2013-04-02 14:31 ` Jeff King
2013-04-02 14:48 ` Jeff King [this message]
2013-04-02 16:11 ` Junio C Hamano
2013-04-02 16:30 ` Jeff King
2013-04-02 16:43 ` Junio C Hamano
2013-04-02 16:51 ` Jeff King
2013-04-02 17:15 ` Jeff King
2013-04-02 17:16 ` Junio C Hamano
2013-04-02 19:16 ` Jeff King
2013-04-03 10:05 ` Jan Larres
2013-04-05 2:09 ` Duy Nguyen
2013-04-05 12:04 ` Jan Larres
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=20130402144814.GD23828@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=jan@majutsushi.net \
/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).