RFC: two minor tweaks to check-ignore to help git-annex assistant
Hi all,
I was recently informed by the author of git-annex that my implementation of git check-ignore has two minor deficiencies which currently prevent him from adding .gitignore support to the git-annex assistant (web UI):
1. When accepting a list of files to check via --stdin, no results are calculated until EOF is hit. This prevents it being used as a persistent background query process which streams results to its caller. (This is inconsistent with check-attr, which *does* support stream-like behaviour.)
2. Even if it did support streaming, the lack of output for files which don't match any ignore pattern make it impossible for the consumer to distinguish between the two cases a) the file doesn't match any pattern and b) it does match but the output hasn't arrived yet.
Both of these are pretty trivial to fix. The first is fixed by changing check_ignore_stdin_paths() to invoke check_ignore() per input line, rather than collecting all input from STDIN and then invoking check_ignore() on the whole lot. (I have not implemented this yet, but may well be able to do it this week, thanks to it being one of SUSE's hack weeks :-)
I already have a rough fix for the second issue, but I wanted to solicit feedback on the appropriate UI changes before proceeding much further. Does something like the below patch seem reasonable, modulo the lack of tests? In case the UI changes I am proposing are not clear from the patch, here's some example output from running it inside a clone of the git source tree:
$ git check-ignore -v -n foo.tar.{gz,bz2}
.gitignore:203:*.tar.gz foo.tar.gz
:: foo.tar.bz2So the number of output fields does not change depending on whether the pattern matches or not, and any caller can determine whether it does simply by checking whether the first field is non-empty.
Also, does it make sense to write a new test to accompany the fix to the first (streaming) issue?
Thanks,
Adam
-- >8 --
Subject: [PATCH] check-ignore: add -n / --non-matching option
If -n or --non-matching are specified, non-matching pathnames will also be output, in which case all fields in each output record except for <pathname> will be empty. This can be useful when running non-interactively, so that files can be incrementally streamed to STDIN of a long-running check-ignore process, and for each of these files, STDOUT will indicate whether that file matched a pattern or not. (Without this option, it would be impossible to tell whether the absence of output for a given file meant that it didn't match any pattern, or that the output hadn't been generated yet.)
--- Documentation/git-check-ignore.txt | 15 +++++++++++++ builtin/check-ignore.c | 43 ++++++++++++++++++++++++-------------- 2 files changed, 42 insertions(+), 16 deletions(-)
Documentation/git-check-ignore.txt +15 -0
@@ -39,6 +39,12 @@ OPTIONS below). If `--stdin` is also given, input paths are separated with a NUL character instead of a linefeed character. +-n, --non-matching:: + Show given paths which don't match any pattern. This only + makes sense when `--verbose` is enabled, otherwise it would + not be possible to distinguish between paths which match a + pattern and those which don't. + OUTPUT ------
@@ -65,6 +71,15 @@ are also used instead of colons and hard tabs: <source> <NULL> <linenum> <NULL> <pattern> <NULL> <pathname> <NULL> +If `-n` or `--non-matching` are specified, non-matching pathnames will +also be output, in which case all fields in each output record except +for <pathname> will be empty. This can be useful when running +non-interactively, so that files can be incrementally streamed to +STDIN of a long-running check-ignore process, and for each of these +files, STDOUT will indicate whether that file matched a pattern or +not. (Without this option, it would be impossible to tell whether the +absence of output for a given file meant that it didn't match any +pattern, or that the output hadn't been generated yet.) EXIT STATUS -----------
builtin/check-ignore.c +27 -16
83 lines not on this page · raw message
Signature · 1 line
1.8.2.242.g8617715.dirty
Quoted 10 lines · Adam Spiers
I was recently informed by the author of git-annex that my implementation of git check-ignore has two minor deficiencies which currently prevent him from adding .gitignore support to the git-annex assistant (web UI):
1. When accepting a list of files to check via --stdin, no results are calculated until EOF is hit. This prevents it being used as a persistent background query process which streams results to its caller. (This is inconsistent with check-attr, which *does* support stream-like behaviour.)
I think flushing on each line is reasonable, though you are also introducing a deadlock possibility for callers which do not read back the output in real-time. For example, if I write N paths out then read N ignore-lines back in, I risk a situation where I am blocked on write() to check-ignore, and it is blocked on write back to me. Somebody has to buffer (the pipe buffers give you some leeway, but they are limited).
Given how new check-ignore is, and that we have not advertised any particular buffering scheme so far, it's probably OK to switch without worrying about breaking existing callers.
But if this is a mode of operation that we expect people to use (here and for check-attr), we should advertise the flushing behavior, and probably warn about the deadlock (I don't think adding a "--no-flush" option is worth it, as it would just mean buffering in check-ignore, which the caller could just as easily do itself).
-Peff
Quoted 7 lines · Adam Spiers
I already have a rough fix for the second issue, but I wanted to solicit feedback on the appropriate UI changes before proceeding much further. Does something like the below patch seem reasonable, modulo the lack of tests? In case the UI changes I am proposing are not clear from the patch, here's some example output from running it inside a clone of the git source tree:
Quoted 7 lines
$ git check-ignore -v -n foo.tar.{gz,bz2} .gitignore:203:*.tar.gz foo.tar.gz :: foo.tar.bz2So the number of output fields does not change depending on whether the pattern matches or not, and any caller can determine whether it does simply by checking whether the first field is non-empty.
Haven't looked at the proposed patch very carefully, but the design looks sound. The above output screams "empty! nothing!", and I do not think there is any other way :: will show up in that position.
Quoted 2 lines
Also, does it make sense to write a new test to accompany the fix to the first (streaming) issue?
Would it be tricky to write safely not to get stuck? You feed one line, stop feeding, while checking that the output has arrived, and then kill the whole thing? Feels somewhat yucky, but sounds doable.
PATCH 1/5 check-ignore: move setup into cmd_check_ignore()
In reply to Adam SpiersInitialisation of the dir_struct and path_exclude_check structs was previously done within check_ignore(). This was acceptable since check_ignore() was only called once per check-ignore invocation; however the next commit will convert it into an inner loop which is called once per line of STDIN when --stdin is given. Therefore moving the initialisation code out into cmd_check_ignore() ensures that initialisation is still only performed once per check-ignore invocation, and consequently that the output is identical whether pathspecs are provided as CLI arguments or via STDIN.
--- builtin/check-ignore.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-)
builtin/check-ignore.c +20 -19
@@ -53,30 +53,20 @@ static void output_exclude(const char *path, struct exclude *exclude) } } -static int check_ignore (const char *prefix,const char **pathspec) +static int check_ignore (struct path_exclude_check check, +const char *prefix,const char **pathspec) { -struct dir_struct dir;const char *path, *full_path;char *seen;int num_ignored =0 , dtype =DT_UNKNOWN , i; -struct path_exclude_check check;struct exclude *exclude; -/* read_cache() is only necessary so we can watch out for submodules. */ -if (read_cache () <0 ) -die (_ ("index file corrupt" )); - -memset (&dir,0 ,sizeof (dir)); - dir.flags |=DIR_COLLECT_IGNORED ; -setup_standard_excludes (&dir); -if (!pathspec || !*pathspec) {if (!quiet)fprintf (stderr,"no pathspec given.\n" );return 0 ; } -path_exclude_check_init (&check, &dir);/* * look for pathspecs matching entries in the index, since these * should not be ignored, in order to be consistent with
@@ -100,13 +90,11 @@ static int check_ignore(const char *prefix, const char **pathspec) } }free (seen); -clear_directory (&dir); -path_exclude_check_clear (&check);return num_ignored; } -static int check_ignore_stdin_paths (const char *prefix) +static int check_ignore_stdin_paths (struct path_exclude_check check,const char *prefix) {struct strbuf buf, nbuf;char **pathspec =NULL ;
@@ -129,17 +117,18 @@ static int check_ignore_stdin_paths(const char *prefix) }ALLOC_GROW (pathspec, nr +1 , alloc); pathspec[nr] =NULL ; - num_ignored =check_ignore (prefix, (const char **)pathspec); + num_ignored =check_ignore (check, prefix, (const char **)pathspec);maybe_flush_or_die (stdout,"attribute to stdout" );strbuf_release (&buf);strbuf_release (&nbuf); -free (pathspec);return num_ignored; }int cmd_check_ignore (int argc,const char **argv,const char *prefix) {int num_ignored; +struct dir_struct dir; +struct path_exclude_check check;git_config (git_default_config,NULL );
@@ -162,12 +151,24 @@ int cmd_check_ignore(int argc, const char **argv, const char *prefix)die (_ ("cannot have both --quiet and --verbose" )); } +/* read_cache() is only necessary so we can watch out for submodules. */ +if (read_cache () <0 ) +die (_ ("index file corrupt" )); + +memset (&dir,0 ,sizeof (dir)); + dir.flags |=DIR_COLLECT_IGNORED ; +setup_standard_excludes (&dir); + +path_exclude_check_init (&check, &dir);if (stdin_paths) { - num_ignored =check_ignore_stdin_paths (prefix); + num_ignored =check_ignore_stdin_paths (check, prefix); }else { - num_ignored =check_ignore (prefix, argv); + num_ignored =check_ignore (check, prefix, argv);maybe_flush_or_die (stdout,"ignore to stdout" ); } +clear_directory (&dir); +path_exclude_check_clear (&check); +return !num_ignored; }
Signature · 1 line
1.8.2.1.347.g37e0606
PATCH 2/5 check-ignore: allow incremental streaming of queries via --stdin
Some callers, such as the git-annex web assistant, find it useful to invoke git check-ignore as a persistent background process, which can then have queries fed to its STDIN at any point, and the corresponding response consumed from its STDOUT. For this we need to invoke check_ignore() once per line of standard input, and flush standard output after each result.
The above use case suggests that empty STDIN is actually a reasonable scenario (e.g. when the caller doesn't know in advance whether any queries need to be fed to the background process until after it's already started), so we make the minor behavioural change that "no pathspec given." is no longer emitted in when STDIN is empty.
Even though check_ignore() could now be changed to operate on a single pathspec, we keep it operating on an array of pathspecs since that is a more convenient way of consuming the existing pathspec API.
--- builtin/check-ignore.c | 16 ++++++---------- t/t0008-ignores.sh | 29 ++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 15 deletions(-)
builtin/check-ignore.c +6 -10
@@ -97,10 +97,9 @@ static int check_ignore(struct path_exclude_check check,static int check_ignore_stdin_paths (struct path_exclude_check check,const char *prefix) {struct strbuf buf, nbuf; -char **pathspec =NULL ; -size_t nr =0 , alloc =0 ; +char *pathspec[2 ] = {NULL ,NULL };int line_termination = null_term_line ?0 :'\n' ; -int num_ignored; +int num_ignored =0 ;strbuf_init (&buf,0 );strbuf_init (&nbuf,0 );
@@ -111,14 +110,11 @@ static int check_ignore_stdin_paths(struct path_exclude_check check, const chardie ("line is badly quoted" );strbuf_swap (&buf, &nbuf); } -ALLOC_GROW (pathspec, nr +1 , alloc); - pathspec[nr] =xcalloc (strlen (buf.buf) +1 ,sizeof (*buf.buf)); -strcpy (pathspec[nr++], buf.buf); + pathspec[0 ] =xcalloc (strlen (buf.buf) +1 ,sizeof (*buf.buf)); +strcpy (pathspec[0 ], buf.buf); + num_ignored +=check_ignore (check, prefix, (const char **)pathspec); +maybe_flush_or_die (stdout,"check-ignore to stdout" ); } -ALLOC_GROW (pathspec, nr +1 , alloc); - pathspec[nr] =NULL ; - num_ignored =check_ignore (check, prefix, (const char **)pathspec); -maybe_flush_or_die (stdout,"attribute to stdout" );strbuf_release (&buf);strbuf_release (&nbuf);return num_ignored;
t/t0008-ignores.sh +24 -5
@@ -189,11 +189,7 @@ test_expect_success_multi 'empty command line' '' ' test_expect_success_multi '--stdin with empty STDIN' '' ' test_check_ignore "--stdin" 1 </dev/null && - if test -n "$quiet_opt"; then - test_stderr "" - else - test_stderr "no pathspec given." - fi + test_stderr "" ' test_expect_success '-q with multiple args' '
@@ -648,5 +644,28 @@ do ' done +test_expect_success 'setup: have stdbuf?' ' + if which stdbuf >/dev/null 2>&1 + then + test_set_prereq STDBUF + fi +' + +test_expect_success STDBUF 'streaming support for --stdin' ' + ( + echo one + sleep 2 + echo two + ) | stdbuf -oL git check-ignore -v -n --stdin >out & + pid=$! && + sleep 1 && + cat out && + grep "^\.gitignore:1:one one" out && + test $( wc -l <out ) = 1 && + sleep 2 && + grep "^:: two" out && + test $( wc -l <out ) = 2 && + ( wait $pid || kill $pid || : ) 2>/dev/null +' test_done
Signature · 1 line
1.8.2.1.347.g37e0606
Re: [PATCH 2/5] check-ignore: allow incremental streaming of queries via --stdin
builtin/check-ignore.c static int check_ignore_stdin_paths(struct path_exclude_check check, const char · line 116
Quoted 11 lines · Adam Spiers
builtin/check-ignore.c +4
-3@@ -111,14 +110,11 @@ static int check_ignore_stdin_paths(struct path_exclude_check check, const chardie ("line is badly quoted" );strbuf_swap (&buf, &nbuf); } -ALLOC_GROW (pathspec, nr +1 , alloc); - pathspec[nr] =xcalloc (strlen (buf.buf) +1 ,sizeof (*buf.buf)); -strcpy (pathspec[nr++], buf.buf); + pathspec[0 ] =xcalloc (strlen (buf.buf) +1 ,sizeof (*buf.buf)); +strcpy (pathspec[0 ], buf.buf); + num_ignored +=check_ignore (check, prefix, (const char **)pathspec); +maybe_flush_or_die (stdout,"check-ignore to stdout" );
Now that you are not storing the whole pathspec at once, the pathspec buffer only needs to be valid for the length of check_ignore, right? That means you can drop this extra copy and just pass in buf.buf:
pathspec[0] = buf.buf; num_ignored += check_ignore(check, prefix, pathspec);
t/t0008-ignores.sh do · line 652
Quoted 6 lines
t/t0008-ignores.sh +6
-0+test_expect_success 'setup: have stdbuf?' ' + if which stdbuf >/dev/null 2>&1 + then + test_set_prereq STDBUF + fi +'
Hmm. Today I learned about stdbuf. :)
-Peff
Re: [PATCH 2/5] check-ignore: allow incremental streaming of queries via --stdin
Quoted 18 lines · Jeff King
builtin/check-ignore.c static int check_ignore_stdin_paths(struct path_exclude_check check, const char · line 116
Quoted 11 lines · Adam Spiers
builtin/check-ignore.c +4
-3@@ -111,14 +110,11 @@ static int check_ignore_stdin_paths(struct path_exclude_check check, const chardie ("line is badly quoted" );strbuf_swap (&buf, &nbuf); } -ALLOC_GROW (pathspec, nr +1 , alloc); - pathspec[nr] =xcalloc (strlen (buf.buf) +1 ,sizeof (*buf.buf)); -strcpy (pathspec[nr++], buf.buf); + pathspec[0 ] =xcalloc (strlen (buf.buf) +1 ,sizeof (*buf.buf)); +strcpy (pathspec[0 ], buf.buf); + num_ignored +=check_ignore (check, prefix, (const char **)pathspec); +maybe_flush_or_die (stdout,"check-ignore to stdout" );Now that you are not storing the whole pathspec at once, the pathspec buffer only needs to be valid for the length of
check_ignore, right? That means you can drop this extra copy and just pass in buf.buf:
Quoted 2 lines
pathspec[0] = buf.buf; num_ignored += check_ignore(check, prefix, pathspec);
Oops, good point - thanks. I've made that change.
Quoted 8 lines
t/t0008-ignores.sh do · line 652
Quoted 6 lines
t/t0008-ignores.sh +6
-0+test_expect_success 'setup: have stdbuf?' ' + if which stdbuf >/dev/null 2>&1 + then + test_set_prereq STDBUF + fi +'Hmm. Today I learned about stdbuf. :)
Yeah, it's a relatively recent addition to coreutils.
Re: [PATCH 2/5] check-ignore: allow incremental streaming of queries via --stdin
In reply to Adam Spierst/t0008-ignores.sh do · line 659
Quoted 6 lines · Adam Spiers
t/t0008-ignores.sh +6
-0+test_expect_success STDBUF 'streaming support for --stdin' ' + ( + echo one + sleep 2 + echo two + ) | stdbuf -oL git check-ignore -v -n --stdin >out &
I just noticed that this patch precedes the one in the same series which adds -n support. I'll reorder them accordingly to avoid breaking git bisect.
Re: [PATCH 2/5] check-ignore: allow incremental streaming of queries via --stdin
Quoted 11 lines · Adam Spiers
t/t0008-ignores.sh do · line 659
Quoted 6 lines · Adam Spiers
t/t0008-ignores.sh +6
-0+test_expect_success STDBUF 'streaming support for --stdin' ' + ( + echo one + sleep 2 + echo two + ) | stdbuf -oL git check-ignore -v -n --stdin >out &I just noticed that this patch precedes the one in the same series which adds -n support. I'll reorder them accordingly to avoid breaking git bisect.
Thanks for noticing. FWIW, I often do this:
GIT_EDITOR='sed -i "/^pick /aexec make test" \ git rebase -i origin/master
on my topics to make sure each commit compiles and passes the tests in isolation (it will stop on a failure, at which point you can fix up and "git rebase --continue").
It's somewhat annoying, because it runs the whole test suite, even for commits that are obviously not going to have an impact (e.g., doc updates, or change to a single test). But it has saved me from embarrassment many times, when I thought for sure that my commits were obviously correct. :)
-Peff
PATCH 3/5 Documentation: add caveats about I/O buffering for check-{attr,ignore}
In reply to Adam Spierscheck-attr and check-ignore have the potential to deadlock callers which do not read back the output in real-time. For example, if a caller writes N paths out and then reads N lines back in, it risks becoming blocked on write() to check-*, and check-* is blocked on write back to the caller. Somebody has to buffer; the pipe buffers provide some leeway, but they are limited.
Thanks to Peff for pointing this out:
http://article.gmane.org/gmane.comp.version-control.git/220534
--- Documentation/git-check-attr.txt | 5 +++++ Documentation/git-check-ignore.txt | 5 +++++ Documentation/git.txt | 16 +++++++++------- 3 files changed, 19 insertions(+), 7 deletions(-)
Documentation/git-check-attr.txt +5 -0
@@ -56,6 +56,11 @@ being queried and <info> can be either: 'set';; when the attribute is defined as true. <value>;; when a value has been assigned to the attribute. +Buffering happens as documented under the `GIT_FLUSH` option in +linkgit:git[1]. The caller is responsible for avoiding deadlocks +caused by overfilling an input buffer or reading from an empty output +buffer. + EXAMPLES --------
Documentation/git-check-ignore.txt +5 -0
@@ -66,6 +66,11 @@ are also used instead of colons and hard tabs: <source> <NULL> <linenum> <NULL> <pattern> <NULL> <pathname> <NULL> +Buffering happens as documented under the `GIT_FLUSH` option in +linkgit:git[1]. The caller is responsible for avoiding deadlocks +caused by overfilling an input buffer or reading from an empty output +buffer. + EXIT STATUS -----------
Documentation/git.txt +9 -7
@@ -808,13 +808,15 @@ for further details. 'GIT_FLUSH':: If this environment variable is set to "1", then commands such - as 'git blame' (in incremental mode), 'git rev-list', 'git log', - and 'git whatchanged' will force a flush of the output stream - after each commit-oriented record have been flushed. If this - variable is set to "0", the output of these commands will be done - using completely buffered I/O. If this environment variable is - not set, Git will choose buffered or record-oriented flushing - based on whether stdout appears to be redirected to a file or not. + as 'git blame' (in incremental mode), 'git rev-list', 'git + log', 'git check-attr', 'git check-ignore', and 'git + whatchanged' will force a flush of the output stream after + each commit-oriented record have been flushed. If this + variable is set to "0", the output of these commands will be + done using completely buffered I/O. If this environment + variable is not set, Git will choose buffered or + record-oriented flushing based on whether stdout appears to be + redirected to a file or not. 'GIT_TRACE':: If this variable is set to "1", "2" or "true" (comparison
Signature · 1 line
1.8.2.1.347.g37e0606
Re: [PATCH 3/5] Documentation: add caveats about I/O buffering for check-{attr,ignore}
Quoted 7 lines · Adam Spiers
check-attr and check-ignore have the potential to deadlock callers which do not read back the output in real-time. For example, if a caller writes N paths out and then reads N lines back in, it risks becoming blocked on
write()to check-*, and check-* is blocked on write back to the caller. Somebody has to buffer; the pipe buffers provide some leeway, but they are limited.
Quoted 5 lines
Thanks to Peff for pointing this out:
http://article.gmane.org/gmane.comp.version-control.git/220534Signed-off-by Adam Spiers <[email protected]>
Thanks, I think the documentation changes look sane.
-Peff
PATCH 4/5 t0008: remove duplicated test fixture data
In reply to Adam SpiersThe expected contents of STDOUT for the final --stdin tests can be derived from the expected contents of STDOUT for the same tests when --verbose is given, in the same way that test_expect_success_multi derives this for earlier tests.
--- t/t0008-ignores.sh | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-)
t/t0008-ignores.sh +1 -15
@@ -571,21 +571,6 @@ cat <<-\EOF >stdin b/globaltwo ../b/globaltwo EOF -cat <<-\EOF >expected-default - ../one - one - b/on - b/one - b/one one - b/one two - "b/one\"three" - b/two - b/twooo - ../globaltwo - globaltwo - b/globaltwo - ../b/globaltwo -EOF cat <<-EOF >expected-verbose .gitignore:1:one ../one .gitignore:1:one one
@@ -601,6 +586,7 @@ cat <<-EOF >expected-verbose $global_excludes:2:!globaltwo b/globaltwo $global_excludes:2:!globaltwo ../b/globaltwo EOF +sed -e 's/.* //' expected-verbose >expected-default sed -e 's/^"//' -e 's/\\//' -e 's/"$//' stdin | \ tr "\n" "\0" >stdin0
Signature · 1 line
1.8.2.1.347.g37e0606
PATCH 5/5 check-ignore: add -n / --non-matching option
In reply to Adam SpiersIf -n or --non-matching are specified, non-matching pathnames will also be output, in which case all fields in each output record except for <pathname> will be empty. This can be useful when running check-ignore as a background process, so that files can be incrementally streamed to STDIN, and for each of these files, STDOUT will indicate whether that file matched a pattern or not. (Without this option, it would be impossible to tell whether the absence of output for a given file meant that it didn't match any pattern, or that the result simply hadn't been flushed to STDOUT yet.)
--- Documentation/git-check-ignore.txt | 15 +++++ builtin/check-ignore.c | 46 ++++++++------ t/t0008-ignores.sh | 122 +++++++++++++++++++++++++++---------- 3 files changed, 134 insertions(+), 49 deletions(-)
Documentation/git-check-ignore.txt +15 -0
@@ -39,6 +39,12 @@ OPTIONS below). If `--stdin` is also given, input paths are separated with a NUL character instead of a linefeed character. +-n, --non-matching:: + Show given paths which don't match any pattern. This only + makes sense when `--verbose` is enabled, otherwise it would + not be possible to distinguish between paths which match a + pattern and those which don't. + OUTPUT ------
@@ -65,6 +71,15 @@ are also used instead of colons and hard tabs: <source> <NULL> <linenum> <NULL> <pattern> <NULL> <pathname> <NULL> +If `-n` or `--non-matching` are specified, non-matching pathnames will +also be output, in which case all fields in each output record except +for <pathname> will be empty. This can be useful when running +non-interactively, so that files can be incrementally streamed to +STDIN of a long-running check-ignore process, and for each of these +files, STDOUT will indicate whether that file matched a pattern or +not. (Without this option, it would be impossible to tell whether the +absence of output for a given file meant that it didn't match any +pattern, or that the output hadn't been generated yet.) Buffering happens as documented under the `GIT_FLUSH` option in linkgit:git[1]. The caller is responsible for avoiding deadlocks
builtin/check-ignore.c +29 -17
89 lines not on this page · raw message
t/t0008-ignores.sh +90 -32
213 lines not on this page · raw message
Signature · 1 line
1.8.2.1.347.g37e0606
Re: [PATCH 1/5] check-ignore: move setup into cmd_check_ignore()
In reply to Adam SpiersQuoted 20 lines · Adam Spiers
Initialisation of the
dir_structandpath_exclude_checkstructs was previously done withincheck_ignore(). This was acceptable sincecheck_ignore()was only called once per check-ignore invocation; however the next commit will convert it into an inner loop which is called once per line of STDIN when --stdin is given. Therefore moving the initialisation code out intocmd_check_ignore()ensures that initialisation is still only performed once per check-ignore invocation, and consequently that the output is identical whether pathspecs are provided as CLI arguments or via STDIN.Signed-off-by Adam Spiers <[email protected]>--- builtin/check-ignore.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-)builtin/check-ignore.c +0
-0
builtin/check-ignore.c static void output_exclude(const char *path, struct exclude *exclude) · line 57
Quoted 6 lines
builtin/check-ignore.c +2
-1@@ -53,30 +53,20 @@ static void output_exclude(const char *path, struct exclude *exclude) } } -static int check_ignore (const char *prefix,const char **pathspec) +static int check_ignore (struct path_exclude_check check, +const char *prefix,const char **pathspec)
Did you mean to pass the struct by value here? If it is truly a per-path value, shouldn't it be declared and initialized inside here? Otherwise you risk one invocation munging things that the struct points to, but the caller's copy does not know about the change.
In particular, I see that the struct includes a strbuf. What happens when one invocation of check_ignore grows the strbuf, then returns? The copy of the struct in the caller will not know that the buffer it is pointing to is now bogus.
builtin/check-ignore.c static int check_ignore(const char *prefix, const char **pathspec) · line 97
Quoted 2 lines
builtin/check-ignore.c +1
-1-static int check_ignore_stdin_paths (const char *prefix) +static int check_ignore_stdin_paths (struct path_exclude_check check,const char *prefix)
Ditto here.
-Peff
Re: [PATCH 1/5] check-ignore: move setup into cmd_check_ignore()
Quoted 15 lines · Jeff King
builtin/check-ignore.c static void output_exclude(const char *path, struct exclude *exclude) · line 57
Quoted 3 lines · Adam Spiers
builtin/check-ignore.c +2
-1-static int check_ignore (const char *prefix,const char **pathspec) +static int check_ignore (struct path_exclude_check check, +const char *prefix,const char **pathspec)Did you mean to pass the struct by value here? If it is truly a per-path value, shouldn't it be declared and initialized inside here? Otherwise you risk one invocation munging things that the struct points to, but the caller's copy does not know about the change.
In particular, I see that the struct includes a strbuf. What happens when one invocation of
check_ignoregrows the strbuf, then returns? The copy of the struct in the caller will not know that the buffer it is pointing to is now bogus.
Quoted 4 lines
builtin/check-ignore.c static int check_ignore(const char *prefix, const char **pathspec) · line 97
Quoted 2 lines
builtin/check-ignore.c +1
-1-static int check_ignore_stdin_paths (const char *prefix) +static int check_ignore_stdin_paths (struct path_exclude_check check,const char *prefix)Ditto here.
It's not a per-path value; it's supposed to be reused across checks for multiple paths, as explained in the comments above last_exclude_matching_path():
...
* A path to a directory known to be excluded is left in check->path to
* optimize for repeated checks for files in the same excluded directory. */
struct exclude *last_exclude_matching_path(struct path_exclude_check *check,
...
So I think you're probably right that there is potential for check->path to become effectively corrupted due to the caller not seeing the reallocation. I'll change this too.
PATCH v2 1/5 t0008: remove duplicated test fixture data
The expected contents of STDOUT for the final --stdin tests can be derived from the expected contents of STDOUT for the same tests when --verbose is given, in the same way that test_expect_success_multi derives this for earlier tests.
--- t/t0008-ignores.sh | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-)
t/t0008-ignores.sh +1 -15
@@ -575,21 +575,6 @@ cat <<-\EOF >stdin b/globaltwo ../b/globaltwo EOF -cat <<-\EOF >expected-default - ../one - one - b/on - b/one - b/one one - b/one two - "b/one\"three" - b/two - b/twooo - ../globaltwo - globaltwo - b/globaltwo - ../b/globaltwo -EOF cat <<-EOF >expected-verbose .gitignore:1:one ../one .gitignore:1:one one
@@ -605,6 +590,7 @@ cat <<-EOF >expected-verbose $global_excludes:2:!globaltwo b/globaltwo $global_excludes:2:!globaltwo ../b/globaltwo EOF +sed -e 's/.* //' expected-verbose >expected-default sed -e 's/^"//' -e 's/\\//' -e 's/"$//' stdin | \ tr "\n" "\0" >stdin0
Signature · 1 line
1.8.2.1.342.gfa7285d
PATCH v2 2/5 check-ignore: add -n / --non-matching option
If -n or --non-matching are specified, non-matching pathnames will also be output, in which case all fields in each output record except for <pathname> will be empty. This can be useful when running check-ignore as a background process, so that files can be incrementally streamed to STDIN, and for each of these files, STDOUT will indicate whether that file matched a pattern or not. (Without this option, it would be impossible to tell whether the absence of output for a given file meant that it didn't match any pattern, or that the result simply hadn't been flushed to STDOUT yet.)
--- Documentation/git-check-ignore.txt | 15 +++++ builtin/check-ignore.c | 46 ++++++++------ t/t0008-ignores.sh | 122 +++++++++++++++++++++++++++---------- 3 files changed, 134 insertions(+), 49 deletions(-)
Documentation/git-check-ignore.txt +15 -0
@@ -39,6 +39,12 @@ OPTIONS below). If `--stdin` is also given, input paths are separated with a NUL character instead of a linefeed character. +-n, --non-matching:: + Show given paths which don't match any pattern. This only + makes sense when `--verbose` is enabled, otherwise it would + not be possible to distinguish between paths which match a + pattern and those which don't. + OUTPUT ------
@@ -65,6 +71,15 @@ are also used instead of colons and hard tabs: <source> <NULL> <linenum> <NULL> <pattern> <NULL> <pathname> <NULL> +If `-n` or `--non-matching` are specified, non-matching pathnames will +also be output, in which case all fields in each output record except +for <pathname> will be empty. This can be useful when running +non-interactively, so that files can be incrementally streamed to +STDIN of a long-running check-ignore process, and for each of these +files, STDOUT will indicate whether that file matched a pattern or +not. (Without this option, it would be impossible to tell whether the +absence of output for a given file meant that it didn't match any +pattern, or that the output hadn't been generated yet.) EXIT STATUS -----------
builtin/check-ignore.c +29 -17
89 lines not on this page · raw message
t/t0008-ignores.sh +90 -32
213 lines not on this page · raw message
Signature · 1 line
1.8.2.1.342.gfa7285d
PATCH v2 3/5 check-ignore: move setup into cmd_check_ignore()
In reply to Adam SpiersInitialisation of the dir_struct and path_exclude_check structs was previously done within check_ignore(). This was acceptable since check_ignore() was only called once per check-ignore invocation; however the next commit will convert it into an inner loop which is called once per line of STDIN when --stdin is given. Therefore moving the initialisation code out into cmd_check_ignore() ensures that initialisation is still only performed once per check-ignore invocation, and consequently that the output is identical whether pathspecs are provided as CLI arguments or via STDIN.
--- builtin/check-ignore.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-)
builtin/check-ignore.c +21 -20
@@ -63,30 +63,20 @@ static void output_exclude(const char *path, struct exclude *exclude) } } -static int check_ignore (const char *prefix,const char **pathspec) +static int check_ignore (struct path_exclude_check *check, +const char *prefix,const char **pathspec) { -struct dir_struct dir;const char *path, *full_path;char *seen;int num_ignored =0 , dtype =DT_UNKNOWN , i; -struct path_exclude_check check;struct exclude *exclude; -/* read_cache() is only necessary so we can watch out for submodules. */ -if (read_cache () <0 ) -die (_ ("index file corrupt" )); - -memset (&dir,0 ,sizeof (dir)); - dir.flags |=DIR_COLLECT_IGNORED ; -setup_standard_excludes (&dir); -if (!pathspec || !*pathspec) {if (!quiet)fprintf (stderr,"no pathspec given.\n" );return 0 ; } -path_exclude_check_init (&check, &dir);/* * look for pathspecs matching entries in the index, since these * should not be ignored, in order to be consistent with
@@ -101,7 +91,7 @@ static int check_ignore(const char *prefix, const char **pathspec)die_if_path_beyond_symlink (full_path, prefix); exclude =NULL ;if (!seen[i]) { - exclude =last_exclude_matching_path (&check, full_path, + exclude =last_exclude_matching_path (check, full_path,-1 , &dtype); }if (!quiet && (exclude || show_non_matching))
@@ -110,13 +100,11 @@ static int check_ignore(const char *prefix, const char **pathspec) num_ignored++; }free (seen); -clear_directory (&dir); -path_exclude_check_clear (&check);return num_ignored; } -static int check_ignore_stdin_paths (const char *prefix) +static int check_ignore_stdin_paths (struct path_exclude_check *check,const char *prefix) {struct strbuf buf, nbuf;char **pathspec =NULL ;
@@ -139,17 +127,18 @@ static int check_ignore_stdin_paths(const char *prefix) }ALLOC_GROW (pathspec, nr +1 , alloc); pathspec[nr] =NULL ; - num_ignored =check_ignore (prefix, (const char **)pathspec); + num_ignored =check_ignore (check, prefix, (const char **)pathspec);maybe_flush_or_die (stdout,"attribute to stdout" );strbuf_release (&buf);strbuf_release (&nbuf); -free (pathspec);return num_ignored; }int cmd_check_ignore (int argc,const char **argv,const char *prefix) {int num_ignored; +struct dir_struct dir; +struct path_exclude_check check;git_config (git_default_config,NULL );
@@ -174,12 +163,24 @@ int cmd_check_ignore(int argc, const char **argv, const char *prefix)if (show_non_matching && !verbose)die (_ ("--non-matching is only valid with --verbose" )); +/* read_cache() is only necessary so we can watch out for submodules. */ +if (read_cache () <0 ) +die (_ ("index file corrupt" )); + +memset (&dir,0 ,sizeof (dir)); + dir.flags |=DIR_COLLECT_IGNORED ; +setup_standard_excludes (&dir); + +path_exclude_check_init (&check, &dir);if (stdin_paths) { - num_ignored =check_ignore_stdin_paths (prefix); + num_ignored =check_ignore_stdin_paths (&check, prefix); }else { - num_ignored =check_ignore (prefix, argv); + num_ignored =check_ignore (&check, prefix, argv);maybe_flush_or_die (stdout,"ignore to stdout" ); } +clear_directory (&dir); +path_exclude_check_clear (&check); +return !num_ignored; }
Signature · 1 line
1.8.2.1.342.gfa7285d
PATCH v2 4/5 check-ignore: allow incremental streaming of queries via --stdin
In reply to Adam SpiersSome callers, such as the git-annex web assistant, find it useful to invoke git check-ignore as a persistent background process, which can then have queries fed to its STDIN at any point, and the corresponding response consumed from its STDOUT. For this we need to invoke check_ignore() once per line of standard input, and flush standard output after each result.
The above use case suggests that empty STDIN is actually a reasonable scenario (e.g. when the caller doesn't know in advance whether any queries need to be fed to the background process until after it's already started), so we make the minor behavioural change that "no pathspec given." is no longer emitted in when STDIN is empty.
Even though check_ignore() could now be changed to operate on a single pathspec, we keep it operating on an array of pathspecs since that is a more convenient way of consuming the existing pathspec API.
--- builtin/check-ignore.c | 15 +++++---------- t/t0008-ignores.sh | 28 +++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 15 deletions(-)
builtin/check-ignore.c +5 -10
@@ -107,10 +107,9 @@ static int check_ignore(struct path_exclude_check *check,static int check_ignore_stdin_paths (struct path_exclude_check *check,const char *prefix) {struct strbuf buf, nbuf; -char **pathspec =NULL ; -size_t nr =0 , alloc =0 ; +char *pathspec[2 ] = {NULL ,NULL };int line_termination = null_term_line ?0 :'\n' ; -int num_ignored; +int num_ignored =0 ;strbuf_init (&buf,0 );strbuf_init (&nbuf,0 );
@@ -121,14 +120,10 @@ static int check_ignore_stdin_paths(struct path_exclude_check *check, const chardie ("line is badly quoted" );strbuf_swap (&buf, &nbuf); } -ALLOC_GROW (pathspec, nr +1 , alloc); - pathspec[nr] =xcalloc (strlen (buf.buf) +1 ,sizeof (*buf.buf)); -strcpy (pathspec[nr++], buf.buf); + pathspec[0 ] = buf.buf; + num_ignored +=check_ignore (check, prefix, (const char **)pathspec); +maybe_flush_or_die (stdout,"check-ignore to stdout" ); } -ALLOC_GROW (pathspec, nr +1 , alloc); - pathspec[nr] =NULL ; - num_ignored =check_ignore (check, prefix, (const char **)pathspec); -maybe_flush_or_die (stdout,"attribute to stdout" );strbuf_release (&buf);strbuf_release (&nbuf);return num_ignored;
t/t0008-ignores.sh +23 -5
@@ -216,11 +216,7 @@ test_expect_success_multi 'empty command line' '' ' test_expect_success_multi '--stdin with empty STDIN' '' ' test_check_ignore "--stdin" 1 </dev/null && - if test -n "$quiet_opt"; then - test_stderr "" - else - test_stderr "no pathspec given." - fi + test_stderr "" ' test_expect_success '-q with multiple args' '
@@ -692,5 +688,27 @@ do ' done +test_expect_success 'setup: have stdbuf?' ' + if which stdbuf >/dev/null 2>&1 + then + test_set_prereq STDBUF + fi +' + +test_expect_success STDBUF 'streaming support for --stdin' ' + ( + echo one + sleep 2 + echo two + ) | stdbuf -oL git check-ignore -v -n --stdin >out & + pid=$! && + sleep 1 && + grep "^\.gitignore:1:one one" out && + test $( wc -l <out ) = 1 && + sleep 2 && + grep "^:: two" out && + test $( wc -l <out ) = 2 && + ( wait $pid || kill $pid || : ) 2>/dev/null +' test_done
Signature · 1 line
1.8.2.1.342.gfa7285d
Re: [PATCH v2 4/5] check-ignore: allow incremental streaming of queries via --stdin
Quoted 12 lines · Adam Spiers
t/t0008-ignores.sh +12
-0+test_expect_success 'setup: have stdbuf?' ' + if which stdbuf >/dev/null 2>&1 + then + test_set_prereq STDBUF + fi +' + +test_expect_success STDBUF 'streaming support for --stdin' ' + ( + echo one + sleep 2 + echo two
t/t0008-ignores.sh do · line 712
Quoted 10 lines
t/t0008-ignores.sh +10
-0+ ) | stdbuf -oL git check-ignore -v -n --stdin >out & + pid=$! && + sleep 1 && + grep "^\.gitignore:1:one one" out && + test $( wc -l <out ) = 1 && + sleep 2 && + grep "^:: two" out && + test $( wc -l <out ) = 2 && + ( wait $pid || kill $pid || : ) 2>/dev/null +'
I always get a little nervous with sleeps in the test suite, as they are indicative that we are trying to avoid some race condition, which means that the test can fail when the system is under load, or when a tool like valgrind is used which drastically alters the timing (e.g., if check-ignore takes longer than 1 second to produce its answer, we may fail here).
Is there a simpler way to test this?
Like:
# Set up a long-running "check-ignore" connected by pipes. mkfifo in out &&
(git check-ignore ... <in >out &) &&
# We cannot just "echo >in" because check-ignore
# would get EOF after echo exited; instead we open # the descriptor in our shell, and then echo to the # fd. We make sure to close it at the end, so that # the subprocess does get EOF and dies properly. exec 9>in && test_when_finished "exec 9>&-" &&
# Now we can do interactive tests
echo >&9 one &&
read response <out &&
test "$response" = ... &&
echo >&9 two &&
read response <out &&
test "$response" = ...
Hmm. Maybe simpler wasn't the right word. :) But it avoids any sleeps or race conditions.
-Peff
Re: [PATCH v2 4/5] check-ignore: allow incremental streaming of queries via --stdin
Quoted 6 lines · Jeff King
I always get a little nervous with sleeps in the test suite, as they are indicative that we are trying to avoid some race condition, which means that the test can fail when the system is under load, or when a tool like valgrind is used which drastically alters the timing (e.g., if check-ignore takes longer than 1 second to produce its answer, we may fail here).
Agreed, especially here where my btrfs filesystems see fit to kindly freeze my system for a few seconds many times each day :-/
Quoted 24 lines
Is there a simpler way to test this?
Like:
# Set up a long-running "check-ignore" connected by pipes. mkfifo in out &&
(git check-ignore ... <in >out &) &&# We cannot just "echo >in" because check-ignore
# would get EOF after echo exited; instead we open # the descriptor in our shell, and then echo to the # fd. We make sure to close it at the end, so that # the subprocess does get EOF and dies properly. exec 9>in && test_when_finished "exec 9>&-" &&# Now we can do interactive tests
echo >&9 one &&
read response <out &&
test "$response" = ... &&
echo >&9 two &&
read response <out &&
test "$response" = ...
Quoted 2 lines
Hmm. Maybe simpler wasn't the right word. :) But it avoids any sleeps or race conditions.
The shell source is strong with this one ;-)
Congrats - I first tried with FIFOs (hence my other patch which moves the PIPE test prerequisite definition into the core framework - the original intention was to reuse it here) but failed to get it working. I'll re-roll using your approach.
Re: [PATCH v2 4/5] check-ignore: allow incremental streaming of queries via --stdin
Quoted 6 lines · Adam Spiers
The shell source is strong with this one ;-)
Congrats - I first tried with FIFOs (hence my other patch which moves the PIPE test prerequisite definition into the core framework - the original intention was to reuse it here) but failed to get it working. I'll re-roll using your approach.
Thanks. If it make you feel any better, it took about 20 minutes of experimenting and at least three head-scratching "wait, that _should_ have worked" moments to get it right. :)
The rest of the series looked good to me, though I admit I did not think too hard about the "--non-matching" patch, as it looked like you and Junio had already given some thought to the output format, which is the tricky part.
-Peff
Re: [PATCH v2 4/5] check-ignore: allow incremental streaming of queries via --stdin
In reply to Adam SpiersQuoted 8 lines · Adam Spiers
Quoted 6 lines · Jeff King
I always get a little nervous with sleeps in the test suite, as they are indicative that we are trying to avoid some race condition, which means that the test can fail when the system is under load, or when a tool like valgrind is used which drastically alters the timing (e.g., if check-ignore takes longer than 1 second to produce its answer, we may fail here).
Quoted 8 lines
Agreed, especially here where my btrfs filesystems see fit to kindly freeze my system for a few seconds many times each day :-/
Quoted 4 lines
Is there a simpler way to test this?
Like:
...I'll re-roll using your approach.
I think I missed this one and it already is in 'next'.
I'll hold it back so please make your re-roll into an incremental update.
Thanks.
Re: [PATCH v2 4/5] check-ignore: allow incremental streaming of queries via --stdin
Quoted 15 lines · Junio C Hamano
Quoted 13 lines · Adam Spiers
Quoted 6 lines · Jeff King
I always get a little nervous with sleeps in the test suite, as they are indicative that we are trying to avoid some race condition, which means that the test can fail when the system is under load, or when a tool like valgrind is used which drastically alters the timing (e.g., if check-ignore takes longer than 1 second to produce its answer, we may fail here).
Agreed, especially here where my btrfs filesystems see fit to kindly freeze my system for a few seconds many times each day :-/
Quoted 2 lines
Is there a simpler way to test this?
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines
Like:
...I'll re-roll using your approach.
I think I missed this one and it already is in 'next'.
I'll hold it back so please make your re-roll into an incremental update.
Will do - will probably take a few days more though, since I'm currently catching up on a post-travel work backlog.
PATCH 1/1 t0008: use named pipe (FIFO) to test check-ignore streaming
sleeps in the check-ignore test suite are not ideal since they can fail when the system is under load, or when a tool like valgrind is used which drastically alters the timing. Therefore we replace them with a more robust solution using a named pipe (FIFO).
Thanks to Jeff King for coming up with the redirection wizardry required to make this work.
http://article.gmane.org/gmane.comp.version-control.git/220916
--- t/t0008-ignores.sh | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-)
t/t0008-ignores.sh +17 -21
@@ -688,27 +688,23 @@ do ' done -test_expect_success 'setup: have stdbuf?' ' - if which stdbuf >/dev/null 2>&1 - then - test_set_prereq STDBUF - fi -' - -test_expect_success STDBUF 'streaming support for --stdin' ' - ( - echo one - sleep 2 - echo two - ) | stdbuf -oL git check-ignore -v -n --stdin >out & - pid=$! && - sleep 1 && - grep "^\.gitignore:1:one one" out && - test $( wc -l <out ) = 1 && - sleep 2 && - grep "^:: two" out && - test $( wc -l <out ) = 2 && - ( wait $pid || kill $pid || : ) 2>/dev/null +test_expect_success PIPE 'streaming support for --stdin' ' + mkfifo in out && + (git check-ignore -n -v --stdin <in >out &) && + + # We cannot just "echo >in" because check-ignore would get EOF + # after echo exited; instead we open the descriptor in our + # shell, and then echo to the fd. We make sure to close it at + # the end, so that the subprocess does get EOF and dies + # properly. + exec 9>in && + test_when_finished "exec 9>&-" && + echo >&9 one && + read response <out && + echo "$response" | grep "^\.gitignore:1:one one" && + echo >&9 two && + read response <out && + echo "$response" | grep "^:: two" ' test_done
Signature · 1 line
1.8.3.rc0.305.g6580fe1
Re: [PATCH v2 4/5] check-ignore: allow incremental streaming of queries via --stdin
In reply to Adam SpiersQuoted 5 lines · Adam Spiers
The above use case suggests that empty STDIN is actually a reasonable scenario (e.g. when the caller doesn't know in advance whether any queries need to be fed to the background process until after it's already started), so we make the minor behavioural change that "no pathspec given." is no longer emitted in when STDIN is empty.
The last "in" there looks to be misplaced. Was that originally something like "in the case"? If so the removed words should be restored or the lingering one removed as well.
Re: [PATCH v2 4/5] check-ignore: allow incremental streaming of queries via --stdin
Quoted 10 lines · Aaron Schrab
Quoted 5 lines · Adam Spiers
The above use case suggests that empty STDIN is actually a reasonable scenario (e.g. when the caller doesn't know in advance whether any queries need to be fed to the background process until after it's already started), so we make the minor behavioural change that "no pathspec given." is no longer emitted in when STDIN is empty.
The last "in" there looks to be misplaced. Was that originally something like "in the case"? If so the removed words should be restored or the lingering one removed as well.
I'll remove it; thanks.
PATCH v2 5/5 Documentation: add caveats about I/O buffering for check-{attr,ignore}
In reply to Adam Spierscheck-attr and check-ignore have the potential to deadlock callers which do not read back the output in real-time. For example, if a caller writes N paths out and then reads N lines back in, it risks becoming blocked on write() to check-*, and check-* is blocked on write back to the caller. Somebody has to buffer; the pipe buffers provide some leeway, but they are limited.
Thanks to Peff for pointing this out:
http://article.gmane.org/gmane.comp.version-control.git/220534
--- Documentation/git-check-attr.txt | 5 +++++ Documentation/git-check-ignore.txt | 5 +++++ Documentation/git.txt | 16 +++++++++------- 3 files changed, 19 insertions(+), 7 deletions(-)
Documentation/git-check-attr.txt +5 -0
@@ -56,6 +56,11 @@ being queried and <info> can be either: 'set';; when the attribute is defined as true. <value>;; when a value has been assigned to the attribute. +Buffering happens as documented under the `GIT_FLUSH` option in +linkgit:git[1]. The caller is responsible for avoiding deadlocks +caused by overfilling an input buffer or reading from an empty output +buffer. + EXAMPLES --------
Documentation/git-check-ignore.txt +5 -0
@@ -81,6 +81,11 @@ not. (Without this option, it would be impossible to tell whether the absence of output for a given file meant that it didn't match any pattern, or that the output hadn't been generated yet.) +Buffering happens as documented under the `GIT_FLUSH` option in +linkgit:git[1]. The caller is responsible for avoiding deadlocks +caused by overfilling an input buffer or reading from an empty output +buffer. + EXIT STATUS -----------
Documentation/git.txt +9 -7
@@ -808,13 +808,15 @@ for further details. 'GIT_FLUSH':: If this environment variable is set to "1", then commands such - as 'git blame' (in incremental mode), 'git rev-list', 'git log', - and 'git whatchanged' will force a flush of the output stream - after each commit-oriented record have been flushed. If this - variable is set to "0", the output of these commands will be done - using completely buffered I/O. If this environment variable is - not set, Git will choose buffered or record-oriented flushing - based on whether stdout appears to be redirected to a file or not. + as 'git blame' (in incremental mode), 'git rev-list', 'git + log', 'git check-attr', 'git check-ignore', and 'git + whatchanged' will force a flush of the output stream after + each commit-oriented record have been flushed. If this + variable is set to "0", the output of these commands will be + done using completely buffered I/O. If this environment + variable is not set, Git will choose buffered or + record-oriented flushing based on whether stdout appears to be + redirected to a file or not. 'GIT_TRACE':: If this variable is set to "1", "2" or "true" (comparison
Signature · 1 line
1.8.2.1.342.gfa7285d
Re: [PATCH v2 5/5] Documentation: add caveats about I/O buffering for check-{attr,ignore}
Quoted 30 lines · Adam Spiers
Documentation/git-check-ignore.txt +5
-0@@ -81,6 +81,11 @@ not. (Without this option, it would be impossible to tell whether the absence of output for a given file meant that it didn't match any pattern, or that the output hadn't been generated yet.) +Buffering happens as documented under the `GIT_FLUSH` option in +linkgit:git[1]. The caller is responsible for avoiding deadlocks +caused by overfilling an input buffer or reading from an empty output +buffer. + EXIT STATUS -----------Documentation/git.txt +0
-6@@ -808,13 +808,15 @@ for further details. 'GIT_FLUSH':: If this environment variable is set to "1", then commands such - as 'git blame' (in incremental mode), 'git rev-list', 'git log', - and 'git whatchanged' will force a flush of the output stream - after each commit-oriented record have been flushed. If this - variable is set to "0", the output of these commands will be done - using completely buffered I/O. If this environment variable is - not set, Git will choose buffered or record-oriented flushing
Documentation/git.txt for further details. · line 819
Quoted 10 lines
Documentation/git.txt +9
-1- based on whether stdout appears to be redirected to a file or not. + as 'git blame' (in incremental mode), 'git rev-list', 'git + log', 'git check-attr', 'git check-ignore', and 'git + whatchanged' will force a flush of the output stream after + each commit-oriented record have been flushed. If this + variable is set to "0", the output of these commands will be + done using completely buffered I/O. If this environment + variable is not set, Git will choose buffered or + record-oriented flushing based on whether stdout appears to be + redirected to a file or not.
Reflowing of the text is very much unappreciated X-<.
It took me five minutes to spot that you only added check-attr and check-ignore and forgot to adjust that "commit-oriented record" to an updated reality, where you now have commands that produce non-commit-oriented record to the output.
It would have been far simpler to review if it were like this, don't you think?
Quoted 11 lines
Documentation/git.txt +3
-2If this environment variable is set to "1", then commands such as 'git blame' (in incremental mode), 'git rev-list', 'git log', - and 'git whatchanged' will force a flush of the output stream - after each commit-oriented record have been flushed. If this + 'git check-attr', 'git check-ignore', and 'git whatchanged' will + force a flush of the output stream + after each record have been flushed. If thisvariable is set to "0", the output of these commands will be done
using completely buffered I/O. If this environment variable isDocumentation/git.txt +0
-0not set, Git will choose buffered or record-oriented flushing based on whether stdout appears to be redirected to a file or not.
PATCH v3 5/5 Documentation: add caveats about I/O buffering for check-{attr,ignore}
Quoted 1 line · Junio C Hamano
Reflowing of the text is very much unappreciated X-<.
I very much appreciate the excellent job you do as maintainer; your attention to detail results in an incredibly high quality project. However I do occasionally find your communication style unnecessarily abrasive. Maybe that's just me.
Quoted 4 lines
It took me five minutes to spot that you only added check-attr and check-ignore and forgot to adjust that "commit-oriented record" to an updated reality, where you now have commands that produce non-commit-oriented record to the output.
I am sorry for wasting five minutes of your time. A non-reflowed version is included inline below, and also at:
https://github.com/aspiers/git/compare/master...git-annex-streaming
Quoted 2 lines
It would have been far simpler to review if it were like this, don't you think?
It would have been slightly simpler, yes. It did occur to me not to re-flow it, but then one of the lines ended up noticeably shorter, and as it was a short paragraph, I estimated that you would prefer it re-flowed. Clearly I was wrong - not the first time, and it won't be the last either, since I'm just a flawed human being trying to do my best in the time available. The question then arises: how uneven does a paragraph's right margin have to be in order to justify re-flowing? I could not find any guidelines in SubmittingPatches or CodingGuidelines regarding re-flowing of documentation. With hindsight, I can now see that it would have been better to skip it on this occasion, or at least keep the re-flow as a separate commit.
So I apologise again for the mistake, but don't you think it would have been far more pleasant if instead you'd worded your email something like this?
Thanks for the patches. I notice that you unnecessarily re-flowed the latter half of the GIT_FLUSH paragraph; unfortunately this meant I had to spend a few extra minutes on the review and almost missed that "commit-oriented" is no longer applicable. In future, please avoid re-flowing text where possible.
Fortunately I'm not the sensitive sort, but I imagine that there are others in this community who might be discouraged from contributing for fear of being on the receiving end of sentences which end with phrases such as "[...] is very much unappreciated X-<." Please don't underestimate the human factor; common courtesy can make a big difference.
Thanks,
Adam
-- >8 --
Subject: [PATCH v3 5/5] Documentation: add caveats about I/O buffering for
check-{attr,ignore}
check-attr and check-ignore have the potential to deadlock callers which do not read back the output in real-time. For example, if a caller writes N paths out and then reads N lines back in, it risks becoming blocked on write() to check-*, and check-* is blocked on write back to the caller. Somebody has to buffer; the pipe buffers provide some leeway, but they are limited.
Thanks to Peff for pointing this out:
http://article.gmane.org/gmane.comp.version-control.git/220534
--- Documentation/git-check-attr.txt | 5 +++++ Documentation/git-check-ignore.txt | 5 +++++ Documentation/git.txt | 7 ++++--- 3 files changed, 14 insertions(+), 3 deletions(-)
Documentation/git-check-attr.txt +5 -0
@@ -56,6 +56,11 @@ being queried and <info> can be either: 'set';; when the attribute is defined as true. <value>;; when a value has been assigned to the attribute. +Buffering happens as documented under the `GIT_FLUSH` option in +linkgit:git[1]. The caller is responsible for avoiding deadlocks +caused by overfilling an input buffer or reading from an empty output +buffer. + EXAMPLES --------
Documentation/git-check-ignore.txt +5 -0
@@ -81,6 +81,11 @@ not. (Without this option, it would be impossible to tell whether the absence of output for a given file meant that it didn't match any pattern, or that the output hadn't been generated yet.) +Buffering happens as documented under the `GIT_FLUSH` option in +linkgit:git[1]. The caller is responsible for avoiding deadlocks +caused by overfilling an input buffer or reading from an empty output +buffer. + EXIT STATUS -----------
Documentation/git.txt +4 -3
@@ -808,9 +808,10 @@ for further details. 'GIT_FLUSH':: If this environment variable is set to "1", then commands such - as 'git blame' (in incremental mode), 'git rev-list', 'git log', - and 'git whatchanged' will force a flush of the output stream - after each commit-oriented record have been flushed. If this + as 'git blame' (in incremental mode), 'git rev-list', 'git + log', 'git check-attr', 'git check-ignore', and 'git + whatchanged' will force a flush of the output stream + after each record has been flushed. If this variable is set to "0", the output of these commands will be done using completely buffered I/O. If this environment variable is not set, Git will choose buffered or record-oriented flushing
Signature · 1 line
1.8.2.1.347.gbef22ca
Re: [PATCH v3 5/5] Documentation: add caveats about I/O buffering for check-{attr,ignore}
Quoted 7 lines · Adam Spiers
Quoted 1 line · Junio C Hamano
Reflowing of the text is very much unappreciated X-<.
I very much appreciate the excellent job you do as maintainer; your attention to detail results in an incredibly high quality project. However I do occasionally find your communication style unnecessarily abrasive. Maybe that's just me.
Sorry for being me X-<. Yeah, I agree that the above came out to be more blunt than needed.
It is usually OK to re-flow the text in the paragraph you are touching. After all, for the purpose of reviewing, people can just blindly apply and then ask "diff --color-words". In this case, however, there was some changes that conflict in the vicinity, and reflowing made the resolution unnecessarily more cumbersome.
I have briefly looked at this series, but it severely conflicts with a few topics in flight that touch the infrastructure you are using, so I haven't merged it to 'pu'. Perhaps after things calm down, we may want to ask you to reroll on top of updated codebase.
Thanks.
Re: [PATCH v3 5/5] Documentation: add caveats about I/O buffering for check-{attr,ignore}
Quoted 5 lines · Junio C Hamano
It is usually OK to re-flow the text in the paragraph you are touching. After all, for the purpose of reviewing, people can just blindly apply and then ask "diff --color-words". In this case, however, there was some changes that conflict in the vicinity, and reflowing made the resolution unnecessarily more cumbersome.
I see. Thanks for the tip; I was only dimly aware of --color-words.
Quoted 4 lines
I have briefly looked at this series, but it severely conflicts with a few topics in flight that touch the infrastructure you are using, so I haven't merged it to 'pu'. Perhaps after things calm down, we may want to ask you to reroll on top of updated codebase.
Sure, no problem. I'll try a quick rebase now to see how ugly it is.
By the way, I've replaced my test for streaming --stdin which was based on stdbuf(1) and sleep(1) with Peff's clever hack based on mkfifo. I'll hold off from sending a reroll until pathspec activity cools down, but in the meantime it's available here:
https://github.com/aspiers/git/compare/master...git-annex-streaming
It requires my "t: make PIPE a standard test prerequisite" patch, but I notice that's already in master which will make things easier later on.
Thanks!
Adam
Re: [PATCH 1/5] check-ignore: move setup into cmd_check_ignore()
In reply to Adam SpiersQuoted 9 lines · Adam Spiers
Quoted 7 lines · Jeff King
builtin/check-ignore.c static void output_exclude(const char *path, struct exclude *exclude) · line 57
Quoted 3 lines · Adam Spiers
builtin/check-ignore.c +2
-1-static int check_ignore (const char *prefix,const char **pathspec) +static int check_ignore (struct path_exclude_check check, +const char *prefix,const char **pathspec)Did you mean to pass the struct by value here? If it is truly a per-path [...]
Quoted 3 lines
It's not a per-path value; it's supposed to be reused across checks for multiple paths, as explained in the comments above
last_exclude_matching_path():
Makes sense (I didn't look into it very far, and was just guessing based on the pass-by-value). Passing a pointer is definitely the right fix, then.
Thanks.
-Peff