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

Re: [PATCH v2 01/10] t: add helper to convert object IDs to paths

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jun 19, 2019, 19:55 UTC
Message-ID
<nycvar.QRO.7.76.6.1906192119380.44@tvgsbejvaqbjf.bet>
In-Reply-To
<20190618170416.GA14636@sigill.intra.peff.net>
Hi Peff,
On Tue, 18 Jun 2019, Jeff King wrote:
Show 31 quoted lines
> On Tue, Jun 18, 2019 at 06:15:46PM +0200, Johannes Schindelin wrote:
>
> > > And looking through this patch series, I see a gazillion of *new*
> > > process substitutions $(test_something...) and $(basename $whatever).
> > > Can't we do something about it?
> >
> > I wish there was. Unix shell scripting has not evolved much in the past,
> > what, 3 decades? So I don't really see a way to "pass variables by
> > reference" to shell functions, short of calling `eval` (which buys
> > preciously little as it _also_ has to spawn a new process [*1*]).
>
> Really? An eval can impact the caller's state, so it _can't_ happen in a
> sub-process in most cases.
>
> E.g., if I run this:
>
> -- >8 --
> #!/bin/sh
>
> # usage: test_oid_to_path <var> <oid>
> # to set the variable <var> in the caller's environment to the path of <oid>
> test_oid_to_path() {
> 	path="${2%${2#??}}/${2#??}"
> 	eval "$1=\$path"
> }
>
> test_oid_to_path foo 1234abcd
> echo foo: $foo
> -- >8 --
>
> it all happens in a single process, under both bash and dash.

Oops. I think I may have read too much into the name `eval.c` in Dash's source code, I assumed that it was all about the `eval` command. But now that I look at this again, I see:

/*
 * Execute a command inside back quotes.  If it's a builtin command, we
 * want to save its output in a block obtained from malloc.  Otherwise
 * we fork off a subprocess and get the output of the command via a pipe.
 * Should be called with interrupts off.
 */
void
evalbackcmd(union node *n, struct backcmd *result)
{
	[...]

I saw this at https://git.kernel.org/pub/scm/utils/dash/dash.git/tree/src/eval.c#n608

So this is actually about `$(...)` (or the old, non-nestable backtick version of it) and not about `eval`.

And of course I was also making another incorrect connection to the Perl command `eval` which allows you to catch code that `die()`s (which *must* run in a subprocess).

So yeah, I guess `eval` would work here to avoid the `$(...)` constructs.

Sorry for the noise, Dscho

Previous: Jeff KingNext: brian m. carlson
Message 10 of 20 in “Hash-independent tests, part 4”
  1. 00/10 Hash-independent tests, part 4brian m. carlson, Jun 16, 2019
  2. 01/10 t: add helper to convert object IDs to pathsbrian m. carlson, Jun 16, 2019
  3. Johannes SchindelinJun 17, 2019
  4. brian m. carlsonJun 18, 2019
  5. Johannes SixtJun 18, 2019
  6. Johannes SchindelinJun 18, 2019
  7. SZEDER GáborJun 18, 2019
  8. Johannes SchindelinJun 19, 2019
  9. Jeff KingJun 18, 2019
  10. Johannes SchindelinJun 19, 2019
  11. brian m. carlsonJun 18, 2019
  12. 02/10 t1410: make hash size independentbrian m. carlson, Jun 16, 2019
  13. 03/10 t1450: make hash size independentbrian m. carlson, Jun 16, 2019
  14. 04/10 t5000: make hash independentbrian m. carlson, Jun 16, 2019
  15. 06/10 t0027: make hash size independentbrian m. carlson, Jun 16, 2019
  16. 05/10 t6030: make test work with SHA-256brian m. carlson, Jun 16, 2019
  17. 07/10 t0090: make test pass with SHA-256brian m. carlson, Jun 16, 2019
  18. 08/10 t1007: remove SHA1 prerequisitesbrian m. carlson, Jun 16, 2019
  19. 09/10 t1710: make hash independentbrian m. carlson, Jun 16, 2019
  20. 10/10 t2203: avoid hard-coded object ID valuesbrian m. carlson, Jun 16, 2019

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.