Library function to check for unmerged index entries
It's small, but it was in three places already, so it should be in the library. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
Daniel Barkalow committed
Feb 7, 2008 at 11:40 UTC
94a5728cfb593d80164620f8fa7e1ef322ad0025
4 files changed
+15
-26
builtin-merge-recursive.c
+2
-13
@@ -223,22 +223,11 @@ static int git_merge_trees(int index_only,
223
return rc;
224
}
225
226
-static int unmerged_index(void)
227
-{
228
- int i;
229
- for (i = 0; i < active_nr; i++) {
230
- struct cache_entry *ce = active_cache[i];
231
- if (ce_stage(ce))
232
- return 1;
233
- }
234
- return 0;
235
-}
236
-
226
struct tree *write_tree_from_memory(void)
227
{
228
struct tree *result = NULL;
229
241
- if (unmerged_index()) {
230
+ if (unmerged_cache()) {
231
int i;
232
output(0, "There are unmerged index entries:");
233
for (i = 0; i < active_nr; i++) {
@@ -1524,7 +1513,7 @@ int merge_trees(struct tree *head,
1513
sha1_to_hex(head->object.sha1),
1514
sha1_to_hex(merge->object.sha1));
1515
1527
- if (unmerged_index()) {
1516
+ if (unmerged_cache()) {
1517
struct path_list *entries, *re_head, *re_merge;
1518
int i;
1519
path_list_clear(¤t_file_set, 1);
builtin-reset.c
+1
-13
@@ -44,18 +44,6 @@ static inline int is_merge(void)
44
return !access(git_path("MERGE_HEAD"), F_OK);
45
}
46
47
-static int unmerged_files(void)
48
-{
49
- int i;
50
- read_cache();
51
- for (i = 0; i < active_nr; i++) {
52
- struct cache_entry *ce = active_cache[i];
53
- if (ce_stage(ce))
54
- return 1;
55
- }
56
- return 0;
57
-}
58
-
47
static int reset_index_file(const unsigned char *sha1, int is_hard_reset)
48
{
49
int i = 0;
@@ -250,7 +238,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
238
* at all, but requires them in a good order. Other resets reset
239
* the index file to the tree object we are switching to. */
240
if (reset_type == SOFT) {
253
- if (is_merge() || unmerged_files())
241
+ if (is_merge() || read_cache() < 0 || unmerged_cache())
242
die("Cannot do a soft reset in the middle of a merge.");
243
}
244
else if (reset_index_file(sha1, (reset_type == HARD)))
cache.h
+2
@@ -208,6 +208,7 @@ extern struct index_state the_index;
208
#define read_cache_from(path) read_index_from(&the_index, (path))
209
#define write_cache(newfd, cache, entries) write_index(&the_index, (newfd))
210
#define discard_cache() discard_index(&the_index)
211
+#define unmerged_cache() unmerged_index(&the_index)
212
#define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen))
213
#define add_cache_entry(ce, option) add_index_entry(&the_index, (ce), (option))
214
#define remove_cache_entry_at(pos) remove_index_entry_at(&the_index, (pos))
@@ -302,6 +303,7 @@ extern int read_index(struct index_state *);
303
extern int read_index_from(struct index_state *, const char *path);
304
extern int write_index(struct index_state *, int newfd);
305
extern int discard_index(struct index_state *);
306
+extern int unmerged_index(struct index_state *);
307
extern int verify_path(const char *path);
308
extern int index_name_exists(struct index_state *istate, const char *name, int namelen);
309
extern int index_name_pos(struct index_state *, const char *name, int namelen);
read-cache.c
+10
@@ -1176,6 +1176,16 @@ int discard_index(struct index_state *istate)
1176
return 0;
1177
}
1178
1179
+int unmerged_index(struct index_state *istate)
1180
+{
1181
+ int i;
1182
+ for (i = 0; i < istate->cache_nr; i++) {
1183
+ if (ce_stage(istate->cache[i]))
1184
+ return 1;
1185
+ }
1186
+ return 0;
1187
+}
1188
+
1189
#define WRITE_BUFFER_SIZE 8192
1190
static unsigned char write_buffer[WRITE_BUFFER_SIZE];
1191
static unsigned long write_buffer_len;