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>
Nguyễn Thái Ngọc Duy committed
Jul 14, 2013 at 15:35 UTC
17ddc66e702a82671744d1dc5ee59272bd220da6
4 files changed
+19
-18
builtin/checkout.c
+1
-1
@@ -304,7 +304,7 @@ static int checkout_paths(const struct checkout_opts *opts,
304
ce->ce_flags |= CE_MATCHED;
305
}
306
307
- if (report_path_error(ps_matched, opts->pathspec.raw, opts->prefix)) {
307
+ if (report_path_error(ps_matched, &opts->pathspec, opts->prefix)) {
308
free(ps_matched);
309
return 1;
310
}
builtin/commit.c
+6
-8
@@ -188,20 +188,18 @@ static int commit_index_files(void)
188
* and return the paths that match the given pattern in list.
189
*/
190
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)
192
{
193
int i;
194
char *m;
195
196
- if (!pattern)
196
+ if (!pattern->nr)
197
return 0;
198
199
- for (i = 0; pattern[i]; i++)
200
- ;
201
- m = xcalloc(1, i);
199
+ m = xcalloc(1, pattern->nr);
200
201
if (with_tree) {
204
- char *max_prefix = common_prefix(pattern);
202
+ char *max_prefix = common_prefix(pattern->raw);
203
overlay_tree_on_cache(with_tree, max_prefix ? max_prefix : prefix);
204
free(max_prefix);
205
}
@@ -212,7 +210,7 @@ static int list_paths(struct string_list *list, const char *with_tree,
210
211
if (ce->ce_flags & CE_UPDATE)
212
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))
214
continue;
215
item = string_list_insert(list, ce->name);
216
if (ce_skip_worktree(ce))
@@ -402,7 +400,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
400
401
memset(&partial, 0, sizeof(partial));
402
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))
404
exit(1);
405
406
discard_cache();
builtin/ls-files.c
+11
-8
@@ -346,15 +346,16 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
346
}
347
}
348
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)
352
{
353
/*
354
* Make sure all pathspec matched; otherwise it is an error.
355
*/
356
struct strbuf sb = STRBUF_INIT;
355
- const char *name;
357
int num, errors = 0;
357
- for (num = 0; pathspec[num]; num++) {
358
+ for (num = 0; num < pathspec->nr; num++) {
359
int other, found_dup;
360
361
if (ps_matched[num])
@@ -362,13 +363,16 @@ int report_path_error(const char *ps_matched, const char **pathspec, const char
363
/*
364
* The caller might have fed identical pathspec
365
* twice. Do not barf on such a mistake.
366
+ * FIXME: parse_pathspec should have eliminated
367
+ * duplicate pathspec.
368
*/
369
for (found_dup = other = 0;
367
- !found_dup && pathspec[other];
370
+ !found_dup && other < pathspec->nr;
371
other++) {
372
if (other == num || !ps_matched[other])
373
continue;
371
- if (!strcmp(pathspec[other], pathspec[num]))
374
+ if (!strcmp(pathspec->items[other].original,
375
+ pathspec->items[num].original))
376
/*
377
* Ok, we have a match already.
378
*/
@@ -377,9 +381,8 @@ int report_path_error(const char *ps_matched, const char **pathspec, const char
381
if (found_dup)
382
continue;
383
380
- name = quote_path_relative(pathspec[num], -1, &sb, prefix);
384
error("pathspec '%s' did not match any file(s) known to git.",
382
- name);
385
+ pathspec->items[num].original);
386
errors++;
387
}
388
strbuf_release(&sb);
@@ -575,7 +578,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
578
579
if (ps_matched) {
580
int bad;
578
- bad = report_path_error(ps_matched, pathspec.raw, prefix);
581
+ bad = report_path_error(ps_matched, &pathspec, prefix);
582
if (bad)
583
fprintf(stderr, "Did you forget to 'git add'?\n");
584
cache.h
+1
-1
@@ -1312,7 +1312,7 @@ extern int ws_blank_line(const char *line, int len, unsigned ws_rule);
1312
#define ws_tab_width(rule) ((rule) & WS_TAB_WIDTH_MASK)
1313
1314
/* 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);
1316
void overlay_tree_on_cache(const char *tree_name, const char *prefix);
1317
1318
char *alias_lookup(const char *alias);