checkout: 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
817b345aeb47eb2dfeccbdbf99442359283434c2
1 file changed
+21
-13
builtin/checkout.c
+21
-13
@@ -46,7 +46,7 @@ struct checkout_opts {
46
47
int branch_exists;
48
const char *prefix;
49
- const char **pathspec;
49
+ struct pathspec pathspec;
50
struct tree *source_tree;
51
};
52
@@ -257,20 +257,18 @@ static int checkout_paths(const struct checkout_opts *opts,
257
258
if (opts->patch_mode)
259
return run_add_interactive(revision, "--patch=checkout",
260
- opts->pathspec);
260
+ opts->pathspec.raw);
261
262
lock_file = xcalloc(1, sizeof(struct lock_file));
263
264
newfd = hold_locked_index(lock_file, 1);
265
- if (read_cache_preload(opts->pathspec) < 0)
265
+ if (read_cache_preload(opts->pathspec.raw) < 0)
266
return error(_("corrupt index file"));
267
268
if (opts->source_tree)
269
- read_tree_some(opts->source_tree, opts->pathspec);
269
+ read_tree_some(opts->source_tree, opts->pathspec.raw);
270
271
- for (pos = 0; opts->pathspec[pos]; pos++)
272
- ;
273
- ps_matched = xcalloc(1, pos);
271
+ ps_matched = xcalloc(1, opts->pathspec.nr);
272
273
/*
274
* Make sure all pathspecs participated in locating the paths
@@ -304,12 +302,12 @@ static int checkout_paths(const struct checkout_opts *opts,
302
* match_pathspec() for _all_ entries when
303
* opts->source_tree != NULL.
304
*/
307
- if (match_pathspec(opts->pathspec, ce->name, ce_namelen(ce),
305
+ if (match_pathspec_depth(&opts->pathspec, ce->name, ce_namelen(ce),
306
0, ps_matched))
307
ce->ce_flags |= CE_MATCHED;
308
}
309
312
- if (report_path_error(ps_matched, opts->pathspec, opts->prefix)) {
310
+ if (report_path_error(ps_matched, opts->pathspec.raw, opts->prefix)) {
311
free(ps_matched);
312
return 1;
313
}
@@ -1002,7 +1000,7 @@ static int switch_unborn_to_new_branch(const struct checkout_opts *opts)
1000
static int checkout_branch(struct checkout_opts *opts,
1001
struct branch_info *new)
1002
{
1005
- if (opts->pathspec)
1003
+ if (opts->pathspec.nr)
1004
die(_("paths cannot be used with switching branches"));
1005
1006
if (opts->patch_mode)
@@ -1154,9 +1152,19 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
1152
}
1153
1154
if (argc) {
1157
- opts.pathspec = get_pathspec(prefix, argv);
1155
+ /*
1156
+ * In patch mode (opts.patch_mode != 0), we pass the
1157
+ * pathspec to an external program, git-add--interactive.
1158
+ * Do not accept any kind of magic that that program
1159
+ * cannot handle. Magic mask is pretty safe to be
1160
+ * lifted for new magic when opts.patch_mode == 0.
1161
+ */
1162
+ parse_pathspec(&opts.pathspec,
1163
+ opts.patch_mode == 0 ? 0 :
1164
+ (PATHSPEC_ALL_MAGIC & ~PATHSPEC_FROMTOP),
1165
+ 0, prefix, argv);
1166
1159
- if (!opts.pathspec)
1167
+ if (!opts.pathspec.nr)
1168
die(_("invalid path specification"));
1169
1170
/*
@@ -1188,7 +1196,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
1196
strbuf_release(&buf);
1197
}
1198
1191
- if (opts.patch_mode || opts.pathspec)
1199
+ if (opts.patch_mode || opts.pathspec.nr)
1200
return checkout_paths(&opts, new.name);
1201
else
1202
return checkout_branch(&opts, &new);