- if (entries < 0) {
- perror("read_cache");
- exit(1);
- }
-
- for (i = 0; i < entries; i++) {
- struct stat st;
- unsigned int oldmode, newmode;
- struct cache_entry *ce = active_cache[i];
- int changed;
-
- if (!ce_path_match(ce, pathspec))
- continue;
-
- if (ce_stage(ce)) {
- show_unmerge(ce->name);
- while (i < entries) {
- struct cache_entry *nce = active_cache[i];
-
- if (strcmp(ce->name, nce->name))
- break;
- /* diff against the proper unmerged stage */
- if (ce_stage(nce) == diff_unmerged_stage)
- ce = nce;
- i++;
- }
- /*
- * Compensate for loop update
- */
- i--;
- /*
- * Show the diff for the 'ce' if we found the one
- * from the desired stage.
- */
- if (ce_stage(ce) != diff_unmerged_stage)
- continue;
- }
-
- if (lstat(ce->name, &st) < 0) {
- if (errno != ENOENT && errno != ENOTDIR) {
- perror(ce->name);
- continue;
- }
- if (silent)
- continue;
- show_file('-', ce);
- continue;
- }
- changed = ce_match_stat(ce, &st);
- if (!changed && !diff_options.find_copies_harder)
- continue;
- oldmode = ntohl(ce->ce_mode);
-
- newmode = DIFF_FILE_CANON_MODE(st.st_mode);
- if (!trust_executable_bit &&
- S_ISREG(newmode) && S_ISREG(oldmode) &&
- ((newmode ^ oldmode) == 0111))
- newmode = oldmode;
- show_modified(oldmode, newmode,
- ce->sha1, (changed ? null_sha1 : ce->sha1),
- ce->name);
- }
- diffcore_std(&diff_options);
- diff_flush(&diff_options);
- return 0;