Merge master.kernel.org:/home/hpa/git/daemon
authorJunio C Hamano <junkio@cox.net>
Wed, 28 Sep 2005 00:05:41 +0000 (17:05 -0700)
committerJunio C Hamano <junkio@cox.net>
Wed, 28 Sep 2005 00:05:41 +0000 (17:05 -0700)
15 files changed:
Documentation/git-update-index.txt
Makefile
cache.h
fetch.c
fetch.h
fsck-objects.c
git-commit.sh
http-fetch.c
local-fetch.c
path.c
sha1_file.c
ssh-fetch.c
t/Makefile
t/t0000-basic.sh
update-index.c

index 8d55659..0d9847c 100644 (file)
@@ -1,6 +1,5 @@
 git-update-index(1)
 ===================
-v0.1, May 2005
 
 NAME
 ----
@@ -15,6 +14,7 @@ SYNOPSIS
             [--force-remove]
             [--cacheinfo <mode> <object> <file>]\*
             [--info-only]
+            [-z] [--stdin]
             [--] [<file>]\*
 
 DESCRIPTION
@@ -65,6 +65,15 @@ OPTIONS
        that conflicts with the entry being added are
        automatically removed with warning messages.
 
+--stdin::
+       Instead of taking list of paths from the command line,
+       read list of paths from the standard input.  Paths are
+       separated by LF (i.e. one path per line) by default.
+
+-z::
+       Only meaningful with `--stdin`; paths are separated with
+       NUL character instead of LF.
+
 --::
        Do not interpret any more arguments as options.
 
index afd4b14..9920467 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -253,7 +253,7 @@ SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) \
          $(patsubst %.py,%,$(SCRIPT_PYTHON)) \
          gitk
 
-export TAR INSTALL DESTDIR
+export TAR INSTALL DESTDIR SHELL_PATH
 ### Build rules
 
 all: $(PROGRAMS) $(SCRIPTS)
diff --git a/cache.h b/cache.h
index 6f3d39d..52a45f9 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -136,6 +136,7 @@ extern unsigned int active_nr, active_alloc, active_cache_changed;
 #define INDEX_ENVIRONMENT "GIT_INDEX_FILE"
 #define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE"
 
+extern char *get_git_dir(void);
 extern char *get_object_directory(void);
 extern char *get_refs_directory(void);
 extern char *get_index_file(void);
diff --git a/fetch.c b/fetch.c
index 1a33ae9..3e073d3 100644 (file)
--- a/fetch.c
+++ b/fetch.c
@@ -15,6 +15,7 @@ int get_tree = 0;
 int get_history = 0;
 int get_all = 0;
 int get_verbosely = 0;
+int get_recover = 0;
 static unsigned char current_commit_sha1[20];
 
 void pull_say(const char *fmt, const char *hex) 
@@ -214,7 +215,9 @@ int pull(char *target)
                        return -1;
        }
 
-       for_each_ref(mark_complete);
+       if (!get_recover) {
+               for_each_ref(mark_complete);
+       }
 
        if (interpret_target(target, sha1))
                return error("Could not interpret %s as something to pull",
diff --git a/fetch.h b/fetch.h
index e7710e8..9837a3d 100644 (file)
--- a/fetch.h
+++ b/fetch.h
@@ -40,6 +40,9 @@ extern int get_all;
 /* Set to be verbose */
 extern int get_verbosely;
 
+/* Set to check on all reachable objects. */
+extern int get_recover;
+
 /* Report what we got under get_verbosely */
 extern void pull_say(const char *, const char *);
 
index 6cb0f29..b82685f 100644 (file)
@@ -406,10 +406,7 @@ static int fsck_head_link(void)
        char hex[40];
        unsigned char sha1[20];
        static char path[PATH_MAX], link[PATH_MAX];
-       const char *git_dir;
-
-       git_dir = getenv(GIT_DIR_ENVIRONMENT);
-       if (!git_dir) git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
+       const char *git_dir = get_git_dir();
 
        snprintf(path, sizeof(path), "%s/HEAD", git_dir);
        if (readlink(path, link, sizeof(link)) < 0)
index 9412840..18ad361 100755 (executable)
@@ -94,13 +94,13 @@ esac
 case "$all,$#" in
 t,*)
        git-diff-files --name-only -z |
-       xargs -0 git-update-index -q --remove --
+       git-update-index --remove -z --stdin
        ;;
 ,0)
        ;;
 *)
        git-diff-files --name-only -z "$@" |
