Skip to content

Commit cffbfad

Browse files
newrengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fc54c1a commit cffbfad

File tree

2 files changed

+33
-31
lines changed

2 files changed

+33
-31
lines changed

merge.c

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,6 @@ static const char *merge_argument(struct commit *commit)
1717
return EMPTY_TREE_SHA1_HEX;
1818
}
1919

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-
5120
int try_merge_command(const char *strategy, size_t xopts_nr,
5221
const char **xopts, struct commit_list *common,
5322
const char *head_arg, struct commit_list *remotes)

read-cache.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#define NO_THE_INDEX_COMPATIBILITY_MACROS
77
#include "cache.h"
88
#include "config.h"
9+
#include "diff.h"
10+
#include "diffcore.h"
911
#include "tempfile.h"
1012
#include "lockfile.h"
1113
#include "cache-tree.h"
@@ -1984,6 +1986,37 @@ int unmerged_index(const struct index_state *istate)
19841986
return 0;
19851987
}
19861988

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+
19872020
#define WRITE_BUFFER_SIZE 8192
19882021
static unsigned char write_buffer[WRITE_BUFFER_SIZE];
19892022
static unsigned long write_buffer_len;

0 commit comments

Comments
 (0)