From e14421b9aa85f11853a0dacae09498515daab7b8 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Thu, 29 Jun 2006 22:11:25 +0200 Subject: [PATCH 001/107] Allow INSTALL, bindir, mandir to be set in main Makefile Makefiles in subdirectories now use existing value of INSTALL, bindir, mandir if it is set, allowing those to be set in main Makefile or in included config.mak. Main Makefile exports variables which it sets. Accidentally it renames bin to bindir in Documentation/Makefile (should be bindir from start, but is unused, perhaps to be removed). Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- Documentation/Makefile | 4 ++-- Makefile | 2 ++ contrib/emacs/Makefile | 4 ++-- contrib/git-svn/Makefile | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Documentation/Makefile b/Documentation/Makefile index 2b0efe7921..ca6b77df28 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -25,8 +25,8 @@ DOC_MAN1=$(patsubst %.txt,%.1,$(MAN1_TXT)) DOC_MAN7=$(patsubst %.txt,%.7,$(MAN7_TXT)) prefix?=$(HOME) -bin=$(prefix)/bin -mandir=$(prefix)/man +bindir?=$(prefix)/bin +mandir?=$(prefix)/man man1=$(mandir)/man1 man7=$(mandir)/man7 # DESTDIR= diff --git a/Makefile b/Makefile index cde619c498..b8fe669720 100644 --- a/Makefile +++ b/Makefile @@ -100,6 +100,8 @@ template_dir = $(prefix)/share/git-core/templates/ GIT_PYTHON_DIR = $(prefix)/share/git-core/python # DESTDIR= +export prefix bindir gitexecdir template_dir GIT_PYTHON_DIR + CC = gcc AR = ar TAR = tar diff --git a/contrib/emacs/Makefile b/contrib/emacs/Makefile index d3619db510..350846de90 100644 --- a/contrib/emacs/Makefile +++ b/contrib/emacs/Makefile @@ -3,9 +3,9 @@ EMACS = emacs ELC = git.elc vc-git.elc -INSTALL = install +INSTALL ?= install INSTALL_ELC = $(INSTALL) -m 644 -prefix = $(HOME) +prefix ?= $(HOME) emacsdir = $(prefix)/share/emacs/site-lisp all: $(ELC) diff --git a/contrib/git-svn/Makefile b/contrib/git-svn/Makefile index 7c20946943..1a6585eeec 100644 --- a/contrib/git-svn/Makefile +++ b/contrib/git-svn/Makefile @@ -1,8 +1,8 @@ all: git-svn prefix?=$(HOME) -bindir=$(prefix)/bin -mandir=$(prefix)/man +bindir?=$(prefix)/bin +mandir?=$(prefix)/man man1=$(mandir)/man1 INSTALL?=install doc_conf=../../Documentation/asciidoc.conf From 7b8cf0cf2973cc8df3bdd36b9b36542b1f04d70a Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Thu, 29 Jun 2006 23:26:54 +0200 Subject: [PATCH 002/107] Rename man1 and man7 variables to man1dir and man7dir This patch renames man1 and man7 variables to man1dir and man7dir, according to "Makefile Conventions: Variables for Installation Directories" in make.info of GNU Make. Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- Documentation/Makefile | 10 +++++----- Makefile | 4 ++-- contrib/git-svn/Makefile | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Documentation/Makefile b/Documentation/Makefile index ca6b77df28..cc83610588 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -27,8 +27,8 @@ DOC_MAN7=$(patsubst %.txt,%.7,$(MAN7_TXT)) prefix?=$(HOME) bindir?=$(prefix)/bin mandir?=$(prefix)/man -man1=$(mandir)/man1 -man7=$(mandir)/man7 +man1dir=$(mandir)/man1 +man7dir=$(mandir)/man7 # DESTDIR= INSTALL?=install @@ -52,9 +52,9 @@ man1: $(DOC_MAN1) man7: $(DOC_MAN7) install: man - $(INSTALL) -d -m755 $(DESTDIR)$(man1) $(DESTDIR)$(man7) - $(INSTALL) $(DOC_MAN1) $(DESTDIR)$(man1) - $(INSTALL) $(DOC_MAN7) $(DESTDIR)$(man7) + $(INSTALL) -d -m755 $(DESTDIR)$(man1dir) $(DESTDIR)$(man7dir) + $(INSTALL) $(DOC_MAN1) $(DESTDIR)$(man1dir) + $(INSTALL) $(DOC_MAN7) $(DESTDIR)$(man7dir) # diff --git a/Makefile b/Makefile index b8fe669720..ccd7c62e57 100644 --- a/Makefile +++ b/Makefile @@ -714,8 +714,8 @@ dist-doc: rm -fr .doc-tmp-dir mkdir .doc-tmp-dir .doc-tmp-dir/man1 .doc-tmp-dir/man7 $(MAKE) -C Documentation DESTDIR=./ \ - man1=../.doc-tmp-dir/man1 \ - man7=../.doc-tmp-dir/man7 \ + man1dir=../.doc-tmp-dir/man1 \ + man7dir=../.doc-tmp-dir/man7 \ install cd .doc-tmp-dir && $(TAR) cf ../$(manpages).tar . gzip -n -9 -f $(manpages).tar diff --git a/contrib/git-svn/Makefile b/contrib/git-svn/Makefile index 1a6585eeec..8cac68873b 100644 --- a/contrib/git-svn/Makefile +++ b/contrib/git-svn/Makefile @@ -3,7 +3,7 @@ all: git-svn prefix?=$(HOME) bindir?=$(prefix)/bin mandir?=$(prefix)/man -man1=$(mandir)/man1 +man1dir=$(mandir)/man1 INSTALL?=install doc_conf=../../Documentation/asciidoc.conf -include ../../config.mak @@ -17,7 +17,7 @@ install: all $(INSTALL) git-svn $(DESTDIR)$(bindir) install-doc: doc - $(INSTALL) git-svn.1 $(DESTDIR)$(man1) + $(INSTALL) git-svn.1 $(DESTDIR)$(man1dir) doc: git-svn.1 git-svn.1 : git-svn.xml From 556677144b55aad8457851a9019e86c3676bd422 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Mon, 3 Jul 2006 01:56:48 +0200 Subject: [PATCH 003/107] autoconf: Use autoconf to write installation directories to config.mak.autogen This is beginning of patch series introducing installation configuration using autoconf (and no other autotools) to git. The idea is to generate config.mak.autogen using ./configure (generated from configure.ac by running autoconf) from config.mak.in, so one can use autoconf as an _alternative_ to ordinary Makefile, and creating one's own config.mak. Local settings in config.mak override generated settings in config.mak.autogen This patch includes minimal configure.ac and config.mak.in, so one can set installation directories using autoconf generated ./configure script e.g. ./configure --prefix=/usr Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- .gitignore | 6 ++++++ INSTALL | 9 +++++++++ Makefile | 1 + config.mak.in | 18 ++++++++++++++++++ configure.ac | 14 ++++++++++++++ 5 files changed, 48 insertions(+) create mode 100644 config.mak.in create mode 100644 configure.ac diff --git a/.gitignore b/.gitignore index 7b954d587e..e103777026 100644 --- a/.gitignore +++ b/.gitignore @@ -135,4 +135,10 @@ git-core.spec *.[ao] *.py[co] config.mak +autom4te.cache +config.log +config.status +config.mak.in +config.mak.autogen +configure git-blame diff --git a/INSTALL b/INSTALL index f8337e2a4d..28245b3e68 100644 --- a/INSTALL +++ b/INSTALL @@ -13,6 +13,15 @@ that uses $prefix, the built results have some paths encoded, which are derived from $prefix, so "make all; make prefix=/usr install" would not work. +Alternatively you can use autoconf generated ./configure script to +set up install paths (via config.mak.autogen), so you can write instead + + $ autoconf ;# as yourself if ./configure doesn't exist yet + $ ./configure --prefix=/usr ;# as yourself + $ make all doc ;# as yourself + # make install install-doc ;# as root + + Issues of note: - git normally installs a helper script wrapper called "git", which diff --git a/Makefile b/Makefile index ccd7c62e57..a37d400591 100644 --- a/Makefile +++ b/Makefile @@ -333,6 +333,7 @@ ifneq (,$(findstring arm,$(uname_M))) ARM_SHA1 = YesPlease endif +-include config.mak.autogen -include config.mak ifdef WITH_OWN_SUBPROCESS_PY diff --git a/config.mak.in b/config.mak.in new file mode 100644 index 0000000000..82c9781f0d --- /dev/null +++ b/config.mak.in @@ -0,0 +1,18 @@ +# git Makefile configuration, included in main Makefile +# @configure_input@ + +prefix = @prefix@ +exec_prefix = @exec_prefix@ +bindir = @bindir@ +#gitexecdir = @libexecdir@/git-core/ +template_dir = @datadir@/git-core/templates/ +GIT_PYTHON_DIR = @datadir@/git-core/python + +mandir=@mandir@ + +srcdir = @srcdir@ +VPATH = @srcdir@ + +export exec_prefix mandir +export srcdir VPATH + diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000000..a0374d4d53 --- /dev/null +++ b/configure.ac @@ -0,0 +1,14 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ(2.59) +AC_INIT([git], [1.4.1], [git@vger.kernel.org]) + +AC_CONFIG_SRCDIR([git.c]) + +config_file=config.mak.autogen +config_in=config.mak.in + +# Output files +AC_CONFIG_FILES(["${config_file}":"${config_in}"]) +AC_OUTPUT From 92b878ade12f6672ce7ff7d12ac74b69c8e35c59 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Sat, 8 Jul 2006 23:07:07 +0200 Subject: [PATCH 004/107] Teach make clean about configure and autoconf Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index a37d400591..cef65861c4 100644 --- a/Makefile +++ b/Makefile @@ -729,6 +729,8 @@ clean: $(LIB_FILE) $(XDIFF_LIB) rm -f $(ALL_PROGRAMS) $(BUILT_INS) git$X rm -f *.spec *.pyc *.pyo */*.pyc */*.pyo common-cmds.h TAGS tags + rm -rf autom4te.cache + rm -f config.log config.mak.autogen configure config.status config.cache rm -rf $(GIT_TARNAME) .doc-tmp-dir rm -f $(GIT_TARNAME).tar.gz git-core_$(GIT_VERSION)-*.tar.gz rm -f $(htmldocs).tar.gz $(manpages).tar.gz From 633b423961df659fbf110fd7b127ebc9a0a38277 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Sat, 8 Jul 2006 23:07:08 +0200 Subject: [PATCH 005/107] Copy description of build configuration variables to configure.ac Copy description of build configuration variables from the commentary in the top Makefile (from 'next' branch) to configure.ac, splitting them into "autoconf" sections. This is to be able to easily check which build/install configuration variables are covered by current configure.ac Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- configure.ac | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index a0374d4d53..12039a124b 100644 --- a/configure.ac +++ b/configure.ac @@ -9,6 +9,118 @@ AC_CONFIG_SRCDIR([git.c]) config_file=config.mak.autogen config_in=config.mak.in -# Output files + +## Checks for programs. +# Define NO_PYTHON if you want to loose all benefits of the recursive merge. + + +## Checks for libraries. +# Define NO_OPENSSL environment variable if you do not have OpenSSL. +# This also implies MOZILLA_SHA1. +# +# Define NO_CURL if you do not have curl installed. git-http-pull and +# git-http-push are not built, and you cannot use http:// and https:// +# transports. +# +# 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 NEEDS_SSL_WITH_CRYPTO if you need -lcrypto with -lssl (Darwin). +# +# Define NEEDS_LIBICONV if linking with libc is not enough (Darwin). +# +# Define NEEDS_SOCKET if linking with libc is not enough (SunOS, +# Patrick Mauritz). + + +## Checks for header files. + + +## Checks for typedefs, structures, and compiler characteristics. +# 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 +# d_type in struct dirent (latest Cygwin -- will be fixed soonish). +# +# Define NO_SOCKADDR_STORAGE if your platform does not have struct +# sockaddr_storage. + + +## Checks for library functions. +# Define NO_STRCASESTR if you don't have strcasestr. +# +# Define NO_STRLCPY if you don't have strlcpy. +# +# Define NO_SETENV if you don't have setenv in the C library. +# +# Define NO_MMAP if you want to avoid mmap. +# +# Define NO_IPV6 if you lack IPv6 support and getaddrinfo(). +# +# Define NO_ICONV if your libc does not properly support iconv. + + +## Other checks. +# Define USE_PIC if you need the main git objects to be built with -fPIC +# in order to build and link perl/Git.so. x86-64 seems to need this. +# +# Define NO_SYMLINK_HEAD if you never want .git/HEAD to be a symbolic link. +# Enable it on Windows. By default, symrefs are still used. +# +# Define WITH_OWN_SUBPROCESS_PY if you want to use with python 2.3. +# +# Define NO_ACCURATE_DIFF if your diff program at least sometimes misses +# a missing newline at the end of the file. + + +## Site configuration +## --with-PACKAGE[=ARG] and --without-PACKAGE +# Define NO_SVN_TESTS if you want to skip time-consuming SVN interopability +# tests. These tests take up a significant amount of the total test time +# but are not needed unless you plan to talk to SVN repos. +# +# Define MOZILLA_SHA1 environment variable when running make to make use of +# a bundled SHA1 routine coming from Mozilla. It is GPL'd and should be fast +# on non-x86 architectures (e.g. PowerPC), while the OpenSSL version (default +# choice) has very fast version optimized for i586. +# +# Define PPC_SHA1 environment variable when running make to make use of +# a bundled SHA1 routine optimized for PowerPC. +# +# Define ARM_SHA1 environment variable when running make to make use of +# a bundled SHA1 routine optimized for ARM. +# +# Define NO_OPENSSL environment variable if you do not have OpenSSL. +# This also implies MOZILLA_SHA1. +# +# Define NO_CURL if you do not have curl installed. git-http-pull and +# git-http-push are not built, and you cannot use http:// and https:// +# transports. +# +# Define CURLDIR=/foo/bar if your curl header and library files are in +# /foo/bar/include and /foo/bar/lib directories. +# +# 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 NO_MMAP if you want to avoid mmap. +# +# Define NO_PYTHON if you want to loose all benefits of the recursive merge. +# +## --enable-FEATURE[=ARG] and --disable-FEATURE +# Define COLLISION_CHECK below if you believe that SHA1's +# 1461501637330902918203684832716283019655932542976 hashes do not give you +# sufficient guarantee that no collisions between objects will ever happen. +# +# Define USE_NSEC below if you want git to care about sub-second file mtimes +# and ctimes. Note that you need recent glibc (at least 2.2.4) for this, and +# it will BREAK YOUR LOCAL DIFFS! show-diff and anything using it will likely +# randomly break unless your underlying filesystem supports those sub-second +# times (my ext3 doesn't). +# +# Define USE_STDEV below if you want git to care about the underlying device +# change being considered an inode change from the update-cache perspective. + +## Output files AC_CONFIG_FILES(["${config_file}":"${config_in}"]) AC_OUTPUT From d3a6db981179a1dc772768ff6af0414d17848d93 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Sat, 8 Jul 2006 23:07:09 +0200 Subject: [PATCH 006/107] autoconf: Preparing the way for autodetection Prepares configure.ac to output autodetected and selected (by using --with/--without and --enable/disable parameters to generated ./configure script) building configuration in "git style", i.e. by appending appropriate variables to output file config.mak.autogen (via temporary file config.mak.append). Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- configure.ac | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 12039a124b..e68d4163c6 100644 --- a/configure.ac +++ b/configure.ac @@ -7,8 +7,19 @@ AC_INIT([git], [1.4.1], [git@vger.kernel.org]) AC_CONFIG_SRCDIR([git.c]) config_file=config.mak.autogen +config_append=config.mak.append config_in=config.mak.in +echo "# ${config_append}. Generated by configure." > "${config_append}" + + +## Definitions of macros +# GIT_CONF_APPEND_LINE(LINE) +# -------------------------- +# Append LINE to file ${config_append} +AC_DEFUN([GIT_CONF_APPEND_LINE], +[echo "$1" >> "${config_append}"])# GIT_CONF_APPEND_LINE + ## Checks for programs. # Define NO_PYTHON if you want to loose all benefits of the recursive merge. @@ -121,6 +132,10 @@ config_in=config.mak.in # Define USE_STDEV below if you want git to care about the underlying device # change being considered an inode change from the update-cache perspective. + ## Output files -AC_CONFIG_FILES(["${config_file}":"${config_in}"]) +AC_CONFIG_FILES(["${config_file}":"${config_in}":"${config_append}"]) AC_OUTPUT + +## Cleanup +rm -f "${config_append}" From eb0f255d6144af26361b12cb38aae9c23581a955 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Sat, 8 Jul 2006 23:07:10 +0200 Subject: [PATCH 007/107] autoconf: Checks for typedefs, structures, and compiler characteristics. ./configure script checks now for existence of the following types, structures, and structure members: * dirent.d_ino in (NO_D_INO_IN_DIRENT) * dirent.d_type in (NO_D_TYPE_IN_DIRENT) * 'struct sockaddr_storage' in (NO_SOCKADDR_STORAGE) Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- configure.ac | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index e68d4163c6..cb812584cb 100644 --- a/configure.ac +++ b/configure.ac @@ -48,13 +48,24 @@ AC_DEFUN([GIT_CONF_APPEND_LINE], ## Checks for typedefs, structures, and compiler characteristics. +AC_MSG_NOTICE([CHECKS for typedefs, structures, and compiler characteristics]) + # Define NO_D_INO_IN_DIRENT if you don't have d_ino in your struct dirent. -# +AC_CHECK_MEMBER(struct dirent.d_ino,[], +GIT_CONF_APPEND_LINE(NO_D_INO_IN_DIRENT=YesPlease), +[#include ]) + # Define NO_D_TYPE_IN_DIRENT if your platform defines DT_UNKNOWN but lacks # d_type in struct dirent (latest Cygwin -- will be fixed soonish). -# +AC_CHECK_MEMBER(struct dirent.d_type,[], +GIT_CONF_APPEND_LINE(NO_D_TYPE_IN_DIRENT=YesPlease), +[#include ]) + # Define NO_SOCKADDR_STORAGE if your platform does not have struct # sockaddr_storage. +AC_CHECK_TYPE(struct sockaddr_storage,[], +GIT_CONF_APPEND_LINE(NO_SOCKADDR_STORAGE=YesPlease), +[#include ]) ## Checks for library functions. From 1bbbadbc2c32d1a6d0e97713e4f6e417daa72759 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Sat, 8 Jul 2006 23:07:11 +0200 Subject: [PATCH 008/107] autoconf: Checks for some library functions. ./configure script checks now for the following library functions: * strcasestr (NO_STRCASESTR) * strlcpy (NO_STRLCPY) * setenv (NO_SETENV) in default C library and in libraries which have AC_CHECK_LIB done for them. Checks not implemented: * NO_MMAP - probably only via optional features configuration * NO_IPV6 - what does "lack IPv6 support" mean? * NO_ICONV - what does "properly support iconv" mean? Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- configure.ac | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index cb812584cb..ab6a77ad5c 100644 --- a/configure.ac +++ b/configure.ac @@ -69,12 +69,21 @@ GIT_CONF_APPEND_LINE(NO_SOCKADDR_STORAGE=YesPlease), ## Checks for library functions. +## (in default C library and libraries checked by AC_CHECK_LIB) +AC_MSG_NOTICE([CHECKS for library functions]) + # Define NO_STRCASESTR if you don't have strcasestr. -# +AC_CHECK_FUNC(strcasestr,[], +GIT_CONF_APPEND_LINE(NO_STRCASESTR=YesPlease)) + # Define NO_STRLCPY if you don't have strlcpy. -# +AC_CHECK_FUNC(strlcpy,[], +GIT_CONF_APPEND_LINE(NO_STRLCPY=YesPlease)) + # Define NO_SETENV if you don't have setenv in the C library. -# +AC_CHECK_FUNC(setenv,[], +GIT_CONF_APPEND_LINE(NO_SETENV=YesPlease)) + # Define NO_MMAP if you want to avoid mmap. # # Define NO_IPV6 if you lack IPv6 support and getaddrinfo(). From ebdf53210ca30eaaa6cf5f555200678bf5f256ac Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Sat, 8 Jul 2006 23:07:12 +0200 Subject: [PATCH 009/107] autoconf: Checks for libraries ./configure script checks now if the following libraries are present: * -lssl for SHA1_Init (NO_OPENSSL) * -lcurl for curl_easy_setopt (NO_CURL) * -lexpat for XML_ParserCreate (NO_EXPAT) It also checks if adding the following libraries are needed: * -lcrypto for SHA1_Init (NEEDS_SSL_WITH_CRYPTO) * -liconv for iconv (NEEDS_LIBICONV) * -lsocket for socket (NEEDS_SOCKET) Policy: we check also if NEEDS_LIBRARY libraries are present, even if there is no NO_LIBRARY variable. Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- configure.ac | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index ab6a77ad5c..d938546940 100644 --- a/configure.ac +++ b/configure.ac @@ -26,22 +26,36 @@ AC_DEFUN([GIT_CONF_APPEND_LINE], ## Checks for libraries. +AC_MSG_NOTICE([CHECKS for libraries]) + # Define NO_OPENSSL environment variable if you do not have OpenSSL. -# This also implies MOZILLA_SHA1. -# +# Define NEEDS_SSL_WITH_CRYPTO if you need -lcrypto with -lssl (Darwin). +AC_CHECK_LIB([ssl], [SHA1_Init],[], +[AC_CHECK_LIB([crypto], [SHA1_INIT], + GIT_CONF_APPEND_LINE(NEEDS_SSL_WITH_CRYPTO=YesPlease), + GIT_CONF_APPEND_LINE(NO_OPENSSL=YesPlease))]) + # Define NO_CURL if you do not have curl installed. git-http-pull and # git-http-push are not built, and you cannot use http:// and https:// # transports. -# +AC_CHECK_LIB([curl], [curl_global_init],[], +GIT_CONF_APPEND_LINE(NO_CURL=YesPlease)) + # 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 NEEDS_SSL_WITH_CRYPTO if you need -lcrypto with -lssl (Darwin). -# +AC_CHECK_LIB([expat], [XML_ParserCreate],[], +GIT_CONF_APPEND_LINE(NO_EXPAT=YesPlease)) + # Define NEEDS_LIBICONV if linking with libc is not enough (Darwin). -# +AC_CHECK_LIB([c], [iconv],[], +[AC_CHECK_LIB([iconv],[iconv], + GIT_CONF_APPEND_LINE(NEEDS_LIBICONV=YesPlease),[])]) + # Define NEEDS_SOCKET if linking with libc is not enough (SunOS, # Patrick Mauritz). +AC_CHECK_LIB([c], [socket],[], +[AC_CHECK_LIB([socket],[socket], + GIT_CONF_APPEND_LINE(NEEDS_SOCKET=YesPlease),[])]) ## Checks for header files. From fd22c0271b33227e651be456beb4cead934f5624 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Sat, 8 Jul 2006 23:07:13 +0200 Subject: [PATCH 010/107] autoconf: Checks for some programs ./configure script checks now for the following programs: * CC - using AC_PROG_CC * AR - using AC_CHECK_TOOL among ar * TAR - among gtar, tar Checks not implemented: * INSTALL - needs install-sh or install.sh in sources * RPMBUILD - not known alternatives for rpmbuild * PYTHON - no PYTHON variable in Makefile, has to set NO_PYTHON if not present Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- config.mak.in | 5 +++++ configure.ac | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/config.mak.in b/config.mak.in index 82c9781f0d..89520ebefe 100644 --- a/config.mak.in +++ b/config.mak.in @@ -1,6 +1,11 @@ # git Makefile configuration, included in main Makefile # @configure_input@ +CC = @CC@ +AR = @AR@ +TAR = @TAR@ +#INSTALL = @INSTALL@ # needs install-sh or install.sh in sources + prefix = @prefix@ exec_prefix = @exec_prefix@ bindir = @bindir@ diff --git a/configure.ac b/configure.ac index d938546940..56e765f7db 100644 --- a/configure.ac +++ b/configure.ac @@ -22,6 +22,13 @@ AC_DEFUN([GIT_CONF_APPEND_LINE], ## Checks for programs. +AC_MSG_NOTICE([CHECKS for programs]) + +AC_PROG_CC +#AC_PROG_INSTALL # needs install-sh or install.sh in sources +AC_CHECK_TOOL(AR, ar, :) +AC_CHECK_PROGS(TAR, [gtar tar]) + # Define NO_PYTHON if you want to loose all benefits of the recursive merge. From f671957206bb5e9cc6db630e74b57bd1ae1157a7 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Sat, 8 Jul 2006 23:07:14 +0200 Subject: [PATCH 011/107] configure.ac vertical whitespace usage cleanup configure.ac | 29 +++++++++++++++-------------- 1 files changed, 15 insertions(+), 14 deletions(-) Signed-off-by: Junio C Hamano --- configure.ac | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/configure.ac b/configure.ac index 56e765f7db..acea6ce294 100644 --- a/configure.ac +++ b/configure.ac @@ -23,41 +23,41 @@ AC_DEFUN([GIT_CONF_APPEND_LINE], ## Checks for programs. AC_MSG_NOTICE([CHECKS for programs]) - +# AC_PROG_CC #AC_PROG_INSTALL # needs install-sh or install.sh in sources AC_CHECK_TOOL(AR, ar, :) AC_CHECK_PROGS(TAR, [gtar tar]) - +# # Define NO_PYTHON if you want to loose all benefits of the recursive merge. ## Checks for libraries. AC_MSG_NOTICE([CHECKS for libraries]) - +# # Define NO_OPENSSL environment variable if you do not have OpenSSL. # Define NEEDS_SSL_WITH_CRYPTO if you need -lcrypto with -lssl (Darwin). AC_CHECK_LIB([ssl], [SHA1_Init],[], [AC_CHECK_LIB([crypto], [SHA1_INIT], GIT_CONF_APPEND_LINE(NEEDS_SSL_WITH_CRYPTO=YesPlease), GIT_CONF_APPEND_LINE(NO_OPENSSL=YesPlease))]) - +# # Define NO_CURL if you do not have curl installed. git-http-pull and # git-http-push are not built, and you cannot use http:// and https:// # transports. AC_CHECK_LIB([curl], [curl_global_init],[], GIT_CONF_APPEND_LINE(NO_CURL=YesPlease)) - +# # 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. AC_CHECK_LIB([expat], [XML_ParserCreate],[], GIT_CONF_APPEND_LINE(NO_EXPAT=YesPlease)) - +# # Define NEEDS_LIBICONV if linking with libc is not enough (Darwin). AC_CHECK_LIB([c], [iconv],[], [AC_CHECK_LIB([iconv],[iconv], GIT_CONF_APPEND_LINE(NEEDS_LIBICONV=YesPlease),[])]) - +# # Define NEEDS_SOCKET if linking with libc is not enough (SunOS, # Patrick Mauritz). AC_CHECK_LIB([c], [socket],[], @@ -70,18 +70,18 @@ AC_CHECK_LIB([c], [socket],[], ## Checks for typedefs, structures, and compiler characteristics. AC_MSG_NOTICE([CHECKS for typedefs, structures, and compiler characteristics]) - +# # Define NO_D_INO_IN_DIRENT if you don't have d_ino in your struct dirent. AC_CHECK_MEMBER(struct dirent.d_ino,[], GIT_CONF_APPEND_LINE(NO_D_INO_IN_DIRENT=YesPlease), [#include ]) - +# # Define NO_D_TYPE_IN_DIRENT if your platform defines DT_UNKNOWN but lacks # d_type in struct dirent (latest Cygwin -- will be fixed soonish). AC_CHECK_MEMBER(struct dirent.d_type,[], GIT_CONF_APPEND_LINE(NO_D_TYPE_IN_DIRENT=YesPlease), [#include ]) - +# # Define NO_SOCKADDR_STORAGE if your platform does not have struct # sockaddr_storage. AC_CHECK_TYPE(struct sockaddr_storage,[], @@ -92,19 +92,19 @@ GIT_CONF_APPEND_LINE(NO_SOCKADDR_STORAGE=YesPlease), ## Checks for library functions. ## (in default C library and libraries checked by AC_CHECK_LIB) AC_MSG_NOTICE([CHECKS for library functions]) - +# # Define NO_STRCASESTR if you don't have strcasestr. AC_CHECK_FUNC(strcasestr,[], GIT_CONF_APPEND_LINE(NO_STRCASESTR=YesPlease)) - +# # Define NO_STRLCPY if you don't have strlcpy. AC_CHECK_FUNC(strlcpy,[], GIT_CONF_APPEND_LINE(NO_STRLCPY=YesPlease)) - +# # Define NO_SETENV if you don't have setenv in the C library. AC_CHECK_FUNC(setenv,[], GIT_CONF_APPEND_LINE(NO_SETENV=YesPlease)) - +# # Define NO_MMAP if you want to avoid mmap. # # Define NO_IPV6 if you lack IPv6 support and getaddrinfo(). @@ -178,5 +178,6 @@ GIT_CONF_APPEND_LINE(NO_SETENV=YesPlease)) AC_CONFIG_FILES(["${config_file}":"${config_in}":"${config_append}"]) AC_OUTPUT + ## Cleanup rm -f "${config_append}" From 81d0e51e28607000712b92f5d7295ad07eb3ccb7 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Sun, 9 Jul 2006 02:46:17 -0700 Subject: [PATCH 012/107] Typofix in configure.ac comment. [jc: copied from Makefile typofix in "master"] Signed-off-by: Junio C Hamano --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index acea6ce294..2932d0e766 100644 --- a/configure.ac +++ b/configure.ac @@ -29,7 +29,7 @@ AC_PROG_CC AC_CHECK_TOOL(AR, ar, :) AC_CHECK_PROGS(TAR, [gtar tar]) # -# Define NO_PYTHON if you want to loose all benefits of the recursive merge. +# Define NO_PYTHON if you want to lose all benefits of the recursive merge. ## Checks for libraries. From e1447e38c00bdc1904458cfabb4bb3ffb678a271 Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Tue, 11 Jul 2006 01:52:54 -0400 Subject: [PATCH 013/107] Log ref changes made by git-merge and git-pull. When git-merge updates HEAD as a result of a merge record what happened during the merge into the reflog associated with HEAD (if any). The log reports who caused the update (git-merge or git-pull, by invoking git-merge), what the remote ref names were and the type of merge process used. The merge information can be useful when reviewing a reflog for a branch such as `master` where fast forward and trivial in index merges might be common as the user tracks an upstream. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- git-merge.sh | 17 ++++++++++++++--- git-pull.sh | 3 ++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/git-merge.sh b/git-merge.sh index 24e3b507ef..a9cfafb1df 100755 --- a/git-merge.sh +++ b/git-merge.sh @@ -58,7 +58,13 @@ squash_message () { } finish () { - test '' = "$2" || echo "$2" + if test '' = "$2" + then + rlogm="$rloga" + else + echo "$2" + rlogm="$rloga: $2" + fi case "$squash" in t) echo "Squash commit -- not updating HEAD" @@ -70,7 +76,7 @@ finish () { echo "No merge message -- not updating HEAD" ;; *) - git-update-ref HEAD "$1" "$head" || exit 1 + git-update-ref -m "$rlogm" HEAD "$1" "$head" || exit 1 ;; esac ;; @@ -88,6 +94,7 @@ finish () { esac } +rloga= while case "$#" in 0) break ;; esac do case "$1" in @@ -117,6 +124,9 @@ do die "available strategies are: $all_strategies" ;; esac ;; + --reflog-action=*) + rloga=`expr "z$1" : 'z-[^=]*=\(.*\)'` + ;; -*) usage ;; *) break ;; esac @@ -131,6 +141,7 @@ shift # All the rest are remote heads test "$#" = 0 && usage ;# we need at least one remote head. +test "$rloga" = '' && rloga="merge: $@" remoteheads= for remote @@ -316,7 +327,7 @@ if test '' != "$result_tree" then parents=$(git-show-branch --independent "$head" "$@" | sed -e 's/^/-p /') result_commit=$(echo "$merge_msg" | git-commit-tree $result_tree $parents) || exit - finish "$result_commit" "Merge $result_commit, made by $wt_strategy." + finish "$result_commit" "Merge made by $wt_strategy." dropsave exit 0 fi diff --git a/git-pull.sh b/git-pull.sh index d337bf4da3..f380437997 100755 --- a/git-pull.sh +++ b/git-pull.sh @@ -102,5 +102,6 @@ case "$strategy_args" in esac merge_name=$(git-fmt-merge-msg <"$GIT_DIR/FETCH_HEAD") || exit -git-merge $no_summary $no_commit $squash $strategy_args \ +git-merge "--reflog-action=pull $*" \ + $no_summary $no_commit $squash $strategy_args \ "$merge_name" HEAD $merge_head From 09a28eccce58d349d93280fd3ac08c5ad0eaa3c5 Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Tue, 11 Jul 2006 02:10:19 -0400 Subject: [PATCH 014/107] Log ref changes made by quiltimport. When importing a quilt patch to a branch which has a reflog record the update to HEAD with a log message indicating the change was made by quiltimport and what patch caused the change. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- git-quiltimport.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-quiltimport.sh b/git-quiltimport.sh index 364baff806..10135da3ac 100755 --- a/git-quiltimport.sh +++ b/git-quiltimport.sh @@ -112,7 +112,7 @@ for patch_name in $(cat "$QUILT_PATCHES/series" | grep -v '^#'); do git-apply --index -C1 "$tmp_patch" && tree=$(git-write-tree) && commit=$((echo "$SUBJECT"; echo; cat "$tmp_msg") | git-commit-tree $tree -p $commit) && - git-update-ref HEAD $commit || exit 4 + git-update-ref -m "quiltimport: $patch_name" HEAD $commit || exit 4 fi done rm -rf $tmp_dir || exit 5 From 5a6852fef1d76369d6dfcad1a40ca5287bb781a6 Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Tue, 11 Jul 2006 02:25:09 -0400 Subject: [PATCH 015/107] Log ref changes made by resolve. Since git-resolve is essentially a form of git-merge record any ref updates it makes similiar to how git-merge would record them. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- git-resolve.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/git-resolve.sh b/git-resolve.sh index 1c7aaefa25..a7bc680d90 100755 --- a/git-resolve.sh +++ b/git-resolve.sh @@ -15,6 +15,7 @@ dropheads() { head=$(git-rev-parse --verify "$1"^0) && merge=$(git-rev-parse --verify "$2"^0) && +merge_name="$2" && merge_msg="$3" || usage # @@ -43,7 +44,8 @@ case "$common" in "$head") echo "Updating from $head to $merge" git-read-tree -u -m $head $merge || exit 1 - git-update-ref HEAD "$merge" "$head" + git-update-ref -m "resolve $merge_name: Fast forward" \ + HEAD "$merge" "$head" git-diff-tree -p $head $merge | git-apply --stat dropheads exit 0 @@ -100,6 +102,7 @@ if [ $? -ne 0 ]; then fi result_commit=$(echo "$merge_msg" | git-commit-tree $result_tree -p $head -p $merge) echo "Committed merge $result_commit" -git-update-ref HEAD "$result_commit" "$head" +git-update-ref -m "resolve $merge_name: In-index merge" \ + HEAD "$result_commit" "$head" git-diff-tree -p $head $result_commit | git-apply --stat dropheads From 756aaf4ac5906e79b22001a96dd4f6aec0d1c89d Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Wed, 12 Jul 2006 01:00:16 -0400 Subject: [PATCH 016/107] Make lazy mkdir more robust. Linus Torvalds wrote: It's entirely possible that we should just make that whole if (ret == ENOENT) go away. Yes, it's the right error code if a subdirectory is missing, and yes, POSIX requires it, and yes, WXP is probably just a horrible piece of sh*t, but on the other hand, I don't think git really has any serious reason to even care. --- sha1_file.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/sha1_file.c b/sha1_file.c index 8734d501fe..e666aec502 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1331,31 +1331,29 @@ char *write_sha1_file_prepare(void *buf, static int link_temp_to_file(const char *tmpfile, char *filename) { int ret; + char *dir; if (!link(tmpfile, filename)) return 0; /* - * Try to mkdir the last path component if that failed - * with an ENOENT. + * Try to mkdir the last path component if that failed. * * Re-try the "link()" regardless of whether the mkdir * succeeds, since a race might mean that somebody * else succeeded. */ ret = errno; - if (ret == ENOENT) { - char *dir = strrchr(filename, '/'); - if (dir) { - *dir = 0; - mkdir(filename, 0777); - if (adjust_shared_perm(filename)) - return -2; - *dir = '/'; - if (!link(tmpfile, filename)) - return 0; - ret = errno; - } + dir = strrchr(filename, '/'); + if (dir) { + *dir = 0; + mkdir(filename, 0777); + if (adjust_shared_perm(filename)) + return -2; + *dir = '/'; + if (!link(tmpfile, filename)) + return 0; + ret = errno; } return ret; } From 8ef1c7c77d3e5950a839d9ae348827fa288a9a11 Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Fri, 14 Jul 2006 00:47:23 -0400 Subject: [PATCH 017/107] Record rebase changes as 'rebase' in the reflog. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- git-am.sh | 6 +++++- git-rebase.sh | 9 ++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/git-am.sh b/git-am.sh index db9a20a811..3a129e0021 100755 --- a/git-am.sh +++ b/git-am.sh @@ -91,6 +91,7 @@ fall_back_3way () { } prec=4 +rloga=am dotest=.dotest sign= utf8= keep= skip= interactive= resolved= binary= ws= resolvemsg= while case "$#" in 0) break;; esac @@ -130,6 +131,9 @@ do --resolvemsg=*) resolvemsg=$(echo "$1" | sed -e "s/^--resolvemsg=//"); shift ;; + --reflog-action=*) + rloga=`expr "z$1" : 'z-[^=]*=\(.*\)'`; shift ;; + --) shift; break ;; -*) @@ -413,7 +417,7 @@ do parent=$(git-rev-parse --verify HEAD) && commit=$(git-commit-tree $tree -p $parent <"$dotest/final-commit") && echo Committed: $commit && - git-update-ref -m "am: $SUBJECT" HEAD $commit $parent || + git-update-ref -m "$rloga: $SUBJECT" HEAD $commit $parent || stop_here $this if test -x "$GIT_DIR"/hooks/post-applypatch diff --git a/git-rebase.sh b/git-rebase.sh index 1b9e986926..29028dd5fc 100755 --- a/git-rebase.sh +++ b/git-rebase.sh @@ -131,7 +131,8 @@ do finish_rb_merge exit fi - git am --resolved --3way --resolvemsg="$RESOLVEMSG" + git am --resolved --3way --resolvemsg="$RESOLVEMSG" \ + --reflog-action=rebase exit ;; --skip) @@ -150,7 +151,8 @@ do finish_rb_merge exit fi - git am -3 --skip --resolvemsg="$RESOLVEMSG" + git am -3 --skip --resolvemsg="$RESOLVEMSG" \ + --reflog-action=rebase exit ;; --abort) @@ -288,7 +290,8 @@ fi if test -z "$do_merge" then git-format-patch -k --stdout --full-index "$upstream"..ORIG_HEAD | - git am --binary -3 -k --resolvemsg="$RESOLVEMSG" + git am --binary -3 -k --resolvemsg="$RESOLVEMSG" \ + --reflog-action=rebase exit $? fi From 57a39690b936c003662b6710241732b980e58790 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 10 Jul 2006 03:34:34 -0700 Subject: [PATCH 018/107] fetch/clone: check return status from ls-remote Some callers of ls-remote did not check its return status. --- git-clone.sh | 4 ++-- git-fetch.sh | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/git-clone.sh b/git-clone.sh index 0368803883..a92b22a13d 100755 --- a/git-clone.sh +++ b/git-clone.sh @@ -266,7 +266,7 @@ yes,yes) echo "$repo/objects" >> "$GIT_DIR/objects/info/alternates" ;; esac - git-ls-remote "$repo" >"$GIT_DIR/CLONE_HEAD" + git-ls-remote "$repo" >"$GIT_DIR/CLONE_HEAD" || exit 1 ;; *) case "$repo" in @@ -296,7 +296,7 @@ yes,yes) done rm -f "$GIT_DIR/TMP_ALT" fi - git-ls-remote "$repo" >"$GIT_DIR/CLONE_HEAD" + git-ls-remote "$repo" >"$GIT_DIR/CLONE_HEAD" || exit 1 ;; http://*) if test -z "@@NO_CURL@@" diff --git a/git-fetch.sh b/git-fetch.sh index ff1769952b..0c7a11d565 100755 --- a/git-fetch.sh +++ b/git-fetch.sh @@ -223,9 +223,16 @@ reflist=$(get_remote_refs_for_fetch "$@") if test "$tags" then taglist=`IFS=" " && - git-ls-remote $upload_pack --tags "$remote" | + ( + git-ls-remote $upload_pack --tags "$remote" || + echo fail ouch + ) | while read sha1 name do + case "$sha1" in + fail) + exit 1 + esac case "$name" in *^*) continue ;; esac @@ -235,7 +242,7 @@ then else echo >&2 "warning: tag ${name} ignored" fi - done` + done` || exit if test "$#" -gt 1 then # remote URL plus explicit refspecs; we need to merge them. From 93821bd97aa516b3b557fc5d1b32fd3431536e44 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 11 Jul 2006 12:48:08 -0700 Subject: [PATCH 019/107] sha1_file: add the ability to parse objects in "pack file format" The pack-file format is slightly different from the traditional git object format, in that it has a much denser binary header encoding. The traditional format uses an ASCII string with type and length information, which is somewhat wasteful. A new object format starts with uncompressed binary header followed by compressed payload -- this will allow us later to copy the payload straight to packfiles. Obviously they cannot be read by older versions of git, so for now new object files are created with the traditional format. core.legacyheaders configuration item, when set to false makes the code write in new format for people to experiment with. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- Documentation/config.txt | 6 +++ cache.h | 1 + config.c | 5 ++ environment.c | 1 + sha1_file.c | 106 ++++++++++++++++++++++++++++++++++++--- 5 files changed, 111 insertions(+), 8 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index 0b434c1f19..9780c89bc3 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -97,6 +97,12 @@ core.compression:: compression, and 1..9 are various speed/size tradeoffs, 9 being slowest. +core.legacyheaders:: + A boolean which enables the legacy object header format in case + you want to interoperate with old clients accessing the object + database directly (where the "http://" and "rsync://" protocols + count as direct access). + alias.*:: Command aliases for the gitlink:git[1] command wrapper - e.g. after defining "alias.last = cat-file commit HEAD", the invocation diff --git a/cache.h b/cache.h index d433d46f23..eee5fc9f8d 100644 --- a/cache.h +++ b/cache.h @@ -176,6 +176,7 @@ extern int commit_lock_file(struct lock_file *); extern void rollback_lock_file(struct lock_file *); /* Environment bits from configuration mechanism */ +extern int use_legacy_headers; extern int trust_executable_bit; extern int assume_unchanged; extern int prefer_symlink_refs; diff --git a/config.c b/config.c index 8445f7dcab..0ac6aebbbc 100644 --- a/config.c +++ b/config.c @@ -279,6 +279,11 @@ int git_default_config(const char *var, const char *value) return 0; } + if (!strcmp(var, "core.legacyheaders")) { + use_legacy_headers = git_config_bool(var, value); + return 0; + } + if (!strcmp(var, "core.compression")) { int level = git_config_int(var, value); if (level == -1) diff --git a/environment.c b/environment.c index 97d42b172b..42f39d657e 100644 --- a/environment.c +++ b/environment.c @@ -11,6 +11,7 @@ char git_default_email[MAX_GITNAME]; char git_default_name[MAX_GITNAME]; +int use_legacy_headers = 1; int trust_executable_bit = 1; int assume_unchanged = 0; int prefer_symlink_refs = 0; diff --git a/sha1_file.c b/sha1_file.c index 8734d501fe..88a2579412 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -684,26 +684,74 @@ static void *map_sha1_file_internal(const unsigned char *sha1, return map; } -static int unpack_sha1_header(z_stream *stream, void *map, unsigned long mapsize, void *buffer, unsigned long size) +static int unpack_sha1_header(z_stream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz) { + unsigned char c; + unsigned int word, bits; + unsigned long size; + static const char *typename[8] = { + NULL, /* OBJ_EXT */ + "commit", "tree", "blob", "tag", + NULL, NULL, NULL + }; + const char *type; + /* Get the data stream */ memset(stream, 0, sizeof(*stream)); stream->next_in = map; stream->avail_in = mapsize; stream->next_out = buffer; - stream->avail_out = size; + stream->avail_out = bufsiz; + /* + * Is it a zlib-compressed buffer? If so, the first byte + * must be 0x78 (15-bit window size, deflated), and the + * first 16-bit word is evenly divisible by 31 + */ + word = (map[0] << 8) + map[1]; + if (map[0] == 0x78 && !(word % 31)) { + inflateInit(stream); + return inflate(stream, 0); + } + + c = *map++; + mapsize--; + type = typename[(c >> 4) & 7]; + if (!type) + return -1; + + bits = 4; + size = c & 0xf; + while ((c & 0x80)) { + if (bits >= 8*sizeof(long)) + return -1; + c = *map++; + size += (c & 0x7f) << bits; + bits += 7; + mapsize--; + } + + /* Set up the stream for the rest.. */ + stream->next_in = map; + stream->avail_in = mapsize; inflateInit(stream); - return inflate(stream, 0); + + /* And generate the fake traditional header */ + stream->total_out = 1 + snprintf(buffer, bufsiz, "%s %lu", type, size); + return 0; } static void *unpack_sha1_rest(z_stream *stream, void *buffer, unsigned long size) { int bytes = strlen(buffer) + 1; unsigned char *buf = xmalloc(1+size); + unsigned long n; - memcpy(buf, (char *) buffer + bytes, stream->total_out - bytes); - bytes = stream->total_out - bytes; + n = stream->total_out - bytes; + if (n > size) + n = size; + memcpy(buf, (char *) buffer + bytes, n); + bytes = n; if (bytes < size) { stream->next_out = buf + bytes; stream->avail_out = size - bytes; @@ -1414,6 +1462,49 @@ static int write_buffer(int fd, const void *buf, size_t len) return 0; } +static int write_binary_header(unsigned char *hdr, enum object_type type, unsigned long len) +{ + int hdr_len; + unsigned char c; + + c = (type << 4) | (len & 15); + len >>= 4; + hdr_len = 1; + while (len) { + *hdr++ = c | 0x80; + hdr_len++; + c = (len & 0x7f); + len >>= 7; + } + *hdr = c; + return hdr_len; +} + +static void setup_object_header(z_stream *stream, const char *type, unsigned long len) +{ + int obj_type, hdr; + + if (use_legacy_headers) { + while (deflate(stream, 0) == Z_OK) + /* nothing */; + return; + } + if (!strcmp(type, blob_type)) + obj_type = OBJ_BLOB; + else if (!strcmp(type, tree_type)) + obj_type = OBJ_TREE; + else if (!strcmp(type, commit_type)) + obj_type = OBJ_COMMIT; + else if (!strcmp(type, tag_type)) + obj_type = OBJ_TAG; + else + die("trying to generate bogus object of type '%s'", type); + hdr = write_binary_header(stream->next_out, obj_type, len); + stream->total_out = hdr; + stream->next_out += hdr; + stream->avail_out -= hdr; +} + int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned char *returnsha1) { int size; @@ -1459,7 +1550,7 @@ int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned cha /* Set it up */ memset(&stream, 0, sizeof(stream)); deflateInit(&stream, zlib_compression_level); - size = deflateBound(&stream, len+hdrlen); + size = 8 + deflateBound(&stream, len+hdrlen); compressed = xmalloc(size); /* Compress it */ @@ -1469,8 +1560,7 @@ int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned cha /* First header.. */ stream.next_in = hdr; stream.avail_in = hdrlen; - while (deflate(&stream, 0) == Z_OK) - /* nothing */; + setup_object_header(&stream, type, len); /* Then the data itself.. */ stream.next_in = buf; From dd4c59121ff8277d49a64a8f105936878a9fd7af Mon Sep 17 00:00:00 2001 From: Alp Toker Date: Fri, 14 Jul 2006 11:31:50 -0700 Subject: [PATCH 020/107] documentation (urls.txt) typofix --- Documentation/urls.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/urls.txt b/Documentation/urls.txt index 93378d2378..9d2ad469ec 100644 --- a/Documentation/urls.txt +++ b/Documentation/urls.txt @@ -15,7 +15,7 @@ to name the remote repository: - ssh://+++[user@+++]host.xz/~/path/to/repo.git =============================================================== -SSH Is the default transport protocol and also supports an +SSH is the default transport protocol and also supports an scp-like syntax. Both syntaxes support username expansion, as does the native git protocol. The following three are identical to the last three above, respectively: From d5b9e6cfa7a20932ca17649c9172619c9d961db4 Mon Sep 17 00:00:00 2001 From: Matthias Lederhofer Date: Fri, 14 Jul 2006 18:37:06 +0200 Subject: [PATCH 021/107] argv created by handle_alias should be NULL terminated Signed-off-by: Matthias Lederhofer Signed-off-by: Junio C Hamano --- git.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/git.c b/git.c index 102735af6c..ee5a0e86a7 100644 --- a/git.c +++ b/git.c @@ -133,13 +133,12 @@ static int handle_alias(int *argcp, const char ***argv) fflush(stderr); } + new_argv = realloc(new_argv, sizeof(char*) * + (count + *argcp + 1)); /* insert after command name */ - if (*argcp > 1) { - new_argv = realloc(new_argv, sizeof(char*) * - (count + *argcp)); - memcpy(new_argv + count, *argv + 1, - sizeof(char*) * *argcp); - } + memcpy(new_argv + count, *argv + 1, + sizeof(char*) * *argcp); + new_argv[count+*argcp] = NULL; *argv = new_argv; *argcp += count - 1; From 7eae7b993ec3c1f5dfeb78d79673627b48d5f772 Mon Sep 17 00:00:00 2001 From: Sergey Vlasov Date: Fri, 14 Jul 2006 19:06:57 +0400 Subject: [PATCH 022/107] Fix "git-fetch --tags" exit status when nothing has been changed After commit 55b7835e1b81a6debc7648149d2b8a4c5c64ddba git-fetch --tags exits with status 1 when no tags have been changed, which breaks calling git-fetch from scripts. Signed-off-by: Sergey Vlasov Signed-off-by: Junio C Hamano --- git-fetch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-fetch.sh b/git-fetch.sh index ff1769952b..ee99280a2a 100755 --- a/git-fetch.sh +++ b/git-fetch.sh @@ -153,7 +153,7 @@ fast_forward_local () { then if now_=$(cat "$GIT_DIR/$1") && test "$now_" = "$2" then - [ "$verbose" ] && echo >&2 "* $1: same as $3" + [ "$verbose" ] && echo >&2 "* $1: same as $3" ||: else echo >&2 "* $1: updating with $3" git-update-ref -m "$rloga: updating tag" "$1" "$2" From c7543ce0be5609df8123f88ac75a06c1bda98f0e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 14 Jul 2006 16:32:38 -0700 Subject: [PATCH 023/107] Documentation/Makefile: product depends on asciidoc.conf Signed-off-by: Junio C Hamano --- Documentation/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/Makefile b/Documentation/Makefile index 2b0efe7921..6dbe45b506 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -46,6 +46,7 @@ all: html man html: $(DOC_HTML) +$(DOC_HTML) $(DOC_MAN1) $(DOC_MAN7): asciidoc.conf man: man1 man7 man1: $(DOC_MAN1) From a3e65d74ee7ec9e6f49de7688a1cdac052910bd4 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Fri, 14 Jul 2006 16:36:00 -0700 Subject: [PATCH 024/107] Documentation/urls.txt: Use substitution to escape square brackets This changes "[user@]" to use {startsb} and {endsb} to insert [ and ], similar to how {caret} is used in git-rev-parse.txt. [jc: Removed a well-intentioned comment that broke the final formatting from the original patch. While we are at it, updated the paragraph that claims to be equivalent to the section that was updated earlier without making matching changes.] Signed-off-by: Jonas Fonseca Signed-off-by: Junio C Hamano --- Documentation/asciidoc.conf | 2 ++ Documentation/urls.txt | 17 +++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Documentation/asciidoc.conf b/Documentation/asciidoc.conf index 7ce71510de..8196d787ab 100644 --- a/Documentation/asciidoc.conf +++ b/Documentation/asciidoc.conf @@ -9,6 +9,8 @@ [attributes] caret=^ +startsb=[ +endsb=] ifdef::backend-docbook[] [gitlink-inlinemacro] diff --git a/Documentation/urls.txt b/Documentation/urls.txt index 9d2ad469ec..26ecba53fb 100644 --- a/Documentation/urls.txt +++ b/Documentation/urls.txt @@ -10,20 +10,21 @@ to name the remote repository: - https://host.xz/path/to/repo.git/ - git://host.xz/path/to/repo.git/ - git://host.xz/~user/path/to/repo.git/ -- ssh://+++[user@+++]host.xz/path/to/repo.git/ -- ssh://+++[user@+++]host.xz/~user/path/to/repo.git/ -- ssh://+++[user@+++]host.xz/~/path/to/repo.git +- ssh://{startsb}user@{endsb}host.xz/path/to/repo.git/ +- ssh://{startsb}user@{endsb}host.xz/~user/path/to/repo.git/ +- ssh://{startsb}user@{endsb}host.xz/~/path/to/repo.git =============================================================== -SSH is the default transport protocol and also supports an -scp-like syntax. Both syntaxes support username expansion, +SSH is the default transport protocol. You can optionally specify +which user to log-in as, and an alternate, scp-like syntax is also +supported. Both syntaxes support username expansion, as does the native git protocol. The following three are identical to the last three above, respectively: =============================================================== -- host.xz:/path/to/repo.git/ -- host.xz:~user/path/to/repo.git/ -- host.xz:path/to/repo.git +- {startsb}user@{endsb}host.xz:/path/to/repo.git/ +- {startsb}user@{endsb}host.xz:~user/path/to/repo.git/ +- {startsb}user@{endsb}host.xz:path/to/repo.git =============================================================== To sync with a local directory, use: From d1566f7883f727f38bf442af3fdb69d36e6fcea2 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Fri, 14 Jul 2006 17:48:51 -0700 Subject: [PATCH 025/107] git-format-patch: Make the second and subsequent mails replies to the first Add message_id and ref_message_id fields to struct rev_info, used in show_log with CMIT_FMT_EMAIL to set Message-Id and In-Reply-To/References respectively. Use these in git-format-patch to make the second and subsequent patch mails replies to the first patch mail. Signed-off-by: Josh Triplett Signed-off-by: Junio C Hamano --- builtin-log.c | 23 +++++++++++++++++++++++ log-tree.c | 5 +++++ revision.h | 2 ++ 3 files changed, 30 insertions(+) diff --git a/builtin-log.c b/builtin-log.c index 7e5cab15c1..1f1074cec6 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -226,6 +226,17 @@ static void get_patch_ids(struct rev_info *rev, struct diff_options *options) o2->flags = flags2; } +static void gen_message_id(char *dest, unsigned int length, char *base) +{ + const char *committer = git_committer_info(1); + const char *email_start = strrchr(committer, '<'); + const char *email_end = strrchr(committer, '>'); + if(!email_start || !email_end || email_start > email_end - 1) + die("Could not extract email from committer identity."); + snprintf(dest, length, "%s.%u.git.%.*s", base, time(NULL), + email_end - email_start - 1, email_start + 1); +} + int cmd_format_patch(int argc, const char **argv, char **envp) { struct commit *commit; @@ -239,6 +250,8 @@ int cmd_format_patch(int argc, const char **argv, char **envp) int ignore_if_in_upstream = 0; struct diff_options patch_id_opts; char *add_signoff = NULL; + char message_id[1024]; + char ref_message_id[1024]; git_config(git_format_config); init_revisions(&rev); @@ -365,6 +378,16 @@ int cmd_format_patch(int argc, const char **argv, char **envp) int shown; commit = list[nr]; rev.nr = total - nr + (start_number - 1); + /* Make the second and subsequent mails replies to the first */ + if (nr == (total - 2)) { + strncpy(ref_message_id, message_id, + sizeof(ref_message_id)); + ref_message_id[sizeof(ref_message_id)-1] = '\0'; + rev.ref_message_id = ref_message_id; + } + gen_message_id(message_id, sizeof(message_id), + sha1_to_hex(commit->object.sha1)); + rev.message_id = message_id; if (!use_stdout) reopen_stdout(commit, rev.nr, keep_subject); shown = log_tree_commit(&rev, commit); diff --git a/log-tree.c b/log-tree.c index 9d8d46fa00..4971988417 100644 --- a/log-tree.c +++ b/log-tree.c @@ -97,6 +97,11 @@ void show_log(struct rev_info *opt, const char *sep) subject = "Subject: "; printf("From %s Mon Sep 17 00:00:00 2001\n", sha1); + if (opt->message_id) + printf("Message-Id: <%s>\n", opt->message_id); + if (opt->ref_message_id) + printf("In-Reply-To: <%s>\nReferences: <%s>\n", + opt->ref_message_id, opt->ref_message_id); if (opt->mime_boundary) { static char subject_buffer[1024]; static char buffer[1024]; diff --git a/revision.h b/revision.h index c010a08116..e23ec8f45a 100644 --- a/revision.h +++ b/revision.h @@ -61,6 +61,8 @@ struct rev_info { struct log_info *loginfo; int nr, total; const char *mime_boundary; + const char *message_id; + const char *ref_message_id; const char *add_signoff; const char *extra_headers; From cc35de8470541e389b7d2bdda4c901574720fa81 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Fri, 14 Jul 2006 17:49:04 -0700 Subject: [PATCH 026/107] Add option to enable threading headers Add a --thread option to enable generation of In-Reply-To and References headers, used to make the second and subsequent mails appear as replies to the first. Signed-off-by: Josh Triplett Signed-off-by: Junio C Hamano --- Documentation/git-format-patch.txt | 10 +++++++++- builtin-log.c | 21 +++++++++++++-------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt index 4ca0014dac..305bd79154 100644 --- a/Documentation/git-format-patch.txt +++ b/Documentation/git-format-patch.txt @@ -9,7 +9,7 @@ git-format-patch - Prepare patches for e-mail submission SYNOPSIS -------- [verse] -'git-format-patch' [-n | -k] [-o | --stdout] [--attach] +'git-format-patch' [-n | -k] [-o | --stdout] [--attach] [--thread] [-s | --signoff] [--diff-options] [--start-number ] [..] @@ -35,6 +35,10 @@ they are created in the current working directory. If -n is specified, instead of "[PATCH] Subject", the first line is formatted as "[PATCH n/m] Subject". +If given --thread, git-format-patch will generate In-Reply-To and +References headers to make the second and subsequent patch mails appear +as replies to the first mail; this also generates a Message-Id header to +reference. OPTIONS ------- @@ -63,6 +67,10 @@ OPTIONS --attach:: Create attachments instead of inlining patches. +--thread:: + Add In-Reply-To and References headers to make the second and + subsequent mails appear as replies to the first. Also generates + the Message-Id header to reference. CONFIGURATION ------------- diff --git a/builtin-log.c b/builtin-log.c index 1f1074cec6..6466768051 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -248,6 +248,7 @@ int cmd_format_patch(int argc, const char **argv, char **envp) int start_number = -1; int keep_subject = 0; int ignore_if_in_upstream = 0; + int thread = 0; struct diff_options patch_id_opts; char *add_signoff = NULL; char message_id[1024]; @@ -317,6 +318,8 @@ int cmd_format_patch(int argc, const char **argv, char **envp) rev.mime_boundary = argv[i] + 9; else if (!strcmp(argv[i], "--ignore-if-in-upstream")) ignore_if_in_upstream = 1; + else if (!strcmp(argv[i], "--thread")) + thread = 1; else argv[j++] = argv[i]; } @@ -379,15 +382,17 @@ int cmd_format_patch(int argc, const char **argv, char **envp) commit = list[nr]; rev.nr = total - nr + (start_number - 1); /* Make the second and subsequent mails replies to the first */ - if (nr == (total - 2)) { - strncpy(ref_message_id, message_id, - sizeof(ref_message_id)); - ref_message_id[sizeof(ref_message_id)-1] = '\0'; - rev.ref_message_id = ref_message_id; + if (thread) { + if (nr == (total - 2)) { + strncpy(ref_message_id, message_id, + sizeof(ref_message_id)); + ref_message_id[sizeof(ref_message_id)-1]='\0'; + rev.ref_message_id = ref_message_id; + } + gen_message_id(message_id, sizeof(message_id), + sha1_to_hex(commit->object.sha1)); + rev.message_id = message_id; } - gen_message_id(message_id, sizeof(message_id), - sha1_to_hex(commit->object.sha1)); - rev.message_id = message_id; if (!use_stdout) reopen_stdout(commit, rev.nr, keep_subject); shown = log_tree_commit(&rev, commit); From da56645dd7c1175fc2ed1628ac35fdd35e705641 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Fri, 14 Jul 2006 17:49:08 -0700 Subject: [PATCH 027/107] Add option to set initial In-Reply-To/References Add the --in-reply-to option to provide a Message-Id for an initial In-Reply-To/References header, useful for including a new patch series as part of an existing thread. Signed-off-by: Josh Triplett Signed-off-by: Junio C Hamano --- Documentation/git-format-patch.txt | 6 ++++++ builtin-log.c | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt index 305bd79154..67425dc035 100644 --- a/Documentation/git-format-patch.txt +++ b/Documentation/git-format-patch.txt @@ -11,6 +11,7 @@ SYNOPSIS [verse] 'git-format-patch' [-n | -k] [-o | --stdout] [--attach] [--thread] [-s | --signoff] [--diff-options] [--start-number ] + [--in-reply-to=Message-Id] [..] DESCRIPTION @@ -72,6 +73,11 @@ OPTIONS subsequent mails appear as replies to the first. Also generates the Message-Id header to reference. +--in-reply-to=Message-Id:: + Make the first mail (or all the mails with --no-thread) appear as a + reply to the given Message-Id, which avoids breaking threads to + provide a new patch series. + CONFIGURATION ------------- You can specify extra mail header lines to be added to each diff --git a/builtin-log.c b/builtin-log.c index 6466768051..705205331e 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -249,6 +249,7 @@ int cmd_format_patch(int argc, const char **argv, char **envp) int keep_subject = 0; int ignore_if_in_upstream = 0; int thread = 0; + char *in_reply_to = NULL; struct diff_options patch_id_opts; char *add_signoff = NULL; char message_id[1024]; @@ -320,6 +321,14 @@ int cmd_format_patch(int argc, const char **argv, char **envp) ignore_if_in_upstream = 1; else if (!strcmp(argv[i], "--thread")) thread = 1; + else if (!strncmp(argv[i], "--in-reply-to=", 14)) + in_reply_to = argv[i] + 14; + else if (!strcmp(argv[i], "--in-reply-to")) { + i++; + if (i == argc) + die("Need a Message-Id for --in-reply-to"); + in_reply_to = argv[i]; + } else argv[j++] = argv[i]; } @@ -377,6 +386,7 @@ int cmd_format_patch(int argc, const char **argv, char **envp) if (numbered) rev.total = total + start_number - 1; rev.add_signoff = add_signoff; + rev.ref_message_id = in_reply_to; while (0 <= --nr) { int shown; commit = list[nr]; From 66142aa1f53979a87678159a82734b0174d98070 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Sat, 15 Jul 2006 01:29:19 -0400 Subject: [PATCH 028/107] Quote all calls to GIT_CONF_APPEND_LINE Not quoting macro arguments that contain other macros is a big no-no in Autoconf. It can break at any time. Signed-off-by: Pavel Roskin Signed-off-by: Junio C Hamano --- configure.ac | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/configure.ac b/configure.ac index 2932d0e766..c1f7751e6f 100644 --- a/configure.ac +++ b/configure.ac @@ -39,30 +39,30 @@ AC_MSG_NOTICE([CHECKS for libraries]) # Define NEEDS_SSL_WITH_CRYPTO if you need -lcrypto with -lssl (Darwin). AC_CHECK_LIB([ssl], [SHA1_Init],[], [AC_CHECK_LIB([crypto], [SHA1_INIT], - GIT_CONF_APPEND_LINE(NEEDS_SSL_WITH_CRYPTO=YesPlease), - GIT_CONF_APPEND_LINE(NO_OPENSSL=YesPlease))]) + [GIT_CONF_APPEND_LINE(NEEDS_SSL_WITH_CRYPTO=YesPlease)], + [GIT_CONF_APPEND_LINE(NO_OPENSSL=YesPlease)])]) # # Define NO_CURL if you do not have curl installed. git-http-pull and # git-http-push are not built, and you cannot use http:// and https:// # transports. AC_CHECK_LIB([curl], [curl_global_init],[], -GIT_CONF_APPEND_LINE(NO_CURL=YesPlease)) +[GIT_CONF_APPEND_LINE(NO_CURL=YesPlease)]) # # 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. AC_CHECK_LIB([expat], [XML_ParserCreate],[], -GIT_CONF_APPEND_LINE(NO_EXPAT=YesPlease)) +[GIT_CONF_APPEND_LINE(NO_EXPAT=YesPlease)]) # # Define NEEDS_LIBICONV if linking with libc is not enough (Darwin). AC_CHECK_LIB([c], [iconv],[], [AC_CHECK_LIB([iconv],[iconv], - GIT_CONF_APPEND_LINE(NEEDS_LIBICONV=YesPlease),[])]) + [GIT_CONF_APPEND_LINE(NEEDS_LIBICONV=YesPlease)],[])]) # # Define NEEDS_SOCKET if linking with libc is not enough (SunOS, # Patrick Mauritz). AC_CHECK_LIB([c], [socket],[], [AC_CHECK_LIB([socket],[socket], - GIT_CONF_APPEND_LINE(NEEDS_SOCKET=YesPlease),[])]) + [GIT_CONF_APPEND_LINE(NEEDS_SOCKET=YesPlease)],[])]) ## Checks for header files. @@ -73,19 +73,19 @@ AC_MSG_NOTICE([CHECKS for typedefs, structures, and compiler characteristics]) # # Define NO_D_INO_IN_DIRENT if you don't have d_ino in your struct dirent. AC_CHECK_MEMBER(struct dirent.d_ino,[], -GIT_CONF_APPEND_LINE(NO_D_INO_IN_DIRENT=YesPlease), +[GIT_CONF_APPEND_LINE(NO_D_INO_IN_DIRENT=YesPlease)], [#include ]) # # Define NO_D_TYPE_IN_DIRENT if your platform defines DT_UNKNOWN but lacks # d_type in struct dirent (latest Cygwin -- will be fixed soonish). AC_CHECK_MEMBER(struct dirent.d_type,[], -GIT_CONF_APPEND_LINE(NO_D_TYPE_IN_DIRENT=YesPlease), +[GIT_CONF_APPEND_LINE(NO_D_TYPE_IN_DIRENT=YesPlease)], [#include ]) # # Define NO_SOCKADDR_STORAGE if your platform does not have struct # sockaddr_storage. AC_CHECK_TYPE(struct sockaddr_storage,[], -GIT_CONF_APPEND_LINE(NO_SOCKADDR_STORAGE=YesPlease), +[GIT_CONF_APPEND_LINE(NO_SOCKADDR_STORAGE=YesPlease)], [#include ]) @@ -95,15 +95,15 @@ AC_MSG_NOTICE([CHECKS for library functions]) # # Define NO_STRCASESTR if you don't have strcasestr. AC_CHECK_FUNC(strcasestr,[], -GIT_CONF_APPEND_LINE(NO_STRCASESTR=YesPlease)) +[GIT_CONF_APPEND_LINE(NO_STRCASESTR=YesPlease)]) # # Define NO_STRLCPY if you don't have strlcpy. AC_CHECK_FUNC(strlcpy,[], -GIT_CONF_APPEND_LINE(NO_STRLCPY=YesPlease)) +[GIT_CONF_APPEND_LINE(NO_STRLCPY=YesPlease)]) # # Define NO_SETENV if you don't have setenv in the C library. AC_CHECK_FUNC(setenv,[], -GIT_CONF_APPEND_LINE(NO_SETENV=YesPlease)) +[GIT_CONF_APPEND_LINE(NO_SETENV=YesPlease)]) # # Define NO_MMAP if you want to avoid mmap. # From 2d023581c9a0ae5efdebfd0084d54d09669a25d5 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Sat, 15 Jul 2006 01:29:21 -0400 Subject: [PATCH 029/107] Set datarootdir in config.mak.in Autoconf 2.60 expresses datadir in terms of datarootdir. If datarootdir is not substituted, configure issues a warning and uses a compatibility substitution for datadir. Signed-off-by: Pavel Roskin Signed-off-by: Junio C Hamano --- config.mak.in | 1 + 1 file changed, 1 insertion(+) diff --git a/config.mak.in b/config.mak.in index 89520ebefe..04f508ab90 100644 --- a/config.mak.in +++ b/config.mak.in @@ -10,6 +10,7 @@ prefix = @prefix@ exec_prefix = @exec_prefix@ bindir = @bindir@ #gitexecdir = @libexecdir@/git-core/ +datarootdir = @datarootdir@ template_dir = @datadir@/git-core/templates/ GIT_PYTHON_DIR = @datadir@/git-core/python From 76af073457320ffcba937a8c7ed4e8b37150cca8 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 14 Jul 2006 22:47:53 -0700 Subject: [PATCH 030/107] builtin-log: typefix for recent format-patch changes. Signed-off-by: Junio C Hamano --- builtin-log.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/builtin-log.c b/builtin-log.c index 705205331e..4052cc75bd 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -10,6 +10,8 @@ #include "revision.h" #include "log-tree.h" #include "builtin.h" +#include +#include /* this is in builtin-diff.c */ void add_head(struct rev_info *revs); @@ -233,8 +235,9 @@ static void gen_message_id(char *dest, unsigned int length, char *base) const char *email_end = strrchr(committer, '>'); if(!email_start || !email_end || email_start > email_end - 1) die("Could not extract email from committer identity."); - snprintf(dest, length, "%s.%u.git.%.*s", base, time(NULL), - email_end - email_start - 1, email_start + 1); + snprintf(dest, length, "%s.%lu.git.%.*s", base, + (unsigned long) time(NULL), + (int)(email_end - email_start - 1), email_start + 1); } int cmd_format_patch(int argc, const char **argv, char **envp) @@ -249,7 +252,7 @@ int cmd_format_patch(int argc, const char **argv, char **envp) int keep_subject = 0; int ignore_if_in_upstream = 0; int thread = 0; - char *in_reply_to = NULL; + const char *in_reply_to = NULL; struct diff_options patch_id_opts; char *add_signoff = NULL; char message_id[1024]; From 26a8ad25b28a1cb906c88bdf539d840774ca5aeb Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 16 Jul 2006 00:00:09 -0700 Subject: [PATCH 031/107] show-branch: fix performance problem. The core function used in show-branch, join_revs(), was supposed to be exactly the same algorithm as merge_bases(), except that it was a version enhanced for use with more than two heads. However, it needed to mark and keep a list of all the commits it has seen, because it needed them for its semi-graphical output. The function to implement this list, mark_seen(), stupidly used insert_by_date(), when it did not need to keep the list sorted during its processing. This made "show-branch --merge-base" more than 20x slower compared to "merge-base --all" in some cases (e.g. between b5032a5 and 48ce8b0 in the Linux 2.6 kernel archive). The performance of "show-branch --independent" suffered from the same reason. This patch sorts the resulting list after the list traversal just once to fix these problems. Signed-off-by: Junio C Hamano --- builtin-show-branch.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/builtin-show-branch.c b/builtin-show-branch.c index 260cb221b9..3d240ca435 100644 --- a/builtin-show-branch.c +++ b/builtin-show-branch.c @@ -172,7 +172,7 @@ static void name_commits(struct commit_list *list, static int mark_seen(struct commit *commit, struct commit_list **seen_p) { if (!commit->object.flags) { - insert_by_date(commit, seen_p); + commit_list_insert(commit, seen_p); return 1; } return 0; @@ -218,9 +218,8 @@ static void join_revs(struct commit_list **list_p, * Postprocess to complete well-poisoning. * * At this point we have all the commits we have seen in - * seen_p list (which happens to be sorted chronologically but - * it does not really matter). Mark anything that can be - * reached from uninteresting commits not interesting. + * seen_p list. Mark anything that can be reached from + * uninteresting commits not interesting. */ for (;;) { int changed = 0; @@ -701,6 +700,8 @@ int cmd_show_branch(int ac, const char **av, char **envp) if (0 <= extra) join_revs(&list, &seen, num_rev, extra); + sort_by_date(&seen); + if (merge_base) return show_merge_base(seen, num_rev); From 7b520e62a2738ce776d1c9f11144021ff1fc63b6 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 15 Jul 2006 07:10:56 -0700 Subject: [PATCH 032/107] git-svn: don't check for migrations/upgrades on commit-diff Unlike other git-svn commands, commit-diff is intended to operate without needing any additional metadata inside .git Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- git-svn.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-svn.perl b/git-svn.perl index 4530ffe42c..89ad840dbf 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -147,7 +147,7 @@ init_vars(); load_authors() if $_authors; load_all_refs() if $_branch_all_refs; svn_compat_check() unless $_use_lib; -migration_check() unless $cmd =~ /^(?:init|rebuild|multi-init)$/; +migration_check() unless $cmd =~ /^(?:init|rebuild|multi-init|commit-diff)$/; $cmd{$cmd}->[0]->(@ARGV); exit 0; From 8641fb24ee3ab86bac62f88d31f6e92a9323f699 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 16 Jul 2006 03:38:40 -0700 Subject: [PATCH 033/107] typechange tests for git apply (currently failing) I've found that git apply is incapable of handling patches involving object type changes to the same path. Of course git itself is perfectly capable of making commits that generate these changes, as it only tracks trees states. It's just that the diffs between them are less useful if they can't be applied. Some of these are rare, but I've hit one of them (file becoming a symlink) recently in real-world usage, and was inspired to find more potential breakages :) I'm not sure when I'll have time to fix these myself and I'm not very familiar with the apply code. So if someone could get some or all of these cases working, they would be my hero :) Some of these are what I would refer to as corner-cases from hell. Most (if not all) other systems fail some of these. In fact, they aren't even capable of representing most of these changes in their histories; much less being able to handle patches to that effect. Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- t/t4114-apply-typechange.sh | 105 ++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100755 t/t4114-apply-typechange.sh diff --git a/t/t4114-apply-typechange.sh b/t/t4114-apply-typechange.sh new file mode 100755 index 0000000000..ca81d72157 --- /dev/null +++ b/t/t4114-apply-typechange.sh @@ -0,0 +1,105 @@ +#!/bin/sh +# +# Copyright (c) 2006 Eric Wong +# + +test_description='git-apply should not get confused with type changes. + +' + +. ./test-lib.sh + +test_expect_success 'setup repository and commits' ' + echo "hello world" > foo && + echo "hi planet" > bar && + git update-index --add foo bar && + git commit -m initial && + git branch initial && + rm -f foo && + ln -s bar foo && + git update-index foo && + git commit -m "foo symlinked to bar" && + git branch foo-symlinked-to-bar && + rm -f foo && + echo "how far is the sun?" > foo && + git update-index foo && + git commit -m "foo back to file" && + git branch foo-back-to-file && + rm -f foo && + git update-index --remove foo && + mkdir foo && + echo "if only I knew" > foo/baz && + git update-index --add foo/baz && + git commit -m "foo becomes a directory" && + git branch "foo-becomes-a-directory" && + echo "hello world" > foo/baz && + git update-index foo/baz && + git commit -m "foo/baz is the original foo" && + git branch foo-baz-renamed-from-foo + ' + +test_expect_success 'file renamed from foo to foo/baz' ' + git checkout -f initial && + git diff-tree -M -p HEAD foo-baz-renamed-from-foo > patch && + git apply --index < patch + ' +test_debug 'cat patch' + + +test_expect_success 'file renamed from foo/baz to foo' ' + git checkout -f foo-baz-renamed-from-foo && + git diff-tree -M -p HEAD initial > patch && + git apply --index < patch + ' +test_debug 'cat patch' + + +test_expect_success 'directory becomes file' ' + git checkout -f foo-becomes-a-directory && + git diff-tree -p HEAD initial > patch && + git apply --index < patch + ' +test_debug 'cat patch' + + +test_expect_success 'file becomes directory' ' + git checkout -f initial && + git diff-tree -p HEAD foo-becomes-a-directory > patch && + git apply --index < patch + ' +test_debug 'cat patch' + + +test_expect_success 'file becomes symlink' ' + git checkout -f initial && + git diff-tree -p HEAD foo-symlinked-to-bar > patch && + git apply --index < patch + ' +test_debug 'cat patch' + + +test_expect_success 'symlink becomes file' ' + git checkout -f foo-symlinked-to-bar && + git diff-tree -p HEAD foo-back-to-file > patch && + git apply --index < patch + ' +test_debug 'cat patch' + + +test_expect_success 'symlink becomes directory' ' + git checkout -f foo-symlinked-to-bar && + git diff-tree -p HEAD foo-becomes-a-directory > patch && + git apply --index < patch + ' +test_debug 'cat patch' + + +test_expect_success 'directory becomes symlink' ' + git checkout -f foo-becomes-a-directory && + git diff-tree -p HEAD foo-symlinked-to-bar > patch && + git apply --index < patch + ' +test_debug 'cat patch' + + +test_done From f8f0b1f0e7e96bf996c657d2c5c15e0ba3a4eeac Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 16 Jul 2006 23:25:12 -0700 Subject: [PATCH 034/107] checkout -f failed to check out a file if an existing directory interfered. When path foo/bar existed in the working tree, checkout -f to switch to a branch that has a file foo silently did a wrong thing. It failed to remove the directory foo, did not check out the file foo, and the worst of all it did not report any errors. Signed-off-by: Junio C Hamano --- builtin-read-tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin-read-tree.c b/builtin-read-tree.c index 6df5d7c5cb..122b6f130b 100644 --- a/builtin-read-tree.c +++ b/builtin-read-tree.c @@ -507,7 +507,7 @@ static int merged_entry(struct cache_entry *merge, struct cache_entry *old) } merge->ce_flags &= ~htons(CE_STAGEMASK); - add_cache_entry(merge, ADD_CACHE_OK_TO_ADD); + add_cache_entry(merge, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE); return 1; } @@ -518,7 +518,7 @@ static int deleted_entry(struct cache_entry *ce, struct cache_entry *old) else verify_absent(ce->name, "removed"); ce->ce_mode = 0; - add_cache_entry(ce, ADD_CACHE_OK_TO_ADD); + add_cache_entry(ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE); invalidate_ce_path(ce); return 1; } From c28c571c143a5145665f4bf334671ac3a7d0980c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 16 Jul 2006 23:28:23 -0700 Subject: [PATCH 035/107] apply: check D/F conflicts more carefully. When creating a new file where a directory used to be (or the user had an empty directory) the code did not check the result from lstat() closely enough, and mistakenly thought the path already existed in the working tree. This does not fix the problem where you have a patch that creates a file at "foo" and removes a file at "foo/bar" (which presumably is the last file in "foo/" directory in the original). For that, we would need to restructure write_out_results() loop. Signed-off-by: Junio C Hamano --- builtin-apply.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/builtin-apply.c b/builtin-apply.c index c903146bb6..97274425d5 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -1732,9 +1732,14 @@ static int check_patch(struct patch *patch) if (check_index && cache_name_pos(new_name, strlen(new_name)) >= 0) return error("%s: already exists in index", new_name); if (!cached) { - if (!lstat(new_name, &st)) - return error("%s: already exists in working directory", new_name); - if (errno != ENOENT) + struct stat nst; + if (!lstat(new_name, &nst)) { + if (S_ISDIR(nst.st_mode)) + ; /* ok */ + else + return error("%s: already exists in working directory", new_name); + } + else if ((errno != ENOENT) && (errno != ENOTDIR)) return error("%s: %s", new_name, strerror(errno)); } if (!patch->new_mode) { @@ -2010,6 +2015,16 @@ static void create_one_file(char *path, unsigned mode, const char *buf, unsigned return; } + if (errno == EEXIST) { + /* We may be trying to create a file where a directory + * used to be. + */ + struct stat st; + errno = 0; + if (!lstat(path, &st) && S_ISDIR(st.st_mode) && !rmdir(path)) + errno = EEXIST; + } + if (errno == EEXIST) { unsigned int nr = getpid(); From eed46644ca48ad08e1fd71e14afbe801399e8a67 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 16 Jul 2006 23:52:09 -0700 Subject: [PATCH 036/107] apply: split out removal and creation into different phases. This reworks write_out_result() loop so we first remove the paths that are to go away and then create them after finishing all the removal. This is necessary when a patch creates a file "foo" and removes a file "foo/bar". Signed-off-by: Junio C Hamano --- builtin-apply.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/builtin-apply.c b/builtin-apply.c index 97274425d5..37404e2e6a 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -2059,32 +2059,42 @@ static void create_file(struct patch *patch) cache_tree_invalidate_path(active_cache_tree, path); } -static void write_out_one_result(struct patch *patch) +/* phase zero is to remove, phase one is to create */ +static void write_out_one_result(struct patch *patch, int phase) { if (patch->is_delete > 0) { - remove_file(patch); + if (phase == 0) + remove_file(patch); return; } if (patch->is_new > 0 || patch->is_copy) { - create_file(patch); + if (phase == 1) + create_file(patch); return; } /* * Rename or modification boils down to the same * thing: remove the old, write the new */ - remove_file(patch); + if (phase == 0) + remove_file(patch); + if (phase == 1) create_file(patch); } static void write_out_results(struct patch *list, int skipped_patch) { + int phase; + if (!list && !skipped_patch) die("No changes"); - while (list) { - write_out_one_result(list); - list = list->next; + for (phase = 0; phase < 2; phase++) { + struct patch *l = list; + while (l) { + write_out_one_result(l, phase); + l = l->next; + } } } From 7f95aef28fa1e2662aebb4556c71ad6912d395e5 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 17 Jul 2006 00:10:47 -0700 Subject: [PATCH 037/107] apply: handle type-changing patch correctly. A type-change diff is always split into a patch to delete old, immediately followed by a patch to create new. check_patch() routine noticed that the path to be created already exists in the working tree and/or in the index when looking at the creation patch and mistakenly thought it to be an error. Signed-off-by: Junio C Hamano --- builtin-apply.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/builtin-apply.c b/builtin-apply.c index 37404e2e6a..8f7cf44c69 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -1664,13 +1664,14 @@ static int apply_data(struct patch *patch, struct stat *st, struct cache_entry * return 0; } -static int check_patch(struct patch *patch) +static int check_patch(struct patch *patch, struct patch *prev_patch) { struct stat st; const char *old_name = patch->old_name; const char *new_name = patch->new_name; const char *name = old_name ? old_name : new_name; struct cache_entry *ce = NULL; + int ok_if_exists; if (old_name) { int changed = 0; @@ -1728,13 +1729,28 @@ static int check_patch(struct patch *patch) old_name, st_mode, patch->old_mode); } + if (new_name && prev_patch && prev_patch->is_delete && + !strcmp(prev_patch->old_name, new_name)) + /* A type-change diff is always split into a patch to + * delete old, immediately followed by a patch to + * create new (see diff.c::run_diff()); in such a case + * it is Ok that the entry to be deleted by the + * previous patch is still in the working tree and in + * the index. + */ + ok_if_exists = 1; + else + ok_if_exists = 0; + if (new_name && (patch->is_new | patch->is_rename | patch->is_copy)) { - if (check_index && cache_name_pos(new_name, strlen(new_name)) >= 0) + if (check_index && + cache_name_pos(new_name, strlen(new_name)) >= 0 && + !ok_if_exists) return error("%s: already exists in index", new_name); if (!cached) { struct stat nst; if (!lstat(new_name, &nst)) { - if (S_ISDIR(nst.st_mode)) + if (S_ISDIR(nst.st_mode) || ok_if_exists) ; /* ok */ else return error("%s: already exists in working directory", new_name); @@ -1767,10 +1783,13 @@ static int check_patch(struct patch *patch) static int check_patch_list(struct patch *patch) { + struct patch *prev_patch = NULL; int error = 0; - for (;patch ; patch = patch->next) - error |= check_patch(patch); + for (prev_patch = NULL; patch ; patch = patch->next) { + error |= check_patch(patch, prev_patch); + prev_patch = patch; + } return error; } From 9919f41c91e525fd813fd2cd006f8fdcf976a661 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 17 Jul 2006 00:34:44 -0700 Subject: [PATCH 038/107] git-diff A...B to (usually) mean "git-diff `git-merge-base A B` B" This tweaks the argument parser of "git diff" to allow "git-diff A...B" to show diffs leading to B since their merge-base, when there is only one sensible merge base between A and B. Currently nonsense cases are thrown at combined-diff to produce nonsense results, which would eventually need to be fixed. Signed-off-by: Junio C Hamano --- builtin-diff.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/builtin-diff.c b/builtin-diff.c index cb38f44561..efd315240f 100644 --- a/builtin-diff.c +++ b/builtin-diff.c @@ -346,7 +346,15 @@ int cmd_diff(int argc, const char **argv, char **envp) return builtin_diff_index(&rev, argc, argv); else if (ents == 2) return builtin_diff_tree(&rev, argc, argv, ent); + else if ((ents == 3) && (ent[0].item->flags & UNINTERESTING)) { + /* diff A...B where there is one sane merge base between + * A and B. We have ent[0] == merge-base, ent[1] == A, + * and ent[2] == B. Show diff between the base and B. + */ + return builtin_diff_tree(&rev, argc, argv, ent); + } else - return builtin_diff_combined(&rev, argc, argv, ent, ents); + return builtin_diff_combined(&rev, argc, argv, + ent, ents); usage(builtin_diff_usage); } From 482faa8dafdf5dcf207b866b9c757271d9a45301 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 17 Jul 2006 13:01:27 -0700 Subject: [PATCH 039/107] git-fetch: fix --keep vs --thin When --keep is specified there is no reason to pass --thin to git-fetch-pack, which are mutually exclusive. This does not hurt because fetch-pack disables thin transfer when both are given internally, but still is confusing. Signed-off-by: Junio C Hamano --- git-fetch.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/git-fetch.sh b/git-fetch.sh index ee99280a2a..b6a223ee46 100755 --- a/git-fetch.sh +++ b/git-fetch.sh @@ -20,6 +20,7 @@ verbose= update_head_ok= exec= upload_pack= +keep=--thin while case "$#" in 0) break ;; esac do case "$1" in @@ -347,7 +348,7 @@ fetch_main () { ( : subshell because we muck with IFS IFS=" $LF" ( - git-fetch-pack $exec $keep --thin "$remote" $rref || echo failed "$remote" + git-fetch-pack $exec $keep "$remote" $rref || echo failed "$remote" ) | while read sha1 remote_name do From e7a0f6714bdfa7e3a169cc756a05cbbf787997eb Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 17 Jul 2006 13:08:14 -0700 Subject: [PATCH 040/107] unpack-objects: remove stale and confusing comment The very initial version of unpack-objects.c::unpack_all() used to unpack from the end of the pack, but since end of June last year it was changed to stream from the front and the comment does not reflect the reality anymore. Signed-off-by: Junio C Hamano --- unpack-objects.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/unpack-objects.c b/unpack-objects.c index 3b824b04a2..48c1ee7968 100644 --- a/unpack-objects.c +++ b/unpack-objects.c @@ -241,11 +241,6 @@ static void unpack_one(unsigned nr, unsigned total) } } -/* - * We unpack from the end, older files first. Now, usually - * there are deltas etc, so we'll not actually write the - * objects in that order, but we might as well try.. - */ static void unpack_all(void) { int i; From 1b91abe35079f3d6e6440b9a49766de06f3f1659 Mon Sep 17 00:00:00 2001 From: Martin Langhoff Date: Tue, 18 Jul 2006 14:22:49 +1200 Subject: [PATCH 041/107] cvsexportcommit - add -a (add author line) flag, cleanup warnings This patch adds support for -a which will add an "Author: " line, and possibly a "Committer: " line to the bottom of the commit message for CVS. The commit message parser is now a little bit better, and some warnings have been cleaned up. Signed-off-by: Junio C Hamano --- Documentation/git-cvsexportcommit.txt | 8 +++-- git-cvsexportcommit.perl | 50 ++++++++++++++++++++------- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/Documentation/git-cvsexportcommit.txt b/Documentation/git-cvsexportcommit.txt index 27ac72d98f..092d0d6730 100644 --- a/Documentation/git-cvsexportcommit.txt +++ b/Documentation/git-cvsexportcommit.txt @@ -8,7 +8,7 @@ git-cvsexportcommit - Export a commit to a CVS checkout SYNOPSIS -------- -'git-cvsexportcommit' [-h] [-v] [-c] [-p] [-f] [-m msgprefix] [PARENTCOMMIT] COMMITID +'git-cvsexportcommit' [-h] [-v] [-c] [-p] [-a] [-f] [-m msgprefix] [PARENTCOMMIT] COMMITID DESCRIPTION @@ -36,9 +36,13 @@ OPTIONS commit if any hunks fail to apply or there were other problems. -p:: - Be pedantic (paranoid) when applying patches. Invokes patch with + Be pedantic (paranoid) when applying patches. Invokes patch with --fuzz=0 +-a:: + Add authorship information. Adds Author line, and Committer (if + different from Author) to the message. + -f:: Force the merge even if the files are not up to date. diff --git a/git-cvsexportcommit.perl b/git-cvsexportcommit.perl index 5d13a54194..99b3dc392a 100755 --- a/git-cvsexportcommit.perl +++ b/git-cvsexportcommit.perl @@ -16,9 +16,9 @@ unless ($ENV{GIT_DIR} && -r $ENV{GIT_DIR}){ die "GIT_DIR is not defined or is unreadable"; } -our ($opt_h, $opt_p, $opt_v, $opt_c, $opt_f, $opt_m ); +our ($opt_h, $opt_p, $opt_v, $opt_c, $opt_f, $opt_a, $opt_m ); -getopts('hpvcfm:'); +getopts('hpvcfam:'); $opt_h && usage(); @@ -29,7 +29,6 @@ our ($tmpdir, $tmpdirname) = tempdir('git-cvsapplycommit-XXXXXX', TMPDIR => 1, CLEANUP => 1); -print Dumper(@ARGV); # resolve target commit my $commit; $commit = pop @ARGV; @@ -53,12 +52,32 @@ if (@ARGV) { # find parents from the commit itself my @commit = safe_pipe_capture('git-cat-file', 'commit', $commit); my @parents; -foreach my $p (@commit) { - if ($p =~ m/^$/) { # end of commit headers, we're done - last; +my $committer; +my $author; +my $stage = 'headers'; # headers, msg +my $title; +my $msg = ''; + +foreach my $line (@commit) { + chomp $line; + if ($stage eq 'headers' && $line eq '') { + $stage = 'msg'; + next; } - if ($p =~ m/^parent (\w{40})$/) { # found a parent - push @parents, $1; + + if ($stage eq 'headers') { + if ($line =~ m/^parent (\w{40})$/) { # found a parent + push @parents, $1; + } elsif ($line =~ m/^author (.+) \d+ \+\d+$/) { + $author = $1; + } elsif ($line =~ m/^committer (.+) \d+ \+\d+$/) { + $committer = $1; + } + } else { + $msg .= $line . "\n"; + unless ($title) { + $title = $line; + } } } @@ -84,12 +103,18 @@ $opt_v && print "Applying to CVS commit $commit from parent $parent\n"; # grab the commit message open(MSG, ">.msg") or die "Cannot open .msg for writing"; -print MSG $opt_m; +if ($opt_m) { + print MSG $opt_m; +} +print MSG $msg; +if ($opt_a) { + print MSG "\n\nAuthor: $author\n"; + if ($author ne $committer) { + print MSG "Committer: $committer\n"; + } +} close MSG; -`git-cat-file commit $commit | sed -e '1,/^\$/d' >> .msg`; -$? && die "Error extracting the commit message"; - my (@afiles, @dfiles, @mfiles, @dirs); my @files = safe_pipe_capture('git-diff-tree', '-r', $parent, $commit); #print @files; @@ -233,6 +258,7 @@ foreach my $f (@dfiles) { } print "Commit to CVS\n"; +print "Patch: $title\n"; my $commitfiles = join(' ', @afiles, @mfiles, @dfiles); my $cmd = "cvs commit -F .msg $commitfiles"; From 56ac168f6f89bebf2846c4bafed01318fe3f25cd Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 18 Jul 2006 19:46:34 +0200 Subject: [PATCH 042/107] Fix t4114 on cygwin On cygwin, when you try to create a symlink over a directory, you do not get EEXIST, but EACCES. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin-apply.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin-apply.c b/builtin-apply.c index 8f7cf44c69..d924ac3d0a 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -2034,7 +2034,7 @@ static void create_one_file(char *path, unsigned mode, const char *buf, unsigned return; } - if (errno == EEXIST) { + if (errno == EEXIST || errno == EACCES) { /* We may be trying to create a file where a directory * used to be. */ From ce1a79b6a74b031213d8efd4f72cb0e954e261d5 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 20 Jul 2006 11:30:44 +0200 Subject: [PATCH 043/107] tar-tree: add the "tar.umask" config option By default, git-tar-tree(1) sets file and directories modes to 0666 or 0777. While this is both useful and acceptable for projects such as the Linux Kernel, it might be excessive for other projects. With this variable, it becomes possible to tell git-tar-tree(1) to apply a specific umask to the modes above. The special value "user" indicates that the user's current umask will be used. This should be enough for most projects, as it will lead to the same permissions as git-checkout(1) would use. The default value remains 0, which means world read-write. Signed-off-by: Willy Tarreau Acked-by: Rene Scharfe Signed-off-by: Junio C Hamano --- Documentation/config.txt | 11 +++++++++++ Documentation/git-tar-tree.txt | 15 ++++++++++++++- builtin-tar-tree.c | 21 ++++++++++++++++++--- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index 0b434c1f19..f4985d453e 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -208,6 +208,17 @@ showbranch.default:: The default set of branches for gitlink:git-show-branch[1]. See gitlink:git-show-branch[1]. +tar.umask:: + By default, git-link:git-tar-tree[1] sets file and directories modes + to 0666 or 0777. While this is both useful and acceptable for projects + such as the Linux Kernel, it might be excessive for other projects. + With this variable, it becomes possible to tell + git-link:git-tar-tree[1] to apply a specific umask to the modes above. + The special value "user" indicates that the user's current umask will + be used. This should be enough for most projects, as it will lead to + the same permissions as git-link:git-checkout[1] would use. The default + value remains 0, which means world read-write. + user.email:: Your email address to be recorded in any newly created commits. Can be overridden by the 'GIT_AUTHOR_EMAIL' and 'GIT_COMMITTER_EMAIL' diff --git a/Documentation/git-tar-tree.txt b/Documentation/git-tar-tree.txt index f2675c4193..7a99acf2ec 100644 --- a/Documentation/git-tar-tree.txt +++ b/Documentation/git-tar-tree.txt @@ -37,7 +37,20 @@ OPTIONS Instead of making a tar archive from local repository, retrieve a tar archive from a remote repository. -Examples +CONFIGURATION +------------- +By default, file and directories modes are set to 0666 or 0777. It is +possible to change this by setting the "umask" variable in the +repository configuration as follows : + +[tar] + umask = 002 ;# group friendly + +The special umask value "user" indicates that the user's current umask +will be used instead. The default value remains 0, which means world +readable/writable files and directories. + +EXAMPLES -------- git tar-tree HEAD junk | (cd /var/tmp/ && tar xf -):: diff --git a/builtin-tar-tree.c b/builtin-tar-tree.c index f2e48aae2a..e5aaded820 100644 --- a/builtin-tar-tree.c +++ b/builtin-tar-tree.c @@ -20,6 +20,7 @@ static char block[BLOCKSIZE]; static unsigned long offset; static time_t archive_time; +static int tar_umask; /* tries hard to write, either succeeds or dies in the attempt */ static void reliable_write(const void *data, unsigned long size) @@ -188,13 +189,13 @@ static void write_entry(const unsigned char *sha1, struct strbuf *path, } else { if (S_ISDIR(mode)) { *header.typeflag = TYPEFLAG_DIR; - mode |= 0777; + mode = (mode | 0777) & ~tar_umask; } else if (S_ISLNK(mode)) { *header.typeflag = TYPEFLAG_LNK; mode |= 0777; } else if (S_ISREG(mode)) { *header.typeflag = TYPEFLAG_REG; - mode |= (mode & 0100) ? 0777 : 0666; + mode = (mode | ((mode & 0100) ? 0777 : 0666)) & ~tar_umask; } else { error("unsupported file mode: 0%o (SHA1: %s)", mode, sha1_to_hex(sha1)); @@ -293,6 +294,20 @@ static void traverse_tree(struct tree_desc *tree, struct strbuf *path) } } +int git_tar_config(const char *var, const char *value) +{ + if (!strcmp(var, "tar.umask")) { + if (!strcmp(value, "user")) { + tar_umask = umask(0); + umask(tar_umask); + } else { + tar_umask = git_config_int(var, value); + } + return 0; + } + return git_default_config(var, value); +} + static int generate_tar(int argc, const char **argv, char** envp) { unsigned char sha1[20], tree_sha1[20]; @@ -305,7 +320,7 @@ static int generate_tar(int argc, const char **argv, char** envp) current_path.len = current_path.eof = 0; setup_git_directory(); - git_config(git_default_config); + git_config(git_tar_config); switch (argc) { case 3: From d0d8f7dc5ffe029d3fc047fb7ffecd7ecfb6601c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 20 Jul 2006 01:43:01 -0700 Subject: [PATCH 044/107] git-svn: fix fetching new directories copies when using SVN:: libs Log output from SVN doesn't list all the new files that were added if a new directory was copied from an existing place in the repository. This means we'll have to do some extra work and traverse new directories ourselves. This has been updated from the original patch to defer traversed adds until all removals have been done. Please disregard the original. Thanks to Ben Williamson for the excellent bug report and testing. Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- git-svn.perl | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/git-svn.perl b/git-svn.perl index 89ad840dbf..6453771f9c 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -2709,6 +2709,12 @@ sub libsvn_fetch { } else { die "Unrecognized action: $m, ($f r$rev)\n"; } + } elsif ($t == $SVN::Node::dir && $m =~ /^[AR]$/) { + my @traversed = (); + libsvn_traverse($gui, '', $f, $rev, \@traversed); + foreach (@traversed) { + push @amr, [ $m, $_ ] + } } $pool->clear; } @@ -2778,7 +2784,7 @@ sub libsvn_parse_revision { } sub libsvn_traverse { - my ($gui, $pfx, $path, $rev) = @_; + my ($gui, $pfx, $path, $rev, $files) = @_; my $cwd = "$pfx/$path"; my $pool = SVN::Pool->new; $cwd =~ s#^/+##g; @@ -2786,10 +2792,15 @@ sub libsvn_traverse { foreach my $d (keys %$dirent) { my $t = $dirent->{$d}->kind; if ($t == $SVN::Node::dir) { - libsvn_traverse($gui, $cwd, $d, $rev); + libsvn_traverse($gui, $cwd, $d, $rev, $files); } elsif ($t == $SVN::Node::file) { - print "\tA\t$cwd/$d\n" unless $_q; - libsvn_get_file($gui, "$cwd/$d", $rev); + my $file = "$cwd/$d"; + if (defined $files) { + push @$files, $file; + } else { + print "\tA\t$file\n" unless $_q; + libsvn_get_file($gui, $file, $rev); + } } } $pool->clear; @@ -2913,9 +2924,7 @@ sub libsvn_new_tree { } my ($paths, $rev, $author, $date, $msg) = @_; open my $gui, '| git-update-index -z --index-info' or croak $!; - my $pool = SVN::Pool->new; - libsvn_traverse($gui, '', $SVN_PATH, $rev, $pool); - $pool->clear; + libsvn_traverse($gui, '', $SVN_PATH, $rev); close $gui or croak $?; return libsvn_log_entry($rev, $author, $date, $msg); } From 51a6e56fb7f63e110dc0c3c1fddd07ca9e22ced6 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Sat, 22 Jul 2006 15:39:02 +0200 Subject: [PATCH 045/107] git.el: Run git-rerere on commits if the rr-cache directory exists. Signed-off-by: Alexandre Julliard Signed-off-by: Junio C Hamano --- contrib/emacs/git.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el index 34c995046d..7371d4b463 100644 --- a/contrib/emacs/git.el +++ b/contrib/emacs/git.el @@ -584,6 +584,8 @@ and returns the process output as a string." (condition-case nil (delete-file ".git/MERGE_HEAD") (error nil)) (with-current-buffer buffer (erase-buffer)) (git-set-files-state files 'uptodate) + (when (file-directory-p ".git/rr-cache") + (git-run-command nil nil "rerere")) (git-refresh-files) (git-refresh-ewoc-hf git-status) (message "Committed %s." commit)) From 9f56a7fda940caa7d4a1b06947481b5157510557 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Sat, 22 Jul 2006 15:39:32 +0200 Subject: [PATCH 046/107] git.el: Prepend a slash to the file name when adding to .gitignore. This way the ignore command will really only ignore the marked files and not files with the same name in subdirectories. Signed-off-by: Alexandre Julliard Signed-off-by: Junio C Hamano --- contrib/emacs/git.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el index 7371d4b463..5837471375 100644 --- a/contrib/emacs/git.el +++ b/contrib/emacs/git.el @@ -258,7 +258,7 @@ and returns the process output as a string." (set-buffer (find-file-noselect ignore-name)) (goto-char (point-max)) (unless (zerop (current-column)) (insert "\n")) - (insert name "\n") + (insert "/" name "\n") (sort-lines nil (point-min) (point-max)) (save-buffer)) (when created From 73389f12bf0ef39820685a322527fab549676f33 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Sat, 22 Jul 2006 15:39:53 +0200 Subject: [PATCH 047/107] git.el: Try to reuse an existing buffer when running git-status. By default, running git-status again will now reuse an existing buffer that displays the same directory. The old behavior of always creating a new buffer can be obtained by customizing the git-reuse-status-buffer option. Signed-off-by: Alexandre Julliard Signed-off-by: Junio C Hamano --- contrib/emacs/git.el | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el index 5837471375..92cb2b90fe 100644 --- a/contrib/emacs/git.el +++ b/contrib/emacs/git.el @@ -83,6 +83,12 @@ then to `add-log-mailing-address' and then to `user-mail-address'." :group 'git :type 'boolean) +(defcustom git-reuse-status-buffer t + "Whether `git-status' should try to reuse an existing buffer +if there is already one that displays the same directory." + :group 'git + :type 'boolean) + (defcustom git-per-dir-ignore-file ".gitignore" "Name of the per-directory ignore file." :group 'git @@ -1003,12 +1009,28 @@ Commands: (set (make-local-variable 'list-buffers-directory) default-directory) (run-hooks 'git-status-mode-hook))) +(defun git-find-status-buffer (dir) + "Find the git status buffer handling a specified directory." + (let ((list (buffer-list)) + (fulldir (expand-file-name dir)) + found) + (while (and list (not found)) + (let ((buffer (car list))) + (with-current-buffer buffer + (when (and list-buffers-directory + (string-equal fulldir (expand-file-name list-buffers-directory)) + (string-match "\\*git-status\\*$" (buffer-name buffer))) + (setq found buffer)))) + (setq list (cdr list))) + found)) + (defun git-status (dir) "Entry point into git-status mode." (interactive "DSelect directory: ") (setq dir (git-get-top-dir dir)) (if (file-directory-p (concat (file-name-as-directory dir) ".git")) - (let ((buffer (create-file-buffer (expand-file-name "*git-status*" dir)))) + (let ((buffer (or (and git-reuse-status-buffer (git-find-status-buffer dir)) + (create-file-buffer (expand-file-name "*git-status*" dir))))) (switch-to-buffer buffer) (cd dir) (git-status-mode) From 5df52584fa6cce1789009ad8a11f9eee92d5168a Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Sat, 22 Jul 2006 15:40:13 +0200 Subject: [PATCH 048/107] git.el: Put the git customize group in the 'tools' parent group. Signed-off-by: Alexandre Julliard Signed-off-by: Junio C Hamano --- contrib/emacs/git.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el index 92cb2b90fe..68de9be0c7 100644 --- a/contrib/emacs/git.el +++ b/contrib/emacs/git.el @@ -55,7 +55,8 @@ ;;;; ------------------------------------------------------------ (defgroup git nil - "Git user interface") + "A user interface for the git versioning system." + :group 'tools) (defcustom git-committer-name nil "User name to use for commits. From 8eb38cad440d8d51d8737d546a067a88361f6c3d Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Mon, 24 Jul 2006 00:28:28 -0400 Subject: [PATCH 049/107] Disable linking with Fink or DarwinPorts. It may be desirable for the compiler to disable linking against Fink or DarwinPorts, especially if both are installed on the system and the user wants GIT to be linked specifically to only one of them. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- Makefile | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 01fb9cfdbd..3e085dfa6f 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,18 @@ all: # tests. These tests take up a significant amount of the total test time # but are not needed unless you plan to talk to SVN repos. # +# Define NO_FINK if you are building on Darwin/Mac OS X, have Fink +# installed in /sw, but don't want GIT to link against any libraries +# installed there. If defined you may specify your own (or Fink's) +# include directories and library directories by defining CFLAGS +# and LDFLAGS appropriately. +# +# Define NO_DARWIN_PORTS if you are building on Darwin/Mac OS X, +# have DarwinPorts installed in /opt/local, but don't want GIT to +# link against any libraries installed there. If defined you may +# specify your own (or DarwinPort's) include directories and +# library directories by defining CFLAGS and LDFLAGS appropriately. +# # Define PPC_SHA1 environment variable when running make to make use of # a bundled SHA1 routine optimized for PowerPC. # @@ -254,15 +266,17 @@ ifeq ($(uname_S),Darwin) NEEDS_SSL_WITH_CRYPTO = YesPlease NEEDS_LIBICONV = YesPlease NO_STRLCPY = YesPlease - ## fink - ifeq ($(shell test -d /sw/lib && echo y),y) - ALL_CFLAGS += -I/sw/include - ALL_LDFLAGS += -L/sw/lib + ifndef NO_FINK + ifeq ($(shell test -d /sw/lib && echo y),y) + ALL_CFLAGS += -I/sw/include + ALL_LDFLAGS += -L/sw/lib + endif endif - ## darwinports - ifeq ($(shell test -d /opt/local/lib && echo y),y) - ALL_CFLAGS += -I/opt/local/include - ALL_LDFLAGS += -L/opt/local/lib + ifndef NO_DARWIN_PORTS + ifeq ($(shell test -d /opt/local/lib && echo y),y) + ALL_CFLAGS += -I/opt/local/include + ALL_LDFLAGS += -L/opt/local/lib + endif endif endif ifeq ($(uname_S),SunOS) From 4812a93a8c0ad25ee701da8ff46a3c5d62994224 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sun, 23 Jul 2006 01:50:30 -0400 Subject: [PATCH 050/107] pack-objects: check pack.window for default window size For some repositories, deltas simply don't make sense. One can disable them for git-repack by adding --window, but git-push insists on making the deltas which can be very CPU-intensive for little benefit. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- Documentation/config.txt | 4 ++++ pack-objects.c | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index f4985d453e..9d08dfceda 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -193,6 +193,10 @@ merge.summary:: Whether to include summaries of merged commits in newly created merge commit messages. False by default. +pack.window:: + The size of the window used by gitlink:git-pack-objects[1] when no + window size is given on the command line. Defaults to 10. + pull.octopus:: The default merge strategy to use when pulling multiple branches at once. diff --git a/pack-objects.c b/pack-objects.c index 04a48b925b..861c7f08ff 100644 --- a/pack-objects.c +++ b/pack-objects.c @@ -63,6 +63,7 @@ static const char *base_name; static unsigned char pack_file_sha1[20]; static int progress = 1; static volatile sig_atomic_t progress_update = 0; +static int window = 10; /* * The object names in objects array are hashed with this hashtable, @@ -1216,16 +1217,26 @@ static void setup_progress_signal(void) setitimer(ITIMER_REAL, &v, NULL); } +static int git_pack_config(const char *k, const char *v) +{ + if(!strcmp(k, "pack.window")) { + window = git_config_int(k, v); + return 0; + } + return git_default_config(k, v); +} + int main(int argc, char **argv) { SHA_CTX ctx; char line[40 + 1 + PATH_MAX + 2]; - int window = 10, depth = 10, pack_to_stdout = 0; + int depth = 10, pack_to_stdout = 0; struct object_entry **list; int num_preferred_base = 0; int i; setup_git_directory(); + git_config(git_pack_config); progress = isatty(2); for (i = 1; i < argc; i++) { From f8263c5339fd70ee00b60c37b715c7e46b30a3bf Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Sun, 23 Jul 2006 19:51:04 +0200 Subject: [PATCH 051/107] show-branch: Fix another performance problem. When naming commits, stop walking the parent chain as soon as we find a commit that already has a name. The parent chain of that commit will be walked later on in any case (or may even have been walked already). This avoids O(n^2) behavior; on a tree where show-branch displays 6800 commits, the total run time drops from 77 seconds to 5 seconds. Signed-off-by: Alexandre Julliard Signed-off-by: Junio C Hamano --- builtin-show-branch.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builtin-show-branch.c b/builtin-show-branch.c index 3d240ca435..82f75b72de 100644 --- a/builtin-show-branch.c +++ b/builtin-show-branch.c @@ -89,6 +89,8 @@ static int name_first_parent_chain(struct commit *c) name_parent(c, p); i++; } + else + break; c = p; } return i; From cbd64afbb3b1ad5433585ac71d94bd0c63270e38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Sandstr=C3=B6m?= Date: Wed, 19 Jul 2006 22:28:00 +0200 Subject: [PATCH 052/107] git-am: Don't accept an mbox on stdin of we already have a .dotest directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It makes no sense to accept an mbox via stdin when we won't accept it on the commandline. The patch helps the following scenario: # git init-db "add file1 with content" # git checkout -b apply "edit file1 && commit" # git checkout -b conflict master "edit file1 && commit" # git checkout -b ok master "add file2" # git checkout apply # git format-patch -k -3 master..conflict | git am -k -3 => git-am fails with a conflict message # git reset --hard # git format-patch -k -3 master..ok | git am -k -3 => git am fails with the same conflict message as above, => since it's trying to apply the old .dotest directory With the patch it complains about an old .dotest directory instead. Signed-off-by: Lukas Sandström Signed-off-by: Junio C Hamano --- git-am.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/git-am.sh b/git-am.sh index 3a129e0021..04f0119435 100755 --- a/git-am.sh +++ b/git-am.sh @@ -156,8 +156,10 @@ fi if test -d "$dotest" then - test ",$#," = ",0," || - die "previous dotest directory $dotest still exists but mbox given." + if test ",$#," != ",0," || ! tty -s + then + die "previous dotest directory $dotest still exists but mbox given." + fi resume=yes else # Make sure we are not given --skip nor --resolved From ce43697379ad8ffcaf061a4709489728c1dbe911 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sun, 23 Jul 2006 05:24:18 -0400 Subject: [PATCH 053/107] Colorize 'commit' lines in log ui When paging through the output of git-whatchanged, the color cues help to visually navigate within a diff. However, it is difficult to notice when a new commit starts, because the commit and log are shown in the "normal" color. This patch colorizes the 'commit' line, customizable through diff.colors.commit and defaulting to yellow. As a side effect, some of the diff color engine (slot enum, get_color) has become accessible outside of diff.c. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- diff.c | 28 +++++++++++----------------- diff.h | 11 +++++++++++ log-tree.c | 5 ++++- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/diff.c b/diff.c index 8b44756136..6a71376483 100644 --- a/diff.c +++ b/diff.c @@ -17,15 +17,6 @@ static int diff_detect_rename_default = 0; static int diff_rename_limit_default = -1; static int diff_use_color_default = 0; -enum color_diff { - DIFF_RESET = 0, - DIFF_PLAIN = 1, - DIFF_METAINFO = 2, - DIFF_FRAGINFO = 3, - DIFF_FILE_OLD = 4, - DIFF_FILE_NEW = 5, -}; - /* "\033[1;38;5;2xx;48;5;2xxm\0" is 23 bytes */ static char diff_colors[][24] = { "\033[m", /* reset */ @@ -33,7 +24,8 @@ static char diff_colors[][24] = { "\033[1m", /* bold */ "\033[36m", /* cyan */ "\033[31m", /* red */ - "\033[32m" /* green */ + "\033[32m", /* green */ + "\033[33m" /* yellow */ }; static int parse_diff_color_slot(const char *var, int ofs) @@ -48,6 +40,8 @@ static int parse_diff_color_slot(const char *var, int ofs) return DIFF_FILE_OLD; if (!strcasecmp(var+ofs, "new")) return DIFF_FILE_NEW; + if (!strcasecmp(var+ofs, "commit")) + return DIFF_COMMIT; die("bad config variable '%s'", var); } @@ -370,7 +364,7 @@ struct emit_callback { const char **label_path; }; -static inline const char *get_color(int diff_use_color, enum color_diff ix) +const char *diff_get_color(int diff_use_color, enum color_diff ix) { if (diff_use_color) return diff_colors[ix]; @@ -381,8 +375,8 @@ static void fn_out_consume(void *priv, char *line, unsigned long len) { int i; struct emit_callback *ecbdata = priv; - const char *set = get_color(ecbdata->color_diff, DIFF_METAINFO); - const char *reset = get_color(ecbdata->color_diff, DIFF_RESET); + const char *set = diff_get_color(ecbdata->color_diff, DIFF_METAINFO); + const char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET); if (ecbdata->label_path[0]) { printf("%s--- %s%s\n", set, ecbdata->label_path[0], reset); @@ -397,7 +391,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len) ; if (2 <= i && i < len && line[i] == ' ') { ecbdata->nparents = i - 1; - set = get_color(ecbdata->color_diff, DIFF_FRAGINFO); + set = diff_get_color(ecbdata->color_diff, DIFF_FRAGINFO); } else if (len < ecbdata->nparents) set = reset; @@ -410,7 +404,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len) else if (line[i] == '+') color = DIFF_FILE_NEW; } - set = get_color(ecbdata->color_diff, color); + set = diff_get_color(ecbdata->color_diff, color); } if (len > 0 && line[len-1] == '\n') len--; @@ -767,8 +761,8 @@ static void builtin_diff(const char *name_a, mmfile_t mf1, mf2; const char *lbl[2]; char *a_one, *b_two; - const char *set = get_color(o->color_diff, DIFF_METAINFO); - const char *reset = get_color(o->color_diff, DIFF_RESET); + const char *set = diff_get_color(o->color_diff, DIFF_METAINFO); + const char *reset = diff_get_color(o->color_diff, DIFF_RESET); a_one = quote_two("a/", name_a); b_two = quote_two("b/", name_b); diff --git a/diff.h b/diff.h index a06f959938..2cced530fa 100644 --- a/diff.h +++ b/diff.h @@ -69,6 +69,17 @@ struct diff_options { add_remove_fn_t add_remove; }; +enum color_diff { + DIFF_RESET = 0, + DIFF_PLAIN = 1, + DIFF_METAINFO = 2, + DIFF_FRAGINFO = 3, + DIFF_FILE_OLD = 4, + DIFF_FILE_NEW = 5, + DIFF_COMMIT = 6, +}; +const char *diff_get_color(int diff_use_color, enum color_diff ix); + extern const char mime_boundary_leader[]; extern void diff_tree_setup_paths(const char **paths, struct diff_options *); diff --git a/log-tree.c b/log-tree.c index 9d8d46fa00..b71cf9ba41 100644 --- a/log-tree.c +++ b/log-tree.c @@ -129,7 +129,8 @@ void show_log(struct rev_info *opt, const char *sep) opt->diffopt.stat_sep = buffer; } } else { - printf("%s%s", + printf("%s%s%s", + diff_get_color(opt->diffopt.color_diff, DIFF_COMMIT), opt->commit_format == CMIT_FMT_ONELINE ? "" : "commit ", diff_unique_abbrev(commit->object.sha1, abbrev_commit)); if (opt->parents) @@ -139,6 +140,8 @@ void show_log(struct rev_info *opt, const char *sep) diff_unique_abbrev(parent->object.sha1, abbrev_commit)); putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n'); + printf("%s", + diff_get_color(opt->diffopt.color_diff, DIFF_RESET)); } /* From 5e27e27e5d3da5dcbe5fbfe204c2ade0128538a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santi=20B=C3=A9jar?= Date: Sun, 23 Jul 2006 00:54:40 +0200 Subject: [PATCH 054/107] Defaulting fetch to origin when set in the repo-config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Santi Béjar Signed-off-by: Junio C Hamano --- git-fetch.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/git-fetch.sh b/git-fetch.sh index b6a223ee46..f7167abdf0 100755 --- a/git-fetch.sh +++ b/git-fetch.sh @@ -70,7 +70,8 @@ case "$#" in 0) test -f "$GIT_DIR/branches/origin" || test -f "$GIT_DIR/remotes/origin" || - die "Where do you want to fetch from today?" + git-repo-config --get remote.origin.url >/dev/null || + die "Where do you want to fetch from today?" set origin ;; esac From 0d516adab8014bc0d16a0ae7bed7a76e4bd98ec5 Mon Sep 17 00:00:00 2001 From: Matthias Lederhofer Date: Tue, 18 Jul 2006 19:14:51 +0200 Subject: [PATCH 055/107] upload-pack: fix timeout in create_pack_file Signed-off-by: Matthias Lederhofer Signed-off-by: Junio C Hamano --- upload-pack.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/upload-pack.c b/upload-pack.c index f6f5a7e3db..07ecdb4281 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -182,6 +182,8 @@ static void create_pack_file(void) ssize_t sz; int pe, pu, pollsize; + reset_timeout(); + pollsize = 0; pe = pu = -1; From e557667e2d0439451f404794cb308affbc0acfb1 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 24 Jul 2006 14:41:41 +0200 Subject: [PATCH 056/107] Always reset the color _before_ printing out the newline This patch brings the benefits of part of v1.4.1-rc2~37 to the "commit" colorizing patch. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- log-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log-tree.c b/log-tree.c index b71cf9ba41..3a6c84dab5 100644 --- a/log-tree.c +++ b/log-tree.c @@ -139,9 +139,9 @@ void show_log(struct rev_info *opt, const char *sep) printf(" (from %s)", diff_unique_abbrev(parent->object.sha1, abbrev_commit)); - putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n'); printf("%s", diff_get_color(opt->diffopt.color_diff, DIFF_RESET)); + putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n'); } /* From 57c7d9a7756f9c0165d0aa003eb8a05c08cd9fae Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Tue, 25 Jul 2006 01:23:03 +0200 Subject: [PATCH 057/107] Trivial path optimization test Linus: get_pathspec() does turn '.' into an empty string (which is correct - git internally does _not_ ever understand the notion of "." as the current working directory), but it doesn't ever do the optimization of noticing that a pathspec that consists solely of an empty string is "equivalent" to an empty pathspec. The test is to ensure that this behaviour stays. Signed-off-by: Alex Riesen Signed-off-by: Junio C Hamano --- t/t6004-rev-list-path-optim.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 t/t6004-rev-list-path-optim.sh diff --git a/t/t6004-rev-list-path-optim.sh b/t/t6004-rev-list-path-optim.sh new file mode 100755 index 0000000000..5182dbb158 --- /dev/null +++ b/t/t6004-rev-list-path-optim.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +test_description='git-rev-list trivial path optimization test' + +. ./test-lib.sh + +test_expect_success setup ' +echo Hello > a && +git add a && +git commit -m "Initial commit" a +' + +test_expect_success path-optimization ' + commit=$(echo "Unchanged tree" | git-commit-tree "HEAD^{tree}" -p HEAD) && + test $(git-rev-list $commit | wc -l) = 2 && + test $(git-rev-list $commit -- . | wc -l) = 1 +' + +test_done From c6e1d9ed509265a66fe9d155b1a66aa954cce675 Mon Sep 17 00:00:00 2001 From: Luben Tuikov Date: Sun, 23 Jul 2006 13:26:30 -0700 Subject: [PATCH 058/107] gitweb.cgi: Teach git_history() to read hash from $hash_base Teach git_history() to take its hash argument from the hb parameter, i.e. from $hash_base. Also change all "a=history" actions to pass "hb=" instead of "h=". Signed-off-by: Luben Tuikov Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 2fd1e5f78e..d976d4adca 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -1687,7 +1687,7 @@ sub git_tree { "" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") . # " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") . - " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash_base;f=$base$t_name")}, "history") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;hb=$hash_base;f=$base$t_name")}, "history") . " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") . "\n"; } elsif ($t_type eq "tree") { @@ -1696,7 +1696,7 @@ sub git_tree { "\n" . "" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") . - " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash_base;f=$base$t_name")}, "history") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;hb=$hash_base;f=$base$t_name")}, "history") . "\n"; } print "\n"; @@ -2041,7 +2041,7 @@ sub git_commit { "[deleted " . file_type($from_mode). "]\n" . "" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") . - " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash;f=$file")}, "history") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;hb=$hash;f=$file")}, "history") . "\n" } elsif ($status eq "M" || $status eq "T") { my $mode_chnge = ""; @@ -2072,7 +2072,7 @@ sub git_commit { if ($to_id ne $from_id) { print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff"); } - print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash;f=$file")}, "history") . "\n"; + print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;hb=$hash;f=$file")}, "history") . "\n"; print "\n"; } elsif ($status eq "R") { my ($from_file, $to_file) = split "\t", $file; @@ -2293,10 +2293,10 @@ sub git_commitdiff_plain { } sub git_history { - if (!defined $hash) { - $hash = git_read_head($project); + if (!defined $hash_base) { + $hash_base = git_read_head($project); } - my %co = git_read_commit($hash); + my %co = git_read_commit($hash_base); if (!%co) { die_error(undef, "Unknown commit object."); } @@ -2306,18 +2306,18 @@ sub git_history { $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") . " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") . " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") . - " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") . - " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") . - " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "

\n" . "\n"; print "
\n" . - $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" . + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "\n" . "
\n"; print "
/" . esc_html($file_name) . "
\n"; open my $fd, "-|", - "$GIT rev-list --full-history $hash -- \'$file_name\'"; + "$GIT rev-list --full-history $hash_base -- \'$file_name\'"; print "\n"; my $alternate = 0; while (my $line = <$fd>) { @@ -2345,7 +2345,7 @@ sub git_history { $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") . " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") . " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;hb=$commit;f=$file_name")}, "blob"); - my $blob = git_get_hash_by_path($hash, $file_name); + my $blob = git_get_hash_by_path($hash_base, $file_name); my $blob_parent = git_get_hash_by_path($commit, $file_name); if (defined $blob && defined $blob_parent && $blob ne $blob_parent) { print " | " . From cff0771bfbc8a8c1a432a99bc297a52a5ba94304 Mon Sep 17 00:00:00 2001 From: Luben Tuikov Date: Sun, 23 Jul 2006 13:28:55 -0700 Subject: [PATCH 059/107] gitweb.cgi: Include direct link to "raw" files from "history" In "history" view, the "page_path" is now also a URL link to the "raw" format of the file, which will always give you the latest version in the repository. This is helpful for externally linking files, such that the latest version is always referenced and in "raw" format. Signed-off-by: Luben Tuikov Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index d976d4adca..7a61de4a77 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -1531,6 +1531,14 @@ sub git_blob_plain_mimetype { } sub git_blob_plain { + if (!defined $hash) { + if (defined $file_name) { + my $base = $hash_base || git_read_head($project); + $hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file."); + } else { + die_error(undef, "No file name defined."); + } + } my $type = shift; open my $fd, "-|", "$GIT cat-file blob $hash" or die_error("Couldn't cat $file_name, $hash"); @@ -1554,10 +1562,14 @@ sub git_blob_plain { } sub git_blob { - if (!defined $hash && defined $file_name) { - my $base = $hash_base || git_read_head($project); - $hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file."); - } + if (!defined $hash) { + if (defined $file_name) { + my $base = $hash_base || git_read_head($project); + $hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file."); + } else { + die_error(undef, "No file name defined."); + } + } my $have_blame = git_get_project_config_bool ('blame'); open my $fd, "-|", "$GIT cat-file blob $hash" or die_error(undef, "Open failed."); my $mimetype = git_blob_plain_mimetype($fd, $file_name); @@ -1687,7 +1699,7 @@ sub git_tree { "\n"; } elsif ($t_type eq "tree") { @@ -2314,7 +2326,18 @@ sub git_history { print "
\n" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "\n" . "
\n"; - print "
/" . esc_html($file_name) . "
\n"; + if (defined $hash) { + my $ftype = git_get_type($hash); + + if ($ftype =~ "blob") { + print "
/" . + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;f=$file_name")}, esc_html($file_name)) . "
\n"; + } else { + print "
/" . esc_html($file_name) . "
\n"; + } + } else { + print "
/" . esc_html($file_name) . "
\n"; + } open my $fd, "-|", "$GIT rev-list --full-history $hash_base -- \'$file_name\'"; From 1f2857ea32fa82ba6039b7fd298dc763b1e6c112 Mon Sep 17 00:00:00 2001 From: Luben Tuikov Date: Sun, 23 Jul 2006 13:34:55 -0700 Subject: [PATCH 060/107] gitweb.cgi: git_blame2: an alternative simple working git blame This patch adds an alternative simple working git-blame called git_blame2(). Simple, because it displays just three columns: the commit, the line number and the line of code. Alternative, because the original git_blame() is left untouched. Lines of code are printed html escaped, but as-is. git_blame2() uses git-blame as opposed to git-annotate used by git_blame(). Signed-off-by: Luben Tuikov Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 71 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 4106cb8eb6..57f4a2e263 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -227,7 +227,7 @@ if (!defined $action || $action eq "summary") { git_tag(); exit; } elsif ($action eq "blame") { - git_blame(); + git_blame2(); exit; } else { undef $action; @@ -1252,6 +1252,75 @@ sub git_tag { git_footer_html(); } +sub git_read_blame_line { + my %bl; + $_ = shift; + + ($bl{'hash'}, $bl{'lineno'}, $bl{'data'}) = /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/; + + return %bl; +} + +sub git_blame2 { + my $fd; + my $ftype; + die_error(undef, "Permission denied.") if (!git_get_project_config_bool ('blame')); + die_error('404 Not Found', "File name not defined") if (!$file_name); + $hash_base ||= git_read_head($project); + die_error(undef, "Reading commit failed") unless ($hash_base); + my %co = git_read_commit($hash_base) + or die_error(undef, "Reading commit failed"); + if (!defined $hash) { + $hash = git_get_hash_by_path($hash_base, $file_name, "blob") + or die_error(undef, "Error looking up file"); + } + $ftype = git_get_type($hash); + if ($ftype !~ "blob") { + die_error("400 Bad Request", "object is not a blob"); + } + open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base) + or die_error(undef, "Open failed"); + git_header_html(); + print "
\n" . + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "
\n"; + print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;f=$file_name")}, "head") . "
\n"; + print "
\n". + "
" . + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . + "
\n"; + git_print_page_path($file_name, $ftype); + + print "
\n"; + + print "
" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") . # " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") . - " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;hb=$hash_base;f=$base$t_name")}, "history") . + " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$t_hash;hb=$hash_base;f=$base$t_name")}, "history") . " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") . "
\n"; + print "\n"; + while (my $line = <$fd>) { + my %blame_line = git_read_blame_line($line); + my $full_rev = $blame_line{'hash'}; + my $rev = substr($full_rev, 0, 8); + my $lineno = $blame_line{'lineno'}; + my $data = $blame_line{'data'}; + + print "\n"; + print "\n"; + print "\n"; + print "\n"; + print "\n"; + } + print "
CommitLineData
" . + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$full_rev;f=$file_name")}, esc_html($rev)) . "" . esc_html($lineno) . "" . esc_html($data) . "
\n"; + print ""; + + close $fd or print "Reading blob failed\n"; + git_footer_html(); +} + sub git_blame { my $fd; die_error('403 Permission denied', "Permission denied.") if (!git_get_project_config_bool ('blame')); From 4f7b34c98f6f3853c6b82a85f3e49121c59180f7 Mon Sep 17 00:00:00 2001 From: Luben Tuikov Date: Sun, 23 Jul 2006 13:36:32 -0700 Subject: [PATCH 061/107] gitweb.cgi: git_blame2: Allow back-trekking through commits This patch adds the capability of back-trekking through commits from git_blame2() as follows: blame2->commit->blame2->commit->blame2->...->initial commit. Signed-off-by: Luben Tuikov Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 57f4a2e263..2c2d9c8d8f 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -2022,7 +2022,13 @@ sub git_commit { print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff"); } print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "\n" . - "

\n"; + "
\n"; + if (defined $file_name && defined $co{'parent'}) { + my $parent = $co{'parent'}; + print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;hb=$parent;f=$file_name")}, "blame") . "\n"; + } + print "
\n"; + if (defined $co{'parent'}) { print "
\n" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash"), -class => "title"}, esc_html($co{'title'}) . $ref) . "\n" . From 93d5f0619ccf10d7a16834b9e3be38871d2aae6c Mon Sep 17 00:00:00 2001 From: Luben Tuikov Date: Sun, 23 Jul 2006 13:30:08 -0700 Subject: [PATCH 062/107] gitweb.cgi: Show "raw" head of project link even when $hash is not defined Some callers of git_history() do not set $hash of $file_name. Add code to find it, if it is not defined. Signed-off-by: Luben Tuikov Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 7a61de4a77..c04283ba58 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -2326,6 +2326,9 @@ sub git_history { print "
\n" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "\n" . "
\n"; + if (!defined $hash && defined $file_name) { + $hash = git_get_hash_by_path($hash_base, $file_name); + } if (defined $hash) { my $ftype = git_get_type($hash); From cc1bf97e24129db2b8c4634bc733ae0a16b2beba Mon Sep 17 00:00:00 2001 From: Luben Tuikov Date: Sun, 23 Jul 2006 13:37:53 -0700 Subject: [PATCH 063/107] gitweb.cgi: git_blame2: Revision blocks now have alternating colors A revision block is the largest number of adjacent lines of code originating from the same revision. This patch adds color to git_blame2(), in that no two adjacent revision blocks have the same color. The color alternates between light and dark. As we annotate the code lines, we alternate the color (light, dark) of code lines _per revision_. This makes it easier to see line conglomerations per revision. Signed-off-by: Luben Tuikov Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 2c2d9c8d8f..16340f2106 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -1295,9 +1295,11 @@ sub git_blame2 { $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "
\n"; git_print_page_path($file_name, $ftype); - + my @rev_color = (qw(light dark)); + my $num_colors = scalar(@rev_color); + my $current_color = 0; + my $last_rev; print "
\n"; - print "\n"; print "\n"; while (my $line = <$fd>) { @@ -1307,7 +1309,13 @@ sub git_blame2 { my $lineno = $blame_line{'lineno'}; my $data = $blame_line{'data'}; - print "\n"; + if (!defined $last_rev) { + $last_rev = $full_rev; + } elsif ($last_rev ne $full_rev) { + $last_rev = $full_rev; + $current_color = ++$current_color % $num_colors; + } + print "\n"; print "\n"; print "\n"; @@ -1316,7 +1324,6 @@ sub git_blame2 { } print "
CommitLineData
" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$full_rev;f=$file_name")}, esc_html($rev)) . "" . esc_html($lineno) . "
\n"; print "
"; - close $fd or print "Reading blob failed\n"; git_footer_html(); } From 634331061599a82968daddae2d2c0896b6137d4c Mon Sep 17 00:00:00 2001 From: Luben Tuikov Date: Sun, 23 Jul 2006 13:31:15 -0700 Subject: [PATCH 064/107] gitweb.cgi: Centralize printing of the page path Centralize printing of the page path so that if the entity is a blob, we can set the page path to be the link to the HEAD revision of the "raw" blob. Signed-off-by: Luben Tuikov Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index c04283ba58..4106cb8eb6 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -1199,6 +1199,20 @@ sub git_summary { git_footer_html(); } +sub git_print_page_path { + my $name = shift; + my $type = shift; + + if (!defined $name) { + print "
/
\n"; + } elsif ($type =~ "blob") { + print "
" . + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;f=$file_name")}, esc_html($name)) . "
\n"; + } else { + print "
" . esc_html($name) . "
\n"; + } +} + sub git_tag { my $head = git_read_head($project); git_header_html(); @@ -1266,7 +1280,7 @@ sub git_blame { "
" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "
\n"; - print "
" . esc_html($file_name) . "
\n"; + git_print_page_path($file_name); print "
\n"; print < @@ -1604,9 +1618,7 @@ sub git_blob { "

\n" . "
$hash
\n"; } - if (defined $file_name) { - print "
" . esc_html($file_name) . "
\n"; - } + git_print_page_path($file_name, "blob"); print "
\n"; my $nr; while (my $line = <$fd>) { @@ -1671,10 +1683,8 @@ sub git_tree { } if (defined $file_name) { $base = esc_html("$file_name/"); - print "
/" . esc_html($file_name) . "
\n"; - } else { - print "
/
\n"; } + git_print_page_path($file_name); print "
\n"; print "\n"; my $alternate = 0; @@ -2132,9 +2142,7 @@ sub git_blobdiff { "

\n" . "
$hash vs $hash_parent
\n"; } - if (defined $file_name) { - print "
/" . esc_html($file_name) . "
\n"; - } + git_print_page_path($file_name, "blob"); print "
\n" . "
blob:" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) . @@ -2308,6 +2316,7 @@ sub git_history { if (!defined $hash_base) { $hash_base = git_read_head($project); } + my $ftype; my %co = git_read_commit($hash_base); if (!%co) { die_error(undef, "Unknown commit object."); @@ -2330,17 +2339,9 @@ sub git_history { $hash = git_get_hash_by_path($hash_base, $file_name); } if (defined $hash) { - my $ftype = git_get_type($hash); - - if ($ftype =~ "blob") { - print "
/" . - $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;f=$file_name")}, esc_html($file_name)) . "
\n"; - } else { - print "
/" . esc_html($file_name) . "
\n"; - } - } else { - print "
/" . esc_html($file_name) . "
\n"; + $ftype = git_get_type($hash); } + git_print_page_path($file_name, $ftype); open my $fd, "-|", "$GIT rev-list --full-history $hash_base -- \'$file_name\'"; From acb0f6f33760b43c1fc9617a45346ab3738f021a Mon Sep 17 00:00:00 2001 From: Luben Tuikov Date: Sun, 23 Jul 2006 14:17:48 -0700 Subject: [PATCH 065/107] gitweb.cgi: git_blame2: slight optimization reading the blame lines Eliminate git_read_blame_line() -- move that code inline and optimize it. Signed-off-by: Luben Tuikov Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 16340f2106..7fbfc0d226 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -1252,15 +1252,6 @@ sub git_tag { git_footer_html(); } -sub git_read_blame_line { - my %bl; - $_ = shift; - - ($bl{'hash'}, $bl{'lineno'}, $bl{'data'}) = /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/; - - return %bl; -} - sub git_blame2 { my $fd; my $ftype; @@ -1302,12 +1293,12 @@ sub git_blame2 { print "
\n"; print "
\n"; print "\n"; - while (my $line = <$fd>) { - my %blame_line = git_read_blame_line($line); - my $full_rev = $blame_line{'hash'}; + while (<$fd>) { + /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/; + my $full_rev = $1; my $rev = substr($full_rev, 0, 8); - my $lineno = $blame_line{'lineno'}; - my $data = $blame_line{'data'}; + my $lineno = $2; + my $data = $3; if (!defined $last_rev) { $last_rev = $full_rev; From 143c89b00348759d2768003d57e0f506d281dc61 Mon Sep 17 00:00:00 2001 From: Daniel Drake Date: Mon, 24 Jul 2006 23:07:23 +0100 Subject: [PATCH 066/107] gitweb: escape tag comments I have a tag with a comment which includes an & character. Firefox wouldn't display my gitweb summary page due to malformed XML. This solves the problem. Signed-off-by: Daniel Drake Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 2fd1e5f78e..5acd66dd6c 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -1138,7 +1138,7 @@ sub git_summary { "\n" . "\n" . "
CommitLineData
"; if (defined($comment)) { - print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment); + print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, esc_html($comment)); } print ""; From 28f7581806479471093b0ec021871a4343874d13 Mon Sep 17 00:00:00 2001 From: Peter Eriksen Date: Tue, 25 Jul 2006 09:30:18 +0200 Subject: [PATCH 067/107] Substitute xmalloc()+memset(0) with xcalloc(). Signed-off-by: Peter Eriksen Signed-off-by: Junio C Hamano --- builtin-add.c | 3 +-- builtin-rm.c | 3 +-- combine-diff.c | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/builtin-add.c b/builtin-add.c index 2d25698173..3a73a173f7 100644 --- a/builtin-add.c +++ b/builtin-add.c @@ -21,8 +21,7 @@ static void prune_directory(struct dir_struct *dir, const char **pathspec, int p for (specs = 0; pathspec[specs]; specs++) /* nothing */; - seen = xmalloc(specs); - memset(seen, 0, specs); + seen = xcalloc(specs, 1); src = dst = dir->entries; i = dir->nr; diff --git a/builtin-rm.c b/builtin-rm.c index 5deb811719..bb810ba41a 100644 --- a/builtin-rm.c +++ b/builtin-rm.c @@ -90,8 +90,7 @@ int cmd_rm(int argc, const char **argv, char **envp) seen = NULL; for (i = 0; pathspec[i] ; i++) /* nothing */; - seen = xmalloc(i); - memset(seen, 0, i); + seen = xcalloc(i, 1); for (i = 0; i < active_nr; i++) { struct cache_entry *ce = active_cache[i]; diff --git a/combine-diff.c b/combine-diff.c index 1bc1484645..919112bba9 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -639,8 +639,7 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent, /* deleted file */ result_size = 0; elem->mode = 0; - result = xmalloc(1); - result[0] = 0; + result = xcalloc(1, 1); } if (0 <= fd) close(fd); From 42217f13efcfd7901636877f020de246d6c58838 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 25 Jul 2006 12:48:52 +0200 Subject: [PATCH 068/107] cvsserver: suppress warnings This patch defines $state->{prependdir} as the empty string, so that quite a few warnings are avoided. Signed-off-by: Johannes Schindelin Acked-by: Martin Langhoff Signed-off-by: Junio C Hamano --- git-cvsserver.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-cvsserver.perl b/git-cvsserver.perl index c30ef70427..4bfca1f93c 100755 --- a/git-cvsserver.perl +++ b/git-cvsserver.perl @@ -81,7 +81,7 @@ my $methods = { # $state holds all the bits of information the clients sends us that could # potentially be useful when it comes to actually _doing_ something. -my $state = {}; +my $state = { prependdir => '' }; $log->info("--------------- STARTING -----------------"); my $TEMP_DIR = tempdir( CLEANUP => 1 ); From 96256bba949f43548a0be0af877680eb62b156f6 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 25 Jul 2006 13:57:57 +0200 Subject: [PATCH 069/107] cvsserver: avoid warning about active db handles Turns out that DBD::SQLite does not favour preparing statements which are never executed. So, turn all 4 statements, which were prepared _always_, into methods, like the other 12 prepared statements. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git-cvsserver.perl | 70 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 14 deletions(-) diff --git a/git-cvsserver.perl b/git-cvsserver.perl index 4bfca1f93c..0bbd871c14 100755 --- a/git-cvsserver.perl +++ b/git-cvsserver.perl @@ -2129,12 +2129,6 @@ sub update # first lets get the commit list $ENV{GIT_DIR} = $self->{git_path}; - # prepare database queries - my $db_insert_rev = $self->{dbh}->prepare_cached("INSERT INTO revision (name, revision, filehash, commithash, modified, author, mode) VALUES (?,?,?,?,?,?,?)",{},1); - my $db_insert_mergelog = $self->{dbh}->prepare_cached("INSERT INTO commitmsgs (key, value) VALUES (?,?)",{},1); - my $db_delete_head = $self->{dbh}->prepare_cached("DELETE FROM head",{},1); - my $db_insert_head = $self->{dbh}->prepare_cached("INSERT INTO head (name, revision, filehash, commithash, modified, author, mode) VALUES (?,?,?,?,?,?,?)",{},1); - my $commitinfo = `git-cat-file commit $self->{module} 2>&1`; unless ( $commitinfo =~ /tree\s+[a-zA-Z0-9]{40}/ ) { @@ -2323,7 +2317,7 @@ sub update author => $commit->{author}, mode => $git_perms, }; - $db_insert_rev->execute($4, $head->{$4}{revision}, $2, $commit->{hash}, $commit->{date}, $commit->{author}, $git_perms); + $self->insert_rev($4, $head->{$4}{revision}, $2, $commit->{hash}, $commit->{date}, $commit->{author}, $git_perms); } elsif ( $3 eq "M" ) { @@ -2337,7 +2331,7 @@ sub update author => $commit->{author}, mode => $git_perms, }; - $db_insert_rev->execute($4, $head->{$4}{revision}, $2, $commit->{hash}, $commit->{date}, $commit->{author}, $git_perms); + $self->insert_rev($4, $head->{$4}{revision}, $2, $commit->{hash}, $commit->{date}, $commit->{author}, $git_perms); } elsif ( $3 eq "A" ) { @@ -2351,7 +2345,7 @@ sub update author => $commit->{author}, mode => $git_perms, }; - $db_insert_rev->execute($4, $head->{$4}{revision}, $2, $commit->{hash}, $commit->{date}, $commit->{author}, $git_perms); + $self->insert_rev($4, $head->{$4}{revision}, $2, $commit->{hash}, $commit->{date}, $commit->{author}, $git_perms); } else { @@ -2408,7 +2402,7 @@ sub update }; - $db_insert_rev->execute($git_filename, $newrevision, $git_hash, $commit->{hash}, $commit->{date}, $commit->{author}, $git_perms); + $self->insert_rev($git_filename, $newrevision, $git_hash, $commit->{hash}, $commit->{date}, $commit->{author}, $git_perms); } } close FILELIST; @@ -2424,7 +2418,7 @@ sub update $head->{$file}{modified} = $commit->{date}; $head->{$file}{author} = $commit->{author}; - $db_insert_rev->execute($file, $head->{$file}{revision}, $head->{$file}{filehash}, $commit->{hash}, $commit->{date}, $commit->{author}, $head->{$file}{mode}); + $self->insert_rev($file, $head->{$file}{revision}, $head->{$file}{filehash}, $commit->{hash}, $commit->{date}, $commit->{author}, $head->{$file}{mode}); } } # END : "Detect deleted files" @@ -2433,7 +2427,7 @@ sub update if (exists $commit->{mergemsg}) { - $db_insert_mergelog->execute($commit->{hash}, $commit->{mergemsg}); + $self->insert_mergelog($commit->{hash}, $commit->{mergemsg}); } $lastpicked = $commit->{hash}; @@ -2441,10 +2435,10 @@ sub update $self->_set_prop("last_commit", $commit->{hash}); } - $db_delete_head->execute(); + $self->delete_head(); foreach my $file ( keys %$head ) { - $db_insert_head->execute( + $self->insert_head( $file, $head->{$file}{revision}, $head->{$file}{filehash}, @@ -2462,6 +2456,54 @@ sub update $self->{dbh}->commit() or die "Failed to commit changes to SQLite"; } +sub insert_rev +{ + my $self = shift; + my $name = shift; + my $revision = shift; + my $filehash = shift; + my $commithash = shift; + my $modified = shift; + my $author = shift; + my $mode = shift; + + my $insert_rev = $self->{dbh}->prepare_cached("INSERT INTO revision (name, revision, filehash, commithash, modified, author, mode) VALUES (?,?,?,?,?,?,?)",{},1); + $insert_rev->execute($name, $revision, $filehash, $commithash, $modified, $author, $mode); +} + +sub insert_mergelog +{ + my $self = shift; + my $key = shift; + my $value = shift; + + my $insert_mergelog = $self->{dbh}->prepare_cached("INSERT INTO commitmsgs (key, value) VALUES (?,?)",{},1); + $insert_mergelog->execute($key, $value); +} + +sub delete_head +{ + my $self = shift; + + my $delete_head = $self->{dbh}->prepare_cached("DELETE FROM head",{},1); + $delete_head->execute(); +} + +sub insert_head +{ + my $self = shift; + my $name = shift; + my $revision = shift; + my $filehash = shift; + my $commithash = shift; + my $modified = shift; + my $author = shift; + my $mode = shift; + + my $insert_head = $self->{dbh}->prepare_cached("INSERT INTO head (name, revision, filehash, commithash, modified, author, mode) VALUES (?,?,?,?,?,?,?)",{},1); + $insert_head->execute($name, $revision, $filehash, $commithash, $modified, $author, $mode); +} + sub _headrev { my $self = shift; From 4ab243a944a6013d9e862adadd6fe6152c842401 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 24 Jul 2006 14:10:45 +0200 Subject: [PATCH 070/107] Allow an alias to start with "-p" Now, something like [alias] pd = -p diff works as expected. [jc: a follow-up fix from Jeff King folded in.] Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/git.c b/git.c index ee5a0e86a7..c0bd19d0ef 100644 --- a/git.c +++ b/git.c @@ -35,6 +35,27 @@ static void prepend_to_path(const char *dir, int len) setenv("PATH", path, 1); } +static int handle_options(const char*** argv, int* argc) +{ + int handled = 0; + + while (*argc > 0) { + const char *cmd = (*argv)[0]; + if (cmd[0] != '-') + break; + + if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) { + setup_pager(); + } else + die ("Unknown option: %s", cmd); + + (*argv)++; + (*argc)--; + handled++; + } + return handled; +} + static const char *alias_command; static char *alias_string = NULL; @@ -106,7 +127,7 @@ static int handle_alias(int *argcp, const char ***argv) subdir = setup_git_directory_gently(&nongit); if (!nongit) { - int count; + int count, option_count; const char** new_argv; alias_command = (*argv)[0]; @@ -114,6 +135,10 @@ static int handle_alias(int *argcp, const char ***argv) if (alias_string) { count = split_cmdline(alias_string, &new_argv); + option_count = handle_options(&new_argv, &count); + memmove(new_argv - option_count, new_argv, + count * sizeof(char *)); + new_argv -= option_count; if (count < 1) die("empty alias for %s", alias_command); @@ -273,13 +298,12 @@ int main(int argc, const char **argv, char **envp) /* Look for flags.. */ while (argc > 1) { - cmd = *++argv; + argv++; argc--; - if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) { - setup_pager(); - continue; - } + handle_options(&argv, &argc); + + cmd = *argv; if (strncmp(cmd, "--", 2)) break; From 6acbcb927f8e34857fa8f68fcb4f9076941b24ff Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 25 Jul 2006 20:24:22 +0200 Subject: [PATCH 071/107] git wrapper: add --git-dir= and --bare options With this, you can say git --bare repack -a -d inside a bare repository, and it will actually work. While at it, also move the --version, --help and --exec-path options to the handle_options() function. While at documenting the new options, also document the --paginate option. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- Documentation/git.txt | 12 +++++- builtin-help.c | 2 +- git.c | 91 ++++++++++++++++++++++--------------------- 3 files changed, 58 insertions(+), 47 deletions(-) diff --git a/Documentation/git.txt b/Documentation/git.txt index ce3058182f..7310a2b8b8 100644 --- a/Documentation/git.txt +++ b/Documentation/git.txt @@ -8,7 +8,8 @@ git - the stupid content tracker SYNOPSIS -------- -'git' [--version] [--exec-path[=GIT_EXEC_PATH]] [--help] COMMAND [ARGS] +'git' [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate] + [--bare] [--git-dir=GIT_DIR] [--help] COMMAND [ARGS] DESCRIPTION ----------- @@ -41,6 +42,15 @@ OPTIONS environment variable. If no path is given 'git' will print the current setting and then exit. +-p|--paginate:: + Pipe all output into 'less' (or if set, $PAGER). + +--git-dir=:: + Set the path to the repository. This can also be controlled by + setting the GIT_DIR environment variable. + +--bare:: + Same as --git-dir=`pwd`. FURTHER DOCUMENTATION --------------------- diff --git a/builtin-help.c b/builtin-help.c index 335fe5fedc..bc1b4da3bc 100644 --- a/builtin-help.c +++ b/builtin-help.c @@ -229,7 +229,7 @@ int cmd_version(int argc, const char **argv, char **envp) int cmd_help(int argc, const char **argv, char **envp) { - const char *help_cmd = argv[1]; + const char *help_cmd = argc > 1 ? argv[1] : NULL; if (!help_cmd) cmd_usage(0, git_exec_path(), NULL); else if (!strcmp(help_cmd, "--all") || !strcmp(help_cmd, "-a")) diff --git a/git.c b/git.c index c0bd19d0ef..885e1ce75b 100644 --- a/git.c +++ b/git.c @@ -44,10 +44,42 @@ static int handle_options(const char*** argv, int* argc) if (cmd[0] != '-') break; - if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) { + /* + * For legacy reasons, the "version" and "help" + * commands can be written with "--" prepended + * to make them look like flags. + */ + if (!strcmp(cmd, "--help") || !strcmp(cmd, "--version")) + break; + + /* + * Check remaining flags. + */ + if (!strncmp(cmd, "--exec-path", 11)) { + cmd += 11; + if (*cmd == '=') + git_set_exec_path(cmd + 1); + else { + puts(git_exec_path()); + exit(0); + } + } else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) { setup_pager(); - } else - die ("Unknown option: %s", cmd); + } else if (!strcmp(cmd, "--git-dir")) { + if (*argc < 1) + return -1; + setenv("GIT_DIR", (*argv)[1], 1); + (*argv)++; + (*argc)--; + } else if (!strncmp(cmd, "--git-dir=", 10)) { + setenv("GIT_DIR", cmd + 10, 1); + } else if (!strcmp(cmd, "--bare")) { + static char git_dir[1024]; + setenv("GIT_DIR", getcwd(git_dir, 1024), 1); + } else { + fprintf(stderr, "Unknown option: %s\n", cmd); + cmd_usage(0, NULL, NULL); + } (*argv)++; (*argc)--; @@ -293,50 +325,19 @@ int main(int argc, const char **argv, char **envp) die("cannot handle %s internally", cmd); } - /* Default command: "help" */ - cmd = "help"; - /* Look for flags.. */ - while (argc > 1) { - argv++; - argc--; - - handle_options(&argv, &argc); - - cmd = *argv; - - if (strncmp(cmd, "--", 2)) - break; - - cmd += 2; - - /* - * For legacy reasons, the "version" and "help" - * commands can be written with "--" prepended - * to make them look like flags. - */ - if (!strcmp(cmd, "help")) - break; - if (!strcmp(cmd, "version")) - break; - - /* - * Check remaining flags (which by now must be - * "--exec-path", but maybe we will accept - * other arguments some day) - */ - if (!strncmp(cmd, "exec-path", 9)) { - cmd += 9; - if (*cmd == '=') { - git_set_exec_path(cmd + 1); - continue; - } - puts(git_exec_path()); - exit(0); - } - cmd_usage(0, NULL, NULL); + argv++; + argc--; + handle_options(&argv, &argc); + if (argc > 0) { + if (!strncmp(argv[0], "--", 2)) + argv[0] += 2; + } else { + /* Default command: "help" */ + argv[0] = "help"; + argc = 1; } - argv[0] = cmd; + cmd = argv[0]; /* * We search for git commands in the following order: From afd222967c6abedcf75e28fe0e57cd5644f6c865 Mon Sep 17 00:00:00 2001 From: Josef Weidendorfer Date: Wed, 26 Jul 2006 15:44:08 +0200 Subject: [PATCH 072/107] Extend testing git-mv for renaming of subdirectories Signed-off-by: Josef Weidendorfer Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 811a4797a5..d78c56a2eb 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -38,4 +38,25 @@ test_expect_success \ 'git-diff-tree -r -M --name-status HEAD^ HEAD | \ grep -E "^R100.+path1/COPYING.+path0/COPYING"' +test_expect_success \ + 'adding another file' \ + 'cp ../../README path0/README && + git-add path0/README && + git-commit -m add2 -a' + +test_expect_success \ + 'moving whole subdirectory' \ + 'git-mv path0 path2' + +test_expect_success \ + 'commiting the change' \ + 'git-commit -m dir-move -a' + +test_expect_success \ + 'checking the commit' \ + 'git-diff-tree -r -M --name-status HEAD^ HEAD | \ + grep -E "^R100.+path0/COPYING.+path2/COPYING" && + git-diff-tree -r -M --name-status HEAD^ HEAD | \ + grep -E "^R100.+path0/README.+path2/README"' + test_done From b7a036bb5f19d3b44443dcc319321663910250e8 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 26 Jul 2006 11:01:07 -0700 Subject: [PATCH 073/107] t4112: simplify the test and remove unneeded working tree file. Signed-off-by: Junio C Hamano --- t/t4112-apply-renames.sh | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/t/t4112-apply-renames.sh b/t/t4112-apply-renames.sh index a06f6956d5..69e9603c78 100755 --- a/t/t4112-apply-renames.sh +++ b/t/t4112-apply-renames.sh @@ -11,31 +11,7 @@ test_description='git-apply should not get confused with rename/copy. # setup -mkdir -p include/arch/x86_64/klibc klibc/arch/x86_64/include/klibc - -cat >include/arch/x86_64/klibc/archsetjmp.h <<\EOF -/* - * arch/x86_64/include/klibc/archsetjmp.h - */ - -#ifndef _KLIBC_ARCHSETJMP_H -#define _KLIBC_ARCHSETJMP_H - -struct __jmp_buf { - unsigned long __rbx; - unsigned long __rsp; - unsigned long __rbp; - unsigned long __r12; - unsigned long __r13; - unsigned long __r14; - unsigned long __r15; - unsigned long __rip; -}; - -typedef struct __jmp_buf jmp_buf[1]; - -#endif /* _SETJMP_H */ -EOF +mkdir -p klibc/arch/x86_64/include/klibc cat >klibc/arch/x86_64/include/klibc/archsetjmp.h <<\EOF /* @@ -139,7 +115,7 @@ rename to include/arch/m32r/klibc/archsetjmp.h +#endif /* _KLIBC_ARCHSETJMP_H */ EOF -find include klibc -type f -print | xargs git-update-index --add -- +find klibc -type f -print | xargs git-update-index --add -- test_expect_success 'check rename/copy patch' 'git-apply --check patch' From 2b5d2d8792c861913d48bcfe02d8a6049c3911f5 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 26 Jul 2006 16:33:18 +0200 Subject: [PATCH 074/107] git-instaweb: some Apache have mod_cgi builtin So test for it, and do not always try to load mod_cgi.o. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git-instaweb.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/git-instaweb.sh b/git-instaweb.sh index 63b18b99f6..9829c59154 100755 --- a/git-instaweb.sh +++ b/git-instaweb.sh @@ -183,8 +183,10 @@ PerlPassEnv GIT_EXEC_DIR EOF else # plain-old CGI + list_mods=`echo "$httpd" | sed "s/-f$/-l/"` + $list_mods | grep 'mod_cgi\.c' >/dev/null || \ + echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf" cat >> "$conf" < Options +ExecCGI From 941ba215fb9fc9e08705e86ea93e0f6f74d0faaf Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 26 Jul 2006 16:32:51 +0200 Subject: [PATCH 075/107] git-instaweb: respect bindir from Makefile Not everybody installs git to /usr/bin/git. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3e085dfa6f..691e40b7b2 100644 --- a/Makefile +++ b/Makefile @@ -575,7 +575,7 @@ git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css -e '/@@GITWEB_CGI@@/d' \ -e '/@@GITWEB_CSS@@/r gitweb/gitweb.css' \ -e '/@@GITWEB_CSS@@/d' \ - $@.sh > $@+ + $@.sh | sed "s|/usr/bin/git|$(bindir)/git|" > $@+ chmod +x $@+ mv $@+ $@ From 4325b4ad16821e936cb619f5e25d273c281bdeeb Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 26 Jul 2006 16:58:35 +0200 Subject: [PATCH 076/107] gitweb: fix two warnings These warnings cluttered up my log. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- gitweb/gitweb.cgi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 5acd66dd6c..30cb624b2a 100755 --- a/gitweb/gitweb.cgi +++ b/gitweb/gitweb.cgi @@ -795,7 +795,7 @@ sub git_read_projects { if (-d $projects_list) { # search in directory my $dir = $projects_list; - opendir my $dh, $dir or return undef; + opendir my ($dh), $dir or return undef; while (my $dir = readdir($dh)) { if (-e "$projectroot/$dir/HEAD") { my $pr = { @@ -810,7 +810,7 @@ sub git_read_projects { # 'git%2Fgit.git Linus+Torvalds' # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin' # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman' - open my $fd , $projects_list or return undef; + open my ($fd), $projects_list or return undef; while (my $line = <$fd>) { chomp $line; my ($path, $owner) = split ' ', $line; From a1dad607fa5227c844c0f8ab180b811d23792c02 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 26 Jul 2006 19:41:05 +0200 Subject: [PATCH 077/107] t7001: add test for git-mv dir1 dir2/ If dir2 already exists, git-mv should move dir1 _into_dir2/. Noticed by Jon Smirl. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- t/t7001-mv.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index d78c56a2eb..322eaadc73 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -59,4 +59,19 @@ test_expect_success \ git-diff-tree -r -M --name-status HEAD^ HEAD | \ grep -E "^R100.+path0/README.+path2/README"' +test_expect_success \ + 'moving whole subdirectory into subdirectory' \ + 'git-mv path2 path1' + +test_expect_success \ + 'commiting the change' \ + 'git-commit -m dir-move -a' + +test_expect_success \ + 'checking the commit' \ + 'git-diff-tree -r -M --name-status HEAD^ HEAD | \ + grep -E "^R100.+path2/COPYING.+path1/path2/COPYING" && + git-diff-tree -r -M --name-status HEAD^ HEAD | \ + grep -E "^R100.+path2/README.+path1/path2/README"' + test_done From 2c3cff49301c44767c72391cb5288aa0d10563a9 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 26 Jul 2006 21:59:08 +0200 Subject: [PATCH 078/107] git-cvsserver: support multiline commit messages Earlier, cvsserver barfed when you tried to check in files with a multiline commit message. That is what Argumentx is for... Argument: lines can be followed by several Argumentx: lines, which means they should be appended. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git-cvsserver.perl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/git-cvsserver.perl b/git-cvsserver.perl index 0bbd871c14..5b73837bb1 100755 --- a/git-cvsserver.perl +++ b/git-cvsserver.perl @@ -547,12 +547,15 @@ sub req_Argument { my ( $cmd, $data ) = @_; - # TODO : Not quite sure how Argument and Argumentx differ, but I assume - # it's for multi-line arguments ... somehow ... + # Argumentx means: append to last Argument (with a newline in front) $log->debug("$cmd : $data"); - push @{$state->{arguments}}, $data; + if ( $cmd eq 'Argumentx') { + ${$state->{arguments}}[$#{$state->{arguments}}] .= "\n" . $data; + } else { + push @{$state->{arguments}}, $data; + } } # expand-modules \n From 8fd2cb4069178539d8cf7711586d4e6378722bf3 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 25 Jul 2006 21:32:18 -0700 Subject: [PATCH 079/107] Extract helper bits from c-merge-recursive work This backports the pieces that are not uncooked from the merge-recursive WIP we have seen earlier, to be used in git-mv rewritten in C. Signed-off-by: Junio C Hamano --- cache.h | 3 ++ path-list.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++ path-list.h | 22 +++++++++++ read-cache.c | 87 +++++++++++++++++++++--------------------- 4 files changed, 172 insertions(+), 45 deletions(-) create mode 100644 path-list.c create mode 100644 path-list.h diff --git a/cache.h b/cache.h index eee5fc9f8d..d0b1f2730f 100644 --- a/cache.h +++ b/cache.h @@ -115,6 +115,7 @@ static inline unsigned int create_ce_mode(unsigned int mode) extern struct cache_entry **active_cache; extern unsigned int active_nr, active_alloc, active_cache_changed; extern struct cache_tree *active_cache_tree; +extern int cache_errno; #define GIT_DIR_ENVIRONMENT "GIT_DIR" #define DEFAULT_GIT_DIR_ENVIRONMENT ".git" @@ -142,6 +143,7 @@ extern void verify_non_filename(const char *prefix, const char *name); /* Initialize and use the cache information */ extern int read_cache(void); +extern int read_cache_from(const char *path); extern int write_cache(int newfd, struct cache_entry **cache, int entries); extern int verify_path(const char *path); extern int cache_name_pos(const char *name, int namelen); @@ -149,6 +151,7 @@ extern int cache_name_pos(const char *name, int namelen); #define ADD_CACHE_OK_TO_REPLACE 2 /* Ok to replace file/directory */ #define ADD_CACHE_SKIP_DFCHECK 4 /* Ok to skip DF conflict checks */ extern int add_cache_entry(struct cache_entry *ce, int option); +extern struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really); extern int remove_cache_entry_at(int pos); extern int remove_file_from_cache(const char *path); extern int ce_same_name(struct cache_entry *a, struct cache_entry *b); diff --git a/path-list.c b/path-list.c new file mode 100644 index 0000000000..f15a10de37 --- /dev/null +++ b/path-list.c @@ -0,0 +1,105 @@ +#include +#include "cache.h" +#include "path-list.h" + +/* if there is no exact match, point to the index where the entry could be + * inserted */ +static int get_entry_index(const struct path_list *list, const char *path, + int *exact_match) +{ + int left = -1, right = list->nr; + + while (left + 1 < right) { + int middle = (left + right) / 2; + int compare = strcmp(path, list->items[middle].path); + if (compare < 0) + right = middle; + else if (compare > 0) + left = middle; + else { + *exact_match = 1; + return middle; + } + } + + *exact_match = 0; + return right; +} + +/* returns -1-index if already exists */ +static int add_entry(struct path_list *list, const char *path) +{ + int exact_match; + int index = get_entry_index(list, path, &exact_match); + + if (exact_match) + return -1 - index; + + if (list->nr + 1 >= list->alloc) { + list->alloc += 32; + list->items = xrealloc(list->items, list->alloc + * sizeof(struct path_list_item)); + } + if (index < list->nr) + memmove(list->items + index + 1, list->items + index, + (list->nr - index) + * sizeof(struct path_list_item)); + list->items[index].path = list->strdup_paths ? + strdup(path) : (char *)path; + list->items[index].util = NULL; + list->nr++; + + return index; +} + +struct path_list_item *path_list_insert(const char *path, struct path_list *list) +{ + int index = add_entry(list, path); + + if (index < 0) + index = 1 - index; + + return list->items + index; +} + +int path_list_has_path(const struct path_list *list, const char *path) +{ + int exact_match; + get_entry_index(list, path, &exact_match); + return exact_match; +} + +struct path_list_item *path_list_lookup(const char *path, struct path_list *list) +{ + int exact_match, i = get_entry_index(list, path, &exact_match); + if (!exact_match) + return NULL; + return list->items + i; +} + +void path_list_clear(struct path_list *list, int free_items) +{ + if (list->items) { + int i; + if (free_items) + for (i = 0; i < list->nr; i++) { + if (list->strdup_paths) + free(list->items[i].path); + if (list->items[i].util) + free(list->items[i].util); + } + free(list->items); + } + list->items = NULL; + list->nr = list->alloc = 0; +} + +void print_path_list(const char *text, const struct path_list *p) +{ + int i; + if ( text ) + printf("%s\n", text); + for (i = 0; i < p->nr; i++) + printf("%s:%p\n", p->items[i].path, p->items[i].util); +} + diff --git a/path-list.h b/path-list.h new file mode 100644 index 0000000000..d6401eaa35 --- /dev/null +++ b/path-list.h @@ -0,0 +1,22 @@ +#ifndef _PATH_LIST_H_ +#define _PATH_LIST_H_ + +struct path_list_item { + char *path; + void *util; +}; +struct path_list +{ + struct path_list_item *items; + unsigned int nr, alloc; + unsigned int strdup_paths:1; +}; + +void print_path_list(const char *text, const struct path_list *p); + +int path_list_has_path(const struct path_list *list, const char *path); +void path_list_clear(struct path_list *list, int free_items); +struct path_list_item *path_list_insert(const char *path, struct path_list *list); +struct path_list_item *path_list_lookup(const char *path, struct path_list *list); + +#endif /* _PATH_LIST_H_ */ diff --git a/read-cache.c b/read-cache.c index a50d3612c8..4c47a0eb9f 100644 --- a/read-cache.c +++ b/read-cache.c @@ -24,6 +24,11 @@ unsigned int active_nr = 0, active_alloc = 0, active_cache_changed = 0; struct cache_tree *active_cache_tree = NULL; +int cache_errno = 0; + +static void *cache_mmap = NULL; +static size_t cache_mmap_size = 0; + /* * This only updates the "non-critical" parts of the directory * cache, ie the parts that aren't tracked by GIT, and only used @@ -577,22 +582,6 @@ int add_cache_entry(struct cache_entry *ce, int option) return 0; } -/* Three functions to allow overloaded pointer return; see linux/err.h */ -static inline void *ERR_PTR(long error) -{ - return (void *) error; -} - -static inline long PTR_ERR(const void *ptr) -{ - return (long) ptr; -} - -static inline long IS_ERR(const void *ptr) -{ - return (unsigned long)ptr > (unsigned long)-1000L; -} - /* * "refresh" does not calculate a new sha1 file or bring the * cache up-to-date for mode/content changes. But what it @@ -604,14 +593,16 @@ static inline long IS_ERR(const void *ptr) * For example, you'd want to do this after doing a "git-read-tree", * to link up the stat cache details with the proper files. */ -static struct cache_entry *refresh_entry(struct cache_entry *ce, int really) +struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really) { struct stat st; struct cache_entry *updated; int changed, size; - if (lstat(ce->name, &st) < 0) - return ERR_PTR(-errno); + if (lstat(ce->name, &st) < 0) { + cache_errno = errno; + return NULL; + } changed = ce_match_stat(ce, &st, really); if (!changed) { @@ -619,11 +610,13 @@ static struct cache_entry *refresh_entry(struct cache_entry *ce, int really) !(ce->ce_flags & htons(CE_VALID))) ; /* mark this one VALID again */ else - return NULL; + return ce; } - if (ce_modified(ce, &st, really)) - return ERR_PTR(-EINVAL); + if (ce_modified(ce, &st, really)) { + cache_errno = EINVAL; + return NULL; + } size = ce_size(ce); updated = xmalloc(size); @@ -666,13 +659,13 @@ int refresh_cache(unsigned int flags) continue; } - new = refresh_entry(ce, really); - if (!new) + new = refresh_cache_entry(ce, really); + if (new == ce) continue; - if (IS_ERR(new)) { - if (not_new && PTR_ERR(new) == -ENOENT) + if (!new) { + if (not_new && cache_errno == ENOENT) continue; - if (really && PTR_ERR(new) == -EINVAL) { + if (really && cache_errno == EINVAL) { /* If we are doing --really-refresh that * means the index is not valid anymore. */ @@ -728,40 +721,44 @@ static int read_index_extension(const char *ext, void *data, unsigned long sz) } int read_cache(void) +{ + return read_cache_from(get_index_file()); +} + +/* remember to discard_cache() before reading a different cache! */ +int read_cache_from(const char *path) { int fd, i; struct stat st; - unsigned long size, offset; - void *map; + unsigned long offset; struct cache_header *hdr; errno = EBUSY; - if (active_cache) + if (cache_mmap) return active_nr; errno = ENOENT; index_file_timestamp = 0; - fd = open(get_index_file(), O_RDONLY); + fd = open(path, O_RDONLY); if (fd < 0) { if (errno == ENOENT) return 0; die("index file open failed (%s)", strerror(errno)); } - size = 0; /* avoid gcc warning */ - map = MAP_FAILED; + cache_mmap = MAP_FAILED; if (!fstat(fd, &st)) { - size = st.st_size; + cache_mmap_size = st.st_size; errno = EINVAL; - if (size >= sizeof(struct cache_header) + 20) - map = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); + if (cache_mmap_size >= sizeof(struct cache_header) + 20) + cache_mmap = mmap(NULL, cache_mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); } close(fd); - if (map == MAP_FAILED) + if (cache_mmap == MAP_FAILED) die("index file mmap failed (%s)", strerror(errno)); - hdr = map; - if (verify_hdr(hdr, size) < 0) + hdr = cache_mmap; + if (verify_hdr(hdr, cache_mmap_size) < 0) goto unmap; active_nr = ntohl(hdr->hdr_entries); @@ -770,12 +767,12 @@ int read_cache(void) offset = sizeof(*hdr); for (i = 0; i < active_nr; i++) { - struct cache_entry *ce = (struct cache_entry *) ((char *) map + offset); + struct cache_entry *ce = (struct cache_entry *) ((char *) cache_mmap + offset); offset = offset + ce_size(ce); active_cache[i] = ce; } index_file_timestamp = st.st_mtime; - while (offset <= size - 20 - 8) { + while (offset <= cache_mmap_size - 20 - 8) { /* After an array of active_nr index entries, * there can be arbitrary number of extended * sections, each of which is prefixed with @@ -783,10 +780,10 @@ int read_cache(void) * in 4-byte network byte order. */ unsigned long extsize; - memcpy(&extsize, (char *) map + offset + 4, 4); + memcpy(&extsize, (char *) cache_mmap + offset + 4, 4); extsize = ntohl(extsize); - if (read_index_extension(((const char *) map) + offset, - (char *) map + offset + 8, + if (read_index_extension(((const char *) cache_mmap) + offset, + (char *) cache_mmap + offset + 8, extsize) < 0) goto unmap; offset += 8; @@ -795,7 +792,7 @@ int read_cache(void) return active_nr; unmap: - munmap(map, size); + munmap(cache_mmap, cache_mmap_size); errno = EINVAL; die("index file corrupt"); } From 11be42a47632a6f7219d34f5e312aa20ae076142 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 26 Jul 2006 03:52:35 +0200 Subject: [PATCH 080/107] Make git-mv a builtin This also moves add_file_to_index() to read-cache.c. Oh, and while touching builtin-add.c, it also removes a duplicate git_config() call. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- Makefile | 11 ++- builtin-add.c | 40 -------- builtin-mv.c | 221 ++++++++++++++++++++++++++++++++++++++++++++ builtin.h | 1 + cache.h | 1 + git-mv.perl | 250 -------------------------------------------------- git.c | 1 + read-cache.c | 39 ++++++++ 8 files changed, 269 insertions(+), 295 deletions(-) create mode 100644 builtin-mv.c delete mode 100755 git-mv.perl diff --git a/Makefile b/Makefile index 49eaa10b3b..73733e9025 100644 --- a/Makefile +++ b/Makefile @@ -151,7 +151,7 @@ SCRIPT_PERL = \ git-archimport.perl git-cvsimport.perl git-relink.perl \ git-shortlog.perl git-rerere.perl \ git-annotate.perl git-cvsserver.perl \ - git-svnimport.perl git-mv.perl git-cvsexportcommit.perl \ + git-svnimport.perl git-cvsexportcommit.perl \ git-send-email.perl git-svn.perl SCRIPT_PYTHON = \ @@ -192,7 +192,7 @@ BUILT_INS = git-log$X git-whatchanged$X git-show$X git-update-ref$X \ git-read-tree$X git-commit-tree$X git-write-tree$X \ git-apply$X git-show-branch$X git-diff-files$X git-update-index$X \ git-diff-index$X git-diff-stages$X git-diff-tree$X git-cat-file$X \ - git-fmt-merge-msg$X git-prune$X + git-fmt-merge-msg$X git-prune$X git-mv$X # what 'all' will build and 'install' will install, in gitexecdir ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS) @@ -221,7 +221,7 @@ LIB_H = \ blob.h cache.h commit.h csum-file.h delta.h \ diff.h object.h pack.h pkt-line.h quote.h refs.h \ run-command.h strbuf.h tag.h tree.h git-compat-util.h revision.h \ - tree-walk.h log-tree.h dir.h + tree-walk.h log-tree.h dir.h path-list.h DIFF_OBJS = \ diff.o diff-lib.o diffcore-break.o diffcore-order.o \ @@ -236,7 +236,7 @@ LIB_OBJS = \ server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \ tag.o tree.o usage.o config.o environment.o ctype.o copy.o \ fetch-clone.o revision.o pager.o tree-walk.o xdiff-interface.o \ - alloc.o merge-file.o $(DIFF_OBJS) + alloc.o merge-file.o path-list.o $(DIFF_OBJS) BUILTIN_OBJS = \ builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \ @@ -248,7 +248,8 @@ BUILTIN_OBJS = \ builtin-apply.o builtin-show-branch.o builtin-diff-files.o \ builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o \ builtin-cat-file.o builtin-mailsplit.o builtin-stripspace.o \ - builtin-update-ref.o builtin-fmt-merge-msg.o builtin-prune.o + builtin-update-ref.o builtin-fmt-merge-msg.o builtin-prune.o \ + builtin-mv.o GITLIBS = $(LIB_FILE) $(XDIFF_LIB) LIBS = $(GITLIBS) -lz diff --git a/builtin-add.c b/builtin-add.c index 3a73a173f7..72d2853176 100644 --- a/builtin-add.c +++ b/builtin-add.c @@ -82,45 +82,6 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec) prune_directory(dir, pathspec, baselen); } -static int add_file_to_index(const char *path, int verbose) -{ - int size, namelen; - struct stat st; - struct cache_entry *ce; - - if (lstat(path, &st)) - die("%s: unable to stat (%s)", path, strerror(errno)); - - if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode)) - die("%s: can only add regular files or symbolic links", path); - - namelen = strlen(path); - size = cache_entry_size(namelen); - ce = xcalloc(1, size); - memcpy(ce->name, path, namelen); - ce->ce_flags = htons(namelen); - fill_stat_cache_info(ce, &st); - - ce->ce_mode = create_ce_mode(st.st_mode); - if (!trust_executable_bit) { - /* If there is an existing entry, pick the mode bits - * from it. - */ - int pos = cache_name_pos(path, namelen); - if (pos >= 0) - ce->ce_mode = active_cache[pos]->ce_mode; - } - - if (index_path(ce->sha1, path, &st, 1)) - die("unable to index file %s", path); - if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD)) - die("unable to add %s to index",path); - if (verbose) - printf("add '%s'\n", path); - cache_tree_invalidate_path(active_cache_tree, path); - return 0; -} - static struct lock_file lock_file; int cmd_add(int argc, const char **argv, char **envp) @@ -159,7 +120,6 @@ int cmd_add(int argc, const char **argv, char **envp) } die(builtin_add_usage); } - git_config(git_default_config); pathspec = get_pathspec(prefix, argv + i); fill_directory(&dir, pathspec); diff --git a/builtin-mv.c b/builtin-mv.c new file mode 100644 index 0000000000..593ff9e434 --- /dev/null +++ b/builtin-mv.c @@ -0,0 +1,221 @@ +/* + * "git mv" builtin command + * + * Copyright (C) 2006 Johannes Schindelin + */ +#include + +#include "cache.h" +#include "builtin.h" +#include "dir.h" +#include "cache-tree.h" +#include "path-list.h" + +static const char builtin_mv_usage[] = +"git-mv [-n] [-f] ( | [-k] ... )"; + +static const char **copy_pathspec(const char *prefix, const char **pathspec, + int count, int base_name) +{ + const char **result = xmalloc((count + 1) * sizeof(const char *)); + memcpy(result, pathspec, count * sizeof(const char *)); + result[count] = NULL; + if (base_name) { + int i; + for (i = 0; i < count; i++) { + const char *last_slash = strrchr(result[i], '/'); + if (last_slash) + result[i] = last_slash + 1; + } + } + return get_pathspec(prefix, result); +} + +static void show_list(const char *label, struct path_list *list) +{ + if (list->nr > 0) { + int i; + printf("%s", label); + for (i = 0; i < list->nr; i++) + printf("%s%s", i > 0 ? ", " : "", list->items[i].path); + putchar('\n'); + } +} + +static struct lock_file lock_file; + +int cmd_mv(int argc, const char **argv, char **envp) +{ + int i, newfd, count; + int verbose = 0, show_only = 0, force = 0, ignore_errors = 0; + const char *prefix = setup_git_directory(); + const char **source, **destination, **dest_path; + struct stat st; + struct path_list overwritten = {NULL, 0, 0, 0}; + struct path_list src_for_dst = {NULL, 0, 0, 0}; + struct path_list added = {NULL, 0, 0, 0}; + struct path_list deleted = {NULL, 0, 0, 0}; + struct path_list changed = {NULL, 0, 0, 0}; + + git_config(git_default_config); + + newfd = hold_lock_file_for_update(&lock_file, get_index_file()); + if (newfd < 0) + die("unable to create new index file"); + + if (read_cache() < 0) + die("index file corrupt"); + + for (i = 1; i < argc; i++) { + const char *arg = argv[i]; + + if (arg[0] != '-') + break; + if (!strcmp(arg, "--")) { + i++; + break; + } + if (!strcmp(arg, "-n")) { + show_only = 1; + continue; + } + if (!strcmp(arg, "-f")) { + force = 1; + continue; + } + if (!strcmp(arg, "-k")) { + ignore_errors = 1; + continue; + } + die(builtin_mv_usage); + } + count = argc - i - 1; + if (count < 1) + usage(builtin_mv_usage); + + source = copy_pathspec(prefix, argv + i, count, 0); + dest_path = copy_pathspec(prefix, argv + argc - 1, 1, 0); + + if (!lstat(dest_path[0], &st) && S_ISDIR(st.st_mode)) + destination = copy_pathspec(dest_path[0], argv + i, count, 1); + else { + if (count != 1) + usage(builtin_mv_usage); + destination = dest_path; + } + + /* Checking */ + for (i = 0; i < count; i++) { + const char *bad = NULL; + + if (show_only) + printf("Checking rename of '%s' to '%s'\n", + source[i], destination[i]); + + if (lstat(source[i], &st) < 0) + bad = "bad source"; + else if (lstat(destination[i], &st) == 0) { + bad = "destination exists"; + if (force) { + /* + * only files can overwrite each other: + * check both source and destination + */ + if (S_ISREG(st.st_mode)) { + fprintf(stderr, "Warning: %s;" + " will overwrite!\n", + bad); + bad = NULL; + path_list_insert(destination[i], + &overwritten); + } else + bad = "Cannot overwrite"; + } + } + + if (!bad && + !strncmp(destination[i], source[i], strlen(source[i]))) + bad = "can not move directory into itself"; + + if (!bad && cache_name_pos(source[i], strlen(source[i])) < 0) + bad = "not under version control"; + + if (!bad) { + if (path_list_has_path(&src_for_dst, destination[i])) + bad = "multiple sources for the same target"; + else + path_list_insert(destination[i], &src_for_dst); + } + + if (bad) { + if (ignore_errors) { + if (--count > 0) { + memmove(source + i, source + i + 1, + (count - i) * sizeof(char *)); + memmove(destination + i, + destination + i + 1, + (count - i) * sizeof(char *)); + } + } else + die ("Error: %s, source=%s, destination=%s", + bad, source[i], destination[i]); + } + } + + for (i = 0; i < count; i++) { + if (show_only || verbose) + printf("Renaming %s to %s\n", + source[i], destination[i]); + if (!show_only && + rename(source[i], destination[i]) < 0 && + !ignore_errors) + die ("renaming %s failed: %s", + source[i], strerror(errno)); + + if (cache_name_pos(source[i], strlen(source[i])) >= 0) { + path_list_insert(source[i], &deleted); + + /* destination can be a directory with 1 file inside */ + if (path_list_has_path(&overwritten, destination[i])) + path_list_insert(destination[i], &changed); + else + path_list_insert(destination[i], &added); + } else + path_list_insert(destination[i], &added); + } + + if (show_only) { + show_list("Changed : ", &changed); + show_list("Adding : ", &added); + show_list("Deleting : ", &deleted); + } else { + for (i = 0; i < changed.nr; i++) { + const char *path = changed.items[i].path; + int i = cache_name_pos(path, strlen(path)); + struct cache_entry *ce = active_cache[i]; + + if (i < 0) + die ("Huh? Cache entry for %s unknown?", path); + refresh_cache_entry(ce, 0); + } + + for (i = 0; i < added.nr; i++) { + const char *path = added.items[i].path; + add_file_to_index(path, verbose); + } + + for (i = 0; i < deleted.nr; i++) { + const char *path = deleted.items[i].path; + remove_file_from_cache(path); + } + + if (active_cache_changed) { + if (write_cache(newfd, active_cache, active_nr) || + close(newfd) || + commit_lock_file(&lock_file)) + die("Unable to write new index file"); + } + } + + return 0; +} diff --git a/builtin.h b/builtin.h index 5339d8627f..6f3a43957c 100644 --- a/builtin.h +++ b/builtin.h @@ -52,6 +52,7 @@ extern int cmd_rev_parse(int argc, const char **argv, char **envp); extern int cmd_update_index(int argc, const char **argv, char **envp); extern int cmd_update_ref(int argc, const char **argv, char **envp); extern int cmd_fmt_merge_msg(int argc, const char **argv, char **envp); +extern int cmd_mv(int argc, const char **argv, char **envp); extern int cmd_write_tree(int argc, const char **argv, char **envp); extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix); diff --git a/cache.h b/cache.h index d0b1f2730f..c575b8a996 100644 --- a/cache.h +++ b/cache.h @@ -154,6 +154,7 @@ extern int add_cache_entry(struct cache_entry *ce, int option); extern struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really); extern int remove_cache_entry_at(int pos); extern int remove_file_from_cache(const char *path); +extern int add_file_to_index(const char *path, int verbose); extern int ce_same_name(struct cache_entry *a, struct cache_entry *b); extern int ce_match_stat(struct cache_entry *ce, struct stat *st, int); extern int ce_modified(struct cache_entry *ce, struct stat *st, int); diff --git a/git-mv.perl b/git-mv.perl deleted file mode 100755 index 75aa8feeb6..0000000000 --- a/git-mv.perl +++ /dev/null @@ -1,250 +0,0 @@ -#!/usr/bin/perl -# -# Copyright 2005, Ryan Anderson -# Josef Weidendorfer -# -# This file is licensed under the GPL v2, or a later version -# at the discretion of Linus Torvalds. - - -use warnings; -use strict; -use Getopt::Std; - -sub usage() { - print < -$0 [-f] [-n] [-k] ... -EOT - exit(1); -} - -our ($opt_n, $opt_f, $opt_h, $opt_k, $opt_v); -getopts("hnfkv") || usage; -usage() if $opt_h; -@ARGV >= 1 or usage; - -my $GIT_DIR = `git rev-parse --git-dir`; -exit 1 if $?; # rev-parse would have given "not a git dir" message. -chomp($GIT_DIR); - -my (@srcArgs, @dstArgs, @srcs, @dsts); -my ($src, $dst, $base, $dstDir); - -# remove any trailing slash in arguments -for (@ARGV) { s/\/*$//; } - -my $argCount = scalar @ARGV; -if (-d $ARGV[$argCount-1]) { - $dstDir = $ARGV[$argCount-1]; - @srcArgs = @ARGV[0..$argCount-2]; - - foreach $src (@srcArgs) { - $base = $src; - $base =~ s/^.*\///; - $dst = "$dstDir/". $base; - push @dstArgs, $dst; - } -} -else { - if ($argCount < 2) { - print "Error: need at least two arguments\n"; - exit(1); - } - if ($argCount > 2) { - print "Error: moving to directory '" - . $ARGV[$argCount-1] - . "' not possible; not existing\n"; - exit(1); - } - @srcArgs = ($ARGV[0]); - @dstArgs = ($ARGV[1]); - $dstDir = ""; -} - -my $subdir_prefix = `git rev-parse --show-prefix`; -chomp($subdir_prefix); - -# run in git base directory, so that git-ls-files lists all revisioned files -chdir "$GIT_DIR/.."; - -# normalize paths, needed to compare against versioned files and update-index -# also, this is nicer to end-users by doing ".//a/./b/.//./c" ==> "a/b/c" -for (@srcArgs, @dstArgs) { - # prepend git prefix as we run from base directory - $_ = $subdir_prefix.$_; - s|^\./||; - s|/\./|/| while (m|/\./|); - s|//+|/|g; - # Also "a/b/../c" ==> "a/c" - 1 while (s,(^|/)[^/]+/\.\./,$1,); -} - -my (@allfiles,@srcfiles,@dstfiles); -my $safesrc; -my (%overwritten, %srcForDst); - -$/ = "\0"; -open(F, 'git-ls-files -z |') - or die "Failed to open pipe from git-ls-files: " . $!; - -@allfiles = map { chomp; $_; } ; -close(F); - - -my ($i, $bad); -while(scalar @srcArgs > 0) { - $src = shift @srcArgs; - $dst = shift @dstArgs; - $bad = ""; - - for ($src, $dst) { - # Be nicer to end-users by doing ".//a/./b/.//./c" ==> "a/b/c" - s|^\./||; - s|/\./|/| while (m|/\./|); - s|//+|/|g; - # Also "a/b/../c" ==> "a/c" - 1 while (s,(^|/)[^/]+/\.\./,$1,); - } - - if ($opt_v) { - print "Checking rename of '$src' to '$dst'\n"; - } - - unless (-f $src || -l $src || -d $src) { - $bad = "bad source '$src'"; - } - - $safesrc = quotemeta($src); - @srcfiles = grep /^$safesrc(\/|$)/, @allfiles; - - $overwritten{$dst} = 0; - if (($bad eq "") && -e $dst) { - $bad = "destination '$dst' already exists"; - if ($opt_f) { - # only files can overwrite each other: check both source and destination - if (-f $dst && (scalar @srcfiles == 1)) { - print "Warning: $bad; will overwrite!\n"; - $bad = ""; - $overwritten{$dst} = 1; - } - else { - $bad = "Can not overwrite '$src' with '$dst'"; - } - } - } - - if (($bad eq "") && ($dst =~ /^$safesrc\//)) { - $bad = "can not move directory '$src' into itself"; - } - - if ($bad eq "") { - if (scalar @srcfiles == 0) { - $bad = "'$src' not under version control"; - } - } - - if ($bad eq "") { - if (defined $srcForDst{$dst}) { - $bad = "can not move '$src' to '$dst'; already target of "; - $bad .= "'".$srcForDst{$dst}."'"; - } - else { - $srcForDst{$dst} = $src; - } - } - - if ($bad ne "") { - if ($opt_k) { - print "Warning: $bad; skipping\n"; - next; - } - print "Error: $bad\n"; - exit(1); - } - push @srcs, $src; - push @dsts, $dst; -} - -# Final pass: rename/move -my (@deletedfiles,@addedfiles,@changedfiles); -$bad = ""; -while(scalar @srcs > 0) { - $src = shift @srcs; - $dst = shift @dsts; - - if ($opt_n || $opt_v) { print "Renaming $src to $dst\n"; } - if (!$opt_n) { - if (!rename($src,$dst)) { - $bad = "renaming '$src' failed: $!"; - if ($opt_k) { - print "Warning: skipped: $bad\n"; - $bad = ""; - next; - } - last; - } - } - - $safesrc = quotemeta($src); - @srcfiles = grep /^$safesrc(\/|$)/, @allfiles; - @dstfiles = @srcfiles; - s/^$safesrc(\/|$)/$dst$1/ for @dstfiles; - - push @deletedfiles, @srcfiles; - if (scalar @srcfiles == 1) { - # $dst can be a directory with 1 file inside - if ($overwritten{$dst} ==1) { - push @changedfiles, $dstfiles[0]; - - } else { - push @addedfiles, $dstfiles[0]; - } - } - else { - push @addedfiles, @dstfiles; - } -} - -if ($opt_n) { - if (@changedfiles) { - print "Changed : ". join(", ", @changedfiles) ."\n"; - } - if (@addedfiles) { - print "Adding : ". join(", ", @addedfiles) ."\n"; - } - if (@deletedfiles) { - print "Deleting : ". join(", ", @deletedfiles) ."\n"; - } -} -else { - if (@changedfiles) { - open(H, "| git-update-index -z --stdin") - or die "git-update-index failed to update changed files with code $!\n"; - foreach my $fileName (@changedfiles) { - print H "$fileName\0"; - } - close(H); - } - if (@addedfiles) { - open(H, "| git-update-index --add -z --stdin") - or die "git-update-index failed to add new names with code $!\n"; - foreach my $fileName (@addedfiles) { - print H "$fileName\0"; - } - close(H); - } - if (@deletedfiles) { - open(H, "| git-update-index --remove -z --stdin") - or die "git-update-index failed to remove old names with code $!\n"; - foreach my $fileName (@deletedfiles) { - print H "$fileName\0"; - } - close(H); - } -} - -if ($bad ne "") { - print "Error: $bad\n"; - exit(1); -} diff --git a/git.c b/git.c index ee5a0e86a7..d47e9d8db9 100644 --- a/git.c +++ b/git.c @@ -202,6 +202,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp) { "update-ref", cmd_update_ref }, { "fmt-merge-msg", cmd_fmt_merge_msg }, { "prune", cmd_prune }, + { "mv", cmd_mv }, }; int i; diff --git a/read-cache.c b/read-cache.c index 4c47a0eb9f..c0b031367b 100644 --- a/read-cache.c +++ b/read-cache.c @@ -319,6 +319,45 @@ int remove_file_from_cache(const char *path) return 0; } +int add_file_to_index(const char *path, int verbose) +{ + int size, namelen; + struct stat st; + struct cache_entry *ce; + + if (lstat(path, &st)) + die("%s: unable to stat (%s)", path, strerror(errno)); + + if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode)) + die("%s: can only add regular files or symbolic links", path); + + namelen = strlen(path); + size = cache_entry_size(namelen); + ce = xcalloc(1, size); + memcpy(ce->name, path, namelen); + ce->ce_flags = htons(namelen); + fill_stat_cache_info(ce, &st); + + ce->ce_mode = create_ce_mode(st.st_mode); + if (!trust_executable_bit) { + /* If there is an existing entry, pick the mode bits + * from it. + */ + int pos = cache_name_pos(path, namelen); + if (pos >= 0) + ce->ce_mode = active_cache[pos]->ce_mode; + } + + if (index_path(ce->sha1, path, &st, 1)) + die("unable to index file %s", path); + if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD)) + die("unable to add %s to index",path); + if (verbose) + printf("add '%s'\n", path); + cache_tree_invalidate_path(active_cache_tree, path); + return 0; +} + int ce_same_name(struct cache_entry *a, struct cache_entry *b) { int len = ce_namelen(a); From ac64a722072bb348476a8a029de9a82073e07fba Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 26 Jul 2006 19:47:54 +0200 Subject: [PATCH 081/107] builtin git-mv: support moving directories This fixes the builtin mv for the test which Josef provided, and also fixes moving directories into existing directories, as noted by Jon Smirl. In case the destination exists, fail early (this cannot be overridden by -f). Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin-mv.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++--- t/t7001-mv.sh | 4 +++ 2 files changed, 86 insertions(+), 5 deletions(-) diff --git a/builtin-mv.c b/builtin-mv.c index 593ff9e434..42c2e39b21 100644 --- a/builtin-mv.c +++ b/builtin-mv.c @@ -42,6 +42,18 @@ static void show_list(const char *label, struct path_list *list) } } +static const char *add_slash(const char *path) +{ + int len = strlen(path); + if (path[len - 1] != '/') { + char *with_slash = xmalloc(len + 2); + memcpy(with_slash, path, len); + strcat(with_slash + len, "/"); + return with_slash; + } + return path; +} + static struct lock_file lock_file; int cmd_mv(int argc, const char **argv, char **envp) @@ -50,6 +62,7 @@ int cmd_mv(int argc, const char **argv, char **envp) int verbose = 0, show_only = 0, force = 0, ignore_errors = 0; const char *prefix = setup_git_directory(); const char **source, **destination, **dest_path; + enum update_mode { BOTH = 0, WORKING_DIRECTORY, INDEX } *modes; struct stat st; struct path_list overwritten = {NULL, 0, 0, 0}; struct path_list src_for_dst = {NULL, 0, 0, 0}; @@ -94,11 +107,14 @@ int cmd_mv(int argc, const char **argv, char **envp) usage(builtin_mv_usage); source = copy_pathspec(prefix, argv + i, count, 0); + modes = xcalloc(count, sizeof(enum update_mode)); dest_path = copy_pathspec(prefix, argv + argc - 1, 1, 0); - if (!lstat(dest_path[0], &st) && S_ISDIR(st.st_mode)) + if (!lstat(dest_path[0], &st) && + S_ISDIR(st.st_mode)) { + dest_path[0] = add_slash(dest_path[0]); destination = copy_pathspec(dest_path[0], argv + i, count, 1); - else { + } else { if (count != 1) usage(builtin_mv_usage); destination = dest_path; @@ -114,7 +130,64 @@ int cmd_mv(int argc, const char **argv, char **envp) if (lstat(source[i], &st) < 0) bad = "bad source"; - else if (lstat(destination[i], &st) == 0) { + + if (S_ISDIR(st.st_mode)) { + const char *dir = source[i], *dest_dir = destination[i]; + int first, last, len = strlen(dir); + + if (lstat(dest_dir, &st) == 0) { + bad = "cannot move directory over file"; + goto next; + } + + modes[i] = WORKING_DIRECTORY; + + first = cache_name_pos(source[i], len); + if (first >= 0) + die ("Huh? %s/ is in index?", dir); + + first = -1 - first; + for (last = first; last < active_nr; last++) { + const char *path = active_cache[last]->name; + if (strncmp(path, dir, len) || path[len] != '/') + break; + } + + if (last - first < 1) + bad = "source directory is empty"; + else if (!bad) { + int j, dst_len = strlen(dest_dir); + + if (last - first > 0) { + source = realloc(source, + (count + last - first) + * sizeof(char *)); + destination = realloc(destination, + (count + last - first) + * sizeof(char *)); + modes = realloc(modes, + (count + last - first) + * sizeof(enum update_mode)); + } + + dest_dir = add_slash(dest_dir); + + for (j = 0; j < last - first; j++) { + const char *path = + active_cache[first + j]->name; + source[count + j] = path; + destination[count + j] = + prefix_path(dest_dir, dst_len, + path + len); + modes[count + j] = INDEX; + } + count += last - first; + } + + goto next; + } + + if (!bad && lstat(destination[i], &st) == 0) { bad = "destination exists"; if (force) { /* @@ -147,6 +220,7 @@ int cmd_mv(int argc, const char **argv, char **envp) path_list_insert(destination[i], &src_for_dst); } +next: if (bad) { if (ignore_errors) { if (--count > 0) { @@ -157,7 +231,7 @@ int cmd_mv(int argc, const char **argv, char **envp) (count - i) * sizeof(char *)); } } else - die ("Error: %s, source=%s, destination=%s", + die ("%s, source=%s, destination=%s", bad, source[i], destination[i]); } } @@ -166,12 +240,15 @@ int cmd_mv(int argc, const char **argv, char **envp) if (show_only || verbose) printf("Renaming %s to %s\n", source[i], destination[i]); - if (!show_only && + if (!show_only && modes[i] != INDEX && rename(source[i], destination[i]) < 0 && !ignore_errors) die ("renaming %s failed: %s", source[i], strerror(errno)); + if (modes[i] == WORKING_DIRECTORY) + continue; + if (cache_name_pos(source[i], strlen(source[i])) >= 0) { path_list_insert(source[i], &deleted); diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 322eaadc73..900ca93cde 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -74,4 +74,8 @@ test_expect_success \ git-diff-tree -r -M --name-status HEAD^ HEAD | \ grep -E "^R100.+path2/README.+path1/path2/README"' +test_expect_failure \ + 'do not move directory over existing directory' \ + 'mkdir path0 && mkdir path0/path2 && git-mv path2 path0' + test_done From 5209eda86363a3ba2e000903ad8de29589b18b58 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 26 Jul 2006 23:11:46 +0200 Subject: [PATCH 082/107] instaweb: Be more clear if httpd or the browser fail Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git-instaweb.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/git-instaweb.sh b/git-instaweb.sh index 9829c59154..16cd351f7f 100755 --- a/git-instaweb.sh +++ b/git-instaweb.sh @@ -54,6 +54,10 @@ start_httpd () { fi done fi + if test $? != 0; then + echo "Could not execute http daemon $httpd." + exit 1 + fi } stop_httpd () { @@ -184,7 +188,7 @@ EOF else # plain-old CGI list_mods=`echo "$httpd" | sed "s/-f$/-l/"` - $list_mods | grep 'mod_cgi\.c' >/dev/null || \ + $list_mods | grep 'mod_cgi\.c' >/dev/null 2>&1 || \ echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf" cat >> "$conf" < Date: Wed, 26 Jul 2006 22:51:52 +0200 Subject: [PATCH 083/107] cvsserver: imitate git-update-ref when committing git-update-ref writes into the lockfile, and renames it afterwards. Like commit v1.3.0-rc3~22, it is not only cleaner, but also helps with shared setups: every developer can have a different primary group; what matters is that $GIT_DIR/refs/heads has to be writable by a group you are in. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git-cvsserver.perl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/git-cvsserver.perl b/git-cvsserver.perl index 5b73837bb1..2130d57020 100755 --- a/git-cvsserver.perl +++ b/git-cvsserver.perl @@ -1142,9 +1142,7 @@ sub req_ci exit; } - open FILE, ">", "$ENV{GIT_DIR}refs/heads/$state->{module}"; - print FILE $commithash; - close FILE; + print LOCKFILE $commithash; $updater->update(); @@ -1171,7 +1169,9 @@ sub req_ci } close LOCKFILE; - unlink($lockfile); + my $reffile = "$ENV{GIT_DIR}refs/heads/$state->{module}"; + unlink($reffile); + rename($lockfile, $reffile); chdir "/"; print "ok\n"; From 6c35119ac711c69c69874d7d52f5cfa12c07ccce Mon Sep 17 00:00:00 2001 From: Matthias Lederhofer Date: Fri, 14 Jul 2006 17:53:29 +0200 Subject: [PATCH 084/107] daemon: documentation for --reuseaddr, --detach and --pid-file Signed-off-by: Matthias Lederhofer Signed-off-by: Junio C Hamano --- Documentation/git-daemon.txt | 13 ++++++++++++- daemon.c | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Documentation/git-daemon.txt b/Documentation/git-daemon.txt index 4c357daf6a..0f7d274eab 100644 --- a/Documentation/git-daemon.txt +++ b/Documentation/git-daemon.txt @@ -11,7 +11,7 @@ SYNOPSIS 'git-daemon' [--verbose] [--syslog] [--inetd | --port=n] [--export-all] [--timeout=n] [--init-timeout=n] [--strict-paths] [--base-path=path] [--user-path | --user-path=path] - [directory...] + [--reuseaddr] [--detach] [--pid-file=file] [directory...] DESCRIPTION ----------- @@ -82,6 +82,17 @@ OPTIONS --verbose:: Log details about the incoming connections and requested files. +--reuseaddr:: + Use SO_REUSEADDR when binding the listening socket. + This allows the server to restart without waiting for + old connections to time out. + +--detach:: + Detach from the shell. Implies --syslog. + +--pid-file=file:: + Save the process id in 'file'. + :: A directory to add to the whitelist of allowed directories. Unless --strict-paths is specified this will also include subdirectories diff --git a/daemon.c b/daemon.c index e4ec676301..810837f0c4 100644 --- a/daemon.c +++ b/daemon.c @@ -19,7 +19,7 @@ static const char daemon_usage[] = "git-daemon [--verbose] [--syslog] [--inetd | --port=n] [--export-all]\n" " [--timeout=n] [--init-timeout=n] [--strict-paths]\n" " [--base-path=path] [--user-path | --user-path=path]\n" -" [--reuseaddr] [directory...]"; +" [--reuseaddr] [--detach] [--pid-file=file] [directory...]"; /* List of acceptable pathname prefixes */ static char **ok_paths = NULL; From cc41cd2e60da8224dcd04f23d837853cff5d4eda Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Thu, 27 Jul 2006 20:58:53 +0200 Subject: [PATCH 085/107] Remove -d from *-fetch usage strings This is a really ancient remnant of the short era of delta objects stored directly in the object database. Signed-off-by: Petr Baudis Signed-off-by: Junio C Hamano --- http-fetch.c | 2 +- local-fetch.c | 4 ++-- ssh-fetch.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/http-fetch.c b/http-fetch.c index 12493fbed2..dc286b79f6 100644 --- a/http-fetch.c +++ b/http-fetch.c @@ -1245,7 +1245,7 @@ int main(int argc, char **argv) arg++; } if (argc < arg + 2) { - usage("git-http-fetch [-c] [-t] [-a] [-d] [-v] [--recover] [-w ref] commit-id url"); + usage("git-http-fetch [-c] [-t] [-a] [-v] [--recover] [-w ref] commit-id url"); return 1; } commit_id = argv[arg]; diff --git a/local-fetch.c b/local-fetch.c index ffa4887570..a05ac16cd0 100644 --- a/local-fetch.c +++ b/local-fetch.c @@ -194,9 +194,9 @@ int fetch_ref(char *ref, unsigned char *sha1) } static const char local_pull_usage[] = -"git-local-fetch [-c] [-t] [-a] [-d] [-v] [-w filename] [--recover] [-l] [-s] [-n] commit-id path"; +"git-local-fetch [-c] [-t] [-a] [-v] [-w filename] [--recover] [-l] [-s] [-n] commit-id path"; -/* +/* * By default we only use file copy. * If -l is specified, a hard link is attempted. * If -s is specified, then a symlink is attempted. diff --git a/ssh-fetch.c b/ssh-fetch.c index 28f7fd9174..a8a6cfbb30 100644 --- a/ssh-fetch.c +++ b/ssh-fetch.c @@ -120,7 +120,7 @@ int fetch_ref(char *ref, unsigned char *sha1) static const char ssh_fetch_usage[] = MY_PROGRAM_NAME - " [-c] [-t] [-a] [-v] [-d] [--recover] [-w ref] commit-id url"; + " [-c] [-t] [-a] [-v] [--recover] [-w ref] commit-id url"; int main(int argc, char **argv) { char *commit_id; From c2c487cf3a6c37bc9b4e3f0e10ad08d9ce048404 Mon Sep 17 00:00:00 2001 From: "Michael S. Tsirkin" Date: Thu, 27 Jul 2006 17:03:43 +0300 Subject: [PATCH 086/107] mailinfo: accept >From in message header Mail I get sometimes has multiple From lines, like this: From Majordomo@vger.kernel.org Thu Jul 27 16:39:36 2006 >From mtsirkin Thu Jul 27 16:39:36 2006 Received: from yok.mtl.com [10.0.8.11] ... which confuses git-mailinfo since that does not recognize >From as a valid header line. This patch makes it recognize >From XXX as a valid header line. Signed-off-by: Michael S. Tsirkin Signed-off-by: Junio C Hamano --- builtin-mailinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c index ac53f76f68..05dc1bfe71 100644 --- a/builtin-mailinfo.c +++ b/builtin-mailinfo.c @@ -446,7 +446,7 @@ static int read_one_header_line(char *line, int sz, FILE *in) break; } /* Count mbox From headers as headers */ - if (!ofs && !memcmp(line, "From ", 5)) + if (!ofs && (!memcmp(line, "From ", 5) || !memcmp(line, ">From ", 6))) ofs = 1; return ofs; } From c6b69bdbc1b0b914aa0d1e59a29305fce82d6f06 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Thu, 27 Jul 2006 23:56:14 +0200 Subject: [PATCH 087/107] Make pull() take some implicit data as explicit arguments Currently it's a bit weird that pull() takes a single argument describing the commit but takes the write_ref from a global variable. This makes it take that as a parameter as well, which might be nicer for the libification in the future, but especially it will make for nicer code when we implement pull()ing multiple commits at once. Signed-off-by: Petr Baudis Signed-off-by: Junio C Hamano --- fetch.c | 6 ++---- fetch.h | 11 ++++------- http-fetch.c | 4 ++-- local-fetch.c | 4 ++-- ssh-fetch.c | 4 ++-- 5 files changed, 12 insertions(+), 17 deletions(-) diff --git a/fetch.c b/fetch.c index 989d7a4788..3255cc6250 100644 --- a/fetch.c +++ b/fetch.c @@ -8,9 +8,6 @@ #include "blob.h" #include "refs.h" -const char *write_ref = NULL; -const char *write_ref_log_details = NULL; - int get_tree = 0; int get_history = 0; int get_all = 0; @@ -213,7 +210,8 @@ static int mark_complete(const char *path, const unsigned char *sha1) return 0; } -int pull(char *target) +int pull(char *target, const char *write_ref, + const char *write_ref_log_details) { struct ref_lock *lock = NULL; unsigned char sha1[20]; diff --git a/fetch.h b/fetch.h index 841bb1af9c..7bda355bc1 100644 --- a/fetch.h +++ b/fetch.h @@ -22,12 +22,6 @@ extern void prefetch(unsigned char *sha1); */ extern int fetch_ref(char *ref, unsigned char *sha1); -/* If set, the ref filename to write the target value to. */ -extern const char *write_ref; - -/* If set additional text will appear in the ref log. */ -extern const char *write_ref_log_details; - /* Set to fetch the target tree. */ extern int get_tree; @@ -46,6 +40,9 @@ extern int get_recover; /* Report what we got under get_verbosely */ extern void pull_say(const char *, const char *); -extern int pull(char *target); +/* If write_ref is set, the ref filename to write the target value to. */ +/* If write_ref_log_details is set, additional text will appear in the ref log. */ +extern int pull(char *target, const char *write_ref, + const char *write_ref_log_details); #endif /* PULL_H */ diff --git a/http-fetch.c b/http-fetch.c index dc286b79f6..963d439f82 100644 --- a/http-fetch.c +++ b/http-fetch.c @@ -1216,6 +1216,7 @@ int fetch_ref(char *ref, unsigned char *sha1) int main(int argc, char **argv) { + const char *write_ref = NULL; char *commit_id; char *url; char *path; @@ -1250,7 +1251,6 @@ int main(int argc, char **argv) } commit_id = argv[arg]; url = argv[arg + 1]; - write_ref_log_details = url; http_init(); @@ -1268,7 +1268,7 @@ int main(int argc, char **argv) alt->path_len = strlen(path); } - if (pull(commit_id)) + if (pull(commit_id, write_ref, url)) rc = 1; http_cleanup(); diff --git a/local-fetch.c b/local-fetch.c index a05ac16cd0..452b83396c 100644 --- a/local-fetch.c +++ b/local-fetch.c @@ -204,6 +204,7 @@ static const char local_pull_usage[] = */ int main(int argc, char **argv) { + const char *write_ref = NULL; char *commit_id; int arg = 1; @@ -240,9 +241,8 @@ int main(int argc, char **argv) usage(local_pull_usage); commit_id = argv[arg]; path = argv[arg + 1]; - write_ref_log_details = path; - if (pull(commit_id)) + if (pull(commit_id, write_ref, path)) return 1; return 0; diff --git a/ssh-fetch.c b/ssh-fetch.c index a8a6cfbb30..aef3aa4a05 100644 --- a/ssh-fetch.c +++ b/ssh-fetch.c @@ -123,6 +123,7 @@ static const char ssh_fetch_usage[] = " [-c] [-t] [-a] [-v] [--recover] [-w ref] commit-id url"; int main(int argc, char **argv) { + const char *write_ref = NULL; char *commit_id; char *url; int arg = 1; @@ -159,7 +160,6 @@ int main(int argc, char **argv) } commit_id = argv[arg]; url = argv[arg + 1]; - write_ref_log_details = url; if (setup_connection(&fd_in, &fd_out, prog, url, arg, argv + 1)) return 1; @@ -167,7 +167,7 @@ int main(int argc, char **argv) if (get_version()) return 1; - if (pull(commit_id)) + if (pull(commit_id, write_ref, url)) return 1; return 0; From 4211e4d10cd98b1aeed97bdb6cdebb9411956bb5 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Thu, 27 Jul 2006 23:56:17 +0200 Subject: [PATCH 088/107] Make pull() support fetching multiple targets at once pull() now takes an array of arguments instead of just one of each kind. Currently, no users use the new capability, but that'll change. Signed-off-by: Petr Baudis Signed-off-by: Junio C Hamano --- fetch.c | 80 +++++++++++++++++++++++++++++---------------------- fetch.h | 2 +- http-fetch.c | 2 +- local-fetch.c | 2 +- ssh-fetch.c | 2 +- 5 files changed, 50 insertions(+), 38 deletions(-) diff --git a/fetch.c b/fetch.c index 3255cc6250..281df61e7b 100644 --- a/fetch.c +++ b/fetch.c @@ -210,55 +210,67 @@ static int mark_complete(const char *path, const unsigned char *sha1) return 0; } -int pull(char *target, const char *write_ref, +int pull(int targets, char **target, const char **write_ref, const char *write_ref_log_details) { - struct ref_lock *lock = NULL; - unsigned char sha1[20]; + struct ref_lock **lock = xcalloc(targets, sizeof(struct ref_lock *)); + unsigned char *sha1 = xmalloc(targets * 20); char *msg; int ret; + int i; save_commit_buffer = 0; track_object_refs = 0; - if (write_ref) { - lock = lock_ref_sha1(write_ref, NULL, 0); - if (!lock) { - error("Can't lock ref %s", write_ref); - return -1; + + for (i = 0; i < targets; i++) { + if (!write_ref[i]) + continue; + + lock[i] = lock_ref_sha1(write_ref[i], NULL, 0); + if (!lock[i]) { + error("Can't lock ref %s", write_ref[i]); + goto unlock_and_fail; } } if (!get_recover) for_each_ref(mark_complete); - if (interpret_target(target, sha1)) { - error("Could not interpret %s as something to pull", target); - if (lock) - unlock_ref(lock); - return -1; - } - if (process(lookup_unknown_object(sha1))) { - if (lock) - unlock_ref(lock); - return -1; - } - if (loop()) { - if (lock) - unlock_ref(lock); - return -1; + for (i = 0; i < targets; i++) { + if (interpret_target(target[i], &sha1[20 * i])) { + error("Could not interpret %s as something to pull", target[i]); + goto unlock_and_fail; + } + if (process(lookup_unknown_object(&sha1[20 * i]))) + goto unlock_and_fail; } - if (write_ref) { - if (write_ref_log_details) { - msg = xmalloc(strlen(write_ref_log_details) + 12); - sprintf(msg, "fetch from %s", write_ref_log_details); - } - else - msg = NULL; - ret = write_ref_sha1(lock, sha1, msg ? msg : "fetch (unknown)"); - if (msg) - free(msg); - return ret; + if (loop()) + goto unlock_and_fail; + + if (write_ref_log_details) { + msg = xmalloc(strlen(write_ref_log_details) + 12); + sprintf(msg, "fetch from %s", write_ref_log_details); + } else { + msg = NULL; } + for (i = 0; i < targets; i++) { + if (!write_ref[i]) + continue; + ret = write_ref_sha1(lock[i], &sha1[20 * i], msg ? msg : "fetch (unknown)"); + lock[i] = NULL; + if (ret) + goto unlock_and_fail; + } + if (msg) + free(msg); + return 0; + + +unlock_and_fail: + for (i = 0; i < targets; i++) + if (lock[i]) + unlock_ref(lock[i]); + return -1; } diff --git a/fetch.h b/fetch.h index 7bda355bc1..75e48af780 100644 --- a/fetch.h +++ b/fetch.h @@ -42,7 +42,7 @@ extern void pull_say(const char *, const char *); /* If write_ref is set, the ref filename to write the target value to. */ /* If write_ref_log_details is set, additional text will appear in the ref log. */ -extern int pull(char *target, const char *write_ref, +extern int pull(int targets, char **target, const char **write_ref, const char *write_ref_log_details); #endif /* PULL_H */ diff --git a/http-fetch.c b/http-fetch.c index 963d439f82..bc67db1add 100644 --- a/http-fetch.c +++ b/http-fetch.c @@ -1268,7 +1268,7 @@ int main(int argc, char **argv) alt->path_len = strlen(path); } - if (pull(commit_id, write_ref, url)) + if (pull(1, &commit_id, &write_ref, url)) rc = 1; http_cleanup(); diff --git a/local-fetch.c b/local-fetch.c index 452b83396c..1be73904f1 100644 --- a/local-fetch.c +++ b/local-fetch.c @@ -242,7 +242,7 @@ int main(int argc, char **argv) commit_id = argv[arg]; path = argv[arg + 1]; - if (pull(commit_id, write_ref, path)) + if (pull(1, &commit_id, &write_ref, path)) return 1; return 0; diff --git a/ssh-fetch.c b/ssh-fetch.c index aef3aa4a05..6e16568f88 100644 --- a/ssh-fetch.c +++ b/ssh-fetch.c @@ -167,7 +167,7 @@ int main(int argc, char **argv) if (get_version()) return 1; - if (pull(commit_id, write_ref, url)) + if (pull(1, &commit_id, &write_ref, url)) return 1; return 0; From 8e87ca661513d9f4b737295b234e93767cd2ee0c Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Thu, 27 Jul 2006 23:56:19 +0200 Subject: [PATCH 089/107] Teach git-local-fetch the --stdin switch This makes it possible to fetch many commits (refs) at once, greatly speeding up cg-clone. Signed-off-by: Petr Baudis Signed-off-by: Junio C Hamano --- Documentation/git-local-fetch.txt | 6 +++++ fetch.c | 40 +++++++++++++++++++++++++++++++ fetch.h | 6 +++++ local-fetch.c | 32 +++++++++++++++++-------- 4 files changed, 74 insertions(+), 10 deletions(-) diff --git a/Documentation/git-local-fetch.txt b/Documentation/git-local-fetch.txt index 87abec1c4e..2fbdfe086a 100644 --- a/Documentation/git-local-fetch.txt +++ b/Documentation/git-local-fetch.txt @@ -29,6 +29,12 @@ OPTIONS Writes the commit-id into the filename under $GIT_DIR/refs/ on the local end after the transfer is complete. +--stdin:: + Instead of a commit id on the commandline (which is not expected in this + case), 'git-local-fetch' expects lines on stdin in the format + + ['\t'] + Author ------ Written by Junio C Hamano diff --git a/fetch.c b/fetch.c index 281df61e7b..2151c7b78c 100644 --- a/fetch.c +++ b/fetch.c @@ -7,6 +7,7 @@ #include "tag.h" #include "blob.h" #include "refs.h" +#include "strbuf.h" int get_tree = 0; int get_history = 0; @@ -210,6 +211,45 @@ static int mark_complete(const char *path, const unsigned char *sha1) return 0; } +int pull_targets_stdin(char ***target, const char ***write_ref) +{ + int targets = 0, targets_alloc = 0; + struct strbuf buf; + *target = NULL; *write_ref = NULL; + strbuf_init(&buf); + while (1) { + char *rf_one = NULL; + char *tg_one; + + read_line(&buf, stdin, '\n'); + if (buf.eof) + break; + tg_one = buf.buf; + rf_one = strchr(tg_one, '\t'); + if (rf_one) + *rf_one++ = 0; + + if (targets >= targets_alloc) { + targets_alloc = targets_alloc ? targets_alloc * 2 : 64; + *target = xrealloc(*target, targets_alloc * sizeof(**target)); + *write_ref = xrealloc(*write_ref, targets_alloc * sizeof(**write_ref)); + } + (*target)[targets] = strdup(tg_one); + (*write_ref)[targets] = rf_one ? strdup(rf_one) : NULL; + targets++; + } + return targets; +} + +void pull_targets_free(int targets, char **target, const char **write_ref) +{ + while (targets--) { + free(target[targets]); + if (write_ref[targets]) + free((char *) write_ref[targets]); + } +} + int pull(int targets, char **target, const char **write_ref, const char *write_ref_log_details) { diff --git a/fetch.h b/fetch.h index 75e48af780..be48c6f190 100644 --- a/fetch.h +++ b/fetch.h @@ -40,6 +40,12 @@ extern int get_recover; /* Report what we got under get_verbosely */ extern void pull_say(const char *, const char *); +/* Load pull targets from stdin */ +extern int pull_targets_stdin(char ***target, const char ***write_ref); + +/* Free up loaded targets */ +extern void pull_targets_free(int targets, char **target, const char **write_ref); + /* If write_ref is set, the ref filename to write the target value to. */ /* If write_ref_log_details is set, additional text will appear in the ref log. */ extern int pull(int targets, char **target, const char **write_ref, diff --git a/local-fetch.c b/local-fetch.c index 1be73904f1..b216bdd557 100644 --- a/local-fetch.c +++ b/local-fetch.c @@ -8,8 +8,9 @@ static int use_link = 0; static int use_symlink = 0; static int use_filecopy = 1; +static int commits_on_stdin = 0; -static char *path; /* "Remote" git repository */ +static const char *path; /* "Remote" git repository */ void prefetch(unsigned char *sha1) { @@ -194,7 +195,7 @@ int fetch_ref(char *ref, unsigned char *sha1) } static const char local_pull_usage[] = -"git-local-fetch [-c] [-t] [-a] [-v] [-w filename] [--recover] [-l] [-s] [-n] commit-id path"; +"git-local-fetch [-c] [-t] [-a] [-v] [-w filename] [--recover] [-l] [-s] [-n] [--stdin] commit-id path"; /* * By default we only use file copy. @@ -202,10 +203,11 @@ static const char local_pull_usage[] = * If -s is specified, then a symlink is attempted. * If -n is _not_ specified, then a regular file-to-file copy is done. */ -int main(int argc, char **argv) +int main(int argc, const char **argv) { - const char *write_ref = NULL; - char *commit_id; + int commits; + const char **write_ref = NULL; + char **commit_id; int arg = 1; setup_git_directory(); @@ -230,20 +232,30 @@ int main(int argc, char **argv) else if (argv[arg][1] == 'v') get_verbosely = 1; else if (argv[arg][1] == 'w') - write_ref = argv[++arg]; + write_ref = &argv[++arg]; else if (!strcmp(argv[arg], "--recover")) get_recover = 1; + else if (!strcmp(argv[arg], "--stdin")) + commits_on_stdin = 1; else usage(local_pull_usage); arg++; } - if (argc < arg + 2) + if (argc < arg + 2 - commits_on_stdin) usage(local_pull_usage); - commit_id = argv[arg]; - path = argv[arg + 1]; + if (commits_on_stdin) { + commits = pull_targets_stdin(&commit_id, &write_ref); + } else { + commit_id = (char **) &argv[arg++]; + commits = 1; + } + path = argv[arg]; - if (pull(1, &commit_id, &write_ref, path)) + if (pull(commits, commit_id, write_ref, path)) return 1; + if (commits_on_stdin) + pull_targets_free(commits, commit_id, write_ref); + return 0; } From 8e29f6a07e321a24f1d4f579817f5a8a43cdac05 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Thu, 27 Jul 2006 23:56:22 +0200 Subject: [PATCH 090/107] Teach git-http-fetch the --stdin switch Speeds up things quite a lot when fetching tags with Cogito. Signed-off-by: Petr Baudis Signed-off-by: Junio C Hamano --- Documentation/git-http-fetch.txt | 8 +++++- http-fetch.c | 45 ++++++++++++++++++++------------ 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/Documentation/git-http-fetch.txt b/Documentation/git-http-fetch.txt index bc1a132891..3d508094af 100644 --- a/Documentation/git-http-fetch.txt +++ b/Documentation/git-http-fetch.txt @@ -8,7 +8,7 @@ git-http-fetch - downloads a remote git repository via HTTP SYNOPSIS -------- -'git-http-fetch' [-c] [-t] [-a] [-d] [-v] [-w filename] [--recover] +'git-http-fetch' [-c] [-t] [-a] [-d] [-v] [-w filename] [--recover] [--stdin] DESCRIPTION ----------- @@ -33,6 +33,12 @@ commit-id:: Writes the commit-id into the filename under $GIT_DIR/refs/ on the local end after the transfer is complete. +--stdin:: + Instead of a commit id on the commandline (which is not expected in this + case), 'git-http-fetch' expects lines on stdin in the format + + ['\t'] + Author ------ Written by Linus Torvalds diff --git a/http-fetch.c b/http-fetch.c index bc67db1add..1aad39b4d8 100644 --- a/http-fetch.c +++ b/http-fetch.c @@ -36,6 +36,8 @@ enum XML_Status { #define PREV_BUF_SIZE 4096 #define RANGE_HEADER_SIZE 30 +static int commits_on_stdin = 0; + static int got_alternates = -1; static int corrupt_object_found = 0; @@ -43,7 +45,7 @@ static struct curl_slist *no_pragma_header; struct alt_base { - char *base; + const char *base; int path_len; int got_indices; struct packed_git *packs; @@ -81,7 +83,7 @@ struct object_request }; struct alternates_request { - char *base; + const char *base; char *url; struct buffer *buffer; struct active_request_slot *slot; @@ -142,7 +144,7 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb, return size; } -static void fetch_alternates(char *base); +static void fetch_alternates(const char *base); static void process_object_response(void *callback_data); @@ -507,7 +509,7 @@ static void process_alternates_response(void *callback_data) (struct alternates_request *)callback_data; struct active_request_slot *slot = alt_req->slot; struct alt_base *tail = alt; - char *base = alt_req->base; + const char *base = alt_req->base; static const char null_byte = '\0'; char *data; int i = 0; @@ -612,7 +614,7 @@ static void process_alternates_response(void *callback_data) got_alternates = 1; } -static void fetch_alternates(char *base) +static void fetch_alternates(const char *base) { struct buffer buffer; char *url; @@ -1185,7 +1187,7 @@ int fetch_ref(char *ref, unsigned char *sha1) char *url; char hex[42]; struct buffer buffer; - char *base = alt->base; + const char *base = alt->base; struct active_request_slot *slot; struct slot_results results; buffer.size = 41; @@ -1214,11 +1216,12 @@ int fetch_ref(char *ref, unsigned char *sha1) return 0; } -int main(int argc, char **argv) +int main(int argc, const char **argv) { - const char *write_ref = NULL; - char *commit_id; - char *url; + int commits; + const char **write_ref = NULL; + char **commit_id; + const char *url; char *path; int arg = 1; int rc = 0; @@ -1238,19 +1241,26 @@ int main(int argc, char **argv) } else if (argv[arg][1] == 'v') { get_verbosely = 1; } else if (argv[arg][1] == 'w') { - write_ref = argv[arg + 1]; + write_ref = &argv[arg + 1]; arg++; } else if (!strcmp(argv[arg], "--recover")) { get_recover = 1; + } else if (!strcmp(argv[arg], "--stdin")) { + commits_on_stdin = 1; } arg++; } - if (argc < arg + 2) { - usage("git-http-fetch [-c] [-t] [-a] [-v] [--recover] [-w ref] commit-id url"); + if (argc < arg + 2 - commits_on_stdin) { + usage("git-http-fetch [-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url"); return 1; } - commit_id = argv[arg]; - url = argv[arg + 1]; + if (commits_on_stdin) { + commits = pull_targets_stdin(&commit_id, &write_ref); + } else { + commit_id = (char **) &argv[arg++]; + commits = 1; + } + url = argv[arg]; http_init(); @@ -1268,13 +1278,16 @@ int main(int argc, char **argv) alt->path_len = strlen(path); } - if (pull(1, &commit_id, &write_ref, url)) + if (pull(commits, commit_id, write_ref, url)) rc = 1; http_cleanup(); curl_slist_free_all(no_pragma_header); + if (commits_on_stdin) + pull_targets_free(commits, commit_id, write_ref); + if (corrupt_object_found) { fprintf(stderr, "Some loose object were found to be corrupt, but they might be just\n" From 5f468c4805c785115cd9c5f6a8f299f23a9034f5 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 27 Jul 2006 22:15:01 -0700 Subject: [PATCH 091/107] lost-found: use fsck-objects --full Signed-off-by: Junio C Hamano --- git-lost-found.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-lost-found.sh b/git-lost-found.sh index ba6d587f31..b928f2ca52 100755 --- a/git-lost-found.sh +++ b/git-lost-found.sh @@ -12,7 +12,7 @@ fi laf="$GIT_DIR/lost-found" rm -fr "$laf" && mkdir -p "$laf/commit" "$laf/other" || exit -git fsck-objects | +git fsck-objects --full | while read dangling type sha1 do case "$dangling" in From dee4e384f376020e08cb78f6dfaf00ae84e97a9e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 27 Jul 2006 22:27:44 -0700 Subject: [PATCH 092/107] git-reset: detect update-ref error and report it. Signed-off-by: Junio C Hamano --- git-reset.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/git-reset.sh b/git-reset.sh index 5c0224090a..36fc8ce25b 100755 --- a/git-reset.sh +++ b/git-reset.sh @@ -52,7 +52,8 @@ then else rm -f "$GIT_DIR/ORIG_HEAD" fi -git-update-ref -m "reset $reset_type $@" HEAD "$rev" +git-update-ref -m "reset $reset_type $*" HEAD "$rev" +update_ref_status=$? case "$reset_type" in --hard ) @@ -66,3 +67,5 @@ case "$reset_type" in esac rm -f "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/rr-cache/MERGE_RR" "$GIT_DIR/SQUASH_MSG" + +exit $update_ref_status From ef1d9c5aa4c8fd57b2a8043c0cd9fea1c507db6a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 27 Jul 2006 22:55:44 -0700 Subject: [PATCH 093/107] log and diff family: honor config even from subdirectories There currently is an unfortunate circular dependency between what init_revisions (the command line revision specification parser) does and setting up the log and diff options. The function uses setup_git_directory() to find the root of the project relative to the current directory and calls diff_setup() to prepare diff generation. However, some of the things that diff_setup() does needs to depend on the configuration variable, which needs to be read after setup_git_directory() is called. This patch is a low impact workaround. It first lets init_revisions() to run and do its thing, then uses git_config() and diff_setup() after it returns, so that configuration variables that affects the diff operation can be used from subdirectories. Signed-off-by: Junio C Hamano --- builtin-diff-files.c | 2 +- builtin-diff-index.c | 2 +- builtin-diff-tree.c | 2 +- builtin-diff.c | 3 ++- builtin-log.c | 9 ++++++--- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/builtin-diff-files.c b/builtin-diff-files.c index 81ac2fe64a..2e10118623 100644 --- a/builtin-diff-files.c +++ b/builtin-diff-files.c @@ -18,8 +18,8 @@ int cmd_diff_files(int argc, const char **argv, char **envp) struct rev_info rev; int silent = 0; - git_config(git_default_config); /* no "diff" UI options */ init_revisions(&rev); + git_config(git_default_config); /* no "diff" UI options */ rev.abbrev = 0; argc = setup_revisions(argc, argv, &rev, NULL); diff --git a/builtin-diff-index.c b/builtin-diff-index.c index a1fa1b85cf..dc52c054ee 100644 --- a/builtin-diff-index.c +++ b/builtin-diff-index.c @@ -15,8 +15,8 @@ int cmd_diff_index(int argc, const char **argv, char **envp) int cached = 0; int i; - git_config(git_default_config); /* no "diff" UI options */ init_revisions(&rev); + git_config(git_default_config); /* no "diff" UI options */ rev.abbrev = 0; argc = setup_revisions(argc, argv, &rev, NULL); diff --git a/builtin-diff-tree.c b/builtin-diff-tree.c index b610668594..8957b459de 100644 --- a/builtin-diff-tree.c +++ b/builtin-diff-tree.c @@ -67,9 +67,9 @@ int cmd_diff_tree(int argc, const char **argv, char **envp) static struct rev_info *opt = &log_tree_opt; int read_stdin = 0; + init_revisions(opt); git_config(git_default_config); /* no "diff" UI options */ nr_sha1 = 0; - init_revisions(opt); opt->abbrev = 0; opt->diff = 1; argc = setup_revisions(argc, argv, opt, NULL); diff --git a/builtin-diff.c b/builtin-diff.c index cb38f44561..7d5ad6271e 100644 --- a/builtin-diff.c +++ b/builtin-diff.c @@ -250,8 +250,9 @@ int cmd_diff(int argc, const char **argv, char **envp) * Other cases are errors. */ - git_config(git_diff_ui_config); init_revisions(&rev); + git_config(git_diff_ui_config); + diff_setup(&rev.diffopt); argc = setup_revisions(argc, argv, &rev, NULL); if (!rev.diffopt.output_format) { diff --git a/builtin-log.c b/builtin-log.c index 4052cc75bd..88c835acba 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -49,8 +49,9 @@ int cmd_whatchanged(int argc, const char **argv, char **envp) { struct rev_info rev; - git_config(git_diff_ui_config); init_revisions(&rev); + git_config(git_diff_ui_config); + diff_setup(&rev.diffopt); rev.diff = 1; rev.diffopt.recursive = 1; rev.simplify_history = 0; @@ -64,8 +65,9 @@ int cmd_show(int argc, const char **argv, char **envp) { struct rev_info rev; - git_config(git_diff_ui_config); init_revisions(&rev); + git_config(git_diff_ui_config); + diff_setup(&rev.diffopt); rev.diff = 1; rev.diffopt.recursive = 1; rev.combine_merges = 1; @@ -81,8 +83,9 @@ int cmd_log(int argc, const char **argv, char **envp) { struct rev_info rev; - git_config(git_diff_ui_config); init_revisions(&rev); + git_config(git_diff_ui_config); + diff_setup(&rev.diffopt); rev.always_show_header = 1; cmd_log_init(argc, argv, envp, &rev); return cmd_log_walk(&rev); From 2941cab99ca9dec3356f0126be41bc3995bb1fef Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 28 Jul 2006 11:17:46 +0200 Subject: [PATCH 094/107] Makefile: ssh-pull.o depends on ssh-fetch.c Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 49eaa10b3b..8349e3defa 100644 --- a/Makefile +++ b/Makefile @@ -614,6 +614,8 @@ $(SIMPLE_PROGRAMS) : git-%$X : %.o $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ $(LIB_FILE) $(SIMPLE_LIB) +ssh-pull.o: ssh-fetch.c +ssh-push.o: ssh-upload.c git-local-fetch$X: fetch.o git-ssh-fetch$X: rsh.o fetch.o git-ssh-upload$X: rsh.o From e5a94313c06b83e034179ca6092ea23343e48dec Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 28 Jul 2006 17:46:11 +0200 Subject: [PATCH 095/107] Teach git-apply about '-R' Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin-apply.c | 65 ++++++++++++++++++++++++++++++++++------- t/t4102-apply-rename.sh | 24 +++++++++++++-- 2 files changed, 77 insertions(+), 12 deletions(-) diff --git a/builtin-apply.c b/builtin-apply.c index d924ac3d0a..6b38a8ad0d 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -120,7 +120,7 @@ struct fragment { struct patch { char *new_name, *old_name, *def_name; unsigned int old_mode, new_mode; - int is_rename, is_copy, is_new, is_delete, is_binary; + int is_rename, is_copy, is_new, is_delete, is_binary, is_reverse; #define BINARY_DELTA_DEFLATED 1 #define BINARY_LITERAL_DEFLATED 2 unsigned long deflate_origlen; @@ -1119,6 +1119,34 @@ static int parse_chunk(char *buffer, unsigned long size, struct patch *patch) return offset + hdrsize + patchsize; } +#define swap(a,b) myswap((a),(b),sizeof(a)) + +#define myswap(a, b, size) do { \ + unsigned char mytmp[size]; \ + memcpy(mytmp, &a, size); \ + memcpy(&a, &b, size); \ + memcpy(&b, mytmp, size); \ +} while (0) + +static void reverse_patches(struct patch *p) +{ + for (; p; p = p->next) { + struct fragment *frag = p->fragments; + + swap(p->new_name, p->old_name); + swap(p->new_mode, p->old_mode); + swap(p->is_new, p->is_delete); + swap(p->lines_added, p->lines_deleted); + swap(p->old_sha1_prefix, p->new_sha1_prefix); + + for (; frag; frag = frag->next) { + swap(frag->newpos, frag->oldpos); + swap(frag->newlines, frag->oldlines); + } + p->is_reverse = !p->is_reverse; + } +} + static const char pluses[] = "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"; static const char minuses[]= "----------------------------------------------------------------------"; @@ -1336,7 +1364,7 @@ static int apply_line(char *output, const char *patch, int plen) } static int apply_one_fragment(struct buffer_desc *desc, struct fragment *frag, - int inaccurate_eof) + int reverse, int inaccurate_eof) { int match_beginning, match_end; char *buf = desc->buffer; @@ -1350,6 +1378,7 @@ static int apply_one_fragment(struct buffer_desc *desc, struct fragment *frag, int pos, lines; while (size > 0) { + char first; int len = linelen(patch, size); int plen; @@ -1366,16 +1395,23 @@ static int apply_one_fragment(struct buffer_desc *desc, struct fragment *frag, plen = len-1; if (len < size && patch[len] == '\\') plen--; - switch (*patch) { + first = *patch; + if (reverse) { + if (first == '-') + first = '+'; + else if (first == '+') + first = '-'; + } + switch (first) { case ' ': case '-': memcpy(old + oldsize, patch + 1, plen); oldsize += plen; - if (*patch == '-') + if (first == '-') break; /* Fall-through for ' ' */ case '+': - if (*patch != '+' || !no_add) + if (first != '+' || !no_add) newsize += apply_line(new + newsize, patch, plen); break; @@ -1615,7 +1651,8 @@ static int apply_fragments(struct buffer_desc *desc, struct patch *patch) return apply_binary(desc, patch); while (frag) { - if (apply_one_fragment(desc, frag, patch->inaccurate_eof) < 0) + if (apply_one_fragment(desc, frag, patch->is_reverse, + patch->inaccurate_eof) < 0) return error("patch failed: %s:%ld", name, frag->oldpos); frag = frag->next; @@ -2142,7 +2179,8 @@ static int use_patch(struct patch *p) return 1; } -static int apply_patch(int fd, const char *filename, int inaccurate_eof) +static int apply_patch(int fd, const char *filename, + int reverse, int inaccurate_eof) { unsigned long offset, size; char *buffer = read_patch_file(fd, &size); @@ -2162,6 +2200,8 @@ static int apply_patch(int fd, const char *filename, int inaccurate_eof) nr = parse_chunk(buffer + offset, size, patch); if (nr < 0) break; + if (reverse) + reverse_patches(patch); if (use_patch(patch)) { patch_stats(patch); *listp = patch; @@ -2226,6 +2266,7 @@ int cmd_apply(int argc, const char **argv, char **envp) { int i; int read_stdin = 1; + int reverse = 0; int inaccurate_eof = 0; const char *whitespace_option = NULL; @@ -2236,7 +2277,7 @@ int cmd_apply(int argc, const char **argv, char **envp) int fd; if (!strcmp(arg, "-")) { - apply_patch(0, "", inaccurate_eof); + apply_patch(0, "", reverse, inaccurate_eof); read_stdin = 0; continue; } @@ -2313,6 +2354,10 @@ int cmd_apply(int argc, const char **argv, char **envp) parse_whitespace_option(arg + 13); continue; } + if (!strcmp(arg, "-R") || !strcmp(arg, "--reverse")) { + reverse = 1; + continue; + } if (!strcmp(arg, "--inaccurate-eof")) { inaccurate_eof = 1; continue; @@ -2333,12 +2378,12 @@ int cmd_apply(int argc, const char **argv, char **envp) usage(apply_usage); read_stdin = 0; set_default_whitespace_mode(whitespace_option); - apply_patch(fd, arg, inaccurate_eof); + apply_patch(fd, arg, reverse, inaccurate_eof); close(fd); } set_default_whitespace_mode(whitespace_option); if (read_stdin) - apply_patch(0, "", inaccurate_eof); + apply_patch(0, "", reverse, inaccurate_eof); if (whitespace_error) { if (squelch_whitespace_errors && squelch_whitespace_errors < whitespace_error) { diff --git a/t/t4102-apply-rename.sh b/t/t4102-apply-rename.sh index fbb508d389..22da6a00cc 100755 --- a/t/t4102-apply-rename.sh +++ b/t/t4102-apply-rename.sh @@ -13,8 +13,8 @@ test_description='git-apply handling copy/rename patch. cat >test-patch <<\EOF diff --git a/foo b/bar similarity index 47% -copy from foo -copy to bar +rename from foo +rename to bar --- a/foo +++ b/bar @@ -1 +1 @@ @@ -39,4 +39,24 @@ else 'test -f bar && ls -l bar | grep "^-..x......"' fi +test_expect_success 'apply reverse' \ + 'git-apply -R --index --stat --summary --apply test-patch && + test "$(cat foo)" = "This is foo"' + +cat >test-patch <<\EOF +diff --git a/foo b/bar +similarity index 47% +copy from foo +copy to bar +--- a/foo ++++ b/bar +@@ -1 +1 @@ +-This is foo ++This is bar +EOF + +test_expect_success 'apply copy' \ + 'git-apply --index --stat --summary --apply test-patch && + test "$(cat bar)" = "This is bar" -a "$(cat foo)" = "This is foo"' + test_done From ab9f30fd7538ec5385bf5a3d11117f23f4f320ee Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 28 Jul 2006 12:21:17 -0700 Subject: [PATCH 096/107] git-apply -R: binary patches are irreversible for now. Signed-off-by: Junio C Hamano --- builtin-apply.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/builtin-apply.c b/builtin-apply.c index 6b38a8ad0d..d4381d9a8f 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -1535,6 +1535,12 @@ static int apply_binary_fragment(struct buffer_desc *desc, struct patch *patch) void *data; void *result; + /* Binary patch is irreversible */ + if (patch->is_reverse) + return error("cannot reverse-apply a binary patch to '%s'", + patch->new_name + ? patch->new_name : patch->old_name); + data = inflate_it(fragment->patch, fragment->size, patch->deflate_origlen); if (!data) From 5afa69b415fd020d6dd36751bdcf45fdbf07dd4a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 28 Jul 2006 12:23:28 -0700 Subject: [PATCH 097/107] t4103: fix binary patch application test. The generated binary patch was _not_ binary -- earlier I made the --full-index flag to imply binary patch generation to the diff machinery, but later we made it independent from --binary (although the latter implies the former). Signed-off-by: Junio C Hamano --- t/t4103-apply-binary.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t4103-apply-binary.sh b/t/t4103-apply-binary.sh index 00bd8b15c6..ff052699a2 100755 --- a/t/t4103-apply-binary.sh +++ b/t/t4103-apply-binary.sh @@ -35,8 +35,8 @@ git-commit -m 'Second Version' git-diff-tree -p master binary >B.diff git-diff-tree -p -C master binary >C.diff -git-diff-tree -p --full-index master binary >BF.diff -git-diff-tree -p --full-index -C master binary >CF.diff +git-diff-tree -p --binary master binary >BF.diff +git-diff-tree -p --binary -C master binary >CF.diff test_expect_success 'stat binary diff -- should not fail.' \ 'git-checkout master From 1b03dfed182a1dc47cc0eb1047a34cd914440ce6 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 29 Jul 2006 02:10:07 +0200 Subject: [PATCH 098/107] Fix http-fetch With the latest changes in fetch.c, http-fetch crashed accessing write_ref[i], where write_ref was NULL. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- fetch.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fetch.c b/fetch.c index 2151c7b78c..aeb6bf2639 100644 --- a/fetch.c +++ b/fetch.c @@ -245,7 +245,7 @@ void pull_targets_free(int targets, char **target, const char **write_ref) { while (targets--) { free(target[targets]); - if (write_ref[targets]) + if (write_ref && write_ref[targets]) free((char *) write_ref[targets]); } } @@ -263,7 +263,7 @@ int pull(int targets, char **target, const char **write_ref, track_object_refs = 0; for (i = 0; i < targets; i++) { - if (!write_ref[i]) + if (!write_ref || !write_ref[i]) continue; lock[i] = lock_ref_sha1(write_ref[i], NULL, 0); @@ -295,7 +295,7 @@ int pull(int targets, char **target, const char **write_ref, msg = NULL; } for (i = 0; i < targets; i++) { - if (!write_ref[i]) + if (!write_ref || !write_ref[i]) continue; ret = write_ref_sha1(lock[i], &sha1[20 * i], msg ? msg : "fetch (unknown)"); lock[i] = NULL; From 818f477c40fee62ab8ea5b493c51bb357f38957c Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Fri, 28 Jul 2006 23:44:51 -0400 Subject: [PATCH 099/107] Display an error from update-ref if target ref name is invalid. Alex Riesen (raa.lkml@gmail.com) recently observed that git branch would fail with no error message due to unexpected situations with regards to refs. For example, if .git/refs/heads/gu is a file but "git branch -b refs/heads/gu/fixa HEAD" was invoked by the user it would fail silently due to refs/heads/gu being a file and not a directory. This change adds a test for trying to create a ref within a directory that is actually currently a file, and adds error printing within the ref locking routine should the resolve operation fail. The error printing code probably belongs at this level of the library as other failures within the ref locking, writing and logging code are also currently at this level of the code. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- refs.c | 5 +++++ t/t1400-update-ref.sh | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/refs.c b/refs.c index 56db394459..02850b6908 100644 --- a/refs.c +++ b/refs.c @@ -294,6 +294,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *path, int plen, const unsigned char *old_sha1, int mustexist) { + const char *orig_path = path; struct ref_lock *lock; struct stat st; @@ -303,7 +304,11 @@ static struct ref_lock *lock_ref_sha1_basic(const char *path, plen = strlen(path) - plen; path = resolve_ref(path, lock->old_sha1, mustexist); if (!path) { + int last_errno = errno; + error("unable to resolve reference %s: %s", + orig_path, strerror(errno)); unlock_ref(lock); + errno = last_errno; return NULL; } lock->lk = xcalloc(1, sizeof(struct lock_file)); diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 04fab26621..ddc80bbeae 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -14,6 +14,8 @@ D=4444444444444444444444444444444444444444 E=5555555555555555555555555555555555555555 F=6666666666666666666666666666666666666666 m=refs/heads/master +n_dir=refs/heads/gu +n=$n_dir/fixes test_expect_success \ "create $m" \ @@ -25,6 +27,16 @@ test_expect_success \ test $B = $(cat .git/$m)' rm -f .git/$m +test_expect_success \ + "fail to create $n" \ + 'touch .git/$n_dir + git-update-ref $n $A >out 2>err + test $? = 1 && + test "" = "$(cat out)" && + grep "error: unable to resolve reference" err && + grep $n err' +rm -f .git/$n_dir out err + test_expect_success \ "create $m (by HEAD)" \ 'git-update-ref HEAD $A && From db6296a566eb1a8007a84330a911b38055720743 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 28 Jul 2006 21:21:48 -0700 Subject: [PATCH 100/107] Call setup_git_directory() early Any git command that expects to work in a subdirectory of a project, and that reads the git config files (which is just about all of them) needs to make sure that it does the "setup_git_directory()" call before it tries to read the config file. This means, among other things, that we need to move the call out of "init_revisions()", and into the caller. This does the mostly trivial conversion to do that. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- blame.c | 2 +- builtin-diff-files.c | 2 +- builtin-diff-index.c | 2 +- builtin-diff-tree.c | 2 +- builtin-diff.c | 6 +++--- builtin-fmt-merge-msg.c | 3 ++- builtin-log.c | 18 ++++++++++-------- builtin-prune.c | 2 +- builtin-rev-list.c | 2 +- http-push.c | 2 +- revision.c | 4 ++-- revision.h | 2 +- 12 files changed, 25 insertions(+), 22 deletions(-) diff --git a/blame.c b/blame.c index b04b8f58aa..76712b5962 100644 --- a/blame.c +++ b/blame.c @@ -834,7 +834,7 @@ int main(int argc, const char **argv) } - init_revisions(&rev); + init_revisions(&rev, setup_git_directory()); rev.remove_empty_trees = 1; rev.topo_order = 1; rev.prune_fn = simplify_commit; diff --git a/builtin-diff-files.c b/builtin-diff-files.c index 2e10118623..ea2936a5ec 100644 --- a/builtin-diff-files.c +++ b/builtin-diff-files.c @@ -18,7 +18,7 @@ int cmd_diff_files(int argc, const char **argv, char **envp) struct rev_info rev; int silent = 0; - init_revisions(&rev); + init_revisions(&rev, setup_git_directory()); git_config(git_default_config); /* no "diff" UI options */ rev.abbrev = 0; diff --git a/builtin-diff-index.c b/builtin-diff-index.c index dc52c054ee..eeeee93fb7 100644 --- a/builtin-diff-index.c +++ b/builtin-diff-index.c @@ -15,7 +15,7 @@ int cmd_diff_index(int argc, const char **argv, char **envp) int cached = 0; int i; - init_revisions(&rev); + init_revisions(&rev, setup_git_directory()); git_config(git_default_config); /* no "diff" UI options */ rev.abbrev = 0; diff --git a/builtin-diff-tree.c b/builtin-diff-tree.c index 8957b459de..f8215ea707 100644 --- a/builtin-diff-tree.c +++ b/builtin-diff-tree.c @@ -67,7 +67,7 @@ int cmd_diff_tree(int argc, const char **argv, char **envp) static struct rev_info *opt = &log_tree_opt; int read_stdin = 0; - init_revisions(opt); + init_revisions(opt, setup_git_directory()); git_config(git_default_config); /* no "diff" UI options */ nr_sha1 = 0; opt->abbrev = 0; diff --git a/builtin-diff.c b/builtin-diff.c index dca223235d..45b27cfca3 100644 --- a/builtin-diff.c +++ b/builtin-diff.c @@ -227,7 +227,7 @@ int cmd_diff(int argc, const char **argv, char **envp) struct rev_info rev; struct object_array_entry ent[100]; int ents = 0, blobs = 0, paths = 0; - const char *path = NULL; + const char *path = NULL, *prefix; struct blobinfo blob[2]; /* @@ -250,9 +250,9 @@ int cmd_diff(int argc, const char **argv, char **envp) * Other cases are errors. */ - init_revisions(&rev); + prefix = setup_git_directory(); git_config(git_diff_ui_config); - diff_setup(&rev.diffopt); + init_revisions(&rev, prefix); argc = setup_revisions(argc, argv, &rev, NULL); if (!rev.diffopt.output_format) { diff --git a/builtin-fmt-merge-msg.c b/builtin-fmt-merge-msg.c index f20b27b8a9..338f2094f3 100644 --- a/builtin-fmt-merge-msg.c +++ b/builtin-fmt-merge-msg.c @@ -250,6 +250,7 @@ int cmd_fmt_merge_msg(int argc, char **argv, char **envp) const char *sep = ""; unsigned char head_sha1[20]; const char *head, *current_branch; + const char *prefix = setup_git_directory(); git_config(fmt_merge_msg_config); @@ -342,7 +343,7 @@ int cmd_fmt_merge_msg(int argc, char **argv, char **envp) struct rev_info rev; head = lookup_commit(head_sha1); - init_revisions(&rev); + init_revisions(&rev, prefix); rev.commit_format = CMIT_FMT_ONELINE; rev.ignore_merges = 1; rev.limited = 1; diff --git a/builtin-log.c b/builtin-log.c index 88c835acba..52064cd178 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -48,10 +48,10 @@ static int cmd_log_walk(struct rev_info *rev) int cmd_whatchanged(int argc, const char **argv, char **envp) { struct rev_info rev; + const char *prefix = setup_git_directory(); - init_revisions(&rev); git_config(git_diff_ui_config); - diff_setup(&rev.diffopt); + init_revisions(&rev, prefix); rev.diff = 1; rev.diffopt.recursive = 1; rev.simplify_history = 0; @@ -64,10 +64,10 @@ int cmd_whatchanged(int argc, const char **argv, char **envp) int cmd_show(int argc, const char **argv, char **envp) { struct rev_info rev; + const char *prefix = setup_git_directory(); - init_revisions(&rev); git_config(git_diff_ui_config); - diff_setup(&rev.diffopt); + init_revisions(&rev, prefix); rev.diff = 1; rev.diffopt.recursive = 1; rev.combine_merges = 1; @@ -82,10 +82,10 @@ int cmd_show(int argc, const char **argv, char **envp) int cmd_log(int argc, const char **argv, char **envp) { struct rev_info rev; + const char *prefix = setup_git_directory(); - init_revisions(&rev); git_config(git_diff_ui_config); - diff_setup(&rev.diffopt); + init_revisions(&rev, prefix); rev.always_show_header = 1; cmd_log_init(argc, argv, envp, &rev); return cmd_log_walk(&rev); @@ -188,6 +188,7 @@ static void get_patch_ids(struct rev_info *rev, struct diff_options *options) struct object *o1, *o2; unsigned flags1, flags2; unsigned char sha1[20]; + const char *prefix = setup_git_directory(); if (rev->pending.nr != 2) die("Need exactly one range."); @@ -206,7 +207,7 @@ static void get_patch_ids(struct rev_info *rev, struct diff_options *options) die("diff_setup_done failed"); /* given a range a..b get all patch ids for b..a */ - init_revisions(&check_rev); + init_revisions(&check_rev, prefix); o1->flags ^= UNINTERESTING; o2->flags ^= UNINTERESTING; add_pending_object(&check_rev, o1, "o1"); @@ -260,9 +261,10 @@ int cmd_format_patch(int argc, const char **argv, char **envp) char *add_signoff = NULL; char message_id[1024]; char ref_message_id[1024]; + const char *prefix = setup_git_directory(); git_config(git_format_config); - init_revisions(&rev); + init_revisions(&rev, prefix); rev.commit_format = CMIT_FMT_EMAIL; rev.verbose_header = 1; rev.diff = 1; diff --git a/builtin-prune.c b/builtin-prune.c index d196c41f13..4ed1e1b43c 100644 --- a/builtin-prune.c +++ b/builtin-prune.c @@ -234,7 +234,7 @@ int cmd_prune(int argc, const char **argv, char **envp) * Set up revision parsing, and mark us as being interested * in all object types, not just commits. */ - init_revisions(&revs); + init_revisions(&revs, setup_git_directory()); revs.tag_objects = 1; revs.blob_objects = 1; revs.tree_objects = 1; diff --git a/builtin-rev-list.c b/builtin-rev-list.c index 8f32871337..2b6691c8e4 100644 --- a/builtin-rev-list.c +++ b/builtin-rev-list.c @@ -311,7 +311,7 @@ int cmd_rev_list(int argc, const char **argv, char **envp) struct commit_list *list; int i; - init_revisions(&revs); + init_revisions(&revs, setup_git_directory()); revs.abbrev = 0; revs.commit_format = CMIT_FMT_UNSPECIFIED; argc = setup_revisions(argc, argv, &revs, NULL); diff --git a/http-push.c b/http-push.c index 47686195cd..4021e7d927 100644 --- a/http-push.c +++ b/http-push.c @@ -2521,7 +2521,7 @@ int main(int argc, char **argv) commit_argv[3] = old_sha1_hex; commit_argc++; } - init_revisions(&revs); + init_revisions(&revs, setup_git_directory()); setup_revisions(commit_argc, commit_argv, &revs, NULL); free(new_sha1_hex); if (old_sha1_hex) { diff --git a/revision.c b/revision.c index 874e349db8..a58257ad80 100644 --- a/revision.c +++ b/revision.c @@ -509,7 +509,7 @@ static int add_parents_only(struct rev_info *revs, const char *arg, int flags) return 1; } -void init_revisions(struct rev_info *revs) +void init_revisions(struct rev_info *revs, const char *prefix) { memset(revs, 0, sizeof(*revs)); @@ -521,7 +521,7 @@ void init_revisions(struct rev_info *revs) revs->pruning.change = file_change; revs->lifo = 1; revs->dense = 1; - revs->prefix = setup_git_directory(); + revs->prefix = prefix; revs->max_age = -1; revs->min_age = -1; revs->max_count = -1; diff --git a/revision.h b/revision.h index e23ec8f45a..0c3b8d9905 100644 --- a/revision.h +++ b/revision.h @@ -87,7 +87,7 @@ struct rev_info { extern int rev_same_tree_as_empty(struct rev_info *, struct tree *t1); extern int rev_compare_tree(struct rev_info *, struct tree *t1, struct tree *t2); -extern void init_revisions(struct rev_info *revs); +extern void init_revisions(struct rev_info *revs, const char *prefix); extern int setup_revisions(int argc, const char **argv, struct rev_info *revs, const char *def); extern void prepare_revision_walk(struct rev_info *revs); extern struct commit *get_revision(struct rev_info *revs); From a633fca0c056aa221d23493c276d3713191621b3 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 28 Jul 2006 22:44:25 -0700 Subject: [PATCH 101/107] Call setup_git_directory() much earlier This changes the calling convention of built-in commands and passes the "prefix" (i.e. pathname of $PWD relative to the project root level) down to them. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- builtin-add.c | 3 +- builtin-apply.c | 2 +- builtin-cat-file.c | 3 +- builtin-check-ref-format.c | 2 +- builtin-commit-tree.c | 4 +- builtin-count.c | 2 +- builtin-diff-files.c | 4 +- builtin-diff-index.c | 4 +- builtin-diff-stages.c | 3 +- builtin-diff-tree.c | 4 +- builtin-diff.c | 5 +-- builtin-fmt-merge-msg.c | 3 +- builtin-grep.c | 3 +- builtin-help.c | 4 +- builtin-init-db.c | 2 +- builtin-log.c | 25 +++++-------- builtin-ls-files.c | 3 +- builtin-ls-tree.c | 8 ++-- builtin-mailinfo.c | 2 +- builtin-mailsplit.c | 2 +- builtin-prune.c | 4 +- builtin-push.c | 2 +- builtin-read-tree.c | 3 +- builtin-rev-list.c | 4 +- builtin-rev-parse.c | 3 +- builtin-rm.c | 3 +- builtin-show-branch.c | 3 +- builtin-stripspace.c | 2 +- builtin-tar-tree.c | 9 ++--- builtin-update-index.c | 3 +- builtin-update-ref.c | 3 +- builtin-upload-tar.c | 2 +- builtin-write-tree.c | 4 +- builtin.h | 76 +++++++++++++++++++------------------- git.c | 63 +++++++++++++++++-------------- 35 files changed, 128 insertions(+), 144 deletions(-) diff --git a/builtin-add.c b/builtin-add.c index 3a73a173f7..0fa7dc1f11 100644 --- a/builtin-add.c +++ b/builtin-add.c @@ -123,11 +123,10 @@ static int add_file_to_index(const char *path, int verbose) static struct lock_file lock_file; -int cmd_add(int argc, const char **argv, char **envp) +int cmd_add(int argc, const char **argv, const char *prefix) { int i, newfd; int verbose = 0, show_only = 0; - const char *prefix = setup_git_directory(); const char **pathspec; struct dir_struct dir; diff --git a/builtin-apply.c b/builtin-apply.c index d4381d9a8f..f8c6763c74 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -2268,7 +2268,7 @@ static int git_apply_config(const char *var, const char *value) } -int cmd_apply(int argc, const char **argv, char **envp) +int cmd_apply(int argc, const char **argv, const char *prefix) { int i; int read_stdin = 1; diff --git a/builtin-cat-file.c b/builtin-cat-file.c index 4d36817e5f..814fb0743f 100644 --- a/builtin-cat-file.c +++ b/builtin-cat-file.c @@ -94,7 +94,7 @@ static int pprint_tag(const unsigned char *sha1, const char *buf, unsigned long return 0; } -int cmd_cat_file(int argc, const char **argv, char **envp) +int cmd_cat_file(int argc, const char **argv, const char *prefix) { unsigned char sha1[20]; char type[20]; @@ -102,7 +102,6 @@ int cmd_cat_file(int argc, const char **argv, char **envp) unsigned long size; int opt; - setup_git_directory(); git_config(git_default_config); if (argc != 3) usage("git-cat-file [-t|-s|-e|-p|] "); diff --git a/builtin-check-ref-format.c b/builtin-check-ref-format.c index 4a23936aff..701de439ae 100644 --- a/builtin-check-ref-format.c +++ b/builtin-check-ref-format.c @@ -6,7 +6,7 @@ #include "refs.h" #include "builtin.h" -int cmd_check_ref_format(int argc, const char **argv, char **envp) +int cmd_check_ref_format(int argc, const char **argv, const char *prefix) { if (argc != 2) usage("git check-ref-format refname"); diff --git a/builtin-commit-tree.c b/builtin-commit-tree.c index ec082bf754..9c98796671 100644 --- a/builtin-commit-tree.c +++ b/builtin-commit-tree.c @@ -77,7 +77,7 @@ static int new_parent(int idx) return 1; } -int cmd_commit_tree(int argc, const char **argv, char **envp) +int cmd_commit_tree(int argc, const char **argv, const char *prefix) { int i; int parents = 0; @@ -88,8 +88,6 @@ int cmd_commit_tree(int argc, const char **argv, char **envp) unsigned int size; setup_ident(); - setup_git_directory(); - git_config(git_default_config); if (argc < 2) diff --git a/builtin-count.c b/builtin-count.c index 5ee72df247..1d3729aa99 100644 --- a/builtin-count.c +++ b/builtin-count.c @@ -67,7 +67,7 @@ static void count_objects(DIR *d, char *path, int len, int verbose, } } -int cmd_count_objects(int ac, const char **av, char **ep) +int cmd_count_objects(int ac, const char **av, const char *prefix) { int i; int verbose = 0; diff --git a/builtin-diff-files.c b/builtin-diff-files.c index ea2936a5ec..ac13db70ff 100644 --- a/builtin-diff-files.c +++ b/builtin-diff-files.c @@ -13,12 +13,12 @@ static const char diff_files_usage[] = "git-diff-files [-q] [-0/-1/2/3 |-c|--cc] [] [...]" COMMON_DIFF_OPTIONS_HELP; -int cmd_diff_files(int argc, const char **argv, char **envp) +int cmd_diff_files(int argc, const char **argv, const char *prefix) { struct rev_info rev; int silent = 0; - init_revisions(&rev, setup_git_directory()); + init_revisions(&rev, prefix); git_config(git_default_config); /* no "diff" UI options */ rev.abbrev = 0; diff --git a/builtin-diff-index.c b/builtin-diff-index.c index eeeee93fb7..95a3db156b 100644 --- a/builtin-diff-index.c +++ b/builtin-diff-index.c @@ -9,13 +9,13 @@ static const char diff_cache_usage[] = "[] [...]" COMMON_DIFF_OPTIONS_HELP; -int cmd_diff_index(int argc, const char **argv, char **envp) +int cmd_diff_index(int argc, const char **argv, const char *prefix) { struct rev_info rev; int cached = 0; int i; - init_revisions(&rev, setup_git_directory()); + init_revisions(&rev, prefix); git_config(git_default_config); /* no "diff" UI options */ rev.abbrev = 0; diff --git a/builtin-diff-stages.c b/builtin-diff-stages.c index 9c62702941..5960e08997 100644 --- a/builtin-diff-stages.c +++ b/builtin-diff-stages.c @@ -55,10 +55,9 @@ static void diff_stages(int stage1, int stage2, const char **pathspec) } } -int cmd_diff_stages(int ac, const char **av, char **envp) +int cmd_diff_stages(int ac, const char **av, const char *prefix) { int stage1, stage2; - const char *prefix = setup_git_directory(); const char **pathspec = NULL; git_config(git_default_config); /* no "diff" UI options */ diff --git a/builtin-diff-tree.c b/builtin-diff-tree.c index f8215ea707..24cb2d7f84 100644 --- a/builtin-diff-tree.c +++ b/builtin-diff-tree.c @@ -59,7 +59,7 @@ static const char diff_tree_usage[] = " --root include the initial commit as diff against /dev/null\n" COMMON_DIFF_OPTIONS_HELP; -int cmd_diff_tree(int argc, const char **argv, char **envp) +int cmd_diff_tree(int argc, const char **argv, const char *prefix) { int nr_sha1; char line[1000]; @@ -67,7 +67,7 @@ int cmd_diff_tree(int argc, const char **argv, char **envp) static struct rev_info *opt = &log_tree_opt; int read_stdin = 0; - init_revisions(opt, setup_git_directory()); + init_revisions(opt, prefix); git_config(git_default_config); /* no "diff" UI options */ nr_sha1 = 0; opt->abbrev = 0; diff --git a/builtin-diff.c b/builtin-diff.c index 45b27cfca3..48d2fd03b7 100644 --- a/builtin-diff.c +++ b/builtin-diff.c @@ -221,13 +221,13 @@ void add_head(struct rev_info *revs) add_pending_object(revs, obj, "HEAD"); } -int cmd_diff(int argc, const char **argv, char **envp) +int cmd_diff(int argc, const char **argv, const char *prefix) { int i; struct rev_info rev; struct object_array_entry ent[100]; int ents = 0, blobs = 0, paths = 0; - const char *path = NULL, *prefix; + const char *path = NULL; struct blobinfo blob[2]; /* @@ -250,7 +250,6 @@ int cmd_diff(int argc, const char **argv, char **envp) * Other cases are errors. */ - prefix = setup_git_directory(); git_config(git_diff_ui_config); init_revisions(&rev, prefix); diff --git a/builtin-fmt-merge-msg.c b/builtin-fmt-merge-msg.c index 338f2094f3..c84224ee84 100644 --- a/builtin-fmt-merge-msg.c +++ b/builtin-fmt-merge-msg.c @@ -242,7 +242,7 @@ static void shortlog(const char *name, unsigned char *sha1, free_list(&subjects); } -int cmd_fmt_merge_msg(int argc, char **argv, char **envp) +int cmd_fmt_merge_msg(int argc, char **argv, const char *prefix) { int limit = 20, i = 0; char line[1024]; @@ -250,7 +250,6 @@ int cmd_fmt_merge_msg(int argc, char **argv, char **envp) const char *sep = ""; unsigned char head_sha1[20]; const char *head, *current_branch; - const char *prefix = setup_git_directory(); git_config(fmt_merge_msg_config); diff --git a/builtin-grep.c b/builtin-grep.c index a79bac305a..69b7c4862a 100644 --- a/builtin-grep.c +++ b/builtin-grep.c @@ -919,14 +919,13 @@ static const char emsg_missing_context_len[] = static const char emsg_missing_argument[] = "option requires an argument -%s"; -int cmd_grep(int argc, const char **argv, char **envp) +int cmd_grep(int argc, const char **argv, const char *prefix) { int hit = 0; int cached = 0; int seen_dashdash = 0; struct grep_opt opt; struct object_array list = { 0, 0, NULL }; - const char *prefix = setup_git_directory(); const char **paths = NULL; int i; diff --git a/builtin-help.c b/builtin-help.c index bc1b4da3bc..bb0b03f1ae 100644 --- a/builtin-help.c +++ b/builtin-help.c @@ -221,13 +221,13 @@ static void show_man_page(const char *git_cmd) execlp("man", "man", page, NULL); } -int cmd_version(int argc, const char **argv, char **envp) +int cmd_version(int argc, const char **argv, const char *prefix) { printf("git version %s\n", git_version_string); return 0; } -int cmd_help(int argc, const char **argv, char **envp) +int cmd_help(int argc, const char **argv, const char *prefix) { const char *help_cmd = argc > 1 ? argv[1] : NULL; if (!help_cmd) diff --git a/builtin-init-db.c b/builtin-init-db.c index 7fdd2fa9f9..52473edf56 100644 --- a/builtin-init-db.c +++ b/builtin-init-db.c @@ -250,7 +250,7 @@ static const char init_db_usage[] = * On the other hand, it might just make lookup slower and messier. You * be the judge. The default case is to have one DB per managed directory. */ -int cmd_init_db(int argc, const char **argv, char **envp) +int cmd_init_db(int argc, const char **argv, const char *prefix) { const char *git_dir; const char *sha1_dir; diff --git a/builtin-log.c b/builtin-log.c index 52064cd178..82c69d1d05 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -16,7 +16,7 @@ /* this is in builtin-diff.c */ void add_head(struct rev_info *revs); -static void cmd_log_init(int argc, const char **argv, char **envp, +static void cmd_log_init(int argc, const char **argv, const char *prefix, struct rev_info *rev) { rev->abbrev = DEFAULT_ABBREV; @@ -45,26 +45,24 @@ static int cmd_log_walk(struct rev_info *rev) return 0; } -int cmd_whatchanged(int argc, const char **argv, char **envp) +int cmd_whatchanged(int argc, const char **argv, const char *prefix) { struct rev_info rev; - const char *prefix = setup_git_directory(); git_config(git_diff_ui_config); init_revisions(&rev, prefix); rev.diff = 1; rev.diffopt.recursive = 1; rev.simplify_history = 0; - cmd_log_init(argc, argv, envp, &rev); + cmd_log_init(argc, argv, prefix, &rev); if (!rev.diffopt.output_format) rev.diffopt.output_format = DIFF_FORMAT_RAW; return cmd_log_walk(&rev); } -int cmd_show(int argc, const char **argv, char **envp) +int cmd_show(int argc, const char **argv, const char *prefix) { struct rev_info rev; - const char *prefix = setup_git_directory(); git_config(git_diff_ui_config); init_revisions(&rev, prefix); @@ -75,19 +73,18 @@ int cmd_show(int argc, const char **argv, char **envp) rev.always_show_header = 1; rev.ignore_merges = 0; rev.no_walk = 1; - cmd_log_init(argc, argv, envp, &rev); + cmd_log_init(argc, argv, prefix, &rev); return cmd_log_walk(&rev); } -int cmd_log(int argc, const char **argv, char **envp) +int cmd_log(int argc, const char **argv, const char *prefix) { struct rev_info rev; - const char *prefix = setup_git_directory(); git_config(git_diff_ui_config); init_revisions(&rev, prefix); rev.always_show_header = 1; - cmd_log_init(argc, argv, envp, &rev); + cmd_log_init(argc, argv, prefix, &rev); return cmd_log_walk(&rev); } @@ -181,14 +178,13 @@ static int get_patch_id(struct commit *commit, struct diff_options *options, return diff_flush_patch_id(options, sha1); } -static void get_patch_ids(struct rev_info *rev, struct diff_options *options) +static void get_patch_ids(struct rev_info *rev, struct diff_options *options, const char *prefix) { struct rev_info check_rev; struct commit *commit; struct object *o1, *o2; unsigned flags1, flags2; unsigned char sha1[20]; - const char *prefix = setup_git_directory(); if (rev->pending.nr != 2) die("Need exactly one range."); @@ -244,7 +240,7 @@ static void gen_message_id(char *dest, unsigned int length, char *base) (int)(email_end - email_start - 1), email_start + 1); } -int cmd_format_patch(int argc, const char **argv, char **envp) +int cmd_format_patch(int argc, const char **argv, const char *prefix) { struct commit *commit; struct commit **list = NULL; @@ -261,7 +257,6 @@ int cmd_format_patch(int argc, const char **argv, char **envp) char *add_signoff = NULL; char message_id[1024]; char ref_message_id[1024]; - const char *prefix = setup_git_directory(); git_config(git_format_config); init_revisions(&rev, prefix); @@ -368,7 +363,7 @@ int cmd_format_patch(int argc, const char **argv, char **envp) } if (ignore_if_in_upstream) - get_patch_ids(&rev, &patch_id_opts); + get_patch_ids(&rev, &patch_id_opts, prefix); if (!use_stdout) realstdout = fdopen(dup(1), "w"); diff --git a/builtin-ls-files.c b/builtin-ls-files.c index 8dae9f70e2..79ffe8f423 100644 --- a/builtin-ls-files.c +++ b/builtin-ls-files.c @@ -322,14 +322,13 @@ static const char ls_files_usage[] = "[ --exclude-per-directory= ] [--full-name] [--abbrev] " "[--] []*"; -int cmd_ls_files(int argc, const char **argv, char** envp) +int cmd_ls_files(int argc, const char **argv, const char *prefix) { int i; int exc_given = 0; struct dir_struct dir; memset(&dir, 0, sizeof(dir)); - prefix = setup_git_directory(); if (prefix) prefix_offset = strlen(prefix); git_config(git_default_config); diff --git a/builtin-ls-tree.c b/builtin-ls-tree.c index b8d0d88ba8..261147fdbe 100644 --- a/builtin-ls-tree.c +++ b/builtin-ls-tree.c @@ -18,7 +18,7 @@ static int abbrev = 0; static int ls_options = 0; static const char **pathspec; static int chomp_prefix = 0; -static const char *prefix; +static const char *ls_tree_prefix; static const char ls_tree_usage[] = "git-ls-tree [-d] [-r] [-t] [-z] [--name-only] [--name-status] [--full-name] [--abbrev[=]] [path...]"; @@ -71,7 +71,7 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen, return 0; if (chomp_prefix && - (baselen < chomp_prefix || memcmp(prefix, base, chomp_prefix))) + (baselen < chomp_prefix || memcmp(ls_tree_prefix, base, chomp_prefix))) return 0; if (!(ls_options & LS_NAME_ONLY)) @@ -85,13 +85,13 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen, return retval; } -int cmd_ls_tree(int argc, const char **argv, char **envp) +int cmd_ls_tree(int argc, const char **argv, const char *prefix) { unsigned char sha1[20]; struct tree *tree; - prefix = setup_git_directory(); git_config(git_default_config); + ls_tree_prefix = prefix; if (prefix && *prefix) chomp_prefix = strlen(prefix); while (1 < argc && argv[1][0] == '-') { diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c index 05dc1bfe71..24a4fc63b3 100644 --- a/builtin-mailinfo.c +++ b/builtin-mailinfo.c @@ -836,7 +836,7 @@ int mailinfo(FILE *in, FILE *out, int ks, const char *encoding, static const char mailinfo_usage[] = "git-mailinfo [-k] [-u | --encoding=] msg patch info"; -int cmd_mailinfo(int argc, const char **argv, char **envp) +int cmd_mailinfo(int argc, const char **argv, const char *prefix) { /* NEEDSWORK: might want to do the optional .git/ directory * discovery diff --git a/builtin-mailsplit.c b/builtin-mailsplit.c index e2a0058435..91a699d34d 100644 --- a/builtin-mailsplit.c +++ b/builtin-mailsplit.c @@ -138,7 +138,7 @@ out: free(name); return ret; } -int cmd_mailsplit(int argc, const char **argv, char **envp) +int cmd_mailsplit(int argc, const char **argv, const char *prefix) { int nr = 0, nr_prec = 4, ret; int allow_bare = 0; diff --git a/builtin-prune.c b/builtin-prune.c index 4ed1e1b43c..6a86eb52ae 100644 --- a/builtin-prune.c +++ b/builtin-prune.c @@ -217,7 +217,7 @@ static void add_cache_refs(void) add_cache_tree(active_cache_tree); } -int cmd_prune(int argc, const char **argv, char **envp) +int cmd_prune(int argc, const char **argv, const char *prefix) { int i; @@ -234,7 +234,7 @@ int cmd_prune(int argc, const char **argv, char **envp) * Set up revision parsing, and mark us as being interested * in all object types, not just commits. */ - init_revisions(&revs, setup_git_directory()); + init_revisions(&revs, prefix); revs.tag_objects = 1; revs.blob_objects = 1; revs.tree_objects = 1; diff --git a/builtin-push.c b/builtin-push.c index 31cbfd7386..a824171066 100644 --- a/builtin-push.c +++ b/builtin-push.c @@ -270,7 +270,7 @@ static int do_push(const char *repo) return 0; } -int cmd_push(int argc, const char **argv, char **envp) +int cmd_push(int argc, const char **argv, const char *prefix) { int i; const char *repo = "origin"; /* default repository */ diff --git a/builtin-read-tree.c b/builtin-read-tree.c index 122b6f130b..49c10bf221 100644 --- a/builtin-read-tree.c +++ b/builtin-read-tree.c @@ -870,7 +870,7 @@ static const char read_tree_usage[] = "git-read-tree ( | [[-m [--aggressive static struct lock_file lock_file; -int cmd_read_tree(int argc, const char **argv, char **envp) +int cmd_read_tree(int argc, const char **argv, const char *prefix) { int i, newfd, stage = 0; unsigned char sha1[20]; @@ -882,7 +882,6 @@ int cmd_read_tree(int argc, const char **argv, char **envp) state.quiet = 1; state.refresh_cache = 1; - setup_git_directory(); git_config(git_default_config); newfd = hold_lock_file_for_update(&lock_file, get_index_file()); diff --git a/builtin-rev-list.c b/builtin-rev-list.c index 2b6691c8e4..0dee1734a3 100644 --- a/builtin-rev-list.c +++ b/builtin-rev-list.c @@ -306,12 +306,12 @@ static void mark_edges_uninteresting(struct commit_list *list) } } -int cmd_rev_list(int argc, const char **argv, char **envp) +int cmd_rev_list(int argc, const char **argv, const char *prefix) { struct commit_list *list; int i; - init_revisions(&revs, setup_git_directory()); + init_revisions(&revs, prefix); revs.abbrev = 0; revs.commit_format = CMIT_FMT_UNSPECIFIED; argc = setup_revisions(argc, argv, &revs, NULL); diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c index b3e4386c1b..aca4a36032 100644 --- a/builtin-rev-parse.c +++ b/builtin-rev-parse.c @@ -209,11 +209,10 @@ static int try_difference(const char *arg) return 0; } -int cmd_rev_parse(int argc, const char **argv, char **envp) +int cmd_rev_parse(int argc, const char **argv, const char *prefix) { int i, as_is = 0, verify = 0; unsigned char sha1[20]; - const char *prefix = setup_git_directory(); git_config(git_default_config); diff --git a/builtin-rm.c b/builtin-rm.c index bb810ba41a..92d205a715 100644 --- a/builtin-rm.c +++ b/builtin-rm.c @@ -43,11 +43,10 @@ static int remove_file(const char *name) static struct lock_file lock_file; -int cmd_rm(int argc, const char **argv, char **envp) +int cmd_rm(int argc, const char **argv, const char *prefix) { int i, newfd; int verbose = 0, show_only = 0, force = 0; - const char *prefix = setup_git_directory(); const char **pathspec; char *seen; diff --git a/builtin-show-branch.c b/builtin-show-branch.c index 82f75b72de..2a1b848f6c 100644 --- a/builtin-show-branch.c +++ b/builtin-show-branch.c @@ -550,7 +550,7 @@ static int omit_in_dense(struct commit *commit, struct commit **rev, int n) return 0; } -int cmd_show_branch(int ac, const char **av, char **envp) +int cmd_show_branch(int ac, const char **av, const char *prefix) { struct commit *rev[MAX_REVS], *commit; struct commit_list *list = NULL, *seen = NULL; @@ -573,7 +573,6 @@ int cmd_show_branch(int ac, const char **av, char **envp) int topics = 0; int dense = 1; - setup_git_directory(); git_config(git_show_branch_config); /* If nothing is specified, try the default first */ diff --git a/builtin-stripspace.c b/builtin-stripspace.c index 2ce1264f7b..09cc9108cd 100644 --- a/builtin-stripspace.c +++ b/builtin-stripspace.c @@ -54,7 +54,7 @@ void stripspace(FILE *in, FILE *out) fputc('\n', out); } -int cmd_stripspace(int argc, const char **argv, char **envp) +int cmd_stripspace(int argc, const char **argv, const char *prefix) { stripspace(stdin, stdout); return 0; diff --git a/builtin-tar-tree.c b/builtin-tar-tree.c index e5aaded820..7c48db9ec8 100644 --- a/builtin-tar-tree.c +++ b/builtin-tar-tree.c @@ -308,7 +308,7 @@ int git_tar_config(const char *var, const char *value) return git_default_config(var, value); } -static int generate_tar(int argc, const char **argv, char** envp) +static int generate_tar(int argc, const char **argv, const char *prefix) { unsigned char sha1[20], tree_sha1[20]; struct commit *commit; @@ -319,7 +319,6 @@ static int generate_tar(int argc, const char **argv, char** envp) current_path.alloc = PATH_MAX; current_path.len = current_path.eof = 0; - setup_git_directory(); git_config(git_tar_config); switch (argc) { @@ -402,19 +401,19 @@ static int remote_tar(int argc, const char **argv) return !!ret; } -int cmd_tar_tree(int argc, const char **argv, char **envp) +int cmd_tar_tree(int argc, const char **argv, const char *prefix) { if (argc < 2) usage(tar_tree_usage); if (!strncmp("--remote=", argv[1], 9)) return remote_tar(argc, argv); - return generate_tar(argc, argv, envp); + return generate_tar(argc, argv, prefix); } /* ustar header + extended global header content */ #define HEADERSIZE (2 * RECORDSIZE) -int cmd_get_tar_commit_id(int argc, const char **argv, char **envp) +int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix) { char buffer[HEADERSIZE]; struct ustar_header *header = (struct ustar_header *)buffer; diff --git a/builtin-update-index.c b/builtin-update-index.c index 1a4200d151..24dca47d8d 100644 --- a/builtin-update-index.c +++ b/builtin-update-index.c @@ -476,12 +476,11 @@ static int do_reupdate(int ac, const char **av, return 0; } -int cmd_update_index(int argc, const char **argv, char **envp) +int cmd_update_index(int argc, const char **argv, const char *prefix) { int i, newfd, entries, has_errors = 0, line_termination = '\n'; int allow_options = 1; int read_from_stdin = 0; - const char *prefix = setup_git_directory(); int prefix_length = prefix ? strlen(prefix) : 0; char set_executable_bit = 0; unsigned int refresh_flags = 0; diff --git a/builtin-update-ref.c b/builtin-update-ref.c index 83094abe0f..5bd71825fd 100644 --- a/builtin-update-ref.c +++ b/builtin-update-ref.c @@ -5,7 +5,7 @@ static const char git_update_ref_usage[] = "git-update-ref [] [-m ]"; -int cmd_update_ref(int argc, const char **argv, char **envp) +int cmd_update_ref(int argc, const char **argv, const char *prefix) { const char *refname=NULL, *value=NULL, *oldval=NULL, *msg=NULL; struct ref_lock *lock; @@ -13,7 +13,6 @@ int cmd_update_ref(int argc, const char **argv, char **envp) int i; setup_ident(); - setup_git_directory(); git_config(git_default_config); for (i = 1; i < argc; i++) { diff --git a/builtin-upload-tar.c b/builtin-upload-tar.c index d4fa7b56c3..7b401bbb77 100644 --- a/builtin-upload-tar.c +++ b/builtin-upload-tar.c @@ -15,7 +15,7 @@ static int nak(const char *reason) return 1; } -int cmd_upload_tar(int argc, const char **argv, char **envp) +int cmd_upload_tar(int argc, const char **argv, const char *prefix) { int len; const char *dir = argv[1]; diff --git a/builtin-write-tree.c b/builtin-write-tree.c index 449a4d1b57..0289f59936 100644 --- a/builtin-write-tree.c +++ b/builtin-write-tree.c @@ -60,14 +60,12 @@ int write_tree(unsigned char *sha1, int missing_ok, const char *prefix) return 0; } -int cmd_write_tree(int argc, const char **argv, char **envp) +int cmd_write_tree(int argc, const char **argv, const char *unused_prefix) { int missing_ok = 0, ret; const char *prefix = NULL; unsigned char sha1[20]; - setup_git_directory(); - while (1 < argc) { const char *arg = argv[1]; if (!strcmp(arg, "--missing-ok")) diff --git a/builtin.h b/builtin.h index 5339d8627f..de244cdf65 100644 --- a/builtin.h +++ b/builtin.h @@ -15,53 +15,53 @@ void cmd_usage(int show_all, const char *exec_path, const char *fmt, ...) #endif ; -extern int cmd_help(int argc, const char **argv, char **envp); -extern int cmd_version(int argc, const char **argv, char **envp); +extern int cmd_help(int argc, const char **argv, const char *prefix); +extern int cmd_version(int argc, const char **argv, const char *prefix); -extern int cmd_whatchanged(int argc, const char **argv, char **envp); -extern int cmd_show(int argc, const char **argv, char **envp); -extern int cmd_log(int argc, const char **argv, char **envp); -extern int cmd_diff(int argc, const char **argv, char **envp); -extern int cmd_format_patch(int argc, const char **argv, char **envp); -extern int cmd_count_objects(int argc, const char **argv, char **envp); +extern int cmd_whatchanged(int argc, const char **argv, const char *prefix); +extern int cmd_show(int argc, const char **argv, const char *prefix); +extern int cmd_log(int argc, const char **argv, const char *prefix); +extern int cmd_diff(int argc, const char **argv, const char *prefix); +extern int cmd_format_patch(int argc, const char **argv, const char *prefix); +extern int cmd_count_objects(int argc, const char **argv, const char *prefix); -extern int cmd_prune(int argc, const char **argv, char **envp); +extern int cmd_prune(int argc, const char **argv, const char *prefix); -extern int cmd_push(int argc, const char **argv, char **envp); -extern int cmd_grep(int argc, const char **argv, char **envp); -extern int cmd_rm(int argc, const char **argv, char **envp); -extern int cmd_add(int argc, const char **argv, char **envp); -extern int cmd_rev_list(int argc, const char **argv, char **envp); -extern int cmd_check_ref_format(int argc, const char **argv, char **envp); -extern int cmd_init_db(int argc, const char **argv, char **envp); -extern int cmd_tar_tree(int argc, const char **argv, char **envp); -extern int cmd_upload_tar(int argc, const char **argv, char **envp); -extern int cmd_get_tar_commit_id(int argc, const char **argv, char **envp); -extern int cmd_ls_files(int argc, const char **argv, char **envp); -extern int cmd_ls_tree(int argc, const char **argv, char **envp); -extern int cmd_read_tree(int argc, const char **argv, char **envp); -extern int cmd_commit_tree(int argc, const char **argv, char **envp); -extern int cmd_apply(int argc, const char **argv, char **envp); -extern int cmd_show_branch(int argc, const char **argv, char **envp); -extern int cmd_diff_files(int argc, const char **argv, char **envp); -extern int cmd_diff_index(int argc, const char **argv, char **envp); -extern int cmd_diff_stages(int argc, const char **argv, char **envp); -extern int cmd_diff_tree(int argc, const char **argv, char **envp); -extern int cmd_cat_file(int argc, const char **argv, char **envp); -extern int cmd_rev_parse(int argc, const char **argv, char **envp); -extern int cmd_update_index(int argc, const char **argv, char **envp); -extern int cmd_update_ref(int argc, const char **argv, char **envp); -extern int cmd_fmt_merge_msg(int argc, const char **argv, char **envp); +extern int cmd_push(int argc, const char **argv, const char *prefix); +extern int cmd_grep(int argc, const char **argv, const char *prefix); +extern int cmd_rm(int argc, const char **argv, const char *prefix); +extern int cmd_add(int argc, const char **argv, const char *prefix); +extern int cmd_rev_list(int argc, const char **argv, const char *prefix); +extern int cmd_check_ref_format(int argc, const char **argv, const char *prefix); +extern int cmd_init_db(int argc, const char **argv, const char *prefix); +extern int cmd_tar_tree(int argc, const char **argv, const char *prefix); +extern int cmd_upload_tar(int argc, const char **argv, const char *prefix); +extern int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix); +extern int cmd_ls_files(int argc, const char **argv, const char *prefix); +extern int cmd_ls_tree(int argc, const char **argv, const char *prefix); +extern int cmd_read_tree(int argc, const char **argv, const char *prefix); +extern int cmd_commit_tree(int argc, const char **argv, const char *prefix); +extern int cmd_apply(int argc, const char **argv, const char *prefix); +extern int cmd_show_branch(int argc, const char **argv, const char *prefix); +extern int cmd_diff_files(int argc, const char **argv, const char *prefix); +extern int cmd_diff_index(int argc, const char **argv, const char *prefix); +extern int cmd_diff_stages(int argc, const char **argv, const char *prefix); +extern int cmd_diff_tree(int argc, const char **argv, const char *prefix); +extern int cmd_cat_file(int argc, const char **argv, const char *prefix); +extern int cmd_rev_parse(int argc, const char **argv, const char *prefix); +extern int cmd_update_index(int argc, const char **argv, const char *prefix); +extern int cmd_update_ref(int argc, const char **argv, const char *prefix); +extern int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix); -extern int cmd_write_tree(int argc, const char **argv, char **envp); +extern int cmd_write_tree(int argc, const char **argv, const char *prefix); extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix); -extern int cmd_mailsplit(int argc, const char **argv, char **envp); +extern int cmd_mailsplit(int argc, const char **argv, const char *prefix); extern int split_mbox(const char **mbox, const char *dir, int allow_bare, int nr_prec, int skip); -extern int cmd_mailinfo(int argc, const char **argv, char **envp); +extern int cmd_mailinfo(int argc, const char **argv, const char *prefix); extern int mailinfo(FILE *in, FILE *out, int ks, const char *encoding, const char *msg, const char *patch); -extern int cmd_stripspace(int argc, const char **argv, char **envp); +extern int cmd_stripspace(int argc, const char **argv, const char *prefix); extern void stripspace(FILE *in, FILE *out); #endif diff --git a/git.c b/git.c index 885e1ce75b..79db43e143 100644 --- a/git.c +++ b/git.c @@ -214,51 +214,54 @@ static int handle_alias(int *argcp, const char ***argv) const char git_version_string[] = GIT_VERSION; +#define NEEDS_PREFIX 1 + static void handle_internal_command(int argc, const char **argv, char **envp) { const char *cmd = argv[0]; static struct cmd_struct { const char *cmd; - int (*fn)(int, const char **, char **); + int (*fn)(int, const char **, const char *); + int prefix; } commands[] = { { "version", cmd_version }, { "help", cmd_help }, - { "log", cmd_log }, - { "whatchanged", cmd_whatchanged }, - { "show", cmd_show }, + { "log", cmd_log, NEEDS_PREFIX }, + { "whatchanged", cmd_whatchanged, NEEDS_PREFIX }, + { "show", cmd_show, NEEDS_PREFIX }, { "push", cmd_push }, - { "format-patch", cmd_format_patch }, + { "format-patch", cmd_format_patch, NEEDS_PREFIX }, { "count-objects", cmd_count_objects }, - { "diff", cmd_diff }, - { "grep", cmd_grep }, - { "rm", cmd_rm }, - { "add", cmd_add }, - { "rev-list", cmd_rev_list }, + { "diff", cmd_diff, NEEDS_PREFIX }, + { "grep", cmd_grep, NEEDS_PREFIX }, + { "rm", cmd_rm, NEEDS_PREFIX }, + { "add", cmd_add, NEEDS_PREFIX }, + { "rev-list", cmd_rev_list, NEEDS_PREFIX }, { "init-db", cmd_init_db }, { "get-tar-commit-id", cmd_get_tar_commit_id }, { "upload-tar", cmd_upload_tar }, { "check-ref-format", cmd_check_ref_format }, - { "ls-files", cmd_ls_files }, - { "ls-tree", cmd_ls_tree }, - { "tar-tree", cmd_tar_tree }, - { "read-tree", cmd_read_tree }, - { "commit-tree", cmd_commit_tree }, + { "ls-files", cmd_ls_files, NEEDS_PREFIX }, + { "ls-tree", cmd_ls_tree, NEEDS_PREFIX }, + { "tar-tree", cmd_tar_tree, NEEDS_PREFIX }, + { "read-tree", cmd_read_tree, NEEDS_PREFIX }, + { "commit-tree", cmd_commit_tree, NEEDS_PREFIX }, { "apply", cmd_apply }, - { "show-branch", cmd_show_branch }, - { "diff-files", cmd_diff_files }, - { "diff-index", cmd_diff_index }, - { "diff-stages", cmd_diff_stages }, - { "diff-tree", cmd_diff_tree }, - { "cat-file", cmd_cat_file }, - { "rev-parse", cmd_rev_parse }, - { "write-tree", cmd_write_tree }, + { "show-branch", cmd_show_branch, NEEDS_PREFIX }, + { "diff-files", cmd_diff_files, NEEDS_PREFIX }, + { "diff-index", cmd_diff_index, NEEDS_PREFIX }, + { "diff-stages", cmd_diff_stages, NEEDS_PREFIX }, + { "diff-tree", cmd_diff_tree, NEEDS_PREFIX }, + { "cat-file", cmd_cat_file, NEEDS_PREFIX }, + { "rev-parse", cmd_rev_parse, NEEDS_PREFIX }, + { "write-tree", cmd_write_tree, NEEDS_PREFIX }, { "mailsplit", cmd_mailsplit }, { "mailinfo", cmd_mailinfo }, { "stripspace", cmd_stripspace }, - { "update-index", cmd_update_index }, - { "update-ref", cmd_update_ref }, - { "fmt-merge-msg", cmd_fmt_merge_msg }, - { "prune", cmd_prune }, + { "update-index", cmd_update_index, NEEDS_PREFIX }, + { "update-ref", cmd_update_ref, NEEDS_PREFIX }, + { "fmt-merge-msg", cmd_fmt_merge_msg, NEEDS_PREFIX }, + { "prune", cmd_prune, NEEDS_PREFIX }, }; int i; @@ -270,9 +273,13 @@ static void handle_internal_command(int argc, const char **argv, char **envp) for (i = 0; i < ARRAY_SIZE(commands); i++) { struct cmd_struct *p = commands+i; + const char *prefix; if (strcmp(p->cmd, cmd)) continue; + prefix = NULL; + if (p->prefix) + prefix = setup_git_directory(); if (getenv("GIT_TRACE")) { int i; fprintf(stderr, "trace: built-in: git"); @@ -284,7 +291,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp) fflush(stderr); } - exit(p->fn(argc, argv, envp)); + exit(p->fn(argc, argv, prefix)); } } From ca7a741647f961eb3b6b9df14d079c99fdc9a827 Mon Sep 17 00:00:00 2001 From: Gerrit Pape Date: Sat, 29 Jul 2006 16:26:18 +0000 Subject: [PATCH 102/107] Build on Debian GNU/kFreeBSD Patch from Petr Salinger to make the build process detect and support the Debian GNU/kFreeBSD architecture, see http://bugs.debian.org/380209 Signed-off-by: Gerrit Pape Signed-off-by: Junio C Hamano --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index e9dce268f8..15864e23bd 100644 --- a/Makefile +++ b/Makefile @@ -265,6 +265,9 @@ LIBS = $(GITLIBS) -lz ifeq ($(uname_S),Linux) NO_STRLCPY = YesPlease endif +ifeq ($(uname_S),GNU/kFreeBSD) + NO_STRLCPY = YesPlease +endif ifeq ($(uname_S),Darwin) NEEDS_SSL_WITH_CRYPTO = YesPlease NEEDS_LIBICONV = YesPlease From 41e95f699088b14c6a949ec858499f98df4f34f6 Mon Sep 17 00:00:00 2001 From: Matthias Lederhofer Date: Sun, 30 Jul 2006 03:30:29 +0200 Subject: [PATCH 103/107] setup_git_directory_gently: do not barf when GIT_DIR is given. Earlier we barfed when GIT_DIR environment variable points at a directory yet to be created, which made it impossible to use configuration mechanism in "git-init-db". Signed-off-by: Matthias Lederhofer Signed-off-by: Junio C Hamano --- setup.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/setup.c b/setup.c index 4612f110ee..358e139d84 100644 --- a/setup.c +++ b/setup.c @@ -184,6 +184,10 @@ const char *setup_git_directory_gently(int *nongit_ok) } return NULL; bad_dir_environ: + if (!nongit_ok) { + *nongit_ok = 1; + return NULL; + } path[len] = 0; die("Not a git repository: '%s'", path); } From 0347a8c7648ea9504badce7bb4ed4c4f3dbacf16 Mon Sep 17 00:00:00 2001 From: Matthias Lederhofer Date: Sun, 30 Jul 2006 03:30:29 +0200 Subject: [PATCH 104/107] git.c: allow alias expansion without a git directory With this, the configuration mechanism can be used to say: [alias] init = init-db --template=/path/to/template Signed-off-by: Matthias Lederhofer Signed-off-by: Junio C Hamano --- git.c | 72 ++++++++++++++++++++++++++++------------------------------- 1 file changed, 34 insertions(+), 38 deletions(-) diff --git a/git.c b/git.c index 452180e23a..7321d6c3f6 100644 --- a/git.c +++ b/git.c @@ -156,52 +156,48 @@ static int handle_alias(int *argcp, const char ***argv) { int nongit = 0, ret = 0, saved_errno = errno; const char *subdir; + int count, option_count; + const char** new_argv; subdir = setup_git_directory_gently(&nongit); - if (!nongit) { - int count, option_count; - const char** new_argv; - alias_command = (*argv)[0]; - git_config(git_alias_config); - if (alias_string) { + alias_command = (*argv)[0]; + git_config(git_alias_config); + if (alias_string) { + count = split_cmdline(alias_string, &new_argv); + option_count = handle_options(&new_argv, &count); + memmove(new_argv - option_count, new_argv, + count * sizeof(char *)); + new_argv -= option_count; - count = split_cmdline(alias_string, &new_argv); - option_count = handle_options(&new_argv, &count); - memmove(new_argv - option_count, new_argv, - count * sizeof(char *)); - new_argv -= option_count; + if (count < 1) + die("empty alias for %s", alias_command); - if (count < 1) - die("empty alias for %s", alias_command); + if (!strcmp(alias_command, new_argv[0])) + die("recursive alias: %s", alias_command); - if (!strcmp(alias_command, new_argv[0])) - die("recursive alias: %s", alias_command); - - if (getenv("GIT_TRACE")) { - int i; - fprintf(stderr, "trace: alias expansion: %s =>", - alias_command); - for (i = 0; i < count; ++i) { - fputc(' ', stderr); - sq_quote_print(stderr, new_argv[i]); - } - fputc('\n', stderr); - fflush(stderr); + if (getenv("GIT_TRACE")) { + int i; + fprintf(stderr, "trace: alias expansion: %s =>", + alias_command); + for (i = 0; i < count; ++i) { + fputc(' ', stderr); + sq_quote_print(stderr, new_argv[i]); } - - new_argv = realloc(new_argv, sizeof(char*) * - (count + *argcp + 1)); - /* insert after command name */ - memcpy(new_argv + count, *argv + 1, - sizeof(char*) * *argcp); - new_argv[count+*argcp] = NULL; - - *argv = new_argv; - *argcp += count - 1; - - ret = 1; + fputc('\n', stderr); + fflush(stderr); } + + new_argv = realloc(new_argv, sizeof(char*) * + (count + *argcp + 1)); + /* insert after command name */ + memcpy(new_argv + count, *argv + 1, sizeof(char*) * *argcp); + new_argv[count+*argcp] = NULL; + + *argv = new_argv; + *argcp += count - 1; + + ret = 1; } if (subdir) From b63fafdfd844c2037fba53b9944431c1378b4135 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 31 Jul 2006 02:26:27 +0200 Subject: [PATCH 105/107] tar-tree: illustrate an obscure feature better Since you can tar just a subdirectory of a certain revision, tell the users so, by showing an example how to do it. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- Documentation/git-tar-tree.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/git-tar-tree.txt b/Documentation/git-tar-tree.txt index 7a99acf2ec..1e1c7fa856 100644 --- a/Documentation/git-tar-tree.txt +++ b/Documentation/git-tar-tree.txt @@ -71,6 +71,11 @@ git tar-tree --remote=example.com:git.git v1.4.0 >git-1.4.0.tar:: Get a tarball v1.4.0 from example.com. +git tar-tree HEAD:Documentation/ git-docs > git-1.4.0-docs.tar:: + + Put everything in the current head's Documentation/ directory + into 'git-1.4.0-docs.tar', with the prefix 'git-docs/'. + Author ------ Written by Rene Scharfe. From 16da134b1f9b0fbd1d328999875d34d02e5470b4 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 30 Jul 2006 20:25:18 +0200 Subject: [PATCH 106/107] read-trees: refactor the unpack_trees() part Basically, the options are passed by a struct unpack_trees_options now. That's all. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- Makefile | 4 +- builtin-read-tree.c | 577 ++++++++------------------------------------ unpack-trees.c | 395 ++++++++++++++++++++++++++++++ unpack-trees.h | 30 +++ 4 files changed, 521 insertions(+), 485 deletions(-) create mode 100644 unpack-trees.c create mode 100644 unpack-trees.h diff --git a/Makefile b/Makefile index 15864e23bd..b2332761ba 100644 --- a/Makefile +++ b/Makefile @@ -221,7 +221,7 @@ LIB_H = \ blob.h cache.h commit.h csum-file.h delta.h \ diff.h object.h pack.h pkt-line.h quote.h refs.h \ run-command.h strbuf.h tag.h tree.h git-compat-util.h revision.h \ - tree-walk.h log-tree.h dir.h path-list.h + tree-walk.h log-tree.h dir.h path-list.h unpack-trees.h DIFF_OBJS = \ diff.o diff-lib.o diffcore-break.o diffcore-order.o \ @@ -236,7 +236,7 @@ LIB_OBJS = \ server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \ tag.o tree.o usage.o config.o environment.o ctype.o copy.o \ fetch-clone.o revision.o pager.o tree-walk.o xdiff-interface.o \ - alloc.o merge-file.o path-list.o $(DIFF_OBJS) + alloc.o merge-file.o path-list.o unpack-trees.o $(DIFF_OBJS) BUILTIN_OBJS = \ builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \ diff --git a/builtin-read-tree.c b/builtin-read-tree.c index 49c10bf221..6bc042f852 100644 --- a/builtin-read-tree.c +++ b/builtin-read-tree.c @@ -11,411 +11,17 @@ #include "tree.h" #include "tree-walk.h" #include "cache-tree.h" -#include -#include +#include "unpack-trees.h" #include "builtin.h" -static int reset = 0; -static int merge = 0; -static int update = 0; -static int index_only = 0; -static int nontrivial_merge = 0; -static int trivial_merges_only = 0; -static int aggressive = 0; -static int verbose_update = 0; -static volatile int progress_update = 0; -static const char *prefix = NULL; - -static int head_idx = -1; -static int merge_size = 0; - static struct object_list *trees = NULL; -static struct cache_entry df_conflict_entry; - -struct tree_entry_list { - struct tree_entry_list *next; - unsigned directory : 1; - unsigned executable : 1; - unsigned symlink : 1; - unsigned int mode; - const char *name; - const unsigned char *sha1; -}; - -static struct tree_entry_list df_conflict_list; - -typedef int (*merge_fn_t)(struct cache_entry **src); - -static struct tree_entry_list *create_tree_entry_list(struct tree *tree) -{ - struct tree_desc desc; - struct name_entry one; - struct tree_entry_list *ret = NULL; - struct tree_entry_list **list_p = &ret; - - desc.buf = tree->buffer; - desc.size = tree->size; - - while (tree_entry(&desc, &one)) { - struct tree_entry_list *entry; - - entry = xmalloc(sizeof(struct tree_entry_list)); - entry->name = one.path; - entry->sha1 = one.sha1; - entry->mode = one.mode; - entry->directory = S_ISDIR(one.mode) != 0; - entry->executable = (one.mode & S_IXUSR) != 0; - entry->symlink = S_ISLNK(one.mode) != 0; - entry->next = NULL; - - *list_p = entry; - list_p = &entry->next; - } - return ret; -} - -static int entcmp(const char *name1, int dir1, const char *name2, int dir2) -{ - int len1 = strlen(name1); - int len2 = strlen(name2); - int len = len1 < len2 ? len1 : len2; - int ret = memcmp(name1, name2, len); - unsigned char c1, c2; - if (ret) - return ret; - c1 = name1[len]; - c2 = name2[len]; - if (!c1 && dir1) - c1 = '/'; - if (!c2 && dir2) - c2 = '/'; - ret = (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0; - if (c1 && c2 && !ret) - ret = len1 - len2; - return ret; -} - -static int unpack_trees_rec(struct tree_entry_list **posns, int len, - const char *base, merge_fn_t fn, int *indpos) -{ - int baselen = strlen(base); - int src_size = len + 1; - do { - int i; - const char *first; - int firstdir = 0; - int pathlen; - unsigned ce_size; - struct tree_entry_list **subposns; - struct cache_entry **src; - int any_files = 0; - int any_dirs = 0; - char *cache_name; - int ce_stage; - - /* Find the first name in the input. */ - - first = NULL; - cache_name = NULL; - - /* Check the cache */ - if (merge && *indpos < active_nr) { - /* This is a bit tricky: */ - /* If the index has a subdirectory (with - * contents) as the first name, it'll get a - * filename like "foo/bar". But that's after - * "foo", so the entry in trees will get - * handled first, at which point we'll go into - * "foo", and deal with "bar" from the index, - * because the base will be "foo/". The only - * way we can actually have "foo/bar" first of - * all the things is if the trees don't - * contain "foo" at all, in which case we'll - * handle "foo/bar" without going into the - * directory, but that's fine (and will return - * an error anyway, with the added unknown - * file case. - */ - - cache_name = active_cache[*indpos]->name; - if (strlen(cache_name) > baselen && - !memcmp(cache_name, base, baselen)) { - cache_name += baselen; - first = cache_name; - } else { - cache_name = NULL; - } - } - -#if DBRT_DEBUG > 1 - if (first) - printf("index %s\n", first); -#endif - for (i = 0; i < len; i++) { - if (!posns[i] || posns[i] == &df_conflict_list) - continue; -#if DBRT_DEBUG > 1 - printf("%d %s\n", i + 1, posns[i]->name); -#endif - if (!first || entcmp(first, firstdir, - posns[i]->name, - posns[i]->directory) > 0) { - first = posns[i]->name; - firstdir = posns[i]->directory; - } - } - /* No name means we're done */ - if (!first) - return 0; - - pathlen = strlen(first); - ce_size = cache_entry_size(baselen + pathlen); - - src = xcalloc(src_size, sizeof(struct cache_entry *)); - - subposns = xcalloc(len, sizeof(struct tree_list_entry *)); - - if (cache_name && !strcmp(cache_name, first)) { - any_files = 1; - src[0] = active_cache[*indpos]; - remove_cache_entry_at(*indpos); - } - - for (i = 0; i < len; i++) { - struct cache_entry *ce; - - if (!posns[i] || - (posns[i] != &df_conflict_list && - strcmp(first, posns[i]->name))) { - continue; - } - - if (posns[i] == &df_conflict_list) { - src[i + merge] = &df_conflict_entry; - continue; - } - - if (posns[i]->directory) { - struct tree *tree = lookup_tree(posns[i]->sha1); - any_dirs = 1; - parse_tree(tree); - subposns[i] = create_tree_entry_list(tree); - posns[i] = posns[i]->next; - src[i + merge] = &df_conflict_entry; - continue; - } - - if (!merge) - ce_stage = 0; - else if (i + 1 < head_idx) - ce_stage = 1; - else if (i + 1 > head_idx) - ce_stage = 3; - else - ce_stage = 2; - - ce = xcalloc(1, ce_size); - ce->ce_mode = create_ce_mode(posns[i]->mode); - ce->ce_flags = create_ce_flags(baselen + pathlen, - ce_stage); - memcpy(ce->name, base, baselen); - memcpy(ce->name + baselen, first, pathlen + 1); - - any_files = 1; - - memcpy(ce->sha1, posns[i]->sha1, 20); - src[i + merge] = ce; - subposns[i] = &df_conflict_list; - posns[i] = posns[i]->next; - } - if (any_files) { - if (merge) { - int ret; - -#if DBRT_DEBUG > 1 - printf("%s:\n", first); - for (i = 0; i < src_size; i++) { - printf(" %d ", i); - if (src[i]) - printf("%s\n", sha1_to_hex(src[i]->sha1)); - else - printf("\n"); - } -#endif - ret = fn(src); - -#if DBRT_DEBUG > 1 - printf("Added %d entries\n", ret); -#endif - *indpos += ret; - } else { - for (i = 0; i < src_size; i++) { - if (src[i]) { - add_cache_entry(src[i], ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK); - } - } - } - } - if (any_dirs) { - char *newbase = xmalloc(baselen + 2 + pathlen); - memcpy(newbase, base, baselen); - memcpy(newbase + baselen, first, pathlen); - newbase[baselen + pathlen] = '/'; - newbase[baselen + pathlen + 1] = '\0'; - if (unpack_trees_rec(subposns, len, newbase, fn, - indpos)) - return -1; - free(newbase); - } - free(subposns); - free(src); - } while (1); -} - static void reject_merge(struct cache_entry *ce) { - die("Entry '%s' would be overwritten by merge. Cannot merge.", + die("Entry '%s' would be overwritten by merge. Cannot merge.", ce->name); } -/* Unlink the last component and attempt to remove leading - * directories, in case this unlink is the removal of the - * last entry in the directory -- empty directories are removed. - */ -static void unlink_entry(char *name) -{ - char *cp, *prev; - - if (unlink(name)) - return; - prev = NULL; - while (1) { - int status; - cp = strrchr(name, '/'); - if (prev) - *prev = '/'; - if (!cp) - break; - - *cp = 0; - status = rmdir(name); - if (status) { - *cp = '/'; - break; - } - prev = cp; - } -} - -static void progress_interval(int signum) -{ - progress_update = 1; -} - -static void setup_progress_signal(void) -{ - struct sigaction sa; - struct itimerval v; - - memset(&sa, 0, sizeof(sa)); - sa.sa_handler = progress_interval; - sigemptyset(&sa.sa_mask); - sa.sa_flags = SA_RESTART; - sigaction(SIGALRM, &sa, NULL); - - v.it_interval.tv_sec = 1; - v.it_interval.tv_usec = 0; - v.it_value = v.it_interval; - setitimer(ITIMER_REAL, &v, NULL); -} - -static struct checkout state; -static void check_updates(struct cache_entry **src, int nr) -{ - unsigned short mask = htons(CE_UPDATE); - unsigned last_percent = 200, cnt = 0, total = 0; - - if (update && verbose_update) { - for (total = cnt = 0; cnt < nr; cnt++) { - struct cache_entry *ce = src[cnt]; - if (!ce->ce_mode || ce->ce_flags & mask) - total++; - } - - /* Don't bother doing this for very small updates */ - if (total < 250) - total = 0; - - if (total) { - fprintf(stderr, "Checking files out...\n"); - setup_progress_signal(); - progress_update = 1; - } - cnt = 0; - } - - while (nr--) { - struct cache_entry *ce = *src++; - - if (total) { - if (!ce->ce_mode || ce->ce_flags & mask) { - unsigned percent; - cnt++; - percent = (cnt * 100) / total; - if (percent != last_percent || - progress_update) { - fprintf(stderr, "%4u%% (%u/%u) done\r", - percent, cnt, total); - last_percent = percent; - progress_update = 0; - } - } - } - if (!ce->ce_mode) { - if (update) - unlink_entry(ce->name); - continue; - } - if (ce->ce_flags & mask) { - ce->ce_flags &= ~mask; - if (update) - checkout_entry(ce, &state, NULL); - } - } - if (total) { - signal(SIGALRM, SIG_IGN); - fputc('\n', stderr); - } -} - -static int unpack_trees(merge_fn_t fn) -{ - int indpos = 0; - unsigned len = object_list_length(trees); - struct tree_entry_list **posns; - int i; - struct object_list *posn = trees; - merge_size = len; - - if (len) { - posns = xmalloc(len * sizeof(struct tree_entry_list *)); - for (i = 0; i < len; i++) { - posns[i] = create_tree_entry_list((struct tree *) posn->item); - posn = posn->next; - } - if (unpack_trees_rec(posns, len, prefix ? prefix : "", - fn, &indpos)) - return -1; - } - - if (trivial_merges_only && nontrivial_merge) - die("Merge requires file-level merging"); - - check_updates(active_cache, active_nr); - return 0; -} - static int list_tree(unsigned char *sha1) { struct tree *tree = parse_tree_indirect(sha1); @@ -440,11 +46,12 @@ static int same(struct cache_entry *a, struct cache_entry *b) * When a CE gets turned into an unmerged entry, we * want it to be up-to-date */ -static void verify_uptodate(struct cache_entry *ce) +static void verify_uptodate(struct cache_entry *ce, + struct unpack_trees_options *o) { struct stat st; - if (index_only || reset) + if (o->index_only || o->reset) return; if (!lstat(ce->name, &st)) { @@ -453,7 +60,7 @@ static void verify_uptodate(struct cache_entry *ce) return; errno = 0; } - if (reset) { + if (o->reset) { ce->ce_flags |= htons(CE_UPDATE); return; } @@ -472,18 +79,20 @@ static void invalidate_ce_path(struct cache_entry *ce) * We do not want to remove or overwrite a working tree file that * is not tracked. */ -static void verify_absent(const char *path, const char *action) +static void verify_absent(const char *path, const char *action, + struct unpack_trees_options *o) { struct stat st; - if (index_only || reset || !update) + if (o->index_only || o->reset || !o->update) return; if (!lstat(path, &st)) die("Untracked working tree file '%s' " "would be %s by merge.", path, action); } -static int merged_entry(struct cache_entry *merge, struct cache_entry *old) +static int merged_entry(struct cache_entry *merge, struct cache_entry *old, + struct unpack_trees_options *o) { merge->ce_flags |= htons(CE_UPDATE); if (old) { @@ -497,12 +106,12 @@ static int merged_entry(struct cache_entry *merge, struct cache_entry *old) if (same(old, merge)) { *merge = *old; } else { - verify_uptodate(old); + verify_uptodate(old, o); invalidate_ce_path(old); } } else { - verify_absent(merge->name, "overwritten"); + verify_absent(merge->name, "overwritten", o); invalidate_ce_path(merge); } @@ -511,12 +120,13 @@ static int merged_entry(struct cache_entry *merge, struct cache_entry *old) return 1; } -static int deleted_entry(struct cache_entry *ce, struct cache_entry *old) +static int deleted_entry(struct cache_entry *ce, struct cache_entry *old, + struct unpack_trees_options *o) { if (old) - verify_uptodate(old); + verify_uptodate(old, o); else - verify_absent(ce->name, "removed"); + verify_absent(ce->name, "removed", o); ce->ce_mode = 0; add_cache_entry(ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE); invalidate_ce_path(ce); @@ -545,11 +155,12 @@ static void show_stage_entry(FILE *o, } #endif -static int threeway_merge(struct cache_entry **stages) +static int threeway_merge(struct cache_entry **stages, + struct unpack_trees_options *o) { struct cache_entry *index; - struct cache_entry *head; - struct cache_entry *remote = stages[head_idx + 1]; + struct cache_entry *head; + struct cache_entry *remote = stages[o->head_idx + 1]; int count; int head_match = 0; int remote_match = 0; @@ -562,7 +173,7 @@ static int threeway_merge(struct cache_entry **stages) int no_anc_exists = 1; int i; - for (i = 1; i < head_idx; i++) { + for (i = 1; i < o->head_idx; i++) { if (!stages[i]) any_anc_missing = 1; else { @@ -573,14 +184,14 @@ static int threeway_merge(struct cache_entry **stages) } index = stages[0]; - head = stages[head_idx]; + head = stages[o->head_idx]; - if (head == &df_conflict_entry) { + if (head == &o->df_conflict_entry) { df_conflict_head = 1; head = NULL; } - if (remote == &df_conflict_entry) { + if (remote == &o->df_conflict_entry) { df_conflict_remote = 1; remote = NULL; } @@ -596,7 +207,7 @@ static int threeway_merge(struct cache_entry **stages) * and #14. */ if (!same(remote, head)) { - for (i = 1; i < head_idx; i++) { + for (i = 1; i < o->head_idx; i++) { if (same(stages[i], head)) { head_match = i; } @@ -614,7 +225,7 @@ static int threeway_merge(struct cache_entry **stages) if (remote && !df_conflict_head && head_match && !remote_match) { if (index && !same(index, remote) && !same(index, head)) reject_merge(index); - return merged_entry(remote, index); + return merged_entry(remote, index, o); } /* * If we have an entry in the index cache, then we want to @@ -627,10 +238,10 @@ static int threeway_merge(struct cache_entry **stages) if (head) { /* #5ALT, #15 */ if (same(head, remote)) - return merged_entry(head, index); + return merged_entry(head, index, o); /* #13, #3ALT */ if (!df_conflict_remote && remote_match && !head_match) - return merged_entry(head, index); + return merged_entry(head, index, o); } /* #1 */ @@ -640,7 +251,7 @@ static int threeway_merge(struct cache_entry **stages) /* Under the new "aggressive" rule, we resolve mostly trivial * cases that we historically had git-merge-one-file resolve. */ - if (aggressive) { + if (o->aggressive) { int head_deleted = !head && !df_conflict_head; int remote_deleted = !remote && !df_conflict_remote; /* @@ -651,35 +262,35 @@ static int threeway_merge(struct cache_entry **stages) (head_deleted && remote && remote_match) || (remote_deleted && head && head_match)) { if (index) - return deleted_entry(index, index); + return deleted_entry(index, index, o); else if (path) - verify_absent(path, "removed"); + verify_absent(path, "removed", o); return 0; } /* * Added in both, identically. */ if (no_anc_exists && head && remote && same(head, remote)) - return merged_entry(head, index); + return merged_entry(head, index, o); } /* Below are "no merge" cases, which require that the index be * up-to-date to avoid the files getting overwritten with - * conflict resolution files. + * conflict resolution files. */ if (index) { - verify_uptodate(index); + verify_uptodate(index, o); } else if (path) - verify_absent(path, "overwritten"); + verify_absent(path, "overwritten", o); - nontrivial_merge = 1; + o->nontrivial_merge = 1; /* #2, #3, #4, #6, #7, #9, #11. */ count = 0; if (!head_match || !remote_match) { - for (i = 1; i < head_idx; i++) { + for (i = 1; i < o->head_idx; i++) { if (stages[i]) { keep_entry(stages[i]); count++; @@ -708,14 +319,15 @@ static int threeway_merge(struct cache_entry **stages) * "carry forward" rule, please see . * */ -static int twoway_merge(struct cache_entry **src) +static int twoway_merge(struct cache_entry **src, + struct unpack_trees_options *o) { struct cache_entry *current = src[0]; struct cache_entry *oldtree = src[1], *newtree = src[2]; - if (merge_size != 2) + if (o->merge_size != 2) return error("Cannot do a twoway merge of %d trees", - merge_size); + o->merge_size); if (current) { if ((!oldtree && !newtree) || /* 4 and 5 */ @@ -730,12 +342,12 @@ static int twoway_merge(struct cache_entry **src) } else if (oldtree && !newtree && same(current, oldtree)) { /* 10 or 11 */ - return deleted_entry(oldtree, current); + return deleted_entry(oldtree, current, o); } else if (oldtree && newtree && same(current, oldtree) && !same(current, newtree)) { /* 20 or 21 */ - return merged_entry(newtree, current); + return merged_entry(newtree, current, o); } else { /* all other failures */ @@ -749,9 +361,9 @@ static int twoway_merge(struct cache_entry **src) } } else if (newtree) - return merged_entry(newtree, current); + return merged_entry(newtree, current, o); else - return deleted_entry(oldtree, current); + return deleted_entry(oldtree, current, o); } /* @@ -760,20 +372,21 @@ static int twoway_merge(struct cache_entry **src) * Keep the index entries at stage0, collapse stage1 but make sure * stage0 does not have anything there. */ -static int bind_merge(struct cache_entry **src) +static int bind_merge(struct cache_entry **src, + struct unpack_trees_options *o) { struct cache_entry *old = src[0]; struct cache_entry *a = src[1]; - if (merge_size != 1) + if (o->merge_size != 1) return error("Cannot do a bind merge of %d trees\n", - merge_size); + o->merge_size); if (a && old) die("Entry '%s' overlaps. Cannot bind.", a->name); if (!a) return keep_entry(old); else - return merged_entry(a, NULL); + return merged_entry(a, NULL, o); } /* @@ -782,19 +395,20 @@ static int bind_merge(struct cache_entry **src) * The rule is: * - take the stat information from stage0, take the data from stage1 */ -static int oneway_merge(struct cache_entry **src) +static int oneway_merge(struct cache_entry **src, + struct unpack_trees_options *o) { struct cache_entry *old = src[0]; struct cache_entry *a = src[1]; - if (merge_size != 1) + if (o->merge_size != 1) return error("Cannot do a oneway merge of %d trees", - merge_size); + o->merge_size); if (!a) - return deleted_entry(old, old); + return deleted_entry(old, old, o); if (old && same(old, a)) { - if (reset) { + if (o->reset) { struct stat st; if (lstat(old->name, &st) || ce_match_stat(old, &st, 1)) @@ -802,7 +416,7 @@ static int oneway_merge(struct cache_entry **src) } return keep_entry(old); } - return merged_entry(a, old); + return merged_entry(a, old, o); } static int read_cache_unmerged(void) @@ -874,14 +488,12 @@ int cmd_read_tree(int argc, const char **argv, const char *prefix) { int i, newfd, stage = 0; unsigned char sha1[20]; - merge_fn_t fn = NULL; + struct unpack_trees_options opts; - df_conflict_list.next = &df_conflict_list; - state.base_dir = ""; - state.force = 1; - state.quiet = 1; - state.refresh_cache = 1; + memset(&opts, 0, sizeof(opts)); + opts.head_idx = -1; + setup_git_directory(); git_config(git_default_config); newfd = hold_lock_file_for_update(&lock_file, get_index_file()); @@ -890,8 +502,6 @@ int cmd_read_tree(int argc, const char **argv, const char *prefix) git_config(git_default_config); - merge = 0; - reset = 0; for (i = 1; i < argc; i++) { const char *arg = argv[i]; @@ -899,12 +509,12 @@ int cmd_read_tree(int argc, const char **argv, const char *prefix) * the working tree. */ if (!strcmp(arg, "-u")) { - update = 1; + opts.update = 1; continue; } if (!strcmp(arg, "-v")) { - verbose_update = 1; + opts.verbose_update = 1; continue; } @@ -912,7 +522,7 @@ int cmd_read_tree(int argc, const char **argv, const char *prefix) * not even look at the working tree. */ if (!strcmp(arg, "-i")) { - index_only = 1; + opts.index_only = 1; continue; } @@ -921,10 +531,10 @@ int cmd_read_tree(int argc, const char **argv, const char *prefix) * given subdirectory. */ if (!strncmp(arg, "--prefix=", 9)) { - if (stage || merge || prefix) + if (stage || opts.merge || opts.prefix) usage(read_tree_usage); - prefix = arg + 9; - merge = 1; + opts.prefix = arg + 9; + opts.merge = 1; stage = 1; if (read_cache_unmerged()) die("you need to resolve your current index first"); @@ -936,38 +546,38 @@ int cmd_read_tree(int argc, const char **argv, const char *prefix) * correspond to them. */ if (!strcmp(arg, "--reset")) { - if (stage || merge || prefix) + if (stage || opts.merge || opts.prefix) usage(read_tree_usage); - reset = 1; - merge = 1; + opts.reset = 1; + opts.merge = 1; stage = 1; read_cache_unmerged(); continue; } if (!strcmp(arg, "--trivial")) { - trivial_merges_only = 1; + opts.trivial_merges_only = 1; continue; } if (!strcmp(arg, "--aggressive")) { - aggressive = 1; + opts.aggressive = 1; continue; } /* "-m" stands for "merge", meaning we start in stage 1 */ if (!strcmp(arg, "-m")) { - if (stage || merge || prefix) + if (stage || opts.merge || opts.prefix) usage(read_tree_usage); if (read_cache_unmerged()) die("you need to resolve your current index first"); stage = 1; - merge = 1; + opts.merge = 1; continue; } /* using -u and -i at the same time makes no sense */ - if (1 < index_only + update) + if (1 < opts.index_only + opts.update) usage(read_tree_usage); if (get_sha1(arg, sha1)) @@ -976,52 +586,53 @@ int cmd_read_tree(int argc, const char **argv, const char *prefix) die("failed to unpack tree object %s", arg); stage++; } - if ((update||index_only) && !merge) + if ((opts.update||opts.index_only) && !opts.merge) usage(read_tree_usage); - if (prefix) { - int pfxlen = strlen(prefix); + if (opts.prefix) { + int pfxlen = strlen(opts.prefix); int pos; - if (prefix[pfxlen-1] != '/') + if (opts.prefix[pfxlen-1] != '/') die("prefix must end with /"); if (stage != 2) die("binding merge takes only one tree"); - pos = cache_name_pos(prefix, pfxlen); + pos = cache_name_pos(opts.prefix, pfxlen); if (0 <= pos) die("corrupt index file"); pos = -pos-1; if (pos < active_nr && - !strncmp(active_cache[pos]->name, prefix, pfxlen)) - die("subdirectory '%s' already exists.", prefix); - pos = cache_name_pos(prefix, pfxlen-1); + !strncmp(active_cache[pos]->name, opts.prefix, pfxlen)) + die("subdirectory '%s' already exists.", opts.prefix); + pos = cache_name_pos(opts.prefix, pfxlen-1); if (0 <= pos) - die("file '%.*s' already exists.", pfxlen-1, prefix); + die("file '%.*s' already exists.", + pfxlen-1, opts.prefix); } - if (merge) { + if (opts.merge) { if (stage < 2) die("just how do you expect me to merge %d trees?", stage-1); switch (stage - 1) { case 1: - fn = prefix ? bind_merge : oneway_merge; + opts.fn = opts.prefix ? bind_merge : oneway_merge; break; case 2: - fn = twoway_merge; + opts.fn = twoway_merge; break; case 3: default: - fn = threeway_merge; + opts.fn = threeway_merge; cache_tree_free(&active_cache_tree); break; } if (stage - 1 >= 3) - head_idx = stage - 2; + opts.head_idx = stage - 2; else - head_idx = 1; + opts.head_idx = 1; } - unpack_trees(fn); + unpack_trees(trees, &opts); /* * When reading only one tree (either the most basic form, @@ -1029,7 +640,7 @@ int cmd_read_tree(int argc, const char **argv, const char *prefix) * valid cache-tree because the index must match exactly * what came from the tree. */ - if (trees && trees->item && !prefix && (!merge || (stage == 2))) { + if (trees && trees->item && !opts.prefix && (!opts.merge || (stage == 2))) { cache_tree_free(&active_cache_tree); prime_cache_tree(); } diff --git a/unpack-trees.c b/unpack-trees.c new file mode 100644 index 0000000000..20251822e4 --- /dev/null +++ b/unpack-trees.c @@ -0,0 +1,395 @@ +#include +#include +#include "cache.h" +#include "tree.h" +#include "tree-walk.h" +#include "unpack-trees.h" + +struct tree_entry_list { + struct tree_entry_list *next; + unsigned directory : 1; + unsigned executable : 1; + unsigned symlink : 1; + unsigned int mode; + const char *name; + const unsigned char *sha1; +}; + +static struct tree_entry_list *create_tree_entry_list(struct tree *tree) +{ + struct tree_desc desc; + struct name_entry one; + struct tree_entry_list *ret = NULL; + struct tree_entry_list **list_p = &ret; + + desc.buf = tree->buffer; + desc.size = tree->size; + + while (tree_entry(&desc, &one)) { + struct tree_entry_list *entry; + + entry = xmalloc(sizeof(struct tree_entry_list)); + entry->name = one.path; + entry->sha1 = one.sha1; + entry->mode = one.mode; + entry->directory = S_ISDIR(one.mode) != 0; + entry->executable = (one.mode & S_IXUSR) != 0; + entry->symlink = S_ISLNK(one.mode) != 0; + entry->next = NULL; + + *list_p = entry; + list_p = &entry->next; + } + return ret; +} + +static int entcmp(const char *name1, int dir1, const char *name2, int dir2) +{ + int len1 = strlen(name1); + int len2 = strlen(name2); + int len = len1 < len2 ? len1 : len2; + int ret = memcmp(name1, name2, len); + unsigned char c1, c2; + if (ret) + return ret; + c1 = name1[len]; + c2 = name2[len]; + if (!c1 && dir1) + c1 = '/'; + if (!c2 && dir2) + c2 = '/'; + ret = (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0; + if (c1 && c2 && !ret) + ret = len1 - len2; + return ret; +} + +static int unpack_trees_rec(struct tree_entry_list **posns, int len, + const char *base, struct unpack_trees_options *o, + int *indpos, + struct tree_entry_list *df_conflict_list) +{ + int baselen = strlen(base); + int src_size = len + 1; + do { + int i; + const char *first; + int firstdir = 0; + int pathlen; + unsigned ce_size; + struct tree_entry_list **subposns; + struct cache_entry **src; + int any_files = 0; + int any_dirs = 0; + char *cache_name; + int ce_stage; + + /* Find the first name in the input. */ + + first = NULL; + cache_name = NULL; + + /* Check the cache */ + if (o->merge && *indpos < active_nr) { + /* This is a bit tricky: */ + /* If the index has a subdirectory (with + * contents) as the first name, it'll get a + * filename like "foo/bar". But that's after + * "foo", so the entry in trees will get + * handled first, at which point we'll go into + * "foo", and deal with "bar" from the index, + * because the base will be "foo/". The only + * way we can actually have "foo/bar" first of + * all the things is if the trees don't + * contain "foo" at all, in which case we'll + * handle "foo/bar" without going into the + * directory, but that's fine (and will return + * an error anyway, with the added unknown + * file case. + */ + + cache_name = active_cache[*indpos]->name; + if (strlen(cache_name) > baselen && + !memcmp(cache_name, base, baselen)) { + cache_name += baselen; + first = cache_name; + } else { + cache_name = NULL; + } + } + +#if DBRT_DEBUG > 1 + if (first) + printf("index %s\n", first); +#endif + for (i = 0; i < len; i++) { + if (!posns[i] || posns[i] == df_conflict_list) + continue; +#if DBRT_DEBUG > 1 + printf("%d %s\n", i + 1, posns[i]->name); +#endif + if (!first || entcmp(first, firstdir, + posns[i]->name, + posns[i]->directory) > 0) { + first = posns[i]->name; + firstdir = posns[i]->directory; + } + } + /* No name means we're done */ + if (!first) + return 0; + + pathlen = strlen(first); + ce_size = cache_entry_size(baselen + pathlen); + + src = xcalloc(src_size, sizeof(struct cache_entry *)); + + subposns = xcalloc(len, sizeof(struct tree_list_entry *)); + + if (cache_name && !strcmp(cache_name, first)) { + any_files = 1; + src[0] = active_cache[*indpos]; + remove_cache_entry_at(*indpos); + } + + for (i = 0; i < len; i++) { + struct cache_entry *ce; + + if (!posns[i] || + (posns[i] != df_conflict_list && + strcmp(first, posns[i]->name))) { + continue; + } + + if (posns[i] == df_conflict_list) { + src[i + o->merge] = o->df_conflict_entry; + continue; + } + + if (posns[i]->directory) { + struct tree *tree = lookup_tree(posns[i]->sha1); + any_dirs = 1; + parse_tree(tree); + subposns[i] = create_tree_entry_list(tree); + posns[i] = posns[i]->next; + src[i + o->merge] = o->df_conflict_entry; + continue; + } + + if (!o->merge) + ce_stage = 0; + else if (i + 1 < o->head_idx) + ce_stage = 1; + else if (i + 1 > o->head_idx) + ce_stage = 3; + else + ce_stage = 2; + + ce = xcalloc(1, ce_size); + ce->ce_mode = create_ce_mode(posns[i]->mode); + ce->ce_flags = create_ce_flags(baselen + pathlen, + ce_stage); + memcpy(ce->name, base, baselen); + memcpy(ce->name + baselen, first, pathlen + 1); + + any_files = 1; + + memcpy(ce->sha1, posns[i]->sha1, 20); + src[i + o->merge] = ce; + subposns[i] = df_conflict_list; + posns[i] = posns[i]->next; + } + if (any_files) { + if (o->merge) { + int ret; + +#if DBRT_DEBUG > 1 + printf("%s:\n", first); + for (i = 0; i < src_size; i++) { + printf(" %d ", i); + if (src[i]) + printf("%s\n", sha1_to_hex(src[i]->sha1)); + else + printf("\n"); + } +#endif + ret = o->fn(src, o); + +#if DBRT_DEBUG > 1 + printf("Added %d entries\n", ret); +#endif + *indpos += ret; + } else { + for (i = 0; i < src_size; i++) { + if (src[i]) { + add_cache_entry(src[i], ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK); + } + } + } + } + if (any_dirs) { + char *newbase = xmalloc(baselen + 2 + pathlen); + memcpy(newbase, base, baselen); + memcpy(newbase + baselen, first, pathlen); + newbase[baselen + pathlen] = '/'; + newbase[baselen + pathlen + 1] = '\0'; + if (unpack_trees_rec(subposns, len, newbase, o, + indpos, df_conflict_list)) + return -1; + free(newbase); + } + free(subposns); + free(src); + } while (1); +} + +/* Unlink the last component and attempt to remove leading + * directories, in case this unlink is the removal of the + * last entry in the directory -- empty directories are removed. + */ +static void unlink_entry(char *name) +{ + char *cp, *prev; + + if (unlink(name)) + return; + prev = NULL; + while (1) { + int status; + cp = strrchr(name, '/'); + if (prev) + *prev = '/'; + if (!cp) + break; + + *cp = 0; + status = rmdir(name); + if (status) { + *cp = '/'; + break; + } + prev = cp; + } +} + +static volatile int progress_update = 0; + +static void progress_interval(int signum) +{ + progress_update = 1; +} + +static void setup_progress_signal(void) +{ + struct sigaction sa; + struct itimerval v; + + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = progress_interval; + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_RESTART; + sigaction(SIGALRM, &sa, NULL); + + v.it_interval.tv_sec = 1; + v.it_interval.tv_usec = 0; + v.it_value = v.it_interval; + setitimer(ITIMER_REAL, &v, NULL); +} + +static struct checkout state; +static void check_updates(struct cache_entry **src, int nr, + struct unpack_trees_options *o) +{ + unsigned short mask = htons(CE_UPDATE); + unsigned last_percent = 200, cnt = 0, total = 0; + + if (o->update && o->verbose_update) { + for (total = cnt = 0; cnt < nr; cnt++) { + struct cache_entry *ce = src[cnt]; + if (!ce->ce_mode || ce->ce_flags & mask) + total++; + } + + /* Don't bother doing this for very small updates */ + if (total < 250) + total = 0; + + if (total) { + fprintf(stderr, "Checking files out...\n"); + setup_progress_signal(); + progress_update = 1; + } + cnt = 0; + } + + while (nr--) { + struct cache_entry *ce = *src++; + + if (total) { + if (!ce->ce_mode || ce->ce_flags & mask) { + unsigned percent; + cnt++; + percent = (cnt * 100) / total; + if (percent != last_percent || + progress_update) { + fprintf(stderr, "%4u%% (%u/%u) done\r", + percent, cnt, total); + last_percent = percent; + progress_update = 0; + } + } + } + if (!ce->ce_mode) { + if (o->update) + unlink_entry(ce->name); + continue; + } + if (ce->ce_flags & mask) { + ce->ce_flags &= ~mask; + if (o->update) + checkout_entry(ce, &state, NULL); + } + } + if (total) { + signal(SIGALRM, SIG_IGN); + fputc('\n', stderr); + } +} + +int unpack_trees(struct object_list *trees, struct unpack_trees_options *o) +{ + int indpos = 0; + unsigned len = object_list_length(trees); + struct tree_entry_list **posns; + int i; + struct object_list *posn = trees; + struct tree_entry_list df_conflict_list; + struct cache_entry df_conflict_entry; + + memset(&df_conflict_list, 0, sizeof(df_conflict_list)); + df_conflict_list.next = &df_conflict_list; + state.base_dir = ""; + state.force = 1; + state.quiet = 1; + state.refresh_cache = 1; + + o->merge_size = len; + o->df_conflict_entry = &df_conflict_entry; + + if (len) { + posns = xmalloc(len * sizeof(struct tree_entry_list *)); + for (i = 0; i < len; i++) { + posns[i] = create_tree_entry_list((struct tree *) posn->item); + posn = posn->next; + } + if (unpack_trees_rec(posns, len, o->prefix ? o->prefix : "", + o, &indpos, &df_conflict_list)) + return -1; + } + + if (o->trivial_merges_only && o->nontrivial_merge) + die("Merge requires file-level merging"); + + check_updates(active_cache, active_nr, o); + return 0; +} diff --git a/unpack-trees.h b/unpack-trees.h new file mode 100644 index 0000000000..38af89a6b7 --- /dev/null +++ b/unpack-trees.h @@ -0,0 +1,30 @@ +#ifndef UNPACK_TREES_H +#define UNPACK_TREES_H + +struct unpack_trees_options; + +typedef int (*merge_fn_t)(struct cache_entry **src, + struct unpack_trees_options *options); + +struct unpack_trees_options { + int reset; + int merge; + int update; + int index_only; + int nontrivial_merge; + int trivial_merges_only; + int verbose_update; + int aggressive; + const char *prefix; + merge_fn_t fn; + + int head_idx; + int merge_size; + + struct cache_entry *df_conflict_entry; +}; + +extern int unpack_trees(struct object_list *trees, + struct unpack_trees_options *options); + +#endif From 076b0adcf9dac7bd9d18624087f679cc811aeb77 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 30 Jul 2006 20:26:15 +0200 Subject: [PATCH 107/107] read-tree: move merge functions to the library This will allow merge-recursive to use the read-tree functionality without exec()ing git-read-tree. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin-read-tree.c | 398 +------------------------------------------ unpack-trees.c | 404 ++++++++++++++++++++++++++++++++++++++++++++ unpack-trees.h | 5 + 3 files changed, 410 insertions(+), 397 deletions(-) diff --git a/builtin-read-tree.c b/builtin-read-tree.c index 6bc042f852..8869cedea1 100644 --- a/builtin-read-tree.c +++ b/builtin-read-tree.c @@ -3,10 +3,8 @@ * * Copyright (C) Linus Torvalds, 2005 */ -#define DBRT_DEBUG 1 #include "cache.h" - #include "object.h" #include "tree.h" #include "tree-walk.h" @@ -16,12 +14,6 @@ static struct object_list *trees = NULL; -static void reject_merge(struct cache_entry *ce) -{ - die("Entry '%s' would be overwritten by merge. Cannot merge.", - ce->name); -} - static int list_tree(unsigned char *sha1) { struct tree *tree = parse_tree_indirect(sha1); @@ -31,394 +23,6 @@ static int list_tree(unsigned char *sha1) return 0; } -static int same(struct cache_entry *a, struct cache_entry *b) -{ - if (!!a != !!b) - return 0; - if (!a && !b) - return 1; - return a->ce_mode == b->ce_mode && - !memcmp(a->sha1, b->sha1, 20); -} - - -/* - * When a CE gets turned into an unmerged entry, we - * want it to be up-to-date - */ -static void verify_uptodate(struct cache_entry *ce, - struct unpack_trees_options *o) -{ - struct stat st; - - if (o->index_only || o->reset) - return; - - if (!lstat(ce->name, &st)) { - unsigned changed = ce_match_stat(ce, &st, 1); - if (!changed) - return; - errno = 0; - } - if (o->reset) { - ce->ce_flags |= htons(CE_UPDATE); - return; - } - if (errno == ENOENT) - return; - die("Entry '%s' not uptodate. Cannot merge.", ce->name); -} - -static void invalidate_ce_path(struct cache_entry *ce) -{ - if (ce) - cache_tree_invalidate_path(active_cache_tree, ce->name); -} - -/* - * We do not want to remove or overwrite a working tree file that - * is not tracked. - */ -static void verify_absent(const char *path, const char *action, - struct unpack_trees_options *o) -{ - struct stat st; - - if (o->index_only || o->reset || !o->update) - return; - if (!lstat(path, &st)) - die("Untracked working tree file '%s' " - "would be %s by merge.", path, action); -} - -static int merged_entry(struct cache_entry *merge, struct cache_entry *old, - struct unpack_trees_options *o) -{ - merge->ce_flags |= htons(CE_UPDATE); - if (old) { - /* - * See if we can re-use the old CE directly? - * That way we get the uptodate stat info. - * - * This also removes the UPDATE flag on - * a match. - */ - if (same(old, merge)) { - *merge = *old; - } else { - verify_uptodate(old, o); - invalidate_ce_path(old); - } - } - else { - verify_absent(merge->name, "overwritten", o); - invalidate_ce_path(merge); - } - - merge->ce_flags &= ~htons(CE_STAGEMASK); - add_cache_entry(merge, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE); - return 1; -} - -static int deleted_entry(struct cache_entry *ce, struct cache_entry *old, - struct unpack_trees_options *o) -{ - if (old) - verify_uptodate(old, o); - else - verify_absent(ce->name, "removed", o); - ce->ce_mode = 0; - add_cache_entry(ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE); - invalidate_ce_path(ce); - return 1; -} - -static int keep_entry(struct cache_entry *ce) -{ - add_cache_entry(ce, ADD_CACHE_OK_TO_ADD); - return 1; -} - -#if DBRT_DEBUG -static void show_stage_entry(FILE *o, - const char *label, const struct cache_entry *ce) -{ - if (!ce) - fprintf(o, "%s (missing)\n", label); - else - fprintf(o, "%s%06o %s %d\t%s\n", - label, - ntohl(ce->ce_mode), - sha1_to_hex(ce->sha1), - ce_stage(ce), - ce->name); -} -#endif - -static int threeway_merge(struct cache_entry **stages, - struct unpack_trees_options *o) -{ - struct cache_entry *index; - struct cache_entry *head; - struct cache_entry *remote = stages[o->head_idx + 1]; - int count; - int head_match = 0; - int remote_match = 0; - const char *path = NULL; - - int df_conflict_head = 0; - int df_conflict_remote = 0; - - int any_anc_missing = 0; - int no_anc_exists = 1; - int i; - - for (i = 1; i < o->head_idx; i++) { - if (!stages[i]) - any_anc_missing = 1; - else { - if (!path) - path = stages[i]->name; - no_anc_exists = 0; - } - } - - index = stages[0]; - head = stages[o->head_idx]; - - if (head == &o->df_conflict_entry) { - df_conflict_head = 1; - head = NULL; - } - - if (remote == &o->df_conflict_entry) { - df_conflict_remote = 1; - remote = NULL; - } - - if (!path && index) - path = index->name; - if (!path && head) - path = head->name; - if (!path && remote) - path = remote->name; - - /* First, if there's a #16 situation, note that to prevent #13 - * and #14. - */ - if (!same(remote, head)) { - for (i = 1; i < o->head_idx; i++) { - if (same(stages[i], head)) { - head_match = i; - } - if (same(stages[i], remote)) { - remote_match = i; - } - } - } - - /* We start with cases where the index is allowed to match - * something other than the head: #14(ALT) and #2ALT, where it - * is permitted to match the result instead. - */ - /* #14, #14ALT, #2ALT */ - if (remote && !df_conflict_head && head_match && !remote_match) { - if (index && !same(index, remote) && !same(index, head)) - reject_merge(index); - return merged_entry(remote, index, o); - } - /* - * If we have an entry in the index cache, then we want to - * make sure that it matches head. - */ - if (index && !same(index, head)) { - reject_merge(index); - } - - if (head) { - /* #5ALT, #15 */ - if (same(head, remote)) - return merged_entry(head, index, o); - /* #13, #3ALT */ - if (!df_conflict_remote && remote_match && !head_match) - return merged_entry(head, index, o); - } - - /* #1 */ - if (!head && !remote && any_anc_missing) - return 0; - - /* Under the new "aggressive" rule, we resolve mostly trivial - * cases that we historically had git-merge-one-file resolve. - */ - if (o->aggressive) { - int head_deleted = !head && !df_conflict_head; - int remote_deleted = !remote && !df_conflict_remote; - /* - * Deleted in both. - * Deleted in one and unchanged in the other. - */ - if ((head_deleted && remote_deleted) || - (head_deleted && remote && remote_match) || - (remote_deleted && head && head_match)) { - if (index) - return deleted_entry(index, index, o); - else if (path) - verify_absent(path, "removed", o); - return 0; - } - /* - * Added in both, identically. - */ - if (no_anc_exists && head && remote && same(head, remote)) - return merged_entry(head, index, o); - - } - - /* Below are "no merge" cases, which require that the index be - * up-to-date to avoid the files getting overwritten with - * conflict resolution files. - */ - if (index) { - verify_uptodate(index, o); - } - else if (path) - verify_absent(path, "overwritten", o); - - o->nontrivial_merge = 1; - - /* #2, #3, #4, #6, #7, #9, #11. */ - count = 0; - if (!head_match || !remote_match) { - for (i = 1; i < o->head_idx; i++) { - if (stages[i]) { - keep_entry(stages[i]); - count++; - break; - } - } - } -#if DBRT_DEBUG - else { - fprintf(stderr, "read-tree: warning #16 detected\n"); - show_stage_entry(stderr, "head ", stages[head_match]); - show_stage_entry(stderr, "remote ", stages[remote_match]); - } -#endif - if (head) { count += keep_entry(head); } - if (remote) { count += keep_entry(remote); } - return count; -} - -/* - * Two-way merge. - * - * The rule is to "carry forward" what is in the index without losing - * information across a "fast forward", favoring a successful merge - * over a merge failure when it makes sense. For details of the - * "carry forward" rule, please see . - * - */ -static int twoway_merge(struct cache_entry **src, - struct unpack_trees_options *o) -{ - struct cache_entry *current = src[0]; - struct cache_entry *oldtree = src[1], *newtree = src[2]; - - if (o->merge_size != 2) - return error("Cannot do a twoway merge of %d trees", - o->merge_size); - - if (current) { - if ((!oldtree && !newtree) || /* 4 and 5 */ - (!oldtree && newtree && - same(current, newtree)) || /* 6 and 7 */ - (oldtree && newtree && - same(oldtree, newtree)) || /* 14 and 15 */ - (oldtree && newtree && - !same(oldtree, newtree) && /* 18 and 19*/ - same(current, newtree))) { - return keep_entry(current); - } - else if (oldtree && !newtree && same(current, oldtree)) { - /* 10 or 11 */ - return deleted_entry(oldtree, current, o); - } - else if (oldtree && newtree && - same(current, oldtree) && !same(current, newtree)) { - /* 20 or 21 */ - return merged_entry(newtree, current, o); - } - else { - /* all other failures */ - if (oldtree) - reject_merge(oldtree); - if (current) - reject_merge(current); - if (newtree) - reject_merge(newtree); - return -1; - } - } - else if (newtree) - return merged_entry(newtree, current, o); - else - return deleted_entry(oldtree, current, o); -} - -/* - * Bind merge. - * - * Keep the index entries at stage0, collapse stage1 but make sure - * stage0 does not have anything there. - */ -static int bind_merge(struct cache_entry **src, - struct unpack_trees_options *o) -{ - struct cache_entry *old = src[0]; - struct cache_entry *a = src[1]; - - if (o->merge_size != 1) - return error("Cannot do a bind merge of %d trees\n", - o->merge_size); - if (a && old) - die("Entry '%s' overlaps. Cannot bind.", a->name); - if (!a) - return keep_entry(old); - else - return merged_entry(a, NULL, o); -} - -/* - * One-way merge. - * - * The rule is: - * - take the stat information from stage0, take the data from stage1 - */ -static int oneway_merge(struct cache_entry **src, - struct unpack_trees_options *o) -{ - struct cache_entry *old = src[0]; - struct cache_entry *a = src[1]; - - if (o->merge_size != 1) - return error("Cannot do a oneway merge of %d trees", - o->merge_size); - - if (!a) - return deleted_entry(old, old, o); - if (old && same(old, a)) { - if (o->reset) { - struct stat st; - if (lstat(old->name, &st) || - ce_match_stat(old, &st, 1)) - old->ce_flags |= htons(CE_UPDATE); - } - return keep_entry(old); - } - return merged_entry(a, old, o); -} - static int read_cache_unmerged(void) { int i; @@ -432,7 +36,7 @@ static int read_cache_unmerged(void) if (ce_stage(ce)) { if (last && !strcmp(ce->name, last->name)) continue; - invalidate_ce_path(ce); + cache_tree_invalidate_path(active_cache_tree, ce->name); last = ce; ce->ce_mode = 0; ce->ce_flags &= ~htons(CE_STAGEMASK); diff --git a/unpack-trees.c b/unpack-trees.c index 20251822e4..a20639be70 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -3,8 +3,11 @@ #include "cache.h" #include "tree.h" #include "tree-walk.h" +#include "cache-tree.h" #include "unpack-trees.h" +#define DBRT_DEBUG 1 + struct tree_entry_list { struct tree_entry_list *next; unsigned directory : 1; @@ -22,6 +25,9 @@ static struct tree_entry_list *create_tree_entry_list(struct tree *tree) struct tree_entry_list *ret = NULL; struct tree_entry_list **list_p = &ret; + if (!tree->object.parsed) + parse_tree(tree); + desc.buf = tree->buffer; desc.size = tree->size; @@ -368,12 +374,14 @@ int unpack_trees(struct object_list *trees, struct unpack_trees_options *o) memset(&df_conflict_list, 0, sizeof(df_conflict_list)); df_conflict_list.next = &df_conflict_list; + memset(&state, 0, sizeof(state)); state.base_dir = ""; state.force = 1; state.quiet = 1; state.refresh_cache = 1; o->merge_size = len; + memset(&df_conflict_entry, 0, sizeof(df_conflict_entry)); o->df_conflict_entry = &df_conflict_entry; if (len) { @@ -393,3 +401,399 @@ int unpack_trees(struct object_list *trees, struct unpack_trees_options *o) check_updates(active_cache, active_nr, o); return 0; } + +/* Here come the merge functions */ + +static void reject_merge(struct cache_entry *ce) +{ + die("Entry '%s' would be overwritten by merge. Cannot merge.", + ce->name); +} + +static int same(struct cache_entry *a, struct cache_entry *b) +{ + if (!!a != !!b) + return 0; + if (!a && !b) + return 1; + return a->ce_mode == b->ce_mode && + !memcmp(a->sha1, b->sha1, 20); +} + + +/* + * When a CE gets turned into an unmerged entry, we + * want it to be up-to-date + */ +static void verify_uptodate(struct cache_entry *ce, + struct unpack_trees_options *o) +{ + struct stat st; + + if (o->index_only || o->reset) + return; + + if (!lstat(ce->name, &st)) { + unsigned changed = ce_match_stat(ce, &st, 1); + if (!changed) + return; + errno = 0; + } + if (o->reset) { + ce->ce_flags |= htons(CE_UPDATE); + return; + } + if (errno == ENOENT) + return; + die("Entry '%s' not uptodate. Cannot merge.", ce->name); +} + +static void invalidate_ce_path(struct cache_entry *ce) +{ + if (ce) + cache_tree_invalidate_path(active_cache_tree, ce->name); +} + +/* + * We do not want to remove or overwrite a working tree file that + * is not tracked. + */ +static void verify_absent(const char *path, const char *action, + struct unpack_trees_options *o) +{ + struct stat st; + + if (o->index_only || o->reset || !o->update) + return; + if (!lstat(path, &st)) + die("Untracked working tree file '%s' " + "would be %s by merge.", path, action); +} + +static int merged_entry(struct cache_entry *merge, struct cache_entry *old, + struct unpack_trees_options *o) +{ + merge->ce_flags |= htons(CE_UPDATE); + if (old) { + /* + * See if we can re-use the old CE directly? + * That way we get the uptodate stat info. + * + * This also removes the UPDATE flag on + * a match. + */ + if (same(old, merge)) { + *merge = *old; + } else { + verify_uptodate(old, o); + invalidate_ce_path(old); + } + } + else { + verify_absent(merge->name, "overwritten", o); + invalidate_ce_path(merge); + } + + merge->ce_flags &= ~htons(CE_STAGEMASK); + add_cache_entry(merge, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE); + return 1; +} + +static int deleted_entry(struct cache_entry *ce, struct cache_entry *old, + struct unpack_trees_options *o) +{ + if (old) + verify_uptodate(old, o); + else + verify_absent(ce->name, "removed", o); + ce->ce_mode = 0; + add_cache_entry(ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE); + invalidate_ce_path(ce); + return 1; +} + +static int keep_entry(struct cache_entry *ce) +{ + add_cache_entry(ce, ADD_CACHE_OK_TO_ADD); + return 1; +} + +#if DBRT_DEBUG +static void show_stage_entry(FILE *o, + const char *label, const struct cache_entry *ce) +{ + if (!ce) + fprintf(o, "%s (missing)\n", label); + else + fprintf(o, "%s%06o %s %d\t%s\n", + label, + ntohl(ce->ce_mode), + sha1_to_hex(ce->sha1), + ce_stage(ce), + ce->name); +} +#endif + +int threeway_merge(struct cache_entry **stages, + struct unpack_trees_options *o) +{ + struct cache_entry *index; + struct cache_entry *head; + struct cache_entry *remote = stages[o->head_idx + 1]; + int count; + int head_match = 0; + int remote_match = 0; + const char *path = NULL; + + int df_conflict_head = 0; + int df_conflict_remote = 0; + + int any_anc_missing = 0; + int no_anc_exists = 1; + int i; + + for (i = 1; i < o->head_idx; i++) { + if (!stages[i]) + any_anc_missing = 1; + else { + if (!path) + path = stages[i]->name; + no_anc_exists = 0; + } + } + + index = stages[0]; + head = stages[o->head_idx]; + + if (head == o->df_conflict_entry) { + df_conflict_head = 1; + head = NULL; + } + + if (remote == o->df_conflict_entry) { + df_conflict_remote = 1; + remote = NULL; + } + + if (!path && index) + path = index->name; + if (!path && head) + path = head->name; + if (!path && remote) + path = remote->name; + + /* First, if there's a #16 situation, note that to prevent #13 + * and #14. + */ + if (!same(remote, head)) { + for (i = 1; i < o->head_idx; i++) { + if (same(stages[i], head)) { + head_match = i; + } + if (same(stages[i], remote)) { + remote_match = i; + } + } + } + + /* We start with cases where the index is allowed to match + * something other than the head: #14(ALT) and #2ALT, where it + * is permitted to match the result instead. + */ + /* #14, #14ALT, #2ALT */ + if (remote && !df_conflict_head && head_match && !remote_match) { + if (index && !same(index, remote) && !same(index, head)) + reject_merge(index); + return merged_entry(remote, index, o); + } + /* + * If we have an entry in the index cache, then we want to + * make sure that it matches head. + */ + if (index && !same(index, head)) { + reject_merge(index); + } + + if (head) { + /* #5ALT, #15 */ + if (same(head, remote)) + return merged_entry(head, index, o); + /* #13, #3ALT */ + if (!df_conflict_remote && remote_match && !head_match) + return merged_entry(head, index, o); + } + + /* #1 */ + if (!head && !remote && any_anc_missing) + return 0; + + /* Under the new "aggressive" rule, we resolve mostly trivial + * cases that we historically had git-merge-one-file resolve. + */ + if (o->aggressive) { + int head_deleted = !head && !df_conflict_head; + int remote_deleted = !remote && !df_conflict_remote; + /* + * Deleted in both. + * Deleted in one and unchanged in the other. + */ + if ((head_deleted && remote_deleted) || + (head_deleted && remote && remote_match) || + (remote_deleted && head && head_match)) { + if (index) + return deleted_entry(index, index, o); + else if (path) + verify_absent(path, "removed", o); + return 0; + } + /* + * Added in both, identically. + */ + if (no_anc_exists && head && remote && same(head, remote)) + return merged_entry(head, index, o); + + } + + /* Below are "no merge" cases, which require that the index be + * up-to-date to avoid the files getting overwritten with + * conflict resolution files. + */ + if (index) { + verify_uptodate(index, o); + } + else if (path) + verify_absent(path, "overwritten", o); + + o->nontrivial_merge = 1; + + /* #2, #3, #4, #6, #7, #9, #11. */ + count = 0; + if (!head_match || !remote_match) { + for (i = 1; i < o->head_idx; i++) { + if (stages[i]) { + keep_entry(stages[i]); + count++; + break; + } + } + } +#if DBRT_DEBUG + else { + fprintf(stderr, "read-tree: warning #16 detected\n"); + show_stage_entry(stderr, "head ", stages[head_match]); + show_stage_entry(stderr, "remote ", stages[remote_match]); + } +#endif + if (head) { count += keep_entry(head); } + if (remote) { count += keep_entry(remote); } + return count; +} + +/* + * Two-way merge. + * + * The rule is to "carry forward" what is in the index without losing + * information across a "fast forward", favoring a successful merge + * over a merge failure when it makes sense. For details of the + * "carry forward" rule, please see . + * + */ +int twoway_merge(struct cache_entry **src, + struct unpack_trees_options *o) +{ + struct cache_entry *current = src[0]; + struct cache_entry *oldtree = src[1], *newtree = src[2]; + + if (o->merge_size != 2) + return error("Cannot do a twoway merge of %d trees", + o->merge_size); + + if (current) { + if ((!oldtree && !newtree) || /* 4 and 5 */ + (!oldtree && newtree && + same(current, newtree)) || /* 6 and 7 */ + (oldtree && newtree && + same(oldtree, newtree)) || /* 14 and 15 */ + (oldtree && newtree && + !same(oldtree, newtree) && /* 18 and 19*/ + same(current, newtree))) { + return keep_entry(current); + } + else if (oldtree && !newtree && same(current, oldtree)) { + /* 10 or 11 */ + return deleted_entry(oldtree, current, o); + } + else if (oldtree && newtree && + same(current, oldtree) && !same(current, newtree)) { + /* 20 or 21 */ + return merged_entry(newtree, current, o); + } + else { + /* all other failures */ + if (oldtree) + reject_merge(oldtree); + if (current) + reject_merge(current); + if (newtree) + reject_merge(newtree); + return -1; + } + } + else if (newtree) + return merged_entry(newtree, current, o); + else + return deleted_entry(oldtree, current, o); +} + +/* + * Bind merge. + * + * Keep the index entries at stage0, collapse stage1 but make sure + * stage0 does not have anything there. + */ +int bind_merge(struct cache_entry **src, + struct unpack_trees_options *o) +{ + struct cache_entry *old = src[0]; + struct cache_entry *a = src[1]; + + if (o->merge_size != 1) + return error("Cannot do a bind merge of %d trees\n", + o->merge_size); + if (a && old) + die("Entry '%s' overlaps. Cannot bind.", a->name); + if (!a) + return keep_entry(old); + else + return merged_entry(a, NULL, o); +} + +/* + * One-way merge. + * + * The rule is: + * - take the stat information from stage0, take the data from stage1 + */ +int oneway_merge(struct cache_entry **src, + struct unpack_trees_options *o) +{ + struct cache_entry *old = src[0]; + struct cache_entry *a = src[1]; + + if (o->merge_size != 1) + return error("Cannot do a oneway merge of %d trees", + o->merge_size); + + if (!a) + return deleted_entry(old, old, o); + if (old && same(old, a)) { + if (o->reset) { + struct stat st; + if (lstat(old->name, &st) || + ce_match_stat(old, &st, 1)) + old->ce_flags |= htons(CE_UPDATE); + } + return keep_entry(old); + } + return merged_entry(a, old, o); +} diff --git a/unpack-trees.h b/unpack-trees.h index 38af89a6b7..c4601621cd 100644 --- a/unpack-trees.h +++ b/unpack-trees.h @@ -27,4 +27,9 @@ struct unpack_trees_options { extern int unpack_trees(struct object_list *trees, struct unpack_trees_options *options); +int threeway_merge(struct cache_entry **stages, struct unpack_trees_options *o); +int twoway_merge(struct cache_entry **src, struct unpack_trees_options *o); +int bind_merge(struct cache_entry **src, struct unpack_trees_options *o); +int oneway_merge(struct cache_entry **src, struct unpack_trees_options *o); + #endif