-       xargs -0 git-update-index -q --remove --
+       git-update-index --remove -z --stdin
        ;;
 esac || exit 1
 git-update-index -q --refresh || exit 1
index 57141a8..0caec10 100644 (file)
@@ -15,6 +15,7 @@
 
 static CURL *curl;
 static struct curl_slist *no_pragma_header;
+static char curl_errorstr[CURL_ERROR_SIZE];
 
 static char *initial_base;
 
@@ -112,10 +113,12 @@ static int fetch_index(struct alt_base *repo, unsigned char *sha1)
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
        curl_easy_setopt(curl, CURLOPT_URL, url);
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, no_pragma_header);
+       curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errorstr);
        
        if (curl_easy_perform(curl)) {
                fclose(indexfile);
-               return error("Unable to get pack index %s", url);
+               return error("Unable to get pack index %s\n%s", url,
+                            curl_errorstr);
        }
 
        fclose(indexfile);
@@ -264,10 +267,10 @@ static int fetch_indices(struct alt_base *repo)
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
        curl_easy_setopt(curl, CURLOPT_URL, url);
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, NULL);
+       curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errorstr);
        
-       if (curl_easy_perform(curl)) {
-               return -1;
-       }
+       if (curl_easy_perform(curl))
+               return error("%s", curl_errorstr);
 
        while (i < buffer.posn) {
                switch (data[i]) {
@@ -327,10 +330,12 @@ static int fetch_pack(struct alt_base *repo, unsigned char *sha1)
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
        curl_easy_setopt(curl, CURLOPT_URL, url);
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, no_pragma_header);
-       
+       curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errorstr);
+
        if (curl_easy_perform(curl)) {
                fclose(packfile);
-               return error("Unable to get pack file %s", url);
+               return error("Unable to get pack file %s\n%s", url,
+                            curl_errorstr);
        }
 
        fclose(packfile);
@@ -373,6 +378,7 @@ int fetch_object(struct alt_base *repo, unsigned char *sha1)
        curl_easy_setopt(curl, CURLOPT_FILE, NULL);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite_sha1_file);
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, no_pragma_header);
+       curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errorstr);
 
        url = xmalloc(strlen(repo->base) + 50);
        strcpy(url, repo->base);
@@ -388,7 +394,7 @@ int fetch_object(struct alt_base *repo, unsigned char *sha1)
 
        if (curl_easy_perform(curl)) {
                unlink(filename);
-               return -1;
+               return error("%s", curl_errorstr);
        }
 
        fchmod(local, 0444);
@@ -453,6 +459,7 @@ int fetch_ref(char *ref, unsigned char *sha1)
         curl_easy_setopt(curl, CURLOPT_FILE, &buffer);
         curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, NULL);
+       curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errorstr);
 
         url = xmalloc(strlen(base) + 6 + strlen(ref));
         strcpy(url, base);
@@ -464,7 +471,8 @@ int fetch_ref(char *ref, unsigned char *sha1)
         curl_easy_setopt(curl, CURLOPT_URL, url);
 
         if (curl_easy_perform(curl))
-                return error("Couldn't get %s for %s\n", url, ref);
+                return error("Couldn't get %s for %s\n%s",
+                            url, ref, curl_errorstr);
 
         hex[40] = '\0';
         get_sha1_hex(hex, sha1);
@@ -491,6 +499,8 @@ int main(int argc, char **argv)
                } else if (argv[arg][1] == 'w') {
                        write_ref = argv[arg + 1];
                        arg++;
+               } else if (!strcmp(argv[arg], "--recover")) {
+                       get_recover = 1;
                }
                arg++;
        }
index 0dbed89..a57386c 100644 (file)
@@ -231,6 +231,8 @@ int main(int argc, char **argv)
                        get_verbosely = 1;
                else if (argv[arg][1] == 'w')
                        write_ref = argv[++arg];
+               else if (!strcmp(argv[arg], "--recover"))
+                       get_recover = 1;
                else
                        usage(local_pull_usage);
                arg++;
diff --git a/path.c b/path.c
index f788028..495d17c 100644 (file)
--- a/path.c
+++ b/path.c
@@ -41,12 +41,10 @@ char *mkpath(const char *fmt, ...)
 
 char *git_path(const char *fmt, ...)
 {
-       const char *git_dir;
+       const char *git_dir = get_git_dir();
        va_list args;
        unsigned len;
 
-       git_dir = getenv(GIT_DIR_ENVIRONMENT);
-       if (!git_dir) git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
        len = strlen(git_dir);
        if (len > PATH_MAX-100)
                return bad_path;
index 6638202..fe374c6 100644 (file)
@@ -70,6 +70,13 @@ static void setup_git_env(void)
                git_graft_file = strdup(git_path("info/grafts"));
 }
 
