+ 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);
+ report("remove '%s'", path);
+ return;
+ }
+ if (add_file_to_cache(p))
+ die("Unable to process file %s", path);
+ report("add '%s'", path);
+}
+
+static void read_index_info(int line_termination)
+{
+ struct strbuf buf;
+ strbuf_init(&buf);
+ while (1) {
+ char *ptr;
+ char *path_name;
+ 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 (line_termination && ptr[0] == '"')
+ path_name = unquote_c_style(ptr, NULL);
+ else
+ path_name = ptr;
+
+ if (!verify_path(path_name)) {
+ fprintf(stderr, "Ignoring path %s\n", path_name);
+ if (path_name != ptr)
+ free(path_name);
+ continue;
+ }
+
+ if (!mode) {
+ /* mode == 0 means there is no such path -- remove */
+ if (remove_file_from_cache(path_name))
+ 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, path_name))
+ die("git-update-index: unable to update %s",
+ path_name);
+ }
+ if (path_name != ptr)
+ free(path_name);
+ 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';