Preserve behaviour of `git_mwindow_scan_recently_used` with `*out_window` set
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
diff --git a/src/mwindow.c b/src/mwindow.c
index bb28e20..ac26452 100644
--- a/src/mwindow.c
+++ b/src/mwindow.c
@@ -184,7 +184,8 @@ int git_mwindow_contains(git_mwindow *win, off64_t offset)
/*
* Find the least- or most-recently-used window in a file that is not currently
* being used. The 'only_unused' flag controls whether the caller requires the
- * file to only have unused windows.
+ * file to only have unused windows. If '*out_window' is non-null, it is used as
+ * a starting point for the comparison.
*
* Returns whether such a window was found in the file.
*/
@@ -197,10 +198,15 @@ static bool git_mwindow_scan_recently_used(
{
git_mwindow *w, *w_last;
git_mwindow *lru_window = NULL, *lru_last = NULL;
+ bool found = false;
assert(mwf);
assert(out_window);
+ lru_window = *out_window;
+ if (out_last)
+ lru_last = *out_last;
+
for (w_last = NULL, w = mwf->windows; w; w_last = w, w = w->next) {
if (w->inuse_cnt) {
if (only_unused)
@@ -219,10 +225,11 @@ static bool git_mwindow_scan_recently_used(
(comparison_sign == GIT_MWINDOW__MRU && lru_window->last_used < w->last_used)) {
lru_window = w;
lru_last = w_last;
+ found = true;
}
}
- if (!lru_window)
+ if (!found)
return false;
*out_window = lru_window;