зеркало из https://github.com/microsoft/git.git
Convert ce_path_match() to use struct pathspec
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
afe069d166
Коммит
eb9cb55b94
|
@ -546,7 +546,10 @@ static int do_reupdate(int ac, const char **av,
|
||||||
*/
|
*/
|
||||||
int pos;
|
int pos;
|
||||||
int has_head = 1;
|
int has_head = 1;
|
||||||
const char **pathspec = get_pathspec(prefix, av + 1);
|
const char **paths = get_pathspec(prefix, av + 1);
|
||||||
|
struct pathspec pathspec;
|
||||||
|
|
||||||
|
init_pathspec(&pathspec, paths);
|
||||||
|
|
||||||
if (read_ref("HEAD", head_sha1))
|
if (read_ref("HEAD", head_sha1))
|
||||||
/* If there is no HEAD, that means it is an initial
|
/* If there is no HEAD, that means it is an initial
|
||||||
|
@ -559,7 +562,7 @@ static int do_reupdate(int ac, const char **av,
|
||||||
struct cache_entry *old = NULL;
|
struct cache_entry *old = NULL;
|
||||||
int save_nr;
|
int save_nr;
|
||||||
|
|
||||||
if (ce_stage(ce) || !ce_path_match(ce, pathspec))
|
if (ce_stage(ce) || !ce_path_match(ce, &pathspec))
|
||||||
continue;
|
continue;
|
||||||
if (has_head)
|
if (has_head)
|
||||||
old = read_one_ent(NULL, head_sha1,
|
old = read_one_ent(NULL, head_sha1,
|
||||||
|
@ -578,6 +581,7 @@ static int do_reupdate(int ac, const char **av,
|
||||||
if (save_nr != active_nr)
|
if (save_nr != active_nr)
|
||||||
goto redo;
|
goto redo;
|
||||||
}
|
}
|
||||||
|
free_pathspec(&pathspec);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
cache.h
2
cache.h
|
@ -515,7 +515,7 @@ struct pathspec {
|
||||||
|
|
||||||
extern int init_pathspec(struct pathspec *, const char **);
|
extern int init_pathspec(struct pathspec *, const char **);
|
||||||
extern void free_pathspec(struct pathspec *);
|
extern void free_pathspec(struct pathspec *);
|
||||||
extern int ce_path_match(const struct cache_entry *ce, const char **pathspec);
|
extern int ce_path_match(const struct cache_entry *ce, const struct pathspec *pathspec);
|
||||||
extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path);
|
extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path);
|
||||||
extern int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object);
|
extern int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object);
|
||||||
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);
|
||||||
|
|
|
@ -106,7 +106,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
|
||||||
DIFF_OPT_TST(&revs->diffopt, HAS_CHANGES))
|
DIFF_OPT_TST(&revs->diffopt, HAS_CHANGES))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (!ce_path_match(ce, revs->prune_data.raw))
|
if (!ce_path_match(ce, &revs->prune_data))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (ce_stage(ce)) {
|
if (ce_stage(ce)) {
|
||||||
|
@ -427,7 +427,7 @@ static int oneway_diff(struct cache_entry **src, struct unpack_trees_options *o)
|
||||||
if (tree == o->df_conflict_entry)
|
if (tree == o->df_conflict_entry)
|
||||||
tree = NULL;
|
tree = NULL;
|
||||||
|
|
||||||
if (ce_path_match(idx ? idx : tree, revs->prune_data.raw))
|
if (ce_path_match(idx ? idx : tree, &revs->prune_data))
|
||||||
do_oneway_diff(o, idx, tree);
|
do_oneway_diff(o, idx, tree);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -35,7 +35,9 @@ static void *preload_thread(void *_data)
|
||||||
struct index_state *index = p->index;
|
struct index_state *index = p->index;
|
||||||
struct cache_entry **cep = index->cache + p->offset;
|
struct cache_entry **cep = index->cache + p->offset;
|
||||||
struct cache_def cache;
|
struct cache_def cache;
|
||||||
|
struct pathspec pathspec;
|
||||||
|
|
||||||
|
init_pathspec(&pathspec, p->pathspec);
|
||||||
memset(&cache, 0, sizeof(cache));
|
memset(&cache, 0, sizeof(cache));
|
||||||
nr = p->nr;
|
nr = p->nr;
|
||||||
if (nr + p->offset > index->cache_nr)
|
if (nr + p->offset > index->cache_nr)
|
||||||
|
@ -51,7 +53,7 @@ static void *preload_thread(void *_data)
|
||||||
continue;
|
continue;
|
||||||
if (ce_uptodate(ce))
|
if (ce_uptodate(ce))
|
||||||
continue;
|
continue;
|
||||||
if (!ce_path_match(ce, p->pathspec))
|
if (!ce_path_match(ce, &pathspec))
|
||||||
continue;
|
continue;
|
||||||
if (threaded_has_symlink_leading_path(&cache, ce->name, ce_namelen(ce)))
|
if (threaded_has_symlink_leading_path(&cache, ce->name, ce_namelen(ce)))
|
||||||
continue;
|
continue;
|
||||||
|
@ -61,6 +63,7 @@ static void *preload_thread(void *_data)
|
||||||
continue;
|
continue;
|
||||||
ce_mark_uptodate(ce);
|
ce_mark_uptodate(ce);
|
||||||
} while (--nr > 0);
|
} while (--nr > 0);
|
||||||
|
free_pathspec(&pathspec);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -706,17 +706,18 @@ 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)
|
int ce_path_match(const struct cache_entry *ce, const struct pathspec *pathspec)
|
||||||
{
|
{
|
||||||
const char *match, *name;
|
const char *match, *name;
|
||||||
|
const char **ps = pathspec->raw;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
if (!pathspec)
|
if (!pathspec->nr)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
len = ce_namelen(ce);
|
len = ce_namelen(ce);
|
||||||
name = ce->name;
|
name = ce->name;
|
||||||
while ((match = *pathspec++) != NULL) {
|
while ((match = *ps++) != NULL) {
|
||||||
int matchlen = strlen(match);
|
int matchlen = strlen(match);
|
||||||
if (matchlen > len)
|
if (matchlen > len)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -969,7 +969,7 @@ static void prepare_show_merge(struct rev_info *revs)
|
||||||
struct cache_entry *ce = active_cache[i];
|
struct cache_entry *ce = active_cache[i];
|
||||||
if (!ce_stage(ce))
|
if (!ce_stage(ce))
|
||||||
continue;
|
continue;
|
||||||
if (ce_path_match(ce, revs->prune_data.raw)) {
|
if (ce_path_match(ce, &revs->prune_data)) {
|
||||||
prune_num++;
|
prune_num++;
|
||||||
prune = xrealloc(prune, sizeof(*prune) * prune_num);
|
prune = xrealloc(prune, sizeof(*prune) * prune_num);
|
||||||
prune[prune_num-2] = ce->name;
|
prune[prune_num-2] = ce->name;
|
||||||
|
|
|
@ -354,14 +354,16 @@ static void wt_status_collect_changes_index(struct wt_status *s)
|
||||||
|
|
||||||
static void wt_status_collect_changes_initial(struct wt_status *s)
|
static void wt_status_collect_changes_initial(struct wt_status *s)
|
||||||
{
|
{
|
||||||
|
struct pathspec pathspec;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
init_pathspec(&pathspec, s->pathspec);
|
||||||
for (i = 0; i < active_nr; i++) {
|
for (i = 0; i < active_nr; i++) {
|
||||||
struct string_list_item *it;
|
struct string_list_item *it;
|
||||||
struct wt_status_change_data *d;
|
struct wt_status_change_data *d;
|
||||||
struct cache_entry *ce = active_cache[i];
|
struct cache_entry *ce = active_cache[i];
|
||||||
|
|
||||||
if (!ce_path_match(ce, s->pathspec))
|
if (!ce_path_match(ce, &pathspec))
|
||||||
continue;
|
continue;
|
||||||
it = string_list_insert(&s->change, ce->name);
|
it = string_list_insert(&s->change, ce->name);
|
||||||
d = it->util;
|
d = it->util;
|
||||||
|
@ -376,6 +378,7 @@ static void wt_status_collect_changes_initial(struct wt_status *s)
|
||||||
else
|
else
|
||||||
d->index_status = DIFF_STATUS_ADDED;
|
d->index_status = DIFF_STATUS_ADDED;
|
||||||
}
|
}
|
||||||
|
free_pathspec(&pathspec);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wt_status_collect_untracked(struct wt_status *s)
|
static void wt_status_collect_untracked(struct wt_status *s)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче