Merge branch 'jk/diff-no-index-initialize'
authorJunio C Hamano <gitster@pobox.com>
Thu, 7 Mar 2019 00:59:59 +0000 (09:59 +0900)
committerJunio C Hamano <gitster@pobox.com>
Thu, 7 Mar 2019 00:59:59 +0000 (09:59 +0900)
"git diff --no-index" may still want to access Git goodies like
--ext-diff and --textconv, but so far these have been ignored,
which has been corrected.

* jk/diff-no-index-initialize:
diff: reuse diff setup for --no-index case

1  2 
builtin/diff.c
diff.h
diff --combined builtin/diff.c
index 9f6109224b7ea75689e9780c5f79343f55e1e3e5,777ca8715626f30937d399326e45bd693ead6661..53d4234ff4812845459556b1257e779c528250b8
@@@ -3,7 -3,6 +3,7 @@@
   *
   * Copyright (c) 2006 Junio C Hamano
   */
 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
  #include "cache.h"
  #include "config.h"
  #include "lockfile.h"
@@@ -103,7 -102,7 +103,7 @@@ static int builtin_diff_blobs(struct re
                              int argc, const char **argv,
                              struct object_array_entry **blob)
  {
 -      unsigned mode = canon_mode(S_IFREG | 0644);
 +      const unsigned mode = canon_mode(S_IFREG | 0644);
  
        if (argc > 1)
                usage(builtin_diff_usage);
@@@ -213,7 -212,7 +213,7 @@@ static void refresh_index_quietly(void
        discard_cache();
        read_cache();
        refresh_cache(REFRESH_QUIET|REFRESH_UNMERGED);
 -      update_index_if_able(&the_index, &lock_file);
 +      repo_update_index_if_able(the_repository, &lock_file);
  }
  
  static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv)
@@@ -338,21 -337,23 +338,23 @@@ int cmd_diff(int argc, const char **arg
                       "--no-index" : "[--no-index]");
  
        }
-       if (no_index)
-               /* If this is a no-index diff, just run it and exit there. */
-               diff_no_index(the_repository, &rev, argc, argv);
-       /* Otherwise, we are doing the usual "git" diff */
-       rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;
  
-       /* Scale to real terminal size and respect statGraphWidth config */
+       /* Set up defaults that will apply to both no-index and regular diffs. */
        rev.diffopt.stat_width = -1;
        rev.diffopt.stat_graph_width = -1;
-       /* Default to let external and textconv be used */
        rev.diffopt.flags.allow_external = 1;
        rev.diffopt.flags.allow_textconv = 1;
  
