@@ -100,16 +100,16 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
100100 int pathlen ;
101101 int never_interesting = -1 ;
102102
103- if (!opt -> nr_paths )
103+ if (!opt -> pathspec . nr )
104104 return 1 ;
105105
106106 sha1 = tree_entry_extract (desc , & path , & mode );
107107
108108 pathlen = tree_entry_len (path , sha1 );
109109
110- for (i = 0 ; i < opt -> nr_paths ; i ++ ) {
111- const char * match = opt -> paths [i ];
112- int matchlen = opt -> pathlens [i ];
110+ for (i = 0 ; i < opt -> pathspec . nr ; i ++ ) {
111+ const char * match = opt -> pathspec . raw [i ];
112+ int matchlen = opt -> pathspec . items [i ]. len ;
113113 int m = -1 ; /* signals that we haven't called strncmp() */
114114
115115 if (baselen >= matchlen ) {
@@ -289,7 +289,7 @@ int diff_tree(struct tree_desc *t1, struct tree_desc *t2, const char *base, stru
289289 if (DIFF_OPT_TST (opt , QUICK ) &&
290290 DIFF_OPT_TST (opt , HAS_CHANGES ))
291291 break ;
292- if (opt -> nr_paths ) {
292+ if (opt -> pathspec . nr ) {
293293 skip_uninteresting (t1 , base , baselen , opt );
294294 skip_uninteresting (t2 , base , baselen , opt );
295295 }
@@ -348,7 +348,7 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
348348 DIFF_OPT_SET (& diff_opts , RECURSIVE );
349349 DIFF_OPT_SET (& diff_opts , FIND_COPIES_HARDER );
350350 diff_opts .output_format = DIFF_FORMAT_NO_OUTPUT ;
351- diff_opts .single_follow = opt -> paths [0 ];
351+ diff_opts .single_follow = opt -> pathspec . raw [0 ];
352352 diff_opts .break_opt = opt -> break_opt ;
353353 paths [0 ] = NULL ;
354354 diff_tree_setup_paths (paths , & diff_opts );
@@ -368,15 +368,15 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
368368 * diff_queued_diff, we will also use that as the path in
369369 * the future!
370370 */
371- if ((p -> status == 'R' || p -> status == 'C' ) && !strcmp (p -> two -> path , opt -> paths [0 ])) {
371+ if ((p -> status == 'R' || p -> status == 'C' ) && !strcmp (p -> two -> path , opt -> pathspec . raw [0 ])) {
372372 /* Switch the file-pairs around */
373373 q -> queue [i ] = choice ;
374374 choice = p ;
375375
376376 /* Update the path we use from now on.. */
377377 diff_tree_release_paths (opt );
378- opt -> paths [0 ] = xstrdup (p -> one -> path );
379- diff_tree_setup_paths (opt -> paths , opt );
378+ opt -> pathspec . raw [0 ] = xstrdup (p -> one -> path );
379+ diff_tree_setup_paths (opt -> pathspec . raw , opt );
380380
381381 /*
382382 * The caller expects us to return a set of vanilla
@@ -451,36 +451,12 @@ int diff_root_tree_sha1(const unsigned char *new, const char *base, struct diff_
451451 return retval ;
452452}
453453
454- static int count_paths (const char * * paths )
455- {
456- int i = 0 ;
457- while (* paths ++ )
458- i ++ ;
459- return i ;
460- }
461-
462454void diff_tree_release_paths (struct diff_options * opt )
463455{
464- free ( opt -> pathlens );
456+ free_pathspec ( & opt -> pathspec );
465457}
466458
467459void diff_tree_setup_paths (const char * * p , struct diff_options * opt )
468460{
469- opt -> nr_paths = 0 ;
470- opt -> pathlens = NULL ;
471- opt -> paths = NULL ;
472-
473- if (p ) {
474- int i ;
475-
476- opt -> paths = p ;
477- opt -> nr_paths = count_paths (p );
478- if (opt -> nr_paths == 0 ) {
479- opt -> pathlens = NULL ;
480- return ;
481- }
482- opt -> pathlens = xmalloc (opt -> nr_paths * sizeof (int ));
483- for (i = 0 ; i < opt -> nr_paths ; i ++ )
484- opt -> pathlens [i ] = strlen (p [i ]);
485- }
461+ init_pathspec (& opt -> pathspec , p );
486462}
0 commit comments