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

Re: [PATCH v6 2/3] Makefile: add Perl runtime prefix support

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Mar 19, 2018, 19:21 UTC
Message-ID
<87y3inc1my.fsf@evledraar.gmail.com>
In-Reply-To
<20180319025046.58052-3-dnj@google.com>
On Mon, Mar 19 2018, Dan Jacques jotted:
Show 15 quoted lines
> +# 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.

Previous: Junio C HamanoNext: Daniel Jacques
Message 11 of 21 in “RUNTIME_PREFIX relocatable Git”
  1. 0/3 RUNTIME_PREFIX relocatable GitDan Jacques, Mar 19, 2018
  2. 1/3 Makefile: generate Perl header from template fileDan Jacques, Mar 19, 2018
  3. Eric SunshineMar 19, 2018
  4. 2/3 Makefile: add Perl runtime prefix supportDan Jacques, Mar 19, 2018
  5. Junio C HamanoMar 19, 2018
  6. Daniel JacquesMar 19, 2018
  7. Ævar Arnfjörð BjarmasonMar 19, 2018
  8. Daniel JacquesMar 19, 2018
  9. Daniel JacquesMar 19, 2018
  10. Junio C HamanoMar 19, 2018
  11. Ævar Arnfjörð BjarmasonMar 19, 2018
  12. Daniel JacquesMar 19, 2018
  13. Martin ÅgrenMar 19, 2018
  14. Daniel JacquesMar 19, 2018
  15. 3/3 exec_cmd: RUNTIME_PREFIX on some POSIX systemsDan Jacques, Mar 19, 2018
  16. Junio C HamanoMar 19, 2018
  17. Daniel JacquesMar 19, 2018
  18. Ævar Arnfjörð BjarmasonMar 19, 2018
  19. Daniel JacquesMar 19, 2018
  20. Junio C HamanoMar 19, 2018
  21. Ævar Arnfjörð BjarmasonMar 19, 2018

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.