Merge branch 'jc/unpack'
authorJunio C Hamano <junkio@cox.net>
Wed, 13 Sep 2006 20:00:02 +0000 (13:00 -0700)
committerJunio C Hamano <junkio@cox.net>
Wed, 13 Sep 2006 20:00:02 +0000 (13:00 -0700)
* jc/unpack:
unpack-objects -r: call it "recover".
unpack-objects desperately salvages objects from a corrupt pack

34 files changed:
.gitignore
Documentation/git-apply.txt
Documentation/git-daemon.txt
Documentation/git-rev-list.txt
Makefile
builtin-apply.c
builtin-pack-objects.c
builtin-rev-list.c
cache.h
config.mak.in
configure.ac
connect.c
contrib/vim/README [new file with mode: 0644]
contrib/vim/syntax/gitcommit.vim [new file with mode: 0644]
daemon.c
diff-lib.c
diff.c
fetch-pack.c
git-repack.sh
git.c
gitweb/git-favicon.png [new file with mode: 0644]
gitweb/gitweb.perl
object-refs.c
object.h
peek-remote.c
quote.c
quote.h
revision.c
revision.h
rsh.c
send-pack.c
sha1_file.c
t/t4103-apply-binary.sh
trace.c
index 78cb6715398eabcd070e5301798b935f5db62565..0d608fe12ada909959a524ec60c4a6aa491bd3fc 100644 (file)
@@ -141,6 +141,7 @@ git-core.spec
 *.py[co]
 config.mak
 autom4te.cache
+config.cache
 config.log
 config.status
 config.mak.autogen
index c76cfffdc6cd9982aa02e34b2b09fc22897e7402..0a6f7b32192df8a8a2266b0d302271a62c612b1f 100644 (file)
@@ -110,15 +110,10 @@ OPTIONS
        deletion part but not addition part.
 
 --allow-binary-replacement, --binary::
-       When applying a patch, which is a git-enhanced patch
-       that was prepared to record the pre- and post-image object
-       name in full, and the path being patched exactly matches
-       the object the patch applies to (i.e. "index" line's
-       pre-image object name is what is in the working tree),
-       and the post-image object is available in the object
-       database, use the post-image object as the patch
-       result.  This allows binary files to be patched in a
-       very limited way.
+       Historically we did not allow binary patch applied
+       without an explicit permission from the user, and this
+       flag was the way to do so.  Currently we always allow binary
+       patch application, so this is a no-op.
 
 --exclude=<path-pattern>::
        Don't apply changes to files matching the given path pattern. This can
index 17619a3f57c939f63a5648b166b52263565e6cb2..741f2c69bdace527c57b644ed072ead4dcb46201 100644 (file)
@@ -11,17 +11,16 @@ 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]
-            [--reuseaddr] [--detach] [--pid-file=file]
-            [--user=user [--group=group]] [directory...]
+             [--enable=service] [--disable=service]
+            [--allow-override=service] [--forbid-override=service]
+             [--reuseaddr] [--detach] [--pid-file=file]
+             [--user=user [--group=group]] [directory...]
 
 DESCRIPTION
 -----------
 A really simple TCP git daemon that normally listens on port "DEFAULT_GIT_PORT"
-aka 9418. It waits for a connection, and will just execute "git-upload-pack"
-when it gets one.
-
-It's careful in that there's a magic request-line that gives the command and
-what directory to upload, and it verifies that the directory is OK.
+aka 9418.  It waits for a connection asking for a service, and will serve
+that service if it is enabled.
 
 It verifies that the directory has the magic file "git-daemon-export-ok", and
 it will refuse to export any git directory that hasn't explicitly been marked
@@ -29,7 +28,12 @@ for export this way (unless the '--export-all' parameter is specified). If you
 pass some directory paths as 'git-daemon' arguments, you can further restrict
 the offers to a whitelist comprising of those.
 
-This is ideally suited for read-only updates, i.e., pulling from git repositories.
+By default, only `upload-pack` service is enabled, which serves
+`git-fetch-pack` and `git-peek-remote` clients that are invoked
+from `git-fetch`, `git-ls-remote`, and `git-clone`.
+
+This is ideally suited for read-only updates, i.e., pulling from
+git repositories.
 
 OPTIONS
 -------
@@ -105,11 +109,32 @@ Giving these options is an error when used with `--inetd`; use
 the facility of inet daemon to achieve the same before spawning
 `git-daemon` if needed.
 
+--enable-service, --disable-service::
+       Enable/disable the service site-wide per default.  Note
+       that a service disabled site-wide can still be enabled
+       per repository if it is marked overridable and the
+       repository enables the service with an configuration
+       item.
+
+--allow-override, --forbid-override::
+       Allow/forbid overriding the site-wide default with per
+       repository configuration.  By default, all the services
+       are overridable.
+
 <directory>::
        A directory to add to the whitelist of allowed directories. Unless
        --strict-paths is specified this will also include subdirectories
        of each named directory.
 
+SERVICES
+--------
+
+upload-pack::
+       This serves `git-fetch-pack` and `git-peek-remote`
+       clients.  It is enabled by default, but a repository can
+       disable it by setting `daemon.uploadpack` configuration
+       item to `false`.
+
 Author
 ------
 Written by Linus Torvalds <torvalds@osdl.org>, YOSHIFUJI Hideaki
index 3c4c2fbfb9b2b9a0873d35850d503c2de199f556..28966adbbce60c2d3fa02f47bf0797bc29d32f60 100644 (file)
@@ -17,6 +17,7 @@ SYNOPSIS
             [ \--remove-empty ]
             [ \--not ]
             [ \--all ]
+            [ \--stdin ]
             [ \--topo-order ]
             [ \--parents ]
             [ [\--objects | \--objects-edge] [ \--unpacked ] ]
@@ -171,6 +172,11 @@ limiting may be applied.
        Pretend as if all the refs in `$GIT_DIR/refs/` are listed on the
        command line as '<commit>'.
 
+--stdin::
+
+       In addition to the '<commit>' listed on the command
+       line, read them from the standard input.
+
 --merge::
 
        After a failed merge, show refs that touch files having a
index a639cdfcfbd7525637496fbcaa8ced3949cb6e65..7b3114f3aac8f040b2d7f291e62a980e282b722e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -131,6 +131,7 @@ GITWEB_LIST =
 GITWEB_HOMETEXT = indextext.html
 GITWEB_CSS = gitweb.css
 GITWEB_LOGO = git-logo.png
+GITWEB_FAVICON = git-favicon.png
 
 export prefix bindir gitexecdir template_dir GIT_PYTHON_DIR
 
@@ -635,6 +636,7 @@ gitweb/gitweb.cgi: gitweb/gitweb.perl
            -e 's|++GITWEB_HOMETEXT++|$(GITWEB_HOMETEXT)|g' \
            -e 's|++GITWEB_CSS++|$(GITWEB_CSS)|g' \
            -e 's|++GITWEB_LOGO++|$(GITWEB_LOGO)|g' \
+           -e 's|++GITWEB_FAVICON++|$(GITWEB_FAVICON)|g' \
            $< >$@+
        chmod +x $@+
        mv $@+ $@
index 872c8005a27c0085d47680a8e638b8cf6f3d70a3..6e0864ce27619d1153575876e2a617a392906aed 100644 (file)
@@ -28,7 +28,6 @@ static int prefix_length = -1;
 static int newfd = -1;
 
 static int p_value = 1;
-static int allow_binary_replacement;
 static int check_index;
 static int write_index;
 static int cached;
@@ -1228,14 +1227,12 @@ static int parse_chunk(char *buffer, unsigned long size, struct patch *patch)
                        }
                }
 
-               /* Empty patch cannot be applied if:
-                * - it is a binary patch and we do not do binary_replace, or
-                * - text patch without metadata change
+               /* Empty patch cannot be applied if it is a text patch
+                * without metadata change.  A binary patch appears
+                * empty to us here.
                 */
                if ((apply || check) &&
-                   (patch->is_binary
-                    ? !allow_binary_replacement
-                    : !metadata_changes(patch)))
+                   (!patch->is_binary && !metadata_changes(patch)))
                        die("patch with only garbage at line %d", linenr);
        }
 
