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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux