update-index: read --show-index-info output from standard input.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Oct 7, 2005 at 03:42 UTC
d4dbf36df0eb2efe78822704d9779d662ed4dd8a
1 file changed
+53
update-index.c
+53
@@ -272,6 +272,54 @@ static void update_one(const char *path, const char *prefix, int prefix_length)
272
die("Unable to process file %s", path);
273
}
274
275
+static void read_index_info(int line_termination)
276
+{
277
+ struct strbuf buf;
278
+ strbuf_init(&buf);
279
+ while (1) {
280
+ char *ptr;
281
+ unsigned char sha1[20];
282
+ unsigned int mode;
283
+
284
+ read_line(&buf, stdin, line_termination);
285
+ if (buf.eof)
286
+ break;
287
+
288
+ mode = strtoul(buf.buf, &ptr, 8);
289
+ if (ptr == buf.buf || *ptr != ' ' ||
290
+ get_sha1_hex(ptr + 1, sha1) ||
291
+ ptr[41] != '\t')
292
+ goto bad_line;
293
+
294
+ ptr += 42;
295
+ if (!verify_path(ptr)) {
296
+ fprintf(stderr, "Ignoring path %s\n", ptr);
297
+ continue;
298
+ }
299
+
300
+ if (!mode) {
301
+ /* mode == 0 means there is no such path -- remove */
302
+ if (remove_file_from_cache(ptr))
303
+ die("git-update-index: unable to remove %s",
304
+ ptr);
305
+ }
306
+ else {
307
+ /* mode ' ' sha1 '\t' name
308
+ * ptr[-1] points at tab,
309
+ * ptr[-41] is at the beginning of sha1
310
+ */
311
+ ptr[-42] = ptr[-1] = 0;
312
+ if (add_cacheinfo(buf.buf, ptr-41, ptr))
313
+ die("git-update-index: unable to update %s",
314
+ ptr);
315
+ }
316
+ continue;
317
+
318
+ bad_line:
319
+ die("malformed index info %s", buf.buf);
320
+ }
321
+}
322
+
323
int main(int argc, const char **argv)
324
{
325
int i, newfd, entries, has_errors = 0, line_termination = '\n';
@@ -346,6 +394,11 @@ int main(int argc, const char **argv)
394
read_from_stdin = 1;
395
break;
396
}
397
+ if (!strcmp(path, "--index-info")) {
398
+ allow_add = allow_replace = allow_remove = 1;
399
+ read_index_info(line_termination);
400
+ continue;
401
+ }
402
if (!strcmp(path, "--ignore-missing")) {
403
not_new = 1;
404
continue;