Merge branch 'sp/runtime-prefix'

* sp/runtime-prefix:
  Windows: Revert to default paths and convert them by RUNTIME_PREFIX
  Compute prefix at runtime if RUNTIME_PREFIX is set
  Modify setup_path() to only add git_exec_path() to PATH
  Add calls to git_extract_argv0_path() in programs that call git_config_*
  git_extract_argv0_path(): Move check for valid argv0 from caller to callee
  Refactor git_set_argv0_path() to git_extract_argv0_path()
  Move computation of absolute paths from Makefile to runtime (in preparation for RUNTIME_PREFIX)
This commit is contained in:
Junio C Hamano 2009-01-31 17:43:59 -08:00
Родитель fa5bc8abb3 2565522174
Коммит ed096c4a23
21 изменённых файлов: 151 добавлений и 46 удалений

Просмотреть файл

@ -182,28 +182,32 @@ STRIP ?= strip
# Among the variables below, these:
# gitexecdir
# template_dir
# mandir
# infodir
# htmldir
# ETC_GITCONFIG (but not sysconfdir)
# can be specified as a relative path ../some/where/else (which must begin
# with ../); this is interpreted as relative to $(bindir) and "git" at
# can be specified as a relative path some/where/else;
# this is interpreted as relative to $(prefix) and "git" at
# runtime figures out where they are based on the path to the executable.
# This can help installing the suite in a relocatable way.
prefix = $(HOME)
bindir = $(prefix)/bin
mandir = $(prefix)/share/man
infodir = $(prefix)/share/info
gitexecdir = $(prefix)/libexec/git-core
bindir_relative = bin
bindir = $(prefix)/$(bindir_relative)
mandir = share/man
infodir = share/info
gitexecdir = libexec/git-core
sharedir = $(prefix)/share
template_dir = $(sharedir)/git-core/templates
htmldir=$(sharedir)/doc/git-doc
template_dir = share/git-core/templates
htmldir = share/doc/git-doc
ifeq ($(prefix),/usr)
sysconfdir = /etc
ETC_GITCONFIG = $(sysconfdir)/gitconfig
else
sysconfdir = $(prefix)/etc
ETC_GITCONFIG = etc/gitconfig
endif
lib = lib
ETC_GITCONFIG = $(sysconfdir)/gitconfig
# DESTDIR=
# default configuration for gitweb
@ -790,6 +794,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
SNPRINTF_RETURNS_BOGUS = YesPlease
NO_SVN_TESTS = YesPlease
NO_PERL_MAKEMAKER = YesPlease
RUNTIME_PREFIX = YesPlease
NO_POSIX_ONLY_PROGRAMS = YesPlease
NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease
COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/regex -Icompat/fnmatch
@ -798,9 +803,6 @@ ifneq (,$(findstring MINGW,$(uname_S)))
COMPAT_OBJS += compat/mingw.o compat/fnmatch/fnmatch.o compat/regex/regex.o compat/winansi.o
EXTLIBS += -lws2_32
X = .exe
gitexecdir = ../libexec/git-core
template_dir = ../share/git-core/templates/
ETC_GITCONFIG = ../etc/gitconfig
endif
ifneq (,$(findstring arm,$(uname_M)))
ARM_SHA1 = YesPlease
@ -1038,6 +1040,9 @@ ifdef INTERNAL_QSORT
COMPAT_CFLAGS += -DINTERNAL_QSORT
COMPAT_OBJS += compat/qsort.o
endif
ifdef RUNTIME_PREFIX
COMPAT_CFLAGS += -DRUNTIME_PREFIX
endif
ifdef NO_PTHREADS
THREADED_DELTA_SEARCH =
@ -1097,6 +1102,7 @@ ETC_GITCONFIG_SQ = $(subst ','\'',$(ETC_GITCONFIG))
DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
bindir_SQ = $(subst ','\'',$(bindir))
bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
mandir_SQ = $(subst ','\'',$(mandir))
infodir_SQ = $(subst ','\'',$(infodir))
gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
@ -1262,7 +1268,12 @@ git.o git.spec \
$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $<
exec_cmd.o: exec_cmd.c GIT-CFLAGS
$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' $<
$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) \
'-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
'-DBINDIR="$(bindir_relative_SQ)"' \
'-DPREFIX="$(prefix_SQ)"' \
$<
builtin-init-db.o: builtin-init-db.c GIT-CFLAGS
$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"' $<
@ -1422,17 +1433,17 @@ remove-dashes:
### Installation rules
ifeq ($(firstword $(subst /, ,$(template_dir))),..)
template_instdir = $(bindir)/$(template_dir)
else
ifeq ($(abspath $(template_dir)),$(template_dir))
template_instdir = $(template_dir)
else
template_instdir = $(prefix)/$(template_dir)
endif
export template_instdir
ifeq ($(firstword $(subst /, ,$(gitexecdir))),..)
gitexec_instdir = $(bindir)/$(gitexecdir)
else
ifeq ($(abspath $(gitexecdir)),$(gitexecdir))
gitexec_instdir = $(gitexecdir)
else
gitexec_instdir = $(prefix)/$(gitexecdir)
endif
gitexec_instdir_SQ = $(subst ','\'',$(gitexec_instdir))
export gitexec_instdir

