diff options
author | Junio C Hamano <gitster@pobox.com> | 2018-03-21 11:30:10 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-03-21 11:30:10 -0700 |
commit | beb2cdf5041104a7513301a9b20944a617eec94e (patch) | |
tree | 6f44e7c048bc9857025235064b956a5d1d53ee25 /builtin | |
parent | 75901dfd52ef97df51621a23156db96c9cd4a90b (diff) | |
parent | 610008146ed1647bb1da6a098e314b8929ff213e (diff) | |
download | git-beb2cdf5041104a7513301a9b20944a617eec94e.tar.gz |
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
Diffstat (limited to 'builtin')
-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 |
5 files changed, 17 insertions, 26 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; } |