@matheusbsbs / matheus-bagliano / commits / 6d2d9e8666
Fork 0

diff: squelch empty diffs even more

When we compare two non-tracked files, or explicitly specify --no-index, the suggestion to run git-status is not helpful. The patch adds a new diff_options bitfield member, no_index, that is used instead of the special value of -2 of the rev_info field max_count to indicate that the index is not to be used. This makes it possible to pass that flag down to diffcore_skip_stat_unmatch(), which only has one diff_options parameter. This could even become a cleanup if we removed all assignments of max_count to a value of -2 (viz. replacement of a magic value with a self-documenting field name) but I didn't dare to do that so late in the rc game.. The no_index bit, if set, then tells diffcore_skip_stat_unmatch() to not account for any skipped stat-mismatches, which avoids the suggestion to run git-status. Signed-off-by: Rene Scharfe <rene.scharfe@lsfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Aug 15, 2007 at 00:41 UTC 6d2d9e8666ef72c8878af4822e243ca33b6752a0
3 files changed +9 -3
diff-lib.c
+6 -2
@@ -189,6 +189,7 @@ static int handle_diff_files_args(struct rev_info *revs,
189 !strcmp(argv[1], "--no-index")) {
190 revs->max_count = -2;
191 revs->diffopt.exit_with_status = 1;
192 + revs->diffopt.no_index = 1;
193 }
194 else if (!strcmp(argv[1], "-q"))
195 *silent = 1;
@@ -204,8 +205,10 @@ static int handle_diff_files_args(struct rev_info *revs,
205 */
206 read_cache();
207 if (!is_in_index(revs->diffopt.paths[0]) ||
207 - !is_in_index(revs->diffopt.paths[1]))
208 + !is_in_index(revs->diffopt.paths[1])) {
209 revs->max_count = -2;
210 + revs->diffopt.no_index = 1;
211 + }
212 }
213
214 /*
@@ -293,6 +296,7 @@ int setup_diff_no_index(struct rev_info *revs,
296 else
297 revs->diffopt.paths = argv + argc - 2;
298 revs->diffopt.nr_paths = 2;
299 + revs->diffopt.no_index = 1;
300 revs->max_count = -2;
301 return 0;
302 }
@@ -304,7 +308,7 @@ int run_diff_files_cmd(struct rev_info *revs, int argc, const char **argv)
308 if (handle_diff_files_args(revs, argc, argv, &silent_on_removed))
309 return -1;
310
307 - if (revs->max_count == -2) {
311 + if (revs->diffopt.no_index) {
312 if (revs->diffopt.nr_paths != 2)
313 return error("need two files/directories with --no-index");
314 if (queue_diff(&revs->diffopt, revs->diffopt.paths[0],
diff.c
+2 -1
@@ -3185,7 +3185,8 @@ static void diffcore_skip_stat_unmatch(struct diff_options *diffopt)
3185 * to determine how many paths were dirty only
3186 * due to stat info mismatch.
3187 */
3188 - diffopt->skip_stat_unmatch++;
3188 + if (!diffopt->no_index)
3189 + diffopt->skip_stat_unmatch++;
3190 diff_free_filepair(p);
3191 }
3192 }
diff.h
+1
@@ -60,6 +60,7 @@ struct diff_options {
60 color_diff_words:1,
61 has_changes:1,
62 quiet:1,
63 + no_index:1,
64 allow_external:1,
65 exit_with_status:1;
66 int context;