@matheusbsbs / matheus-bagliano / commits / 973d6a2015
Fork 0

update-index --index-info: adjust for funny-path quoting.

Although the sole current user uses -z to read this, we should be prepared for somebody to feed non-z format to the command. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Oct 16, 2005 at 00:39 UTC 973d6a2015ead1afa17ea4c728b4b9a4b9716d19
1 file changed +17 -5
update-index.c
+17 -5
@@ -5,6 +5,7 @@
5 */
6 #include "cache.h"
7 #include "strbuf.h"
8 +#include "quote.h"
9
10 /*
11 * Default to not allowing changes to the list of files. The
@@ -338,6 +339,7 @@ static void read_index_info(int line_termination)
339 strbuf_init(&buf);
340 while (1) {
341 char *ptr;
342 + char *path_name;
343 unsigned char sha1[20];
344 unsigned int mode;
345
@@ -352,14 +354,22 @@ static void read_index_info(int line_termination)
354 goto bad_line;
355
356 ptr += 42;
355 - if (!verify_path(ptr)) {
356 - fprintf(stderr, "Ignoring path %s\n", ptr);
357 +
358 + if (line_termination && ptr[0] == '"')
359 + path_name = unquote_c_style(ptr, NULL);
360 + else
361 + path_name = ptr;
362 +
363 + if (!verify_path(path_name)) {
364 + fprintf(stderr, "Ignoring path %s\n", path_name);
365 + if (path_name != ptr)
366 + free(path_name);
367 continue;
368 }
369
370 if (!mode) {
371 /* mode == 0 means there is no such path -- remove */
362 - if (remove_file_from_cache(ptr))
372 + if (remove_file_from_cache(path_name))
373 die("git-update-index: unable to remove %s",
374 ptr);
375 }
@@ -369,10 +379,12 @@ static void read_index_info(int line_termination)
379 * ptr[-41] is at the beginning of sha1
380 */
381 ptr[-42] = ptr[-1] = 0;
372 - if (add_cacheinfo(buf.buf, ptr-41, ptr))
382 + if (add_cacheinfo(buf.buf, ptr-41, path_name))
383 die("git-update-index: unable to update %s",
374 - ptr);
384 + path_name);
385 }
386 + if (path_name != ptr)
387 + free(path_name);
388 continue;
389
390 bad_line: