summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Documentation/git-update-index.txt11
-rw-r--r--Makefile2
-rw-r--r--cache.h1
-rw-r--r--fetch.c5
-rw-r--r--fetch.h3
-rw-r--r--fsck-objects.c5
-rwxr-xr-xgit-commit.sh4
-rw-r--r--http-fetch.c26
-rw-r--r--local-fetch.c2
-rw-r--r--path.c4
-rw-r--r--sha1_file.c7
-rw-r--r--ssh-fetch.c2
-rw-r--r--t/Makefile3
-rwxr-xr-xt/t0000-basic.sh2
-rw-r--r--update-index.c54
15 files changed, 96 insertions, 35 deletions
diff --git a/Documentation/git-update-index.txt b/Documentation/git-update-index.txt
index 8d55659..0d9847c 100644
--- a/Documentation/git-update-index.txt
+++ b/Documentation/git-update-index.txt
@@ -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.
diff --git a/Makefile b/Makefile
index afd4b14..9920467 100644
--- 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
--- 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
--- 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
--- 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 *);
diff --git a/fsck-objects.c b/fsck-objects.c
index 6cb0f29..b82685f 100644
--- a/fsck-objects.c
+++ b/fsck-objects.c
@@ -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)
diff --git a/git-commit.sh b/git-commit.sh
index 9412840..18ad361 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -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
diff --git a/http-fetch.c b/http-fetch.c
index 57141a8..0caec10 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -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++;
}
diff --git a/local-fetch.c b/local-fetch.c
index 0dbed89..a57386c 100644
--- a/local-fetch.c
+++ b/local-fetch.c
@@ -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
--- 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;
diff --git a/sha1_file.c b/sha1_file.c
index 6638202..fe374c6 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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)
diff --git a/ssh-fetch.c b/ssh-fetch.c
index 683a1e4..05d3e49 100644
--- a/ssh-fetch.c
+++ b/ssh-fetch.c
@@ -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++;
}
diff --git a/t/Makefile b/t/Makefile
index 6882e23..a6b8088 100644
--- a/t/Makefile
+++ b/t/Makefile
@@ -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:
diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index 3649f0f..bd940bd 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -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 \
diff --git a/update-index.c b/update-index.c
index 1ea36ea..01eaa1a 100644
--- a/update-index.c
+++ b/update-index.c
@@ -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))