Просмотреть файл

@ -329,7 +329,7 @@ static void setup_man_path(void)
* old_path, the ':' at the end will let 'man' to try
* system-wide paths after ours to find the manual page. If
* there is old_path, we need ':' as delimiter. */
strbuf_addstr(&new_path, GIT_MAN_PATH);
strbuf_addstr(&new_path, system_path(GIT_MAN_PATH));
strbuf_addch(&new_path, ':');
if (old_path)
strbuf_addstr(&new_path, old_path);
@ -375,7 +375,7 @@ static void show_man_page(const char *git_cmd)
static void show_info_page(const char *git_cmd)
{
const char *page = cmd_to_page(git_cmd);
setenv("INFOPATH", GIT_INFO_PATH, 1);
setenv("INFOPATH", system_path(GIT_INFO_PATH), 1);
execlp("info", "info", "gitman", page, NULL);
}

Просмотреть файл

@ -937,6 +937,8 @@ int main(int argc, char **argv)
gid_t gid = 0;
int i;
git_extract_argv0_path(argv[0]);
for (i = 1; i < argc; i++) {
char *arg = argv[i];

Просмотреть файл

@ -9,17 +9,78 @@ static const char *argv0_path;
const char *system_path(const char *path)
{
if (!is_absolute_path(path) && argv0_path) {
struct strbuf d = STRBUF_INIT;
strbuf_addf(&d, "%s/%s", argv0_path, path);
path = strbuf_detach(&d, NULL);
#ifdef RUNTIME_PREFIX
static const char *prefix;
#else
static const char *prefix = PREFIX;
#endif
struct strbuf d = STRBUF_INIT;
if (is_absolute_path(path))
return path;
#ifdef RUNTIME_PREFIX
assert(argv0_path);
assert(is_absolute_path(argv0_path));
if (!prefix) {
const char *strip[] = {
GIT_EXEC_PATH,
BINDIR,
0
};
const char **s;
for (s = strip; *s; s++) {
const char *sargv = argv0_path + strlen(argv0_path);
const char *ss = *s + strlen(*s);
while (argv0_path < sargv && *s < ss
&& (*sargv == *ss ||
(is_dir_sep(*sargv) && is_dir_sep(*ss)))) {
sargv--;
ss--;
}
if (*s == ss) {
struct strbuf d = STRBUF_INIT;
/* We also skip the trailing directory separator. */
assert(sargv - argv0_path - 1 >= 0);
strbuf_add(&d, argv0_path, sargv - argv0_path - 1);
prefix = strbuf_detach(&d, NULL);
break;
}
}
}
if (!prefix) {
prefix = PREFIX;
fprintf(stderr, "RUNTIME_PREFIX requested, "
"but prefix computation failed. "
"Using static fallback '%s'.\n", prefix);
}
#endif
strbuf_addf(&d, "%s/%s", prefix, path);
path = strbuf_detach(&d, NULL);
return path;
}
void git_set_argv0_path(const char *path)
const char *git_extract_argv0_path(const char *argv0)
{
argv0_path = path;
const char *slash;
if (!argv0 || !*argv0)
return NULL;
slash = argv0 + strlen(argv0);
while (argv0 <= slash && !is_dir_sep(*slash))
slash--;
if (slash >= argv0) {
argv0_path = xstrndup(argv0, slash - argv0);
return slash + 1;
}
return argv0;
}
void git_set_argv_exec_path(const char *exec_path)
@ -61,9 +122,7 @@ void setup_path(void)
const char *old_path = getenv("PATH");
struct strbuf new_path = STRBUF_INIT;
add_path(&new_path, argv_exec_path);
add_path(&new_path, getenv(EXEC_PATH_ENVIRONMENT));
add_path(&new_path, system_path(GIT_EXEC_PATH));
add_path(&new_path, git_exec_path());
add_path(&new_path, argv0_path);
if (old_path)

Просмотреть файл

@ -2,8 +2,8 @@
#define GIT_EXEC_CMD_H
extern void git_set_argv_exec_path(const char *exec_path);
extern void git_set_argv0_path(const char *path);
extern const char* git_exec_path(void);
extern const char *git_extract_argv0_path(const char *path);
extern const char *git_exec_path(void);
extern void setup_path(void);
extern const char **prepare_git_cmd(const char **argv);
extern int execv_git_cmd(const char **argv); /* NULL terminated */

Просмотреть файл

@ -150,6 +150,7 @@ Format of STDIN stream:
#include "refs.h"
#include "csum-file.h"
#include "quote.h"
#include "exec_cmd.h"
#define PACK_ID_BITS 16
#define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)
@ -2406,6 +2407,8 @@ int main(int argc, const char **argv)
{
unsigned int i, show_stats = 1;
git_extract_argv0_path(argv[0]);
setup_git_directory();
git_config(git_pack_config, NULL);
if (!pack_compression_seen && core_compression_seen)

18
git.c
Просмотреть файл

@ -442,21 +442,11 @@ static int run_argv(int *argcp, const char ***argv)
int main(int argc, const char **argv)
{
const char *cmd = argv[0] && *argv[0] ? argv[0] : "git-help";
char *slash = (char *)cmd + strlen(cmd);
const char *cmd;
/*
* Take the basename of argv[0] as the command
* name, and the dirname as the default exec_path
* if we don't have anything better.
*/
while (cmd <= slash && !is_dir_sep(*slash))
slash--;
if (cmd <= slash) {
*slash++ = 0;
git_set_argv0_path(cmd);
cmd = slash;
}
cmd = git_extract_argv0_path(argv[0]);
if (!cmd)
cmd = "git-help";
/*
* "git-xxxx" is the same as "git xxxx", but we obviously:

Просмотреть файл

@ -8,6 +8,7 @@
#include "blob.h"
#include "quote.h"
#include "parse-options.h"
#include "exec_cmd.h"
static void hash_fd(int fd, const char *type, int write_object, const char *path)
{
@ -81,6 +82,8 @@ int main(int argc, const char **argv)
type = blob_type;
git_extract_argv0_path(argv[0]);
git_config(git_default_config, NULL);
argc = parse_options(argc, argv, hash_object_options, hash_object_usage, 0);

Просмотреть файл

@ -2196,6 +2196,8 @@ int main(int argc, char **argv)
struct ref *ref;
char *rewritten_url = NULL;
git_extract_argv0_path(argv[0]);
setup_git_directory();
remote = xcalloc(sizeof(*remote), 1);

Просмотреть файл

@ -23,6 +23,7 @@
*/
#include "cache.h"
#include "exec_cmd.h"
#ifdef NO_OPENSSL
typedef void *SSL;
#endif
@ -1389,6 +1390,8 @@ int main(int argc, char **argv)
int total, n = 0;
int nongit_ok;
git_extract_argv0_path(argv[0]);
/* init the random number generator */
arc4_init();

Просмотреть файл

@ -8,6 +8,7 @@
#include "tree.h"
#include "progress.h"
#include "fsck.h"
#include "exec_cmd.h"
static const char index_pack_usage[] =
"git index-pack [-v] [-o <index-file>] [{ ---keep | --keep=<msg> }] [--strict] { <pack-file> | --stdin [--fix-thin] [<pack-file>] }";
@ -880,6 +881,8 @@ int main(int argc, char **argv)
struct pack_idx_entry **idx_objects;
unsigned char pack_sha1[20];
git_extract_argv0_path(argv[0]);
/*
* We wish to read the repository's config file if any, and
* for that it is necessary to call setup_git_directory_gently().

Просмотреть файл

@ -1,5 +1,6 @@
#include "cache.h"
#include "run-command.h"
#include "exec_cmd.h"
static const char *pgm;
static const char *arguments[9];
@ -93,6 +94,8 @@ int main(int argc, char **argv)
if (argc < 3)
usage("git-merge-index [-o] [-q] <merge-program> (-a | [--] <filename>*)");
git_extract_argv0_path(argv[0]);
setup_git_directory();
read_cache();

Просмотреть файл

@ -2,6 +2,7 @@
#include "tree-walk.h"
#include "xdiff-interface.h"
#include "blob.h"
#include "exec_cmd.h"
static const char merge_tree_usage[] = "git-merge-tree <base-tree> <branch1> <branch2>";
static int resolve_directories = 1;
@ -344,6 +345,8 @@ int main(int argc, char **argv)
if (argc != 4)
usage(merge_tree_usage);
git_extract_argv0_path(argv[0]);
setup_git_directory();
buf1 = get_tree_descriptor(t+0, argv[1]);

Просмотреть файл

@ -1,5 +1,6 @@
#include "cache.h"
#include "tag.h"
#include "exec_cmd.h"
/*
* A signature file has a very simple fixed format: four lines
@ -159,6 +160,8 @@ int main(int argc, char **argv)
if (argc != 1)
usage("git-mktag < signaturefile");
git_extract_argv0_path(argv[0]);
setup_git_directory();
if (strbuf_read(&buf, 0, 4096) < 0) {

Просмотреть файл

@ -6,6 +6,7 @@
#include "cache.h"
#include "quote.h"
#include "tree.h"
#include "exec_cmd.h"
static struct treeent {
unsigned mode;
@ -70,6 +71,8 @@ int main(int ac, char **av)
unsigned char sha1[20];
int line_termination = '\n';
git_extract_argv0_path(av[0]);
setup_git_directory();
while ((1 < ac) && av[1][0] == '-') {

Просмотреть файл

@ -7,6 +7,7 @@
*/
#include "cache.h"
#include "exec_cmd.h"
#define BLKSIZE 512
@ -601,6 +602,8 @@ int main(int argc, char **argv)
unsigned char *sha1;
char buf[42]; /* 40 byte sha1 + \n + \0 */
git_extract_argv0_path(argv[0]);
setup_git_directory();
for (i = 1; i < argc; i++) {

Просмотреть файл

@ -1,4 +1,5 @@
#include "cache.h"
#include "exec_cmd.h"
static void flush_current_id(int patchlen, unsigned char *id, git_SHA_CTX *c)
{
@ -79,6 +80,8 @@ int main(int argc, char **argv)
if (argc != 1)
usage(patch_id_usage);
git_extract_argv0_path(argv[0]);
generate_id_list();
return 0;
}

Просмотреть файл

@ -1,5 +1,6 @@
#include "cache.h"
#include "blob.h"
#include "exec_cmd.h"
static char *create_temp_file(unsigned char *sha1)
{
@ -25,6 +26,8 @@ int main(int argc, char **argv)
{
unsigned char sha1[20];
git_extract_argv0_path(argv[0]);
if (argc != 2)
usage("git-unpack-file <sha1>");
if (get_sha1(argv[1], sha1))

Просмотреть файл

@ -1,4 +1,5 @@
#include "cache.h"
#include "exec_cmd.h"
static const char update_server_info_usage[] =
"git update-server-info [--force]";
@ -19,6 +20,8 @@ int main(int ac, char **av)
if (i != ac)
usage(update_server_info_usage);
git_extract_argv0_path(av[0]);
setup_git_directory();
return !!update_server_info(force);

Просмотреть файл

@ -616,6 +616,8 @@ int main(int argc, char **argv)
int i;
int strict = 0;
git_extract_argv0_path(argv[0]);
for (i = 1; i < argc; i++) {
char *arg = argv[i];

3
var.c
Просмотреть файл

@ -4,6 +4,7 @@
* Copyright (C) Eric Biederman, 2005
*/
#include "cache.h"
#include "exec_cmd.h"
static const char var_usage[] = "git var [-l | <variable>]";
@ -56,6 +57,8 @@ int main(int argc, char **argv)
usage(var_usage);
}
git_extract_argv0_path(argv[0]);
setup_git_directory_gently(&nongit);
val = NULL;