Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

0 comments on commit eb9cb55

Please sign in to comment.
Something went wrong with that request. Please try again.