+char *get_git_dir(void)
+{
+       if (!git_dir)
+               setup_git_env();
+       return git_dir;
+}
+
 char *get_object_directory(void)
 {
        if (!git_object_dir)
index 683a1e4..05d3e49 100644 (file)
@@ -119,6 +119,8 @@ int main(int argc, char **argv)
                } else if (argv[arg][1] == 'w') {
                        write_ref = argv[arg + 1];
                        arg++;
+               } else if (!strcmp(argv[arg], "--recover")) {
+                       get_recover = 1;
                }
                arg++;
        }
index 6882e23..a6b8088 100644 (file)
@@ -4,11 +4,12 @@
 #
 
 #GIT_TEST_OPTS=--verbose --debug
+SHELL_PATH ?= $(SHELL)
 
 T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
 
 all:
-       @$(foreach t,$T,echo "*** $t ***"; sh $t $(GIT_TEST_OPTS) || exit; )
+       @$(foreach t,$T,echo "*** $t ***"; $(SHELL_PATH) $t $(GIT_TEST_OPTS) || exit; )
        @rm -fr trash
 
 clean:
index 3649f0f..bd940bd 100755 (executable)
@@ -85,7 +85,7 @@ do
 done
 test_expect_success \
     'adding various types of objects with git-update-index --add.' \
-    'find path* ! -type d -print0 | xargs -0 git-update-index --add'
+    'find path* ! -type d -print | xargs git-update-index --add'
 
 # Show them and see that matches what we expect.
 test_expect_success \
index 1ea36ea..01eaa1a 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "strbuf.h"
 
 /*
  * Default to not allowing changes to the list of files. The
@@ -277,11 +278,30 @@ static int add_cacheinfo(const char *arg1, const char *arg2, const char *arg3)
 
 static struct cache_file cache_file;
 
+
+static void update_one(const char *path, const char *prefix, int prefix_length)
+{
+       const char *p = prefix_path(prefix, prefix_length, path);
+       if (!verify_path(p)) {
+               fprintf(stderr, "Ignoring path %s\n", path);
+               return;
+       }
+       if (force_remove) {
+               if (remove_file_from_cache(p))
+                       die("git-update-index: unable to remove %s", path);
+               return;
+       }
+       if (add_file_to_cache(p))
+               die("Unable to process file %s", path);
+}
+
 int main(int argc, const char **argv)
 {
-       int i, newfd, entries, has_errors = 0;
+       int i, newfd, entries, has_errors = 0, line_termination = '\n';
        int allow_options = 1;
+       int read_from_stdin = 0;
        const char *prefix = setup_git_directory();
+       int prefix_length = prefix ? strlen(prefix) : 0;
 
        newfd = hold_index_file_for_update(&cache_file, get_index_file());
        if (newfd < 0)
@@ -335,25 +355,33 @@ int main(int argc, const char **argv)
                                force_remove = 1;
                                continue;
                        }
-
+                       if (!strcmp(path, "-z")) {
+                               line_termination = 0;
+                               continue;
+                       }
+                       if (!strcmp(path, "--stdin")) {
+                               if (i != argc - 1)
+                                       die("--stdin must be at the end");
+                               read_from_stdin = 1;
+                               break;
+                       }
                        if (!strcmp(path, "--ignore-missing")) {
                                not_new = 1;
                                continue;
                        }
                        die("unknown option %s", path);
                }
-               path = prefix_path(prefix, prefix ? strlen(prefix) : 0, path);
-               if (!verify_path(path)) {
-                       fprintf(stderr, "Ignoring path %s\n", argv[i]);
-                       continue;
-               }
-               if (force_remove) {
-                       if (remove_file_from_cache(path))
-                               die("git-update-index: unable to remove %s", path);
-                       continue;
+               update_one(path, prefix, prefix_length);
+       }
+       if (read_from_stdin) {
+               struct strbuf buf;
+               strbuf_init(&buf);
+               while (1) {
+                       read_line(&buf, stdin, line_termination);
+                       if (buf.eof)
+                               break;
+                       update_one(buf.buf, prefix, prefix_length);
                }
-               if (add_file_to_cache(path))
-                       die("Unable to process file %s", path);
        }
        if (write_cache(newfd, active_cache, active_nr) ||
            commit_index_file(&cache_file))