move index_has_changes() from builtin/am.c to merge.c for reuse
index_has_changes() is a function we want to reuse outside of just am, making it also available for merge-recursive and merge-ort. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Dec 21, 2017 at 11:19 UTC
b101793c431b858e49b909bb309a87145fb7348c
3 files changed
+42
-37
builtin/am.c
-37
@@ -1142,43 +1142,6 @@ static void refresh_and_write_cache(void)
1142
die(_("unable to write index file"));
1143
}
1144
1145
-/**
1146
- * Returns 1 if the index differs from HEAD, 0 otherwise. When on an unborn
1147
- * branch, returns 1 if there are entries in the index, 0 otherwise. If an
1148
- * strbuf is provided, the space-separated list of files that differ will be
1149
- * appended to it.
1150
- */
1151
-static int index_has_changes(struct strbuf *sb)
1152
-{
1153
- struct object_id head;
1154
- int i;
1155
-
1156
- if (!get_oid_tree("HEAD", &head)) {
1157
- struct diff_options opt;
1158
-
1159
- diff_setup(&opt);
1160
- DIFF_OPT_SET(&opt, EXIT_WITH_STATUS);
1161
- if (!sb)
1162
- DIFF_OPT_SET(&opt, QUICK);
1163
- do_diff_cache(&head, &opt);
1164
- diffcore_std(&opt);
1165
- for (i = 0; sb && i < diff_queued_diff.nr; i++) {
1166
- if (i)
1167
- strbuf_addch(sb, ' ');
1168
- strbuf_addstr(sb, diff_queued_diff.queue[i]->two->path);
1169
- }
1170
- diff_flush(&opt);
1171
- return DIFF_OPT_TST(&opt, HAS_CHANGES) != 0;
1172
- } else {
1173
- for (i = 0; sb && i < active_nr; i++) {
1174
- if (i)
1175
- strbuf_addch(sb, ' ');
1176
- strbuf_addstr(sb, active_cache[i]->name);
1177
- }
1178
- return !!active_nr;
1179
- }
1180
-}
1181
-
1145
/**
1146
* Dies with a user-friendly message on how to proceed after resolving the
1147
* problem. This message can be overridden with state->resolvemsg.
cache.h
+9
@@ -608,6 +608,15 @@ extern int write_locked_index(struct index_state *, struct lock_file *lock, unsi
608
extern int discard_index(struct index_state *);
609
extern void move_index_extensions(struct index_state *dst, struct index_state *src);
610
extern int unmerged_index(const struct index_state *);
611
+
612
+/**
613
+ * Returns 1 if the index differs from HEAD, 0 otherwise. When on an unborn
614
+ * branch, returns 1 if there are entries in the index, 0 otherwise. If an
615
+ * strbuf is provided, the space-separated list of files that differ will be
616
+ * appended to it.
617
+ */
618
+extern int index_has_changes(struct strbuf *sb);
619
+
620
extern int verify_path(const char *path);
621
extern int strcmp_offset(const char *s1, const char *s2, size_t *first_change);
622
extern int index_dir_exists(struct index_state *istate, const char *name, int namelen);
merge.c
+33
@@ -1,4 +1,6 @@
1
#include "cache.h"
2
+#include "diff.h"
3
+#include "diffcore.h"
4
#include "lockfile.h"
5
#include "commit.h"
6
#include "run-command.h"
@@ -15,6 +17,37 @@ static const char *merge_argument(struct commit *commit)
17
return EMPTY_TREE_SHA1_HEX;
18
}
19
20
+int index_has_changes(struct strbuf *sb)
21
+{
22
+ struct object_id head;
23
+ int i;
24
+
25
+ if (!get_oid_tree("HEAD", &head)) {
26
+ struct diff_options opt;
27
+
28
+ diff_setup(&opt);
29
+ DIFF_OPT_SET(&opt, EXIT_WITH_STATUS);
30
+ if (!sb)
31
+ DIFF_OPT_SET(&opt, QUICK);
32
+ do_diff_cache(&head, &opt);
33
+ diffcore_std(&opt);
34
+ for (i = 0; sb && i < diff_queued_diff.nr; i++) {
35
+ if (i)
36
+ strbuf_addch(sb, ' ');
37
+ strbuf_addstr(sb, diff_queued_diff.queue[i]->two->path);
38
+ }
39
+ diff_flush(&opt);
40
+ return DIFF_OPT_TST(&opt, HAS_CHANGES) != 0;
41
+ } else {
42
+ for (i = 0; sb && i < active_nr; i++) {
43
+ if (i)
44
+ strbuf_addch(sb, ' ');
45
+ strbuf_addstr(sb, active_cache[i]->name);
46
+ }
47
+ return !!active_nr;
48
+ }
49
+}
50
+
51
int try_merge_command(const char *strategy, size_t xopts_nr,
52
const char **xopts, struct commit_list *common,
53
const char *head_arg, struct commit_list *remotes)