diff options
-rw-r--r-- | .gitignore | 6 | ||||
-rw-r--r-- | Documentation/git-daemon.txt | 13 | ||||
-rw-r--r-- | Documentation/git-http-fetch.txt | 8 | ||||
-rw-r--r-- | Documentation/git-local-fetch.txt | 6 | ||||
-rw-r--r-- | Documentation/git.txt | 12 | ||||
-rw-r--r-- | INSTALL | 9 | ||||
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | builtin-apply.c | 71 | ||||
-rw-r--r-- | builtin-diff-files.c | 2 | ||||
-rw-r--r-- | builtin-diff-index.c | 2 | ||||
-rw-r--r-- | builtin-diff-tree.c | 2 | ||||
-rw-r--r-- | builtin-diff.c | 13 | ||||
-rw-r--r-- | builtin-help.c | 2 | ||||
-rw-r--r-- | builtin-log.c | 9 | ||||
-rw-r--r-- | builtin-mailinfo.c | 2 | ||||
-rw-r--r-- | config.mak.in | 24 | ||||
-rw-r--r-- | configure.ac | 183 | ||||
-rw-r--r-- | daemon.c | 2 | ||||
-rw-r--r-- | fetch.c | 122 | ||||
-rw-r--r-- | fetch.h | 17 | ||||
-rwxr-xr-x | git-cvsserver.perl | 8 | ||||
-rwxr-xr-x | git-instaweb.sh | 9 | ||||
-rwxr-xr-x | git-lost-found.sh | 2 | ||||
-rwxr-xr-x | git-reset.sh | 5 | ||||
-rw-r--r-- | git.c | 113 | ||||
-rwxr-xr-x | gitweb/gitweb.cgi | 83 | ||||
-rw-r--r-- | http-fetch.c | 45 | ||||
-rw-r--r-- | local-fetch.c | 34 | ||||
-rw-r--r-- | refs.c | 5 | ||||
-rw-r--r-- | ssh-fetch.c | 6 | ||||
-rwxr-xr-x | t/t1400-update-ref.sh | 12 | ||||
-rwxr-xr-x | t/t4102-apply-rename.sh | 24 | ||||
-rwxr-xr-x | t/t4103-apply-binary.sh | 4 |
33 files changed, 679 insertions, 181 deletions
diff --git a/.gitignore b/.gitignore index 52d61f3193..fb0fa3f16a 100644 --- a/.gitignore +++ b/.gitignore @@ -137,4 +137,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/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'. + <directory>:: A directory to add to the whitelist of allowed directories. Unless --strict-paths is specified this will also include subdirectories 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] <commit> <url> +'git-http-fetch' [-c] [-t] [-a] [-d] [-v] [-w filename] [--recover] [--stdin] <commit> <url> DESCRIPTION ----------- @@ -33,6 +33,12 @@ commit-id:: Writes the commit-id into the filename under $GIT_DIR/refs/<filename> 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 + + <commit-id>['\t'<filename-as-in--w>] + Author ------ Written by Linus Torvalds <torvalds@osdl.org> 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/<filename> 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 + + <commit-id>['\t'<filename-as-in--w>] + Author ------ Written by Junio C Hamano <junkio@cox.net> 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=<path>:: + 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 --------------------- @@ -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 @@ -353,6 +353,7 @@ ifneq (,$(findstring arm,$(uname_M))) ARM_SHA1 = YesPlease endif +-include config.mak.autogen -include config.mak ifdef WITH_OWN_SUBPROCESS_PY @@ -615,6 +616,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 @@ -770,6 +773,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 diff --git a/builtin-apply.c b/builtin-apply.c index d924ac3d0a..d4381d9a8f 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; @@ -1499,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) @@ -1615,7 +1657,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 +2185,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 +2206,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 +2272,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 +2283,7 @@ int cmd_apply(int argc, const char **argv, char **envp) int fd; if (!strcmp(arg, "-")) { - apply_patch(0, "<stdin>", inaccurate_eof); + apply_patch(0, "<stdin>", reverse, inaccurate_eof); read_stdin = 0; continue; } @@ -2313,6 +2360,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 +2384,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, "<stdin>", inaccurate_eof); + apply_patch(0, "<stdin>", reverse, inaccurate_eof); if (whitespace_error) { if (squelch_whitespace_errors && squelch_whitespace_errors < whitespace_error) { 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..dca223235d 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) { @@ -346,7 +347,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); } 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/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); 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; } diff --git a/config.mak.in b/config.mak.in new file mode 100644 index 0000000000..04f508ab90 --- /dev/null +++ b/config.mak.in @@ -0,0 +1,24 @@ +# 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@ +#gitexecdir = @libexecdir@/git-core/ +datarootdir = @datarootdir@ +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..c1f7751e6f --- /dev/null +++ b/configure.ac @@ -0,0 +1,183 @@ +# -*- 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_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. +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 lose 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],[], +[AC_CHECK_LIB([socket],[socket], + [GIT_CONF_APPEND_LINE(NEEDS_SOCKET=YesPlease)],[])]) + + +## Checks for header files. + + +## 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 <dirent.h>]) +# +# 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 <dirent.h>]) +# +# 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 <netinet/in.h>]) + + +## 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(). +# +# 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}":"${config_append}"]) +AC_OUTPUT + + +## Cleanup +rm -f "${config_append}" @@ -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; @@ -7,9 +7,7 @@ #include "tag.h" #include "blob.h" #include "refs.h" - -const char *write_ref = NULL; -const char *write_ref_log_details = NULL; +#include "strbuf.h" int get_tree = 0; int get_history = 0; @@ -213,54 +211,106 @@ static int mark_complete(const char *path, const unsigned char *sha1) return 0; } -int pull(char *target) +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) { - struct ref_lock *lock = NULL; - unsigned char sha1[20]; + while (targets--) { + free(target[targets]); + if (write_ref && write_ref[targets]) + free((char *) write_ref[targets]); + } +} + +int pull(int targets, char **target, const char **write_ref, + const char *write_ref_log_details) +{ + 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 || !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; + 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 (process(lookup_unknown_object(sha1))) { - if (lock) - unlock_ref(lock); - return -1; + + 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; } - if (loop()) { - if (lock) - unlock_ref(lock); - return -1; + for (i = 0; i < targets; i++) { + if (!write_ref || !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); - 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; - } return 0; + + +unlock_and_fail: + for (i = 0; i < targets; i++) + if (lock[i]) + unlock_ref(lock[i]); + return -1; } @@ -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,15 @@ extern int get_recover; /* Report what we got under get_verbosely */ extern void pull_say(const char *, const char *); -extern int pull(char *target); +/* 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, + const char *write_ref_log_details); #endif /* PULL_H */ 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"; 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" <<EOF AddHandler cgi-script .cgi @@ -234,4 +238,5 @@ esac start_httpd test -z "$browser" && browser=echo -$browser http://127.0.0.1:$port +url=http://127.0.0.1:$port +$browser $url || echo $url 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 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 @@ -35,6 +35,59 @@ 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; + + /* + * 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 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)--; + handled++; + } + return handled; +} + static const char *alias_command; static char *alias_string = NULL; @@ -106,7 +159,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 +167,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); @@ -269,51 +326,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) { - cmd = *++argv; - argc--; - - if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) { - setup_pager(); - continue; - } - - 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: diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi index 30cb624b2a..243a2921f8 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 "<div class=\"page_path\"><b>/</b></div>\n"; + } elsif ($type =~ "blob") { + print "<div class=\"page_path\"><b>" . + $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;f=$file_name")}, esc_html($name)) . "</b><br/></div>\n"; + } else { + print "<div class=\"page_path\"><b>" . esc_html($name) . "</b><br/></div>\n"; + } +} + sub git_tag { my $head = git_read_head($project); git_header_html(); @@ -1266,7 +1280,7 @@ sub git_blame { "<div>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "</div>\n"; - print "<div class=\"page_path\"><b>" . esc_html($file_name) . "</b></div>\n"; + git_print_page_path($file_name); print "<div class=\"page_body\">\n"; print <<HTML; <table class="blame"> @@ -1531,6 +1545,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 +1576,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); @@ -1592,9 +1618,7 @@ sub git_blob { "<br/><br/></div>\n" . "<div class=\"title\">$hash</div>\n"; } - if (defined $file_name) { - print "<div class=\"page_path\"><b>" . esc_html($file_name) . "</b></div>\n"; - } + git_print_page_path($file_name, "blob"); print "<div class=\"page_body\">\n"; my $nr; while (my $line = <$fd>) { @@ -1659,10 +1683,8 @@ sub git_tree { } if (defined $file_name) { $base = esc_html("$file_name/"); - print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b></div>\n"; - } else { - print "<div class=\"page_path\"><b>/</b></div>\n"; } + git_print_page_path($file_name); print "<div class=\"page_body\">\n"; print "<table cellspacing=\"0\">\n"; my $alternate = 0; @@ -1687,7 +1709,7 @@ sub git_tree { "<td class=\"link\">" . $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;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") . "</td>\n"; } elsif ($t_type eq "tree") { @@ -1696,7 +1718,7 @@ sub git_tree { "</td>\n" . "<td class=\"link\">" . $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") . "</td>\n"; } print "</tr>\n"; @@ -2041,7 +2063,7 @@ sub git_commit { "<td><span class=\"file_status deleted\">[deleted " . file_type($from_mode). "]</span></td>\n" . "<td class=\"link\">" . $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") . "</td>\n" } elsif ($status eq "M" || $status eq "T") { my $mode_chnge = ""; @@ -2072,7 +2094,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 "</td>\n"; } elsif ($status eq "R") { my ($from_file, $to_file) = split "\t", $file; @@ -2120,9 +2142,7 @@ sub git_blobdiff { "<br/><br/></div>\n" . "<div class=\"title\">$hash vs $hash_parent</div>\n"; } - if (defined $file_name) { - print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b></div>\n"; - } + git_print_page_path($file_name, "blob"); print "<div class=\"page_body\">\n" . "<div class=\"diff_info\">blob:" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) . @@ -2293,10 +2313,11 @@ 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 $ftype; + my %co = git_read_commit($hash_base); if (!%co) { die_error(undef, "Unknown commit object."); } @@ -2306,18 +2327,24 @@ 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") . "<br/><br/>\n" . "</div>\n"; print "<div>\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" . "</div>\n"; - print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b><br/></div>\n"; + if (!defined $hash && defined $file_name) { + $hash = git_get_hash_by_path($hash_base, $file_name); + } + if (defined $hash) { + $ftype = git_get_type($hash); + } + git_print_page_path($file_name, $ftype); open my $fd, "-|", - "$GIT rev-list --full-history $hash -- \'$file_name\'"; + "$GIT rev-list --full-history $hash_base -- \'$file_name\'"; print "<table cellspacing=\"0\">\n"; my $alternate = 0; while (my $line = <$fd>) { @@ -2345,7 +2372,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 " | " . diff --git a/http-fetch.c b/http-fetch.c index 12493fbed2..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,10 +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) { - 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; @@ -1237,20 +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] [-d] [-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]; - write_ref_log_details = url; + 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(commit_id)) + 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" diff --git a/local-fetch.c b/local-fetch.c index ffa4887570..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,17 +195,19 @@ 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] [--stdin] 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. * 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) { - char *commit_id; + int commits; + const char **write_ref = NULL; + char **commit_id; int arg = 1; setup_git_directory(); @@ -229,21 +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]; - write_ref_log_details = path; + 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(commit_id)) + if (pull(commits, commit_id, write_ref, path)) return 1; + if (commits_on_stdin) + pull_targets_free(commits, commit_id, write_ref); + return 0; } @@ -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/ssh-fetch.c b/ssh-fetch.c index 28f7fd9174..6e16568f88 100644 --- a/ssh-fetch.c +++ b/ssh-fetch.c @@ -120,9 +120,10 @@ 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) { + 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(1, &commit_id, &write_ref, url)) return 1; return 0; 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" \ @@ -26,6 +28,16 @@ test_expect_success \ 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 && test $A = $(cat .git/$m)' 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 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 |