diff options
author | Russell Belfer <rb@github.com> | 2013-11-01 01:36:52 +0400 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2013-11-01 21:20:51 +0400 |
commit | 4bf630b6baf342fa929a8f7e4e6643197b74216f (patch) | |
tree | 95778a5807b4043202eaea18a266a264e611649c /src/index.c | |
parent | 3940310e29363978ccdc1f3b557bc6f48ebae8f0 (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/index.c')
-rw-r--r-- | src/index.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/index.c b/src/index.c index 5cdd40aaa..19de43d29 100644 --- a/src/index.c +++ b/src/index.c @@ -349,7 +349,7 @@ int git_index_open(git_index **index_out, const char *index_path) *index_out = index; GIT_REFCOUNT_INC(index); - return (index_path != NULL) ? git_index_read(index) : 0; + return (index_path != NULL) ? git_index_read(index, false) : 0; } int git_index_new(git_index **out) @@ -451,11 +451,11 @@ unsigned int git_index_caps(const git_index *index) (index->no_symlinks ? GIT_INDEXCAP_NO_SYMLINKS : 0)); } -int git_index_read(git_index *index) +int git_index_read(git_index *index, int only_if_changed) { int error = 0, updated; git_buf buffer = GIT_BUF_INIT; - git_futils_filestamp stamp = {0}; + git_futils_filestamp stamp = index->stamp; if (!index->index_file_path) return create_index_error(-1, @@ -464,12 +464,13 @@ int git_index_read(git_index *index) index->on_disk = git_path_exists(index->index_file_path); if (!index->on_disk) { - git_index_clear(index); + if (!only_if_changed) + git_index_clear(index); return 0; } updated = git_futils_filestamp_check(&stamp, index->index_file_path); - if (updated <= 0) + if (updated < 0 || (only_if_changed && !updated)) return updated; error = git_futils_readbuffer(&buffer, index->index_file_path); |