diff.c: remove implicit dependency on the_index
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Fri, 21 Sep 2018 15:57:24 +0000 (17:57 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 21 Sep 2018 16:48:10 +0000 (09:48 -0700)
A new variant repo_diff_setup() is added that takes 'struct repository *'
and diff_setup() becomes a thin macro around it that is protected by
NO_THE_REPOSITORY_COMPATIBILITY_MACROS, similar to NO_THE_INDEX_....
The plan is these macros will always be defined for all library files
and the macros are only accessible in builtin/

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 files changed:
Documentation/technical/api-diff.txt
blame.c
builtin/diff.c
builtin/log.c
builtin/merge.c
builtin/range-diff.c
diff-no-index.c
diff.c
diff.h
merge-recursive.c
notes-merge.c
patch-ids.c
read-cache.c
revision.c
tree-diff.c
index 8b001de0db3628d4f02c2890d5614e067e701ed4..30fc0e9c93b2562b87abb107acf5ad2ae1c7fea0 100644 (file)
@@ -18,8 +18,8 @@ Calling sequence
 ----------------
 
 * Prepare `struct diff_options` to record the set of diff options, and
-  then call `diff_setup()` to initialize this structure.  This sets up
-  the vanilla default.
+  then call `repo_diff_setup()` to initialize this structure.  This
+  sets up the vanilla default.
 
 * Fill in the options structure to specify desired output format, rename
   detection, etc.  `diff_opt_parse()` can be used to parse options given
diff --git a/blame.c b/blame.c
index 9d57c76baa0951a369e6af49b72b6520cddd4e86..c229a10c0e3c9e809286ee8af8694dc135c340f2 100644 (file)
--- a/blame.c
+++ b/blame.c
@@ -541,8 +541,9 @@ static int fill_blob_sha1_and_mode(struct repository *r,
  * We have an origin -- check if the same path exists in the
  * parent and return an origin structure to represent it.
  */
-static struct blame_origin *find_origin(struct commit *parent,
-                                 struct blame_origin *origin)
+static struct blame_origin *find_origin(struct repository *r,
+                                       struct commit *parent,
+                                       struct blame_origin *origin)
 {
        struct blame_origin *porigin;
        struct diff_options diff_opts;
@@ -562,7 +563,7 @@ static struct blame_origin *find_origin(struct commit *parent,
         * and origin first.  Most of the time they are the
         * same and diff-tree is fairly efficient about this.
         */
-       diff_setup(&diff_opts);
+       repo_diff_setup(r, &diff_opts);
        diff_opts.flags.recursive = 1;
        diff_opts.detect_rename = 0;
        diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
@@ -629,14 +630,15 @@ static struct blame_origin *find_origin(struct commit *parent,
  * We have an origin -- find the path that corresponds to it in its
  * parent and return an origin structure to represent it.
  */
-static struct blame_origin *find_rename(struct commit *parent,
-                                 struct blame_origin *origin)
+static struct blame_origin *find_rename(struct repository *r,
+                                       struct commit *parent,
+                                       struct blame_origin *origin)
 {
        struct blame_origin *porigin = NULL;
        struct diff_options diff_opts;
        int i;
 
-       diff_setup(&diff_opts);
+       repo_diff_setup(r, &diff_opts);
        diff_opts.flags.recursive = 1;
        diff_opts.detect_rename = DIFF_DETECT_RENAME;
        diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
@@ -1260,7 +1262,7 @@ static void find_copy_in_parent(struct blame_scoreboard *sb,
        if (!unblamed)
                return; /* nothing remains for this target */
 
-       diff_setup(&diff_opts);
+       repo_diff_setup(sb->repo, &diff_opts);
        diff_opts.flags.recursive = 1;
        diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
 
@@ -1442,7 +1444,7 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
         * common cases, then we look for renames in the second pass.
         */
        for (pass = 0; pass < 2 - sb->no_whole_file_rename; pass++) {
-               struct blame_origin *(*find)(struct commit *, struct blame_origin *);
+               struct blame_origin *(*find)(struct repository *, struct commit *, struct blame_origin *);
                find = pass ? find_rename : find_origin;
 
                for (i = 0, sg = first_scapegoat(revs, commit, sb->reverse);
@@ -1455,7 +1457,7 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
                                continue;
                        if (parse_commit(p))
                                continue;
-                       porigin = find(p, origin);
+                       porigin = find(sb->repo, p, origin);
                        if (!porigin)
                                continue;
                        if (!oidcmp(&porigin->blob_oid, &origin->blob_oid)) {
index 361a3c3ed38769f798b83933755fed84724ce43c..ab89b06d18e47794d32d75b788b0685365e7c576 100644 (file)
@@ -339,7 +339,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
        }
        if (no_index)
                /* If this is a no-index diff, just run it and exit there. */
-               diff_no_index(&rev, argc, argv);
+               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;
index b62082472cfe4331632b4ae12b390ada5e12da3a..4b602236d6ee50fff8a08ac23b186e7d6ebd8c22 100644 (file)
@@ -1361,7 +1361,7 @@ static void prepare_bases(struct base_tree_info *bases,
                return;
 
        init_commit_base(&commit_base);
-       diff_setup(&diffopt);
+       repo_diff_setup(the_repository, &diffopt);
        diffopt.flags.recursive = 1;
        diff_setup_done(&diffopt);
 
index 8f4a5065c209b5b50e02271b48277fff90306338..592cb19caf6ae8056c99b23e0ba12c0571af47de 100644 (file)
@@ -452,7 +452,7 @@ static void finish(struct commit *head_commit,
        }
        if (new_head && show_diffstat) {
                struct diff_options opts;
-               diff_setup(&opts);
+               repo_diff_setup(the_repository, &opts);
                opts.stat_width = -1; /* use full terminal width */
                opts.stat_graph_width = -1; /* respect statGraphWidth config */
                opts.output_format |=
index 0aa9bed41f35bf99784acd4abab52df415c5fb00..1c477c4dc5ee80d29c7e01f0a88b466782810fc2 100644 (file)
@@ -34,7 +34,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
 
        git_config(git_diff_ui_config, NULL);
 
-       diff_setup(&diffopt);
+       repo_diff_setup(the_repository, &diffopt);
        diffopt.output_format = DIFF_FORMAT_PATCH;
        diffopt.flags.suppress_diff_headers = 1;
        diffopt.output_prefix = output_prefix_cb;
index 0ed5f0f496882cef9e04f9a93fe718a9f55a268a..9414e922d164e96ffedfa2504045930b058dbc80 100644 (file)
@@ -233,7 +233,8 @@ static void fixup_paths(const char **path, struct strbuf *replacement)
        }
 }
 
-void diff_no_index(struct rev_info *revs,
+void diff_no_index(struct repository *r,
+                  struct rev_info *revs,
                   int argc, const char **argv)
 {
        int i;
@@ -241,7 +242,11 @@ void diff_no_index(struct rev_info *revs,
        struct strbuf replacement = STRBUF_INIT;
        const char *prefix = revs->prefix;
 
-       diff_setup(&revs->diffopt);
+       /*
+        * FIXME: --no-index should not look at index and we should be
+        * able to pass NULL repo. Maybe later.
+        */
+       repo_diff_setup(r, &revs->diffopt);
        for (i = 1; i < argc - 2; ) {
                int j;
                if (!strcmp(argv[i], "--no-index"))
diff --git a/diff.c b/diff.c
index 0848ac65dfc56e31f99c861fd5e6a76634643150..1bcc0818df30a773c5661900e9e920915ddc28b8 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -4390,12 +4390,12 @@ static void run_checkdiff(struct diff_filepair *p, struct diff_options *o)
        builtin_checkdiff(name, other, attr_path, p->one, p->two, o);
 }
 
-void diff_setup(struct diff_options *options)
+void repo_diff_setup(struct repository *r, struct diff_options *options)
 {
        memcpy(options, &default_diff_options, sizeof(*options));
 
        options->file = stdout;
-       options->repo->index = &the_index;
+       options->repo = r;
 
        options->abbrev = DEFAULT_ABBREV;
        options->line_termination = '\n';
diff --git a/diff.h b/diff.h
index 812f71d9535de13003e80b549e839e951186920d..b88fccd2fb13b8bd7ae74d670b001ebb1980dc46 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -336,7 +336,10 @@ int git_diff_basic_config(const char *var, const char *value, void *cb);
 int git_diff_heuristic_config(const char *var, const char *value, void *cb);
 void init_diff_ui_defaults(void);
 int git_diff_ui_config(const char *var, const char *value, void *cb);
-void diff_setup(struct diff_options *);
+#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
+#define diff_setup(diffopts) repo_diff_setup(the_repository, diffopts)
+#endif
+void repo_diff_setup(struct repository *, struct diff_options *);
 int diff_opt_parse(struct diff_options *, const char **, int, const char *);
 void diff_setup_done(struct diff_options *);
 int git_config_rename(const char *var, const char *value);
@@ -426,7 +429,7 @@ int diff_flush_patch_id(struct diff_options *, struct object_id *, int);
 
 int diff_result_code(struct diff_options *, int);
 
-void diff_no_index(struct rev_info *, int, const char **);
+void diff_no_index(struct repository *, struct rev_info *, int, const char **);
 
 int index_differs_from(const char *def, const struct diff_flags *flags,
                       int ita_invisible_in_index);
index e5243dbc542d786a645a9c038c855a6ca30acaba..939843e81555e151fea6c897e81538f4abb74713 100644 (file)
@@ -1812,7 +1812,7 @@ static struct diff_queue_struct *get_diffpairs(struct merge_options *o,
        struct diff_queue_struct *ret;
        struct diff_options opts;
 
-       diff_setup(&opts);
+       repo_diff_setup(the_repository, &opts);
        opts.flags.recursive = 1;
        opts.flags.rename_empty = 0;
        opts.detect_rename = merge_detect_rename(o);
index 76ab19e702423aeb511bfc1e939a7998c61fab61..9b154a5da6b27ea9ad55b3404d5e3ad4f7c8d744 100644 (file)
@@ -126,7 +126,7 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,
        trace_printf("\tdiff_tree_remote(base = %.7s, remote = %.7s)\n",
               oid_to_hex(base), oid_to_hex(remote));
 
-       diff_setup(&opt);
+       repo_diff_setup(the_repository, &opt);
        opt.flags.recursive = 1;
        opt.output_format = DIFF_FORMAT_NO_OUTPUT;
        diff_setup_done(&opt);
@@ -189,7 +189,7 @@ static void diff_tree_local(struct notes_merge_options *o,
        trace_printf("\tdiff_tree_local(len = %i, base = %.7s, local = %.7s)\n",
               len, oid_to_hex(base), oid_to_hex(local));
 
-       diff_setup(&opt);
+       repo_diff_setup(the_repository, &opt);
        opt.flags.recursive = 1;
        opt.output_format = DIFF_FORMAT_NO_OUTPUT;
        diff_setup_done(&opt);
index 8f7c25d5dbf5ccdcbf27db51fbe1970addebf9a7..342950c79d14346252fad24467c809415f3042bf 100644 (file)
@@ -59,7 +59,7 @@ static int patch_id_cmp(const void *cmpfn_data,
 int init_patch_ids(struct patch_ids *ids)
 {
        memset(ids, 0, sizeof(*ids));
-       diff_setup(&ids->diffopts);
+       repo_diff_setup(the_repository, &ids->diffopts);
        ids->diffopts.detect_rename = 0;
        ids->diffopts.flags.recursive = 1;
        diff_setup_done(&ids->diffopts);
index 86134e56a6819b2417a7fe16bc3594d320a34526..6f772b2885c109e6f063acd5cfb038d826b00b0d 100644 (file)
@@ -2137,7 +2137,7 @@ int index_has_changes(struct index_state *istate,
        if (tree || !get_oid_tree("HEAD", &cmp)) {
                struct diff_options opt;
 
-               diff_setup(&opt);
+               repo_diff_setup(the_repository, &opt);
                opt.flags.exit_with_status = 1;
                if (!sb)
                        opt.flags.quick = 1;
index 3457064ff3cd59d075ac537ab0651b86f2232be3..0c6dc8c163fe2e21040b08b5762fc9409b4fb969 100644 (file)
@@ -1468,7 +1468,7 @@ void init_revisions(struct rev_info *revs, const char *prefix)
        grep_init(&revs->grep_filter, the_repository, prefix);
        revs->grep_filter.status_only = 1;
 
-       diff_setup(&revs->diffopt);
+       repo_diff_setup(the_repository, &revs->diffopt);
        if (prefix && !revs->diffopt.prefix) {
                revs->diffopt.prefix = prefix;
                revs->diffopt.prefix_length = strlen(prefix);
index 553bc0e63ae37ada1c3e19ae748d1228561f00f6..57a15f51f0e13e711ad7d92a0fc04ce5d53d3336 100644 (file)
@@ -605,7 +605,7 @@ static void try_to_follow_renames(const struct object_id *old_oid,
        choice = q->queue[0];
        q->nr = 0;
 
-       diff_setup(&diff_opts);
+       repo_diff_setup(the_repository, &diff_opts);
        diff_opts.flags.recursive = 1;
        diff_opts.flags.find_copies_harder = 1;
        diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;