Skip to content

Commit

Permalink
update-index: read --show-index-info output from standard input.
Browse files Browse the repository at this point in the history
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Junio C Hamano committed Oct 7, 2005
1 parent 2cf67f1 commit d4dbf36
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions update-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d4dbf36

Please sign in to comment.