Merge branch 'ja/i18n-similar-messages'
[git/debian.git] / builtin / ls-files.c
blobf7ea56cc63820b27efe7bec00ab9ac8660e06766
1 /*
2 * This merges the file listing in the directory cache index
3 * with the actual working directory list, and shows different
4 * combinations of the two.
6 * Copyright (C) Linus Torvalds, 2005
7 */
8 #include "cache.h"
9 #include "repository.h"
10 #include "config.h"
11 #include "quote.h"
12 #include "dir.h"
13 #include "builtin.h"
14 #include "tree.h"
15 #include "cache-tree.h"
16 #include "parse-options.h"
17 #include "resolve-undo.h"
18 #include "string-list.h"
19 #include "pathspec.h"
20 #include "run-command.h"
21 #include "submodule.h"
22 #include "submodule-config.h"
24 static int abbrev;
25 static int show_deleted;
26 static int show_cached;
27 static int show_others;
28 static int show_stage;
29 static int show_unmerged;
30 static int show_resolve_undo;
31 static int show_modified;
32 static int show_killed;
33 static int show_valid_bit;
34 static int show_fsmonitor_bit;
35 static int line_terminator = '\n';
36 static int debug_mode;
37 static int show_eol;
38 static int recurse_submodules;
39 static int skipping_duplicates;
40 static int show_sparse_dirs;
42 static const char *prefix;
43 static int max_prefix_len;
44 static int prefix_len;
45 static struct pathspec pathspec;
46 static int error_unmatch;
47 static char *ps_matched;
48 static const char *with_tree;
49 static int exc_given;
50 static int exclude_args;
52 static const char *tag_cached = "";
53 static const char *tag_unmerged = "";
54 static const char *tag_removed = "";
55 static const char *tag_other = "";
56 static const char *tag_killed = "";
57 static const char *tag_modified = "";
58 static const char *tag_skip_worktree = "";
59 static const char *tag_resolve_undo = "";
61 static void write_eolinfo(struct index_state *istate,
62 const struct cache_entry *ce, const char *path)
64 if (show_eol) {
65 struct stat st;
66 const char *i_txt = "";
67 const char *w_txt = "";
68 const char *a_txt = get_convert_attr_ascii(istate, path);
69 if (ce && S_ISREG(ce->ce_mode))
70 i_txt = get_cached_convert_stats_ascii(istate,
71 ce->name);
72 if (!lstat(path, &st) && S_ISREG(st.st_mode))
73 w_txt = get_wt_convert_stats_ascii(path);
74 printf("i/%-5s w/%-5s attr/%-17s\t", i_txt, w_txt, a_txt);
78 static void write_name(const char *name)
81 * With "--full-name", prefix_len=0; this caller needs to pass
82 * an empty string in that case (a NULL is good for "").
84 write_name_quoted_relative(name, prefix_len ? prefix : NULL,
85 stdout, line_terminator);
88 static const char *get_tag(const struct cache_entry *ce, const char *tag)
90 static char alttag[4];
92 if (tag && *tag && ((show_valid_bit && (ce->ce_flags & CE_VALID)) ||
93 (show_fsmonitor_bit && (ce->ce_flags & CE_FSMONITOR_VALID)))) {
94 memcpy(alttag, tag, 3);
96 if (isalpha(tag[0])) {
97 alttag[0] = tolower(tag[0]);
98 } else if (tag[0] == '?') {
99 alttag[0] = '!';
100 } else {
101 alttag[0] = 'v';
102 alttag[1] = tag[0];
103 alttag[2] = ' ';
104 alttag[3] = 0;
107 tag = alttag;
110 return tag;
113 static void print_debug(const struct cache_entry *ce)
115 if (debug_mode) {
116 const struct stat_data *sd = &ce->ce_stat_data;
118 printf(" ctime: %u:%u\n", sd->sd_ctime.sec, sd->sd_ctime.nsec);
119 printf(" mtime: %u:%u\n", sd->sd_mtime.sec, sd->sd_mtime.nsec);
120 printf(" dev: %u\tino: %u\n", sd->sd_dev, sd->sd_ino);
121 printf(" uid: %u\tgid: %u\n", sd->sd_uid, sd->sd_gid);
122 printf(" size: %u\tflags: %x\n", sd->sd_size, ce->ce_flags);
126 static void show_dir_entry(struct index_state *istate,
127 const char *tag, struct dir_entry *ent)
129 int len = max_prefix_len;
131 if (len > ent->len)
132 die("git ls-files: internal error - directory entry not superset of prefix");
134 /* If ps_matches is non-NULL, figure out which pathspec(s) match. */
135 if (ps_matched)
136 dir_path_match(istate, ent, &pathspec, len, ps_matched);
138 fputs(tag, stdout);
139 write_eolinfo(istate, NULL, ent->name);
140 write_name(ent->name);
143 static void show_other_files(struct index_state *istate,
144 const struct dir_struct *dir)
146 int i;
148 for (i = 0; i < dir->nr; i++) {
149 struct dir_entry *ent = dir->entries[i];
150 if (!index_name_is_other(istate, ent->name, ent->len))
151 continue;
152 show_dir_entry(istate, tag_other, ent);
156 static void show_killed_files(struct index_state *istate,
157 const struct dir_struct *dir)
159 int i;
160 for (i = 0; i < dir->nr; i++) {
161 struct dir_entry *ent = dir->entries[i];
162 char *cp, *sp;
163 int pos, len, killed = 0;
165 for (cp = ent->name; cp - ent->name < ent->len; cp = sp + 1) {
166 sp = strchr(cp, '/');
167 if (!sp) {
168 /* If ent->name is prefix of an entry in the
169 * cache, it will be killed.
171 pos = index_name_pos(istate, ent->name, ent->len);
172 if (0 <= pos)
173 BUG("killed-file %.*s not found",
174 ent->len, ent->name);
175 pos = -pos - 1;
176 while (pos < istate->cache_nr &&
177 ce_stage(istate->cache[pos]))
178 pos++; /* skip unmerged */
179 if (istate->cache_nr <= pos)
180 break;
181 /* pos points at a name immediately after
182 * ent->name in the cache. Does it expect
183 * ent->name to be a directory?
185 len = ce_namelen(istate->cache[pos]);
186 if ((ent->len < len) &&
187 !strncmp(istate->cache[pos]->name,
188 ent->name, ent->len) &&
189 istate->cache[pos]->name[ent->len] == '/')
190 killed = 1;
191 break;
193 if (0 <= index_name_pos(istate, ent->name, sp - ent->name)) {
194 /* If any of the leading directories in
195 * ent->name is registered in the cache,
196 * ent->name will be killed.
198 killed = 1;
199 break;
202 if (killed)
203 show_dir_entry(istate, tag_killed, dir->entries[i]);
207 static void show_files(struct repository *repo, struct dir_struct *dir);
209 static void show_submodule(struct repository *superproject,
210 struct dir_struct *dir, const char *path)
212 struct repository subrepo;
214 if (repo_submodule_init(&subrepo, superproject, path, null_oid()))
215 return;
217 if (repo_read_index(&subrepo) < 0)
218 die("index file corrupt");
220 show_files(&subrepo, dir);
222 repo_clear(&subrepo);
225 static void show_ce(struct repository *repo, struct dir_struct *dir,
226 const struct cache_entry *ce, const char *fullname,
227 const char *tag)
229 if (max_prefix_len > strlen(fullname))
230 die("git ls-files: internal error - cache entry not superset of prefix");
232 if (recurse_submodules && S_ISGITLINK(ce->ce_mode) &&
233 is_submodule_active(repo, ce->name)) {
234 show_submodule(repo, dir, ce->name);
235 } else if (match_pathspec(repo->index, &pathspec, fullname, strlen(fullname),
236 max_prefix_len, ps_matched,
237 S_ISDIR(ce->ce_mode) ||
238 S_ISGITLINK(ce->ce_mode))) {
239 tag = get_tag(ce, tag);
241 if (!show_stage) {
242 fputs(tag, stdout);
243 } else {
244 printf("%s%06o %s %d\t",
245 tag,
246 ce->ce_mode,
247 find_unique_abbrev(&ce->oid, abbrev),
248 ce_stage(ce));
250 write_eolinfo(repo->index, ce, fullname);
251 write_name(fullname);
252 print_debug(ce);
256 static void show_ru_info(struct index_state *istate)
258 struct string_list_item *item;
260 if (!istate->resolve_undo)
261 return;
263 for_each_string_list_item(item, istate->resolve_undo) {
264 const char *path = item->string;
265 struct resolve_undo_info *ui = item->util;
266 int i, len;
268 len = strlen(path);
269 if (len < max_prefix_len)
270 continue; /* outside of the prefix */
271 if (!match_pathspec(istate, &pathspec, path, len,
272 max_prefix_len, ps_matched, 0))
273 continue; /* uninterested */
274 for (i = 0; i < 3; i++) {
275 if (!ui->mode[i])
276 continue;
277 printf("%s%06o %s %d\t", tag_resolve_undo, ui->mode[i],
278 find_unique_abbrev(&ui->oid[i], abbrev),
279 i + 1);
280 write_name(path);
285 static int ce_excluded(struct dir_struct *dir, struct index_state *istate,
286 const char *fullname, const struct cache_entry *ce)
288 int dtype = ce_to_dtype(ce);
289 return is_excluded(dir, istate, fullname, &dtype);
292 static void construct_fullname(struct strbuf *out, const struct repository *repo,
293 const struct cache_entry *ce)
295 strbuf_reset(out);
296 if (repo->submodule_prefix)
297 strbuf_addstr(out, repo->submodule_prefix);
298 strbuf_addstr(out, ce->name);
301 static void show_files(struct repository *repo, struct dir_struct *dir)
303 int i;
304 struct strbuf fullname = STRBUF_INIT;
306 /* For cached/deleted files we don't need to even do the readdir */
307 if (show_others || show_killed) {
308 if (!show_others)
309 dir->flags |= DIR_COLLECT_KILLED_ONLY;
310 fill_directory(dir, repo->index, &pathspec);
311 if (show_others)
312 show_other_files(repo->index, dir);
313 if (show_killed)
314 show_killed_files(repo->index, dir);
317 if (!(show_cached || show_stage || show_deleted || show_modified))
318 return;
320 if (!show_sparse_dirs)
321 ensure_full_index(repo->index);
323 for (i = 0; i < repo->index->cache_nr; i++) {
324 const struct cache_entry *ce = repo->index->cache[i];
325 struct stat st;
326 int stat_err;
328 construct_fullname(&fullname, repo, ce);
330 if ((dir->flags & DIR_SHOW_IGNORED) &&
331 !ce_excluded(dir, repo->index, fullname.buf, ce))
332 continue;
333 if (ce->ce_flags & CE_UPDATE)
334 continue;
335 if ((show_cached || show_stage) &&
336 (!show_unmerged || ce_stage(ce))) {
337 show_ce(repo, dir, ce, fullname.buf,
338 ce_stage(ce) ? tag_unmerged :
339 (ce_skip_worktree(ce) ? tag_skip_worktree :
340 tag_cached));
341 if (skipping_duplicates)
342 goto skip_to_next_name;
345 if (!(show_deleted || show_modified))
346 continue;
347 if (ce_skip_worktree(ce))
348 continue;
349 stat_err = lstat(fullname.buf, &st);
350 if (stat_err && (errno != ENOENT && errno != ENOTDIR))
351 error_errno("cannot lstat '%s'", fullname.buf);
352 if (stat_err && show_deleted) {
353 show_ce(repo, dir, ce, fullname.buf, tag_removed);
354 if (skipping_duplicates)
355 goto skip_to_next_name;
357 if (show_modified &&
358 (stat_err || ie_modified(repo->index, ce, &st, 0))) {
359 show_ce(repo, dir, ce, fullname.buf, tag_modified);
360 if (skipping_duplicates)
361 goto skip_to_next_name;
363 continue;
365 skip_to_next_name:
367 int j;
368 struct cache_entry **cache = repo->index->cache;
369 for (j = i + 1; j < repo->index->cache_nr; j++)
370 if (strcmp(ce->name, cache[j]->name))
371 break;
372 i = j - 1; /* compensate for the for loop */
376 strbuf_release(&fullname);
380 * Prune the index to only contain stuff starting with "prefix"
382 static void prune_index(struct index_state *istate,
383 const char *prefix, size_t prefixlen)
385 int pos;
386 unsigned int first, last;
388 if (!prefix || !istate->cache_nr)
389 return;
390 pos = index_name_pos(istate, prefix, prefixlen);
391 if (pos < 0)
392 pos = -pos-1;
393 first = pos;
394 last = istate->cache_nr;
395 while (last > first) {
396 int next = first + ((last - first) >> 1);
397 const struct cache_entry *ce = istate->cache[next];
398 if (!strncmp(ce->name, prefix, prefixlen)) {
399 first = next+1;
400 continue;
402 last = next;
404 MOVE_ARRAY(istate->cache, istate->cache + pos, last - pos);
405 istate->cache_nr = last - pos;
408 static int get_common_prefix_len(const char *common_prefix)
410 int common_prefix_len;
412 if (!common_prefix)
413 return 0;
415 common_prefix_len = strlen(common_prefix);
418 * If the prefix has a trailing slash, strip it so that submodules wont
419 * be pruned from the index.
421 if (common_prefix[common_prefix_len - 1] == '/')
422 common_prefix_len--;
424 return common_prefix_len;
427 static int read_one_entry_opt(struct index_state *istate,
428 const struct object_id *oid,
429 struct strbuf *base,
430 const char *pathname,
431 unsigned mode, int opt)
433 int len;
434 struct cache_entry *ce;
436 if (S_ISDIR(mode))
437 return READ_TREE_RECURSIVE;
439 len = strlen(pathname);
440 ce = make_empty_cache_entry(istate, base->len + len);
442 ce->ce_mode = create_ce_mode(mode);
443 ce->ce_flags = create_ce_flags(1);
444 ce->ce_namelen = base->len + len;
445 memcpy(ce->name, base->buf, base->len);
446 memcpy(ce->name + base->len, pathname, len+1);
447 oidcpy(&ce->oid, oid);
448 return add_index_entry(istate, ce, opt);
451 static int read_one_entry(const struct object_id *oid, struct strbuf *base,
452 const char *pathname, unsigned mode,
453 void *context)
455 struct index_state *istate = context;
456 return read_one_entry_opt(istate, oid, base, pathname,
457 mode,
458 ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK);
462 * This is used when the caller knows there is no existing entries at
463 * the stage that will conflict with the entry being added.
465 static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base,
466 const char *pathname, unsigned mode,
467 void *context)
469 struct index_state *istate = context;
470 return read_one_entry_opt(istate, oid, base, pathname,
471 mode, ADD_CACHE_JUST_APPEND);
475 * Read the tree specified with --with-tree option
476 * (typically, HEAD) into stage #1 and then
477 * squash them down to stage #0. This is used for
478 * --error-unmatch to list and check the path patterns
479 * that were given from the command line. We are not
480 * going to write this index out.
482 void overlay_tree_on_index(struct index_state *istate,
483 const char *tree_name, const char *prefix)
485 struct tree *tree;
486 struct object_id oid;
487 struct pathspec pathspec;
488 struct cache_entry *last_stage0 = NULL;
489 int i;
490 read_tree_fn_t fn = NULL;
491 int err;
493 if (get_oid(tree_name, &oid))
494 die("tree-ish %s not found.", tree_name);
495 tree = parse_tree_indirect(&oid);
496 if (!tree)
497 die("bad tree-ish %s", tree_name);
499 /* Hoist the unmerged entries up to stage #3 to make room */
500 /* TODO: audit for interaction with sparse-index. */
501 ensure_full_index(istate);
502 for (i = 0; i < istate->cache_nr; i++) {
503 struct cache_entry *ce = istate->cache[i];
504 if (!ce_stage(ce))
505 continue;
506 ce->ce_flags |= CE_STAGEMASK;
509 if (prefix) {
510 static const char *(matchbuf[1]);
511 matchbuf[0] = NULL;
512 parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC,
513 PATHSPEC_PREFER_CWD, prefix, matchbuf);
514 } else
515 memset(&pathspec, 0, sizeof(pathspec));
518 * See if we have cache entry at the stage. If so,
519 * do it the original slow way, otherwise, append and then
520 * sort at the end.
522 for (i = 0; !fn && i < istate->cache_nr; i++) {
523 const struct cache_entry *ce = istate->cache[i];
524 if (ce_stage(ce) == 1)
525 fn = read_one_entry;
528 if (!fn)
529 fn = read_one_entry_quick;
530 err = read_tree(the_repository, tree, &pathspec, fn, istate);
531 if (err)
532 die("unable to read tree entries %s", tree_name);
535 * Sort the cache entry -- we need to nuke the cache tree, though.
537 if (fn == read_one_entry_quick) {
538 cache_tree_free(&istate->cache_tree);
539 QSORT(istate->cache, istate->cache_nr, cmp_cache_name_compare);
542 for (i = 0; i < istate->cache_nr; i++) {
543 struct cache_entry *ce = istate->cache[i];
544 switch (ce_stage(ce)) {
545 case 0:
546 last_stage0 = ce;
547 /* fallthru */
548 default:
549 continue;
550 case 1:
552 * If there is stage #0 entry for this, we do not
553 * need to show it. We use CE_UPDATE bit to mark
554 * such an entry.
556 if (last_stage0 &&
557 !strcmp(last_stage0->name, ce->name))
558 ce->ce_flags |= CE_UPDATE;
563 static const char * const ls_files_usage[] = {
564 N_("git ls-files [<options>] [<file>...]"),
565 NULL
568 static int option_parse_exclude(const struct option *opt,
569 const char *arg, int unset)
571 struct string_list *exclude_list = opt->value;
573 BUG_ON_OPT_NEG(unset);
575 exc_given = 1;
576 string_list_append(exclude_list, arg);
578 return 0;
581 static int option_parse_exclude_from(const struct option *opt,
582 const char *arg, int unset)
584 struct dir_struct *dir = opt->value;
586 BUG_ON_OPT_NEG(unset);
588 exc_given = 1;
589 add_patterns_from_file(dir, arg);
591 return 0;
594 static int option_parse_exclude_standard(const struct option *opt,
595 const char *arg, int unset)
597 struct dir_struct *dir = opt->value;
599 BUG_ON_OPT_NEG(unset);
600 BUG_ON_OPT_ARG(arg);
602 exc_given = 1;
603 setup_standard_excludes(dir);
605 return 0;
608 int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
610 int require_work_tree = 0, show_tag = 0, i;
611 char *max_prefix;
612 struct dir_struct dir = DIR_INIT;
613 struct pattern_list *pl;
614 struct string_list exclude_list = STRING_LIST_INIT_NODUP;
615 struct option builtin_ls_files_options[] = {
616 /* Think twice before adding "--nul" synonym to this */
617 OPT_SET_INT('z', NULL, &line_terminator,
618 N_("separate paths with the NUL character"), '\0'),
619 OPT_BOOL('t', NULL, &show_tag,
620 N_("identify the file status with tags")),
621 OPT_BOOL('v', NULL, &show_valid_bit,
622 N_("use lowercase letters for 'assume unchanged' files")),
623 OPT_BOOL('f', NULL, &show_fsmonitor_bit,
624 N_("use lowercase letters for 'fsmonitor clean' files")),
625 OPT_BOOL('c', "cached", &show_cached,
626 N_("show cached files in the output (default)")),
627 OPT_BOOL('d', "deleted", &show_deleted,
628 N_("show deleted files in the output")),
629 OPT_BOOL('m', "modified", &show_modified,
630 N_("show modified files in the output")),
631 OPT_BOOL('o', "others", &show_others,
632 N_("show other files in the output")),
633 OPT_BIT('i', "ignored", &dir.flags,
634 N_("show ignored files in the output"),
635 DIR_SHOW_IGNORED),
636 OPT_BOOL('s', "stage", &show_stage,
637 N_("show staged contents' object name in the output")),
638 OPT_BOOL('k', "killed", &show_killed,
639 N_("show files on the filesystem that need to be removed")),
640 OPT_BIT(0, "directory", &dir.flags,
641 N_("show 'other' directories' names only"),
642 DIR_SHOW_OTHER_DIRECTORIES),
643 OPT_BOOL(0, "eol", &show_eol, N_("show line endings of files")),
644 OPT_NEGBIT(0, "empty-directory", &dir.flags,
645 N_("don't show empty directories"),
646 DIR_HIDE_EMPTY_DIRECTORIES),
647 OPT_BOOL('u', "unmerged", &show_unmerged,
648 N_("show unmerged files in the output")),
649 OPT_BOOL(0, "resolve-undo", &show_resolve_undo,
650 N_("show resolve-undo information")),
651 OPT_CALLBACK_F('x', "exclude", &exclude_list, N_("pattern"),
652 N_("skip files matching pattern"),
653 PARSE_OPT_NONEG, option_parse_exclude),
654 OPT_CALLBACK_F('X', "exclude-from", &dir, N_("file"),
655 N_("read exclude patterns from <file>"),
656 PARSE_OPT_NONEG, option_parse_exclude_from),
657 OPT_STRING(0, "exclude-per-directory", &dir.exclude_per_dir, N_("file"),
658 N_("read additional per-directory exclude patterns in <file>")),
659 OPT_CALLBACK_F(0, "exclude-standard", &dir, NULL,
660 N_("add the standard git exclusions"),
661 PARSE_OPT_NOARG | PARSE_OPT_NONEG,
662 option_parse_exclude_standard),
663 OPT_SET_INT_F(0, "full-name", &prefix_len,
664 N_("make the output relative to the project top directory"),
665 0, PARSE_OPT_NONEG),
666 OPT_BOOL(0, "recurse-submodules", &recurse_submodules,
667 N_("recurse through submodules")),
668 OPT_BOOL(0, "error-unmatch", &error_unmatch,
669 N_("if any <file> is not in the index, treat this as an error")),
670 OPT_STRING(0, "with-tree", &with_tree, N_("tree-ish"),
671 N_("pretend that paths removed since <tree-ish> are still present")),
672 OPT__ABBREV(&abbrev),
673 OPT_BOOL(0, "debug", &debug_mode, N_("show debugging data")),
674 OPT_BOOL(0, "deduplicate", &skipping_duplicates,
675 N_("suppress duplicate entries")),
676 OPT_BOOL(0, "sparse", &show_sparse_dirs,
677 N_("show sparse directories in the presence of a sparse index")),
678 OPT_END()
680 int ret = 0;
682 if (argc == 2 && !strcmp(argv[1], "-h"))
683 usage_with_options(ls_files_usage, builtin_ls_files_options);
685 prepare_repo_settings(the_repository);
686 the_repository->settings.command_requires_full_index = 0;
688 prefix = cmd_prefix;
689 if (prefix)
690 prefix_len = strlen(prefix);
691 git_config(git_default_config, NULL);
693 if (repo_read_index(the_repository) < 0)
694 die("index file corrupt");
696 argc = parse_options(argc, argv, prefix, builtin_ls_files_options,
697 ls_files_usage, 0);
698 pl = add_pattern_list(&dir, EXC_CMDL, "--exclude option");
699 for (i = 0; i < exclude_list.nr; i++) {
700 add_pattern(exclude_list.items[i].string, "", 0, pl, --exclude_args);
702 if (show_tag || show_valid_bit || show_fsmonitor_bit) {
703 tag_cached = "H ";
704 tag_unmerged = "M ";
705 tag_removed = "R ";
706 tag_modified = "C ";
707 tag_other = "? ";
708 tag_killed = "K ";
709 tag_skip_worktree = "S ";
710 tag_resolve_undo = "U ";
712 if (show_modified || show_others || show_deleted || (dir.flags & DIR_SHOW_IGNORED) || show_killed)
713 require_work_tree = 1;
714 if (show_unmerged)
716 * There's no point in showing unmerged unless
717 * you also show the stage information.
719 show_stage = 1;
720 if (show_tag || show_stage)
721 skipping_duplicates = 0;
722 if (dir.exclude_per_dir)
723 exc_given = 1;
725 if (require_work_tree && !is_inside_work_tree())
726 setup_work_tree();
728 if (recurse_submodules &&
729 (show_stage || show_deleted || show_others || show_unmerged ||
730 show_killed || show_modified || show_resolve_undo || with_tree))
731 die("ls-files --recurse-submodules unsupported mode");
733 if (recurse_submodules && error_unmatch)
734 die("ls-files --recurse-submodules does not support "
735 "--error-unmatch");
737 parse_pathspec(&pathspec, 0,
738 PATHSPEC_PREFER_CWD,
739 prefix, argv);
742 * Find common prefix for all pathspec's
743 * This is used as a performance optimization which unfortunately cannot
744 * be done when recursing into submodules because when a pathspec is
745 * given which spans repository boundaries you can't simply remove the
746 * submodule entry because the pathspec may match something inside the
747 * submodule.
749 if (recurse_submodules)
750 max_prefix = NULL;
751 else
752 max_prefix = common_prefix(&pathspec);
753 max_prefix_len = get_common_prefix_len(max_prefix);
755 prune_index(the_repository->index, max_prefix, max_prefix_len);
757 /* Treat unmatching pathspec elements as errors */
758 if (pathspec.nr && error_unmatch)
759 ps_matched = xcalloc(pathspec.nr, 1);
761 if ((dir.flags & DIR_SHOW_IGNORED) && !show_others && !show_cached)
762 die("ls-files -i must be used with either -o or -c");
764 if ((dir.flags & DIR_SHOW_IGNORED) && !exc_given)
765 die("ls-files --ignored needs some exclude pattern");
767 /* With no flags, we default to showing the cached files */
768 if (!(show_stage || show_deleted || show_others || show_unmerged ||
769 show_killed || show_modified || show_resolve_undo))
770 show_cached = 1;
772 if (with_tree) {
774 * Basic sanity check; show-stages and show-unmerged
775 * would not make any sense with this option.
777 if (show_stage || show_unmerged)
778 die(_("options '%s' and '%s' cannot be used together"), "ls-files --with-tree", "-s/-u");
779 overlay_tree_on_index(the_repository->index, with_tree, max_prefix);
782 show_files(the_repository, &dir);
784 if (show_resolve_undo)
785 show_ru_info(the_repository->index);
787 if (ps_matched && report_path_error(ps_matched, &pathspec)) {
788 fprintf(stderr, "Did you forget to 'git add'?\n");
789 ret = 1;
792 string_list_clear(&exclude_list, 0);
793 dir_clear(&dir);
794 free(max_prefix);
795 return ret;