mirror of
https://git.proxmox.com/git/libgit2
synced 2025-08-11 10:25:14 +00:00
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.
This commit is contained in:
parent
32b9e647c5
commit
cb0ff012d3
41
src/index.c
41
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;
|
||||
|
||||
/* TODO: use the (non-fnmatching) filelist iterator */
|
||||
diff_opts.pathspec.count = 1;
|
||||
diff_opts.pathspec.strings = (char **) &entry->path;
|
||||
|
||||
if ((error = git_diff_index_to_workdir(&diff, INDEX_OWNER(index), index, &diff_opts)) < 0)
|
||||
return error;
|
||||
|
||||
if (git_diff_num_deltas(diff) > 0)
|
||||
entry->file_size = 0;
|
||||
|
||||
git_diff_free(diff);
|
||||
git_vector_insert(&paths, (char *)entry->path);
|
||||
}
|
||||
|
||||
if (paths.length == 0)
|
||||
goto done;
|
||||
|
||||
diff_opts.pathspec.count = paths.length;
|
||||
diff_opts.pathspec.strings = (char **)paths.contents;
|
||||
|
||||
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);
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user