Make "ce_match_path()" a generic helper function

... and make git-diff-files use it too.  This all _should_ make the
diffcore-pathspec.c phase unnecessary, since the diff'ers now all do the
path matching early interally.
This commit is contained in:
Linus Torvalds 2005-07-14 16:55:06 -07:00
parent fdee7d07ba
commit c0fd1f517e
4 changed files with 33 additions and 23 deletions

View File

@ -148,6 +148,7 @@ extern int remove_cache_entry_at(int pos);
extern int remove_file_from_cache(char *path); extern int remove_file_from_cache(char *path);
extern int ce_same_name(struct cache_entry *a, struct cache_entry *b); extern int ce_same_name(struct cache_entry *a, struct cache_entry *b);
extern int ce_match_stat(struct cache_entry *ce, struct stat *st); extern int ce_match_stat(struct cache_entry *ce, struct stat *st);
extern int ce_path_match(const struct cache_entry *ce, const char **pathspec);
extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, const char *type); extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, const char *type);
extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st); extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);

View File

@ -87,28 +87,6 @@ static int show_modified(struct cache_entry *old,
return 0; return 0;
} }
static int ce_path_match(const struct cache_entry *ce, const char **pathspec)
{
const char *match, *name;
int len;
if (!pathspec)
return 1;
len = ce_namelen(ce);
name = ce->name;
while ((match = *pathspec++) != NULL) {
int matchlen = strlen(match);
if (matchlen > len)
continue;
if (memcmp(name, match, matchlen))
continue;
if (name[matchlen] == '/' || !name[matchlen])
return 1;
}
return 0;
}
static int diff_cache(struct cache_entry **ac, int entries, const char **pathspec) static int diff_cache(struct cache_entry **ac, int entries, const char **pathspec)
{ {
while (entries) { while (entries) {

View File

@ -43,6 +43,7 @@ static void show_modified(int oldmode, int mode,
int main(int argc, const char **argv) int main(int argc, const char **argv)
{ {
static const unsigned char null_sha1[20] = { 0, }; static const unsigned char null_sha1[20] = { 0, };
const char **pathspec;
int entries = read_cache(); int entries = read_cache();
int i; int i;
@ -95,6 +96,9 @@ int main(int argc, const char **argv)
argv++; argc--; argv++; argc--;
} }
/* Do we have a pathspec? */
pathspec = (argc > 1) ? argv + 1 : NULL;
if (find_copies_harder && detect_rename != DIFF_DETECT_COPY) if (find_copies_harder && detect_rename != DIFF_DETECT_COPY)
usage(diff_files_usage); usage(diff_files_usage);
@ -114,6 +118,9 @@ int main(int argc, const char **argv)
struct cache_entry *ce = active_cache[i]; struct cache_entry *ce = active_cache[i];
int changed; int changed;
if (!ce_path_match(ce, pathspec))
continue;
if (ce_stage(ce)) { if (ce_stage(ce)) {
show_unmerge(ce->name); show_unmerge(ce->name);
while (i < entries && while (i < entries &&
@ -141,7 +148,7 @@ int main(int argc, const char **argv)
ce->sha1, (changed ? null_sha1 : ce->sha1), ce->sha1, (changed ? null_sha1 : ce->sha1),
ce->name); ce->name);
} }
diffcore_std((1 < argc) ? argv + 1 : NULL, diffcore_std(pathspec,
detect_rename, diff_score_opt, detect_rename, diff_score_opt,
pickaxe, pickaxe_opts, pickaxe, pickaxe_opts,
diff_break_opt, diff_break_opt,

View File

@ -171,6 +171,30 @@ int ce_same_name(struct cache_entry *a, struct cache_entry *b)
return ce_namelen(b) == len && !memcmp(a->name, b->name, len); return ce_namelen(b) == len && !memcmp(a->name, b->name, len);
} }
int ce_path_match(const struct cache_entry *ce, const char **pathspec)
{
const char *match, *name;
int len;
if (!pathspec)
return 1;
len = ce_namelen(ce);
name = ce->name;
while ((match = *pathspec++) != NULL) {
int matchlen = strlen(match);
if (matchlen > len)
continue;
if (memcmp(name, match, matchlen))
continue;
if (matchlen && name[matchlen-1] == '/')
return 1;
if (name[matchlen] == '/' || !name[matchlen])
return 1;
}
return 0;
}
/* /*
* Do we have another file that has the beginning components being a * Do we have another file that has the beginning components being a
* proper superset of the name we're trying to add? * proper superset of the name we're trying to add?