git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Jeff King <peff@peff.net>
Cc: Johannes Sixt <j6t@kdbg.org>,
	"brian m. carlson" <sandals@crustytoothpaste.net>,
	git@vger.kernel.org, Duy Nguyen <pclouds@gmail.com>,
	Jonathan Tan <jonathantanmy@google.com>,
	Eric Sunshine <sunshine@sunshineco.com>,
	Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH v2 01/10] t: add helper to convert object IDs to paths
Date: Wed, 19 Jun 2019 21:55:38 +0200 (CEST)	[thread overview]
Message-ID: <nycvar.QRO.7.76.6.1906192119380.44@tvgsbejvaqbjf.bet> (raw)
In-Reply-To: <20190618170416.GA14636@sigill.intra.peff.net>

Hi Peff,

On Tue, 18 Jun 2019, Jeff King wrote:

> 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

  reply	other threads:[~2019-06-19 19:55 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-16 18:53 [PATCH v2 00/10] Hash-independent tests, part 4 brian m. carlson
2019-06-16 18:53 ` [PATCH v2 01/10] t: add helper to convert object IDs to paths brian m. carlson
2019-06-17 19:05   ` Johannes Schindelin
2019-06-18  1:29     ` brian m. carlson
2019-06-18  6:14       ` Johannes Sixt
2019-06-18 16:15         ` Johannes Schindelin
2019-06-18 16:55           ` SZEDER Gábor
2019-06-19 19:56             ` Johannes Schindelin
2019-06-18 17:04           ` Jeff King
2019-06-19 19:55             ` Johannes Schindelin [this message]
2019-06-18 23:03         ` brian m. carlson
2019-06-16 18:53 ` [PATCH v2 02/10] t1410: make hash size independent brian m. carlson
2019-06-16 18:53 ` [PATCH v2 03/10] t1450: " brian m. carlson
2019-06-16 18:53 ` [PATCH v2 04/10] t5000: make hash independent brian m. carlson
2019-06-16 18:53 ` [PATCH v2 05/10] t6030: make test work with SHA-256 brian m. carlson
2019-06-16 18:53 ` [PATCH v2 06/10] t0027: make hash size independent brian m. carlson
2019-06-16 18:53 ` [PATCH v2 07/10] t0090: make test pass with SHA-256 brian m. carlson
2019-06-16 18:53 ` [PATCH v2 08/10] t1007: remove SHA1 prerequisites brian m. carlson
2019-06-16 18:53 ` [PATCH v2 09/10] t1710: make hash independent brian m. carlson
2019-06-16 18:53 ` [PATCH v2 10/10] t2203: avoid hard-coded object ID values brian m. carlson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=nycvar.QRO.7.76.6.1906192119380.44@tvgsbejvaqbjf.bet \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=jonathantanmy@google.com \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    --cc=sandals@crustytoothpaste.net \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).