Skip to content

Commit 5ab2a2d

Browse files
pcloudsgitster
authored andcommitted
convert read_cache_preload() to take struct pathspec
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 78a9514 commit 5ab2a2d

File tree

7 files changed

+19
-17
lines changed

7 files changed

+19
-17
lines changed

builtin/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ static int checkout_paths(const struct checkout_opts *opts,
262262
lock_file = xcalloc(1, sizeof(struct lock_file));
263263

264264
newfd = hold_locked_index(lock_file, 1);
265-
if (read_cache_preload(opts->pathspec.raw) < 0)
265+
if (read_cache_preload(&opts->pathspec) < 0)
266266
return error(_("corrupt index file"));
267267

268268
if (opts->source_tree)

builtin/commit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
294294
PATHSPEC_PREFER_FULL,
295295
prefix, argv);
296296

297-
if (read_cache_preload(pathspec.raw) < 0)
297+
if (read_cache_preload(&pathspec) < 0)
298298
die(_("index file corrupt"));
299299

300300
if (interactive) {
@@ -1245,7 +1245,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
12451245
PATHSPEC_PREFER_FULL,
12461246
prefix, argv);
12471247

1248-
read_cache_preload(s.pathspec.raw);
1248+
read_cache_preload(&s.pathspec);
12491249
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, s.pathspec.raw, NULL, NULL);
12501250

12511251
fd = hold_locked_index(&index_lock, 0);

builtin/diff-files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
6161
(rev.diffopt.output_format & DIFF_FORMAT_PATCH))
6262
rev.combine_merges = rev.dense_combined_merges = 1;
6363

64-
if (read_cache_preload(rev.diffopt.pathspec.raw) < 0) {
64+
if (read_cache_preload(&rev.diffopt.pathspec) < 0) {
6565
perror("read_cache_preload");
6666
return -1;
6767
}

builtin/diff-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
4343
usage(diff_cache_usage);
4444
if (!cached) {
4545
setup_work_tree();
46-
if (read_cache_preload(rev.diffopt.pathspec.raw) < 0) {
46+
if (read_cache_preload(&rev.diffopt.pathspec) < 0) {
4747
perror("read_cache_preload");
4848
return -1;
4949
}

builtin/diff.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static int builtin_diff_index(struct rev_info *revs,
140140
usage(builtin_diff_usage);
141141
if (!cached) {
142142
setup_work_tree();
143-
if (read_cache_preload(revs->diffopt.pathspec.raw) < 0) {
143+
if (read_cache_preload(&revs->diffopt.pathspec) < 0) {
144144
perror("read_cache_preload");
145145
return -1;
146146
}
@@ -242,7 +242,7 @@ static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv
242242
revs->combine_merges = revs->dense_combined_merges = 1;
243243

244244
setup_work_tree();
245-
if (read_cache_preload(revs->diffopt.pathspec.raw) < 0) {
245+
if (read_cache_preload(&revs->diffopt.pathspec) < 0) {
246246
perror("read_cache_preload");
247247
return -1;
248248
}

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ extern int init_db(const char *template_dir, unsigned int flags);
449449

450450
/* Initialize and use the cache information */
451451
extern int read_index(struct index_state *);
452-
extern int read_index_preload(struct index_state *, const char **pathspec);
452+
extern int read_index_preload(struct index_state *, const struct pathspec *pathspec);
453453
extern int read_index_from(struct index_state *, const char *path);
454454
extern int is_index_unborn(struct index_state *);
455455
extern int read_index_unmerged(struct index_state *);

preload-index.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#include "pathspec.h"
66

77
#ifdef NO_PTHREADS
8-
static void preload_index(struct index_state *index, const char **pathspec)
8+
static void preload_index(struct index_state *index,
9+
const struct pathspec *pathspec)
910
{
1011
; /* nothing */
1112
}
@@ -25,7 +26,7 @@ static void preload_index(struct index_state *index, const char **pathspec)
2526
struct thread_data {
2627
pthread_t pthread;
2728
struct index_state *index;
28-
const char **pathspec;
29+
struct pathspec pathspec;
2930
int offset, nr;
3031
};
3132

@@ -36,9 +37,7 @@ static void *preload_thread(void *_data)
3637
struct index_state *index = p->index;
3738
struct cache_entry **cep = index->cache + p->offset;
3839
struct cache_def cache;
39-
struct pathspec pathspec;
4040

41-
init_pathspec(&pathspec, p->pathspec);
4241
memset(&cache, 0, sizeof(cache));
4342
nr = p->nr;
4443
if (nr + p->offset > index->cache_nr)
@@ -54,7 +53,7 @@ static void *preload_thread(void *_data)
5453
continue;
5554
if (ce_uptodate(ce))
5655
continue;
57-
if (!ce_path_match(ce, &pathspec))
56+
if (!ce_path_match(ce, &p->pathspec))
5857
continue;
5958
if (threaded_has_symlink_leading_path(&cache, ce->name, ce_namelen(ce)))
6059
continue;
@@ -64,11 +63,11 @@ static void *preload_thread(void *_data)
6463
continue;
6564
ce_mark_uptodate(ce);
6665
} while (--nr > 0);
67-
free_pathspec(&pathspec);
6866
return NULL;
6967
}
7068

71-
static void preload_index(struct index_state *index, const char **pathspec)
69+
static void preload_index(struct index_state *index,
70+
const struct pathspec *pathspec)
7271
{
7372
int threads, i, work, offset;
7473
struct thread_data data[MAX_PARALLEL];
@@ -83,10 +82,12 @@ static void preload_index(struct index_state *index, const char **pathspec)
8382
threads = MAX_PARALLEL;
8483
offset = 0;
8584
work = DIV_ROUND_UP(index->cache_nr, threads);
85+
memset(&data, 0, sizeof(data));
8686
for (i = 0; i < threads; i++) {
8787
struct thread_data *p = data+i;
8888
p->index = index;
89-
p->pathspec = pathspec;
89+
if (pathspec)
90+
copy_pathspec(&p->pathspec, pathspec);
9091
p->offset = offset;
9192
p->nr = work;
9293
offset += work;
@@ -101,7 +102,8 @@ static void preload_index(struct index_state *index, const char **pathspec)
101102
}
102103
#endif
103104

104-
int read_index_preload(struct index_state *index, const char **pathspec)
105+
int read_index_preload(struct index_state *index,
106+
const struct pathspec *pathspec)
105107
{
106108
int retval = read_index(index);
107109

0 commit comments

Comments
 (0)