1#include"cache.h" 2#include"dir.h" 3#include"pathspec.h" 4 5/* 6 * Finds which of the given pathspecs match items in the index. 7 * 8 * For each pathspec, sets the corresponding entry in the seen[] array 9 * (which should be specs items long, i.e. the same size as pathspec) 10 * to the nature of the "closest" (i.e. most specific) match found for 11 * that pathspec in the index, if it was a closer type of match than 12 * the existing entry. As an optimization, matching is skipped 13 * altogether if seen[] already only contains non-zero entries. 14 * 15 * If seen[] has not already been written to, it may make sense 16 * to use find_used_pathspec() instead. 17 */ 18voidfill_pathspec_matches(const char**pathspec,char*seen,int specs) 19{ 20int num_unmatched =0, i; 21 22/* 23 * Since we are walking the index as if we were walking the directory, 24 * we have to mark the matched pathspec as seen; otherwise we will 25 * mistakenly think that the user gave a pathspec that did not match 26 * anything. 27 */ 28for(i =0; i < specs; i++) 29if(!seen[i]) 30 num_unmatched++; 31if(!num_unmatched) 32return; 33for(i =0; i < active_nr; i++) { 34struct cache_entry *ce = active_cache[i]; 35match_pathspec(pathspec, ce->name,ce_namelen(ce),0, seen); 36} 37} 38 39/* 40 * Finds which of the given pathspecs match items in the index. 41 * 42 * This is a one-shot wrapper around fill_pathspec_matches() which 43 * allocates, populates, and returns a seen[] array indicating the 44 * nature of the "closest" (i.e. most specific) matches which each of 45 * the given pathspecs achieves against all items in the index. 46 */ 47char*find_used_pathspec(const char**pathspec) 48{ 49char*seen; 50int i; 51 52for(i =0; pathspec[i]; i++) 53;/* just counting */ 54 seen =xcalloc(i,1); 55fill_pathspec_matches(pathspec, seen, i); 56return seen; 57}