@@ -1676,11 +1673,6 @@ static int apply_binary(struct buffer_desc *desc, struct patch *patch)
        unsigned char hdr[50];
        int hdrlen;
 
-       if (!allow_binary_replacement)
-               return error("cannot apply binary patch to '%s' "
-                            "without --allow-binary-replacement",
-                            name);
-
        /* For safety, we require patch index line to contain
         * full 40-byte textual SHA1 for old and new, at least for now.
         */
@@ -2497,8 +2489,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
                }
                if (!strcmp(arg, "--allow-binary-replacement") ||
                    !strcmp(arg, "--binary")) {
-                       allow_binary_replacement = 1;
-                       continue;
+                       continue; /* now no-op */
                }
                if (!strcmp(arg, "--numstat")) {
                        apply = 0;
index 46f524dfc32a5eaea06df6e3502c83710a1c09bb..149fa283971712650f124e96aa5bf9e2f99b0ebb 100644 (file)
@@ -65,6 +65,7 @@ static unsigned char pack_file_sha1[20];
 static int progress = 1;
 static volatile sig_atomic_t progress_update;
 static int window = 10;
+static int pack_to_stdout;
 
 /*
  * The object names in objects array are hashed with this hashtable,
@@ -242,6 +243,82 @@ static int encode_header(enum object_type type, unsigned long size, unsigned cha
        return n;
 }
 
+static int check_inflate(unsigned char *data, unsigned long len, unsigned long expect)
+{
+       z_stream stream;
+       unsigned char fakebuf[4096];
+       int st;
+
+       memset(&stream, 0, sizeof(stream));
+       stream.next_in = data;
+       stream.avail_in = len;
+       stream.next_out = fakebuf;
+       stream.avail_out = sizeof(fakebuf);
+       inflateInit(&stream);
+
+       while (1) {
+               st = inflate(&stream, Z_FINISH);
+               if (st == Z_STREAM_END || st == Z_OK) {
+                       st = (stream.total_out == expect &&
+                             stream.total_in == len) ? 0 : -1;
+                       break;
+               }
+               if (st != Z_BUF_ERROR) {
+                       st = -1;
+                       break;
+               }
+               stream.next_out = fakebuf;
+               stream.avail_out = sizeof(fakebuf);
+       }
+       inflateEnd(&stream);
+       return st;
+}
+
+/*
+ * we are going to reuse the existing pack entry data.  make
+ * sure it is not corrupt.
+ */
+static int revalidate_pack_entry(struct object_entry *entry, unsigned char *data, unsigned long len)
+{
+       enum object_type type;
+       unsigned long size, used;
+
+       if (pack_to_stdout)
+               return 0;
+
+       /* the caller has already called use_packed_git() for us,
+        * so it is safe to access the pack data from mmapped location.
+        * make sure the entry inflates correctly.
+        */
+       used = unpack_object_header_gently(data, len, &type, &size);
+       if (!used)
+               return -1;
+       if (type == OBJ_DELTA)
+               used += 20; /* skip base object name */
+       data += used;
+       len -= used;
+       return check_inflate(data, len, entry->size);
+}
+
+static int revalidate_loose_object(struct object_entry *entry,
+                                  unsigned char *map,
+                                  unsigned long mapsize)
+{
+       /* we already know this is a loose object with new type header. */
+       enum object_type type;
+       unsigned long size, used;
+
+       if (pack_to_stdout)
+               return 0;
+
+       used = unpack_object_header_gently(map, mapsize, &type, &size);
+       if (!used)
+               return -1;
+       map += used;
+       mapsize -= used;
+       return check_inflate(map, mapsize, size);
+}
+
 static unsigned long write_object(struct sha1file *f,
                                  struct object_entry *entry)
 {
@@ -276,6 +353,9 @@ static unsigned long write_object(struct sha1file *f,
                map = map_sha1_file(entry->sha1, &mapsize);
                if (map && !legacy_loose_object(map)) {
                        /* We can copy straight into the pack file */
+                       if (revalidate_loose_object(entry, map, mapsize))
+                               die("corrupt loose object %s",
+                                   sha1_to_hex(entry->sha1));
                        sha1write(f, map, mapsize);
                        munmap(map, mapsize);
                        written++;
@@ -286,7 +366,7 @@ static unsigned long write_object(struct sha1file *f,
                        munmap(map, mapsize);
        }
 
-       if (! to_reuse) {
+       if (!to_reuse) {
                buf = read_sha1_file(entry->sha1, type, &size);
                if (!buf)
                        die("unable to read %s", sha1_to_hex(entry->sha1));
@@ -319,6 +399,9 @@ static unsigned long write_object(struct sha1file *f,
 
                datalen = find_packed_object_size(p, entry->in_pack_offset);
                buf = (char *) p->pack_base + entry->in_pack_offset;
+
+               if (revalidate_pack_entry(entry, buf, datalen))
+                       die("corrupt delta in pack %s", sha1_to_hex(entry->sha1));
                sha1write(f, buf, datalen);
                unuse_packed_git(p);
                hdrlen = 0; /* not really */
@@ -1163,7 +1246,7 @@ static void prepare_pack(int window, int depth)
                find_deltas(sorted_by_type, window+1, depth);
 }
 
-static int reuse_cached_pack(unsigned char *sha1, int pack_to_stdout)
+static int reuse_cached_pack(unsigned char *sha1)
 {
        static const char cache[] = "pack-cache/pack-%s.%s";
        char *cached_pack, *cached_idx;
@@ -1247,7 +1330,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 {
        SHA_CTX ctx;
        char line[40 + 1 + PATH_MAX + 2];
-       int depth = 10, pack_to_stdout = 0;
+       int depth = 10;
        struct object_entry **list;
        int num_preferred_base = 0;
        int i;
@@ -1367,7 +1450,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
        if (progress && (nr_objects != nr_result))
                fprintf(stderr, "Result has %d objects.\n", nr_result);
 
-       if (reuse_cached_pack(object_list_sha1, pack_to_stdout))
+       if (reuse_cached_pack(object_list_sha1))
                ;
        else {
                if (nr_result)
index 8437454fbe4e3237aaa6aaecefe54caefb621f1b..8fe8afbd0469c689cad111df6302508d352b6c29 100644 (file)
@@ -23,6 +23,7 @@ static const char rev_list_usage[] =
 "    --no-merges\n"
 "    --remove-empty\n"
 "    --all\n"
+"    --stdin\n"
 "  ordering output:\n"
 "    --topo-order\n"
 "    --date-order\n"
@@ -304,10 +305,28 @@ static void mark_edges_uninteresting(struct commit_list *list)
        }
 }
 
+static void read_revisions_from_stdin(struct rev_info *revs)
+{
+       char line[1000];
+
+       while (fgets(line, sizeof(line), stdin) != NULL) {
+               int len = strlen(line);
+               if (line[len - 1] == '\n')
+                       line[--len] = 0;
+               if (!len)
+                       break;
+               if (line[0] == '-')
+                       die("options not supported in --stdin mode");
+               if (handle_revision_arg(line, revs, 0, 1))
+                       die("bad revision '%s'", line);
+       }
+}
+
 int cmd_rev_list(int argc, const char **argv, const char *prefix)
 {
        struct commit_list *list;
        int i;
+       int read_from_stdin = 0;
 
        init_revisions(&revs, prefix);
        revs.abbrev = 0;
@@ -329,6 +348,12 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
                        bisect_list = 1;
                        continue;
                }
+               if (!strcmp(arg, "--stdin")) {
+                       if (read_from_stdin++)
+                               die("--stdin given twice?");
+                       read_revisions_from_stdin(&revs);
+                       continue;
+               }
                usage(rev_list_usage);
 
        }
diff --git a/cache.h b/cache.h
index 195908fc34445d6c0368e1973955a6e3a058eb65..8d099979d9a04231d73307c786d25bf412a3f22c 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -267,6 +267,17 @@ extern int legacy_loose_object(unsigned char *);
 extern int has_pack_file(const unsigned char *sha1);
 extern int has_pack_index(const unsigned char *sha1);
 
+enum object_type {
+       OBJ_NONE = 0,
+       OBJ_COMMIT = 1,
+       OBJ_TREE = 2,
+       OBJ_BLOB = 3,
+       OBJ_TAG = 4,
+       /* 5/6 for future expansion */
+       OBJ_DELTA = 7,
+       OBJ_BAD,
+};
+
 /* Convert to/from hex/sha1 representation */
 #define MINIMUM_ABBREV 4
 #define DEFAULT_ABBREV 7
@@ -348,7 +359,7 @@ struct ref {
 #define REF_HEADS      (1u << 1)
 #define REF_TAGS       (1u << 2)
 
-extern int git_connect(int fd[2], char *url, const char *prog);
+extern pid_t git_connect(int fd[2], char *url, const char *prog);
 extern int finish_connect(pid_t pid);
 extern int path_match(const char *path, int nr, char **match);
 extern int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
@@ -374,6 +385,7 @@ extern int num_packed_objects(const struct packed_git *p);
 extern int nth_packed_object_sha1(const struct packed_git *, int, unsigned char*);
 extern int find_pack_entry_one(const unsigned char *, struct pack_entry *, struct packed_git *);
 extern void *unpack_entry_gently(struct pack_entry *, char *, unsigned long *);
+extern unsigned long unpack_object_header_gently(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
 extern void packed_object_info_detail(struct pack_entry *, char *, unsigned long *, unsigned long *, unsigned int *, unsigned char *);
 
 /* Dumb servers support */
index 369e6116e0aa63bc9e6ca88996b2dcfc12ebb967..6d20673b24552c505664c8d6983eb9ceb1b106d8 100644 (file)
@@ -37,4 +37,5 @@ NO_C99_FORMAT=@NO_C99_FORMAT@
 NO_STRCASESTR=@NO_STRCASESTR@
 NO_STRLCPY=@NO_STRLCPY@
 NO_SETENV=@NO_SETENV@
+NO_ICONV=@NO_ICONV@
 
index 36f9cd94d847f1dc95d293ebafbab74cf37fec53..511cac93d6cec11f3717e810d0c80b27646a5713 100644 (file)
@@ -143,10 +143,15 @@ AC_CHECK_LIB([expat], [XML_ParserCreate],
 AC_SUBST(NO_EXPAT)
 #
 # Define NEEDS_LIBICONV if linking with libc is not enough (Darwin).
+# Define NO_ICONV if neither libc nor libiconv support iconv.
 AC_CHECK_LIB([c], [iconv],
-[NEEDS_LIBICONV=],
-[NEEDS_LIBICONV=YesPlease])
+       [NEEDS_LIBICONV=],
+       AC_CHECK_LIB([iconv], [iconv],
+               [NEEDS_LIBICONV=YesPlease],
+               [NO_ICONV=YesPlease]))
 AC_SUBST(NEEDS_LIBICONV)
+AC_SUBST(NO_ICONV)
+test -n "$NEEDS_LIBICONV" && LIBS="$LIBS -liconv"
 #
 # Define NEEDS_SOCKET if linking with libc is not enough (SunOS,
 # Patrick Mauritz).
@@ -204,8 +209,8 @@ AC_SUBST(NO_IPV6)
 # do not support the 'size specifiers' introduced by C99, namely ll, hh,
 # j, z, t. (representing long long int, char, intmax_t, size_t, ptrdiff_t).
 # some C compilers supported these specifiers prior to C99 as an extension.
-AC_CACHE_CHECK(whether formatted IO functions support C99 size specifiers,
ac_cv_c_c99_format,
+AC_CACHE_CHECK([whether formatted IO functions support C99 size specifiers],
[ac_cv_c_c99_format],
 [# Actually git uses only %z (%zu) in alloc.c, and %t (%td) in mktag.c
 AC_RUN_IFELSE(
        [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
@@ -260,6 +265,16 @@ AC_SUBST(NO_SETENV)
 # Enable it on Windows.  By default, symrefs are still used.
 #
 # Define WITH_OWN_SUBPROCESS_PY if you want to use with python 2.3.
+AC_CACHE_CHECK([for subprocess.py],
+ [ac_cv_python_has_subprocess_py],
+[if $PYTHON_PATH -c 'import subprocess' 2>/dev/null; then
+       ac_cv_python_has_subprocess_py=yes
+else
+       ac_cv_python_has_subprocess_py=no
+fi])
+if test $ac_cv_python_has_subprocess_py != yes; then
+       GIT_CONF_APPEND_LINE([WITH_OWN_SUBPROCESS_PY=YesPlease])
+fi
 #
 # Define NO_ACCURATE_DIFF if your diff program at least sometimes misses
 # a missing newline at the end of the file.
@@ -329,6 +344,16 @@ GIT_PARSE_WITH(expat))
 # library directories by defining CFLAGS and LDFLAGS appropriately.
 #
 # Define NO_MMAP if you want to avoid mmap.
+#
+# Define NO_ICONV if your libc does not properly support iconv.
+AC_ARG_WITH(iconv,
+AS_HELP_STRING([--without-iconv],
+[if your architecture doesn't properly support iconv])
+AS_HELP_STRING([--with-iconv=PATH],
+[PATH is prefix for libiconv library and headers])
+AS_HELP_STRING([],
+[used only if you need linking with libiconv]),
+GIT_PARSE_WITH(iconv))
 
 ## --enable-FEATURE[=ARG] and --disable-FEATURE
 #
index 06ef387649e0645b934f3294df8b843aa328393f..c55a20a4aa31e7cf1bbf0dcec6b4ebccb655d850 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -17,7 +17,7 @@ static int check_ref(const char *name, int len, unsigned int flags)
        if (!flags)
                return 1;
 
-       if (len > 45 || memcmp(name, "refs/", 5))
+       if (len 5 || memcmp(name, "refs/", 5))
                return 0;
 
        /* Skip the "refs/" part */
@@ -599,12 +599,19 @@ static void git_proxy_connect(int fd[2], char *host)
        close(pipefd[1][0]);
 }
 
+#define MAX_CMD_LEN 1024
+
 /*
- * Yeah, yeah, fixme. Need to pass in the heads etc.
+ * This returns 0 if the transport protocol does not need fork(2),
+ * or a process id if it does.  Once done, finish the connection
+ * with finish_connect() with the value returned from this function
+ * (it is safe to call finish_connect() with 0 to support the former
+ * case).
+ *
+ * Does not return a negative value on error; it just dies.
  */
-int git_connect(int fd[2], char *url, const char *prog)
+pid_t git_connect(int fd[2], char *url, const char *prog)
 {
-       char command[1024];
        char *host, *path = url;
        char *end;
        int c;
@@ -697,8 +704,18 @@ int git_connect(int fd[2], char *url, const char *prog)
        if (pid < 0)
                die("unable to fork");
        if (!pid) {
-               snprintf(command, sizeof(command), "%s %s", prog,
-                        sq_quote(path));
+               char command[MAX_CMD_LEN];
+               char *posn = command;
+               int size = MAX_CMD_LEN;
+               int of = 0;
+
+               of |= add_to_string(&posn, &size, prog, 0);
+               of |= add_to_string(&posn, &size, " ", 0);
+               of |= add_to_string(&posn, &size, path, 1);
+
+               if (of)
+                       die("command line too long");
+
                dup2(pipefd[1][0], 0);
                dup2(pipefd[0][1], 1);
                close(pipefd[0][0]);
@@ -737,6 +754,9 @@ int git_connect(int fd[2], char *url, const char *prog)
 
 int finish_connect(pid_t pid)
 {
+       if (pid == 0)
+               return 0;
+
        while (waitpid(pid, NULL, 0) < 0) {
                if (errno != EINTR)
                        return -1;
diff --git a/contrib/vim/README b/contrib/vim/README
new file mode 100644 (file)
index 0000000..9e7881f
--- /dev/null
@@ -0,0 +1,8 @@
+To syntax highlight git's commit messages, you need to:
+  1. Copy syntax/gitcommit.vim to vim's syntax directory:
+     $ mkdir -p $HOME/.vim/syntax
+     $ cp syntax/gitcommit.vim $HOME/.vim/syntax
+  2. Auto-detect the editing of git commit files:
+     $ cat >>$HOME/.vimrc <<'EOF'
+     autocmd BufNewFile,BufRead COMMIT_EDITMSG set filetype=gitcommit
+     EOF
diff --git a/contrib/vim/syntax/gitcommit.vim b/contrib/vim/syntax/gitcommit.vim
new file mode 100644 (file)
index 0000000..a9de09f
--- /dev/null
@@ -0,0 +1,18 @@
+syn region gitLine start=/^#/ end=/$/
+syn region gitCommit start=/^# Updated but not checked in:$/ end=/^#$/ contains=gitHead,gitCommitFile
+syn region gitHead contained start=/^#   (.*)/ end=/^#$/
+syn region gitChanged start=/^# Changed but not updated:/ end=/^#$/ contains=gitHead,gitChangedFile
+syn region gitUntracked start=/^# Untracked files:/ end=/^#$/ contains=gitHead,gitUntrackedFile
+
+syn match gitCommitFile contained /^#\t.*/hs=s+2
+syn match gitChangedFile contained /^#\t.*/hs=s+2
+syn match gitUntrackedFile contained /^#\t.*/hs=s+2
+
+hi def link gitLine Comment
+hi def link gitCommit Comment
+hi def link gitChanged Comment
+hi def link gitHead Comment
+hi def link gitUntracked Comment
+hi def link gitCommitFile Type
+hi def link gitChangedFile Constant
+hi def link gitUntrackedFile Constant
index e430cfbc8d0f4daccaae19fe44c9d699db6412e8..b14d8083bb14bd28a824c4417712842b1f70d829 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -22,6 +22,7 @@ static const char daemon_usage[] =
 "           [--timeout=n] [--init-timeout=n] [--strict-paths]\n"
 "           [--base-path=path] [--user-path | --user-path=path]\n"
 "           [--reuseaddr] [--detach] [--pid-file=file]\n"
+"           [--[enable|disable|allow-override|forbid-override]=service]\n"
 "           [--user=user [[--group=group]] [directory...]";
 
 /* List of acceptable pathname prefixes */
@@ -896,12 +897,12 @@ int main(int argc, char **argv)
                        enable_service(arg + 10, 0);
                        continue;
                }
-               if (!strncmp(arg, "--enable-override=", 18)) {
-                       make_service_overridable(arg + 18, 1);
+               if (!strncmp(arg, "--allow-override=", 17)) {
+                       make_service_overridable(arg + 17, 1);
                        continue;
                }
-               if (!strncmp(arg, "--disable-override=", 19)) {
-                       make_service_overridable(arg + 19, 0);
+               if (!strncmp(arg, "--forbid-override=", 18)) {
+                       make_service_overridable(arg + 18, 0);
                        continue;
                }
                if (!strcmp(arg, "--")) {
index 9edfa9262622c64edecfaf7b4f72a79873b8882a..fc69fb92a50c3dff67da76fedf1bf1df561c6065 100644 (file)
@@ -213,6 +213,31 @@ static int show_modified(struct rev_info *revs,
                return -1;
        }
 
+       if (revs->combine_merges && !cached &&
+           (hashcmp(sha1, old->sha1) || hashcmp(old->sha1, new->sha1))) {
+               struct combine_diff_path *p;
+               int pathlen = ce_namelen(new);
+
+               p = xmalloc(combine_diff_path_size(2, pathlen));
+               p->path = (char *) &p->parent[2];
+               p->next = NULL;
+               p->len = pathlen;
+               memcpy(p->path, new->name, pathlen);
+               p->path[pathlen] = 0;
+               p->mode = ntohl(mode);
+               hashclr(p->sha1);
+               memset(p->parent, 0, 2 * sizeof(struct combine_diff_parent));
+               p->parent[0].status = DIFF_STATUS_MODIFIED;
+               p->parent[0].mode = ntohl(new->ce_mode);
+               hashcpy(p->parent[0].sha1, new->sha1);
+               p->parent[1].status = DIFF_STATUS_MODIFIED;
+               p->parent[1].mode = ntohl(old->ce_mode);
+               hashcpy(p->parent[1].sha1, old->sha1);
+               show_combined_diff(p, 2, revs->dense_combined_merges, revs);
+               free(p);
+               return 0;
+       }
+
        oldmode = old->ce_mode;
        if (mode == oldmode && !hashcmp(sha1, old->sha1) &&
            !revs->diffopt.find_copies_harder)
diff --git a/diff.c b/diff.c
index 9dcbda3117a5b225aa5ee0f077b03cf8e859228b..6638865709888cc0ad2860ca1389a098b6f402f1 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -1588,6 +1588,12 @@ static void run_diff(struct diff_filepair *p, struct diff_options *o)
        if (hashcmp(one->sha1, two->sha1)) {
                int abbrev = o->full_index ? 40 : DEFAULT_ABBREV;
 
+               if (o->binary) {
+                       mmfile_t mf;
+                       if ((!fill_mmfile(&mf, one) && mmfile_is_binary(&mf)) ||
+                           (!fill_mmfile(&mf, two) && mmfile_is_binary(&mf)))
+                               abbrev = 40;
+               }
                len += snprintf(msg + len, sizeof(msg) - len,
                                "index %.*s..%.*s",
                                abbrev, sha1_to_hex(one->sha1),
@@ -1818,7 +1824,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
                options->full_index = 1;
        else if (!strcmp(arg, "--binary")) {
                options->output_format |= DIFF_FORMAT_PATCH;
-               options->full_index = options->binary = 1;
+               options->binary = 1;
        }
        else if (!strcmp(arg, "-a") || !strcmp(arg, "--text")) {
                options->text = 1;
index 377feded1ccafdece86499d1917d297145fd28ac..1b4d8272dce834d10b16ecbcea7ae2fa974fc856 100644 (file)
@@ -519,7 +519,7 @@ int main(int argc, char **argv)
        ret = fetch_pack(fd, nr_heads, heads);
        close(fd[0]);
        close(fd[1]);
-       finish_connect(pid);
+       ret |= finish_connect(pid);
 
        if (!ret && nr_heads) {
                /* If the heads to pull were given, we should have
@@ -534,5 +534,5 @@ int main(int argc, char **argv)
                        }
        }
 
-       return ret;
+       return !!ret;
 }
index 584a7323acd79e4092910ec4415f51603eccea61..b525fc5dfd9053a6fb63a4d38517e25e75341199 100755 (executable)
@@ -24,8 +24,10 @@ do
        shift
 done
 
-rm -f .tmp-pack-*
 PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
+PACKTMP="$GIT_DIR/.tmp-$$-pack"
+rm -f "$PACKTMP"-*
+trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
 
 # There will be more repacking strategies to come...
 case ",$all_into_one," in
@@ -42,11 +44,12 @@ case ",$all_into_one," in
            find . -type f \( -name '*.pack' -o -name '*.idx' \) -print`
        ;;
 esac
+
 pack_objects="$pack_objects $local $quiet $no_reuse_delta$extra"
 name=$( { git-rev-list --objects --all $rev_list ||
          echo "git-rev-list died with exit code $?"
        } |
-       git-pack-objects --non-empty $pack_objects .tmp-pack) ||
+       git-pack-objects --non-empty $pack_objects "$PACKTMP") ||
        exit 1
 if [ -z "$name" ]; then
        echo Nothing new to pack.
@@ -64,8 +67,8 @@ else
                                "$PACKDIR/old-pack-$name.$sfx"
                fi
        done &&
-       mv -f .tmp-pack-$name.pack "$PACKDIR/pack-$name.pack" &&
-       mv -f .tmp-pack-$name.idx  "$PACKDIR/pack-$name.idx" &&
+       mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
+       mv -f "$PACKTMP-$name.idx"  "$PACKDIR/pack-$name.idx" &&
        test -f "$PACKDIR/pack-$name.pack" &&
        test -f "$PACKDIR/pack-$name.idx" || {
                echo >&2 "Couldn't replace the existing pack with updated one."
diff --git a/git.c b/git.c
index 1d00111819f69cb4495be582bebee95be73ab214..335f405c20b3b07af5bb2e96dd00a75eb47ff809 100644 (file)
--- a/git.c
+++ b/git.c
@@ -36,6 +36,8 @@ static void prepend_to_path(const char *dir, int len)
        memcpy(path + len + 1, old_path, path_len - len);
 
        setenv("PATH", path, 1);
+
+       free(path);
 }
 
 static int handle_options(const char*** argv, int* argc)
diff --git a/gitweb/git-favicon.png b/gitweb/git-favicon.png
new file mode 100644 (file)
index 0000000..de637c0
Binary files /dev/null and b/gitweb/git-favicon.png differ
index 2b40aa11e7a56af788b42238d55258aff1d03b60..c3544ddc4ccbe8772fa59a626211444837f6312b 100755 (executable)
@@ -48,6 +48,8 @@
 our $stylesheet = "++GITWEB_CSS++";
 # URI of GIT logo
 our $logo = "++GITWEB_LOGO++";
+# URI of GIT favicon, assumed to be image/png type
+our $favicon = "++GITWEB_FAVICON++";
 
 # source of projects list
 our $projects_list = "++GITWEB_LIST++";
                'override' => 0,
                #         => [content-encoding, suffix, program]
                'default' => ['x-gzip', 'gz', 'gzip']},
+
+       'pickaxe' => {
+               'sub' => \&feature_pickaxe,
+               'override' => 0,
+               'default' => [1]},
 );
 
 sub gitweb_check_feature {
@@ -141,6 +148,24 @@ sub feature_snapshot {
        return ($ctype, $suffix, $command);
 }
 
+# To enable system wide have in $GITWEB_CONFIG
+# $feature{'pickaxe'}{'default'} = [1];
+# To have project specific config enable override in $GITWEB_CONFIG
+# $feature{'pickaxe'}{'override'} = 1;
+# and in project config gitweb.pickaxe = 0|1;
+
+sub feature_pickaxe {
+       my ($val) = git_get_project_config('pickaxe', '--bool');
+
+       if ($val eq 'true') {
+               return (1);
+       } elsif ($val eq 'false') {
+               return (0);
+       }
+
+       return ($_[0]);
+}
+
 # rename detection options for git-diff and git-diff-tree
 # - default is '-M', with the cost proportional to
 #   (number of removed files) * (number of new files).
@@ -1222,6 +1247,9 @@ sub git_header_html {
                       'href="%s" type="application/rss+xml"/>'."\n",
                       esc_param($project), href(action=>"rss"));
        }
+       if (defined $favicon) {
+               print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
+       }
 
        print "</head>\n" .
              "<body>\n" .
@@ -1400,19 +1428,32 @@ sub git_print_page_path {
 
        if (!defined $name) {
                print "<div class=\"page_path\">/</div>\n";
-       } elsif (defined $type && $type eq 'blob') {
+       } else {
+               my @dirname = split '/', $name;
+               my $basename = pop @dirname;
+               my $fullname = '';
+
                print "<div class=\"page_path\">";
-               if (defined $hb) {
+               foreach my $dir (@dirname) {
+                       $fullname .= $dir . '/';
+                       print $cgi->a({-href => href(action=>"tree", file_name=>$fullname,
+                                                    hash_base=>$hb),
+                                     -title => $fullname}, esc_html($dir));
+                       print "/";
+               }
+               if (defined $type && $type eq 'blob') {
                        print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,
-                                                    hash_base=>$hb)},
-                                     esc_html($name));
+                                                    hash_base=>$hb),
+                                     -title => $name}, esc_html($basename));
+               } elsif (defined $type && $type eq 'tree') {
+                       print $cgi->a({-href => href(action=>"tree", file_name=>$file_name,
+                                                    hash_base=>$hb),
+                                     -title => $name}, esc_html($basename));
+                       print "/";
                } else {
-                       print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name)},
-                                     esc_html($name));
+                       print esc_html($basename);
                }
                print "<br/></div>\n";
-       } else {
-               print "<div class=\"page_path\">" . esc_html($name) . "<br/></div>\n";
        }
 }
 
@@ -1587,7 +1628,7 @@ sub git_difftree_body {
                              $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
                                                     hash_base=>$hash, file_name=>$diff{'file'})},
                                      "blob");
-                       if ($action == "commitdiff") {
+                       if ($action eq 'commitdiff') {
                                # link to patch
                                $patchno++;
                                print " | " .
@@ -1608,7 +1649,7 @@ sub git_difftree_body {
                                                     hash_base=>$parent, file_name=>$diff{'file'})},
                                      "blob") .
                              " | ";
-                       if ($action == "commitdiff") {
+                       if ($action eq 'commitdiff') {
                                # link to patch
                                $patchno++;
                                print " | " .
@@ -1654,7 +1695,7 @@ sub git_difftree_body {
                                                     hash_base=>$hash, file_name=>$diff{'file'})},
                                      "blob");
                        if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
-                               if ($action == "commitdiff") {
+                               if ($action eq 'commitdiff') {
                                        # link to patch
                                        $patchno++;
                                        print " | " .
@@ -1696,7 +1737,7 @@ sub git_difftree_body {
                                                     hash=>$diff{'to_id'}, file_name=>$diff{'to_file'})},
                                      "blob");
                        if ($diff{'to_id'} ne $diff{'from_id'}) {
-                               if ($action == "commitdiff") {
+                               if ($action eq 'commitdiff') {
                                        # link to patch
                                        $patchno++;
                                        print " | " .
@@ -1892,12 +1933,15 @@ sub git_shortlog_body {
 
 sub git_history_body {
        # Warning: assumes constant type (blob or tree) during history
-       my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
+       my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
+
+       $from = 0 unless defined $from;
+       $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
 
        print "<table class=\"history\" cellspacing=\"0\">\n";
        my $alternate = 0;
-       while (my $line = <$fd>) {
-               if ($line !~ m/^([0-9a-fA-F]{40})/) {
+       for (my $i = $from; $i <= $to; $i++) {
+               if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
                        next;
                }
 
@@ -3073,29 +3117,70 @@ sub git_history {
        if (!defined $hash_base) {
                $hash_base = git_get_head_hash($project);
        }
+       if (!defined $page) {
+               $page = 0;
+       }
        my $ftype;
        my %co = parse_commit($hash_base);
        if (!%co) {
                die_error(undef, "Unknown commit object");
        }
+
        my $refs = git_get_references();
-       git_header_html();
-       git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base);
-       git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
+       my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
+
        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, $hash_base);
 
        open my $fd, "-|",
-               git_cmd(), "rev-list", "--full-history", $hash_base, "--", $file_name;
+               git_cmd(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
+                       or die_error(undef, "Open git-rev-list-failed");
+       my @revlist = map { chomp; $_ } <$fd>;
+       close $fd
+               or die_error(undef, "Reading git-rev-list failed");
+
+       my $paging_nav = '';
+       if ($page > 0) {
+               $paging_nav .=
+                       $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
+                                              file_name=>$file_name)},
+                               "first");
+               $paging_nav .= " &sdot; " .
+                       $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
+                                              file_name=>$file_name, page=>$page-1),
+                                -accesskey => "p", -title => "Alt-p"}, "prev");
+       } else {
+               $paging_nav .= "first";
+               $paging_nav .= " &sdot; prev";
+       }
+       if ($#revlist >= (100 * ($page+1)-1)) {
+               $paging_nav .= " &sdot; " .
+                       $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
+                                              file_name=>$file_name, page=>$page+1),
+                                -accesskey => "n", -title => "Alt-n"}, "next");
+       } else {
+               $paging_nav .= " &sdot; next";
+       }
+       my $next_link = '';
+       if ($#revlist >= (100 * ($page+1)-1)) {
+               $next_link =
+                       $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
+                                              file_name=>$file_name, page=>$page+1),
+                                -title => "Alt-n"}, "next");
+       }
+
+       git_header_html();
+       git_print_page_nav('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
+       git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
+       git_print_page_path($file_name, $ftype, $hash_base);
 
-       git_history_body($fd, $refs, $hash_base, $ftype);
+       git_history_body(\@revlist, ($page * 100), $#revlist,
+                        $refs, $hash_base, $ftype, $next_link);
 
-       close $fd;
        git_footer_html();
 }
 
@@ -3110,8 +3195,7 @@ sub git_search {
        if (!%co) {
                die_error(undef, "Unknown commit object");
        }
-       # pickaxe may take all resources of your box and run for several minutes
-       # with every query - so decide by yourself how public you make this feature :)
+
        my $commit_search = 1;
        my $author_search = 0;
        my $committer_search = 0;
@@ -3123,6 +3207,13 @@ sub git_search {
        } elsif ($searchtext =~ s/^pickaxe\\://i) {
                $commit_search = 0;
                $pickaxe_search = 1;
+
+               # pickaxe may take all resources of your box and run for several minutes
+               # with every query - so decide by yourself how public you make this feature
+               my ($have_pickaxe) = gitweb_check_feature('pickaxe');
+               if (!$have_pickaxe) {
+                       die_error('403 Permission denied', "Permission denied");
+               }
        }
        git_header_html();
        git_print_page_nav('','', $hash,$co{'tree'},$hash);
index b0034e4b217e12b267a51301c52b75e7255aec7b..98ea10005a851c3879c6e65929e3e34068dc9e8b 100644 (file)
@@ -55,9 +55,13 @@ static void add_object_refs(struct object *obj, struct object_refs *ref)
 
 struct object_refs *lookup_object_refs(struct object *obj)
 {
-       int j = hash_obj(obj, refs_hash_size);
        struct object_refs *ref;
+       int j;
 
+       /* nothing to lookup */
+       if (!refs_hash_size)
+               return NULL;
+       j = hash_obj(obj, refs_hash_size);
        while ((ref = refs_hash[j]) != NULL) {
                if (ref->base == obj)
                        break;
@@ -125,9 +129,6 @@ void mark_reachable(struct object *obj, unsigned int mask)
 
        if (!track_object_refs)
                die("cannot do reachability with object refs turned off");
-       /* nothing to lookup */
-       if (!refs_hash_size)
-               return;
        /* If we've been here already, don't bother */
        if (obj->flags & mask)
                return;
index 733faac4ccd1c9a8bb4ed1fc67986b369d9442b3..3d4ff4611f55d766cf2f82baa9771a80b50c85f9 100644 (file)
--- a/object.h
+++ b/object.h
@@ -27,17 +27,6 @@ struct object_array {
 /*
  * The object type is stored in 3 bits.
  */
-enum object_type {
-       OBJ_NONE = 0,
-       OBJ_COMMIT = 1,
-       OBJ_TREE = 2,
-       OBJ_BLOB = 3,
-       OBJ_TAG = 4,
-       /* 5/6 for future expansion */
-       OBJ_DELTA = 7,
-       OBJ_BAD,
-};
-
 struct object {
        unsigned parsed : 1;
        unsigned used : 1;
index 87f1543fec05e88fd1bc554740993397f0aa3807..353da002b4c7632ed66c1b3ceacaa985ec137627 100644 (file)
@@ -66,6 +66,6 @@ int main(int argc, char **argv)
        ret = peek_remote(fd, flags);
        close(fd[0]);
        close(fd[1]);
-       finish_connect(pid);
-       return ret;
+       ret |= finish_connect(pid);
+       return !!ret;
 }
diff --git a/quote.c b/quote.c
index a38786c177d090b36bcd13a13b08dbe42a2c2340..e3a4d4aef3478148ff89aebeba23e1cbf4202ba1 100644 (file)
--- a/quote.c
+++ b/quote.c
@@ -106,6 +106,35 @@ char *sq_quote_argv(const char** argv, int count)
        return buf;
 }
 
+/*
+ * Append a string to a string buffer, with or without shell quoting.
+ * Return true if the buffer overflowed.
+ */
+int add_to_string(char **ptrp, int *sizep, const char *str, int quote)
+{
+       char *p = *ptrp;
+       int size = *sizep;
+       int oc;
+       int err = 0;
+
+       if (quote)
+               oc = sq_quote_buf(p, size, str);
+       else {
+               oc = strlen(str);
+               memcpy(p, str, (size <= oc) ? size - 1 : oc);
+       }
+
+       if (size <= oc) {
+               err = 1;
+               oc = size - 1;
+       }
+
+       *ptrp += oc;
+       **ptrp = '\0';
+       *sizep -= oc;
+       return err;
+}
+
 char *sq_dequote(char *arg)
 {
        char *dst = arg;
diff --git a/quote.h b/quote.h
index a6c4611c250da6175fe217364894715d690c04a8..1a29e791dd59324138a8d1e73704114da199fc12 100644 (file)
--- a/quote.h
+++ b/quote.h
@@ -33,6 +33,12 @@ extern void sq_quote_print(FILE *stream, const char *src);
 extern size_t sq_quote_buf(char *dst, size_t n, const char *src);
 extern char *sq_quote_argv(const char** argv, int count);
 
+/*
+ * Append a string to a string buffer, with or without shell quoting.
+ * Return true if the buffer overflowed.
+ */
+extern int add_to_string(char **ptrp, int *sizep, const char *str, int quote);
+
 /* This unwraps what sq_quote() produces in place, but returns
  * NULL if the input does not look like what sq_quote would have
  * produced.
index b588f7487035027755954575f922afee99651662..db01682750a4dfa820ea3f0e4a99e306aa6b075a 100644 (file)
@@ -592,6 +592,85 @@ static void prepare_show_merge(struct rev_info *revs)
        revs->prune_data = prune;
 }
 
+int handle_revision_arg(const char *arg, struct rev_info *revs,
+                       int flags,
+                       int cant_be_filename)
+{
+       char *dotdot;
+       struct object *object;
+       unsigned char sha1[20];
+       int local_flags;
+
+       dotdot = strstr(arg, "..");
+       if (dotdot) {
+               unsigned char from_sha1[20];
+               const char *next = dotdot + 2;
+               const char *this = arg;
+               int symmetric = *next == '.';
+               unsigned int flags_exclude = flags ^ UNINTERESTING;
+
+               *dotdot = 0;
+               next += symmetric;
+
+               if (!*next)
+                       next = "HEAD";
+               if (dotdot == arg)
+                       this = "HEAD";
+               if (!get_sha1(this, from_sha1) &&
+                   !get_sha1(next, sha1)) {
+                       struct commit *a, *b;
+                       struct commit_list *exclude;
+
+                       a = lookup_commit_reference(from_sha1);
+                       b = lookup_commit_reference(sha1);
+                       if (!a || !b) {
+                               die(symmetric ?
+                                   "Invalid symmetric difference expression %s...%s" :
+                                   "Invalid revision range %s..%s",
+                                   arg, next);
+                       }
+
+                       if (!cant_be_filename) {
+                               *dotdot = '.';
+                               verify_non_filename(revs->prefix, arg);
+                       }
+
+                       if (symmetric) {
+                               exclude = get_merge_bases(a, b, 1);
+                               add_pending_commit_list(revs, exclude,
+                                                       flags_exclude);
+                               free_commit_list(exclude);
+                               a->object.flags |= flags;
+                       } else
+                               a->object.flags |= flags_exclude;
+                       b->object.flags |= flags;
+                       add_pending_object(revs, &a->object, this);
+                       add_pending_object(revs, &b->object, next);
+                       return 0;
+               }
+               *dotdot = '.';
+       }
+       dotdot = strstr(arg, "^@");
+       if (dotdot && !dotdot[2]) {
+               *dotdot = 0;
+               if (add_parents_only(revs, arg, flags))
+                       return 0;
+               *dotdot = '^';
+       }
+       local_flags = 0;
+       if (*arg == '^') {
+               local_flags = UNINTERESTING;
+               arg++;
+       }
+       if (get_sha1(arg, sha1))
+               return -1;
+       if (!cant_be_filename)
+               verify_non_filename(revs->prefix, arg);
+       object = get_reference(revs, arg, sha1, flags ^ local_flags);
+       add_pending_object(revs, object, arg);
+       return 0;
+}
+
 /*
  * Parse revision information, filling in the "rev_info" structure,
  * and removing the used arguments from the argument list.
@@ -620,12 +699,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
 
        flags = show_merge = 0;
        for (i = 1; i < argc; i++) {
-               struct object *object;
                const char *arg = argv[i];
-               unsigned char sha1[20];
-               char *dotdot;
-               int local_flags;
-
                if (*arg == '-') {
                        int opts;
                        if (!strncmp(arg, "--max-count=", 12)) {
@@ -830,71 +904,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
                        left++;
                        continue;
                }
-               dotdot = strstr(arg, "..");
-               if (dotdot) {
-                       unsigned char from_sha1[20];
-                       const char *next = dotdot + 2;
-                       const char *this = arg;
-                       int symmetric = *next == '.';
-                       unsigned int flags_exclude = flags ^ UNINTERESTING;
-
-                       *dotdot = 0;
-                       next += symmetric;
-
-                       if (!*next)
-                               next = "HEAD";
-                       if (dotdot == arg)
-                               this = "HEAD";
-                       if (!get_sha1(this, from_sha1) &&
-                           !get_sha1(next, sha1)) {
-                               struct commit *a, *b;
-                               struct commit_list *exclude;
-
-                               a = lookup_commit_reference(from_sha1);
-                               b = lookup_commit_reference(sha1);
-                               if (!a || !b) {
-                                       die(symmetric ?
-                                           "Invalid symmetric difference expression %s...%s" :
-                                           "Invalid revision range %s..%s",
-                                           arg, next);
-                               }
-
-                               if (!seen_dashdash) {
-                                       *dotdot = '.';
-                                       verify_non_filename(revs->prefix, arg);
-                               }
-
-                               if (symmetric) {
-                                       exclude = get_merge_bases(a, b, 1);
-                                       add_pending_commit_list(revs, exclude,
-                                                               flags_exclude);
-                                       free_commit_list(exclude);
-                                       a->object.flags |= flags;
-                               } else
-                                       a->object.flags |= flags_exclude;
-                               b->object.flags |= flags;
-                               add_pending_object(revs, &a->object, this);
-                               add_pending_object(revs, &b->object, next);
-                               continue;
-                       }
-                       *dotdot = '.';
-               }
-               dotdot = strstr(arg, "^@");
-               if (dotdot && !dotdot[2]) {
-                       *dotdot = 0;
-                       if (add_parents_only(revs, arg, flags))
-                               continue;
-                       *dotdot = '^';
-               }
-               local_flags = 0;
-               if (*arg == '^') {
-                       local_flags = UNINTERESTING;
-                       arg++;
-               }
-               if (get_sha1(arg, sha1)) {
-                       int j;
 
-                       if (seen_dashdash || local_flags)
+               if (handle_revision_arg(arg, revs, flags, seen_dashdash)) {
+                       int j;
+                       if (seen_dashdash || *arg == '^')
                                die("bad revision '%s'", arg);
 
                        /* If we didn't have a "--":
@@ -906,14 +919,12 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
                        for (j = i; j < argc; j++)
                                verify_filename(revs->prefix, argv[j]);
 
-                       revs->prune_data = get_pathspec(revs->prefix, argv + i);
+                       revs->prune_data = get_pathspec(revs->prefix,
+                                                       argv + i);
                        break;
                }
-               if (!seen_dashdash)
-                       verify_non_filename(revs->prefix, arg);
-               object = get_reference(revs, arg, sha1, flags ^ local_flags);
-               add_pending_object(revs, object, arg);
        }
+
        if (show_merge)
                prepare_show_merge(revs);
        if (def && !revs->pending.nr) {
index d289781051c523c7e1596c6e215625616d51f088..c1f71afe6fa71075b64df03c1e9616f50325d29e 100644 (file)
@@ -90,6 +90,8 @@ extern int rev_compare_tree(struct rev_info *, struct tree *t1, struct tree *t2)
 
 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 int handle_revision_arg(const char *arg, struct rev_info *revs,int flags,int cant_be_filename);
+
 extern void prepare_revision_walk(struct rev_info *revs);
 extern struct commit *get_revision(struct rev_info *revs);
 
diff --git a/rsh.c b/rsh.c
index 07166addd9629675c4b0c7c065564a283014b69d..f34409e1bc5fcf3b6295021043339793b25a8913 100644 (file)
--- a/rsh.c
+++ b/rsh.c
@@ -8,36 +8,7 @@
 
 #define COMMAND_SIZE 4096
 
-/*
- * Append a string to a string buffer, with or without shell quoting.
- * Return true if the buffer overflowed.
- */
-static int add_to_string(char **ptrp, int *sizep, const char *str, int quote)
-{
-       char *p = *ptrp;
-       int size = *sizep;
-       int oc;
-       int err = 0;
-
-       if ( quote ) {
-               oc = sq_quote_buf(p, size, str);
-       } else {
-               oc = strlen(str);
-               memcpy(p, str, (oc >= size) ? size-1 : oc);
-       }
-
-       if ( oc >= size ) {
-               err = 1;
-               oc = size-1;
-       }
-
-       *ptrp  += oc;
-       **ptrp  = '\0';
-       *sizep -= oc;
-       return err;
-}
-
-int setup_connection(int *fd_in, int *fd_out, const char *remote_prog, 
+int setup_connection(int *fd_in, int *fd_out, const char *remote_prog,
                     char *url, int rmt_argc, char **rmt_argv)
 {
        char *host;
index ac4501d34154301030cf98ff122eb233095417b7..5bb123a37696384c5413dac128529d1c1f679940 100644 (file)
@@ -38,9 +38,8 @@ static void exec_pack_objects(void)
 
 static void exec_rev_list(struct ref *refs)
 {
-       struct ref *ref;
-       static const char *args[1000];
-       int i = 0, j;
+       static const char *args[4];
+       int i = 0;
 
        args[i++] = "rev-list"; /* 0 */
        if (use_thin_pack)      /* 1 */
@@ -48,43 +47,16 @@ static void exec_rev_list(struct ref *refs)
        else
                args[i++] = "--objects";
 
-       /* First send the ones we care about most */
-       for (ref = refs; ref; ref = ref->next) {
-               if (900 < i)
-                       die("git-rev-list environment overflow");
-               if (!is_zero_sha1(ref->new_sha1)) {
-                       char *buf = xmalloc(100);
-                       args[i++] = buf;
-                       snprintf(buf, 50, "%s", sha1_to_hex(ref->new_sha1));
-                       buf += 50;
-                       if (!is_zero_sha1(ref->old_sha1) &&
-                           has_sha1_file(ref->old_sha1)) {
-                               args[i++] = buf;
-                               snprintf(buf, 50, "^%s",
-                                        sha1_to_hex(ref->old_sha1));
-                       }
-               }
-       }
+       args[i++] = "--stdin";
 
-       /* Then a handful of the remainder
-        * NEEDSWORK: we would be better off if used the newer ones first.
-        */
-       for (ref = refs, j = i + 16;
-            i < 900 && i < j && ref;
-            ref = ref->next) {
-               if (is_zero_sha1(ref->new_sha1) &&
-                   !is_zero_sha1(ref->old_sha1) &&
-                   has_sha1_file(ref->old_sha1)) {
-                       char *buf = xmalloc(42);
-                       args[i++] = buf;
-                       snprintf(buf, 42, "^%s", sha1_to_hex(ref->old_sha1));
-               }
-       }
        args[i] = NULL;
        execv_git_cmd(args);
        die("git-rev-list exec failed (%s)", strerror(errno));
 }
 
+/*
+ * Run "rev-list --stdin | pack-objects" pipe.
+ */
 static void rev_list(int fd, struct ref *refs)
 {
        int pipe_fd[2];
@@ -94,6 +66,9 @@ static void rev_list(int fd, struct ref *refs)
                die("rev-list setup: pipe failed");
        pack_objects_pid = fork();
        if (!pack_objects_pid) {
+               /* The child becomes pack-objects; reads from pipe
+                * and writes to the original fd
+                */
                dup2(pipe_fd[0], 0);
                dup2(fd, 1);
                close(pipe_fd[0]);
@@ -104,6 +79,8 @@ static void rev_list(int fd, struct ref *refs)
        }
        if (pack_objects_pid < 0)
                die("pack-objects fork failed");
+
+       /* We become rev-list --stdin; output goes to pipe. */
        dup2(pipe_fd[1], 1);
        close(pipe_fd[0]);
        close(pipe_fd[1]);
@@ -111,13 +88,71 @@ static void rev_list(int fd, struct ref *refs)
        exec_rev_list(refs);
 }
 
+/*
+ * Create "rev-list --stdin | pack-objects" pipe and feed
+ * the refs into the pipeline.
+ */
+static void rev_list_generate(int fd, struct ref *refs)
+{
+       int pipe_fd[2];
+       pid_t rev_list_generate_pid;
+
+       if (pipe(pipe_fd) < 0)
+               die("rev-list-generate setup: pipe failed");
+       rev_list_generate_pid = fork();
+       if (!rev_list_generate_pid) {
+               /* The child becomes the "rev-list | pack-objects"
+                * pipeline.  It takes input from us, and its output
+                * goes to fd.
+                */
+               dup2(pipe_fd[0], 0);
+               dup2(fd, 1);
+               close(pipe_fd[0]);
+               close(pipe_fd[1]);
+               close(fd);
+               rev_list(fd, refs);
+               die("rev-list setup failed");
+       }
+       if (rev_list_generate_pid < 0)
+               die("rev-list-generate fork failed");
+
+       /* We feed the rev parameters to them.  We do not write into
+        * fd nor read from the pipe.
+        */
+       close(pipe_fd[0]);
+       close(fd);
+       while (refs) {
+               char buf[42];
+
+               if (!is_null_sha1(refs->old_sha1) &&
+                   has_sha1_file(refs->old_sha1)) {
+                       memcpy(buf + 1, sha1_to_hex(refs->old_sha1), 40);
+                       buf[0] = '^';
+                       buf[41] = '\n';
+                       write(pipe_fd[1], buf, 42);
+               }
+               if (!is_null_sha1(refs->new_sha1)) {
+                       memcpy(buf, sha1_to_hex(refs->new_sha1), 40);
+                       buf[40] = '\n';
+                       write(pipe_fd[1], buf, 41);
+               }
+               refs = refs->next;
+       }
+       close(pipe_fd[1]);
+       // waitpid(rev_list_generate_pid);
+       exit(0);
+}
+
+/*
+ * Make a pack stream and spit it out into file descriptor fd
+ */
 static void pack_objects(int fd, struct ref *refs)
 {
        pid_t rev_list_pid;
 
        rev_list_pid = fork();
        if (!rev_list_pid) {
-               rev_list(fd, refs);
+               rev_list_generate(fd, refs);
                die("rev-list setup failed");
        }
        if (rev_list_pid < 0)
@@ -408,6 +443,6 @@ int main(int argc, char **argv)
        ret = send_pack(fd[0], fd[1], nr_heads, heads);
        close(fd[0]);
        close(fd[1]);
-       finish_connect(pid);
-       return ret;
+       ret |= finish_connect(pid);
+       return !!ret;
 }
index 4ef98053f8b5ba9988fd28afc60a1ae2fced93c9..b64b92de4e7a6c59edfb3e60ff1440a98cacdeea 100644 (file)
@@ -26,15 +26,43 @@ const unsigned char null_sha1[20];
 
 static unsigned int sha1_file_open_flag = O_NOATIME;
 
-static unsigned hexval(char c)
-{
-       if (c >= '0' && c <= '9')
-               return c - '0';
-       if (c >= 'a' && c <= 'f')
-               return c - 'a' + 10;
-       if (c >= 'A' && c <= 'F')
-               return c - 'A' + 10;
-       return ~0;
+static inline unsigned int hexval(unsigned int c)
+{
+       static signed char val[256] = {
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* 00-07 */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* 08-0f */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* 10-17 */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* 18-1f */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* 20-27 */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* 28-2f */
+                 0,  1,  2,  3,  4,  5,  6,  7,                /* 30-37 */
+                 8,  9, -1, -1, -1, -1, -1, -1,                /* 38-3f */
+                -1, 10, 11, 12, 13, 14, 15, -1,                /* 40-47 */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* 48-4f */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* 50-57 */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* 58-5f */
+                -1, 10, 11, 12, 13, 14, 15, -1,                /* 60-67 */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* 68-67 */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* 70-77 */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* 78-7f */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* 80-87 */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* 88-8f */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* 90-97 */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* 98-9f */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* a0-a7 */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* a8-af */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* b0-b7 */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* b8-bf */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* c0-c7 */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* c8-cf */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* d0-d7 */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* d8-df */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* e0-e7 */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* e8-ef */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* f0-f7 */
+                -1, -1, -1, -1, -1, -1, -1, -1,                /* f8-ff */
+       };
+       return val[c];
 }
 
 int get_sha1_hex(const char *hex, unsigned char *sha1)
@@ -711,7 +739,7 @@ int legacy_loose_object(unsigned char *map)
                return 0;
 }
 
-static unsigned long unpack_object_header_gently(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep)
+unsigned long unpack_object_header_gently(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep)
 {
        unsigned shift;
        unsigned char c;
index ff052699a28d2d96de4bdaa4702f175527f28536..e2b1124c78540ed9613877d10eed3641268c2c8f 100755 (executable)
@@ -94,11 +94,11 @@ test_expect_failure 'apply binary diff (copy) -- should fail.' \
        'do_reset
         git-apply --index C.diff'
 
-test_expect_failure 'apply binary diff without replacement -- should fail.' \
+test_expect_success 'apply binary diff without replacement.' \
        'do_reset
         git-apply BF.diff'
 
-test_expect_failure 'apply binary diff without replacement (copy) -- should fail.' \
+test_expect_success 'apply binary diff without replacement (copy).' \
        'do_reset
         git-apply CF.diff'
 
diff --git a/trace.c b/trace.c
index ce01c3474948ec593c87843309ec767ace57f07e..f9efc918b8a0aa907a36edd107a2fa2a14582e78 100644 (file)
--- a/trace.c
+++ b/trace.c
@@ -55,7 +55,7 @@ static int get_trace_fd(int *need_close)
 {
        char *trace = getenv("GIT_TRACE");
 
-       if (!trace || !strcmp(trace, "0") || !strcasecmp(trace,false"))
+       if (!trace || !strcmp(trace, "0") || !strcasecmp(trace, "false"))
                return 0;
        if (!strcmp(trace, "1") || !strcasecmp(trace, "true"))
                return STDERR_FILENO;