From: Brandon Williams <hidden> Date: 2017-02-24 23:51:20
It was discovered that when using the --recurse-submodules flag with `git grep`
and `git ls-files` and specifying a relative path when not at the root causes
the child processes spawned to error out with an error like:
fatal: ..: '..' is outside repository
While true that ".." is outside the scope of the submodule repository, it
probably doesn't make much sense to the user who gave that pathspec with
respect to the superproject. Since the child processes that are spawned to
handle the submodules have some context that they are executing underneath a
superproject (via the 'super_prefix'), they should be able to prevent dying
under this circumstance.
This series fixes this bug in both git grep and git ls-files as well as
correctly formatting the output from submodules to handle the relative paths
with "..".
One of the changes made to fix this was to add an additional flag for the
parse_pathspec() function in order to treat all paths provided as being from
the root of the repository. I hesitantly selected the name 'PATHSPEC_FROMROOT'
but I'm not fond of it since its too similar to the pathspec magic define
'PATHSPEC_FROMTOP'. So I'm open for naming suggestions.
Brandon Williams (5):
grep: illustrate bug when recursing with relative pathspec
pathspec: add PATHSPEC_FROMROOT flag
grep: fix bug when recuring with relative pathspec
ls-files: illustrate bug when recursing with relative pathspec
ls-files: fix bug when recuring with relative pathspec
builtin/grep.c | 8 ++++--
builtin/ls-files.c | 8 ++++--
pathspec.c | 2 +-
pathspec.h | 2 ++
t/t3007-ls-files-recurse-submodules.sh | 50 ++++++++++++++++++++++++++++++++++
t/t7814-grep-recurse-submodules.sh | 42 ++++++++++++++++++++++++++++
6 files changed, 107 insertions(+), 5 deletions(-)
--
2.11.0.483.g087da7b7c-goog
From: Brandon Williams <hidden> Date: 2017-02-24 23:51:15
When using the --recurse-submodules flag with a relative pathspec which
includes "..", an error is produced inside the child process spawned for
a submodule. When creating the pathspec struct in the child, the ".."
is interpreted to mean "go up a directory" which causes an error stating
that the path ".." is outside of the repository.
While it is true that ".." is outside the scope of the submodule, it is
confusing to a user who originally invoked the command where ".." was
indeed still inside the scope of the superproject. Since the child
process luanched for the submodule has some context that it is operating
underneath a superproject, this error could be avoided.
Signed-off-by: Brandon Williams <redacted>
---
t/t7814-grep-recurse-submodules.sh | 42 ++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
@@ -227,6 +227,48 @@ test_expect_success 'grep history with moved submoules' 'test_cmpexpectactual'+test_expect_failure'grep using relative path''+test_when_finished"rm -rf parent sub"&&+gitinitsub&&+echo"foobar">sub/file&&+git-Csubaddfile&&+git-Csubcommit-m"add file"&&++gitinitparent&&+echo"foobar">parent/file&&+git-Cparentaddfile&&+mkdirparent/src&&+echo"foobar">parent/src/file2&&+git-Cparentaddsrc/file2&&+git-Cparentsubmoduleadd../sub&&+git-Cparentcommit-m"add files and submodule"&&++# From top works+cat>expect<<-\EOF&&+file:foobar+src/file2:foobar+sub/file:foobar+EOF+git-Cparentgrep--recurse-submodules-e"foobar">actual&&+test_cmpexpectactual&&++# Relative path to top errors out+cat>expect<<-\EOF&&+../file:foobar+file2:foobar+../sub/file:foobar+EOF+git-Cparent/srcgrep--recurse-submodules-e"foobar"--..>actual&&+test_cmpexpectactual&&++# Relative path to submodule errors out+cat>expect<<-\EOF&&+../sub/file:foobar+EOF+git-Cparent/srcgrep--recurse-submodules-e"foobar"--../sub>actual&&+test_cmpexpectactual+'+ test_incompatible_with_recurse_submodules(){test_expect_success"--recurse-submodules and $1 are incompatible""
From: Brandon Williams <hidden> Date: 2017-02-24 23:51:17
Add the `PATHSPEC_FROMROOT` flag to allow callers to instruct
'parse_pathspec()' that all provided pathspecs are relative to the root
of the repository. This allows a caller to prevent a path that may be
outside of the repository from erroring out during the pathspec struct
construction.
Signed-off-by: Brandon Williams <redacted>
---
pathspec.c | 2 +-
pathspec.h | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
@@ -66,6 +66,8 @@ struct pathspec {*allowed,thenitwillautomaticallysetforeverypathspec.*/#define PATHSPEC_LITERAL_PATH (1<<8)+/* For callers that know all paths are relative to the root of the repository */+#define PATHSPEC_FROMROOT (1<<9)externvoidparse_pathspec(structpathspec*pathspec,unsignedmagic_mask,
From: Brandon Williams <hidden> Date: 2017-02-24 23:51:21
Fix a bug which causes a child process for a submodule to error out when
a relative pathspec with a ".." is provided in the superproject.
While at it, correctly construct the super-prefix to be used in a
submodule when not at the root of the repository.
Signed-off-by: Brandon Williams <redacted>
---
builtin/grep.c | 8 ++++++--
t/t7814-grep-recurse-submodules.sh | 2 +-
2 files changed, 7 insertions(+), 3 deletions(-)
@@ -227,7 +227,7 @@ test_expect_success 'grep history with moved submoules' 'test_cmpexpectactual'-test_expect_failure'grep using relative path''+test_expect_success'grep using relative path''test_when_finished"rm -rf parent sub"&&gitinitsub&&echo"foobar">sub/file&&
From: Brandon Williams <hidden> Date: 2017-02-24 23:51:23
Fix a bug which causes a child process for a submodule to error out when a
relative pathspec with a ".." is provided in the superproject.
While at it, correctly construct the super-prefix to be used in a submodule
when not at the root of the repository.
Signed-off-by: Brandon Williams <redacted>
---
builtin/ls-files.c | 8 ++++++--
t/t3007-ls-files-recurse-submodules.sh | 2 +-
2 files changed, 7 insertions(+), 3 deletions(-)
@@ -188,7 +188,7 @@ test_expect_success '--recurse-submodules and pathspecs' 'test_cmpexpectactual'-test_expect_failure'--recurse-submodules and relative paths''+test_expect_success'--recurse-submodules and relative paths''# From top workscat>expect<<-\EOF&&.gitmodules
From: Brandon Williams <hidden> Date: 2017-02-24 23:51:39
When using the --recurse-submodules flag with a relative pathspec which
includes "..", an error is produced inside the child process spawned for a
submodule. When creating the pathspec struct in the child, the ".." is
interpreted to mean "go up a directory" which causes an error stating that the
path ".." is outside of the repository.
While it is true that ".." is outside the scope of the submodule, it is
confusing to a user who originally invoked the command where ".." was indeed
still inside the scope of the superproject. Since the child process luanched
for the submodule has some context that it is operating underneath a
superproject, this error could be avoided.
Signed-off-by: Brandon Williams <redacted>
---
t/t3007-ls-files-recurse-submodules.sh | 50 ++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
@@ -188,6 +188,56 @@ test_expect_success '--recurse-submodules and pathspecs' 'test_cmpexpectactual'+test_expect_failure'--recurse-submodules and relative paths''+# From top works+cat>expect<<-\EOF&&+.gitmodules+a+b/b+h.txt+sib/file+sub/file+submodule/.gitmodules+submodule/c+submodule/f.TXT+submodule/g.txt+submodule/subsub/d+submodule/subsub/e.txt+EOF+gitls-files--recurse-submodules>actual&&+test_cmpexpectactual&&++# Relative path to top errors out+cat>expect<<-\EOF&&+../.gitmodules+../a+b+../h.txt+../sib/file+../sub/file+../submodule/.gitmodules+../submodule/c+../submodule/f.TXT+../submodule/g.txt+../submodule/subsub/d+../submodule/subsub/e.txt+EOF+git-Cbls-files--recurse-submodules--..>actual&&+test_cmpexpectactual&&++# Relative path to submodule errors out+cat>expect<<-\EOF&&+../submodule/.gitmodules+../submodule/c+../submodule/f.TXT+../submodule/g.txt+../submodule/subsub/d+../submodule/subsub/e.txt+EOF+git-Cbls-files--recurse-submodules--../submodule>actual&&+test_cmpexpectactual+'+ test_expect_success'--recurse-submodules does not support --error-unmatch''test_must_failgitls-files--recurse-submodules--error-unmatch2>actual&&test_i18ngrep"does not support --error-unmatch"actual
From: Stefan Beller <hidden> Date: 2017-02-25 00:38:23
On Fri, Feb 24, 2017 at 3:50 PM, Brandon Williams [off-list ref] wrote:
Add the `PATHSPEC_FROMROOT` flag to allow callers to instruct
'parse_pathspec()' that all provided pathspecs are relative to the root
of the repository. This allows a caller to prevent a path that may be
outside of the repository from erroring out during the pathspec struct
construction.
+/* For callers that know all paths are relative to the root of the repository */
+#define PATHSPEC_FROMROOT (1<<9)
What is the calling convention for these submodule pathspecs?
IIRC, we'd pass on the super-prefix and the literal pathspec,
e.g. when there is a submodule "sub" inside the superproject,
The invocation on the submodule would be
git FOO --super-prefix="sub" <arguments> -- sub/pathspec/inside/...
and then the submodule process would need to "subtract" the superprefix
from the pathspec argument to see its actual pathspec, e.g. in gerrit:
$ GIT_TRACE=1 git grep --recurse-submodules -i test -- \
plugins/cookbook-plugin/
...
trace: run_command: '--super-prefix=plugins/cookbook-plugin/' 'grep' \
'--recurse-submodules' '-i' '-etest' '--threads=4' '--'
'plugins/cookbook-plugin/'
..
but also:
...
trace: run_command: '--super-prefix=plugins/download-commands/' 'grep' \
'--recurse-submodules' '-i' '-etest' '--threads=4' '--'
'plugins/cookbook-plugin/'
...
So if I change into a directory:
$ cd plugins
plugins$ git grep --recurse-submodules -i test -- cookbook-plugin/
plugins$ #empty?
plugins$ git grep --recurse-submodules -i test -- plugins/cookbook-plugin/
...
Usual output, so the pathspecs are absolute path to the superprojects
root? Let's try relative path:
plugins$ git grep --recurse-submodules -i test -- ../plugins/cookbook-plugin/
fatal: ../plugins/cookbook-plugin/: '../plugins/cookbook-plugin/' is
outside repository
...
Running with GIT_TRACE=1:
trace: run_command: '--super-prefix=plugins/cookbook-plugin/' 'grep' \
'--recurse-submodules' '-i' '-etest' '--threads=4' '--'
'../plugins/cookbook-plugin/'
that seems like a mismatch of pathspec and superproject prefix, the prefix ought
to be different then? Maybe also including ../ because that is the
relative path from
cwd to the superporojects root and that is where we anchor all paths?
Easy to test that out:
plugins$ GIT_TRACE=1 git --super-prefix=../ grep --recurse-submodules \
-i test -- ../plugins/cookbook-plugin/
fatal: can't use --super-prefix from a subdirectory
ok, not as easy. :/
So another test with relative path:
(in git.git)
cd t/diff-lib
t/diff-lib$ git grep freedom
COPYING:freedom to share and change it. By contrast, the GNU General Public
...
So the path displayed is relative to the cwd (and the search results as well)
In the submodule case we would expect to have the super prefix
to be computed to be relative to the cwd?
Checking the tests, this is handled correctly with this patch series. :)
But nevertheless, I think I know why I dislike this approach now:
The super prefix is handled "too dumb" IMHO, see the case
plugins$ git grep test -- cookbook-plugin/
above, that doesn't correctly figure out the correct output.
Although this might be a separate bug, but it sounds like it
is the same underlying issue.
--
for the naming: How about PATHSPEC_FROMOUTSIDE
when going with the series as is here?
(the superprefix is not resolved, so the pathspecs given are
literally pathspecs that are outside this repo and we can ignore
them?
Thanks,
Stefan
On Sat, Feb 25, 2017 at 6:50 AM, Brandon Williams [off-list ref] wrote:
When using the --recurse-submodules flag with a relative pathspec which
includes "..", an error is produced inside the child process spawned for
a submodule. When creating the pathspec struct in the child, the ".."
is interpreted to mean "go up a directory" which causes an error stating
that the path ".." is outside of the repository.
While it is true that ".." is outside the scope of the submodule, it is
confusing to a user who originally invoked the command where ".." was
indeed still inside the scope of the superproject. Since the child
process luanched for the submodule has some context that it is operating
s/luanched/launched/
I would prefer 1/5 t to be merged with 3/5 though. The problem
description is very light there, and the test demonstration in the
diff is simply switching from failure to success, which forces the
reader to come back here. It's easier to find here now, but it'll be a
bit harder when it enters master and we have to read it from git-log,
I think.
I'm still munching through the super-prefix patches. From how you
changed match_pathspec call in 0281e487fd (grep: optionally recurse
into submodules - 2016-12-16), I guess pathspecs should be handled
with super-prefix instead of the submodule's prefix (which is empty
anyway, I guess). The right solution wrt. handling relative paths may
be teach pathspec about super-prefix (and even original super's cwd)
then let it processes path in supermodule's context.
Does it handle relative paths with wildcards correctly btw? Ones that
cross submodules? I have a feeling it doesn't, but I haven't seen how
exactly super-prefix works yet.
There's another problem with passing pathspec from one process to
another. The issue with preserving the prefix, see 233c3e6c59
(parse_pathspec: preserve prefix length via PATHSPEC_PREFIX_ORIGIN -
2013-07-14). :(icase) needs this because given a path
"<prefix>/foobar", only the "foobar" part is considered case
insensitive, the prefix part is always case-sensitive. For example, if
you have 4 paths "abc/def", "abc/DEF", "ABC/def" and "ABC/DEF" and are
standing at "abc", you would want ":(icase)def" to match the first two
only, not all of them.
quoted hunk
underneath a superproject, this error could be avoided.
Signed-off-by: Brandon Williams <redacted>
---
t/t7814-grep-recurse-submodules.sh | 42 ++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
@@ -227,6 +227,48 @@ test_expect_success 'grep history with moved submoules' 'test_cmpexpectactual'+test_expect_failure'grep using relative path''+test_when_finished"rm -rf parent sub"&&+gitinitsub&&+echo"foobar">sub/file&&+git-Csubaddfile&&+git-Csubcommit-m"add file"&&++gitinitparent&&+echo"foobar">parent/file&&+git-Cparentaddfile&&+mkdirparent/src&&+echo"foobar">parent/src/file2&&+git-Cparentaddsrc/file2&&+git-Cparentsubmoduleadd../sub&&+git-Cparentcommit-m"add files and submodule"&&++# From top works+cat>expect<<-\EOF&&+file:foobar+src/file2:foobar+sub/file:foobar+EOF+git-Cparentgrep--recurse-submodules-e"foobar">actual&&+test_cmpexpectactual&&++# Relative path to top errors out
From: Brandon Williams <hidden> Date: 2017-02-27 18:16:25
On 02/26, Duy Nguyen wrote:
On Sat, Feb 25, 2017 at 6:50 AM, Brandon Williams [off-list ref] wrote:
quoted
When using the --recurse-submodules flag with a relative pathspec which
includes "..", an error is produced inside the child process spawned for
a submodule. When creating the pathspec struct in the child, the ".."
is interpreted to mean "go up a directory" which causes an error stating
that the path ".." is outside of the repository.
While it is true that ".." is outside the scope of the submodule, it is
confusing to a user who originally invoked the command where ".." was
indeed still inside the scope of the superproject. Since the child
process luanched for the submodule has some context that it is operating
s/luanched/launched/
I would prefer 1/5 t to be merged with 3/5 though. The problem
We can definitely merge them and I agree that it may be easier for
looking through the logs if they are merged.
description is very light there, and the test demonstration in the
diff is simply switching from failure to success, which forces the
reader to come back here. It's easier to find here now, but it'll be a
bit harder when it enters master and we have to read it from git-log,
I think.
I'm still munching through the super-prefix patches. From how you
changed match_pathspec call in 0281e487fd (grep: optionally recurse
into submodules - 2016-12-16), I guess pathspecs should be handled
with super-prefix instead of the submodule's prefix (which is empty
anyway, I guess). The right solution wrt. handling relative paths may
be teach pathspec about super-prefix (and even original super's cwd)
then let it processes path in supermodule's context.
Does it handle relative paths with wildcards correctly btw? Ones that
cross submodules? I have a feeling it doesn't, but I haven't seen how
exactly super-prefix works yet.
I'm not 100% sure about the relative paths with wildcards. I did notice
that this series solves one problem and introduces another (recursing
from a subdirectory doesn't work with this series) so I need to
rethink the solution a little bit. And I'll take into account wildcards
as well.
There's another problem with passing pathspec from one process to
another. The issue with preserving the prefix, see 233c3e6c59
(parse_pathspec: preserve prefix length via PATHSPEC_PREFIX_ORIGIN -
2013-07-14). :(icase) needs this because given a path
"<prefix>/foobar", only the "foobar" part is considered case
insensitive, the prefix part is always case-sensitive. For example, if
you have 4 paths "abc/def", "abc/DEF", "ABC/def" and "ABC/DEF" and are
standing at "abc", you would want ":(icase)def" to match the first two
only, not all of them.
Hmm...yeah its a really difficult thing to get 100% correct (as I'm now
noticing). It also makes it a little more challenging because you don't
have the same state in both processes (child and parent). I'm thinking
I may have to a little bit more work, which is more involved, to
properly handle the pathspecs passed to the children. As in we may not
be able to pass the raw pathspec used in the parent to the child and
instead may have to do a little pre-processing on it.
quoted
underneath a superproject, this error could be avoided.
Signed-off-by: Brandon Williams <redacted>
---
t/t7814-grep-recurse-submodules.sh | 42 ++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
@@ -227,6 +227,48 @@ test_expect_success 'grep history with moved submoules' 'test_cmpexpectactual'+test_expect_failure'grep using relative path''+test_when_finished"rm -rf parent sub"&&+gitinitsub&&+echo"foobar">sub/file&&+git-Csubaddfile&&+git-Csubcommit-m"add file"&&++gitinitparent&&+echo"foobar">parent/file&&+git-Cparentaddfile&&+mkdirparent/src&&+echo"foobar">parent/src/file2&&+git-Cparentaddsrc/file2&&+git-Cparentsubmoduleadd../sub&&+git-Cparentcommit-m"add files and submodule"&&++# From top works+cat>expect<<-\EOF&&+file:foobar+src/file2:foobar+sub/file:foobar+EOF+git-Cparentgrep--recurse-submodules-e"foobar">actual&&+test_cmpexpectactual&&++# Relative path to top errors out
From: Brandon Williams <hidden> Date: 2017-02-27 18:56:38
On 02/24, Brandon Williams wrote:
It was discovered that when using the --recurse-submodules flag with `git grep`
and `git ls-files` and specifying a relative path when not at the root causes
the child processes spawned to error out with an error like:
fatal: ..: '..' is outside repository
While true that ".." is outside the scope of the submodule repository, it
probably doesn't make much sense to the user who gave that pathspec with
respect to the superproject. Since the child processes that are spawned to
handle the submodules have some context that they are executing underneath a
superproject (via the 'super_prefix'), they should be able to prevent dying
under this circumstance.
This series fixes this bug in both git grep and git ls-files as well as
correctly formatting the output from submodules to handle the relative paths
with "..".
One of the changes made to fix this was to add an additional flag for the
parse_pathspec() function in order to treat all paths provided as being from
the root of the repository. I hesitantly selected the name 'PATHSPEC_FROMROOT'
but I'm not fond of it since its too similar to the pathspec magic define
'PATHSPEC_FROMTOP'. So I'm open for naming suggestions.
Brandon Williams (5):
grep: illustrate bug when recursing with relative pathspec
pathspec: add PATHSPEC_FROMROOT flag
grep: fix bug when recuring with relative pathspec
ls-files: illustrate bug when recursing with relative pathspec
ls-files: fix bug when recuring with relative pathspec
builtin/grep.c | 8 ++++--
builtin/ls-files.c | 8 ++++--
pathspec.c | 2 +-
pathspec.h | 2 ++
t/t3007-ls-files-recurse-submodules.sh | 50 ++++++++++++++++++++++++++++++++++
t/t7814-grep-recurse-submodules.sh | 42 ++++++++++++++++++++++++++++
6 files changed, 107 insertions(+), 5 deletions(-)
Turns out that this series doesn't address all of the issues. This
series also seems to introduce broken behavior when recursing from a
subdirectory. So I need to think about this problem a little bit more
and reroll.
--
Brandon Williams
From: Brandon Williams <hidden> Date: 2017-03-06 23:16:35
When using the --recurse-submodules flag with a relative pathspec which
includes "..", an error is produced inside the child process spawned for
a submodule. When creating the pathspec struct in the child, the ".."
is interpreted to mean "go up a directory" which causes an error stating
that the path ".." is outside of the repository.
While it is true that ".." is outside the scope of the submodule, it is
confusing to a user who originally invoked the command where ".." was
indeed still inside the scope of the superproject. Since the child
process launched for the submodule has some context that it is operating
underneath a superproject, this error could be avoided.
This patch fixes the bug by passing the 'prefix' to the child process.
Now each child process that works on a submodule has two points of
reference to the superproject: (1) the 'super_prefix' which is the path
from the root of the superproject down to root of the submodule and (2)
the 'prefix' which is the path from the root of the superproject down to
the directory where the user invoked the git command.
With these two pieces of information a child process can correctly
interpret the pathspecs provided by the user as well as being able to
properly format the its output relative to the directory the user
invoked a git command from.
Signed-off-by: Brandon Williams <redacted>
---
After taking a closer look at this bug I determined that I did a poor job at
thinking of all the corner cases when implementing a recursive grep. As it
turns out I think we really need to pass on the prefix information to the child
process so that it has enough context to do path matching and to format its
output. Unfortunately I don't know the best way to pass on this information
without breaking other commands that rely on the GIT_PREFIX being overridden
during discovery. Maybe we'll need to add in another env var to account for
that? For the purposes of showing how to fix this bug while still getting the
test suite to pass, I have git respect the GIT_PREFIX env var only if the
super_prefix is set (which it should only be used in submodule operations at
this point in time). Its a pretty hacky fix, so I'm up for other suggestions
on how to properly pass on this information to the child process.
builtin/grep.c | 39 ++++++++++++--------
git.c | 2 --
setup.c | 5 +++
t/t7814-grep-recurse-submodules.sh | 73 ++++++++++++++++++++++++++++++++++++++
4 files changed, 102 insertions(+), 17 deletions(-)
@@ -361,8 +361,6 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)if(!help&&get_super_prefix()){if(!(p->option&SUPPORT_SUPER_PREFIX))die("%s doesn't support --super-prefix",p->cmd);-if(prefix)-die("can't use --super-prefix from a subdirectory");}if(!help&&p->option&NEED_WORK_TREE)
@@ -227,6 +227,79 @@ test_expect_success 'grep history with moved submoules' 'test_cmpexpectactual'+test_expect_success'grep using relative path''+test_when_finished"rm -rf parent sub"&&+gitinitsub&&+echo"foobar">sub/file&&+git-Csubaddfile&&+git-Csubcommit-m"add file"&&++gitinitparent&&+echo"foobar">parent/file&&+git-Cparentaddfile&&+mkdirparent/src&&+echo"foobar">parent/src/file2&&+git-Cparentaddsrc/file2&&+git-Cparentsubmoduleadd../sub&&+git-Cparentcommit-m"add files and submodule"&&++# From top works+cat>expect<<-\EOF&&+file:foobar+src/file2:foobar+sub/file:foobar+EOF+git-Cparentgrep--recurse-submodules-e"foobar">actual&&+test_cmpexpectactual&&++# Relative path to top errors out+cat>expect<<-\EOF&&+../file:foobar+file2:foobar+../sub/file:foobar+EOF+git-Cparent/srcgrep--recurse-submodules-e"foobar"--..>actual&&+test_cmpexpectactual&&++# Relative path to submodule errors out+cat>expect<<-\EOF&&+../sub/file:foobar+EOF+git-Cparent/srcgrep--recurse-submodules-e"foobar"--../sub>actual&&+test_cmpexpectactual+'++test_expect_success'grep from a subdir''+test_when_finished"rm -rf parent sub"&&+gitinitsub&&+echo"foobar">sub/file&&+git-Csubaddfile&&+git-Csubcommit-m"add file"&&++gitinitparent&&+mkdirparent/src&&+echo"foobar">parent/src/file&&+git-Cparentaddsrc/file&&+git-Cparentsubmoduleadd../subsrc/sub&&+git-Cparentsubmoduleadd../subsub&&+git-Cparentcommit-m"add files and submodules"&&++cat>expect<<-\EOF&&+src/file:foobar+src/sub/file:foobar+sub/file:foobar+EOF+git-Cparentgrep--recurse-submodules-e"foobar">actual&&+test_cmpexpectactual&&++cat>expect<<-\EOF&&+file:foobar+sub/file:foobar+EOF+git-Cparent/srcgrep--recurse-submodules-e"foobar">actual&&+test_cmpexpectactual+'+ test_incompatible_with_recurse_submodules(){test_expect_success"--recurse-submodules and $1 are incompatible""
From: Brandon Williams <hidden> Date: 2017-03-14 22:11:18
v2 of the series tackles the problem slightly differently than v1 did, and in a
less invasive way in my opinion. v1 also didn't fix everything.
v2 introduces a way to pass a 'prefix' that is respected by a git process.
This allows the git child processes (which operate on submodules) to have the
super_prefix (the path from the root of the superproject to the submodule) and
the prefix (path from the root of the superproject to the directory in which
the original command was launched). With these two pieces of information the
child process can correctly handle pathspec matching as well as correctly
formatting their output with relative paths.
In order to pass the prefix to a child I made a new env var since the existing
GIT_PREFIX isn't respected. I'm not sure this is the best method so I'm open
to ideas on the best way to convey this information to a child process.
Brandon Williams (4):
grep: fix help text typo
setup: allow for prefix to be passed to git commands
grep: fix bug when recursing with relative pathspec
ls-files: fix bug when recursing with relative pathspec
builtin/grep.c | 41 +++++++++++--------
builtin/ls-files.c | 41 ++++++++++---------
cache.h | 1 +
git.c | 2 -
setup.c | 6 +++
t/t3007-ls-files-recurse-submodules.sh | 39 ++++++++++++++++++
t/t7814-grep-recurse-submodules.sh | 75 ++++++++++++++++++++++++++++++++++
7 files changed, 167 insertions(+), 38 deletions(-)
--
2.12.0.367.g23dc2f6d3c-goog
@@ -979,7 +979,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)OPT_SET_INT(0,"exclude-standard",&opt_exclude,N_("ignore files specified via '.gitignore'"),1),OPT_BOOL(0,"recurse-submodules",&recurse_submodules,-N_("recursivley search in each submodule")),+N_("recursively search in each submodule")),OPT_STRING(0,"parent-basename",&parent_basename,N_("basename"),N_("prepend parent project's basename to output")),
From: Brandon Williams <hidden> Date: 2017-03-14 22:11:29
In a future patch child processes which act on submodules need a little
more context about the original command that was invoked. This patch
teaches git to use the prefix stored in `GIT_INTERNAL_TOPLEVEL_PREFIX`
if another prefix wasn't found during the git directory setup process.
---
cache.h | 1 +
git.c | 2 --
setup.c | 6 ++++++
3 files changed, 7 insertions(+), 2 deletions(-)
@@ -361,8 +361,6 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)if(!help&&get_super_prefix()){if(!(p->option&SUPPORT_SUPER_PREFIX))die("%s doesn't support --super-prefix",p->cmd);-if(prefix)-die("can't use --super-prefix from a subdirectory");}if(!help&&p->option&NEED_WORK_TREE)
From: Brandon Williams <hidden> Date: 2017-03-14 22:11:32
When using the --recurse-submodules flag with a relative pathspec which
includes "..", an error is produced inside the child process spawned for
a submodule. When creating the pathspec struct in the child, the ".."
is interpreted to mean "go up a directory" which causes an error stating
that the path ".." is outside of the repository.
While it is true that ".." is outside the scope of the submodule, it is
confusing to a user who originally invoked the command where ".." was
indeed still inside the scope of the superproject. Since the child
process launched for the submodule has some context that it is operating
underneath a superproject, this error could be avoided.
This patch fixes the bug by passing the 'prefix' to the child process.
Now each child process that works on a submodule has two points of
reference to the superproject: (1) the 'super_prefix' which is the path
from the root of the superproject down to root of the submodule and (2)
the 'prefix' which is the path from the root of the superproject down to
the directory where the user invoked the git command.
With these two pieces of information a child process can correctly
interpret the pathspecs provided by the user as well as being able to
properly format its output relative to the directory the user invoked
the original command from.
Signed-off-by: Brandon Williams <redacted>
---
builtin/grep.c | 39 ++++++++++++--------
t/t7814-grep-recurse-submodules.sh | 75 ++++++++++++++++++++++++++++++++++++++
2 files changed, 99 insertions(+), 15 deletions(-)
@@ -227,6 +227,81 @@ test_expect_success 'grep history with moved submoules' 'test_cmpexpectactual'+test_expect_success'grep using relative path''+test_when_finished"rm -rf parent sub"&&+gitinitsub&&+echo"foobar">sub/file&&+git-Csubaddfile&&+git-Csubcommit-m"add file"&&++gitinitparent&&+echo"foobar">parent/file&&+git-Cparentaddfile&&+mkdirparent/src&&+echo"foobar">parent/src/file2&&+git-Cparentaddsrc/file2&&+git-Cparentsubmoduleadd../sub&&+git-Cparentcommit-m"add files and submodule"&&++# From top works+cat>expect<<-\EOF&&+file:foobar+src/file2:foobar+sub/file:foobar+EOF+git-Cparentgrep--recurse-submodules-e"foobar">actual&&+test_cmpexpectactual&&++# Relative path to top+cat>expect<<-\EOF&&+../file:foobar+file2:foobar+../sub/file:foobar+EOF+git-Cparent/srcgrep--recurse-submodules-e"foobar"--..>actual&&+test_cmpexpectactual&&++# Relative path to submodule+cat>expect<<-\EOF&&+../sub/file:foobar+EOF+git-Cparent/srcgrep--recurse-submodules-e"foobar"--../sub>actual&&+test_cmpexpectactual+'++test_expect_success'grep from a subdir''+test_when_finished"rm -rf parent sub"&&+gitinitsub&&+echo"foobar">sub/file&&+git-Csubaddfile&&+git-Csubcommit-m"add file"&&++gitinitparent&&+mkdirparent/src&&+echo"foobar">parent/src/file&&+git-Cparentaddsrc/file&&+git-Cparentsubmoduleadd../subsrc/sub&&+git-Cparentsubmoduleadd../subsub&&+git-Cparentcommit-m"add files and submodules"&&++# Verify grep from root works+cat>expect<<-\EOF&&+src/file:foobar+src/sub/file:foobar+sub/file:foobar+EOF+git-Cparentgrep--recurse-submodules-e"foobar">actual&&+test_cmpexpectactual&&++# Verify grep from a subdir works+cat>expect<<-\EOF&&+file:foobar+sub/file:foobar+EOF+git-Cparent/srcgrep--recurse-submodules-e"foobar">actual&&+test_cmpexpectactual+'+ test_incompatible_with_recurse_submodules(){test_expect_success"--recurse-submodules and $1 are incompatible""
From: Brandon Williams <hidden> Date: 2017-03-14 22:11:34
When using the --recurse-submodules flag with a relative pathspec which
includes "..", an error is produced inside the child process spawned for a
submodule. When creating the pathspec struct in the child, the ".." is
interpreted to mean "go up a directory" which causes an error stating that the
path ".." is outside of the repository.
While it is true that ".." is outside the scope of the submodule, it is
confusing to a user who originally invoked the command where ".." was indeed
still inside the scope of the superproject. Since the child process launched
for the submodule has some context that it is operating underneath a
superproject, this error could be avoided.
This patch fixes the bug by passing the 'prefix' to the child process. Now
each child process that works on a submodule has two points of reference to the
superproject: (1) the 'super_prefix' which is the path from the root of the
superproject down to root of the submodule and (2) the 'prefix' which is the
path from the root of the superproject down to the directory where the user
invoked the git command.
With these two pieces of information a child process can correctly interpret
the pathspecs provided by the user as well as being able to properly format its
output relative to the directory the user invoked the original command from.
Signed-off-by: Brandon Williams <redacted>
---
builtin/ls-files.c | 41 +++++++++++++++++-----------------
t/t3007-ls-files-recurse-submodules.sh | 39 ++++++++++++++++++++++++++++++++
2 files changed, 60 insertions(+), 20 deletions(-)
@@ -188,6 +188,45 @@ test_expect_success '--recurse-submodules and pathspecs' 'test_cmpexpectactual'+test_expect_success'--recurse-submodules and relative paths''+# From subdir+cat>expect<<-\EOF&&+b+EOF+git-Cbls-files--recurse-submodules>actual&&+test_cmpexpectactual&&++# Relative path to top+cat>expect<<-\EOF&&+../.gitmodules+../a+b+../h.txt+../sib/file+../sub/file+../submodule/.gitmodules+../submodule/c+../submodule/f.TXT+../submodule/g.txt+../submodule/subsub/d+../submodule/subsub/e.txt+EOF+git-Cbls-files--recurse-submodules--..>actual&&+test_cmpexpectactual&&++# Relative path to submodule+cat>expect<<-\EOF&&+../submodule/.gitmodules+../submodule/c+../submodule/f.TXT+../submodule/g.txt+../submodule/subsub/d+../submodule/subsub/e.txt+EOF+git-Cbls-files--recurse-submodules--../submodule>actual&&+test_cmpexpectactual+'+ test_expect_success'--recurse-submodules does not support --error-unmatch''test_must_failgitls-files--recurse-submodules--error-unmatch2>actual&&test_i18ngrep"does not support --error-unmatch"actual
From: Johannes Schindelin <hidden> Date: 2017-03-14 22:28:44
Hi Brandon,
On Tue, 14 Mar 2017, Brandon Williams wrote:
In a future patch child processes which act on submodules need a little
more context about the original command that was invoked. This patch
teaches git to use the prefix stored in `GIT_INTERNAL_TOPLEVEL_PREFIX`
if another prefix wasn't found during the git directory setup process.
The commit message claims that env_prefix is used if no other prefix was
found, but this code ignores any prefix if the environment variable was
set.
Which version is correct?
Ciao,
Johannes
From: Brandon Williams <hidden> Date: 2017-03-14 22:35:40
On 03/14, Johannes Schindelin wrote:
Hi Brandon,
On Tue, 14 Mar 2017, Brandon Williams wrote:
quoted
In a future patch child processes which act on submodules need a little
more context about the original command that was invoked. This patch
teaches git to use the prefix stored in `GIT_INTERNAL_TOPLEVEL_PREFIX`
if another prefix wasn't found during the git directory setup process.
Missing SOB ;-)
Thanks for that catch. I'm expecting some discussion on this patch in
particular (and cc'd you since you've been working on this area of the
code) so I'll make sure to add it in the next reroll.
The commit message claims that env_prefix is used if no other prefix was
found, but this code ignores any prefix if the environment variable was
set.
Which version is correct?
Well, as you can tell I flip-flopped on what I thought the best course
of action would be. For my intentions (submodule-centric) I don't
believe they would ever both have a value so it doesn't matter to me
which it is. Though future users may want a particular order of
precedence.
@@ -979,7 +979,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)OPT_SET_INT(0,"exclude-standard",&opt_exclude,N_("ignore files specified via '.gitignore'"),1),OPT_BOOL(0,"recurse-submodules",&recurse_submodules,-N_("recursivley search in each submodule")),+N_("recursively search in each submodule")),OPT_STRING(0,"parent-basename",&parent_basename,N_("basename"),N_("prepend parent project's basename to output")),--
From: Stefan Beller <hidden> Date: 2017-03-14 23:03:59
On Tue, Mar 14, 2017 at 3:10 PM, Brandon Williams [off-list ref] wrote:
This patch fixes the bug by passing the 'prefix' to the child process.
Now each child process that works on a submodule has two points of
reference to the superproject: (1) the 'super_prefix' which is the path
from the root of the superproject down to root of the submodule and (2)
the 'prefix' which is the path from the root of the superproject down to
the directory where the user invoked the git command.
Would the information of this paragraph also be well suited in the
documentation?
(1) clarifies what the super prefix is.
(2) maybe the docs or this commit message should talk about
how the prefix is relayed, i.e. it doesn't set 'prefix' in the child,
but it reads GIT_TOPLEVEL_PREFIX_ENVIRONMENT and
acts on that as (2) ?
From: Stefan Beller <hidden> Date: 2017-03-14 23:06:56
On Tue, Mar 14, 2017 at 3:11 PM, Brandon Williams [off-list ref] wrote:
quoted hunk
When using the --recurse-submodules flag with a relative pathspec which
includes "..", an error is produced inside the child process spawned for a
submodule. When creating the pathspec struct in the child, the ".." is
interpreted to mean "go up a directory" which causes an error stating that the
path ".." is outside of the repository.
While it is true that ".." is outside the scope of the submodule, it is
confusing to a user who originally invoked the command where ".." was indeed
still inside the scope of the superproject. Since the child process launched
for the submodule has some context that it is operating underneath a
superproject, this error could be avoided.
This patch fixes the bug by passing the 'prefix' to the child process. Now
each child process that works on a submodule has two points of reference to the
superproject: (1) the 'super_prefix' which is the path from the root of the
superproject down to root of the submodule and (2) the 'prefix' which is the
path from the root of the superproject down to the directory where the user
invoked the git command.
With these two pieces of information a child process can correctly interpret
the pathspecs provided by the user as well as being able to properly format its
output relative to the directory the user invoked the original command from.
Signed-off-by: Brandon Williams <redacted>
---
builtin/ls-files.c | 41 +++++++++++++++++-----------------
t/t3007-ls-files-recurse-submodules.sh | 39 ++++++++++++++++++++++++++++++++
2 files changed, 60 insertions(+), 20 deletions(-)
Up to here we only rename a variable? If you want to help reviewers,
please separate this into two patches. One refactoring, stating it doesn't
change behavior; and the other adding the behavioral changes.
@@ -979,7 +979,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)OPT_SET_INT(0,"exclude-standard",&opt_exclude,N_("ignore files specified via '.gitignore'"),1),OPT_BOOL(0,"recurse-submodules",&recurse_submodules,-N_("recursivley search in each submodule")),+N_("recursively search in each submodule")),OPT_STRING(0,"parent-basename",&parent_basename,N_("basename"),N_("prepend parent project's basename to output")),--
From: Brandon Williams <hidden> Date: 2017-03-15 17:03:58
On 03/14, Stefan Beller wrote:
On Tue, Mar 14, 2017 at 3:11 PM, Brandon Williams [off-list ref] wrote:
quoted
When using the --recurse-submodules flag with a relative pathspec which
includes "..", an error is produced inside the child process spawned for a
submodule. When creating the pathspec struct in the child, the ".." is
interpreted to mean "go up a directory" which causes an error stating that the
path ".." is outside of the repository.
While it is true that ".." is outside the scope of the submodule, it is
confusing to a user who originally invoked the command where ".." was indeed
still inside the scope of the superproject. Since the child process launched
for the submodule has some context that it is operating underneath a
superproject, this error could be avoided.
This patch fixes the bug by passing the 'prefix' to the child process. Now
each child process that works on a submodule has two points of reference to the
superproject: (1) the 'super_prefix' which is the path from the root of the
superproject down to root of the submodule and (2) the 'prefix' which is the
path from the root of the superproject down to the directory where the user
invoked the git command.
With these two pieces of information a child process can correctly interpret
the pathspecs provided by the user as well as being able to properly format its
output relative to the directory the user invoked the original command from.
Signed-off-by: Brandon Williams <redacted>
---
builtin/ls-files.c | 41 +++++++++++++++++-----------------
t/t3007-ls-files-recurse-submodules.sh | 39 ++++++++++++++++++++++++++++++++
2 files changed, 60 insertions(+), 20 deletions(-)
Up to here we only rename a variable? If you want to help reviewers,
please separate this into two patches. One refactoring, stating it doesn't
change behavior; and the other adding the behavioral changes.
From: Brandon Williams <hidden> Date: 2017-03-17 17:23:23
When using the --recurse-submodules flag with a relative pathspec which
includes "..", an error is produced inside the child process spawned for
a submodule. When creating the pathspec struct in the child, the ".."
is interpreted to mean "go up a directory" which causes an error stating
that the path ".." is outside of the repository.
While it is true that ".." is outside the scope of the submodule, it is
confusing to a user who originally invoked the command where ".." was
indeed still inside the scope of the superproject. Since the child
process launched for the submodule has some context that it is operating
underneath a superproject, this error could be avoided.
This patch fixes the bug by passing the 'prefix' to the child process.
Now each child process that works on a submodule has two points of
reference to the superproject: (1) the 'super_prefix' which is the path
from the root of the superproject down to root of the submodule and (2)
the 'prefix' which is the path from the root of the superproject down to
the directory where the user invoked the git command.
With these two pieces of information a child process can correctly
interpret the pathspecs provided by the user as well as being able to
properly format its output relative to the directory the user invoked
the original command from.
Signed-off-by: Brandon Williams <redacted>
---
builtin/grep.c | 39 ++++++++++++--------
t/t7814-grep-recurse-submodules.sh | 75 ++++++++++++++++++++++++++++++++++++++
2 files changed, 99 insertions(+), 15 deletions(-)
@@ -227,6 +227,81 @@ test_expect_success 'grep history with moved submoules' 'test_cmpexpectactual'+test_expect_success'grep using relative path''+test_when_finished"rm -rf parent sub"&&+gitinitsub&&+echo"foobar">sub/file&&+git-Csubaddfile&&+git-Csubcommit-m"add file"&&++gitinitparent&&+echo"foobar">parent/file&&+git-Cparentaddfile&&+mkdirparent/src&&+echo"foobar">parent/src/file2&&+git-Cparentaddsrc/file2&&+git-Cparentsubmoduleadd../sub&&+git-Cparentcommit-m"add files and submodule"&&++# From top works+cat>expect<<-\EOF&&+file:foobar+src/file2:foobar+sub/file:foobar+EOF+git-Cparentgrep--recurse-submodules-e"foobar">actual&&+test_cmpexpectactual&&++# Relative path to top+cat>expect<<-\EOF&&+../file:foobar+file2:foobar+../sub/file:foobar+EOF+git-Cparent/srcgrep--recurse-submodules-e"foobar"--..>actual&&+test_cmpexpectactual&&++# Relative path to submodule+cat>expect<<-\EOF&&+../sub/file:foobar+EOF+git-Cparent/srcgrep--recurse-submodules-e"foobar"--../sub>actual&&+test_cmpexpectactual+'++test_expect_success'grep from a subdir''+test_when_finished"rm -rf parent sub"&&+gitinitsub&&+echo"foobar">sub/file&&+git-Csubaddfile&&+git-Csubcommit-m"add file"&&++gitinitparent&&+mkdirparent/src&&+echo"foobar">parent/src/file&&+git-Cparentaddsrc/file&&+git-Cparentsubmoduleadd../subsrc/sub&&+git-Cparentsubmoduleadd../subsub&&+git-Cparentcommit-m"add files and submodules"&&++# Verify grep from root works+cat>expect<<-\EOF&&+src/file:foobar+src/sub/file:foobar+sub/file:foobar+EOF+git-Cparentgrep--recurse-submodules-e"foobar">actual&&+test_cmpexpectactual&&++# Verify grep from a subdir works+cat>expect<<-\EOF&&+file:foobar+sub/file:foobar+EOF+git-Cparent/srcgrep--recurse-submodules-e"foobar">actual&&+test_cmpexpectactual+'+ test_incompatible_with_recurse_submodules(){test_expect_success"--recurse-submodules and $1 are incompatible""
From: Brandon Williams <hidden> Date: 2017-03-17 17:23:25
When using the --recurse-submodules flag with a relative pathspec which
includes "..", an error is produced inside the child process spawned for a
submodule. When creating the pathspec struct in the child, the ".." is
interpreted to mean "go up a directory" which causes an error stating that the
path ".." is outside of the repository.
While it is true that ".." is outside the scope of the submodule, it is
confusing to a user who originally invoked the command where ".." was indeed
still inside the scope of the superproject. Since the child process launched
for the submodule has some context that it is operating underneath a
superproject, this error could be avoided.
This patch fixes the bug by passing the 'prefix' to the child process. Now
each child process that works on a submodule has two points of reference to the
superproject: (1) the 'super_prefix' which is the path from the root of the
superproject down to root of the submodule and (2) the 'prefix' which is the
path from the root of the superproject down to the directory where the user
invoked the git command.
With these two pieces of information a child process can correctly interpret
the pathspecs provided by the user as well as being able to properly format its
output relative to the directory the user invoked the original command from.
Signed-off-by: Brandon Williams <redacted>
---
builtin/ls-files.c | 25 +++++++++++-----------
t/t3007-ls-files-recurse-submodules.sh | 39 ++++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+), 12 deletions(-)
@@ -188,6 +188,45 @@ test_expect_success '--recurse-submodules and pathspecs' 'test_cmpexpectactual'+test_expect_success'--recurse-submodules and relative paths''+# From subdir+cat>expect<<-\EOF&&+b+EOF+git-Cbls-files--recurse-submodules>actual&&+test_cmpexpectactual&&++# Relative path to top+cat>expect<<-\EOF&&+../.gitmodules+../a+b+../h.txt+../sib/file+../sub/file+../submodule/.gitmodules+../submodule/c+../submodule/f.TXT+../submodule/g.txt+../submodule/subsub/d+../submodule/subsub/e.txt+EOF+git-Cbls-files--recurse-submodules--..>actual&&+test_cmpexpectactual&&++# Relative path to submodule+cat>expect<<-\EOF&&+../submodule/.gitmodules+../submodule/c+../submodule/f.TXT+../submodule/g.txt+../submodule/subsub/d+../submodule/subsub/e.txt+EOF+git-Cbls-files--recurse-submodules--../submodule>actual&&+test_cmpexpectactual+'+ test_expect_success'--recurse-submodules does not support --error-unmatch''test_must_failgitls-files--recurse-submodules--error-unmatch2>actual&&test_i18ngrep"does not support --error-unmatch"actual
From: Brandon Williams <hidden> Date: 2017-03-17 17:23:27
In a future patch child processes which act on submodules need a little
more context about the original command that was invoked. This patch
teaches git to use the prefix stored in `GIT_INTERNAL_TOPLEVEL_PREFIX`
instead of the prefix that was potentally found during the git directory
setup process.
Signed-off-by: Brandon Williams <redacted>
---
cache.h | 1 +
git.c | 2 --
setup.c | 7 ++++++-
3 files changed, 7 insertions(+), 3 deletions(-)
@@ -361,8 +361,6 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)if(!help&&get_super_prefix()){if(!(p->option&SUPPORT_SUPER_PREFIX))die("%s doesn't support --super-prefix",p->cmd);-if(prefix)-die("can't use --super-prefix from a subdirectory");}if(!help&&p->option&NEED_WORK_TREE)
From: Brandon Williams <hidden> Date: 2017-03-17 17:23:28
Changes in v3:
* Added sign-off to the patches where it was missing.
* slight tweak to the style and commit msgs of a few patches.
* broke up the last patch (for ls-files) into a typo fix followed by fixing the
bug itself. This was to make the diff easier to review.
Brandon Williams (5):
grep: fix help text typo
setup: allow for prefix to be passed to git commands
grep: fix bug when recursing with relative pathspec
ls-files: fix typo in variable name
ls-files: fix bug when recursing with relative pathspec
builtin/grep.c | 41 +++++++++++--------
builtin/ls-files.c | 41 ++++++++++---------
cache.h | 1 +
git.c | 2 -
setup.c | 7 +++-
t/t3007-ls-files-recurse-submodules.sh | 39 ++++++++++++++++++
t/t7814-grep-recurse-submodules.sh | 75 ++++++++++++++++++++++++++++++++++
7 files changed, 167 insertions(+), 39 deletions(-)
--
2.12.0.367.g23dc2f6d3c-goog
@@ -979,7 +979,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)OPT_SET_INT(0,"exclude-standard",&opt_exclude,N_("ignore files specified via '.gitignore'"),1),OPT_BOOL(0,"recurse-submodules",&recurse_submodules,-N_("recursivley search in each submodule")),+N_("recursively search in each submodule")),OPT_STRING(0,"parent-basename",&parent_basename,N_("basename"),N_("prepend parent project's basename to output")),
so we load that GIT_TOPLEVEL_PREFIX_ENVIRONMENT prefix
first, such that we essentially copy it into GIT_PREFIX_ENVIRONMENT,
such that e.g. aliased commands will know about the superprefix, too.
ok, sounds reasonable to me; though I do not use this feature,
so my judgement is not as good.
Do we need a test for this behavior?
Thanks,
Stefan
so we load that GIT_TOPLEVEL_PREFIX_ENVIRONMENT prefix
first, such that we essentially copy it into GIT_PREFIX_ENVIRONMENT,
such that e.g. aliased commands will know about the superprefix, too.
I don't follow, this doesn't have anything to do with super-prefix.
s/superprefix/prefix as passed in via GIT_TOPLEVEL_PREFIX_ENVIRONMENT/
sorry for the confusion.
so we load that GIT_TOPLEVEL_PREFIX_ENVIRONMENT prefix
first, such that we essentially copy it into GIT_PREFIX_ENVIRONMENT,
such that e.g. aliased commands will know about the superprefix, too.
I don't follow, this doesn't have anything to do with super-prefix.
ok, sounds reasonable to me; though I do not use this feature,
so my judgement is not as good.
Do we need a test for this behavior?
Thanks,
Stefan
so we load that GIT_TOPLEVEL_PREFIX_ENVIRONMENT prefix
first, such that we essentially copy it into GIT_PREFIX_ENVIRONMENT,
such that e.g. aliased commands will know about the superprefix, too.
I don't follow, this doesn't have anything to do with super-prefix.
s/superprefix/prefix as passed in via GIT_TOPLEVEL_PREFIX_ENVIRONMENT/
sorry for the confusion.
Alternatively we could not copy it into GIT_PREFIX_ENVIRONMENT.
--
Brandon Williams
On Sat, Mar 18, 2017 at 12:22 AM, Brandon Williams [off-list ref] wrote:
With these two pieces of information a child process can correctly
interpret the pathspecs provided by the user as well as being able to
properly format its output relative to the directory the user invoked
the original command from.
This part can stand alone as a separate patch right? It would help
focus on the pathspec thingy first.
quoted hunk
@@ -399,13 +405,12 @@ static void run_pager(struct grep_opt *opt, const char *prefix) } static void compile_submodule_options(const struct grep_opt *opt,- const struct pathspec *pathspec,+ const char **argv, int cached, int untracked, int opt_exclude, int use_index, int pattern_type_arg) { struct grep_pat *pattern;- int i; if (recurse_submodules) argv_array_push(&submodule_options, "--recurse-submodules");
Side note. It would be awesome if you could make parse_options() (or a
new function) do the reverse process: given a 'struct option' with
valid data, spit out argv_array. Less worrying about git-grep having
new option but not passed to subgrep by accident. You can have a new
flag to tell it to ignore certain options if you don't want to pass
all.
--
Duy
From: Brandon Williams <hidden> Date: 2017-03-22 21:47:02
On 03/21, Duy Nguyen wrote:
On Sat, Mar 18, 2017 at 12:22 AM, Brandon Williams [off-list ref] wrote:
quoted
With these two pieces of information a child process can correctly
interpret the pathspecs provided by the user as well as being able to
properly format its output relative to the directory the user invoked
the original command from.
This part can stand alone as a separate patch right? It would help
focus on the pathspec thingy first.
I guess it could probably be factored out, though it is necessary for it
to work. The issue I was running into was that when no pathspecs were
given it would create a 'prefix' pathspec. So if we were in directory
'dir/' the pathspec that would get created would be:
ps.match = "dir/"
ps.original = "dir/"
Since it also set the original field it messed up when the child tried
to interpret the pathspecs again. I solved this by just passing the raw
pathspec through to the child.
quoted
@@ -399,13 +405,12 @@ static void run_pager(struct grep_opt *opt, const char *prefix) } static void compile_submodule_options(const struct grep_opt *opt,- const struct pathspec *pathspec,+ const char **argv, int cached, int untracked, int opt_exclude, int use_index, int pattern_type_arg) { struct grep_pat *pattern;- int i; if (recurse_submodules) argv_array_push(&submodule_options, "--recurse-submodules");
Side note. It would be awesome if you could make parse_options() (or a
new function) do the reverse process: given a 'struct option' with
valid data, spit out argv_array. Less worrying about git-grep having
new option but not passed to subgrep by accident. You can have a new
flag to tell it to ignore certain options if you don't want to pass
all.
I thought about this for a second but didn't pursue it very far. Mostly
because of how you would handle options with callback routines. Maybe
if you want the option to be reversible you need to have an additional
callback routine to do the conversion? I agree that having this sort of
functionality would be nice as it does save you from forgetting about
passing on options to a child process.
--
Brandon Williams