|
3 | 3 | #include "dir.h"
|
4 | 4 | #include "pathspec.h"
|
5 | 5 | #include "attr.h"
|
| 6 | +#include "argv-array.h" |
| 7 | +#include "quote.h" |
6 | 8 |
|
7 | 9 | /*
|
8 | 10 | * Finds which of the given pathspecs match items in the index.
|
@@ -613,6 +615,42 @@ void parse_pathspec(struct pathspec *pathspec,
|
613 | 615 | }
|
614 | 616 | }
|
615 | 617 |
|
| 618 | +void parse_pathspec_file(struct pathspec *pathspec, unsigned magic_mask, |
| 619 | + unsigned flags, const char *prefix, |
| 620 | + const char *file, int nul_term_line) |
| 621 | +{ |
| 622 | + struct argv_array parsed_file = ARGV_ARRAY_INIT; |
| 623 | + strbuf_getline_fn getline_fn = nul_term_line ? strbuf_getline_nul : |
| 624 | + strbuf_getline; |
| 625 | + struct strbuf buf = STRBUF_INIT; |
| 626 | + struct strbuf unquoted = STRBUF_INIT; |
| 627 | + FILE *in; |
| 628 | + |
| 629 | + if (!strcmp(file, "-")) |
| 630 | + in = stdin; |
| 631 | + else |
| 632 | + in = xfopen(file, "r"); |
| 633 | + |
| 634 | + while (getline_fn(&buf, in) != EOF) { |
| 635 | + if (!nul_term_line && buf.buf[0] == '"') { |
| 636 | + strbuf_reset(&unquoted); |
| 637 | + if (unquote_c_style(&unquoted, buf.buf, NULL)) |
| 638 | + die(_("line is badly quoted: %s"), buf.buf); |
| 639 | + strbuf_swap(&buf, &unquoted); |
| 640 | + } |
| 641 | + argv_array_push(&parsed_file, buf.buf); |
| 642 | + strbuf_reset(&buf); |
| 643 | + } |
| 644 | + |
| 645 | + strbuf_release(&unquoted); |
| 646 | + strbuf_release(&buf); |
| 647 | + if (in != stdin) |
| 648 | + fclose(in); |
| 649 | + |
| 650 | + parse_pathspec(pathspec, magic_mask, flags, prefix, parsed_file.argv); |
| 651 | + argv_array_clear(&parsed_file); |
| 652 | +} |
| 653 | + |
616 | 654 | void copy_pathspec(struct pathspec *dst, const struct pathspec *src)
|
617 | 655 | {
|
618 | 656 | int i, j;
|
|
0 commit comments