read-cache.c: move index_has_changes() from merge.c
authorElijah Newren <newren@gmail.com>
Sun, 1 Jul 2018 01:24:55 +0000 (18:24 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 3 Jul 2018 20:13:17 +0000 (13:13 -0700)
Since index_has_change() is an index-related function, move it to
read-cache.c, only modifying it to avoid uses of the active_cache and
active_nr macros.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
merge.c
read-cache.c
diff --git a/merge.c b/merge.c
index f06a4773d4f4093d700c652accc79ae17f161a59..fb5eaf24622f2f0b6c8dfd1bdc6fb051e31007d5 100644 (file)
--- a/merge.c
+++ b/merge.c
@@ -17,37 +17,6 @@ static const char *merge_argument(struct commit *commit)
                return EMPTY_TREE_SHA1_HEX;
 }
 
-int index_has_changes(struct strbuf *sb)
-{
-       struct object_id head;
-       int i;
-
-       if (!get_oid_tree("HEAD", &head)) {
-               struct diff_options opt;
-
-               diff_setup(&opt);
-               opt.flags.exit_with_status = 1;
-               if (!sb)
-                       opt.flags.quick = 1;
-               do_diff_cache(&head, &opt);
-               diffcore_std(&opt);
-               for (i = 0; sb && i < diff_queued_diff.nr; i++) {
-                       if (i)
-                               strbuf_addch(sb, ' ');
-                       strbuf_addstr(sb, diff_queued_diff.queue[i]->two->path);
-               }
-               diff_flush(&opt);
-               return opt.flags.has_changes != 0;
-       } else {
-               for (i = 0; sb && i < active_nr; i++) {
-                       if (i)
-                               strbuf_addch(sb, ' ');
-                       strbuf_addstr(sb, active_cache[i]->name);
-               }
-               return !!active_nr;
-       }
-}
-
 int try_merge_command(const char *strategy, size_t xopts_nr,
                      const char **xopts, struct commit_list *common,
                      const char *head_arg, struct commit_list *remotes)
index 4b35e87847f0c346f4968765fa8dc64a863a8047..ba094fd48553efdad083b83df11fa30ac6c282cf 100644 (file)
@@ -6,6 +6,8 @@
 #define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
+#include "diff.h"
+#include "diffcore.h"
 #include "tempfile.h"
 #include "lockfile.h"
 #include "cache-tree.h"
@@ -1984,6 +1986,37 @@ int unmerged_index(const struct index_state *istate)
        return 0;
 }
 
+int index_has_changes(struct strbuf *sb)
+{
+       struct object_id head;
+       int i;
+
+       if (!get_oid_tree("HEAD", &head)) {
+               struct diff_options opt;
+
+               diff_setup(&opt);
+               opt.flags.exit_with_status = 1;
+               if (!sb)
+                       opt.flags.quick = 1;
+               do_diff_cache(&head, &opt);
+               diffcore_std(&opt);
+               for (i = 0; sb && i < diff_queued_diff.nr; i++) {
+                       if (i)
+                               strbuf_addch(sb, ' ');
+                       strbuf_addstr(sb, diff_queued_diff.queue[i]->two->path);
+               }
+               diff_flush(&opt);
+               return opt.flags.has_changes != 0;
+       } else {
+               for (i = 0; sb && i < the_index.cache_nr; i++) {
+                       if (i)
+                               strbuf_addch(sb, ' ');
+                       strbuf_addstr(sb, the_index.cache[i]->name);
+               }
+               return !!the_index.cache_nr;
+       }
+}
+
 #define WRITE_BUFFER_SIZE 8192
 static unsigned char write_buffer[WRITE_BUFFER_SIZE];
 static unsigned long write_buffer_len;