+       /* If this is a no-index diff, just run it and exit there. */
+       if (no_index)
+               diff_no_index(&rev, argc, argv);
+       /*
+        * Otherwise, we are doing the usual "git" diff; set up any
+        * further defaults that apply to regular diffs.
+        */
+       rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;
        /*
         * Default to intent-to-add entries invisible in the
         * index. This makes them show up as new files in diff-files
diff --combined diff.h
index 0478abe07d11e4e076fdc26ef68174c50a7f6e55,6e6a6730f562ec6107136868f83d569858d6c427..c9db9825bb782fda45f463c3f51600fb3756b7c1
--- 1/diff.h
--- 2/diff.h
+++ b/diff.h
@@@ -9,17 -9,16 +9,17 @@@
  #include "object.h"
  #include "oidset.h"
  
 -struct rev_info;
 +struct combine_diff_path;
 +struct commit;
 +struct diff_filespec;
  struct diff_options;
  struct diff_queue_struct;
 -struct strbuf;
 -struct diff_filespec;
 -struct userdiff_driver;
  struct oid_array;
 -struct commit;
 -struct combine_diff_path;
 +struct option;
  struct repository;
 +struct rev_info;
 +struct strbuf;
 +struct userdiff_driver;
  
  typedef int (*pathchange_fn_t)(struct diff_options *options,
                 struct combine_diff_path *path);
@@@ -65,39 -64,39 +65,39 @@@ typedef struct strbuf *(*diff_prefix_fn
  
  #define DIFF_FLAGS_INIT { 0 }
  struct diff_flags {
 -      unsigned recursive:1;
 -      unsigned tree_in_recursive:1;
 -      unsigned binary:1;
 -      unsigned text:1;
 -      unsigned full_index:1;
 -      unsigned silent_on_remove:1;
 -      unsigned find_copies_harder:1;
 -      unsigned follow_renames:1;
 -      unsigned rename_empty:1;
 -      unsigned has_changes:1;
 -      unsigned quick:1;
 -      unsigned no_index:1;
 -      unsigned allow_external:1;
 -      unsigned exit_with_status:1;
 -      unsigned reverse_diff:1;
 -      unsigned check_failed:1;
 -      unsigned relative_name:1;
 -      unsigned ignore_submodules:1;
 -      unsigned dirstat_cumulative:1;
 -      unsigned dirstat_by_file:1;
 -      unsigned allow_textconv:1;
 -      unsigned textconv_set_via_cmdline:1;
 -      unsigned diff_from_contents:1;
 -      unsigned dirty_submodules:1;
 -      unsigned ignore_untracked_in_submodules:1;
 -      unsigned ignore_dirty_submodules:1;
 -      unsigned override_submodule_config:1;
 -      unsigned dirstat_by_line:1;
 -      unsigned funccontext:1;
 -      unsigned default_follow_renames:1;
 -      unsigned stat_with_summary:1;
 -      unsigned suppress_diff_headers:1;
 -      unsigned dual_color_diffed_diffs:1;
 +      unsigned recursive;
 +      unsigned tree_in_recursive;
 +      unsigned binary;
 +      unsigned text;
 +      unsigned full_index;
 +      unsigned silent_on_remove;
 +      unsigned find_copies_harder;
 +      unsigned follow_renames;
 +      unsigned rename_empty;
 +      unsigned has_changes;
 +      unsigned quick;
 +      unsigned no_index;
 +      unsigned allow_external;
 +      unsigned exit_with_status;
 +      unsigned reverse_diff;
 +      unsigned check_failed;
 +      unsigned relative_name;
 +      unsigned ignore_submodules;
 +      unsigned dirstat_cumulative;
 +      unsigned dirstat_by_file;
 +      unsigned allow_textconv;
 +      unsigned textconv_set_via_cmdline;
 +      unsigned diff_from_contents;
 +      unsigned dirty_submodules;
 +      unsigned ignore_untracked_in_submodules;
 +      unsigned ignore_dirty_submodules;
 +      unsigned override_submodule_config;
 +      unsigned dirstat_by_line;
 +      unsigned funccontext;
 +      unsigned default_follow_renames;
 +      unsigned stat_with_summary;
 +      unsigned suppress_diff_headers;
 +      unsigned dual_color_diffed_diffs;
  };
  
  static inline void diff_flags_or(struct diff_flags *a,
@@@ -226,11 -225,9 +226,11 @@@ struct diff_options 
  
        /* XDF_WHITESPACE_FLAGS regarding block detection are set at 2, 3, 4 */
        #define COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE (1<<5)
 -      int color_moved_ws_handling;
 +      #define COLOR_MOVED_WS_ERROR (1<<0)
 +      unsigned color_moved_ws_handling;
  
        struct repository *repo;
 +      struct option *parseopts;
  };
  
  void diff_emit_submodule_del(struct diff_options *o, const char *line);
@@@ -296,7 -293,6 +296,7 @@@ struct combine_diff_path 
                char status;
                unsigned int mode;
                struct object_id oid;
 +              struct strbuf path;
        } parent[FLEX_ARRAY];
  };
  #define combine_diff_path_size(n, l) \
@@@ -370,7 -366,7 +370,7 @@@ int git_config_rename(const char *var, 
  #define DIFF_PICKAXE_IGNORE_CASE      32
  
  void diffcore_std(struct diff_options *);
 -void diffcore_fix_diff_index(struct diff_options *);
 +void diffcore_fix_diff_index(void);
  
  #define COMMON_DIFF_OPTIONS_HELP \
  "\ncommon diff options:\n" \
@@@ -438,10 -434,9 +438,10 @@@ int diff_flush_patch_id(struct diff_opt
  
  int diff_result_code(struct diff_options *, int);
  
- void diff_no_index(struct repository *, struct rev_info *, int, const char **);
+ void diff_no_index(struct rev_info *, int, const char **);
  
 -int index_differs_from(const char *def, const struct diff_flags *flags,
 +int index_differs_from(struct repository *r, const char *def,
 +                     const struct diff_flags *flags,
                       int ita_invisible_in_index);
  
  /*
@@@ -465,7 -460,7 +465,7 @@@ size_t fill_textconv(struct repository 
   * and only if it has textconv enabled (otherwise return NULL). The result
   * can be passed to fill_textconv().
   */
 -struct userdiff_driver *get_textconv(struct index_state *istate,
 +struct userdiff_driver *get_textconv(struct repository *r,
                                     struct diff_filespec *one);
  
  /*