[PATCH 2/3] merge: use refresh_and_write_cache
- From
Thomas Gummerer <t.gummerer@gmail.com>
- Date
- Aug 27, 2019, 10:14 UTC
- Message-ID
- <20190827101408.76757-3-t.gummerer@gmail.com>
- In-Reply-To
- <20190827101408.76757-1-t.gummerer@gmail.com>
Use the 'refresh_and_write_cache()' convenience function introduced in the last commit, instead of refreshing and writing the index manually in merge.c
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com> --- builtin/merge.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
diff --git a/builtin/merge.c b/builtin/merge.c index e2ccbc44e2..b5e31ce283 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -691,11 +691,8 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common, struct lock_file lock = LOCK_INIT; const char *head_arg = "HEAD"; - hold_locked_index(&lock, LOCK_DIE_ON_ERROR); - refresh_cache(REFRESH_QUIET); - if (write_locked_index(&the_index, &lock, - COMMIT_LOCK | SKIP_IF_UNCHANGED)) - return error(_("Unable to write index.")); + if (refresh_and_write_cache(REFRESH_QUIET, COMMIT_LOCK | SKIP_IF_UNCHANGED) < 0) + return -1; if (!strcmp(strategy, "recursive") || !strcmp(strategy, "subtree")) { int clean, x; @@ -860,13 +857,9 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads) { struct object_id result_tree, result_commit; struct commit_list *parents, **pptr = &parents; - struct lock_file lock = LOCK_INIT; - hold_locked_index(&lock, LOCK_DIE_ON_ERROR); - refresh_cache(REFRESH_QUIET); - if (write_locked_index(&the_index, &lock, - COMMIT_LOCK | SKIP_IF_UNCHANGED)) - return error(_("Unable to write index.")); + if (refresh_and_write_cache(REFRESH_QUIET, COMMIT_LOCK | SKIP_IF_UNCHANGED) < 0) + return -1; write_tree_trivial(&result_tree); printf(_("Wonderful.\n"));
-- 2.23.0.rc2.194.ge5444969c9