archive: convert to use parse_pathspec
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Jul 14, 2013 at 15:35 UTC
f3e743a0d972e8ed3367d74c1152ff66f7cde416
2 files changed
+14
-9
archive.c
+11
-8
@@ -5,7 +5,6 @@
5
#include "archive.h"
6
#include "parse-options.h"
7
#include "unpack-trees.h"
8
-#include "pathspec.h"
8
9
static char const * const archive_usage[] = {
10
N_("git archive [options] <tree-ish> [<path>...]"),
@@ -152,7 +151,6 @@ int write_archive_entries(struct archiver_args *args,
151
struct archiver_context context;
152
struct unpack_trees_options opts;
153
struct tree_desc t;
155
- struct pathspec pathspec;
154
int err;
155
156
if (args->baselen > 0 && args->base[args->baselen - 1] == '/') {
@@ -187,10 +185,8 @@ int write_archive_entries(struct archiver_args *args,
185
git_attr_set_direction(GIT_ATTR_INDEX, &the_index);
186
}
187
190
- init_pathspec(&pathspec, args->pathspec);
191
- err = read_tree_recursive(args->tree, "", 0, 0, &pathspec,
188
+ err = read_tree_recursive(args->tree, "", 0, 0, &args->pathspec,
189
write_archive_entry, &context);
193
- free_pathspec(&pathspec);
190
if (err == READ_TREE_RECURSIVE)
191
err = 0;
192
return err;
@@ -223,7 +219,7 @@ static int path_exists(struct tree *tree, const char *path)
219
struct pathspec pathspec;
220
int ret;
221
226
- init_pathspec(&pathspec, paths);
222
+ parse_pathspec(&pathspec, 0, 0, "", paths);
223
ret = read_tree_recursive(tree, "", 0, 0, &pathspec, reject_entry, NULL);
224
free_pathspec(&pathspec);
225
return ret != 0;
@@ -232,11 +228,18 @@ static int path_exists(struct tree *tree, const char *path)
228
static void parse_pathspec_arg(const char **pathspec,
229
struct archiver_args *ar_args)
230
{
235
- ar_args->pathspec = pathspec = get_pathspec("", pathspec);
231
+ /*
232
+ * must be consistent with parse_pathspec in path_exists()
233
+ * Also if pathspec patterns are dependent, we're in big
234
+ * trouble as we test each one separately
235
+ */
236
+ parse_pathspec(&ar_args->pathspec, 0,
237
+ PATHSPEC_PREFER_FULL,
238
+ "", pathspec);
239
if (pathspec) {
240
while (*pathspec) {
241
if (**pathspec && !path_exists(ar_args->tree, *pathspec))
239
- die("path not found: %s", *pathspec);
242
+ die(_("pathspec '%s' did not match any files"), *pathspec);
243
pathspec++;
244
}
245
}
archive.h
+3
-1
@@ -1,6 +1,8 @@
1
#ifndef ARCHIVE_H
2
#define ARCHIVE_H
3
4
+#include "pathspec.h"
5
+
6
struct archiver_args {
7
const char *base;
8
size_t baselen;
@@ -8,7 +10,7 @@ struct archiver_args {
10
const unsigned char *commit_sha1;
11
const struct commit *commit;
12
time_t time;
11
- const char **pathspec;
13
+ struct pathspec pathspec;
14
unsigned int verbose : 1;
15
unsigned int worktree_attributes : 1;
16
unsigned int convert : 1;