@@ -46,7 +46,7 @@ struct checkout_opts {
4646
4747 int branch_exists ;
4848 const char * prefix ;
49- const char * * pathspec ;
49+ struct pathspec pathspec ;
5050 struct tree * source_tree ;
5151};
5252
@@ -257,20 +257,18 @@ static int checkout_paths(const struct checkout_opts *opts,
257257
258258 if (opts -> patch_mode )
259259 return run_add_interactive (revision , "--patch=checkout" ,
260- opts -> pathspec );
260+ opts -> pathspec . raw );
261261
262262 lock_file = xcalloc (1 , sizeof (struct lock_file ));
263263
264264 newfd = hold_locked_index (lock_file , 1 );
265- if (read_cache_preload (opts -> pathspec ) < 0 )
265+ if (read_cache_preload (opts -> pathspec . raw ) < 0 )
266266 return error (_ ("corrupt index file" ));
267267
268268 if (opts -> source_tree )
269- read_tree_some (opts -> source_tree , opts -> pathspec );
269+ read_tree_some (opts -> source_tree , opts -> pathspec . raw );
270270
271- for (pos = 0 ; opts -> pathspec [pos ]; pos ++ )
272- ;
273- ps_matched = xcalloc (1 , pos );
271+ ps_matched = xcalloc (1 , opts -> pathspec .nr );
274272
275273 /*
276274 * Make sure all pathspecs participated in locating the paths
@@ -304,12 +302,12 @@ static int checkout_paths(const struct checkout_opts *opts,
304302 * match_pathspec() for _all_ entries when
305303 * opts->source_tree != NULL.
306304 */
307- if (match_pathspec ( opts -> pathspec , ce -> name , ce_namelen (ce ),
305+ if (match_pathspec_depth ( & opts -> pathspec , ce -> name , ce_namelen (ce ),
308306 0 , ps_matched ))
309307 ce -> ce_flags |= CE_MATCHED ;
310308 }
311309
312- if (report_path_error (ps_matched , opts -> pathspec , opts -> prefix )) {
310+ if (report_path_error (ps_matched , opts -> pathspec . raw , opts -> prefix )) {
313311 free (ps_matched );
314312 return 1 ;
315313 }
@@ -1002,7 +1000,7 @@ static int switch_unborn_to_new_branch(const struct checkout_opts *opts)
10021000static int checkout_branch (struct checkout_opts * opts ,
10031001 struct branch_info * new )
10041002{
1005- if (opts -> pathspec )
1003+ if (opts -> pathspec . nr )
10061004 die (_ ("paths cannot be used with switching branches" ));
10071005
10081006 if (opts -> patch_mode )
@@ -1154,9 +1152,19 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
11541152 }
11551153
11561154 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 );
11581166
1159- if (!opts .pathspec )
1167+ if (!opts .pathspec . nr )
11601168 die (_ ("invalid path specification" ));
11611169
11621170 /*
@@ -1188,7 +1196,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
11881196 strbuf_release (& buf );
11891197 }
11901198
1191- if (opts .patch_mode || opts .pathspec )
1199+ if (opts .patch_mode || opts .pathspec . nr )
11921200 return checkout_paths (& opts , new .name );
11931201 else
11941202 return checkout_branch (& opts , & new );
0 commit comments