summaryrefslogtreecommitdiff
path: root/read-cache.c
diff options
context:
space:
mode:
Diffstat (limited to 'read-cache.c')
-rw-r--r--read-cache.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/read-cache.c b/read-cache.c
index cff1280..133f790 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1276,7 +1276,7 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
*/
if (istate->cache_nr > 0 &&
strcmp(ce->name, istate->cache[istate->cache_nr - 1]->name) > 0)
- pos = -istate->cache_nr - 1;
+ pos = index_pos_to_insert_pos(istate->cache_nr);
else
pos = index_name_stage_pos(istate, ce->name, ce_namelen(ce), ce_stage(ce));
@@ -1472,6 +1472,27 @@ static void show_file(const char * fmt, const char * name, int in_porcelain,
printf(fmt, name);
}
+int repo_refresh_and_write_index(struct repository *repo,
+ unsigned int refresh_flags,
+ unsigned int write_flags,
+ int gentle,
+ const struct pathspec *pathspec,
+ char *seen, const char *header_msg)
+{
+ struct lock_file lock_file = LOCK_INIT;
+ int fd, ret = 0;
+
+ fd = repo_hold_locked_index(repo, &lock_file, 0);
+ if (!gentle && fd < 0)
+ return -1;
+ if (refresh_index(repo->index, refresh_flags, pathspec, seen, header_msg))
+ ret = 1;
+ if (0 <= fd && write_locked_index(repo->index, &lock_file, COMMIT_LOCK | write_flags))
+ ret = -1;
+ return ret;
+}
+
+
int refresh_index(struct index_state *istate, unsigned int flags,
const struct pathspec *pathspec,
char *seen, const char *header_msg)
@@ -1894,7 +1915,7 @@ static size_t estimate_cache_size(size_t ondisk_size, unsigned int entries)
/*
* Account for potential alignment differences.
*/
- per_entry += align_padding_size(sizeof(struct cache_entry), -sizeof(struct ondisk_cache_entry));
+ per_entry += align_padding_size(per_entry, 0);
return ondisk_size + entries * per_entry;
}