diff options
author | Junio C Hamano <gitster@pobox.com> | 2018-03-21 19:30:10 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-03-21 19:30:10 +0100 |
commit | beb2cdf5041104a7513301a9b20944a617eec94e (patch) | |
tree | 6f44e7c048bc9857025235064b956a5d1d53ee25 | |
parent | Merge branch 'ma/config-page-only-in-list-mode' (diff) | |
parent | write_locked_index(): add flag to avoid writing unchanged index (diff) | |
download | git-beb2cdf5041104a7513301a9b20944a617eec94e.tar.xz git-beb2cdf5041104a7513301a9b20944a617eec94e.zip |
Merge branch 'ma/skip-writing-unchanged-index'
Internal API clean-up to allow write_locked_index() optionally skip
writing the in-core index when it is not modified.
* ma/skip-writing-unchanged-index:
write_locked_index(): add flag to avoid writing unchanged index
-rw-r--r-- | builtin/add.c | 7 | ||||
-rw-r--r-- | builtin/commit.c | 10 | ||||
-rw-r--r-- | builtin/merge.c | 15 | ||||
-rw-r--r-- | builtin/mv.c | 4 | ||||
-rw-r--r-- | builtin/rm.c | 7 | ||||
-rw-r--r-- | cache.h | 4 | ||||
-rw-r--r-- | merge-recursive.c | 5 | ||||
-rw-r--r-- | read-cache.c | 6 | ||||
-rw-r--r-- | rerere.c | 8 | ||||
-rw-r--r-- | sequencer.c | 11 |
10 files changed, 37 insertions, 40 deletions
diff --git a/builtin/add.c b/builtin/add.c index ac7c1c3277..9ef7fb02d5 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -534,10 +534,9 @@ int cmd_add(int argc, const char **argv, const char *prefix) unplug_bulk_checkin(); finish: - if (active_cache_changed) { - if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK)) - die(_("Unable to write new index file")); - } + if (write_locked_index(&the_index, &lock_file, + COMMIT_LOCK | SKIP_IF_UNCHANGED)) + die(_("Unable to write new index file")); UNLEAK(pathspec); UNLEAK(dir); diff --git a/builtin/commit.c b/builtin/commit.c index 092077c3ee..37fcb55ab0 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -389,13 +389,9 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix if (active_cache_changed || !cache_tree_fully_valid(active_cache_tree)) update_main_cache_tree(WRITE_TREE_SILENT); - if (active_cache_changed) { - if (write_locked_index(&the_index, &index_lock, - COMMIT_LOCK)) - die(_("unable to write new_index file")); - } else { - rollback_lock_file(&index_lock); - } + if (write_locked_index(&the_index, &index_lock, + COMMIT_LOCK | SKIP_IF_UNCHANGED)) + die(_("unable to write new_index file")); commit_style = COMMIT_AS_IS; ret = get_index_file(); goto out; diff --git a/builtin/merge.c b/builtin/merge.c index e8d9d4383e..ee050a47f3 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -652,10 +652,9 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common, hold_locked_index(&lock, LOCK_DIE_ON_ERROR); refresh_cache(REFRESH_QUIET); - if (active_cache_changed && - write_locked_index(&the_index, &lock, COMMIT_LOCK)) + if (write_locked_index(&the_index, &lock, + COMMIT_LOCK | SKIP_IF_UNCHANGED)) return error(_("Unable to write index.")); - rollback_lock_file(&lock); if (!strcmp(strategy, "recursive") || !strcmp(strategy, "subtree")) { int clean, x; @@ -692,10 +691,9 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common, remoteheads->item, reversed, &result); if (clean < 0) exit(128); - if (active_cache_changed && - write_locked_index(&the_index, &lock, COMMIT_LOCK)) + if (write_locked_index(&the_index, &lock, + COMMIT_LOCK | SKIP_IF_UNCHANGED)) die (_("unable to write %s"), get_index_file()); - rollback_lock_file(&lock); return clean ? 0 : 1; } else { return try_merge_command(strategy, xopts_nr, xopts, @@ -811,10 +809,9 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads) hold_locked_index(&lock, LOCK_DIE_ON_ERROR); refresh_cache(REFRESH_QUIET); - if (active_cache_changed && - write_locked_index(&the_index, &lock, COMMIT_LOCK)) + if (write_locked_index(&the_index, &lock, + COMMIT_LOCK | SKIP_IF_UNCHANGED)) return error(_("Unable to write index.")); - rollback_lock_file(&lock); write_tree_trivial(&result_tree); printf(_("Wonderful.\n")); diff --git a/builtin/mv.c b/builtin/mv.c index 8eceb310aa..6d141f7a53 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -293,8 +293,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix) if (gitmodules_modified) stage_updated_gitmodules(&the_index); - if (active_cache_changed && - write_locked_index(&the_index, &lock_file, COMMIT_LOCK)) + if (write_locked_index(&the_index, &lock_file, + COMMIT_LOCK | SKIP_IF_UNCHANGED)) die(_("Unable to write new index file")); return 0; diff --git a/builtin/rm.c b/builtin/rm.c index a818efe230..4447bb4d0f 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -385,10 +385,9 @@ int cmd_rm(int argc, const char **argv, const char *prefix) stage_updated_gitmodules(&the_index); } - if (active_cache_changed) { - if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK)) - die(_("Unable to write new index file")); - } + if (write_locked_index(&the_index, &lock_file, + COMMIT_LOCK | SKIP_IF_UNCHANGED)) + die(_("Unable to write new index file")); return 0; } @@ -599,6 +599,7 @@ extern int read_index_unmerged(struct index_state *); /* For use with `write_locked_index()`. */ #define COMMIT_LOCK (1 << 0) +#define SKIP_IF_UNCHANGED (1 << 1) /* * Write the index while holding an already-taken lock. Close the lock, @@ -615,6 +616,9 @@ extern int read_index_unmerged(struct index_state *); * With `COMMIT_LOCK`, the lock is always committed or rolled back. * Without it, the lock is closed, but neither committed nor rolled * back. + * + * If `SKIP_IF_UNCHANGED` is given and the index is unchanged, nothing + * is written (and the lock is rolled back if `COMMIT_LOCK` is given). */ extern int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags); diff --git a/merge-recursive.c b/merge-recursive.c index 129577987b..2f232ad3b4 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -2223,10 +2223,9 @@ int merge_recursive_generic(struct merge_options *o, return clean; } - if (active_cache_changed && - write_locked_index(&the_index, &lock, COMMIT_LOCK)) + if (write_locked_index(&the_index, &lock, + COMMIT_LOCK | SKIP_IF_UNCHANGED)) return err(o, _("Unable to write index.")); - rollback_lock_file(&lock); return clean ? 0 : 1; } diff --git a/read-cache.c b/read-cache.c index 977921d90c..d05eb725b5 100644 --- a/read-cache.c +++ b/read-cache.c @@ -2538,6 +2538,12 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock, int new_shared_index, ret; struct split_index *si = istate->split_index; + if ((flags & SKIP_IF_UNCHANGED) && !istate->cache_changed) { + if (flags & COMMIT_LOCK) + rollback_lock_file(lock); + return 0; + } + if (istate->fsmonitor_last_update) fill_fsmonitor_bitmap(istate); @@ -719,11 +719,9 @@ static void update_paths(struct string_list *update) item->string); } - if (active_cache_changed) { - if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK)) - die("Unable to write new index file"); - } else - rollback_lock_file(&index_lock); + if (write_locked_index(&the_index, &index_lock, + COMMIT_LOCK | SKIP_IF_UNCHANGED)) + die("Unable to write new index file"); } static void remove_variant(struct rerere_id *id) diff --git a/sequencer.c b/sequencer.c index 091bd6bda5..f9d1001dee 100644 --- a/sequencer.c +++ b/sequencer.c @@ -517,15 +517,14 @@ static int do_recursive_merge(struct commit *base, struct commit *next, return clean; } - if (active_cache_changed && - write_locked_index(&the_index, &index_lock, COMMIT_LOCK)) + if (write_locked_index(&the_index, &index_lock, + COMMIT_LOCK | SKIP_IF_UNCHANGED)) /* * TRANSLATORS: %s will be "revert", "cherry-pick" or * "rebase -i". */ return error(_("%s: Unable to write new index file"), _(action_name(opts))); - rollback_lock_file(&index_lock); if (!clean) append_conflicts_hint(msgbuf); @@ -1713,13 +1712,13 @@ static int read_and_refresh_cache(struct replay_opts *opts) _(action_name(opts))); } refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL); - if (the_index.cache_changed && index_fd >= 0) { - if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK)) { + if (index_fd >= 0) { + if (write_locked_index(&the_index, &index_lock, + COMMIT_LOCK | SKIP_IF_UNCHANGED)) { return error(_("git %s: failed to refresh the index"), _(action_name(opts))); } } - rollback_lock_file(&index_lock); return 0; } |