2 * Copyright (C) 2005 Junio C Hamano
15 int run_diff_files(struct rev_info *revs, int silent_on_removed)
18 int diff_unmerged_stage = revs->max_count;
20 if (diff_unmerged_stage < 0)
21 diff_unmerged_stage = 2;
22 entries = read_cache();
27 for (i = 0; i < entries; i++) {
29 unsigned int oldmode, newmode;
30 struct cache_entry *ce = active_cache[i];
33 if (!ce_path_match(ce, revs->prune_data))
38 struct combine_diff_path p;
39 struct combine_diff_parent filler[5];
41 int num_compare_stages = 0;
43 combine.p.next = NULL;
44 combine.p.len = ce_namelen(ce);
45 combine.p.path = xmalloc(combine.p.len + 1);
46 memcpy(combine.p.path, ce->name, combine.p.len);
47 combine.p.path[combine.p.len] = 0;
49 memset(combine.p.sha1, 0, 20);
50 memset(&combine.p.parent[0], 0,
51 sizeof(combine.filler));
54 struct cache_entry *nce = active_cache[i];
57 if (strcmp(ce->name, nce->name))
60 /* Stage #2 (ours) is the first parent,
61 * stage #3 (theirs) is the second.
63 stage = ce_stage(nce);
65 int mode = ntohl(nce->ce_mode);
67 memcpy(combine.p.parent[stage-2].sha1,
69 combine.p.parent[stage-2].mode =
71 combine.p.parent[stage-2].status =
75 /* diff against the proper unmerged stage */
76 if (stage == diff_unmerged_stage)
81 * Compensate for loop update
85 if (revs->combine_merges && num_compare_stages == 2) {
86 show_combined_diff(&combine.p, 2,
87 revs->dense_combined_merges,
95 * Show the diff for the 'ce' if we found the one
96 * from the desired stage.
98 diff_unmerge(&revs->diffopt, ce->name);
99 if (ce_stage(ce) != diff_unmerged_stage)
103 if (lstat(ce->name, &st) < 0) {
104 if (errno != ENOENT && errno != ENOTDIR) {
108 if (silent_on_removed)
110 diff_addremove(&revs->diffopt, '-', ntohl(ce->ce_mode),
111 ce->sha1, ce->name, NULL);
114 changed = ce_match_stat(ce, &st, 0);
115 if (!changed && !revs->diffopt.find_copies_harder)
117 oldmode = ntohl(ce->ce_mode);
119 newmode = canon_mode(st.st_mode);
120 if (!trust_executable_bit &&
121 S_ISREG(newmode) && S_ISREG(oldmode) &&
122 ((newmode ^ oldmode) == 0111))
124 diff_change(&revs->diffopt, oldmode, newmode,
125 ce->sha1, (changed ? null_sha1 : ce->sha1),
129 diffcore_std(&revs->diffopt);
130 diff_flush(&revs->diffopt);