Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit f3e743a

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent 9e06d6e commit f3e743a

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

archive.c

+11-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "archive.h"
66
#include "parse-options.h"
77
#include "unpack-trees.h"
8-
#include "pathspec.h"
98

109
static char const * const archive_usage[] = {
1110
N_("git archive [options] <tree-ish> [<path>...]"),
@@ -152,7 +151,6 @@ int write_archive_entries(struct archiver_args *args,
152151
struct archiver_context context;
153152
struct unpack_trees_options opts;
154153
struct tree_desc t;
155-
struct pathspec pathspec;
156154
int err;
157155

158156
if (args->baselen > 0 && args->base[args->baselen - 1] == '/') {
@@ -187,10 +185,8 @@ int write_archive_entries(struct archiver_args *args,
187185
git_attr_set_direction(GIT_ATTR_INDEX, &the_index);
188186
}
189187

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,
192189
write_archive_entry, &context);
193-
free_pathspec(&pathspec);
194190
if (err == READ_TREE_RECURSIVE)
195191
err = 0;
196192
return err;
@@ -223,7 +219,7 @@ static int path_exists(struct tree *tree, const char *path)
223219
struct pathspec pathspec;
224220
int ret;
225221

226-
init_pathspec(&pathspec, paths);
222+
parse_pathspec(&pathspec, 0, 0, "", paths);
227223
ret = read_tree_recursive(tree, "", 0, 0, &pathspec, reject_entry, NULL);
228224
free_pathspec(&pathspec);
229225
return ret != 0;
@@ -232,11 +228,18 @@ static int path_exists(struct tree *tree, const char *path)
232228
static void parse_pathspec_arg(const char **pathspec,
233229
struct archiver_args *ar_args)
234230
{
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);
236239
if (pathspec) {
237240
while (*pathspec) {
238241
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);
240243
pathspec++;
241244
}
242245
}

archive.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#ifndef ARCHIVE_H
22
#define ARCHIVE_H
33

4+
#include "pathspec.h"
5+
46
struct archiver_args {
57
const char *base;
68
size_t baselen;
79
struct tree *tree;
810
const unsigned char *commit_sha1;
911
const struct commit *commit;
1012
time_t time;
11-
const char **pathspec;
13+
struct pathspec pathspec;
1214
unsigned int verbose : 1;
1315
unsigned int worktree_attributes : 1;
1416
unsigned int convert : 1;

0 commit comments

Comments
 (0)