diff options
author | Edward Thomson <ethomson@microsoft.com> | 2015-11-06 17:15:35 -0500 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2015-11-16 22:58:57 -0500 |
commit | cb0ff012d3cb9658b88ad4f752046286ba5ea442 (patch) | |
tree | fb581ca6a8c64eb61e00757bafc12a71ad750b23 /src | |
parent | 32b9e647c5a91bb2cfb42822d86962054cfeeeea (diff) | |
download | libgit2-cb0ff012d3cb9658b88ad4f752046286ba5ea442.tar.gz |
racy-git: do a single index->workdir diff
When examining paths that are racily clean, do a single index->workdir
diff over the entirety of the racily clean files, instead of a diff
per file.
Diffstat (limited to 'src')
-rw-r--r-- | src/index.c | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/src/index.c b/src/index.c index 0903770bb..9eb1289c3 100644 --- a/src/index.c +++ b/src/index.c @@ -18,6 +18,7 @@ #include "ignore.h" #include "blob.h" #include "idxmap.h" +#include "diff.h" #include "git2/odb.h" #include "git2/oid.h" @@ -752,7 +753,9 @@ static int truncate_racily_clean(git_index *index) int error; git_index_entry *entry; git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT; - git_diff *diff; + git_diff *diff = NULL; + git_vector paths = GIT_VECTOR_INIT; + git_diff_delta *delta; /* Nothing to do if there's no repo to talk about */ if (!INDEX_OWNER(index)) @@ -765,21 +768,31 @@ static int truncate_racily_clean(git_index *index) diff_opts.flags |= GIT_DIFF_INCLUDE_TYPECHANGE | GIT_DIFF_IGNORE_SUBMODULES | GIT_DIFF_DISABLE_PATHSPEC_MATCH; git_vector_foreach(&index->entries, i, entry) { if (!is_racy_timestamp(&index->stamp.mtime, entry)) - continue; + git_vector_insert(&paths, (char *)entry->path); + } - /* TODO: use the (non-fnmatching) filelist iterator */ - diff_opts.pathspec.count = 1; - diff_opts.pathspec.strings = (char **) &entry->path; + if (paths.length == 0) + goto done; - if ((error = git_diff_index_to_workdir(&diff, INDEX_OWNER(index), index, &diff_opts)) < 0) - return error; + diff_opts.pathspec.count = paths.length; + diff_opts.pathspec.strings = (char **)paths.contents; - if (git_diff_num_deltas(diff) > 0) - entry->file_size = 0; + if ((error = git_diff_index_to_workdir(&diff, INDEX_OWNER(index), index, &diff_opts)) < 0) + return error; + + git_vector_foreach(&diff->deltas, i, delta) { + entry = (git_index_entry *)git_index_get_bypath(index, delta->old_file.path, 0); - git_diff_free(diff); + /* Ensure that we have a stage 0 for this file (ie, it's not a + * conflict), otherwise smudging it is quite pointless. + */ + if (entry) + entry->file_size = 0; } +done: + git_diff_free(diff); + git_vector_free(&paths); return 0; } |