git-update-index(1)
===================
-v0.1, May 2005
NAME
----
[--force-remove]
[--cacheinfo <mode> <object> <file>]\*
[--info-only]
+ [-z] [--stdin]
[--] [<file>]\*
DESCRIPTION
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.
$(patsubst %.py,%,$(SCRIPT_PYTHON)) \
gitk
-export TAR INSTALL DESTDIR
+export TAR INSTALL DESTDIR SHELL_PATH
### Build rules
all: $(PROGRAMS) $(SCRIPTS)
#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);
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)
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",
/* 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 *);
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)
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
static CURL *curl;
static struct curl_slist *no_pragma_header;
+static char curl_errorstr[CURL_ERROR_SIZE];
static char *initial_base;
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);
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]) {
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);
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);
if (curl_easy_perform(curl)) {
unlink(filename);
- return -1;
+ return error("%s", curl_errorstr);
}
fchmod(local, 0444);
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);
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);
} else if (argv[arg][1] == 'w') {
write_ref = argv[arg + 1];
arg++;
+ } else if (!strcmp(argv[arg], "--recover")) {
+ get_recover = 1;
}
arg++;
}
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++;
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;
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)
} else if (argv[arg][1] == 'w') {
write_ref = argv[arg + 1];
arg++;
+ } else if (!strcmp(argv[arg], "--recover")) {
+ get_recover = 1;
}
arg++;
}
#
#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:
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 \
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
+#include "strbuf.h"
/*
* Default to not allowing changes to the list of files. The
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)
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))