read-cache.c: move index_has_changes() from merge.c
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>
Elijah Newren committed
Jun 30, 2018 at 18:24 UTC
cffbfad50d1f37aea03520dd8d8ea983bc57da02
2 files changed
+33
-31
merge.c
-31
@@ -17,37 +17,6 @@ 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
- opt.flags.exit_with_status = 1;
30
- if (!sb)
31
- opt.flags.quick = 1;
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 opt.flags.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
-
20
int try_merge_command(const char *strategy, size_t xopts_nr,
21
const char **xopts, struct commit_list *common,
22
const char *head_arg, struct commit_list *remotes)
read-cache.c
+33
@@ -6,6 +6,8 @@
6
#define NO_THE_INDEX_COMPATIBILITY_MACROS
7
#include "cache.h"
8
#include "config.h"
9
+#include "diff.h"
10
+#include "diffcore.h"
11
#include "tempfile.h"
12
#include "lockfile.h"
13
#include "cache-tree.h"
@@ -1984,6 +1986,37 @@ int unmerged_index(const struct index_state *istate)
1986
return 0;
1987
}
1988
1989
+int index_has_changes(struct strbuf *sb)
1990
+{
1991
+ struct object_id head;
1992
+ int i;
1993
+
1994
+ if (!get_oid_tree("HEAD", &head)) {
1995
+ struct diff_options opt;
1996
+
1997
+ diff_setup(&opt);
1998
+ opt.flags.exit_with_status = 1;
1999
+ if (!sb)
2000
+ opt.flags.quick = 1;
2001
+ do_diff_cache(&head, &opt);
2002
+ diffcore_std(&opt);
2003
+ for (i = 0; sb && i < diff_queued_diff.nr; i++) {
2004
+ if (i)
2005
+ strbuf_addch(sb, ' ');
2006
+ strbuf_addstr(sb, diff_queued_diff.queue[i]->two->path);
2007
+ }
2008
+ diff_flush(&opt);
2009
+ return opt.flags.has_changes != 0;
2010
+ } else {
2011
+ for (i = 0; sb && i < the_index.cache_nr; i++) {
2012
+ if (i)
2013
+ strbuf_addch(sb, ' ');
2014
+ strbuf_addstr(sb, the_index.cache[i]->name);
2015
+ }
2016
+ return !!the_index.cache_nr;
2017
+ }
2018
+}
2019
+
2020
#define WRITE_BUFFER_SIZE 8192
2021
static unsigned char write_buffer[WRITE_BUFFER_SIZE];
2022
static unsigned long write_buffer_len;