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>
Nguyễn Thái Ngọc Duy committed
Jul 14, 2013 at 15:35 UTC
5ab2a2dabd6e13cd6830ff4f12f232dc79278e29
7 files changed
+19
-17
builtin/checkout.c
+1
-1
@@ -262,7 +262,7 @@ static int checkout_paths(const struct checkout_opts *opts,
262
lock_file = xcalloc(1, sizeof(struct lock_file));
263
264
newfd = hold_locked_index(lock_file, 1);
265
- if (read_cache_preload(opts->pathspec.raw) < 0)
265
+ if (read_cache_preload(&opts->pathspec) < 0)
266
return error(_("corrupt index file"));
267
268
if (opts->source_tree)
builtin/commit.c
+2
-2
@@ -294,7 +294,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
294
PATHSPEC_PREFER_FULL,
295
prefix, argv);
296
297
- if (read_cache_preload(pathspec.raw) < 0)
297
+ if (read_cache_preload(&pathspec) < 0)
298
die(_("index file corrupt"));
299
300
if (interactive) {
@@ -1245,7 +1245,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1245
PATHSPEC_PREFER_FULL,
1246
prefix, argv);
1247
1248
- read_cache_preload(s.pathspec.raw);
1248
+ read_cache_preload(&s.pathspec);
1249
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, s.pathspec.raw, NULL, NULL);
1250
1251
fd = hold_locked_index(&index_lock, 0);
builtin/diff-files.c
+1
-1
@@ -61,7 +61,7 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
61
(rev.diffopt.output_format & DIFF_FORMAT_PATCH))
62
rev.combine_merges = rev.dense_combined_merges = 1;
63
64
- if (read_cache_preload(rev.diffopt.pathspec.raw) < 0) {
64
+ if (read_cache_preload(&rev.diffopt.pathspec) < 0) {
65
perror("read_cache_preload");
66
return -1;
67
}
builtin/diff-index.c
+1
-1
@@ -43,7 +43,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
43
usage(diff_cache_usage);
44
if (!cached) {
45
setup_work_tree();
46
- if (read_cache_preload(rev.diffopt.pathspec.raw) < 0) {
46
+ if (read_cache_preload(&rev.diffopt.pathspec) < 0) {
47
perror("read_cache_preload");
48
return -1;
49
}
builtin/diff.c
+2
-2
@@ -140,7 +140,7 @@ static int builtin_diff_index(struct rev_info *revs,
140
usage(builtin_diff_usage);
141
if (!cached) {
142
setup_work_tree();
143
- if (read_cache_preload(revs->diffopt.pathspec.raw) < 0) {
143
+ if (read_cache_preload(&revs->diffopt.pathspec) < 0) {
144
perror("read_cache_preload");
145
return -1;
146
}
@@ -242,7 +242,7 @@ static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv
242
revs->combine_merges = revs->dense_combined_merges = 1;
243
244
setup_work_tree();
245
- if (read_cache_preload(revs->diffopt.pathspec.raw) < 0) {
245
+ if (read_cache_preload(&revs->diffopt.pathspec) < 0) {
246
perror("read_cache_preload");
247
return -1;
248
}
cache.h
+1
-1
@@ -449,7 +449,7 @@ extern int init_db(const char *template_dir, unsigned int flags);
449
450
/* Initialize and use the cache information */
451
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);
453
extern int read_index_from(struct index_state *, const char *path);
454
extern int is_index_unborn(struct index_state *);
455
extern int read_index_unmerged(struct index_state *);
preload-index.c
+11
-9
@@ -5,7 +5,8 @@
5
#include "pathspec.h"
6
7
#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)
10
{
11
; /* nothing */
12
}
@@ -25,7 +26,7 @@ static void preload_index(struct index_state *index, const char **pathspec)
26
struct thread_data {
27
pthread_t pthread;
28
struct index_state *index;
28
- const char **pathspec;
29
+ struct pathspec pathspec;
30
int offset, nr;
31
};
32
@@ -36,9 +37,7 @@ static void *preload_thread(void *_data)
37
struct index_state *index = p->index;
38
struct cache_entry **cep = index->cache + p->offset;
39
struct cache_def cache;
39
- struct pathspec pathspec;
40
41
- init_pathspec(&pathspec, p->pathspec);
41
memset(&cache, 0, sizeof(cache));
42
nr = p->nr;
43
if (nr + p->offset > index->cache_nr)
@@ -54,7 +53,7 @@ static void *preload_thread(void *_data)
53
continue;
54
if (ce_uptodate(ce))
55
continue;
57
- if (!ce_path_match(ce, &pathspec))
56
+ if (!ce_path_match(ce, &p->pathspec))
57
continue;
58
if (threaded_has_symlink_leading_path(&cache, ce->name, ce_namelen(ce)))
59
continue;
@@ -64,11 +63,11 @@ static void *preload_thread(void *_data)
63
continue;
64
ce_mark_uptodate(ce);
65
} while (--nr > 0);
67
- free_pathspec(&pathspec);
66
return NULL;
67
}
68
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)
71
{
72
int threads, i, work, offset;
73
struct thread_data data[MAX_PARALLEL];
@@ -83,10 +82,12 @@ static void preload_index(struct index_state *index, const char **pathspec)
82
threads = MAX_PARALLEL;
83
offset = 0;
84
work = DIV_ROUND_UP(index->cache_nr, threads);
85
+ memset(&data, 0, sizeof(data));
86
for (i = 0; i < threads; i++) {
87
struct thread_data *p = data+i;
88
p->index = index;
89
- p->pathspec = pathspec;
89
+ if (pathspec)
90
+ copy_pathspec(&p->pathspec, pathspec);
91
p->offset = offset;
92
p->nr = work;
93
offset += work;
@@ -101,7 +102,8 @@ static void preload_index(struct index_state *index, const char **pathspec)
102
}
103
#endif
104
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)
107
{
108
int retval = read_index(index);
109