Skip to content

Commit 17ddc66

Browse files
pcloudsgitster
authored andcommitted
convert report_path_error 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 18e4f40 commit 17ddc66

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

builtin/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ static int checkout_paths(const struct checkout_opts *opts,
304304
ce->ce_flags |= CE_MATCHED;
305305
}
306306

307-
if (report_path_error(ps_matched, opts->pathspec.raw, opts->prefix)) {
307+
if (report_path_error(ps_matched, &opts->pathspec, opts->prefix)) {
308308
free(ps_matched);
309309
return 1;
310310
}

builtin/commit.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,20 +188,18 @@ static int commit_index_files(void)
188188
* and return the paths that match the given pattern in list.
189189
*/
190190
static int list_paths(struct string_list *list, const char *with_tree,
191-
const char *prefix, const char **pattern)
191+
const char *prefix, const struct pathspec *pattern)
192192
{
193193
int i;
194194
char *m;
195195

196-
if (!pattern)
196+
if (!pattern->nr)
197197
return 0;
198198

199-
for (i = 0; pattern[i]; i++)
200-
;
201-
m = xcalloc(1, i);
199+
m = xcalloc(1, pattern->nr);
202200

203201
if (with_tree) {
204-
char *max_prefix = common_prefix(pattern);
202+
char *max_prefix = common_prefix(pattern->raw);
205203
overlay_tree_on_cache(with_tree, max_prefix ? max_prefix : prefix);
206204
free(max_prefix);
207205
}
@@ -212,7 +210,7 @@ static int list_paths(struct string_list *list, const char *with_tree,
212210

213211
if (ce->ce_flags & CE_UPDATE)
214212
continue;
215-
if (!match_pathspec(pattern, ce->name, ce_namelen(ce), 0, m))
213+
if (!match_pathspec_depth(pattern, ce->name, ce_namelen(ce), 0, m))
216214
continue;
217215
item = string_list_insert(list, ce->name);
218216
if (ce_skip_worktree(ce))
@@ -402,7 +400,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
402400

403401
memset(&partial, 0, sizeof(partial));
404402
partial.strdup_strings = 1;
405-
if (list_paths(&partial, !current_head ? NULL : "HEAD", prefix, pathspec.raw))
403+
if (list_paths(&partial, !current_head ? NULL : "HEAD", prefix, &pathspec))
406404
exit(1);
407405

408406
discard_cache();

builtin/ls-files.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,29 +346,33 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
346346
}
347347
}
348348

349-
int report_path_error(const char *ps_matched, const char **pathspec, const char *prefix)
349+
int report_path_error(const char *ps_matched,
350+
const struct pathspec *pathspec,
351+
const char *prefix)
350352
{
351353
/*
352354
* Make sure all pathspec matched; otherwise it is an error.
353355
*/
354356
struct strbuf sb = STRBUF_INIT;
355-
const char *name;
356357
int num, errors = 0;
357-
for (num = 0; pathspec[num]; num++) {
358+
for (num = 0; num < pathspec->nr; num++) {
358359
int other, found_dup;
359360

360361
if (ps_matched[num])
361362
continue;
362363
/*
363364
* The caller might have fed identical pathspec
364365
* twice. Do not barf on such a mistake.
366+
* FIXME: parse_pathspec should have eliminated
367+
* duplicate pathspec.
365368
*/
366369
for (found_dup = other = 0;
367-
!found_dup && pathspec[other];
370+
!found_dup && other < pathspec->nr;
368371
other++) {
369372
if (other == num || !ps_matched[other])
370373
continue;
371-
if (!strcmp(pathspec[other], pathspec[num]))
374+
if (!strcmp(pathspec->items[other].original,
375+
pathspec->items[num].original))
372376
/*
373377
* Ok, we have a match already.
374378
*/
@@ -377,9 +381,8 @@ int report_path_error(const char *ps_matched, const char **pathspec, const char
377381
if (found_dup)
378382
continue;
379383

380-
name = quote_path_relative(pathspec[num], -1, &sb, prefix);
381384
error("pathspec '%s' did not match any file(s) known to git.",
382-
name);
385+
pathspec->items[num].original);
383386
errors++;
384387
}
385388
strbuf_release(&sb);
@@ -575,7 +578,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
575578

576579
if (ps_matched) {
577580
int bad;
578-
bad = report_path_error(ps_matched, pathspec.raw, prefix);
581+
bad = report_path_error(ps_matched, &pathspec, prefix);
579582
if (bad)
580583
fprintf(stderr, "Did you forget to 'git add'?\n");
581584

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,7 +1312,7 @@ extern int ws_blank_line(const char *line, int len, unsigned ws_rule);
13121312
#define ws_tab_width(rule) ((rule) & WS_TAB_WIDTH_MASK)
13131313

13141314
/* ls-files */
1315-
int report_path_error(const char *ps_matched, const char **pathspec, const char *prefix);
1315+
int report_path_error(const char *ps_matched, const struct pathspec *pathspec, const char *prefix);
13161316
void overlay_tree_on_cache(const char *tree_name, const char *prefix);
13171317

13181318
char *alias_lookup(const char *alias);

0 commit comments

Comments
 (0)