Skip to content

Commit 15bf57a

Browse files
author
Junio C Hamano
committed
diff-files: show diffs with stage0 and unmerged stage at the same time.
After thinking about it more, I realized that much of the change I did on top of Linus' version does not make much sense. This commit reverts it so that it by default shows diffs with stage0 paths or stage2 paths with working tree; the unmerged stage to use can be overridden with -1/-2/-3 option (-2 is the default so essentially is a no-op). When the index file is unmerged, we are by definition in the middle of a conflicting merge, and we should show the diff with stage 2 by default. More importantly, paths without conflicts are updated in the working tree and collapsed to stage0 in the index, so showing diff with stage0 at the same time does not hurt. In normal cases, stage0 entries should be in sync with the working tree files and does not clutter the output. It even helps the user to realize that the working tree has local changes unrelated to the merge and remember to be careful not to do a "git-commit -a" after resolving the conflicts. When there is no unmerged entries, giving diff_unmerged_stage a default value of 2 does not cause any harm, because it would not be used anyway. So in all, always showing diff between stage0 paths and unmerged entries from a stage (defaulting to 2) is the right thing to do, as Linus originally did. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 354b9b5 commit 15bf57a

File tree

2 files changed

+5
-23
lines changed

2 files changed

+5
-23
lines changed

Documentation/git-diff-files.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ include::diff-options.txt[]
2626
branch" respectively. With these options, diffs for
2727
merged entries are not shown.
2828
+
29-
The default is to diff against our branch (-2) if there
30-
is an unmerged path, and show diff for unmerged entries
31-
otherwise. The option -0 can be given to force diff for
32-
unmerged entries even when the index is unmerged.
29+
The default is to diff against our branch (-2) and the
30+
cleanly resolved paths. The option -0 can be given to
31+
omit diff output for unmerged entries and just show "Unmerged".
3332

3433
-q::
3534
Remain silent even on nonexisting files

diff-files.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ COMMON_DIFF_OPTIONS_HELP;
1212

1313
static struct diff_options diff_options;
1414
static int silent = 0;
15-
static int diff_unmerged_stage = -1;
15+
static int diff_unmerged_stage = 2;
1616

1717
static void show_unmerge(const char *path)
1818
{
@@ -87,20 +87,6 @@ int main(int argc, const char **argv)
8787
pathspec = get_pathspec(prefix, argv + 1);
8888
entries = read_cache();
8989

90-
if (diff_unmerged_stage < 0) {
91-
/* default to "ours" if unmerged index, otherwise 0 */
92-
for (i = 0; i < entries; i++) {
93-
struct cache_entry *ce = active_cache[i];
94-
if (ce_stage(ce)) {
95-
diff_unmerged_stage = 2;
96-
break;
97-
}
98-
}
99-
if (diff_unmerged_stage < 0)
100-
diff_unmerged_stage = 0;
101-
}
102-
103-
10490
if (diff_setup_done(&diff_options) < 0)
10591
usage(diff_files_usage);
10692

@@ -122,8 +108,7 @@ int main(int argc, const char **argv)
122108
continue;
123109

124110
if (ce_stage(ce)) {
125-
if (!diff_unmerged_stage)
126-
show_unmerge(ce->name);
111+
show_unmerge(ce->name);
127112
while (i < entries) {
128113
struct cache_entry *nce = active_cache[i];
129114

@@ -145,8 +130,6 @@ int main(int argc, const char **argv)
145130
if (ce_stage(ce) != diff_unmerged_stage)
146131
continue;
147132
}
148-
else if (diff_unmerged_stage)
149-
continue;
150133

151134
if (lstat(ce->name, &st) < 0) {
152135
if (errno != ENOENT && errno != ENOTDIR) {

0 commit comments

Comments
 (0)