Code

compat/mingw: Support a timeout in the poll emulation if no fds are given
[git.git] / builtin-diff.c
index faaa85a1d45ce6c5f398a44b1241f6325430918b..35da366f46009eab8eab693f7f56403d91d5d677 100644 (file)
@@ -74,6 +74,8 @@ static int builtin_diff_b_f(struct rev_info *revs,
        if (!(S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)))
                die("'%s': not a regular file or symlink", path);
 
+       diff_set_mnemonic_prefix(&revs->diffopt, "o/", "w/");
+
        if (blob[0].mode == S_IFINVALID)
                blob[0].mode = canon_mode(st.st_mode);
 
@@ -122,6 +124,8 @@ static int builtin_diff_index(struct rev_info *revs,
                        usage(builtin_diff_usage);
                argv++; argc--;
        }
+       if (!cached)
+               setup_work_tree();
        /*
         * Make sure there is one revision (i.e. pending object),
         * and there is no revision filtering parameters.
@@ -221,10 +225,17 @@ static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv
                argv++; argc--;
        }
 
-       if (revs->max_count == -1 &&
+       /*
+        * "diff --base" should not combine merges because it was not
+        * asked to.  "diff -c" should not densify (if the user wants
+        * dense one, --cc can be explicitly asked for, or just rely
+        * on the default).
+        */
+       if (revs->max_count == -1 && !revs->combine_merges &&
            (revs->diffopt.output_format & DIFF_FORMAT_PATCH))
                revs->combine_merges = revs->dense_combined_merges = 1;
 
+       setup_work_tree();
        if (read_cache() < 0) {
                perror("read_cache");
                return -1;
@@ -296,7 +307,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
         * If the user asked for our exit code then don't start a
         * pager or we would end up reporting its exit code instead.
         */
-       if (!DIFF_OPT_TST(&rev.diffopt, EXIT_WITH_STATUS))
+       if (!DIFF_OPT_TST(&rev.diffopt, EXIT_WITH_STATUS) &&
+           check_pager_config("diff") != 0)
                setup_pager();
 
        /*