summaryrefslogtreecommitdiff
path: root/update-index.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-10-07 10:42:00 (GMT)
committerJunio C Hamano <junkio@cox.net>2005-10-07 10:42:00 (GMT)
commitd4dbf36df0eb2efe78822704d9779d662ed4dd8a (patch)
treec85d4a8690d99542f15313f1e1eda179bf51487e /update-index.c
parent2cf67f1e35d3a2175e426b4b2841374e68105c2c (diff)
downloadgit-d4dbf36df0eb2efe78822704d9779d662ed4dd8a.zip
git-d4dbf36df0eb2efe78822704d9779d662ed4dd8a.tar.gz
git-d4dbf36df0eb2efe78822704d9779d662ed4dd8a.tar.bz2
update-index: read --show-index-info output from standard input.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'update-index.c')
-rw-r--r--update-index.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/update-index.c b/update-index.c
index 9dc5188..01b4088 100644
--- a/update-index.c
+++ b/update-index.c
@@ -272,6 +272,54 @@ static void update_one(const char *path, const char *prefix, int prefix_length)
die("Unable to process file %s", path);
}
+static void read_index_info(int line_termination)
+{
+ struct strbuf buf;
+ strbuf_init(&buf);
+ while (1) {
+ char *ptr;
+ unsigned char sha1[20];
+ unsigned int mode;
+
+ read_line(&buf, stdin, line_termination);
+ if (buf.eof)
+ break;
+
+ mode = strtoul(buf.buf, &ptr, 8);
+ if (ptr == buf.buf || *ptr != ' ' ||
+ get_sha1_hex(ptr + 1, sha1) ||
+ ptr[41] != '\t')
+ goto bad_line;
+
+ ptr += 42;
+ if (!verify_path(ptr)) {
+ fprintf(stderr, "Ignoring path %s\n", ptr);
+ continue;
+ }
+
+ if (!mode) {
+ /* mode == 0 means there is no such path -- remove */
+ if (remove_file_from_cache(ptr))
+ die("git-update-index: unable to remove %s",
+ ptr);
+ }
+ else {
+ /* mode ' ' sha1 '\t' name
+ * ptr[-1] points at tab,
+ * ptr[-41] is at the beginning of sha1
+ */
+ ptr[-42] = ptr[-1] = 0;
+ if (add_cacheinfo(buf.buf, ptr-41, ptr))
+ die("git-update-index: unable to update %s",
+ ptr);
+ }
+ continue;
+
+ bad_line:
+ die("malformed index info %s", buf.buf);
+ }
+}
+
int main(int argc, const char **argv)
{
int i, newfd, entries, has_errors = 0, line_termination = '\n';
@@ -346,6 +394,11 @@ int main(int argc, const char **argv)
read_from_stdin = 1;
break;
}
+ if (!strcmp(path, "--index-info")) {
+ allow_add = allow_replace = allow_remove = 1;
+ read_index_info(line_termination);
+ continue;
+ }
if (!strcmp(path, "--ignore-missing")) {
not_new = 1;
continue;