summaryrefslogtreecommitdiff
path: root/src/status.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-10-31 14:36:52 -0700
committerRussell Belfer <rb@github.com>2013-11-01 10:20:51 -0700
commit4bf630b6baf342fa929a8f7e4e6643197b74216f (patch)
tree95778a5807b4043202eaea18a266a264e611649c /src/status.c
parent3940310e29363978ccdc1f3b557bc6f48ebae8f0 (diff)
downloadlibgit2-4bf630b6baf342fa929a8f7e4e6643197b74216f.tar.gz
Make diff and status perform soft index reload
This changes `git_index_read` to have two modes - a hard index reload that always resets the index to match the on-disk data (which was the old behavior) and a soft index reload that uses the timestamp / file size information and only replaces the index data if the file on disk has been modified. This then updates the git_status code to do a soft reload unless the new GIT_STATUS_OPT_NO_REFRESH flag is passed in. This also changes the behavior of the git_diff functions that use the index so that when an index is not explicitly passed in (i.e. when the functions call git_repository_index for you), they will also do a soft reload for you. This intentionally breaks the file signature of git_index_read because there has been some confusion about the behavior previously and it seems like all existing uses of the API should probably be examined to select the desired behavior.
Diffstat (limited to 'src/status.c')
-rw-r--r--src/status.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/status.c b/src/status.c
index 2b84794b5..74bccf7a1 100644
--- a/src/status.c
+++ b/src/status.c
@@ -251,12 +251,17 @@ int git_status_list_new(
return error;
/* if there is no HEAD, that's okay - we'll make an empty iterator */
- if (((error = git_repository_head_tree(&head, repo)) < 0) &&
- error != GIT_ENOTFOUND && error != GIT_EUNBORNBRANCH) {
- git_index_free(index); /* release index */
- return error;
+ if ((error = git_repository_head_tree(&head, repo)) < 0) {
+ if (error != GIT_ENOTFOUND && error != GIT_EUNBORNBRANCH)
+ goto done;
+ giterr_clear();
}
+ /* refresh index from disk unless prevented */
+ if ((flags & GIT_STATUS_OPT_NO_REFRESH) == 0 &&
+ git_index_read(index, true) < 0)
+ giterr_clear();
+
status = git_status_list_alloc(index);
GITERR_CHECK_ALLOC(status);
@@ -291,7 +296,7 @@ int git_status_list_new(
if (show != GIT_STATUS_SHOW_WORKDIR_ONLY) {
if ((error = git_diff_tree_to_index(
- &status->head2idx, repo, head, NULL, &diffopt)) < 0)
+ &status->head2idx, repo, head, index, &diffopt)) < 0)
goto done;
if ((flags & GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX) != 0 &&
@@ -301,7 +306,7 @@ int git_status_list_new(
if (show != GIT_STATUS_SHOW_INDEX_ONLY) {
if ((error = git_diff_index_to_workdir(
- &status->idx2wd, repo, NULL, &diffopt)) < 0)
+ &status->idx2wd, repo, index, &diffopt)) < 0)
goto done;
if ((flags & GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR) != 0 &&