Skip to content

Commit 9a08727

Browse files
pcloudsgitster
authored andcommitted
remove init_pathspec() in favor of parse_pathspec()
While at there, move free_pathspec() to pathspec.c Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bd1928d commit 9a08727

File tree

10 files changed

+21
-81
lines changed

10 files changed

+21
-81
lines changed

builtin/blame.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ static struct origin *find_origin(struct scoreboard *sb,
408408
paths[0] = origin->path;
409409
paths[1] = NULL;
410410

411-
init_pathspec(&diff_opts.pathspec, paths);
411+
parse_pathspec(&diff_opts.pathspec, PATHSPEC_ALL_MAGIC, 0, "", paths);
412412
diff_setup_done(&diff_opts);
413413

414414
if (is_null_sha1(origin->commit->object.sha1))
@@ -486,15 +486,12 @@ static struct origin *find_rename(struct scoreboard *sb,
486486
struct origin *porigin = NULL;
487487
struct diff_options diff_opts;
488488
int i;
489-
const char *paths[2];
490489

491490
diff_setup(&diff_opts);
492491
DIFF_OPT_SET(&diff_opts, RECURSIVE);
493492
diff_opts.detect_rename = DIFF_DETECT_RENAME;
494493
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
495494
diff_opts.single_follow = origin->path;
496-
paths[0] = NULL;
497-
init_pathspec(&diff_opts.pathspec, paths);
498495
diff_setup_done(&diff_opts);
499496

500497
if (is_null_sha1(origin->commit->object.sha1))
@@ -1064,7 +1061,6 @@ static int find_copy_in_parent(struct scoreboard *sb,
10641061
int opt)
10651062
{
10661063
struct diff_options diff_opts;
1067-
const char *paths[1];
10681064
int i, j;
10691065
int retval;
10701066
struct blame_list *blame_list;
@@ -1078,8 +1074,6 @@ static int find_copy_in_parent(struct scoreboard *sb,
10781074
DIFF_OPT_SET(&diff_opts, RECURSIVE);
10791075
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
10801076

1081-
paths[0] = NULL;
1082-
init_pathspec(&diff_opts.pathspec, paths);
10831077
diff_setup_done(&diff_opts);
10841078

10851079
/* Try "find copies harder" on new path if requested;

builtin/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
503503
init_grep_defaults();
504504
git_config(git_log_config, NULL);
505505

506-
init_pathspec(&match_all, NULL);
506+
memset(&match_all, 0, sizeof(match_all));
507507
init_revisions(&rev, prefix);
508508
rev.diff = 1;
509509
rev.always_show_header = 1;

builtin/ls-files.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,12 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
315315
}
316316

317317
if (prefix) {
318-
static const char *(matchbuf[2]);
319-
matchbuf[0] = prefix;
320-
matchbuf[1] = NULL;
321-
init_pathspec(&pathspec, matchbuf);
322-
pathspec.items[0].nowildcard_len = pathspec.items[0].len;
318+
static const char *(matchbuf[1]);
319+
matchbuf[0] = NULL;
320+
parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC,
321+
PATHSPEC_PREFER_CWD, prefix, matchbuf);
323322
} else
324-
init_pathspec(&pathspec, NULL);
323+
memset(&pathspec, 0, sizeof(pathspec));
325324
if (read_tree(tree, 1, &pathspec))
326325
die("unable to read tree entries %s", tree_name);
327326

diff-lib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
501501
struct rev_info revs;
502502

503503
init_revisions(&revs, NULL);
504-
init_pathspec(&revs.prune_data, opt->pathspec.raw);
504+
copy_pathspec(&revs.prune_data, &opt->pathspec);
505505
revs.diffopt = *opt;
506506

507507
if (diff_cache(&revs, tree_sha1, NULL, 1))

dir.c

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,64 +1580,6 @@ int remove_path(const char *name)
15801580
return 0;
15811581
}
15821582

1583-
static int pathspec_item_cmp(const void *a_, const void *b_)
1584-
{
1585-
struct pathspec_item *a, *b;
1586-
1587-
a = (struct pathspec_item *)a_;
1588-
b = (struct pathspec_item *)b_;
1589-
return strcmp(a->match, b->match);
1590-
}
1591-
1592-
int init_pathspec(struct pathspec *pathspec, const char **paths)
1593-
{
1594-
const char **p = paths;
1595-
int i;
1596-
1597-
memset(pathspec, 0, sizeof(*pathspec));
1598-
if (!p)
1599-
return 0;
1600-
while (*p)
1601-
p++;
1602-
pathspec->raw = paths;
1603-
pathspec->nr = p - paths;
1604-
if (!pathspec->nr)
1605-
return 0;
1606-
1607-
pathspec->items = xmalloc(sizeof(struct pathspec_item)*pathspec->nr);
1608-
for (i = 0; i < pathspec->nr; i++) {
1609-
struct pathspec_item *item = pathspec->items+i;
1610-
const char *path = paths[i];
1611-
1612-
item->match = path;
1613-
item->original = path;
1614-
item->len = strlen(path);
1615-
item->flags = 0;
1616-
if (limit_pathspec_to_literal()) {
1617-
item->nowildcard_len = item->len;
1618-
} else {
1619-
item->nowildcard_len = simple_length(path);
1620-
if (item->nowildcard_len < item->len) {
1621-
pathspec->has_wildcard = 1;
1622-
if (path[item->nowildcard_len] == '*' &&
1623-
no_wildcard(path + item->nowildcard_len + 1))
1624-
item->flags |= PATHSPEC_ONESTAR;
1625-
}
1626-
}
1627-
}
1628-
1629-
qsort(pathspec->items, pathspec->nr,
1630-
sizeof(struct pathspec_item), pathspec_item_cmp);
1631-
1632-
return 0;
1633-
}
1634-
1635-
void free_pathspec(struct pathspec *pathspec)
1636-
{
1637-
free(pathspec->items);
1638-
pathspec->items = NULL;
1639-
}
1640-
16411583
int limit_pathspec_to_literal(void)
16421584
{
16431585
static int flag = -1;

merge-recursive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ static int get_files_dirs(struct merge_options *o, struct tree *tree)
297297
{
298298
int n;
299299
struct pathspec match_all;
300-
init_pathspec(&match_all, NULL);
300+
memset(&match_all, 0, sizeof(match_all));
301301
if (read_tree_recursive(tree, "", 0, 0, &match_all, save_files_dirs, o))
302302
return 0;
303303
n = o->current_file_set.nr + o->current_directory_set.nr;

pathspec.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,9 @@ void copy_pathspec(struct pathspec *dst, const struct pathspec *src)
372372
memcpy(dst->items, src->items,
373373
sizeof(struct pathspec_item) * dst->nr);
374374
}
375+
376+
void free_pathspec(struct pathspec *pathspec)
377+
{
378+
free(pathspec->items);
379+
pathspec->items = NULL;
380+
}

pathspec.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ struct pathspec {
5353
#define PATHSPEC_PREFIX_ORIGIN (1<<6)
5454
#define PATHSPEC_KEEP_ORDER (1<<7)
5555

56-
extern int init_pathspec(struct pathspec *, const char **);
5756
extern void parse_pathspec(struct pathspec *pathspec,
5857
unsigned magic_mask,
5958
unsigned flags,

revision.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,7 @@ static void prepare_show_merge(struct rev_info *revs)
13721372
i++;
13731373
}
13741374
free_pathspec(&revs->prune_data);
1375-
init_pathspec(&revs->prune_data, prune);
1375+
parse_pathspec(&revs->prune_data, PATHSPEC_ALL_MAGIC, 0, "", prune);
13761376
revs->limited = 1;
13771377
}
13781378

tree-diff.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
195195
struct diff_options diff_opts;
196196
struct diff_queue_struct *q = &diff_queued_diff;
197197
struct diff_filepair *choice;
198-
const char *paths[1];
199198
int i;
200199

201200
/*
@@ -228,8 +227,6 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
228227
diff_opts.single_follow = opt->pathspec.raw[0];
229228
diff_opts.break_opt = opt->break_opt;
230229
diff_opts.rename_score = opt->rename_score;
231-
paths[0] = NULL;
232-
init_pathspec(&diff_opts.pathspec, paths);
233230
diff_setup_done(&diff_opts);
234231
diff_tree(t1, t2, base, &diff_opts);
235232
diffcore_std(&diff_opts);
@@ -247,14 +244,17 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
247244
*/
248245
if ((p->status == 'R' || p->status == 'C') &&
249246
!strcmp(p->two->path, opt->pathspec.raw[0])) {
247+
const char *path[2];
248+
250249
/* Switch the file-pairs around */
251250
q->queue[i] = choice;
252251
choice = p;
253252

254253
/* Update the path we use from now on.. */
254+
path[0] = p->one->path;
255+
path[1] = NULL;
255256
free_pathspec(&opt->pathspec);
256-
opt->pathspec.raw[0] = xstrdup(p->one->path);
257-
init_pathspec(&opt->pathspec, opt->pathspec.raw);
257+
parse_pathspec(&opt->pathspec, PATHSPEC_ALL_MAGIC, 0, "", path);
258258

259259
/*
260260
* The caller expects us to return a set of vanilla

0 commit comments

Comments
 (0)