Skip to content

Commit eb9cb55

Browse files
pcloudsgitster
authored andcommitted
Convert ce_path_match() to use struct pathspec
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent afe069d commit eb9cb55

File tree

7 files changed

+22
-11
lines changed

7 files changed

+22
-11
lines changed

builtin/update-index.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,10 @@ static int do_reupdate(int ac, const char **av,
546546
*/
547547
int pos;
548548
int has_head = 1;
549-
const char **pathspec = get_pathspec(prefix, av + 1);
549+
const char **paths = get_pathspec(prefix, av + 1);
550+
struct pathspec pathspec;
551+
552+
init_pathspec(&pathspec, paths);
550553

551554
if (read_ref("HEAD", head_sha1))
552555
/* If there is no HEAD, that means it is an initial
@@ -559,7 +562,7 @@ static int do_reupdate(int ac, const char **av,
559562
struct cache_entry *old = NULL;
560563
int save_nr;
561564

562-
if (ce_stage(ce) || !ce_path_match(ce, pathspec))
565+
if (ce_stage(ce) || !ce_path_match(ce, &pathspec))
563566
continue;
564567
if (has_head)
565568
old = read_one_ent(NULL, head_sha1,
@@ -578,6 +581,7 @@ static int do_reupdate(int ac, const char **av,
578581
if (save_nr != active_nr)
579582
goto redo;
580583
}
584+
free_pathspec(&pathspec);
581585
return 0;
582586
}
583587

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ struct pathspec {
515515

516516
extern int init_pathspec(struct pathspec *, const char **);
517517
extern void free_pathspec(struct pathspec *);
518-
extern int ce_path_match(const struct cache_entry *ce, const char **pathspec);
518+
extern int ce_path_match(const struct cache_entry *ce, const struct pathspec *pathspec);
519519
extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path);
520520
extern int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object);
521521
extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);

diff-lib.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
106106
DIFF_OPT_TST(&revs->diffopt, HAS_CHANGES))
107107
break;
108108

109-
if (!ce_path_match(ce, revs->prune_data.raw))
109+
if (!ce_path_match(ce, &revs->prune_data))
110110
continue;
111111

112112
if (ce_stage(ce)) {
@@ -427,7 +427,7 @@ static int oneway_diff(struct cache_entry **src, struct unpack_trees_options *o)
427427
if (tree == o->df_conflict_entry)
428428
tree = NULL;
429429

430-
if (ce_path_match(idx ? idx : tree, revs->prune_data.raw))
430+
if (ce_path_match(idx ? idx : tree, &revs->prune_data))
431431
do_oneway_diff(o, idx, tree);
432432

433433
return 0;

preload-index.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ static void *preload_thread(void *_data)
3535
struct index_state *index = p->index;
3636
struct cache_entry **cep = index->cache + p->offset;
3737
struct cache_def cache;
38+
struct pathspec pathspec;
3839

40+
init_pathspec(&pathspec, p->pathspec);
3941
memset(&cache, 0, sizeof(cache));
4042
nr = p->nr;
4143
if (nr + p->offset > index->cache_nr)
@@ -51,7 +53,7 @@ static void *preload_thread(void *_data)
5153
continue;
5254
if (ce_uptodate(ce))
5355
continue;
54-
if (!ce_path_match(ce, p->pathspec))
56+
if (!ce_path_match(ce, &pathspec))
5557
continue;
5658
if (threaded_has_symlink_leading_path(&cache, ce->name, ce_namelen(ce)))
5759
continue;
@@ -61,6 +63,7 @@ static void *preload_thread(void *_data)
6163
continue;
6264
ce_mark_uptodate(ce);
6365
} while (--nr > 0);
66+
free_pathspec(&pathspec);
6467
return NULL;
6568
}
6669

read-cache.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -706,17 +706,18 @@ int ce_same_name(struct cache_entry *a, struct cache_entry *b)
706706
return ce_namelen(b) == len && !memcmp(a->name, b->name, len);
707707
}
708708

709-
int ce_path_match(const struct cache_entry *ce, const char **pathspec)
709+
int ce_path_match(const struct cache_entry *ce, const struct pathspec *pathspec)
710710
{
711711
const char *match, *name;
712+
const char **ps = pathspec->raw;
712713
int len;
713714

714-
if (!pathspec)
715+
if (!pathspec->nr)
715716
return 1;
716717

717718
len = ce_namelen(ce);
718719
name = ce->name;
719-
while ((match = *pathspec++) != NULL) {
720+
while ((match = *ps++) != NULL) {
720721
int matchlen = strlen(match);
721722
if (matchlen > len)
722723
continue;

revision.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ static void prepare_show_merge(struct rev_info *revs)
969969
struct cache_entry *ce = active_cache[i];
970970
if (!ce_stage(ce))
971971
continue;
972-
if (ce_path_match(ce, revs->prune_data.raw)) {
972+
if (ce_path_match(ce, &revs->prune_data)) {
973973
prune_num++;
974974
prune = xrealloc(prune, sizeof(*prune) * prune_num);
975975
prune[prune_num-2] = ce->name;

wt-status.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,16 @@ static void wt_status_collect_changes_index(struct wt_status *s)
354354

355355
static void wt_status_collect_changes_initial(struct wt_status *s)
356356
{
357+
struct pathspec pathspec;
357358
int i;
358359

360+
init_pathspec(&pathspec, s->pathspec);
359361
for (i = 0; i < active_nr; i++) {
360362
struct string_list_item *it;
361363
struct wt_status_change_data *d;
362364
struct cache_entry *ce = active_cache[i];
363365

364-
if (!ce_path_match(ce, s->pathspec))
366+
if (!ce_path_match(ce, &pathspec))
365367
continue;
366368
it = string_list_insert(&s->change, ce->name);
367369
d = it->util;
@@ -376,6 +378,7 @@ static void wt_status_collect_changes_initial(struct wt_status *s)
376378
else
377379
d->index_status = DIFF_STATUS_ADDED;
378380
}
381+
free_pathspec(&pathspec);
379382
}
380383

381384
static void wt_status_collect_untracked(struct wt_status *s)

0 commit comments

Comments
 (0)