All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Dan Jacques <dnj@google.com>
Cc: git@vger.kernel.org, gitster@pobox.com, Johannes.Schindelin@gmx.de
Subject: Re: [PATCH v6 2/3] Makefile: add Perl runtime prefix support
Date: Mon, 19 Mar 2018 20:21:25 +0100	[thread overview]
Message-ID: <87y3inc1my.fsf@evledraar.gmail.com> (raw)
In-Reply-To: <20180319025046.58052-3-dnj@google.com>


On Mon, Mar 19 2018, Dan Jacques jotted:


> +# BEGIN RUNTIME_PREFIX generated code.
> +#
> +# This finds our Git::* libraries relative to the script's runtime path.
> +sub __git_system_path {
> +	my ($relpath) = @_;
> +	my $gitexecdir_relative = '@@GITEXECDIR_REL@@';
> +
> +	# GIT_EXEC_PATH is supplied by `git` or the test suite.
> +	my $exec_path = $ENV{GIT_EXEC_PATH};
> +	if ($exec_path eq "") {
> +		# This can happen if this script is being directly invoked instead of run
> +		# by "git".
> +		require FindBin;
> +		$exec_path = $FindBin::Bin;
> +	}

I think it would be more idiomatic and more paranoid (we'll catch bugs)
to do:

    my $exec_path;
    if (exists $ENV{GIT_EXEC_PATH}) {
        $exec_path = $ENV{GIT_EXEC_PATH};
    } else {
        [...]
    }

I.e. we're interested if we got passed GIT_EXEC_PATH, so let's see if it
exists in the env hash, and then use it as-is. If we have some bug where
it's an empty string we'd like to know, presumably...

> +
> +	# Trim off the relative gitexecdir path to get the system path.
> +	(my $prefix = $exec_path) =~ s=${gitexecdir_relative}$==;

The path could contain regex metacharacters, so let's quote those via:

    (my $prefix = $exec_path) =~ s/\Q$gitexecdir_relative\E$//;

This also nicely gets us rid of the more verbose ${} form, which makes
esnse when we're doing ${foo}$ instead of the arguably less readbale
$foo$, but when it's \Q$foo\E$ it's clear what's going on.

  parent reply	other threads:[~2018-03-19 19:21 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-19  2:50 [PATCH v6 0/3] RUNTIME_PREFIX relocatable Git Dan Jacques
2018-03-19  2:50 ` [PATCH v6 1/3] Makefile: generate Perl header from template file Dan Jacques
2018-03-19  3:07   ` Eric Sunshine
2018-03-19  2:50 ` [PATCH v6 2/3] Makefile: add Perl runtime prefix support Dan Jacques
2018-03-19 17:14   ` Junio C Hamano
2018-03-19 17:21     ` Daniel Jacques
2018-03-19 19:12   ` Ævar Arnfjörð Bjarmason
2018-03-19 19:14     ` Daniel Jacques
2018-03-19 19:17       ` Daniel Jacques
2018-03-19 20:41         ` Junio C Hamano
2018-03-19 19:21   ` Ævar Arnfjörð Bjarmason [this message]
2018-03-19 19:47     ` Daniel Jacques
2018-03-19 21:32   ` Martin Ågren
2018-03-19 22:07     ` Daniel Jacques
2018-03-19  2:50 ` [PATCH v6 3/3] exec_cmd: RUNTIME_PREFIX on some POSIX systems Dan Jacques
2018-03-19 17:24   ` Junio C Hamano
2018-03-19 17:30     ` Daniel Jacques
2018-03-19 19:27   ` Ævar Arnfjörð Bjarmason
2018-03-19 19:38     ` Daniel Jacques
2018-03-19 17:02 ` [PATCH v6 0/3] RUNTIME_PREFIX relocatable Git Junio C Hamano
2018-03-19 19:30 ` Ævar Arnfjörð Bjarmason

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

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

  git send-email \
    --in-reply-to=87y3inc1my.fsf@evledraar.gmail.com \
    --to=avarab@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=dnj@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.