Commit f3e743a0 authored by Duy Nguyen's avatar Duy Nguyen Committed by Junio C Hamano

archive: convert to use parse_pathspec

Signed-off-by: Duy Nguyen's avatarNguyễn Thái Ngọc Duy <[email protected]>
Signed-off-by: default avatarJunio C Hamano <[email protected]>
parent 9e06d6ed
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "archive.h" #include "archive.h"
#include "parse-options.h" #include "parse-options.h"
#include "unpack-trees.h" #include "unpack-trees.h"
#include "pathspec.h"
static char const * const archive_usage[] = { static char const * const archive_usage[] = {
N_("git archive [options] <tree-ish> [<path>...]"), N_("git archive [options] <tree-ish> [<path>...]"),
...@@ -152,7 +151,6 @@ int write_archive_entries(struct archiver_args *args, ...@@ -152,7 +151,6 @@ int write_archive_entries(struct archiver_args *args,
struct archiver_context context; struct archiver_context context;
struct unpack_trees_options opts; struct unpack_trees_options opts;
struct tree_desc t; struct tree_desc t;
struct pathspec pathspec;
int err; int err;
if (args->baselen > 0 && args->base[args->baselen - 1] == '/') { if (args->baselen > 0 && args->base[args->baselen - 1] == '/') {
...@@ -187,10 +185,8 @@ int write_archive_entries(struct archiver_args *args, ...@@ -187,10 +185,8 @@ int write_archive_entries(struct archiver_args *args,
git_attr_set_direction(GIT_ATTR_INDEX, &the_index); git_attr_set_direction(GIT_ATTR_INDEX, &the_index);
} }
init_pathspec(&pathspec, args->pathspec); err = read_tree_recursive(args->tree, "", 0, 0, &args->pathspec,
err = read_tree_recursive(args->tree, "", 0, 0, &pathspec,
write_archive_entry, &context); write_archive_entry, &context);
free_pathspec(&pathspec);
if (err == READ_TREE_RECURSIVE) if (err == READ_TREE_RECURSIVE)
err = 0; err = 0;
return err; return err;
...@@ -223,7 +219,7 @@ static int path_exists(struct tree *tree, const char *path) ...@@ -223,7 +219,7 @@ static int path_exists(struct tree *tree, const char *path)
struct pathspec pathspec; struct pathspec pathspec;
int ret; int ret;
init_pathspec(&pathspec, paths); parse_pathspec(&pathspec, 0, 0, "", paths);
ret = read_tree_recursive(tree, "", 0, 0, &pathspec, reject_entry, NULL); ret = read_tree_recursive(tree, "", 0, 0, &pathspec, reject_entry, NULL);
free_pathspec(&pathspec); free_pathspec(&pathspec);
return ret != 0; return ret != 0;
...@@ -232,11 +228,18 @@ static int path_exists(struct tree *tree, const char *path) ...@@ -232,11 +228,18 @@ static int path_exists(struct tree *tree, const char *path)
static void parse_pathspec_arg(const char **pathspec, static void parse_pathspec_arg(const char **pathspec,
struct archiver_args *ar_args) struct archiver_args *ar_args)
{ {
ar_args->pathspec = pathspec = get_pathspec("", pathspec); /*
* must be consistent with parse_pathspec in path_exists()
* Also if pathspec patterns are dependent, we're in big
* trouble as we test each one separately
*/
parse_pathspec(&ar_args->pathspec, 0,
PATHSPEC_PREFER_FULL,
"", pathspec);
if (pathspec) { if (pathspec) {
while (*pathspec) { while (*pathspec) {
if (**pathspec && !path_exists(ar_args->tree, *pathspec)) if (**pathspec && !path_exists(ar_args->tree, *pathspec))
die("path not found: %s", *pathspec); die(_("pathspec '%s' did not match any files"), *pathspec);
pathspec++; pathspec++;
} }
} }
......
#ifndef ARCHIVE_H #ifndef ARCHIVE_H
#define ARCHIVE_H #define ARCHIVE_H
#include "pathspec.h"
struct archiver_args { struct archiver_args {
const char *base; const char *base;
size_t baselen; size_t baselen;
...@@ -8,7 +10,7 @@ struct archiver_args { ...@@ -8,7 +10,7 @@ struct archiver_args {
const unsigned char *commit_sha1; const unsigned char *commit_sha1;
const struct commit *commit; const struct commit *commit;
time_t time; time_t time;
const char **pathspec; struct pathspec pathspec;
unsigned int verbose : 1; unsigned int verbose : 1;
unsigned int worktree_attributes : 1; unsigned int worktree_attributes : 1;
unsigned int convert : 1; unsigned int convert : 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment