{"thread":{"id":"48078","subject":"[PATCH v6 0/3] RUNTIME_PREFIX relocatable Git","startedAt":"2018-03-19T02:50:59Z","lastAt":"2018-03-19T22:07:22Z","messageCount":21,"participants":["Dan Jacques","Eric Sunshine","Junio C Hamano","Daniel Jacques","Ævar Arnfjörð Bjarmason","Martin Ågren"],"isPatch":true,"patchVersion":6,"patchTotal":3},"messages":[{"id":"342124","messageId":"20180319025046.58052-1-dnj@google.com","threadId":"48078","inReplyTo":null,"subject":"[PATCH v6 0/3] RUNTIME_PREFIX relocatable Git","fromName":"Dan Jacques","fromEmail":"dnj@google.com","sentAt":"2018-03-19T02:50:43Z","receivedAt":"2018-03-19T02:50:59Z","isPatch":true,"sender":{"key":"dnj@google.com","avatar":"https://avatars.githubusercontent.com/u/9965104?v=4"},"body":"This patch set expands support for the RUNTIME_PREFIX configuration flag,\ncurrently only used on Windows builds, to include Linux, Darwin, and\nFreeBSD. When Git is built with RUNTIME_PREFIX enabled, it resolves its\nancillary paths relative to the runtime location of its executable\nrather than hard-coding them at compile-time, allowing a Git\ninstallation to be deployed to a path other than the one in which it\nwas built/installed.\n\nNote that RUNTIME_PREFIX is not currently used outside of Windows.\nThis patch set should not have an impact on default Git builds.\n\nI'm dusting this back off now that avarab@'s Perl Makefile simplification\npatch set has landed. It's been a few months, so I'm a bit rusty, but I think\nthat I've incorporated all of the feedback. Please take a look and let me know\nwhat you think!\n\nPrevious threads:\nv1: https://public-inbox.org/git/20171116170523.28696-1-dnj@google.com/\nv2: https://public-inbox.org/git/20171119173141.4896-1-dnj@google.com/\nv3: https://public-inbox.org/git/20171127164055.93283-1-dnj@google.com/\nv4: https://public-inbox.org/git/20171129223807.91343-1-dnj@google.com/\nv5: https://public-inbox.org/git/20180108030239.92036-1-dnj@google.com/\n\nChanges in v6 from v5:\n\n- Rebased on top of \"master\".\n- Updated commit messages.\n- Updated runtime prefix Perl header comment and code to clarify when and\n  why FindBin is used.\n- With Johannes' blessing on Git-for-Windows, folded \"RUNTIME_PREFIX_PERL\"\n  functionality into \"RUNTIME_PREFIX\".\n- Updated \"run-command\" test to accommodate RUNTIME_PREFIX trace messages.\n\n=== Testing ===\n\nThe latest patch set is available for testing on my GitHub fork, including\n\"travis.ci\" testing. The \"runtime-prefix\" branch includes a \"config.mak\"\ncommit that enables runtime prefix for the Travis build; the\n\"runtime-prefix-no-config\" omits this file, testing this patch without\nruntime prefix enabled:\n- https://github.com/danjacques/git/tree/runtime-prefix\n- https://github.com/danjacques/git/tree/runtime-prefix-no-config\n- https://travis-ci.org/danjacques/git/branches\n\nBuilt/tested locally using this \"config.mak\" w/ autoconf:\n\n=== Example config.mak ===\n\n## (BEGIN config.mak)\n\nRUNTIME_PREFIX = YesPlease\nRUNTIME_PREFIX_PERL = YesPlease\ngitexecdir = libexec/git-core\ntemplate_dir = share/git-core/templates\nsysconfdir = etc\n\n## (END config.mak)\n\n=== Revision History ===\n\nChanges in v5 from v4:\n\n- Rebase on top of \"next\", notably incorporating the\n  \"ab/simplify-perl-makefile\" branch.\n- Cleaner Makefile relative path enforcement.\n- Update Perl header template path now that the \"perl/\" directory has\n  fewer build-related files in it.\n- Update Perl runtime prefix header to use a general system path resolution\n  function.\n- Implemented the injection of the locale directory into Perl's\n  \"Git/I18N.pm\" module from the runtime prefix Perl script header.\n- Updated Perl's \"Git/I18N.pm\" module to accept injected locale directory.\n- Added more content to some comments.\n\n\nChanges in v4 from v3:\n\n- Incorporated some quoting and Makefile dependency fixes, courtesy of\n  <johannes.schindelin@gmx.de>.\n\nChanges in v3 from v2:\n\n- Broken into multiple patches now that Perl is isolated in its own\n  RUNTIME_PREFIX_PERL flag.\n- Working with avarab@, several changes to Perl script runtime prefix\n  support:\n  - Moved Perl header body content from Makefile into external template\n    file(s).\n  - Added generic \"perllibdir\" variable to override Perl installation\n    path.\n  - RUNTIME_PREFIX_PERL generated script header is more descriptive and\n    consistent with how the C version operates.\n  - Fixed Generated Perl header Makefile dependency, should rebuild\n    when dependent files and flags change.\n- Changed some of the new RUNTIME_PREFIX trace strings to use consistent\n  formatting and terminology.\n\nChanges in v2 from v1:\n\n- Added comments and formatting to improve readability of\n  platform-sepecific executable path resolution sleds in\n  `git_get_exec_path`.\n- Consolidated \"cached_exec_path\" and \"argv_exec_path\" globals\n  into \"exec_path_value\".\n- Use `strbuf_realpath` instead of `realpath` for procfs resolution.\n- Removed new environment variable exports. Git with RUNTIME_PREFIX no\n  longer exports or consumes any additional environment information.\n- Updated Perl script resolution strategy: rather than having Git export\n  the relative executable path to the Perl scripts, they now resolve\n  it independently when RUNTIME_PREFIX_PERL is enabled.\n- Updated resolution strategy for \"gettext()\": use system_path() instead\n  of special environment variable.\n- Added `sysctl` executable resolution support for BSDs that don't\n  mount \"procfs\" by default (most of them).\n\nDan Jacques (3):\n  Makefile: generate Perl header from template file\n  Makefile: add Perl runtime prefix support\n  exec_cmd: RUNTIME_PREFIX on some POSIX systems\n\n .gitignore                                       |   1 +\n Makefile                                         | 120 +++++++++--\n cache.h                                          |   1 +\n common-main.c                                    |   4 +-\n config.mak.uname                                 |   7 +\n exec_cmd.c                                       | 241 ++++++++++++++++++++---\n exec_cmd.h                                       |   4 +-\n gettext.c                                        |   8 +-\n git.c                                            |   2 +-\n perl/Git/I18N.pm                                 |   2 +-\n perl/header_templates/fixed_prefix.template.pl   |   1 +\n perl/header_templates/runtime_prefix.template.pl |  40 ++++\n t/t0061-run-command.sh                           |   2 +-\n 13 files changed, 379 insertions(+), 54 deletions(-)\n create mode 100644 perl/header_templates/fixed_prefix.template.pl\n create mode 100644 perl/header_templates/runtime_prefix.template.pl\n\n-- \n2.15.0.chromium12\n\n"},{"id":"342125","messageId":"20180319025046.58052-2-dnj@google.com","threadId":"48078","inReplyTo":"20180319025046.58052-1-dnj@google.com","subject":"[PATCH v6 1/3] Makefile: generate Perl header from template file","fromName":"Dan Jacques","fromEmail":"dnj@google.com","sentAt":"2018-03-19T02:50:44Z","receivedAt":"2018-03-19T02:51:05Z","isPatch":true,"sender":{"key":"dnj@google.com","avatar":"https://avatars.githubusercontent.com/u/9965104?v=4"},"body":"Currently, the generated Perl script headers are emitted by commands in\nthe Makefile. This mechanism restricts options to introduce alternative\nheader content, needed by Perl runtime prefix support, and obscures the\norigin of the Perl script header.\n\nChange the Makefile to generate a header by processing a template file and\nmove the header content into the \"perl/\" subdirectory. The processed\ngenerated will now be stored in the \"GIT-PERL-HEADER\" file. This allows\nthe content of the Perl header to be controlled by changing the path of\nthe template in the Makefile.\n\nSigned-off-by: Dan Jacques <dnj@google.com>\nThanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\nThanks-to: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n .gitignore                                     |  1 +\n Makefile                                       | 27 +++++++++++++++-----------\n perl/header_templates/fixed_prefix.template.pl |  1 +\n 3 files changed, 18 insertions(+), 11 deletions(-)\n create mode 100644 perl/header_templates/fixed_prefix.template.pl\n\ndiff --git a/.gitignore b/.gitignore\nindex 833ef3b0b..89bd7bd8a 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -3,6 +3,7 @@\n /GIT-LDFLAGS\n /GIT-PREFIX\n /GIT-PERL-DEFINES\n+/GIT-PERL-HEADER\n /GIT-PYTHON-VARS\n /GIT-SCRIPT-DEFINES\n /GIT-USER-AGENT\ndiff --git a/Makefile b/Makefile\nindex a1d8775ad..e479822ce 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1975,20 +1975,15 @@ git.res: git.rc GIT-VERSION-FILE\n $(SCRIPT_PERL_GEN): GIT-BUILD-OPTIONS\n \n ifndef NO_PERL\n-$(SCRIPT_PERL_GEN):\n-\n+PERL_HEADER_TEMPLATE = perl/header_templates/fixed_prefix.template.pl\n PERL_DEFINES = $(PERL_PATH_SQ):$(PERLLIB_EXTRA_SQ):$(perllibdir_SQ)\n-$(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-VERSION-FILE\n+\n+$(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE\n \t$(QUIET_GEN)$(RM) $@ $@+ && \\\n-\tINSTLIBDIR='$(perllibdir_SQ)' && \\\n-\tINSTLIBDIR_EXTRA='$(PERLLIB_EXTRA_SQ)' && \\\n-\tINSTLIBDIR=\"$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}\" && \\\n \tsed -e '1{' \\\n \t    -e '\ts|#!.*perl|#!$(PERL_PATH_SQ)|' \\\n-\t    -e '\th' \\\n-\t    -e '\ts=.*=use lib (split(/$(pathsep)/, $$ENV{GITPERLLIB} || \"'\"$$INSTLIBDIR\"'\"));=' \\\n-\t    -e '\tH' \\\n-\t    -e '\tx' \\\n+\t    -e '\trGIT-PERL-HEADER' \\\n+\t    -e '\tG' \\\n \t    -e '}' \\\n \t    -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n \t    $< >$@+ && \\\n@@ -2002,6 +1997,16 @@ GIT-PERL-DEFINES: FORCE\n \t\techo \"$$FLAGS\" >$@; \\\n \t    fi\n \n+GIT-PERL-HEADER: $(PERL_HEADER_TEMPLATE) GIT-PERL-DEFINES Makefile\n+\t$(QUIET_GEN)$(RM) $@ && \\\n+\tINSTLIBDIR='$(perllibdir_SQ)' && \\\n+\tINSTLIBDIR_EXTRA='$(PERLLIB_EXTRA_SQ)' && \\\n+\tINSTLIBDIR=\"$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}\" && \\\n+\tsed -e 's=@@PATHSEP@@=$(pathsep)=g' \\\n+\t    -e 's=@@INSTLIBDIR@@='$$INSTLIBDIR'=g' \\\n+\t    -e 's=@@PERLLIBDIR@@='$(perllibdir_SQ)'=g' \\\n+\t    $< >$@+ && \\\n+\tmv $@+ $@\n \n .PHONY: gitweb\n gitweb:\n@@ -2770,7 +2775,7 @@ ifndef NO_TCLTK\n endif\n \t$(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-LDFLAGS GIT-BUILD-OPTIONS\n \t$(RM) GIT-USER-AGENT GIT-PREFIX\n-\t$(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PYTHON-VARS\n+\t$(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PERL-HEADER GIT-PYTHON-VARS\n \n .PHONY: all install profile-clean clean strip\n .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell\ndiff --git a/perl/header_templates/fixed_prefix.template.pl b/perl/header_templates/fixed_prefix.template.pl\nnew file mode 100644\nindex 000000000..857b4391a\n--- /dev/null\n+++ b/perl/header_templates/fixed_prefix.template.pl\n@@ -0,0 +1 @@\n+use lib (split(/@@PATHSEP@@/, $ENV{GITPERLLIB} || '@@INSTLIBDIR@@'));\n-- \n2.15.0.chromium12\n\n"},{"id":"342126","messageId":"20180319025046.58052-3-dnj@google.com","threadId":"48078","inReplyTo":"20180319025046.58052-1-dnj@google.com","subject":"[PATCH v6 2/3] Makefile: add Perl runtime prefix support","fromName":"Dan Jacques","fromEmail":"dnj@google.com","sentAt":"2018-03-19T02:50:45Z","receivedAt":"2018-03-19T02:51:08Z","isPatch":true,"sender":{"key":"dnj@google.com","avatar":"https://avatars.githubusercontent.com/u/9965104?v=4"},"body":"Add a new Makefile flag, RUNTIME_PREFIX_PERL, which, when enabled,\nconfigures Perl scripts to locate the Git installation's Perl support\nlibraries by resolving against the script's path, rather than\nhard-coding that path at build-time.\n\nRUNTIME_PREFIX_PERL requires that system paths are expressed relative to\na common installation directory, and uses that relationship to locate\nsupport files based on the known starting point of the script being\nexecuted, much like RUNTIME_PREFIX does for the Git binary.\n\nThis change enables Git's Perl scripts to work when their Git installation\nis relocated or moved to another system.\n\nSigned-off-by: Dan Jacques <dnj@google.com>\nThanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\nThanks-to: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n Makefile                                         | 67 +++++++++++++++++++++++-\n perl/Git/I18N.pm                                 |  2 +-\n perl/header_templates/runtime_prefix.template.pl | 40 ++++++++++++++\n 3 files changed, 107 insertions(+), 2 deletions(-)\n create mode 100644 perl/header_templates/runtime_prefix.template.pl\n\ndiff --git a/Makefile b/Makefile\nindex e479822ce..101a98a78 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -434,6 +434,13 @@ all::\n #\n # When cross-compiling, define HOST_CPU as the canonical name of the CPU on\n # which the built Git will run (for instance \"x86_64\").\n+#\n+# Define RUNTIME_PREFIX to configure Git to resolve its ancillary tooling and\n+# support files relative to the location of the runtime binary, rather than\n+# hard-coding them into the binary. Git installations built with RUNTIME_PREFIX\n+# can be moved to arbitrary filesystem locations. RUNTIME_PREFIX also causes\n+# Perl scripts to use a modified entry point header allowing them to resolve\n+# support files at runtime.\n \n GIT-VERSION-FILE: FORCE\n \t@$(SHELL_PATH) ./GIT-VERSION-GEN\n@@ -471,6 +478,8 @@ ARFLAGS = rcs\n #   mandir\n #   infodir\n #   htmldir\n+#   localedir\n+#   perllibdir\n # This can help installing the suite in a relocatable way.\n \n prefix = $(HOME)\n@@ -492,9 +501,12 @@ lib = lib\n # DESTDIR =\n pathsep = :\n \n+gitexecdir_relative = $(patsubst $(prefix)/%,%,$(gitexecdir))\n mandir_relative = $(patsubst $(prefix)/%,%,$(mandir))\n infodir_relative = $(patsubst $(prefix)/%,%,$(infodir))\n+localedir_relative = $(patsubst $(prefix)/%,%,$(localedir))\n htmldir_relative = $(patsubst $(prefix)/%,%,$(htmldir))\n+perllibdir_relative = $(patsubst $(prefix)/%,%,$(perllibdir))\n \n export prefix bindir sharedir sysconfdir gitwebdir perllibdir localedir\n \n@@ -1740,10 +1752,13 @@ mandir_relative_SQ = $(subst ','\\'',$(mandir_relative))\n infodir_relative_SQ = $(subst ','\\'',$(infodir_relative))\n perllibdir_SQ = $(subst ','\\'',$(perllibdir))\n localedir_SQ = $(subst ','\\'',$(localedir))\n+localedir_relative_SQ = $(subst ','\\'',$(localedir_relative))\n gitexecdir_SQ = $(subst ','\\'',$(gitexecdir))\n+gitexecdir_relative_SQ = $(subst ','\\'',$(gitexecdir_relative))\n template_dir_SQ = $(subst ','\\'',$(template_dir))\n htmldir_relative_SQ = $(subst ','\\'',$(htmldir_relative))\n prefix_SQ = $(subst ','\\'',$(prefix))\n+perllibdir_relative_SQ = $(subst ','\\'',$(perllibdir_relative))\n gitwebdir_SQ = $(subst ','\\'',$(gitwebdir))\n \n SHELL_PATH_SQ = $(subst ','\\'',$(SHELL_PATH))\n@@ -1754,6 +1769,31 @@ TCLTK_PATH_SQ = $(subst ','\\'',$(TCLTK_PATH))\n DIFF_SQ = $(subst ','\\'',$(DIFF))\n PERLLIB_EXTRA_SQ = $(subst ','\\'',$(PERLLIB_EXTRA))\n \n+# RUNTIME_PREFIX's resolution logic requires resource paths to be expressed\n+# relative to each other and share an installation path.\n+#\n+# This is a dependnecy in:\n+# - Git's binary RUNTIME_PREFIX logic in (see \"exec_cmd.c\").\n+# - The runtime prefix Perl header (see\n+#   \"perl/header_templates/runtime_prefix.template.pl\").\n+ifdef RUNTIME_PREFIX\n+\n+ifneq ($(filter /%,$(firstword $(gitexecdir_relative))),)\n+$(error RUNTIME_PREFIX requires a relative gitexecdir, not: $(gitexecdir))\n+endif\n+\n+ifneq ($(filter /%,$(firstword $(localedir_relative))),)\n+$(error RUNTIME_PREFIX requires a relative localedir, not: $(localedir))\n+endif\n+\n+ifndef NO_PERL\n+ifneq ($(filter /%,$(firstword $(perllibdir_relative))),)\n+$(error RUNTIME_PREFIX requires a relative perllibdir, not: $(perllibdir))\n+endif\n+endif\n+\n+endif\n+\n # We must filter out any object files from $(GITLIBS),\n # as it is typically used like:\n #\n@@ -1974,10 +2014,31 @@ git.res: git.rc GIT-VERSION-FILE\n # This makes sure we depend on the NO_PERL setting itself.\n $(SCRIPT_PERL_GEN): GIT-BUILD-OPTIONS\n \n+# Used for substitution in Perl modules. Disabled when using RUNTIME_PREFIX\n+# since the locale directory is injected.\n+perl_localedir_SQ = $(localedir_SQ)\n+\n ifndef NO_PERL\n PERL_HEADER_TEMPLATE = perl/header_templates/fixed_prefix.template.pl\n PERL_DEFINES = $(PERL_PATH_SQ):$(PERLLIB_EXTRA_SQ):$(perllibdir_SQ)\n \n+PERL_DEFINES := $(PERL_PATH_SQ) $(PERLLIB_EXTRA_SQ) $(perllibdir_SQ)\n+PERL_DEFINES += $(RUNTIME_PREFIX)\n+\n+# Support Perl runtime prefix. In this mode, a different header is installed\n+# into Perl scripts.\n+ifdef RUNTIME_PREFIX\n+\n+PERL_HEADER_TEMPLATE = perl/header_templates/runtime_prefix.template.pl\n+\n+# Don't export a fixed $(localedir) path; it will be resolved by the Perl header\n+# at runtime.\n+perl_localedir_SQ =\n+\n+endif\n+\n+PERL_DEFINES += $(gitexecdir) $(perllibdir) $(localedir)\n+\n $(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE\n \t$(QUIET_GEN)$(RM) $@ $@+ && \\\n \tsed -e '1{' \\\n@@ -1990,6 +2051,7 @@ $(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE\n \tchmod +x $@+ && \\\n \tmv $@+ $@\n \n+PERL_DEFINES := $(subst $(space),:,$(PERL_DEFINES))\n GIT-PERL-DEFINES: FORCE\n \t@FLAGS='$(PERL_DEFINES)'; \\\n \t    if test x\"$$FLAGS\" != x\"`cat $@ 2>/dev/null`\" ; then \\\n@@ -2005,6 +2067,9 @@ GIT-PERL-HEADER: $(PERL_HEADER_TEMPLATE) GIT-PERL-DEFINES Makefile\n \tsed -e 's=@@PATHSEP@@=$(pathsep)=g' \\\n \t    -e 's=@@INSTLIBDIR@@='$$INSTLIBDIR'=g' \\\n \t    -e 's=@@PERLLIBDIR@@='$(perllibdir_SQ)'=g' \\\n+\t    -e 's=@@PERLLIBDIR_REL@@=$(perllibdir_relative_SQ)=g' \\\n+\t    -e 's=@@GITEXECDIR_REL@@=$(gitexecdir_relative_SQ)=g' \\\n+\t    -e 's=@@LOCALEDIR_REL@@=$(localedir_relative_SQ)=g' \\\n \t    $< >$@+ && \\\n \tmv $@+ $@\n \n@@ -2328,7 +2393,7 @@ endif\n \n perl/build/lib/%.pm: perl/%.pm\n \t$(QUIET_GEN)mkdir -p $(dir $@) && \\\n-\tsed -e 's|@@LOCALEDIR@@|$(localedir_SQ)|g' \\\n+\tsed -e 's|@@LOCALEDIR@@|$(perl_localedir_SQ)|g' \\\n \t    -e 's|@@NO_PERL_CPAN_FALLBACKS@@|$(NO_PERL_CPAN_FALLBACKS_SQ)|g' \\\n \t< $< > $@\n \ndiff --git a/perl/Git/I18N.pm b/perl/Git/I18N.pm\nindex dba96fff0..bfb4fb67a 100644\n--- a/perl/Git/I18N.pm\n+++ b/perl/Git/I18N.pm\n@@ -18,7 +18,7 @@ our @EXPORT_OK = @EXPORT;\n \n sub __bootstrap_locale_messages {\n \tour $TEXTDOMAIN = 'git';\n-\tour $TEXTDOMAINDIR = $ENV{GIT_TEXTDOMAINDIR} || '@@LOCALEDIR@@';\n+\tour $TEXTDOMAINDIR ||= $ENV{GIT_TEXTDOMAINDIR} || '@@LOCALEDIR@@';\n \n \trequire POSIX;\n \tPOSIX->import(qw(setlocale));\ndiff --git a/perl/header_templates/runtime_prefix.template.pl b/perl/header_templates/runtime_prefix.template.pl\nnew file mode 100644\nindex 000000000..a18913967\n--- /dev/null\n+++ b/perl/header_templates/runtime_prefix.template.pl\n@@ -0,0 +1,40 @@\n+# BEGIN RUNTIME_PREFIX generated code.\n+#\n+# This finds our Git::* libraries relative to the script's runtime path.\n+sub __git_system_path {\n+\tmy ($relpath) = @_;\n+\tmy $gitexecdir_relative = '@@GITEXECDIR_REL@@';\n+\n+\t# GIT_EXEC_PATH is supplied by `git` or the test suite.\n+\tmy $exec_path = $ENV{GIT_EXEC_PATH};\n+\tif ($exec_path eq \"\") {\n+\t\t# This can happen if this script is being directly invoked instead of run\n+\t\t# by \"git\".\n+\t\trequire FindBin;\n+\t\t$exec_path = $FindBin::Bin;\n+\t}\n+\n+\t# Trim off the relative gitexecdir path to get the system path.\n+\t(my $prefix = $exec_path) =~ s=${gitexecdir_relative}$==;\n+\n+\trequire File::Spec;\n+\treturn File::Spec->catdir($prefix, $relpath);\n+}\n+\n+BEGIN {\n+\tuse lib split /@@PATHSEP@@/,\n+\t(\n+\t\t$ENV{GITPERLLIB} ||\n+\t\tdo {\n+\t\t\tmy $perllibdir = __git_system_path('@@PERLLIBDIR_REL@@');\n+\t\t\t(-e $perllibdir) || die(\"Invalid system path ($relpath): $path\");\n+\t\t\t$perllibdir;\n+\t\t}\n+\t);\n+\n+\t# Export the system locale directory to the I18N module. The locale directory\n+\t# is only installed if NO_GETTEXT is set.\n+\t$Git::I18N::TEXTDOMAINDIR = __git_system_path('@@LOCALEDIR_REL@@');\n+}\n+\n+# END RUNTIME_PREFIX generated code.\n-- \n2.15.0.chromium12\n\n"},{"id":"342127","messageId":"20180319025046.58052-4-dnj@google.com","threadId":"48078","inReplyTo":"20180319025046.58052-1-dnj@google.com","subject":"[PATCH v6 3/3] exec_cmd: RUNTIME_PREFIX on some POSIX systems","fromName":"Dan Jacques","fromEmail":"dnj@google.com","sentAt":"2018-03-19T02:50:46Z","receivedAt":"2018-03-19T02:51:10Z","isPatch":true,"sender":{"key":"dnj@google.com","avatar":"https://avatars.githubusercontent.com/u/9965104?v=4"},"body":"Enable Git to resolve its own binary location using a variety of\nOS-specific and generic methods, including:\n\n- procfs via \"/proc/self/exe\" (Linux)\n- _NSGetExecutablePath (Darwin)\n- KERN_PROC_PATHNAME sysctl on BSDs.\n- argv0, if absolute (all, including Windows).\n\nThis is used to enable RUNTIME_PREFIX support for non-Windows systems,\nnotably Linux and Darwin. When configured with RUNTIME_PREFIX, Git will\ndo a best-effort resolution of its executable path and automatically use\nthis as its \"exec_path\" for relative helper and data lookups, unless\nexplicitly overridden.\n\nSmall incidental formatting cleanup of \"exec_cmd.c\".\n\nSigned-off-by: Dan Jacques <dnj@google.com>\nThanks-to: Robbie Iannucci <iannucci@google.com>\nThanks-to: Junio C Hamano <gitster@pobox.com>\n---\n Makefile               |  26 +++++-\n cache.h                |   1 +\n common-main.c          |   4 +-\n config.mak.uname       |   7 ++\n exec_cmd.c             | 241 ++++++++++++++++++++++++++++++++++++++++++-------\n exec_cmd.h             |   4 +-\n gettext.c              |   8 +-\n git.c                  |   2 +-\n t/t0061-run-command.sh |   2 +-\n 9 files changed, 254 insertions(+), 41 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 101a98a78..df17a62a4 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -418,6 +418,16 @@ all::\n #\n # Define HAVE_BSD_SYSCTL if your platform has a BSD-compatible sysctl function.\n #\n+# Define HAVE_BSD_KERN_PROC_SYSCTL if your platform supports the KERN_PROC BSD\n+# sysctl function.\n+#\n+# Define PROCFS_EXECUTABLE_PATH if your platform mounts a \"procfs\" filesystem\n+# capable of resolving the path of the current executable. If defined, this\n+# must be the canonical path for the \"procfs\" current executable path.\n+#\n+# Define HAVE_NS_GET_EXECUTABLE_PATH if your platform supports calling\n+# _NSGetExecutablePath to retrieve the path of the running executable.\n+#\n # Define HAVE_GETDELIM if your system has the getdelim() function.\n #\n # Define PAGER_ENV to a SP separated VAR=VAL pairs to define\n@@ -1664,10 +1674,23 @@ ifdef HAVE_BSD_SYSCTL\n \tBASIC_CFLAGS += -DHAVE_BSD_SYSCTL\n endif\n \n+ifdef HAVE_BSD_KERN_PROC_SYSCTL\n+\tBASIC_CFLAGS += -DHAVE_BSD_KERN_PROC_SYSCTL\n+endif\n+\n ifdef HAVE_GETDELIM\n \tBASIC_CFLAGS += -DHAVE_GETDELIM\n endif\n \n+ifneq ($(PROCFS_EXECUTABLE_PATH),)\n+\tprocfs_executable_path_SQ = $(subst ','\\'',$(PROCFS_EXECUTABLE_PATH))\n+\tBASIC_CFLAGS += '-DPROCFS_EXECUTABLE_PATH=\"$(procfs_executable_path_SQ)\"'\n+endif\n+\n+ifdef HAVE_NS_GET_EXECUTABLE_PATH\n+\tBASIC_CFLAGS += -DHAVE_NS_GET_EXECUTABLE_PATH\n+endif\n+\n ifeq ($(TCLTK_PATH),)\n NO_TCLTK = NoThanks\n endif\n@@ -2216,6 +2239,7 @@ endif\n exec_cmd.sp exec_cmd.s exec_cmd.o: GIT-PREFIX\n exec_cmd.sp exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \\\n \t'-DGIT_EXEC_PATH=\"$(gitexecdir_SQ)\"' \\\n+\t'-DGIT_LOCALE_PATH=\"$(localedir_relative_SQ)\"' \\\n \t'-DBINDIR=\"$(bindir_relative_SQ)\"' \\\n \t'-DPREFIX=\"$(prefix_SQ)\"'\n \n@@ -2233,7 +2257,7 @@ attr.sp attr.s attr.o: EXTRA_CPPFLAGS = \\\n \n gettext.sp gettext.s gettext.o: GIT-PREFIX\n gettext.sp gettext.s gettext.o: EXTRA_CPPFLAGS = \\\n-\t-DGIT_LOCALE_PATH='\"$(localedir_SQ)\"'\n+\t-DGIT_LOCALE_PATH='\"$(localedir_relative_SQ)\"'\n \n http-push.sp http.sp http-walker.sp remote-curl.sp imap-send.sp: SPARSE_FLAGS += \\\n \t-DCURL_DISABLE_TYPECHECK\ndiff --git a/cache.h b/cache.h\nindex d06932ed0..2d1999a5f 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -428,6 +428,7 @@ static inline enum object_type object_type(unsigned int mode)\n #define GIT_ICASE_PATHSPECS_ENVIRONMENT \"GIT_ICASE_PATHSPECS\"\n #define GIT_QUARANTINE_ENVIRONMENT \"GIT_QUARANTINE_PATH\"\n #define GIT_OPTIONAL_LOCKS_ENVIRONMENT \"GIT_OPTIONAL_LOCKS\"\n+#define GIT_TEXT_DOMAIN_DIR_ENVIRONMENT \"GIT_TEXTDOMAINDIR\"\n \n /*\n  * Environment variable used in handshaking the wire protocol.\ndiff --git a/common-main.c b/common-main.c\nindex 6a689007e..6516a1f89 100644\n--- a/common-main.c\n+++ b/common-main.c\n@@ -32,12 +32,12 @@ int main(int argc, const char **argv)\n \t */\n \tsanitize_stdfds();\n \n+\tgit_resolve_executable_dir(argv[0]);\n+\n \tgit_setup_gettext();\n \n \tattr_start();\n \n-\tgit_extract_argv0_path(argv[0]);\n-\n \trestore_sigpipe_to_default();\n \n \treturn cmd_main(argc, argv);\ndiff --git a/config.mak.uname b/config.mak.uname\nindex 6a1d0de0c..e1cfe5e5e 100644\n--- a/config.mak.uname\n+++ b/config.mak.uname\n@@ -37,6 +37,7 @@ ifeq ($(uname_S),Linux)\n \tHAVE_GETDELIM = YesPlease\n \tSANE_TEXT_GREP=-a\n \tFREAD_READS_DIRECTORIES = UnfortunatelyYes\n+\tPROCFS_EXECUTABLE_PATH = /proc/self/exe\n endif\n ifeq ($(uname_S),GNU/kFreeBSD)\n \tHAVE_ALLOCA_H = YesPlease\n@@ -111,6 +112,7 @@ ifeq ($(uname_S),Darwin)\n \tBASIC_CFLAGS += -DPROTECT_HFS_DEFAULT=1\n \tHAVE_BSD_SYSCTL = YesPlease\n \tFREAD_READS_DIRECTORIES = UnfortunatelyYes\n+\tHAVE_NS_GET_EXECUTABLE_PATH = YesPlease\n endif\n ifeq ($(uname_S),SunOS)\n \tNEEDS_SOCKET = YesPlease\n@@ -205,6 +207,7 @@ ifeq ($(uname_S),FreeBSD)\n \tHAVE_PATHS_H = YesPlease\n \tGMTIME_UNRELIABLE_ERRORS = UnfortunatelyYes\n \tHAVE_BSD_SYSCTL = YesPlease\n+\tHAVE_BSD_KERN_PROC_SYSCTL = YesPlease\n \tPAGER_ENV = LESS=FRX LV=-c MORE=FRX\n \tFREAD_READS_DIRECTORIES = UnfortunatelyYes\n endif\n@@ -217,6 +220,8 @@ ifeq ($(uname_S),OpenBSD)\n \tBASIC_LDFLAGS += -L/usr/local/lib\n \tHAVE_PATHS_H = YesPlease\n \tHAVE_BSD_SYSCTL = YesPlease\n+\tHAVE_BSD_KERN_PROC_SYSCTL = YesPlease\n+\tPROCFS_EXECUTABLE_PATH = /proc/curproc/file\n endif\n ifeq ($(uname_S),MirBSD)\n \tNO_STRCASESTR = YesPlease\n@@ -235,6 +240,8 @@ ifeq ($(uname_S),NetBSD)\n \tUSE_ST_TIMESPEC = YesPlease\n \tHAVE_PATHS_H = YesPlease\n \tHAVE_BSD_SYSCTL = YesPlease\n+\tHAVE_BSD_KERN_PROC_SYSCTL = YesPlease\n+\tPROCFS_EXECUTABLE_PATH = /proc/curproc/exe\n endif\n ifeq ($(uname_S),AIX)\n \tDEFAULT_PAGER = more\ndiff --git a/exec_cmd.c b/exec_cmd.c\nindex ce192a2d6..6585fc05a 100644\n--- a/exec_cmd.c\n+++ b/exec_cmd.c\n@@ -2,53 +2,234 @@\n #include \"exec_cmd.h\"\n #include \"quote.h\"\n #include \"argv-array.h\"\n-#define MAX_ARGS\t32\n \n-static const char *argv_exec_path;\n+#if defined(RUNTIME_PREFIX)\n+\n+#if defined(HAVE_NS_GET_EXECUTABLE_PATH)\n+#include <mach-o/dyld.h>\n+#endif\n+\n+#if defined(HAVE_BSD_KERN_PROC_SYSCTL)\n+#include <sys/param.h>\n+#include <sys/types.h>\n+#include <sys/sysctl.h>\n+#endif\n+\n+#endif /* RUNTIME_PREFIX */\n+\n+#define MAX_ARGS 32\n+\n+static const char *system_prefix(void);\n \n #ifdef RUNTIME_PREFIX\n-static const char *argv0_path;\n+\n+/**\n+ * When using a runtime prefix, Git dynamically resolves paths relative to its\n+ * executable.\n+ *\n+ * The method for determining the path of the executable is highly\n+ * platform-specific.\n+ */\n+\n+/**\n+ * Path to the current Git executable. Resolved on startup by\n+ * 'git_resolve_executable_dir'.\n+ */\n+static const char *executable_dirname;\n \n static const char *system_prefix(void)\n {\n \tstatic const char *prefix;\n \n-\tassert(argv0_path);\n-\tassert(is_absolute_path(argv0_path));\n+\tassert(executable_dirname);\n+\tassert(is_absolute_path(executable_dirname));\n \n \tif (!prefix &&\n-\t    !(prefix = strip_path_suffix(argv0_path, GIT_EXEC_PATH)) &&\n-\t    !(prefix = strip_path_suffix(argv0_path, BINDIR)) &&\n-\t    !(prefix = strip_path_suffix(argv0_path, \"git\"))) {\n+\t    !(prefix = strip_path_suffix(executable_dirname, GIT_EXEC_PATH)) &&\n+\t    !(prefix = strip_path_suffix(executable_dirname, BINDIR)) &&\n+\t    !(prefix = strip_path_suffix(executable_dirname, \"git\"))) {\n \t\tprefix = PREFIX;\n \t\ttrace_printf(\"RUNTIME_PREFIX requested, \"\n-\t\t\t\t\"but prefix computation failed.  \"\n-\t\t\t\t\"Using static fallback '%s'.\\n\", prefix);\n+\t\t\t     \"but prefix computation failed.  \"\n+\t\t\t     \"Using static fallback '%s'.\\n\",\n+\t\t\t     prefix);\n \t}\n \treturn prefix;\n }\n \n-void git_extract_argv0_path(const char *argv0)\n+/*\n+ * Resolves the executable path from argv[0], only if it is absolute.\n+ *\n+ * Returns 0 on success, -1 on failure.\n+ */\n+static int git_get_exec_path_from_argv0(struct strbuf *buf, const char *argv0)\n {\n \tconst char *slash;\n \n \tif (!argv0 || !*argv0)\n-\t\treturn;\n+\t\treturn -1;\n \n \tslash = find_last_dir_sep(argv0);\n+\tif (slash) {\n+\t\ttrace_printf(\"trace: resolved executable path from argv0: %s\\n\",\n+\t\t\t     argv0);\n+\t\tstrbuf_add_absolute_path(buf, argv0);\n+\t\treturn 0;\n+\t}\n+\treturn -1;\n+}\n \n+#ifdef PROCFS_EXECUTABLE_PATH\n+/*\n+ * Resolves the executable path by examining a procfs symlink.\n+ *\n+ * Returns 0 on success, -1 on failure.\n+ */\n+static int git_get_exec_path_procfs(struct strbuf *buf)\n+{\n+\tif (strbuf_realpath(buf, PROCFS_EXECUTABLE_PATH, 0)) {\n+\t\ttrace_printf(\n+\t\t\t\"trace: resolved executable path from procfs: %s\\n\",\n+\t\t\tbuf->buf);\n+\t\treturn 0;\n+\t}\n+\treturn -1;\n+}\n+#endif /* PROCFS_EXECUTABLE_PATH */\n+\n+#ifdef HAVE_BSD_KERN_PROC_SYSCTL\n+/*\n+ * Resolves the executable path using KERN_PROC_PATHNAME BSD sysctl.\n+ *\n+ * Returns 0 on success, -1 on failure.\n+ */\n+static int git_get_exec_path_bsd_sysctl(struct strbuf *buf)\n+{\n+\tint mib[4];\n+\tchar path[MAXPATHLEN];\n+\tsize_t cb = sizeof(path);\n+\n+\tmib[0] = CTL_KERN;\n+\tmib[1] = KERN_PROC;\n+\tmib[2] = KERN_PROC_PATHNAME;\n+\tmib[3] = -1;\n+\tif (!sysctl(mib, 4, path, &cb, NULL, 0)) {\n+\t\ttrace_printf(\n+\t\t\t\"trace: resolved executable path from sysctl: %s\\n\",\n+\t\t\tpath);\n+\t\tstrbuf_addstr(buf, path);\n+\t\treturn 0;\n+\t}\n+\treturn -1;\n+}\n+#endif /* HAVE_BSD_KERN_PROC_SYSCTL */\n+\n+#ifdef HAVE_NS_GET_EXECUTABLE_PATH\n+/*\n+ * Resolves the executable path by querying Darwin applicaton stack.\n+ *\n+ * Returns 0 on success, -1 on failure.\n+ */\n+static int git_get_exec_path_darwin(struct strbuf *buf)\n+{\n+\tchar path[PATH_MAX];\n+\tuint32_t size = sizeof(path);\n+\tif (!_NSGetExecutablePath(path, &size)) {\n+\t\ttrace_printf(\n+\t\t\t\"trace: resolved executable path from Darwin stack: %s\\n\",\n+\t\t\tpath);\n+\t\tstrbuf_addstr(buf, path);\n+\t\treturn 0;\n+\t}\n+\treturn -1;\n+}\n+#endif /* HAVE_NS_GET_EXECUTABLE_PATH */\n+\n+/*\n+ * Resolves the absolute path of the current executable.\n+ *\n+ * Returns 0 on success, -1 on failure.\n+ */\n+static int git_get_exec_path(struct strbuf *buf, const char *argv0)\n+{\n+\t/*\n+\t * Identifying the executable path is operating system specific.\n+\t * Selectively employ all available methods in order of preference,\n+\t * preferring highly-available authoratative methods over\n+\t * selectively-available or non- authoratative methods.\n+\t *\n+\t * All cases fall back on resolving against argv[0] if there isn't a\n+\t * better functional method. However, note that argv[0] can be\n+\t * used-supplied on many operating sysetems, and is not authoratative\n+\t * in those cases.\n+\t *\n+\t * Each of these functions returns 0 on success, so evaluation will stop\n+\t * after the first successful method.\n+\t */\n+\tif (\n+#ifdef HAVE_BSD_KERN_PROC_SYSCTL\n+\t\tgit_get_exec_path_bsd_sysctl(buf) &&\n+#endif /* HAVE_BSD_KERN_PROC_SYSCTL */\n+\n+#ifdef HAVE_NS_GET_EXECUTABLE_PATH\n+\t\tgit_get_exec_path_darwin(buf) &&\n+#endif /* HAVE_NS_GET_EXECUTABLE_PATH */\n+\n+#ifdef PROCFS_EXECUTABLE_PATH\n+\t\tgit_get_exec_path_procfs(buf) &&\n+#endif /* PROCFS_EXECUTABLE_PATH */\n+\n+\t\tgit_get_exec_path_from_argv0(buf, argv0)) {\n+\t\treturn -1;\n+\t}\n+\n+\tif (strbuf_normalize_path(buf)) {\n+\t\ttrace_printf(\"trace: could not normalize path: %s\\n\", buf->buf);\n+\t\treturn -1;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+void git_resolve_executable_dir(const char *argv0)\n+{\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tchar *resolved;\n+\tconst char *slash;\n+\n+\tif (git_get_exec_path(&buf, argv0)) {\n+\t\ttrace_printf(\n+\t\t\t\"trace: could not determine executable path from: %s\\n\",\n+\t\t\targv0);\n+\t\tstrbuf_release(&buf);\n+\t\treturn;\n+\t}\n+\n+\tresolved = strbuf_detach(&buf, NULL);\n+\tslash = find_last_dir_sep(resolved);\n \tif (slash)\n-\t\targv0_path = xstrndup(argv0, slash - argv0);\n+\t\tresolved[slash - resolved] = '\\0';\n+\n+\texecutable_dirname = resolved;\n+\ttrace_printf(\"trace: resolved executable dir: %s\\n\",\n+\t\t     executable_dirname);\n }\n \n #else\n \n+/*\n+ * When not using a runtime prefix, Git uses a hard-coded path.\n+ */\n static const char *system_prefix(void)\n {\n \treturn PREFIX;\n }\n \n-void git_extract_argv0_path(const char *argv0)\n+/*\n+ * This is called during initialization, but No work needs to be done here when\n+ * runtime prefix is not being used.\n+ */\n+void git_resolve_executable_dir(const char *argv0)\n {\n }\n \n@@ -65,32 +246,28 @@ char *system_path(const char *path)\n \treturn strbuf_detach(&d, NULL);\n }\n \n-void git_set_argv_exec_path(const char *exec_path)\n+static const char *exec_path_value;\n+\n+void git_set_exec_path(const char *exec_path)\n {\n-\targv_exec_path = exec_path;\n+\texec_path_value = exec_path;\n \t/*\n \t * Propagate this setting to external programs.\n \t */\n \tsetenv(EXEC_PATH_ENVIRONMENT, exec_path, 1);\n }\n \n-\n-/* Returns the highest-priority, location to look for git programs. */\n+/* Returns the highest-priority location to look for git programs. */\n const char *git_exec_path(void)\n {\n-\tstatic char *cached_exec_path;\n-\n-\tif (argv_exec_path)\n-\t\treturn argv_exec_path;\n-\n-\tif (!cached_exec_path) {\n+\tif (!exec_path_value) {\n \t\tconst char *env = getenv(EXEC_PATH_ENVIRONMENT);\n \t\tif (env && *env)\n-\t\t\tcached_exec_path = xstrdup(env);\n+\t\t\texec_path_value = xstrdup(env);\n \t\telse\n-\t\t\tcached_exec_path = system_path(GIT_EXEC_PATH);\n+\t\t\texec_path_value = system_path(GIT_EXEC_PATH);\n \t}\n-\treturn cached_exec_path;\n+\treturn exec_path_value;\n }\n \n static void add_path(struct strbuf *out, const char *path)\n@@ -103,10 +280,12 @@ static void add_path(struct strbuf *out, const char *path)\n \n void setup_path(void)\n {\n+\tconst char *exec_path = git_exec_path();\n \tconst char *old_path = getenv(\"PATH\");\n \tstruct strbuf new_path = STRBUF_INIT;\n \n-\tadd_path(&new_path, git_exec_path());\n+\tgit_set_exec_path(exec_path);\n+\tadd_path(&new_path, exec_path);\n \n \tif (old_path)\n \t\tstrbuf_addstr(&new_path, old_path);\n@@ -125,7 +304,8 @@ const char **prepare_git_cmd(struct argv_array *out, const char **argv)\n \treturn out->argv;\n }\n \n-int execv_git_cmd(const char **argv) {\n+int execv_git_cmd(const char **argv)\n+{\n \tstruct argv_array nargv = ARGV_ARRAY_INIT;\n \n \tprepare_git_cmd(&nargv, argv);\n@@ -140,8 +320,7 @@ int execv_git_cmd(const char **argv) {\n \treturn -1;\n }\n \n-\n-int execl_git_cmd(const char *cmd,...)\n+int execl_git_cmd(const char *cmd, ...)\n {\n \tint argc;\n \tconst char *argv[MAX_ARGS + 1];\ndiff --git a/exec_cmd.h b/exec_cmd.h\nindex ff0b48048..2522453cd 100644\n--- a/exec_cmd.h\n+++ b/exec_cmd.h\n@@ -3,8 +3,8 @@\n \n struct argv_array;\n \n-extern void git_set_argv_exec_path(const char *exec_path);\n-extern void git_extract_argv0_path(const char *path);\n+extern void git_set_exec_path(const char *exec_path);\n+extern void git_resolve_executable_dir(const char *path);\n extern const char *git_exec_path(void);\n extern void setup_path(void);\n extern const char **prepare_git_cmd(struct argv_array *out, const char **argv);\ndiff --git a/gettext.c b/gettext.c\nindex db727ea02..6b64d5c2e 100644\n--- a/gettext.c\n+++ b/gettext.c\n@@ -2,7 +2,8 @@\n  * Copyright (c) 2010 Ævar Arnfjörð Bjarmason\n  */\n \n-#include \"git-compat-util.h\"\n+#include \"cache.h\"\n+#include \"exec_cmd.h\"\n #include \"gettext.h\"\n #include \"strbuf.h\"\n #include \"utf8.h\"\n@@ -157,10 +158,11 @@ static void init_gettext_charset(const char *domain)\n \n void git_setup_gettext(void)\n {\n-\tconst char *podir = getenv(\"GIT_TEXTDOMAINDIR\");\n+\tconst char *podir = getenv(GIT_TEXT_DOMAIN_DIR_ENVIRONMENT);\n \n \tif (!podir)\n-\t\tpodir = GIT_LOCALE_PATH;\n+\t\tpodir = system_path(GIT_LOCALE_PATH);\n+\n \tbindtextdomain(\"git\", podir);\n \tsetlocale(LC_MESSAGES, \"\");\n \tsetlocale(LC_TIME, \"\");\ndiff --git a/git.c b/git.c\nindex 96cd734f1..33a0d5040 100644\n--- a/git.c\n+++ b/git.c\n@@ -65,7 +65,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)\n \t\t */\n \t\tif (skip_prefix(cmd, \"--exec-path\", &cmd)) {\n \t\t\tif (*cmd == '=')\n-\t\t\t\tgit_set_argv_exec_path(cmd + 1);\n+\t\t\t\tgit_set_exec_path(cmd + 1);\n \t\t\telse {\n \t\t\t\tputs(git_exec_path());\n \t\t\t\texit(0);\ndiff --git a/t/t0061-run-command.sh b/t/t0061-run-command.sh\nindex 24c92b6cd..1009595d6 100755\n--- a/t/t0061-run-command.sh\n+++ b/t/t0061-run-command.sh\n@@ -145,7 +145,7 @@ test_trace () {\n \texpect=\"$1\"\n \tshift\n \tGIT_TRACE=1 test-run-command \"$@\" run-command true 2>&1 >/dev/null | \\\n-\t\tsed 's/.* run_command: //' >actual &&\n+\t\tsed -e 's/.* run_command: //' -e '/trace: .*/d' >actual &&\n \techo \"$expect true\" >expect &&\n \ttest_cmp expect actual\n }\n-- \n2.15.0.chromium12\n\n"},{"id":"342128","messageId":"CAPig+cRPX9fHdco-g0GOUCwMr5Sh=hdBTAtUHyYSpKPherRd-Q@mail.gmail.com","threadId":"48078","inReplyTo":"20180319025046.58052-2-dnj@google.com","subject":"Re: [PATCH v6 1/3] Makefile: generate Perl header from template file","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-03-19T03:07:41Z","receivedAt":"2018-03-19T03:07:54Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sun, Mar 18, 2018 at 10:50 PM, Dan Jacques <dnj@google.com> wrote:\n> Currently, the generated Perl script headers are emitted by commands in\n> the Makefile. This mechanism restricts options to introduce alternative\n> header content, needed by Perl runtime prefix support, and obscures the\n> origin of the Perl script header.\n>\n> Change the Makefile to generate a header by processing a template file and\n> move the header content into the \"perl/\" subdirectory. The processed\n> generated will now be stored in the \"GIT-PERL-HEADER\" file. This allows\n\n\"processed generated\"?\n\n> the content of the Perl header to be controlled by changing the path of\n> the template in the Makefile.\n>\n> Signed-off-by: Dan Jacques <dnj@google.com>\n"},{"id":"342204","messageId":"xmqqfu4wvw0d.fsf@gitster-ct.c.googlers.com","threadId":"48078","inReplyTo":"20180319025046.58052-1-dnj@google.com","subject":"Re: [PATCH v6 0/3] RUNTIME_PREFIX relocatable Git","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-03-19T17:02:42Z","receivedAt":"2018-03-19T17:02:54Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Dan Jacques <dnj@google.com> writes:\n\n> This patch set expands support for the RUNTIME_PREFIX configuration flag,\n> currently only used on Windows builds, to include Linux, Darwin, and\n> FreeBSD. When Git is built with RUNTIME_PREFIX enabled, it resolves its\n> ancillary paths relative to the runtime location of its executable\n> rather than hard-coding them at compile-time, allowing a Git\n> installation to be deployed to a path other than the one in which it\n> was built/installed.\n>\n> Note that RUNTIME_PREFIX is not currently used outside of Windows.\n> This patch set should not have an impact on default Git builds.\n>\n> I'm dusting this back off now that avarab@'s Perl Makefile simplification\n> patch set has landed. It's been a few months, so I'm a bit rusty, but I think\n> that I've incorporated all of the feedback. Please take a look and let me know\n> what you think!\n\nYay.  Thanks for rebooting the effort.\n"},{"id":"342207","messageId":"xmqqbmfkvvhc.fsf@gitster-ct.c.googlers.com","threadId":"48078","inReplyTo":"20180319025046.58052-3-dnj@google.com","subject":"Re: [PATCH v6 2/3] Makefile: add Perl runtime prefix support","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-03-19T17:14:07Z","receivedAt":"2018-03-19T17:14:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Dan Jacques <dnj@google.com> writes:\n\n> +# RUNTIME_PREFIX's resolution logic requires resource paths to be expressed\n> +# relative to each other and share an installation path.\n> +#\n> +# This is a dependnecy in:\n\ndependency?\n\n> +# - Git's binary RUNTIME_PREFIX logic in (see \"exec_cmd.c\").\n> +# - The runtime prefix Perl header (see\n> +#   \"perl/header_templates/runtime_prefix.template.pl\").\n> +ifdef RUNTIME_PREFIX\n> +\n> +ifneq ($(filter /%,$(firstword $(gitexecdir_relative))),)\n> +$(error RUNTIME_PREFIX requires a relative gitexecdir, not: $(gitexecdir))\n> +endif\n\nI see Dscho is CC'ed so I won't worry about \"is there a more\nportable test than 'the path begins with a slash' to see if a path\nis relative, or is this good enough even for Windows in the context\nof this patch?\".  It won't be a show-stopper issue as long as we do\nnot error out with false positive, though ;-).\n"},{"id":"342208","messageId":"CAD1RUU9R5xfGghQP-A=yU0RkmVDaS0hPGMHVieCyb-DRg97SnQ@mail.gmail.com","threadId":"48078","inReplyTo":"xmqqbmfkvvhc.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH v6 2/3] Makefile: add Perl runtime prefix support","fromName":"Daniel Jacques","fromEmail":"dnj@google.com","sentAt":"2018-03-19T17:21:34Z","receivedAt":"2018-03-19T17:22:58Z","isPatch":true,"sender":{"key":"dnj@google.com","avatar":"https://avatars.githubusercontent.com/u/9965104?v=4"},"body":"On Mon, Mar 19, 2018 at 1:14 PM Junio C Hamano <gitster@pobox.com> wrote:\n\n> > +# RUNTIME_PREFIX's resolution logic requires resource paths to be\nexpressed\n> > +# relative to each other and share an installation path.\n> > +#\n> > +# This is a dependnecy in:\n\n> dependency?\n\nOops, this is the second typo that has been pointed out. I'll release one\nlast series after a small review period with these fixed.\n\n> > +# - Git's binary RUNTIME_PREFIX logic in (see \"exec_cmd.c\").\n> > +# - The runtime prefix Perl header (see\n> > +#   \"perl/header_templates/runtime_prefix.template.pl\").\n> > +ifdef RUNTIME_PREFIX\n> > +\n> > +ifneq ($(filter /%,$(firstword $(gitexecdir_relative))),)\n> > +$(error RUNTIME_PREFIX requires a relative gitexecdir, not:\n$(gitexecdir))\n> > +endif\n\n> I see Dscho is CC'ed so I won't worry about \"is there a more\n> portable test than 'the path begins with a slash' to see if a path\n> is relative, or is this good enough even for Windows in the context\n> of this patch?\".  It won't be a show-stopper issue as long as we do\n> not error out with false positive, though ;-).\n\nOK sounds good! There are other places in the Makefile that use this method\nfor this purpose, so hopefully the worst-case is that this is no more\nbroken than they are.\n"},{"id":"342209","messageId":"xmqq7eq8vv09.fsf@gitster-ct.c.googlers.com","threadId":"48078","inReplyTo":"20180319025046.58052-4-dnj@google.com","subject":"Re: [PATCH v6 3/3] exec_cmd: RUNTIME_PREFIX on some POSIX systems","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-03-19T17:24:22Z","receivedAt":"2018-03-19T17:24:31Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Dan Jacques <dnj@google.com> writes:\n\n> Enable Git to resolve its own binary location using a variety of\n> OS-specific and generic methods, including:\n>\n> - procfs via \"/proc/self/exe\" (Linux)\n> - _NSGetExecutablePath (Darwin)\n> - KERN_PROC_PATHNAME sysctl on BSDs.\n> - argv0, if absolute (all, including Windows).\n>\n> This is used to enable RUNTIME_PREFIX support for non-Windows systems,\n> notably Linux and Darwin. When configured with RUNTIME_PREFIX, Git will\n> do a best-effort resolution of its executable path and automatically use\n> this as its \"exec_path\" for relative helper and data lookups, unless\n> explicitly overridden.\n>\n> Small incidental formatting cleanup of \"exec_cmd.c\".\n>\n> Signed-off-by: Dan Jacques <dnj@google.com>\n> Thanks-to: Robbie Iannucci <iannucci@google.com>\n> Thanks-to: Junio C Hamano <gitster@pobox.com>\n> ---\n\nLook for these misspelled words:\n\n    sysetems\n    applicaton\n    authoratative\n\n> diff --git a/Makefile b/Makefile\n> index 101a98a78..df17a62a4 100644\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -418,6 +418,16 @@ all::\n>  #\n>  # Define HAVE_BSD_SYSCTL if your platform has a BSD-compatible sysctl function.\n>  #\n> +# Define HAVE_BSD_KERN_PROC_SYSCTL if your platform supports the KERN_PROC BSD\n> +# sysctl function.\n> +#\n> +# Define PROCFS_EXECUTABLE_PATH if your platform mounts a \"procfs\" filesystem\n> +# capable of resolving the path of the current executable. If defined, this\n> +# must be the canonical path for the \"procfs\" current executable path.\n> +#\n> +# Define HAVE_NS_GET_EXECUTABLE_PATH if your platform supports calling\n> +# _NSGetExecutablePath to retrieve the path of the running executable.\n> +#\n\nSounds sensible.\n\n> +/**\n> + * Path to the current Git executable. Resolved on startup by\n> + * 'git_resolve_executable_dir'.\n> + */\n> +static const char *executable_dirname;\n>  \n>  static const char *system_prefix(void)\n>  {\n>  \tstatic const char *prefix;\n>  \n> -\tassert(argv0_path);\n> -\tassert(is_absolute_path(argv0_path));\n> +\tassert(executable_dirname);\n> +\tassert(is_absolute_path(executable_dirname));\n>  \n>  \tif (!prefix &&\n> -\t    !(prefix = strip_path_suffix(argv0_path, GIT_EXEC_PATH)) &&\n> -\t    !(prefix = strip_path_suffix(argv0_path, BINDIR)) &&\n> -\t    !(prefix = strip_path_suffix(argv0_path, \"git\"))) {\n> +\t    !(prefix = strip_path_suffix(executable_dirname, GIT_EXEC_PATH)) &&\n> +\t    !(prefix = strip_path_suffix(executable_dirname, BINDIR)) &&\n> +\t    !(prefix = strip_path_suffix(executable_dirname, \"git\"))) {\n>  \t\tprefix = PREFIX;\n>  \t\ttrace_printf(\"RUNTIME_PREFIX requested, \"\n> -\t\t\t\t\"but prefix computation failed.  \"\n> -\t\t\t\t\"Using static fallback '%s'.\\n\", prefix);\n> +\t\t\t     \"but prefix computation failed.  \"\n> +\t\t\t     \"Using static fallback '%s'.\\n\",\n> +\t\t\t     prefix);\n>  \t}\n>  \treturn prefix;\n>  }\n\nOK.  An essentially no-op change but with the name better suited in\nthe extended context---we used to only care about argv0 but that was\nan implementation detail of \"where did our binary come from\".  Nice.\n"},{"id":"342212","messageId":"CAD1RUU_1cNPF=HPvqgrgHisscxt4N39MnvPYGuaHES48axAPBw@mail.gmail.com","threadId":"48078","inReplyTo":"xmqq7eq8vv09.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH v6 3/3] exec_cmd: RUNTIME_PREFIX on some POSIX systems","fromName":"Daniel Jacques","fromEmail":"dnj@google.com","sentAt":"2018-03-19T17:30:40Z","receivedAt":"2018-03-19T17:30:58Z","isPatch":true,"sender":{"key":"dnj@google.com","avatar":"https://avatars.githubusercontent.com/u/9965104?v=4"},"body":"On Mon, Mar 19, 2018 at 1:24 PM Junio C Hamano <gitster@pobox.com> wrote:\n\n> Look for these misspelled words:\n\nOh boy ... thanks, and done.\n\n> OK.  An essentially no-op change but with the name better suited in\n> the extended context---we used to only care about argv0 but that was\n> an implementation detail of \"where did our binary come from\".  Nice.\n\nYes, exactly. Plus I think some other patches that I've seen circulating\naround here recently use it in this new capacity, so the name update is\nappropriate.\n"},{"id":"342230","messageId":"87zi33c22l.fsf@evledraar.gmail.com","threadId":"48078","inReplyTo":"20180319025046.58052-3-dnj@google.com","subject":"Re: [PATCH v6 2/3] Makefile: add Perl runtime prefix support","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2018-03-19T19:12:02Z","receivedAt":"2018-03-19T19:12:15Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Mon, Mar 19 2018, Dan Jacques jotted:\n\n> +gitexecdir_relative = $(patsubst $(prefix)/%,%,$(gitexecdir))\n>  mandir_relative = $(patsubst $(prefix)/%,%,$(mandir))\n>  infodir_relative = $(patsubst $(prefix)/%,%,$(infodir))\n> +localedir_relative = $(patsubst $(prefix)/%,%,$(localedir))\n>  htmldir_relative = $(patsubst $(prefix)/%,%,$(htmldir))\n> +perllibdir_relative = $(patsubst $(prefix)/%,%,$(perllibdir))\n\nI stole a small part of this for my a4d79b99a0 (\"Makefile: add a\ngitexecdir_relative variable\", 2018-03-13) patch now sitting in next, if\nyou do this:\n\n    diff --git a/Makefile b/Makefile\n    index 101a98a783..033a55505e 100644\n    --- a/Makefile\n    +++ b/Makefile\n    @@ -501,9 +501,9 @@ lib = lib\n     # DESTDIR =\n     pathsep = :\n\n    -gitexecdir_relative = $(patsubst $(prefix)/%,%,$(gitexecdir))\n     mandir_relative = $(patsubst $(prefix)/%,%,$(mandir))\n     infodir_relative = $(patsubst $(prefix)/%,%,$(infodir))\n    +gitexecdir_relative = $(patsubst $(prefix)/%,%,$(gitexecdir))\n     localedir_relative = $(patsubst $(prefix)/%,%,$(localedir))\n     htmldir_relative = $(patsubst $(prefix)/%,%,$(htmldir))\n     perllibdir_relative = $(patsubst $(prefix)/%,%,$(perllibdir))\n\nThe merge conflict becomes a tad easier to deal with, also makes sense\nto have gitexecdir after infodir since that's the order we're listing\nthese in just a few lines earlier, and this is otherwise (mostly)\nconsistent.\n"},{"id":"342233","messageId":"CAD1RUU_MpCeXfCF9NqvD-CvsWtsJShfMyg9HFAXrN-ULCE67FA@mail.gmail.com","threadId":"48078","inReplyTo":"87zi33c22l.fsf@evledraar.gmail.com","subject":"Re: [PATCH v6 2/3] Makefile: add Perl runtime prefix support","fromName":"Daniel Jacques","fromEmail":"dnj@google.com","sentAt":"2018-03-19T19:14:35Z","receivedAt":"2018-03-19T19:14:54Z","isPatch":true,"sender":{"key":"dnj@google.com","avatar":"https://avatars.githubusercontent.com/u/9965104?v=4"},"body":"On Mon, Mar 19, 2018 at 3:12 PM Ævar Arnfjörð Bjarmason <avarab@gmail.com>\nwrote:\n\n> The merge conflict becomes a tad easier to deal with, also makes sense\n> to have gitexecdir after infodir since that's the order we're listing\n> these in just a few lines earlier, and this is otherwise (mostly)\n> consistent.\n\nGot it, I'll update my patch set to include this in v7, which I'll post\nafter a little more time for comment on v6. Thanks!\n"},{"id":"342234","messageId":"CAD1RUU-K1rFaOEVXE=XZ_gu4ktmaEBGr3wtJvGJd1fivNXa21A@mail.gmail.com","threadId":"48078","inReplyTo":"CAD1RUU_MpCeXfCF9NqvD-CvsWtsJShfMyg9HFAXrN-ULCE67FA@mail.gmail.com","subject":"Re: [PATCH v6 2/3] Makefile: add Perl runtime prefix support","fromName":"Daniel Jacques","fromEmail":"dnj@google.com","sentAt":"2018-03-19T19:17:14Z","receivedAt":"2018-03-19T19:17:51Z","isPatch":true,"sender":{"key":"dnj@google.com","avatar":"https://avatars.githubusercontent.com/u/9965104?v=4"},"body":"> > The merge conflict becomes a tad easier to deal with, also makes sense\n> > to have gitexecdir after infodir since that's the order we're listing\n> > these in just a few lines earlier, and this is otherwise (mostly)\n> > consistent.\n\nActually as a quick follow-up question: for these patch sets, is it best\nfor me to have them based off of \"master\", \"next\", or a different branch?\n"},{"id":"342235","messageId":"87y3inc1my.fsf@evledraar.gmail.com","threadId":"48078","inReplyTo":"20180319025046.58052-3-dnj@google.com","subject":"Re: [PATCH v6 2/3] Makefile: add Perl runtime prefix support","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2018-03-19T19:21:25Z","receivedAt":"2018-03-19T19:21:36Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Mon, Mar 19 2018, Dan Jacques jotted:\n\n\n> +# BEGIN RUNTIME_PREFIX generated code.\n> +#\n> +# This finds our Git::* libraries relative to the script's runtime path.\n> +sub __git_system_path {\n> +\tmy ($relpath) = @_;\n> +\tmy $gitexecdir_relative = '@@GITEXECDIR_REL@@';\n> +\n> +\t# GIT_EXEC_PATH is supplied by `git` or the test suite.\n> +\tmy $exec_path = $ENV{GIT_EXEC_PATH};\n> +\tif ($exec_path eq \"\") {\n> +\t\t# This can happen if this script is being directly invoked instead of run\n> +\t\t# by \"git\".\n> +\t\trequire FindBin;\n> +\t\t$exec_path = $FindBin::Bin;\n> +\t}\n\nI think it would be more idiomatic and more paranoid (we'll catch bugs)\nto do:\n\n    my $exec_path;\n    if (exists $ENV{GIT_EXEC_PATH}) {\n        $exec_path = $ENV{GIT_EXEC_PATH};\n    } else {\n        [...]\n    }\n\nI.e. we're interested if we got passed GIT_EXEC_PATH, so let's see if it\nexists in the env hash, and then use it as-is. If we have some bug where\nit's an empty string we'd like to know, presumably...\n\n> +\n> +\t# Trim off the relative gitexecdir path to get the system path.\n> +\t(my $prefix = $exec_path) =~ s=${gitexecdir_relative}$==;\n\nThe path could contain regex metacharacters, so let's quote those via:\n\n    (my $prefix = $exec_path) =~ s/\\Q$gitexecdir_relative\\E$//;\n\nThis also nicely gets us rid of the more verbose ${} form, which makes\nesnse when we're doing ${foo}$ instead of the arguably less readbale\n$foo$, but when it's \\Q$foo\\E$ it's clear what's going on.\n"},{"id":"342237","messageId":"87woy7c1cf.fsf@evledraar.gmail.com","threadId":"48078","inReplyTo":"20180319025046.58052-4-dnj@google.com","subject":"Re: [PATCH v6 3/3] exec_cmd: RUNTIME_PREFIX on some POSIX systems","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2018-03-19T19:27:44Z","receivedAt":"2018-03-19T19:27:57Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Mon, Mar 19 2018, Dan Jacques jotted:\n\n>  #\n>  # Define HAVE_BSD_SYSCTL if your platform has a BSD-compatible sysctl function.\n>  #\n> +# Define HAVE_BSD_KERN_PROC_SYSCTL if your platform supports the KERN_PROC BSD\n> +# sysctl function.\n> +#\n> +# Define PROCFS_EXECUTABLE_PATH if your platform mounts a \"procfs\" filesystem\n> +# capable of resolving the path of the current executable. If defined, this\n> +# must be the canonical path for the \"procfs\" current executable path.\n> +#\n> +# Define HAVE_NS_GET_EXECUTABLE_PATH if your platform supports calling\n> +# _NSGetExecutablePath to retrieve the path of the running executable.\n> +#\n>  # Define HAVE_GETDELIM if your system has the getdelim() function.\n>  #\n>  # Define PAGER_ENV to a SP separated VAR=VAL pairs to define\n\nThis is fine in isolation, but the sum total of the series ends up\nbeing:\n\n    diff --git a/Makefile b/Makefile\n    index 96f6138f63..c23d4d10f0 100644\n    --- a/Makefile\n    +++ b/Makefile\n    @@ -425,6 +425,16 @@ all::\n     #\n     # Define HAVE_BSD_SYSCTL if your platform has a BSD-compatible sysctl function.\n     #\n    +# Define HAVE_BSD_KERN_PROC_SYSCTL if your platform supports the KERN_PROC BSD\n    +# sysctl function.\n    +#\n    +# Define PROCFS_EXECUTABLE_PATH if your platform mounts a \"procfs\" filesystem\n    +# capable of resolving the path of the current executable. If defined, this\n    +# must be the canonical path for the \"procfs\" current executable path.\n    +#\n    +# Define HAVE_NS_GET_EXECUTABLE_PATH if your platform supports calling\n    +# _NSGetExecutablePath to retrieve the path of the running executable.\n    +#\n     # Define HAVE_GETDELIM if your system has the getdelim() function.\n     #\n     # Define PAGER_ENV to a SP separated VAR=VAL pairs to define\n    @@ -441,6 +451,13 @@ all::\n     #\n     # When cross-compiling, define HOST_CPU as the canonical name of the CPU on\n     # which the built Git will run (for instance \"x86_64\").\n    +#\n    +# Define RUNTIME_PREFIX to configure Git to resolve its ancillary tooling and\n    +# support files relative to the location of the runtime binary, rather than\n    +# hard-coding them into the binary. Git installations built with RUNTIME_PREFIX\n    +# can be moved to arbitrary filesystem locations. RUNTIME_PREFIX also causes\n    +# Perl scripts to use a modified entry point header allowing them to resolve\n    +# support files at runtime.\n\nI wonder if it wouldn't be a lot more understandable if these were noted\ntogether, i.e. let's first document RUNTIME_PREFIX, then for all the\nother ones say below that:\n\n   # When using RUNTIME_PREFIX, define HAVE_BSD[...]\n\nOr something like that. We can always drop the \"When using\nRUNTIME_PREFIX, \" bit later if it ends up benig used for other stuff,\nbut for now it's helpful to note that you don't need to care about these\nif you're not using RUNTIME_PREFIX.\n\n> -\t\t\t\t\"but prefix computation failed.  \"\n> -\t\t\t\t\"Using static fallback '%s'.\\n\", prefix);\n> +\t\t\t     \"but prefix computation failed.  \"\n> +\t\t\t     \"Using static fallback '%s'.\\n\",\n> +\t\t\t     prefix);\n\nWhitespace changed mixed in with the actual change.\n"},{"id":"342238","messageId":"87vadrc185.fsf@evledraar.gmail.com","threadId":"48078","inReplyTo":"20180319025046.58052-1-dnj@google.com","subject":"Re: [PATCH v6 0/3] RUNTIME_PREFIX relocatable Git","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2018-03-19T19:30:18Z","receivedAt":"2018-03-19T19:30:30Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Mon, Mar 19 2018, Dan Jacques jotted:\n\n> I'm dusting this back off now that avarab@'s Perl Makefile simplification\n> patch set has landed. It's been a few months, so I'm a bit rusty, but I think\n> that I've incorporated all of the feedback. Please take a look and let me know\n> what you think!\n\nThanks a lot, sans the tiny nits I noted in individual patch review (and\nstuff noted by others) these all look good to me.\n\nAlso it would be great if you could test it for your use-case with the\nnext branch and define my new INSTALL_SYMLINKS to check that it doesn't\nruin anything for you, it shouldn't since I made it use relative\nsymlinks, but better to make sure (maybe I missed some edge case, and\nwe're largely modifying code in similar places).\n"},{"id":"342239","messageId":"CAD1RUU8JnQjspZjmWvM5h=3Rprk4TmfsNvBRAGVzze=WAnRQbg@mail.gmail.com","threadId":"48078","inReplyTo":"87woy7c1cf.fsf@evledraar.gmail.com","subject":"Re: [PATCH v6 3/3] exec_cmd: RUNTIME_PREFIX on some POSIX systems","fromName":"Daniel Jacques","fromEmail":"dnj@google.com","sentAt":"2018-03-19T19:38:14Z","receivedAt":"2018-03-19T19:38:33Z","isPatch":true,"sender":{"key":"dnj@google.com","avatar":"https://avatars.githubusercontent.com/u/9965104?v=4"},"body":"On Mon, Mar 19, 2018 at 3:27 PM Ævar Arnfjörð Bjarmason <avarab@gmail.com>\nwrote:\n\n> I wonder if it wouldn't be a lot more understandable if these were noted\n> together, i.e. let's first document RUNTIME_PREFIX, then for all the\n> other ones say below that:\n\nSounds good to me, done.\n\n> Whitespace changed mixed in with the actual change.\n\nOops, automatic \"clang-format\" slipped in there. I've reverted this part.\n\nThanks for reviewing!\n"},{"id":"342242","messageId":"CAD1RUU-3Q_SYvJorU+vEY2-0CPMZ1eL-41Z6eL7Sq4USiJ0U+w@mail.gmail.com","threadId":"48078","inReplyTo":"87y3inc1my.fsf@evledraar.gmail.com","subject":"Re: [PATCH v6 2/3] Makefile: add Perl runtime prefix support","fromName":"Daniel Jacques","fromEmail":"dnj@google.com","sentAt":"2018-03-19T19:47:21Z","receivedAt":"2018-03-19T19:47:44Z","isPatch":true,"sender":{"key":"dnj@google.com","avatar":"https://avatars.githubusercontent.com/u/9965104?v=4"},"body":"On Mon, Mar 19, 2018 at 3:21 PM Ævar Arnfjörð Bjarmason <avarab@gmail.com>\nwrote:\n\n> I think it would be more idiomatic and more paranoid (we'll catch bugs)\n> to do:\n\n>       my $exec_path;\n>       if (exists $ENV{GIT_EXEC_PATH}) {\n>           $exec_path = $ENV{GIT_EXEC_PATH};\n>       } else {\n>           [...]\n>       }\n\n> I.e. we're interested if we got passed GIT_EXEC_PATH, so let's see if it\n> exists in the env hash, and then use it as-is. If we have some bug where\n> it's an empty string we'd like to know, presumably...\n\nGood idea, done.\n\n> > +\n> > +     # Trim off the relative gitexecdir path to get the system path.\n> > +     (my $prefix = $exec_path) =~ s=${gitexecdir_relative}$==;\n\n> The path could contain regex metacharacters, so let's quote those via:\n\n>       (my $prefix = $exec_path) =~ s/\\Q$gitexecdir_relative\\E$//;\n\n> This also nicely gets us rid of the more verbose ${} form, which makes\n> esnse when we're doing ${foo}$ instead of the arguably less readbale\n> $foo$, but when it's \\Q$foo\\E$ it's clear what's going on.\n\nAh cool - makes sense. I'm not strong with Perl, so I wasn't aware that\nthis was an option, but I agree it's cleaner. Done.\n"},{"id":"342249","messageId":"xmqqpo3zu7aj.fsf@gitster-ct.c.googlers.com","threadId":"48078","inReplyTo":"CAD1RUU-K1rFaOEVXE=XZ_gu4ktmaEBGr3wtJvGJd1fivNXa21A@mail.gmail.com","subject":"Re: [PATCH v6 2/3] Makefile: add Perl runtime prefix support","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-03-19T20:41:56Z","receivedAt":"2018-03-19T20:42:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Daniel Jacques <dnj@google.com> writes:\n\n>> > The merge conflict becomes a tad easier to deal with, also makes sense\n>> > to have gitexecdir after infodir since that's the order we're listing\n>> > these in just a few lines earlier, and this is otherwise (mostly)\n>> > consistent.\n>\n> Actually as a quick follow-up question: for these patch sets, is it best\n> for me to have them based off of \"master\", \"next\", or a different branch?\n\nWhen you are cooperating with somebody else, e.g. in this case you\nare planning your changes to work well with the ab/install-symlinks\ntopic, there are three choices, I think.\n\n (1) Build your topic on 'master'.  From time to time (and\n     especially before sending it out to the list), do a trial merge\n     of your topic to 'master', 'next' and 'pu' to see how badly it\n     interacts with the other topic.  \n\n     If the conflicts are not too bad, and if it makes sense for\n     your topic to graduate without the other topic being in\n     'master', then this is the preferrable approach.\n\n (2) Build your topic on top of the other's topic.  When the other\n     branch gets updated (either by rerolling if it is not yet on\n     'next', or by adding a follow up commit), you may need to\n     rebase before sending an update.\n\n     As long as you can live without new stuff added to 'master'\n     since the other's topic forked from 'master', this is probably\n     the second best option.  It definitely is worse than (1) as\n     you'd need to rebase on top of other's work, which will become\n     impossible once your topic hits 'next'.\n\n (3) Make a merge of the other's topic into 'master', and then build\n     your topic on top of the result.  Keep the updates from the\n     other's topic to the minimum once you start working on your\n     topic to simplify the task to update your topic.  From time to\n     time, do a trial merge to 'master', 'next' and 'pu' to ensure\n     you are compatible with the updates made to the other's topic\n     since you forked from them.\n\n     As long as the other's topic is already fairly stable, and if\n     you need to depend on new stuff added to 'master' since the\n     other's topic forked from 'master', this is a workable\n     approach.\n\nI suspect that (1) is fine in this case.  As to the reordering of\ngitexecdir_relative thing Ævar mentioned, I agree that such a change\nis good because the order of the lines in the result makes more\nsense.\n\nThanks.\n"},{"id":"342256","messageId":"CAN0heSpu4Lv9P+zzKPgJe3nx+J20Yex9is8SCztKobLc5ZfWCA@mail.gmail.com","threadId":"48078","inReplyTo":"20180319025046.58052-3-dnj@google.com","subject":"Re: [PATCH v6 2/3] Makefile: add Perl runtime prefix support","fromName":"Martin Ågren","fromEmail":"martin.agren@gmail.com","sentAt":"2018-03-19T21:32:37Z","receivedAt":"2018-03-19T21:32:46Z","isPatch":true,"sender":{"key":"martin.agren@gmail.com","avatar":null},"body":"On 19 March 2018 at 03:50, Dan Jacques <dnj@google.com> wrote:\n> Add a new Makefile flag, RUNTIME_PREFIX_PERL, which, when enabled,\n> configures Perl scripts to locate the Git installation's Perl support\n> libraries by resolving against the script's path, rather than\n> hard-coding that path at build-time.\n>\n> RUNTIME_PREFIX_PERL requires that system paths are expressed relative to\n\nThis commit message mentions RUNTIME_PREFIX_PERL twice, but there is no\nuse of RUNTIME_PREFIX_PERL in the actual diffs (patches 1-3/3). Should\nit be s/_PERL//? Your cover letter hints as much under \"Changes in v6\nfrom v5\". And \"Add a new Makefile flag ...\" would need some more\nrewriting since this patch rather expands the scope of the existing\nflag?\n\n> a common installation directory, and uses that relationship to locate\n> support files based on the known starting point of the script being\n> executed, much like RUNTIME_PREFIX does for the Git binary.\n\nWith s/_PERL//, this part above reads a bit odd. Would this be\ns/RUNTIME_PREFIX/it/?\n\nMartin\n"},{"id":"342260","messageId":"CAD1RUU-emF0n2Qwvs_A4GqZ=CVZmfoRWoSAkr7J6yeov7zfp4Q@mail.gmail.com","threadId":"48078","inReplyTo":"CAN0heSpu4Lv9P+zzKPgJe3nx+J20Yex9is8SCztKobLc5ZfWCA@mail.gmail.com","subject":"Re: [PATCH v6 2/3] Makefile: add Perl runtime prefix support","fromName":"Daniel Jacques","fromEmail":"dnj@google.com","sentAt":"2018-03-19T22:07:02Z","receivedAt":"2018-03-19T22:07:22Z","isPatch":true,"sender":{"key":"dnj@google.com","avatar":"https://avatars.githubusercontent.com/u/9965104?v=4"},"body":"On Mon, Mar 19, 2018 at 5:32 PM Martin Ågren <martin.agren@gmail.com> wrote:\n\n> This commit message mentions RUNTIME_PREFIX_PERL twice, but there is no\n> use of RUNTIME_PREFIX_PERL in the actual diffs (patches 1-3/3). Should\n> it be s/_PERL//? Your cover letter hints as much under \"Changes in v6\n> from v5\". And \"Add a new Makefile flag ...\" would need some more\n> rewriting since this patch rather expands the scope of the existing\n> flag?\n\nThanks for pointing this out - the two were separate flags in my original\npatch set because I\nwanted to minimize the scope of impact; however, I have since received\nadvice and buy-in\non converging them and RUNTIME_PREFIX_PERL functionality was merged\nunderneath\nof RUNTIME_PREFIX in this latest patch set.\n\nI'll update the commit message!\n"}]}