Merge branch 'sp/runtime-prefix'
authorJunio C Hamano <gitster@pobox.com>
Sun, 1 Feb 2009 01:43:59 +0000 (17:43 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sun, 1 Feb 2009 01:43:59 +0000 (17:43 -0800)
* 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)

1  2 
Makefile
http-push.c
index-pack.c
diff --combined Makefile
index d10895f3c8d9f99ee4e960ebfdab1369099d7f22,74ecd77f337585c1b657d9fb32c481bc0c35dc93..9f3a8ab0977bf23eb276e9cf5a6db96b206893e3
+++ b/Makefile
@@@ -23,9 -23,6 +23,9 @@@ all:
  # Define NO_EXPAT if you do not have expat installed.  git-http-push is
  # not built, and you cannot push using http:// and https:// transports.
  #
 +# Define EXPATDIR=/foo/bar if your expat header and library files are in
 +# /foo/bar/include and /foo/bar/lib directories.
 +#
  # Define NO_D_INO_IN_DIRENT if you don't have d_ino in your struct dirent.
  #
  # Define NO_D_TYPE_IN_DIRENT if your platform defines DT_UNKNOWN but lacks
@@@ -182,28 -179,32 +182,32 @@@ STRIP ?= stri
  # 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
@@@ -391,7 -392,6 +395,7 @@@ LIB_H += revision.
  LIB_H += run-command.h
  LIB_H += sha1-lookup.h
  LIB_H += sideband.h
 +LIB_H += sigchain.h
  LIB_H += strbuf.h
  LIB_H += tag.h
  LIB_H += transport.h
@@@ -485,7 -485,6 +489,7 @@@ LIB_OBJS += sha1-lookup.
  LIB_OBJS += sha1_name.o
  LIB_OBJS += shallow.o
  LIB_OBJS += sideband.o
 +LIB_OBJS += sigchain.o
  LIB_OBJS += strbuf.o
  LIB_OBJS += symlinks.o
  LIB_OBJS += tag.o
@@@ -790,6 -789,7 +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
        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
