]> asedeno.scripts.mit.edu Git - git.git/blobdiff - builtin-diff.c
Always set *nongit_ok in setup_git_directory_gently()
[git.git] / builtin-diff.c
index 9d878f6a71a5a7a53b11112396cb963ba149d6e6..7c2a8412fa8cefa2f53a5f7c2035ea9f2536e1c4 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (c) 2006 Junio C Hamano
  */
 #include "cache.h"
+#include "color.h"
 #include "commit.h"
 #include "blob.h"
 #include "tag.h"
@@ -43,12 +44,17 @@ static void stuff_change(struct diff_options *opt,
                tmp_u = old_sha1; old_sha1 = new_sha1; new_sha1 = tmp_u;
                tmp_c = old_name; old_name = new_name; new_name = tmp_c;
        }
+
+       if (opt->prefix &&
+           (strncmp(old_name, opt->prefix, opt->prefix_length) ||
+            strncmp(new_name, opt->prefix, opt->prefix_length)))
+               return;
+
        one = alloc_filespec(old_name);
        two = alloc_filespec(new_name);
        fill_filespec(one, old_sha1, old_mode);
        fill_filespec(two, new_sha1, new_mode);
 
-       /* NEEDSWORK: shouldn't this part of diffopt??? */
        diff_queue(&diff_queued_diff, one, two);
 }
 
@@ -190,7 +196,7 @@ static void refresh_index_quietly(void)
        refresh_cache(REFRESH_QUIET|REFRESH_UNMERGED);
 
        if (active_cache_changed &&
-           !write_cache(fd, active_cache, active_nr) && !close(fd))
+           !write_cache(fd, active_cache, active_nr))
                commit_locked_index(lock_file);
 
        rollback_lock_file(lock_file);
@@ -204,7 +210,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
        int ents = 0, blobs = 0, paths = 0;
        const char *path = NULL;
        struct blobinfo blob[2];
-       int nongit = 0;
+       int nongit;
        int result = 0;
 
        /*
@@ -229,6 +235,10 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
 
        prefix = setup_git_directory_gently(&nongit);
        git_config(git_diff_ui_config);
+
+       if (diff_use_color_default == -1)
+               diff_use_color_default = git_use_color_default;
+
        init_revisions(&rev, prefix);
        rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;
 
@@ -241,14 +251,18 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
                if (diff_setup_done(&rev.diffopt) < 0)
                        die("diff_setup_done failed");
        }
+       if (rev.diffopt.prefix && nongit) {
+               rev.diffopt.prefix = NULL;
+               rev.diffopt.prefix_length = 0;
+       }
        DIFF_OPT_SET(&rev.diffopt, ALLOW_EXTERNAL);
        DIFF_OPT_SET(&rev.diffopt, RECURSIVE);
 
-       /* If the user asked for our exit code then don't start a
+       /*
+        * 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) &&
-           (!(rev.diffopt.output_format & DIFF_FORMAT_CHECKDIFF)))
+       if (!DIFF_OPT_TST(&rev.diffopt, EXIT_WITH_STATUS))
                setup_pager();
 
        /* Do we have --cached and not have a pending object, then
@@ -352,10 +366,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
        else
                result = builtin_diff_combined(&rev, argc, argv,
                                             ent, ents);
-       if (DIFF_OPT_TST(&rev.diffopt, EXIT_WITH_STATUS))
-               result = DIFF_OPT_TST(&rev.diffopt, HAS_CHANGES) != 0;
-       if (rev.diffopt.output_format & DIFF_FORMAT_CHECKDIFF)
-               return DIFF_OPT_TST(&rev.diffopt, CHECK_FAILED) != 0;
+       result = diff_result_code(&rev.diffopt, result);
        if (1 < rev.diffopt.skip_stat_unmatch)
                refresh_index_quietly();
        return result;