@matheusbsbs / matheus-bagliano / commits / 9c20a47067
Fork 0

Teach update-index to read from ls-tree.

git-update-index --index-info can almost be usable to read from ls-tree output to update the index (and not the working tree file) to HEAD commit, but not quite. It was designed to read from git-apply --index-info output, and does not want " blob " in ls-tree output. Accept that as well. This lets us update "git-checkout <ent> <path>" that used to filter the extra " blob " string out. Noted by Luben. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Nov 21, 2005 at 21:46 UTC 9c20a4706767e6003e62f6500ed94ccddcbe322f
2 files changed +8 -6
git-checkout.sh
-1
@@ -82,7 +82,6 @@ then
82 # rescuing paths and is never meant to remove what
83 # is not in the named tree-ish.
84 git-ls-tree -r "$new" "$@" |
85 - sed -ne 's/^\([0-7]*\) blob \(.*\)$/\1 \2/p' |
85 git-update-index --index-info || exit $?
86 fi
87 git-checkout-index -f -u -- "$@"
update-index.c
+8 -5
@@ -338,7 +338,7 @@ static void read_index_info(int line_termination)
338 struct strbuf buf;
339 strbuf_init(&buf);
340 while (1) {
341 - char *ptr;
341 + char *ptr, *tab;
342 char *path_name;
343 unsigned char sha1[20];
344 unsigned int mode;
@@ -348,12 +348,15 @@ static void read_index_info(int line_termination)
348 break;
349
350 mode = strtoul(buf.buf, &ptr, 8);
351 - if (ptr == buf.buf || *ptr != ' ' ||
352 - get_sha1_hex(ptr + 1, sha1) ||
353 - ptr[41] != '\t')
351 + if (ptr == buf.buf || *ptr != ' ')
352 goto bad_line;
353
356 - ptr += 42;
354 + tab = strchr(ptr, '\t');
355 + if (!tab || tab - ptr < 41)
356 + goto bad_line;
357 + if (get_sha1_hex(tab - 40, sha1) || tab[-41] != ' ')
358 + goto bad_line;
359 + ptr = tab + 1;
360
361 if (line_termination && ptr[0] == '"')
362 path_name = unquote_c_style(ptr, NULL);