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>
Nguyễn Thái Ngọc Duy committed
Dec 17, 2010 at 19:43 UTC
eb9cb55b944796374402ab4e2639300dc9b0b409
7 files changed
+22
-11
builtin/update-index.c
+6
-2
@@ -546,7 +546,10 @@ static int do_reupdate(int ac, const char **av,
546
*/
547
int pos;
548
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);
553
554
if (read_ref("HEAD", head_sha1))
555
/* If there is no HEAD, that means it is an initial
@@ -559,7 +562,7 @@ static int do_reupdate(int ac, const char **av,
562
struct cache_entry *old = NULL;
563
int save_nr;
564
562
- if (ce_stage(ce) || !ce_path_match(ce, pathspec))
565
+ if (ce_stage(ce) || !ce_path_match(ce, &pathspec))
566
continue;
567
if (has_head)
568
old = read_one_ent(NULL, head_sha1,
@@ -578,6 +581,7 @@ static int do_reupdate(int ac, const char **av,
581
if (save_nr != active_nr)
582
goto redo;
583
}
584
+ free_pathspec(&pathspec);
585
return 0;
586
}
587
cache.h
+1
-1
@@ -515,7 +515,7 @@ struct pathspec {
515
516
extern int init_pathspec(struct pathspec *, const char **);
517
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);
519
extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path);
520
extern int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object);
521
extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
diff-lib.c
+2
-2
@@ -106,7 +106,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
106
DIFF_OPT_TST(&revs->diffopt, HAS_CHANGES))
107
break;
108
109
- if (!ce_path_match(ce, revs->prune_data.raw))
109
+ if (!ce_path_match(ce, &revs->prune_data))
110
continue;
111
112
if (ce_stage(ce)) {
@@ -427,7 +427,7 @@ static int oneway_diff(struct cache_entry **src, struct unpack_trees_options *o)
427
if (tree == o->df_conflict_entry)
428
tree = NULL;
429
430
- if (ce_path_match(idx ? idx : tree, revs->prune_data.raw))
430
+ if (ce_path_match(idx ? idx : tree, &revs->prune_data))
431
do_oneway_diff(o, idx, tree);
432
433
return 0;
preload-index.c
+4
-1
@@ -35,7 +35,9 @@ static void *preload_thread(void *_data)
35
struct index_state *index = p->index;
36
struct cache_entry **cep = index->cache + p->offset;
37
struct cache_def cache;
38
+ struct pathspec pathspec;
39
40
+ init_pathspec(&pathspec, p->pathspec);
41
memset(&cache, 0, sizeof(cache));
42
nr = p->nr;
43
if (nr + p->offset > index->cache_nr)
@@ -51,7 +53,7 @@ static void *preload_thread(void *_data)
53
continue;
54
if (ce_uptodate(ce))
55
continue;
54
- if (!ce_path_match(ce, p->pathspec))
56
+ if (!ce_path_match(ce, &pathspec))
57
continue;
58
if (threaded_has_symlink_leading_path(&cache, ce->name, ce_namelen(ce)))
59
continue;
@@ -61,6 +63,7 @@ static void *preload_thread(void *_data)
63
continue;
64
ce_mark_uptodate(ce);
65
} while (--nr > 0);
66
+ free_pathspec(&pathspec);
67
return NULL;
68
}
69
read-cache.c
+4
-3
@@ -706,17 +706,18 @@ int ce_same_name(struct cache_entry *a, struct cache_entry *b)
706
return ce_namelen(b) == len && !memcmp(a->name, b->name, len);
707
}
708
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)
710
{
711
const char *match, *name;
712
+ const char **ps = pathspec->raw;
713
int len;
714
714
- if (!pathspec)
715
+ if (!pathspec->nr)
716
return 1;
717
718
len = ce_namelen(ce);
719
name = ce->name;
719
- while ((match = *pathspec++) != NULL) {
720
+ while ((match = *ps++) != NULL) {
721
int matchlen = strlen(match);
722
if (matchlen > len)
723
continue;
revision.c
+1
-1
@@ -969,7 +969,7 @@ static void prepare_show_merge(struct rev_info *revs)
969
struct cache_entry *ce = active_cache[i];
970
if (!ce_stage(ce))
971
continue;
972
- if (ce_path_match(ce, revs->prune_data.raw)) {
972
+ if (ce_path_match(ce, &revs->prune_data)) {
973
prune_num++;
974
prune = xrealloc(prune, sizeof(*prune) * prune_num);
975
prune[prune_num-2] = ce->name;
wt-status.c
+4
-1
@@ -354,14 +354,16 @@ static void wt_status_collect_changes_index(struct wt_status *s)
354
355
static void wt_status_collect_changes_initial(struct wt_status *s)
356
{
357
+ struct pathspec pathspec;
358
int i;
359
360
+ init_pathspec(&pathspec, s->pathspec);
361
for (i = 0; i < active_nr; i++) {
362
struct string_list_item *it;
363
struct wt_status_change_data *d;
364
struct cache_entry *ce = active_cache[i];
365
364
- if (!ce_path_match(ce, s->pathspec))
366
+ if (!ce_path_match(ce, &pathspec))
367
continue;
368
it = string_list_insert(&s->change, ce->name);
369
d = it->util;
@@ -376,6 +378,7 @@ static void wt_status_collect_changes_initial(struct wt_status *s)
378
else
379
d->index_status = DIFF_STATUS_ADDED;
380
}
381
+ free_pathspec(&pathspec);
382
}
383
384
static void wt_status_collect_untracked(struct wt_status *s)