Merge branch 'dj/runtime-prefix'
authorJunio C Hamano <gitster@pobox.com>
Tue, 8 May 2018 06:59:17 +0000 (15:59 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 May 2018 06:59:17 +0000 (15:59 +0900)
A build-time option has been added to allow Git to be told to refer
to its associated files relative to the main binary, in the same
way that has been possible on Windows for quite some time, for
Linux, BSDs and Darwin.

* dj/runtime-prefix:
Makefile: quote $INSTLIBDIR when passing it to sed
Makefile: remove unused @@PERLLIBDIR@@ substitution variable
mingw/msvc: use the new-style RUNTIME_PREFIX helper
exec_cmd: provide a new-style RUNTIME_PREFIX helper for Windows
exec_cmd: RUNTIME_PREFIX on some POSIX systems
Makefile: add Perl runtime prefix support
Makefile: generate Perl header from template file

1  2 
.gitignore
Makefile
cache.h
common-main.c
exec-cmd.c
exec-cmd.h
gettext.c
git.c
diff --combined .gitignore
index 2d0450c262e1c8ec9cb433b7eb78e168274060f5,89bd7bd8a781d7425e7924c26876a62b16ac58d1..8d9a4585554b46909d7bea62d79746eac67ab7e9
@@@ -3,6 -3,7 +3,7 @@@
  /GIT-LDFLAGS
  /GIT-PREFIX
  /GIT-PERL-DEFINES
+ /GIT-PERL-HEADER
  /GIT-PYTHON-VARS
  /GIT-SCRIPT-DEFINES
  /GIT-USER-AGENT
  /git-rm
  /git-send-email
  /git-send-pack
 +/git-serve
  /git-sh-i18n
  /git-sh-i18n--envsubst
  /git-sh-setup
diff --combined Makefile
index b345d0eaa956e9a28be7c852e1988cc9e81b65bb,2ba24035f55d8cc5b10aaf44bddbf4c3d86bf089..46a215dc89f61ccb24ade982315251c3ed2de16a
+++ b/Makefile
@@@ -441,6 -441,29 +441,29 @@@ all:
  #
  # When cross-compiling, define HOST_CPU as the canonical name of the CPU on
  # which the built Git will run (for instance "x86_64").
+ #
+ # Define RUNTIME_PREFIX to configure Git to resolve its ancillary tooling and
+ # support files relative to the location of the runtime binary, rather than
+ # hard-coding them into the binary. Git installations built with RUNTIME_PREFIX
+ # can be moved to arbitrary filesystem locations. RUNTIME_PREFIX also causes
+ # Perl scripts to use a modified entry point header allowing them to resolve
+ # support files at runtime.
+ #
+ # When using RUNTIME_PREFIX, define HAVE_BSD_KERN_PROC_SYSCTL if your platform
+ # supports the KERN_PROC BSD sysctl function.
+ #
+ # When using RUNTIME_PREFIX, define PROCFS_EXECUTABLE_PATH if your platform
+ # mounts a "procfs" filesystem capable of resolving the path of the current
+ # executable. If defined, this must be the canonical path for the "procfs"
+ # current executable path.
+ #
+ # When using RUNTIME_PREFIX, define HAVE_NS_GET_EXECUTABLE_PATH if your platform
+ # supports calling _NSGetExecutablePath to retrieve the path of the running
+ # executable.
+ #
+ # When using RUNTIME_PREFIX, define HAVE_WPGMPTR if your platform offers
+ # the global variable _wpgmptr containing the absolute path of the current
+ # executable (this is the case on Windows).
  
  GIT-VERSION-FILE: FORCE
        @$(SHELL_PATH) ./GIT-VERSION-GEN
@@@ -478,6 -501,8 +501,8 @@@ ARFLAGS = rc
  #   mandir
  #   infodir
  #   htmldir
+ #   localedir
+ #   perllibdir
  # This can help installing the suite in a relocatable way.
  
  prefix = $(HOME)
@@@ -502,7 -527,9 +527,9 @@@ bindir_relative = $(patsubst $(prefix)/
  mandir_relative = $(patsubst $(prefix)/%,%,$(mandir))
  infodir_relative = $(patsubst $(prefix)/%,%,$(infodir))
  gitexecdir_relative = $(patsubst $(prefix)/%,%,$(gitexecdir))
+ localedir_relative = $(patsubst $(prefix)/%,%,$(localedir))
  htmldir_relative = $(patsubst $(prefix)/%,%,$(htmldir))
+ perllibdir_relative = $(patsubst $(prefix)/%,%,$(perllibdir))
  
  export prefix bindir sharedir sysconfdir gitwebdir perllibdir localedir
  
@@@ -652,6 -679,7 +679,6 @@@ PROGRAM_OBJS += imap-send.
  PROGRAM_OBJS += sh-i18n--envsubst.o
  PROGRAM_OBJS += shell.o
  PROGRAM_OBJS += show-index.o
 -PROGRAM_OBJS += upload-pack.o
  PROGRAM_OBJS += remote-testsvn.o
  
  # Binary suffix, set to .exe for Windows builds
@@@ -700,7 -728,6 +727,7 @@@ TEST_PROGRAMS_NEED_X += test-dump-untra
  TEST_PROGRAMS_NEED_X += test-fake-ssh
  TEST_PROGRAMS_NEED_X += test-line-buffer
  TEST_PROGRAMS_NEED_X += test-parse-options
 +TEST_PROGRAMS_NEED_X += test-pkt-line
  TEST_PROGRAMS_NEED_X += test-svn-fe
  TEST_PROGRAMS_NEED_X += test-tool
  
@@@ -783,7 -810,6 +810,7 @@@ LIB_OBJS += branch.
  LIB_OBJS += bulk-checkin.o
  LIB_OBJS += bundle.o
  LIB_OBJS += cache-tree.o
 +LIB_OBJS += chdir-notify.o
  LIB_OBJS += checkout.o
  LIB_OBJS += color.o
  LIB_OBJS += column.o
@@@ -819,7 -845,7 +846,7 @@@ LIB_OBJS += ewah/bitmap.
  LIB_OBJS += ewah/ewah_bitmap.o
  LIB_OBJS += ewah/ewah_io.o
  LIB_OBJS += ewah/ewah_rlw.o
 -LIB_OBJS += exec_cmd.o
 +LIB_OBJS += exec-cmd.o
  LIB_OBJS += fetch-object.o
  LIB_OBJS += fetch-pack.o
  LIB_OBJS += fsck.o
@@@ -842,11 -868,9 +869,11 @@@ LIB_OBJS += list-objects-filter-options
  LIB_OBJS += ll-merge.o
  LIB_OBJS += lockfile.o
  LIB_OBJS += log-tree.o
 +LIB_OBJS += ls-refs.o
  LIB_OBJS += mailinfo.o
  LIB_OBJS += mailmap.o
  LIB_OBJS += match-trees.o
 +LIB_OBJS += mem-pool.o
  LIB_OBJS += merge.o
  LIB_OBJS += merge-blobs.o
  LIB_OBJS += merge-recursive.o
@@@ -891,7 -915,7 +918,7 @@@ LIB_OBJS += refs/packed-backend.
  LIB_OBJS += refs/ref-cache.o
  LIB_OBJS += ref-filter.o
  LIB_OBJS += remote.o
 -LIB_OBJS += replace_object.o
 +LIB_OBJS += replace-object.o
  LIB_OBJS += repository.o
  LIB_OBJS += rerere.o
  LIB_OBJS += resolve-undo.o
@@@ -899,13 -923,12 +926,13 @@@ LIB_OBJS += revision.
  LIB_OBJS += run-command.o
  LIB_OBJS += send-pack.o
  LIB_OBJS += sequencer.o
 +LIB_OBJS += serve.o
  LIB_OBJS += server-info.o
  LIB_OBJS += setup.o
  LIB_OBJS += sha1-array.o
  LIB_OBJS += sha1-lookup.o
 -LIB_OBJS += sha1_file.o
 -LIB_OBJS += sha1_name.o
 +LIB_OBJS += sha1-file.o
 +LIB_OBJS += sha1-name.o
  LIB_OBJS += shallow.o
  LIB_OBJS += sideband.o
  LIB_OBJS += sigchain.o
@@@ -928,7 -951,6 +955,7 @@@ LIB_OBJS += tree-diff.
  LIB_OBJS += tree.o
  LIB_OBJS += tree-walk.o
  LIB_OBJS += unpack-trees.o
 +LIB_OBJS += upload-pack.o
  LIB_OBJS += url.o
  LIB_OBJS += urlmatch.o
  LIB_OBJS += usage.o
@@@ -941,7 -963,7 +968,7 @@@ LIB_OBJS += walker.
  LIB_OBJS += wildmatch.o
  LIB_OBJS += worktree.o
  LIB_OBJS += wrapper.o
 -LIB_OBJS += write_or_die.o
 +LIB_OBJS += write-or-die.o
  LIB_OBJS += ws.o
  LIB_OBJS += wt-status.o
  LIB_OBJS += xdiff-interface.o
@@@ -1033,7 -1055,6 +1060,7 @@@ BUILTIN_OBJS += builtin/rev-parse.
  BUILTIN_OBJS += builtin/revert.o
  BUILTIN_OBJS += builtin/rm.o
  BUILTIN_OBJS += builtin/send-pack.o
 +BUILTIN_OBJS += builtin/serve.o
  BUILTIN_OBJS += builtin/shortlog.o
  BUILTIN_OBJS += builtin/show-branch.o
  BUILTIN_OBJS += builtin/show-ref.o
@@@ -1047,7 -1068,6 +1074,7 @@@ BUILTIN_OBJS += builtin/update-index.
  BUILTIN_OBJS += builtin/update-ref.o
  BUILTIN_OBJS += builtin/update-server-info.o
  BUILTIN_OBJS += builtin/upload-archive.o
 +BUILTIN_OBJS += builtin/upload-pack.o
  BUILTIN_OBJS += builtin/var.o
  BUILTIN_OBJS += builtin/verify-commit.o
  BUILTIN_OBJS += builtin/verify-pack.o
@@@ -1670,10 -1690,27 +1697,27 @@@ ifdef HAVE_BSD_SYSCT
        BASIC_CFLAGS += -DHAVE_BSD_SYSCTL
  endif
  
+ ifdef HAVE_BSD_KERN_PROC_SYSCTL
+       BASIC_CFLAGS += -DHAVE_BSD_KERN_PROC_SYSCTL
+ endif
  ifdef HAVE_GETDELIM
        BASIC_CFLAGS += -DHAVE_GETDELIM
  endif
  
+ ifneq ($(PROCFS_EXECUTABLE_PATH),)
+       procfs_executable_path_SQ = $(subst ','\'',$(PROCFS_EXECUTABLE_PATH))
+       BASIC_CFLAGS += '-DPROCFS_EXECUTABLE_PATH="$(procfs_executable_path_SQ)"'
+ endif
+ ifdef HAVE_NS_GET_EXECUTABLE_PATH
+       BASIC_CFLAGS += -DHAVE_NS_GET_EXECUTABLE_PATH
+ endif
+ ifdef HAVE_WPGMPTR
+       BASIC_CFLAGS += -DHAVE_WPGMPTR
+ endif
  ifeq ($(TCLTK_PATH),)
  NO_TCLTK = NoThanks
  endif
@@@ -1758,11 -1795,13 +1802,13 @@@ mandir_relative_SQ = $(subst ','\'',$(m
  infodir_relative_SQ = $(subst ','\'',$(infodir_relative))
  perllibdir_SQ = $(subst ','\'',$(perllibdir))
  localedir_SQ = $(subst ','\'',$(localedir))
+ localedir_relative_SQ = $(subst ','\'',$(localedir_relative))
  gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
  gitexecdir_relative_SQ = $(subst ','\'',$(gitexecdir_relative))
  template_dir_SQ = $(subst ','\'',$(template_dir))
  htmldir_relative_SQ = $(subst ','\'',$(htmldir_relative))
  prefix_SQ = $(subst ','\'',$(prefix))
+ perllibdir_relative_SQ = $(subst ','\'',$(perllibdir_relative))
  gitwebdir_SQ = $(subst ','\'',$(gitwebdir))
  
  SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
@@@ -1773,6 -1812,31 +1819,31 @@@ TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_
  DIFF_SQ = $(subst ','\'',$(DIFF))
  PERLLIB_EXTRA_SQ = $(subst ','\'',$(PERLLIB_EXTRA))
  
+ # RUNTIME_PREFIX's resolution logic requires resource paths to be expressed
+ # relative to each other and share an installation path.
+ #
+ # This is a dependency in:
+ # - Git's binary RUNTIME_PREFIX logic in (see "exec_cmd.c").
+ # - The runtime prefix Perl header (see
+ #   "perl/header_templates/runtime_prefix.template.pl").
+ ifdef RUNTIME_PREFIX
+ ifneq ($(filter /%,$(firstword $(gitexecdir_relative))),)
+ $(error RUNTIME_PREFIX requires a relative gitexecdir, not: $(gitexecdir))
+ endif
+ ifneq ($(filter /%,$(firstword $(localedir_relative))),)
+ $(error RUNTIME_PREFIX requires a relative localedir, not: $(localedir))
+ endif
+ ifndef NO_PERL
+ ifneq ($(filter /%,$(firstword $(perllibdir_relative))),)
+ $(error RUNTIME_PREFIX requires a relative perllibdir, not: $(perllibdir))
+ endif
+ endif
+ endif
  # We must filter out any object files from $(GITLIBS),
  # as it is typically used like:
  #
@@@ -1993,27 -2057,44 +2064,44 @@@ git.res: git.rc GIT-VERSION-FIL
  # This makes sure we depend on the NO_PERL setting itself.
  $(SCRIPT_PERL_GEN): GIT-BUILD-OPTIONS
  
- ifndef NO_PERL
- $(SCRIPT_PERL_GEN):
+ # Used for substitution in Perl modules. Disabled when using RUNTIME_PREFIX
+ # since the locale directory is injected.
+ perl_localedir_SQ = $(localedir_SQ)
  
+ ifndef NO_PERL
+ PERL_HEADER_TEMPLATE = perl/header_templates/fixed_prefix.template.pl
  PERL_DEFINES = $(PERL_PATH_SQ):$(PERLLIB_EXTRA_SQ):$(perllibdir_SQ)
- $(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-VERSION-FILE
+ PERL_DEFINES := $(PERL_PATH_SQ) $(PERLLIB_EXTRA_SQ) $(perllibdir_SQ)
+ PERL_DEFINES += $(RUNTIME_PREFIX)
+ # Support Perl runtime prefix. In this mode, a different header is installed
+ # into Perl scripts.
+ ifdef RUNTIME_PREFIX
+ PERL_HEADER_TEMPLATE = perl/header_templates/runtime_prefix.template.pl
+ # Don't export a fixed $(localedir) path; it will be resolved by the Perl header
+ # at runtime.
+ perl_localedir_SQ =
+ endif
+ PERL_DEFINES += $(gitexecdir) $(perllibdir) $(localedir)
+ $(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE
        $(QUIET_GEN)$(RM) $@ $@+ && \
-       INSTLIBDIR='$(perllibdir_SQ)' && \
-       INSTLIBDIR_EXTRA='$(PERLLIB_EXTRA_SQ)' && \
-       INSTLIBDIR="$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}" && \
        sed -e '1{' \
            -e '        s|#!.*perl|#!$(PERL_PATH_SQ)|' \
-           -e '        h' \
-           -e '        s=.*=use lib (split(/$(pathsep)/, $$ENV{GITPERLLIB} || "'"$$INSTLIBDIR"'"));=' \
-           -e '        H' \
-           -e '        x' \
+           -e '        rGIT-PERL-HEADER' \
+           -e '        G' \
            -e '}' \
            -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
            $< >$@+ && \
        chmod +x $@+ && \
        mv $@+ $@
  
+ PERL_DEFINES := $(subst $(space),:,$(PERL_DEFINES))
  GIT-PERL-DEFINES: FORCE
        @FLAGS='$(PERL_DEFINES)'; \
            if test x"$$FLAGS" != x"`cat $@ 2>/dev/null`" ; then \
                echo "$$FLAGS" >$@; \
            fi
  
+ GIT-PERL-HEADER: $(PERL_HEADER_TEMPLATE) GIT-PERL-DEFINES Makefile
+       $(QUIET_GEN)$(RM) $@ && \
+       INSTLIBDIR='$(perllibdir_SQ)' && \
+       INSTLIBDIR_EXTRA='$(PERLLIB_EXTRA_SQ)' && \
+       INSTLIBDIR="$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}" && \
+       sed -e 's=@@PATHSEP@@=$(pathsep)=g' \
+           -e "s=@@INSTLIBDIR@@=$$INSTLIBDIR=g" \
+           -e 's=@@PERLLIBDIR_REL@@=$(perllibdir_relative_SQ)=g' \
+           -e 's=@@GITEXECDIR_REL@@=$(gitexecdir_relative_SQ)=g' \
+           -e 's=@@LOCALEDIR_REL@@=$(localedir_relative_SQ)=g' \
+           $< >$@+ && \
+       mv $@+ $@
 +.PHONY: perllibdir
 +perllibdir:
 +      @echo '$(perllibdir_SQ)'
 +
  .PHONY: gitweb
  gitweb:
        $(QUIET_SUBDIR0)gitweb $(QUIET_SUBDIR1) all
  $(OBJECTS): $(LIB_H)
  endif
  
 -exec_cmd.sp exec_cmd.s exec_cmd.o: GIT-PREFIX
 -exec_cmd.sp exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
 +exec-cmd.sp exec-cmd.s exec-cmd.o: GIT-PREFIX
 +exec-cmd.sp exec-cmd.s exec-cmd.o: EXTRA_CPPFLAGS = \
        '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
+       '-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \
        '-DBINDIR="$(bindir_relative_SQ)"' \
        '-DPREFIX="$(prefix_SQ)"'
  
@@@ -2185,7 -2276,7 +2287,7 @@@ attr.sp attr.s attr.o: EXTRA_CPPFLAGS 
  
  gettext.sp gettext.s gettext.o: GIT-PREFIX
  gettext.sp gettext.s gettext.o: EXTRA_CPPFLAGS = \
-       -DGIT_LOCALE_PATH='"$(localedir_SQ)"'
+       -DGIT_LOCALE_PATH='"$(localedir_relative_SQ)"'
  
  http-push.sp http.sp http-walker.sp remote-curl.sp imap-send.sp: SPARSE_FLAGS += \
        -DCURL_DISABLE_TYPECHECK
@@@ -2345,7 -2436,7 +2447,7 @@@ endi
  
  perl/build/lib/%.pm: perl/%.pm
        $(QUIET_GEN)mkdir -p $(dir $@) && \
-       sed -e 's|@@LOCALEDIR@@|$(localedir_SQ)|g' \
+       sed -e 's|@@LOCALEDIR@@|$(perl_localedir_SQ)|g' \
            -e 's|@@NO_PERL_CPAN_FALLBACKS@@|$(NO_PERL_CPAN_FALLBACKS_SQ)|g' \
        < $< > $@
  
@@@ -2803,7 -2894,7 +2905,7 @@@ ifndef NO_TCLT
  endif
        $(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-LDFLAGS GIT-BUILD-OPTIONS
        $(RM) GIT-USER-AGENT GIT-PREFIX
-       $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PYTHON-VARS
+       $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PERL-HEADER GIT-PYTHON-VARS
  
  .PHONY: all install profile-clean clean strip
  .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
diff --combined cache.h
index 77b7acebb6f73b6681fdd6bc4111e3b325409fdb,bc6636b7df28b8b69e51b42748a9072097fd91c5..6f14cfbb6f19dabd1aabdc63499bd741669e5c0d
+++ b/cache.h
@@@ -428,6 -428,7 +428,7 @@@ static inline enum object_type object_t
  #define GIT_ICASE_PATHSPECS_ENVIRONMENT "GIT_ICASE_PATHSPECS"
  #define GIT_QUARANTINE_ENVIRONMENT "GIT_QUARANTINE_PATH"
  #define GIT_OPTIONAL_LOCKS_ENVIRONMENT "GIT_OPTIONAL_LOCKS"
+ #define GIT_TEXT_DOMAIN_DIR_ENVIRONMENT "GIT_TEXTDOMAINDIR"
  
  /*
   * Environment variable used in handshaking the wire protocol.
@@@ -477,7 -478,7 +478,7 @@@ extern const char *get_git_common_dir(v
  extern char *get_object_directory(void);
  extern char *get_index_file(void);
  extern char *get_graft_file(void);
 -extern int set_git_dir(const char *path);
 +extern void set_git_dir(const char *path);
  extern int get_common_dir_noenv(struct strbuf *sb, const char *gitdir);
  extern int get_common_dir(struct strbuf *sb, const char *gitdir);
  extern const char *get_git_namespace(void);
diff --combined common-main.c
index b989e136b5df3736ae8e14264b9738df204f91e8,b2e5a86dffd2e11b346a71615e3f146165c41ad9..3728f66b4cce80d298aab0e551a2d3c03e2c4357
@@@ -1,5 -1,5 +1,5 @@@
  #include "cache.h"
 -#include "exec_cmd.h"
 +#include "exec-cmd.h"
  #include "attr.h"
  
  /*
@@@ -32,14 -32,14 +32,14 @@@ int main(int argc, const char **argv
         */
        sanitize_stdfds();
  
+       git_resolve_executable_dir(argv[0]);
        git_setup_gettext();
  
        initialize_the_repository();
  
        attr_start();
  
-       git_extract_argv0_path(argv[0]);
        restore_sigpipe_to_default();
  
        return cmd_main(argc, argv);
diff --combined exec-cmd.c
index 8a8261746afc66441408e1a4ea3b6f98dba5f884,0000000000000000000000000000000000000000..3b0a039083a8d377325983272e4aa38ee1b5674c
mode 100644,000000..100644
--- /dev/null
@@@ -1,165 -1,0 +1,365 @@@
- #define MAX_ARGS      32
 +#include "cache.h"
 +#include "exec-cmd.h"
 +#include "quote.h"
 +#include "argv-array.h"
- static const char *argv_exec_path;
 +
- static const char *argv0_path;
++#if defined(RUNTIME_PREFIX)
++
++#if defined(HAVE_NS_GET_EXECUTABLE_PATH)
++#include <mach-o/dyld.h>
++#endif
++
++#if defined(HAVE_BSD_KERN_PROC_SYSCTL)
++#include <sys/param.h>
++#include <sys/types.h>
++#include <sys/sysctl.h>
++#endif
++
++#endif /* RUNTIME_PREFIX */
++
++#define MAX_ARGS 32
++
++static const char *system_prefix(void);
 +
 +#ifdef RUNTIME_PREFIX
-       assert(argv0_path);
-       assert(is_absolute_path(argv0_path));
++
++/**
++ * When using a runtime prefix, Git dynamically resolves paths relative to its
++ * executable.
++ *
++ * The method for determining the path of the executable is highly
++ * platform-specific.
++ */
++
++/**
++ * Path to the current Git executable. Resolved on startup by
++ * 'git_resolve_executable_dir'.
++ */
++static const char *executable_dirname;
 +
 +static const char *system_prefix(void)
 +{
 +      static const char *prefix;
 +
-           !(prefix = strip_path_suffix(argv0_path, GIT_EXEC_PATH)) &&
-           !(prefix = strip_path_suffix(argv0_path, BINDIR)) &&
-           !(prefix = strip_path_suffix(argv0_path, "git"))) {
++      assert(executable_dirname);
++      assert(is_absolute_path(executable_dirname));
 +
 +      if (!prefix &&
- void git_extract_argv0_path(const char *argv0)
++          !(prefix = strip_path_suffix(executable_dirname, GIT_EXEC_PATH)) &&
++          !(prefix = strip_path_suffix(executable_dirname, BINDIR)) &&
++          !(prefix = strip_path_suffix(executable_dirname, "git"))) {
 +              prefix = PREFIX;
 +              trace_printf("RUNTIME_PREFIX requested, "
 +                              "but prefix computation failed.  "
 +                              "Using static fallback '%s'.\n", prefix);
 +      }
 +      return prefix;
 +}
 +
-               return;
++/*
++ * Resolves the executable path from argv[0], only if it is absolute.
++ *
++ * Returns 0 on success, -1 on failure.
++ */
++static int git_get_exec_path_from_argv0(struct strbuf *buf, const char *argv0)
 +{
 +      const char *slash;
 +
 +      if (!argv0 || !*argv0)
-               argv0_path = xstrndup(argv0, slash - argv0);
++              return -1;
 +
 +      slash = find_last_dir_sep(argv0);
++      if (slash) {
++              trace_printf("trace: resolved executable path from argv0: %s\n",
++                           argv0);
++              strbuf_add_absolute_path(buf, argv0);
++              return 0;
++      }
++      return -1;
++}
++
++#ifdef PROCFS_EXECUTABLE_PATH
++/*
++ * Resolves the executable path by examining a procfs symlink.
++ *
++ * Returns 0 on success, -1 on failure.
++ */
++static int git_get_exec_path_procfs(struct strbuf *buf)
++{
++      if (strbuf_realpath(buf, PROCFS_EXECUTABLE_PATH, 0)) {
++              trace_printf(
++                      "trace: resolved executable path from procfs: %s\n",
++                      buf->buf);
++              return 0;
++      }
++      return -1;
++}
++#endif /* PROCFS_EXECUTABLE_PATH */
++
++#ifdef HAVE_BSD_KERN_PROC_SYSCTL
++/*
++ * Resolves the executable path using KERN_PROC_PATHNAME BSD sysctl.
++ *
++ * Returns 0 on success, -1 on failure.
++ */
++static int git_get_exec_path_bsd_sysctl(struct strbuf *buf)
++{
++      int mib[4];
++      char path[MAXPATHLEN];
++      size_t cb = sizeof(path);
++
++      mib[0] = CTL_KERN;
++      mib[1] = KERN_PROC;
++      mib[2] = KERN_PROC_PATHNAME;
++      mib[3] = -1;
++      if (!sysctl(mib, 4, path, &cb, NULL, 0)) {
++              trace_printf(
++                      "trace: resolved executable path from sysctl: %s\n",
++                      path);
++              strbuf_addstr(buf, path);
++              return 0;
++      }
++      return -1;
++}
++#endif /* HAVE_BSD_KERN_PROC_SYSCTL */
++
++#ifdef HAVE_NS_GET_EXECUTABLE_PATH
++/*
++ * Resolves the executable path by querying Darwin application stack.
++ *
++ * Returns 0 on success, -1 on failure.
++ */
++static int git_get_exec_path_darwin(struct strbuf *buf)
++{
++      char path[PATH_MAX];
++      uint32_t size = sizeof(path);
++      if (!_NSGetExecutablePath(path, &size)) {
++              trace_printf(
++                      "trace: resolved executable path from Darwin stack: %s\n",
++                      path);
++              strbuf_addstr(buf, path);
++              return 0;
++      }
++      return -1;
++}
++#endif /* HAVE_NS_GET_EXECUTABLE_PATH */
++
++#ifdef HAVE_WPGMPTR
++/*
++ * Resolves the executable path by using the global variable _wpgmptr.
++ *
++ * Returns 0 on success, -1 on failure.
++ */
++static int git_get_exec_path_wpgmptr(struct strbuf *buf)
++{
++      int len = wcslen(_wpgmptr) * 3 + 1;
++      strbuf_grow(buf, len);
++      len = xwcstoutf(buf->buf, _wpgmptr, len);
++      if (len < 0)
++              return -1;
++      buf->len += len;
++      return 0;
++}
++#endif /* HAVE_WPGMPTR */
++
++/*
++ * Resolves the absolute path of the current executable.
++ *
++ * Returns 0 on success, -1 on failure.
++ */
++static int git_get_exec_path(struct strbuf *buf, const char *argv0)
++{
++      /*
++       * Identifying the executable path is operating system specific.
++       * Selectively employ all available methods in order of preference,
++       * preferring highly-available authoritative methods over
++       * selectively-available or non-authoritative methods.
++       *
++       * All cases fall back on resolving against argv[0] if there isn't a
++       * better functional method. However, note that argv[0] can be
++       * used-supplied on many operating systems, and is not authoritative
++       * in those cases.
++       *
++       * Each of these functions returns 0 on success, so evaluation will stop
++       * after the first successful method.
++       */
++      if (
++#ifdef HAVE_BSD_KERN_PROC_SYSCTL
++              git_get_exec_path_bsd_sysctl(buf) &&
++#endif /* HAVE_BSD_KERN_PROC_SYSCTL */
++
++#ifdef HAVE_NS_GET_EXECUTABLE_PATH
++              git_get_exec_path_darwin(buf) &&
++#endif /* HAVE_NS_GET_EXECUTABLE_PATH */
++
++#ifdef PROCFS_EXECUTABLE_PATH
++              git_get_exec_path_procfs(buf) &&
++#endif /* PROCFS_EXECUTABLE_PATH */
++
++#ifdef HAVE_WPGMPTR
++              git_get_exec_path_wpgmptr(buf) &&
++#endif /* HAVE_WPGMPTR */
++
++              git_get_exec_path_from_argv0(buf, argv0)) {
++              return -1;
++      }
++
++      if (strbuf_normalize_path(buf)) {
++              trace_printf("trace: could not normalize path: %s\n", buf->buf);
++              return -1;
++      }
++
++      return 0;
++}
 +
++void git_resolve_executable_dir(const char *argv0)
++{
++      struct strbuf buf = STRBUF_INIT;
++      char *resolved;
++      const char *slash;
++
++      if (git_get_exec_path(&buf, argv0)) {
++              trace_printf(
++                      "trace: could not determine executable path from: %s\n",
++                      argv0);
++              strbuf_release(&buf);
++              return;
++      }
++
++      resolved = strbuf_detach(&buf, NULL);
++      slash = find_last_dir_sep(resolved);
 +      if (slash)
- void git_extract_argv0_path(const char *argv0)
++              resolved[slash - resolved] = '\0';
++
++      executable_dirname = resolved;
++      trace_printf("trace: resolved executable dir: %s\n",
++                   executable_dirname);
 +}
 +
 +#else
 +
++/*
++ * When not using a runtime prefix, Git uses a hard-coded path.
++ */
 +static const char *system_prefix(void)
 +{
 +      return PREFIX;
 +}
 +
- void git_set_argv_exec_path(const char *exec_path)
++/*
++ * This is called during initialization, but No work needs to be done here when
++ * runtime prefix is not being used.
++ */
++void git_resolve_executable_dir(const char *argv0)
 +{
 +}
 +
 +#endif /* RUNTIME_PREFIX */
 +
 +char *system_path(const char *path)
 +{
 +      struct strbuf d = STRBUF_INIT;
 +
 +      if (is_absolute_path(path))
 +              return xstrdup(path);
 +
 +      strbuf_addf(&d, "%s/%s", system_prefix(), path);
 +      return strbuf_detach(&d, NULL);
 +}
 +
-       argv_exec_path = exec_path;
++static const char *exec_path_value;
++
++void git_set_exec_path(const char *exec_path)
 +{
- /* Returns the highest-priority, location to look for git programs. */
++      exec_path_value = exec_path;
 +      /*
 +       * Propagate this setting to external programs.
 +       */
 +      setenv(EXEC_PATH_ENVIRONMENT, exec_path, 1);
 +}
 +
-       static char *cached_exec_path;
-       if (argv_exec_path)
-               return argv_exec_path;
-       if (!cached_exec_path) {
++/* Returns the highest-priority location to look for git programs. */
 +const char *git_exec_path(void)
 +{
-                       cached_exec_path = xstrdup(env);
++      if (!exec_path_value) {
 +              const char *env = getenv(EXEC_PATH_ENVIRONMENT);
 +              if (env && *env)
-                       cached_exec_path = system_path(GIT_EXEC_PATH);
++                      exec_path_value = xstrdup(env);
 +              else
-       return cached_exec_path;
++                      exec_path_value = system_path(GIT_EXEC_PATH);
 +      }
-       add_path(&new_path, git_exec_path());
++      return exec_path_value;
 +}
 +
 +static void add_path(struct strbuf *out, const char *path)
 +{
 +      if (path && *path) {
 +              strbuf_add_absolute_path(out, path);
 +              strbuf_addch(out, PATH_SEP);
 +      }
 +}
 +
 +void setup_path(void)
 +{
++      const char *exec_path = git_exec_path();
 +      const char *old_path = getenv("PATH");
 +      struct strbuf new_path = STRBUF_INIT;
 +
- int execv_git_cmd(const char **argv) {
++      git_set_exec_path(exec_path);
++      add_path(&new_path, exec_path);
 +
 +      if (old_path)
 +              strbuf_addstr(&new_path, old_path);
 +      else
 +              strbuf_addstr(&new_path, _PATH_DEFPATH);
 +
 +      setenv("PATH", new_path.buf, 1);
 +
 +      strbuf_release(&new_path);
 +}
 +
 +const char **prepare_git_cmd(struct argv_array *out, const char **argv)
 +{
 +      argv_array_push(out, "git");
 +      argv_array_pushv(out, argv);
 +      return out->argv;
 +}
 +
- int execl_git_cmd(const char *cmd,...)
++int execv_git_cmd(const char **argv)
++{
 +      struct argv_array nargv = ARGV_ARRAY_INIT;
 +
 +      prepare_git_cmd(&nargv, argv);
 +      trace_argv_printf(nargv.argv, "trace: exec:");
 +
 +      /* execvp() can only ever return if it fails */
 +      sane_execvp("git", (char **)nargv.argv);
 +
 +      trace_printf("trace: exec failed: %s\n", strerror(errno));
 +
 +      argv_array_clear(&nargv);
 +      return -1;
 +}
 +
++int execl_git_cmd(const char *cmd, ...)
 +{
 +      int argc;
 +      const char *argv[MAX_ARGS + 1];
 +      const char *arg;
 +      va_list param;
 +
 +      va_start(param, cmd);
 +      argv[0] = cmd;
 +      argc = 1;
 +      while (argc < MAX_ARGS) {
 +              arg = argv[argc++] = va_arg(param, char *);
 +              if (!arg)
 +                      break;
 +      }
 +      va_end(param);
 +      if (MAX_ARGS <= argc)
 +              return error("too many args to run %s", cmd);
 +
 +      argv[argc] = NULL;
 +      return execv_git_cmd(argv);
 +}
diff --combined exec-cmd.h
index ff0b48048a6ba82827b4d441654c34c21cfb7b9a,0000000000000000000000000000000000000000..2522453cdaa74d9e9d806f20036518a394dd32e2
mode 100644,000000..100644
--- /dev/null
@@@ -1,16 -1,0 +1,16 @@@
- extern void git_set_argv_exec_path(const char *exec_path);
- extern void git_extract_argv0_path(const char *path);
 +#ifndef GIT_EXEC_CMD_H
 +#define GIT_EXEC_CMD_H
 +
 +struct argv_array;
 +
++extern void git_set_exec_path(const char *exec_path);
++extern void git_resolve_executable_dir(const char *path);
 +extern const char *git_exec_path(void);
 +extern void setup_path(void);
 +extern const char **prepare_git_cmd(struct argv_array *out, const char **argv);
 +extern int execv_git_cmd(const char **argv); /* NULL terminated */
 +LAST_ARG_MUST_BE_NULL
 +extern int execl_git_cmd(const char *cmd, ...);
 +extern char *system_path(const char *path);
 +
 +#endif /* GIT_EXEC_CMD_H */
diff --combined gettext.c
index db727ea0204aa13acea0f189ea03e59b5cdb918f,6b64d5c2e8a5cc2a194ba1486de05437dd8051c6..baba28343c311594e048d62e190ded09e49ed5b0
+++ b/gettext.c
@@@ -2,7 -2,8 +2,8 @@@
   * Copyright (c) 2010 Ævar Arnfjörð Bjarmason
   */
  
- #include "git-compat-util.h"
+ #include "cache.h"
 -#include "exec_cmd.h"
++#include "exec-cmd.h"
  #include "gettext.h"
  #include "strbuf.h"
  #include "utf8.h"
@@@ -157,10 -158,11 +158,11 @@@ static void init_gettext_charset(const 
  
  void git_setup_gettext(void)
  {
-       const char *podir = getenv("GIT_TEXTDOMAINDIR");
+       const char *podir = getenv(GIT_TEXT_DOMAIN_DIR_ENVIRONMENT);
  
        if (!podir)
-               podir = GIT_LOCALE_PATH;
+               podir = system_path(GIT_LOCALE_PATH);
        bindtextdomain("git", podir);
        setlocale(LC_MESSAGES, "");
        setlocale(LC_TIME, "");
diff --combined git.c
index 158f2cbdb15210a4f05da537690e70300fb62610,48432f9fb86cfa4b0b2dd83d608157f8b7d1d949..70798f68370abefbfa9e65c83f2e9d9ab2118107
--- 1/git.c
--- 2/git.c
+++ b/git.c
@@@ -1,6 -1,6 +1,6 @@@
  #include "builtin.h"
  #include "config.h"
 -#include "exec_cmd.h"
 +#include "exec-cmd.h"
  #include "help.h"
  #include "run-command.h"
  
@@@ -83,7 -83,7 +83,7 @@@ static int handle_options(const char **
                 */
                if (skip_prefix(cmd, "--exec-path", &cmd)) {
                        if (*cmd == '=')
-                               git_set_argv_exec_path(cmd + 1);
+                               git_set_exec_path(cmd + 1);
                        else {
                                puts(git_exec_path());
                                exit(0);
@@@ -465,7 -465,6 +465,7 @@@ static struct cmd_struct commands[] = 
        { "revert", cmd_revert, RUN_SETUP | NEED_WORK_TREE },
        { "rm", cmd_rm, RUN_SETUP },
        { "send-pack", cmd_send_pack, RUN_SETUP },
 +      { "serve", cmd_serve, RUN_SETUP },
        { "shortlog", cmd_shortlog, RUN_SETUP_GENTLY | USE_PAGER },
        { "show", cmd_show, RUN_SETUP },
        { "show-branch", cmd_show_branch, RUN_SETUP },
        { "update-server-info", cmd_update_server_info, RUN_SETUP },
        { "upload-archive", cmd_upload_archive, NO_PARSEOPT },
        { "upload-archive--writer", cmd_upload_archive_writer, NO_PARSEOPT },
 +      { "upload-pack", cmd_upload_pack },
        { "var", cmd_var, RUN_SETUP_GENTLY | NO_PARSEOPT },
        { "verify-commit", cmd_verify_commit, RUN_SETUP },
        { "verify-pack", cmd_verify_pack },