28
27
static const char **pathspec;
29
28
static int error_unmatch;
30
29
static char *ps_matched;
30
static const char *with_tree;
32
32
static const char *tag_cached = "";
33
33
static const char *tag_unmerged = "";
91
91
static void show_other_files(struct dir_struct *dir)
97
* Skip matching and unmerged entries for the paths,
98
* since we want just "others".
100
* (Matching entries are normally pruned during
101
* the directory tree walk, but will show up for
102
* gitlinks because we don't necessarily have
103
* dir->show_other_directories set to suppress
94
106
for (i = 0; i < dir->nr; i++) {
95
/* We should not have a matching entry, but we
96
* may have an unmerged entry for this path.
98
107
struct dir_entry *ent = dir->entries[i];
99
int pos = cache_name_pos(ent->name, ent->len);
100
109
struct cache_entry *ce;
112
* Remove the '/' at the end that directory
113
* walking adds for directory entries.
116
if (len && ent->name[len-1] == '/')
118
pos = cache_name_pos(ent->name, len);
102
die("bug in show-other-files");
120
continue; /* exact match */
104
if (pos < active_nr) {
122
if (pos < active_nr) {
105
123
ce = active_cache[pos];
106
if (ce_namelen(ce) == ent->len &&
107
!memcmp(ce->name, ent->name, ent->len))
124
if (ce_namelen(ce) == len &&
125
!memcmp(ce->name, ent->name, len))
108
126
continue; /* Yup, this one exists unmerged */
110
128
show_dir_entry(tag_other, ent);
220
238
path = base = prefix;
221
read_directory(dir, path, base, baselen);
239
read_directory(dir, path, base, baselen, pathspec);
223
241
show_other_files(dir);
316
337
return real_prefix;
341
* Read the tree specified with --with-tree option
342
* (typically, HEAD) into stage #1 and then
343
* squash them down to stage #0. This is used for
344
* --error-unmatch to list and check the path patterns
345
* that were given from the command line. We are not
346
* going to write this index out.
348
static void overlay_tree(const char *tree_name, const char *prefix)
351
unsigned char sha1[20];
353
struct cache_entry *last_stage0 = NULL;
356
if (get_sha1(tree_name, sha1))
357
die("tree-ish %s not found.", tree_name);
358
tree = parse_tree_indirect(sha1);
360
die("bad tree-ish %s", tree_name);
362
/* Hoist the unmerged entries up to stage #3 to make room */
363
for (i = 0; i < active_nr; i++) {
364
struct cache_entry *ce = active_cache[i];
367
ce->ce_flags |= htons(CE_STAGEMASK);
371
static const char *(matchbuf[2]);
372
matchbuf[0] = prefix;
377
if (read_tree(tree, 1, match))
378
die("unable to read tree entries %s", tree_name);
380
for (i = 0; i < active_nr; i++) {
381
struct cache_entry *ce = active_cache[i];
382
switch (ce_stage(ce)) {
390
* If there is stage #0 entry for this, we do not
391
* need to show it. We use CE_UPDATE bit to mark
395
!strcmp(last_stage0->name, ce->name))
396
ce->ce_flags |= htons(CE_UPDATE);
319
401
static const char ls_files_usage[] =
320
402
"git-ls-files [-z] [-t] [-v] (--[cached|deleted|others|stage|unmerged|killed|modified])* "
321
403
"[ --ignored ] [--exclude=<pattern>] [--exclude-from=<file>] "
325
407
int cmd_ls_files(int argc, const char **argv, const char *prefix)
410
int exc_given = 0, require_work_tree = 0;
329
411
struct dir_struct dir;
331
413
memset(&dir, 0, sizeof(dir));
366
448
if (!strcmp(arg, "-m") || !strcmp(arg, "--modified")) {
367
449
show_modified = 1;
450
require_work_tree = 1;
370
453
if (!strcmp(arg, "-o") || !strcmp(arg, "--others")) {
455
require_work_tree = 1;
374
458
if (!strcmp(arg, "-i") || !strcmp(arg, "--ignored")) {
375
459
dir.show_ignored = 1;
460
require_work_tree = 1;
378
463
if (!strcmp(arg, "-s") || !strcmp(arg, "--stage")) {
404
490
add_exclude(argv[++i], "", 0, &dir.exclude_list[EXC_CMDL]);
407
if (!strncmp(arg, "--exclude=", 10)) {
493
if (!prefixcmp(arg, "--exclude=")) {
409
495
add_exclude(arg+10, "", 0, &dir.exclude_list[EXC_CMDL]);
414
500
add_excludes_from_file(&dir, argv[++i]);
417
if (!strncmp(arg, "--exclude-from=", 15)) {
503
if (!prefixcmp(arg, "--exclude-from=")) {
419
505
add_excludes_from_file(&dir, arg+15);
422
if (!strncmp(arg, "--exclude-per-directory=", 24)) {
508
if (!prefixcmp(arg, "--exclude-per-directory=")) {
424
510
dir.exclude_per_dir = arg + 24;
432
518
error_unmatch = 1;
435
if (!strncmp(arg, "--abbrev=", 9)) {
521
if (!prefixcmp(arg, "--with-tree=")) {
522
with_tree = arg + 12;
525
if (!prefixcmp(arg, "--abbrev=")) {
436
526
abbrev = strtoul(arg+9, NULL, 10);
437
527
if (abbrev && abbrev < MINIMUM_ABBREV)
438
528
abbrev = MINIMUM_ABBREV;
542
if (require_work_tree && !is_inside_work_tree()) {
543
const char *work_tree = get_git_work_tree();
544
if (!work_tree || chdir(work_tree))
545
die("This operation must be run in a work tree");
452
548
pathspec = get_pathspec(prefix, argv + i);
454
550
/* Verify that the pathspec matches the prefix */
479
575
prune_cache(prefix);
578
* Basic sanity check; show-stages and show-unmerged
579
* would not make any sense with this option.
581
if (show_stage || show_unmerged)
582
die("ls-files --with-tree is incompatible with -s or -u");
583
overlay_tree(with_tree, prefix);
480
585
show_files(&dir, prefix);
482
587
if (ps_matched) {
486
591
int num, errors = 0;
487
592
for (num = 0; pathspec[num]; num++) {
593
int other, found_dup;
488
595
if (ps_matched[num])
490
error("pathspec '%s' did not match any.",
598
* The caller might have fed identical pathspec
599
* twice. Do not barf on such a mistake.
601
for (found_dup = other = 0;
602
!found_dup && pathspec[other];
604
if (other == num || !ps_matched[other])
606
if (!strcmp(pathspec[other], pathspec[num]))
608
* Ok, we have a match already.
615
error("pathspec '%s' did not match any file(s) known to git.",
491
616
pathspec[num] + prefix_offset);
621
fprintf(stderr, "Did you forget to 'git add'?\n");
494
623
return errors ? 1 : 0;