]> git.ipfire.org Git - thirdparty/git.git/blobdiff - pathspec.c
Merge branch 'jk/escaped-wildcard-dwim'
[thirdparty/git.git] / pathspec.c
index 12c2b322b30a59d2091d2c87df1bed88246d5950..128f27fcb7ae8c88b0f7143943ea8a7171a83c5d 100644 (file)
@@ -3,6 +3,8 @@
 #include "dir.h"
 #include "pathspec.h"
 #include "attr.h"
+#include "argv-array.h"
+#include "quote.h"
 
 /*
  * Finds which of the given pathspecs match items in the index.
@@ -613,6 +615,42 @@ void parse_pathspec(struct pathspec *pathspec,
        }
 }
 
+void parse_pathspec_file(struct pathspec *pathspec, unsigned magic_mask,
+                        unsigned flags, const char *prefix,
+                        const char *file, int nul_term_line)
+{
+       struct argv_array parsed_file = ARGV_ARRAY_INIT;
+       strbuf_getline_fn getline_fn = nul_term_line ? strbuf_getline_nul :
+                                                      strbuf_getline;
+       struct strbuf buf = STRBUF_INIT;
+       struct strbuf unquoted = STRBUF_INIT;
+       FILE *in;
+
+       if (!strcmp(file, "-"))
+               in = stdin;
+       else
+               in = xfopen(file, "r");
+
+       while (getline_fn(&buf, in) != EOF) {
+               if (!nul_term_line && buf.buf[0] == '"') {
+                       strbuf_reset(&unquoted);
+                       if (unquote_c_style(&unquoted, buf.buf, NULL))
+                               die(_("line is badly quoted: %s"), buf.buf);
+                       strbuf_swap(&buf, &unquoted);
+               }
+               argv_array_push(&parsed_file, buf.buf);
+               strbuf_reset(&buf);
+       }
+
+       strbuf_release(&unquoted);
+       strbuf_release(&buf);
+       if (in != stdin)
+               fclose(in);
+
+       parse_pathspec(pathspec, magic_mask, flags, prefix, parsed_file.argv);
+       argv_array_clear(&parsed_file);
+}
+
 void copy_pathspec(struct pathspec *dst, const struct pathspec *src)
 {
        int i, j;