git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: What's cooking in git.git (Nov 2016, #06; Mon, 28)

From
Jeff King <peff@peff.net>
Date
Nov 30, 2016, 23:59 UTC
Message-ID
<20161130235952.4j63gkdlbobjitdb@sigill.intra.peff.net>
In-Reply-To
<20161130234636.6az7xfywzprpn6ly@sigill.intra.peff.net>
On Wed, Nov 30, 2016 at 06:46:36PM -0500, Jeff King wrote:
Show 5 quoted lines
> > For now the work around could be to just pass "-C <dir>" to the child
> > process instead of relying on run-command to chdir.
> 
> Yeah, that would push it after the exec. I just don't understand why
> that would be necessary.

Hmm. It still seems to fail, even with the workaround (the patch in run-command is there to make sure there's not some other call that we're not catching):

diff --git a/builtin/grep.c b/builtin/grep.c
index 2c727ef49..3323a3e7f 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -553,6 +553,7 @@ static int grep_submodule_launch(struct grep_opt *opt,
 	argv_array_pushf(&cp.args, "--super-prefix=%s%s/",
 			 super_prefix ? super_prefix : "",
 			 name);
+	argv_array_pushl(&cp.args, "-C", gs->path, NULL);
 	argv_array_push(&cp.args, "grep");
 
 	/*
@@ -586,7 +587,6 @@ static int grep_submodule_launch(struct grep_opt *opt,
 	}
 
 	cp.git_cmd = 1;
-	cp.dir = gs->path;
 
 	/*
 	 * Capture output to output buffer and check the return code from the
diff --git a/run-command.c b/run-command.c
index 5a4dbb66d..d040f4f77 100644
--- a/run-command.c
+++ b/run-command.c
@@ -393,6 +393,8 @@ int start_command(struct child_process *cmd)
 			close(cmd->out);
 		}
 
+		if (cmd->dir && git_env_bool("GIT_NO_CHDIR", 0))
+			die("temporarily disallowing chdir");
 		if (cmd->dir && chdir(cmd->dir))
 			die_errno("exec '%s': cd to '%s' failed", cmd->argv[0],
 			    cmd->dir);
diff --git a/t/t7814-grep-recurse-submodules.sh b/t/t7814-grep-recurse-submodules.sh
index 050777186..591ff74ed 100755
--- a/t/t7814-grep-recurse-submodules.sh
+++ b/t/t7814-grep-recurse-submodules.sh
@@ -175,7 +175,7 @@ test_expect_success 'grep recurse submodule colon in name' '
 	fi:le:foobar
 	su:b/fi:le:foobar
 	EOF
-	git -C parent grep -e "foobar" --recurse-submodules >actual &&
+	GIT_NO_CHDIR=1 strace -o foo.out -f git -C parent grep -e "foobar" --recurse-submodules >actual &&
 	test_cmp expect actual &&
 
 	cat >expect <<-\EOF &&


So I think there is some other chdir(). I'm not sure if there is an easy
way to get a backtrace on every call to chdir() in every thread. I'm
sure somebody more clever than me could figure out how to make gdb do it
automatically, but it might be workable manually. I think the chdir was
in the main thread.

-Peff
Previous: Brandon WilliamsNext: Jeff King
Message 12 of 34 in “What's cooking in git.git (Nov 2016, #06; Mon, 28)”
  1. Junio C HamanoNov 29, 2016
  2. Brandon WilliamsNov 29, 2016
  3. Jeff KingNov 29, 2016
  4. Jeff KingNov 29, 2016
  5. Brandon WilliamsNov 30, 2016
  6. Brandon WilliamsNov 30, 2016
  7. Jeff KingNov 30, 2016
  8. Jeff KingNov 30, 2016
  9. Brandon WilliamsNov 30, 2016
  10. Jeff KingNov 30, 2016
  11. Brandon WilliamsNov 30, 2016
  12. Jeff KingNov 30, 2016
  13. Jeff KingDec 1, 2016
  14. Brandon WilliamsDec 1, 2016
  15. Stefan BellerDec 1, 2016
  16. Brandon WilliamsDec 1, 2016
  17. Jeff KingDec 1, 2016
  18. Brandon WilliamsDec 1, 2016
  19. Stefan BellerNov 30, 2016
  20. Johannes SixtDec 1, 2016
  21. Jeff KingDec 1, 2016
  22. Jeff KingNov 29, 2016
  23. Junio C HamanoNov 29, 2016
  24. Jeff KingNov 29, 2016
  25. Stefan BellerNov 29, 2016
  26. Junio C HamanoNov 29, 2016
  27. Stefan BellerNov 29, 2016
  28. Stefan BellerNov 30, 2016
  29. bw/transport-protocol-policyJeff King, Dec 1, 2016
  30. Brandon WilliamsDec 1, 2016
  31. Jeff KingDec 1, 2016
  32. Brandon WilliamsDec 1, 2016
  33. Jeff KingDec 1, 2016
  34. Brandon WilliamsDec 1, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.