Merge branch 'cb/add-pathspec'
* cb/add-pathspec: remove pathspec_match, use match_pathspec instead clean up pathspec matchingmaint
						commit
						d64d4835b8
					
				|  | @ -230,7 +230,7 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec, | ||||||
|  |  | ||||||
| 	for (pos = 0; pos < active_nr; pos++) { | 	for (pos = 0; pos < active_nr; pos++) { | ||||||
| 		struct cache_entry *ce = active_cache[pos]; | 		struct cache_entry *ce = active_cache[pos]; | ||||||
| 		pathspec_match(pathspec, ps_matched, ce->name, 0); | 		match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, ps_matched); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if (report_path_error(ps_matched, pathspec, 0)) | 	if (report_path_error(ps_matched, pathspec, 0)) | ||||||
|  | @ -239,7 +239,7 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec, | ||||||
| 	/* Any unmerged paths? */ | 	/* Any unmerged paths? */ | ||||||
| 	for (pos = 0; pos < active_nr; pos++) { | 	for (pos = 0; pos < active_nr; pos++) { | ||||||
| 		struct cache_entry *ce = active_cache[pos]; | 		struct cache_entry *ce = active_cache[pos]; | ||||||
| 		if (pathspec_match(pathspec, NULL, ce->name, 0)) { | 		if (match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, NULL)) { | ||||||
| 			if (!ce_stage(ce)) | 			if (!ce_stage(ce)) | ||||||
| 				continue; | 				continue; | ||||||
| 			if (opts->force) { | 			if (opts->force) { | ||||||
|  | @ -264,7 +264,7 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec, | ||||||
| 	state.refresh_cache = 1; | 	state.refresh_cache = 1; | ||||||
| 	for (pos = 0; pos < active_nr; pos++) { | 	for (pos = 0; pos < active_nr; pos++) { | ||||||
| 		struct cache_entry *ce = active_cache[pos]; | 		struct cache_entry *ce = active_cache[pos]; | ||||||
| 		if (pathspec_match(pathspec, NULL, ce->name, 0)) { | 		if (match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, NULL)) { | ||||||
| 			if (!ce_stage(ce)) { | 			if (!ce_stage(ce)) { | ||||||
| 				errs |= checkout_entry(ce, &state, NULL); | 				errs |= checkout_entry(ce, &state, NULL); | ||||||
| 				continue; | 				continue; | ||||||
|  |  | ||||||
|  | @ -166,7 +166,7 @@ static int list_paths(struct string_list *list, const char *with_tree, | ||||||
| 		struct cache_entry *ce = active_cache[i]; | 		struct cache_entry *ce = active_cache[i]; | ||||||
| 		if (ce->ce_flags & CE_UPDATE) | 		if (ce->ce_flags & CE_UPDATE) | ||||||
| 			continue; | 			continue; | ||||||
| 		if (!pathspec_match(pattern, m, ce->name, 0)) | 		if (!match_pathspec(pattern, ce->name, ce_namelen(ce), 0, m)) | ||||||
| 			continue; | 			continue; | ||||||
| 		string_list_insert(ce->name, list); | 		string_list_insert(ce->name, list); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -36,42 +36,6 @@ static const char *tag_other = ""; | ||||||
| static const char *tag_killed = ""; | static const char *tag_killed = ""; | ||||||
| static const char *tag_modified = ""; | static const char *tag_modified = ""; | ||||||
|  |  | ||||||
|  |  | ||||||
| /* |  | ||||||
|  * Match a pathspec against a filename. The first "skiplen" characters |  | ||||||
|  * are the common prefix |  | ||||||
|  */ |  | ||||||
| int pathspec_match(const char **spec, char *ps_matched, |  | ||||||
| 		   const char *filename, int skiplen) |  | ||||||
| { |  | ||||||
| 	const char *m; |  | ||||||
|  |  | ||||||
| 	while ((m = *spec++) != NULL) { |  | ||||||
| 		int matchlen = strlen(m + skiplen); |  | ||||||
|  |  | ||||||
| 		if (!matchlen) |  | ||||||
| 			goto matched; |  | ||||||
| 		if (!strncmp(m + skiplen, filename + skiplen, matchlen)) { |  | ||||||
| 			if (m[skiplen + matchlen - 1] == '/') |  | ||||||
| 				goto matched; |  | ||||||
| 			switch (filename[skiplen + matchlen]) { |  | ||||||
| 			case '/': case '\0': |  | ||||||
| 				goto matched; |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 		if (!fnmatch(m + skiplen, filename + skiplen, 0)) |  | ||||||
| 			goto matched; |  | ||||||
| 		if (ps_matched) |  | ||||||
| 			ps_matched++; |  | ||||||
| 		continue; |  | ||||||
| 	matched: |  | ||||||
| 		if (ps_matched) |  | ||||||
| 			*ps_matched = 1; |  | ||||||
| 		return 1; |  | ||||||
| 	} |  | ||||||
| 	return 0; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static void show_dir_entry(const char *tag, struct dir_entry *ent) | static void show_dir_entry(const char *tag, struct dir_entry *ent) | ||||||
| { | { | ||||||
| 	int len = prefix_len; | 	int len = prefix_len; | ||||||
|  | @ -80,7 +44,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent) | ||||||
| 	if (len >= ent->len) | 	if (len >= ent->len) | ||||||
| 		die("git ls-files: internal error - directory entry not superset of prefix"); | 		die("git ls-files: internal error - directory entry not superset of prefix"); | ||||||
|  |  | ||||||
| 	if (pathspec && !pathspec_match(pathspec, ps_matched, ent->name, len)) | 	if (!match_pathspec(pathspec, ent->name, ent->len, len, ps_matched)) | ||||||
| 		return; | 		return; | ||||||
|  |  | ||||||
| 	fputs(tag, stdout); | 	fputs(tag, stdout); | ||||||
|  | @ -156,7 +120,7 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce) | ||||||
| 	if (len >= ce_namelen(ce)) | 	if (len >= ce_namelen(ce)) | ||||||
| 		die("git ls-files: internal error - cache entry not superset of prefix"); | 		die("git ls-files: internal error - cache entry not superset of prefix"); | ||||||
|  |  | ||||||
| 	if (pathspec && !pathspec_match(pathspec, ps_matched, ce->name, len)) | 	if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), len, ps_matched)) | ||||||
| 		return; | 		return; | ||||||
|  |  | ||||||
| 	if (tag && *tag && show_valid_bit && | 	if (tag && *tag && show_valid_bit && | ||||||
|  |  | ||||||
							
								
								
									
										1
									
								
								cache.h
								
								
								
								
							
							
						
						
									
										1
									
								
								cache.h
								
								
								
								
							|  | @ -937,7 +937,6 @@ extern int ws_fix_copy(char *, const char *, int, unsigned, int *); | ||||||
| extern int ws_blank_line(const char *line, int len, unsigned ws_rule); | extern int ws_blank_line(const char *line, int len, unsigned ws_rule); | ||||||
|  |  | ||||||
| /* ls-files */ | /* ls-files */ | ||||||
| int pathspec_match(const char **spec, char *matched, const char *filename, int skiplen); |  | ||||||
| int report_path_error(const char *ps_matched, const char **pathspec, int prefix_offset); | int report_path_error(const char *ps_matched, const char **pathspec, int prefix_offset); | ||||||
| void overlay_tree_on_cache(const char *tree_name, const char *prefix); | void overlay_tree_on_cache(const char *tree_name, const char *prefix); | ||||||
|  |  | ||||||
|  |  | ||||||
							
								
								
									
										19
									
								
								dir.c
								
								
								
								
							
							
						
						
									
										19
									
								
								dir.c
								
								
								
								
							|  | @ -108,25 +108,28 @@ static int match_one(const char *match, const char *name, int namelen) | ||||||
|  * and a mark is left in seen[] array for pathspec element that |  * and a mark is left in seen[] array for pathspec element that | ||||||
|  * actually matched anything. |  * actually matched anything. | ||||||
|  */ |  */ | ||||||
| int match_pathspec(const char **pathspec, const char *name, int namelen, int prefix, char *seen) | int match_pathspec(const char **pathspec, const char *name, int namelen, | ||||||
|  | 		int prefix, char *seen) | ||||||
| { | { | ||||||
| 	int retval; | 	int i, retval = 0; | ||||||
| 	const char *match; |  | ||||||
|  | 	if (!pathspec) | ||||||
|  | 		return 1; | ||||||
|  |  | ||||||
| 	name += prefix; | 	name += prefix; | ||||||
| 	namelen -= prefix; | 	namelen -= prefix; | ||||||
|  |  | ||||||
| 	for (retval = 0; (match = *pathspec++) != NULL; seen++) { | 	for (i = 0; pathspec[i] != NULL; i++) { | ||||||
| 		int how; | 		int how; | ||||||
| 		if (retval && *seen == MATCHED_EXACTLY) | 		const char *match = pathspec[i] + prefix; | ||||||
|  | 		if (seen && seen[i] == MATCHED_EXACTLY) | ||||||
| 			continue; | 			continue; | ||||||
| 		match += prefix; |  | ||||||
| 		how = match_one(match, name, namelen); | 		how = match_one(match, name, namelen); | ||||||
| 		if (how) { | 		if (how) { | ||||||
| 			if (retval < how) | 			if (retval < how) | ||||||
| 				retval = how; | 				retval = how; | ||||||
| 			if (*seen < how) | 			if (seen && seen[i] < how) | ||||||
| 				*seen = how; | 				seen[i] = how; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	return retval; | 	return retval; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Junio C Hamano
						Junio C Hamano