- /*
- * No entries in the cache (with this base)?
- * Output the tree contents.
- */
- if (!entries || ce_namelen(ce = *ac) < baselen || memcmp(ce->name, base, baselen)) {
- if (!size)
- return entries;
- sha1 = extract(tree, size, &path, &mode);
- show_file("-", path, mode, sha1, base);
- update_tree_entry(&tree, &size);
- continue;
+ switch (ce_stage(ce)) {
+ case 0:
+ /* No stage 1 entry? That means it's a new file */
+ if (!same) {
+ show_new_file(ce);
+ break;
+ }
+ /* Show difference between old and new */
+ show_modified(ac[1], ce, 1);
+ break;
+ case 1:
+ /* No stage 3 (merge) entry? That means it's been deleted */
+ if (!same) {
+ show_file("-", ce, ce->sha1, ce->ce_mode);
+ break;
+ }
+ /* We come here with ce pointing at stage 1
+ * (original tree) and ac[1] pointing at stage
+ * 3 (unmerged). show-modified with
+ * report-mising set to false does not say the
+ * file is deleted but reports true if work
+ * tree does not have it, in which case we
+ * fall through to report the unmerged state.
+ * Otherwise, we show the differences between
+ * the original tree and the work tree.
+ */
+ if (!cached_only && !show_modified(ce, ac[1], 0))
+ break;
+ /* fallthru */
+ case 3:
+ diff_unmerge(ce->name);
+ break;
+
+ default:
+ die("impossible cache entry stage");