]> git.ipfire.org Git - thirdparty/git.git/commitdiff
diff-lib: accept option flags in run_diff_index()
authorDenton Liu <liu.denton@gmail.com>
Sun, 20 Sep 2020 11:22:22 +0000 (04:22 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 21 Sep 2020 04:30:26 +0000 (21:30 -0700)
In a future commit, we will teach run_diff_index() to accept more
options via flag bits. For now, change `cached` into a flag in the
`option` bitfield. The behaviour should remain exactly the same.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/diff-index.c
builtin/diff.c
diff-lib.c
diff.h

index 93ec6424234c65f486dcfca724c77a48e5e91f91..c3878f7ad641823b6a27c2df76f8e317c2fc1478 100644 (file)
@@ -15,7 +15,7 @@ COMMON_DIFF_OPTIONS_HELP;
 int cmd_diff_index(int argc, const char **argv, const char *prefix)
 {
        struct rev_info rev;
-       int cached = 0;
+       unsigned int option = 0;
        int i;
        int result;
 
@@ -32,7 +32,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
                const char *arg = argv[i];
 
                if (!strcmp(arg, "--cached"))
-                       cached = 1;
+                       option |= DIFF_INDEX_CACHED;
                else
                        usage(diff_cache_usage);
        }
@@ -46,7 +46,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
        if (rev.pending.nr != 1 ||
            rev.max_count != -1 || rev.min_age != -1 || rev.max_age != -1)
                usage(diff_cache_usage);
-       if (!cached) {
+       if (!(option & DIFF_INDEX_CACHED)) {
                setup_work_tree();
                if (read_cache_preload(&rev.diffopt.pathspec) < 0) {
                        perror("read_cache_preload");
@@ -56,7 +56,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
                perror("read_cache");
                return -1;
        }
-       result = run_diff_index(&rev, cached);
+       result = run_diff_index(&rev, option);
        UNLEAK(rev);
        return diff_result_code(&rev.diffopt, result);
 }
index cb98811c21db7dfc2169f35f0d09e9c20dfd0cfd..e45e19e37e19f7c15e387fa5f76cfc2263b230ab 100644 (file)
@@ -134,11 +134,11 @@ static int builtin_diff_blobs(struct rev_info *revs,
 static int builtin_diff_index(struct rev_info *revs,
                              int argc, const char **argv)
 {
-       int cached = 0;
+       unsigned int option = 0;
        while (1 < argc) {
                const char *arg = argv[1];
                if (!strcmp(arg, "--cached") || !strcmp(arg, "--staged"))
-                       cached = 1;
+                       option |= DIFF_INDEX_CACHED;
                else
                        usage(builtin_diff_usage);
                argv++; argc--;
@@ -151,7 +151,7 @@ static int builtin_diff_index(struct rev_info *revs,
            revs->max_count != -1 || revs->min_age != -1 ||
            revs->max_age != -1)
                usage(builtin_diff_usage);
-       if (!cached) {
+       if (!(option & DIFF_INDEX_CACHED)) {
                setup_work_tree();
                if (read_cache_preload(&revs->diffopt.pathspec) < 0) {
                        perror("read_cache_preload");
@@ -161,7 +161,7 @@ static int builtin_diff_index(struct rev_info *revs,
                perror("read_cache");
                return -1;
        }
-       return run_diff_index(revs, cached);
+       return run_diff_index(revs, option);
 }
 
 static int builtin_diff_tree(struct rev_info *revs,
index 5d5d3dafab3386920d2c0883d33d06f860f6d11b..ed720853ede3e2c1e9f2b1a6ce3a1b9a00ff8c9f 100644 (file)
@@ -512,9 +512,10 @@ static int diff_cache(struct rev_info *revs,
        return unpack_trees(1, &t, &opts);
 }
 
-int run_diff_index(struct rev_info *revs, int cached)
+int run_diff_index(struct rev_info *revs, unsigned int option)
 {
        struct object_array_entry *ent;
+       int cached = !!(option & DIFF_INDEX_CACHED);
 
        if (revs->pending.nr != 1)
                BUG("run_diff_index must be passed exactly one tree");
diff --git a/diff.h b/diff.h
index e0c0af6286bbab24fde5174282c66a122737c392..aea0d5b96beca8adeb365c30bf4cf410a9d39be4 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -585,7 +585,9 @@ const char *diff_aligned_abbrev(const struct object_id *sha1, int);
 /* report racily-clean paths as modified */
 #define DIFF_RACY_IS_MODIFIED 02
 int run_diff_files(struct rev_info *revs, unsigned int option);
-int run_diff_index(struct rev_info *revs, int cached);
+
+#define DIFF_INDEX_CACHED 01
+int run_diff_index(struct rev_info *revs, unsigned int option);
 
 int do_diff_cache(const struct object_id *, struct diff_options *);
 int diff_flush_patch_id(struct diff_options *, struct object_id *, int, int);