update-index: read --show-index-info output from standard input.
authorJunio C Hamano <junkio@cox.net>
Fri, 7 Oct 2005 10:42:00 +0000 (03:42 -0700)
committerJunio C Hamano <junkio@cox.net>
Fri, 7 Oct 2005 10:42:00 +0000 (03:42 -0700)
Signed-off-by: Junio C Hamano <junkio@cox.net>
update-index.c

index 9dc518877b67bedced29ac91ecd8fafbb2a60135..01b4088ad661691c8a8b778071b12527bfc45c3c 100644 (file)
@@ -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;