9
#include "quote.h"
10
#include "dir.h"
11
#include "builtin.h"
12
+#include "tree.h"
13
14
static int abbrev;
15
static int show_deleted;
27
static const char **pathspec;
28
static int error_unmatch;
29
static char *ps_matched;
30
+static const char *with_tree;
31
32
static const char *tag_cached = "";
33
static const char *tag_unmerged = "";
249
continue;
250
if (show_unmerged && !ce_stage(ce))
251
continue;
252
+ if (ce->ce_flags & htons(CE_UPDATE))
253
+ continue;
254
show_ce_entry(ce_stage(ce) ? tag_unmerged : tag_cached, ce);
255
}
256
}
336
return real_prefix;
337
}
338
339
+/*
340
+ * Read the tree specified with --with-tree option
341
+ * (typically, HEAD) into stage #1 and then
342
+ * squash them down to stage #0. This is used for
343
+ * --error-unmatch to list and check the path patterns
344
+ * that were given from the command line. We are not
345
+ * going to write this index out.
346
+ */
347
+static void overlay_tree(const char *tree_name, const char *prefix)
348
+{
349
+ struct tree *tree;
350
+ unsigned char sha1[20];
351
+ const char **match;
352
+ struct cache_entry *last_stage0 = NULL;
353
+ int i;
354
+
355
+ if (get_sha1(tree_name, sha1))
356
+ die("tree-ish %s not found.", tree_name);
357
+ tree = parse_tree_indirect(sha1);
358
+ if (!tree)
359
+ die("bad tree-ish %s", tree_name);
360
+
361
+ /* Hoist the unmerged entries up to stage #3 to make room */
362
+ for (i = 0; i < active_nr; i++) {
363
+ struct cache_entry *ce = active_cache[i];
364
+ if (!ce_stage(ce))
365
+ continue;
366
+ ce->ce_flags |= htons(CE_STAGEMASK);
367
+ }
368
+
369
+ if (prefix) {
370
+ static const char *(matchbuf[2]);
371
+ matchbuf[0] = prefix;
372
+ matchbuf [1] = NULL;
373
+ match = matchbuf;
374
+ } else
375
+ match = NULL;
376
+ if (read_tree(tree, 1, match))
377
+ die("unable to read tree entries %s", tree_name);
378
+
379
+ for (i = 0; i < active_nr; i++) {
380
+ struct cache_entry *ce = active_cache[i];
381
+ switch (ce_stage(ce)) {
382
+ case 0:
383
+ last_stage0 = ce;
384
+ /* fallthru */
385
+ default:
386
+ continue;
387
+ case 1:
388
+ /*
389
+ * If there is stage #0 entry for this, we do not
390
+ * need to show it. We use CE_UPDATE bit to mark
391
+ * such an entry.
392
+ */
393
+ if (last_stage0 &&
394
+ !strcmp(last_stage0->name, ce->name))
395
+ ce->ce_flags |= htons(CE_UPDATE);
396
+ }
397
+ }
398
+}
399
+
400
static const char ls_files_usage[] =
401
"git-ls-files [-z] [-t] [-v] (--[cached|deleted|others|stage|unmerged|killed|modified])* "
402
"[ --ignored ] [--exclude=<pattern>] [--exclude-from=<file>] "
517
error_unmatch = 1;
518
continue;
519
}
520
+ if (!prefixcmp(arg, "--with-tree=")) {
521
+ with_tree = arg + 12;
522
+ continue;
523
+ }
524
if (!prefixcmp(arg, "--abbrev=")) {
525
abbrev = strtoul(arg+9, NULL, 10);
526
if (abbrev && abbrev < MINIMUM_ABBREV)
572
read_cache();
573
if (prefix)
574
prune_cache(prefix);
575
+ if (with_tree) {
576
+ /*
577
+ * Basic sanity check; show-stages and show-unmerged
578
+ * would not make any sense with this option.
579
+ */
580
+ if (show_stage || show_unmerged)
581
+ die("ls-files --with-tree is incompatible with -s or -u");
582
+ overlay_tree(with_tree, prefix);
583
+ }
584
show_files(&dir, prefix);
585
586
if (ps_matched) {