Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-11-01 01:36:52 +0400
committerRussell Belfer <rb@github.com>2013-11-01 21:20:51 +0400
commit4bf630b6baf342fa929a8f7e4e6643197b74216f (patch)
tree95778a5807b4043202eaea18a266a264e611649c /src/diff.c
parent3940310e29363978ccdc1f3b557bc6f48ebae8f0 (diff)
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/diff.c')
-rw-r--r--src/diff.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/diff.c b/src/diff.c
index b1f64e6a3..d1ff04b52 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -1184,6 +1184,17 @@ int git_diff_tree_to_tree(
return error;
}
+static int diff_load_index(git_index **index, git_repository *repo)
+{
+ int error = git_repository_index__weakptr(index, repo);
+
+ /* reload the repository index when user did not pass one in */
+ if (!error && git_index_read(*index, true) < 0)
+ giterr_clear();
+
+ return error;
+}
+
int git_diff_tree_to_index(
git_diff **diff,
git_repository *repo,
@@ -1196,7 +1207,7 @@ int git_diff_tree_to_index(
assert(diff && repo);
- if (!index && (error = git_repository_index__weakptr(&index, repo)) < 0)
+ if (!index && (error = diff_load_index(&index, repo)) < 0)
return error;
if (index->ignore_case) {
@@ -1239,7 +1250,7 @@ int git_diff_index_to_workdir(
assert(diff && repo);
- if (!index && (error = git_repository_index__weakptr(&index, repo)) < 0)
+ if (!index && (error = diff_load_index(&index, repo)) < 0)
return error;
DIFF_FROM_ITERATORS(
@@ -1278,11 +1289,15 @@ int git_diff_tree_to_workdir_with_index(
{
int error = 0;
git_diff *d1 = NULL, *d2 = NULL;
+ git_index *index = NULL;
assert(diff && repo);
- if (!(error = git_diff_tree_to_index(&d1, repo, old_tree, NULL, opts)) &&
- !(error = git_diff_index_to_workdir(&d2, repo, NULL, opts)))
+ if ((error = diff_load_index(&index, repo)) < 0)
+ return error;
+
+ if (!(error = git_diff_tree_to_index(&d1, repo, old_tree, index, opts)) &&
+ !(error = git_diff_index_to_workdir(&d2, repo, index, opts)))
error = git_diff_merge(d1, d2);
git_diff_free(d2);