@@@ -822,7 -819,6 +824,7 @@@ ifeq ($(uname_S),Darwin
                        BASIC_LDFLAGS += -L/opt/local/lib
                endif
        endif
 +      PTHREAD_LIBS =
  endif
  
  ifndef CC_LD_DYNPATH
@@@ -855,12 -851,7 +857,12 @@@ els
                endif
        endif
        ifndef NO_EXPAT
 -              EXPAT_LIBEXPAT = -lexpat
 +              ifdef EXPATDIR
 +                      BASIC_CFLAGS += -I$(EXPATDIR)/include
 +                      EXPAT_LIBEXPAT = -L$(EXPATDIR)/$(lib) $(CC_LD_DYNPATH)$(EXPATDIR)/$(lib) -lexpat
 +              else
 +                      EXPAT_LIBEXPAT = -lexpat
 +              endif
        endif
  endif
  
@@@ -1038,6 -1029,9 +1040,9 @@@ ifdef INTERNAL_QSOR
        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 -1091,7 +1102,7 @@@ ETC_GITCONFIG_SQ = $(subst ','\'',$(ETC
  
  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 -1257,12 +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)"' $<
  
@@@ -1298,7 -1298,7 +1309,7 @@@ $(LIB_FILE): $(LIB_OBJS
        $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIB_OBJS)
  
  XDIFF_OBJS=xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \
 -      xdiff/xmerge.o
 +      xdiff/xmerge.o xdiff/xpatience.o
  $(XDIFF_OBJS): xdiff/xinclude.h xdiff/xmacros.h xdiff/xdiff.h xdiff/xtypes.h \
        xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h
  
@@@ -1368,7 -1368,6 +1379,7 @@@ endi
  ### Testing rules
  
  TEST_PROGRAMS += test-chmtime$X
 +TEST_PROGRAMS += test-ctype$X
  TEST_PROGRAMS += test-date$X
  TEST_PROGRAMS += test-delta$X
  TEST_PROGRAMS += test-genrandom$X
@@@ -1376,7 -1375,6 +1387,7 @@@ TEST_PROGRAMS += test-match-trees$
  TEST_PROGRAMS += test-parse-options$X
  TEST_PROGRAMS += test-path-utils$X
  TEST_PROGRAMS += test-sha1$X
 +TEST_PROGRAMS += test-sigchain$X
  
  all:: $(TEST_PROGRAMS)
  
@@@ -1389,8 -1387,6 +1400,8 @@@ export NO_SVN_TEST
  test: all
        $(MAKE) -C t/ all
  
 +test-ctype$X: ctype.o
 +
  test-date$X: date.o ctype.o
  
  test-delta$X: diff-delta.o patch-delta.o
@@@ -1422,17 -1418,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
@@@ -1456,12 -1452,10 +1467,12 @@@ endi
        { $(RM) "$$execdir/git-add$X" && \
                ln git-add$X "$$execdir/git-add$X" 2>/dev/null || \
                cp git-add$X "$$execdir/git-add$X"; } && \
 -      { $(foreach p,$(filter-out git-add$X,$(BUILT_INS)), $(RM) "$$execdir/$p" && \
 -              ln "$$execdir/git-add$X" "$$execdir/$p" 2>/dev/null || \
 -              ln -s "git-add$X" "$$execdir/$p" 2>/dev/null || \
 -              cp "$$execdir/git-add$X" "$$execdir/$p" || exit;) } && \
 +      { for p in $(filter-out git-add$X,$(BUILT_INS)); do \
 +              $(RM) "$$execdir/$$p" && \
 +              ln "$$execdir/git-add$X" "$$execdir/$$p" 2>/dev/null || \
 +              ln -s "git-add$X" "$$execdir/$$p" 2>/dev/null || \
 +              cp "$$execdir/git-add$X" "$$execdir/$$p" || exit; \
 +        done } && \
        ./check_bindir "z$$bindir" "z$$execdir" "$$bindir/git-add$X"
  
  install-doc:
diff --combined http-push.c
index 53c14141e0518dddf2a67ffabb04ce79b14fa618,a99fdfc0efe7a12d4f1c7442b483c880c662b5b7..18d81acd1b3743761b23ded035dc58e32b6aad80
@@@ -10,7 -10,6 +10,7 @@@
  #include "exec_cmd.h"
  #include "remote.h"
  #include "list-objects.h"
 +#include "sigchain.h"
  
  #include <expat.h>
  
@@@ -178,38 -177,6 +178,38 @@@ struct remote_ls_ct
        struct remote_ls_ctx *parent;
  };
  
 +/* get_dav_token_headers options */
 +enum dav_header_flag {
 +      DAV_HEADER_IF = (1u << 0),
 +      DAV_HEADER_LOCK = (1u << 1),
 +      DAV_HEADER_TIMEOUT = (1u << 2)
 +};
 +
 +static struct curl_slist *get_dav_token_headers(struct remote_lock *lock, enum dav_header_flag options)
 +{
 +      struct strbuf buf = STRBUF_INIT;
 +      struct curl_slist *dav_headers = NULL;
 +
 +      if (options & DAV_HEADER_IF) {
 +              strbuf_addf(&buf, "If: (<%s>)", lock->token);
 +              dav_headers = curl_slist_append(dav_headers, buf.buf);
 +              strbuf_reset(&buf);
 +      }
 +      if (options & DAV_HEADER_LOCK) {
 +              strbuf_addf(&buf, "Lock-Token: <%s>", lock->token);
 +              dav_headers = curl_slist_append(dav_headers, buf.buf);
 +              strbuf_reset(&buf);
 +      }
 +      if (options & DAV_HEADER_TIMEOUT) {
 +              strbuf_addf(&buf, "Timeout: Second-%ld", lock->timeout);
 +              dav_headers = curl_slist_append(dav_headers, buf.buf);
 +              strbuf_reset(&buf);
 +      }
 +      strbuf_release(&buf);
 +
 +      return dav_headers;
 +}
 +
  static void finish_request(struct transfer_request *request);
  static void release_request(struct transfer_request *request);
  
@@@ -242,7 -209,7 +242,7 @@@ static size_t fwrite_sha1_file(void *pt
        do {
                request->stream.next_out = expn;
                request->stream.avail_out = sizeof(expn);
 -              request->zret = inflate(&request->stream, Z_SYNC_FLUSH);
 +              request->zret = git_inflate(&request->stream, Z_SYNC_FLUSH);
                git_SHA1_Update(&request->c, expn,
                            sizeof(expn) - request->stream.avail_out);
        } while (request->stream.avail_in && request->zret == Z_OK);
@@@ -302,7 -269,7 +302,7 @@@ static void start_fetch_loose(struct tr
  
        memset(&request->stream, 0, sizeof(request->stream));
  
 -      inflateInit(&request->stream);
 +      git_inflate_init(&request->stream);
  
        git_SHA1_Init(&request->c);
  
           file; also rewind to the beginning of the local file. */
        if (prev_read == -1) {
                memset(&request->stream, 0, sizeof(request->stream));
 -              inflateInit(&request->stream);
 +              git_inflate_init(&request->stream);
                git_SHA1_Init(&request->c);
                if (prev_posn>0) {
                        prev_posn = 0;
@@@ -621,12 -588,18 +621,12 @@@ static int refresh_lock(struct remote_l
  {
        struct active_request_slot *slot;
        struct slot_results results;
 -      char *if_header;
 -      char timeout_header[25];
 -      struct curl_slist *dav_headers = NULL;
 +      struct curl_slist *dav_headers;
        int rc = 0;
  
        lock->refreshing = 1;
  
 -      if_header = xmalloc(strlen(lock->token) + 25);
 -      sprintf(if_header, "If: (<%s>)", lock->token);
 -      sprintf(timeout_header, "Timeout: Second-%ld", lock->timeout);
 -      dav_headers = curl_slist_append(dav_headers, if_header);
 -      dav_headers = curl_slist_append(dav_headers, timeout_header);
 +      dav_headers = get_dav_token_headers(lock, DAV_HEADER_IF | DAV_HEADER_TIMEOUT);
  
        slot = get_active_slot();
        slot->results = &results;
  
        lock->refreshing = 0;
        curl_slist_free_all(dav_headers);
 -      free(if_header);
  
        return rc;
  }
@@@ -768,7 -742,7 +768,7 @@@ static void finish_request(struct trans
                        if (request->http_code == 416)
                                fprintf(stderr, "Warning: requested range invalid; we may already have all the data.\n");
  
 -                      inflateEnd(&request->stream);
 +                      git_inflate_end(&request->stream);
                        git_SHA1_Final(request->real_sha1, &request->c);
                        if (request->zret != Z_STREAM_END) {
                                unlink(request->tmpfile);
@@@ -1329,10 -1303,14 +1329,10 @@@ static int unlock_remote(struct remote_
        struct active_request_slot *slot;
        struct slot_results results;
        struct remote_lock *prev = remote->locks;
 -      char *lock_token_header;
 -      struct curl_slist *dav_headers = NULL;
 +      struct curl_slist *dav_headers;
        int rc = 0;
  
 -      lock_token_header = xmalloc(strlen(lock->token) + 31);
 -      sprintf(lock_token_header, "Lock-Token: <%s>",
 -              lock->token);
 -      dav_headers = curl_slist_append(dav_headers, lock_token_header);
 +      dav_headers = get_dav_token_headers(lock, DAV_HEADER_LOCK);
  
        slot = get_active_slot();
        slot->results = &results;
        }
  
        curl_slist_free_all(dav_headers);
 -      free(lock_token_header);
  
        if (remote->locks == lock) {
                remote->locks = lock->next;
@@@ -1385,7 -1364,7 +1385,7 @@@ static void remove_locks(void
  static void remove_locks_on_signal(int signo)
  {
        remove_locks();
 -      signal(signo, SIG_DFL);
 +      sigchain_pop(signo);
        raise(signo);
  }
  
@@@ -1752,10 -1731,13 +1752,10 @@@ static int update_remote(unsigned char 
  {
        struct active_request_slot *slot;
        struct slot_results results;
 -      char *if_header;
        struct buffer out_buffer = { STRBUF_INIT, 0 };
 -      struct curl_slist *dav_headers = NULL;
 +      struct curl_slist *dav_headers;
  
 -      if_header = xmalloc(strlen(lock->token) + 25);
 -      sprintf(if_header, "If: (<%s>)", lock->token);
 -      dav_headers = curl_slist_append(dav_headers, if_header);
 +      dav_headers = get_dav_token_headers(lock, DAV_HEADER_IF);
  
        strbuf_addf(&out_buffer.buf, "%s\n", sha1_to_hex(sha1));
  
        if (start_active_slot(slot)) {
                run_active_slot(slot);
                strbuf_release(&out_buffer.buf);
 -              free(if_header);
                if (results.curl_result != CURLE_OK) {
                        fprintf(stderr,
                                "PUT error: curl result=%d, HTTP code=%ld\n",
                }
        } else {
                strbuf_release(&out_buffer.buf);
 -              free(if_header);
                fprintf(stderr, "Unable to start PUT request\n");
                return 0;
        }
@@@ -1964,12 -1948,15 +1964,12 @@@ static void update_remote_info_refs(str
        struct buffer buffer = { STRBUF_INIT, 0 };
        struct active_request_slot *slot;
        struct slot_results results;
 -      char *if_header;
 -      struct curl_slist *dav_headers = NULL;
 +      struct curl_slist *dav_headers;
  
        remote_ls("refs/", (PROCESS_FILES | RECURSIVE),
                  add_remote_info_ref, &buffer.buf);
        if (!aborted) {
 -              if_header = xmalloc(strlen(lock->token) + 25);
 -              sprintf(if_header, "If: (<%s>)", lock->token);
 -              dav_headers = curl_slist_append(dav_headers, if_header);
 +              dav_headers = get_dav_token_headers(lock, DAV_HEADER_IF);
  
                slot = get_active_slot();
                slot->results = &results;
                                        results.curl_result, results.http_code);
                        }
                }
 -              free(if_header);
        }
        strbuf_release(&buffer.buf);
  }
@@@ -2196,6 -2184,8 +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);
                goto cleanup;
        }
  
 -      signal(SIGINT, remove_locks_on_signal);
 -      signal(SIGHUP, remove_locks_on_signal);
 -      signal(SIGQUIT, remove_locks_on_signal);
 -      signal(SIGTERM, remove_locks_on_signal);
 +      sigchain_push_common(remove_locks_on_signal);
  
        /* Check whether the remote has server info files */
        remote->can_update_info_refs = 0;
diff --combined index-pack.c
index b46a6d65973ac4b6ce4600a67c11e7bb37e49b89,72c41fd4f7b8c50f2b84f6125a81e1608533339c..f7a38079e1ec1a68606ba728964efbd5b2a04c4c
@@@ -8,6 -8,7 +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>] }";
@@@ -275,10 -276,10 +276,10 @@@ static void *unpack_entry_data(unsigne
        stream.avail_out = size;
        stream.next_in = fill(1);
        stream.avail_in = input_len;
 -      inflateInit(&stream);
 +      git_inflate_init(&stream);
  
        for (;;) {
 -              int ret = inflate(&stream, 0);
 +              int ret = git_inflate(&stream, 0);
                use(input_len - stream.avail_in);
                if (stream.total_out == size && ret == Z_STREAM_END)
                        break;
                stream.next_in = fill(1);
                stream.avail_in = input_len;
        }
 -      inflateEnd(&stream);
 +      git_inflate_end(&stream);
        return buf;
  }
  
@@@ -382,9 -383,9 +383,9 @@@ static void *get_data_from_pack(struct 
        stream.avail_out = obj->size;
        stream.next_in = src;
        stream.avail_in = len;
 -      inflateInit(&stream);
 -      while ((st = inflate(&stream, Z_FINISH)) == Z_OK);
 -      inflateEnd(&stream);
 +      git_inflate_init(&stream);
 +      while ((st = git_inflate(&stream, Z_FINISH)) == Z_OK);
 +      git_inflate_end(&stream);
        if (st != Z_STREAM_END || stream.total_out != obj->size)
                die("serious inflate inconsistency");
        free(src);
@@@ -880,6 -881,8 +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().