Skip to content

Commit 04d5946

Browse files
committed
Preserve behaviour of git_mwindow_scan_recently_used with *out_window set
1 parent 8ea9187 commit 04d5946

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/mwindow.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ int git_mwindow_contains(git_mwindow *win, off64_t offset)
184184
/*
185185
* Find the least- or most-recently-used window in a file that is not currently
186186
* being used. The 'only_unused' flag controls whether the caller requires the
187-
* file to only have unused windows.
187+
* file to only have unused windows. If '*out_window' is non-null, it is used as
188+
* a starting point for the comparison.
188189
*
189190
* Returns whether such a window was found in the file.
190191
*/
@@ -197,10 +198,15 @@ static bool git_mwindow_scan_recently_used(
197198
{
198199
git_mwindow *w, *w_last;
199200
git_mwindow *lru_window = NULL, *lru_last = NULL;
201+
bool found = false;
200202

201203
assert(mwf);
202204
assert(out_window);
203205

206+
lru_window = *out_window;
207+
if (out_last)
208+
lru_last = *out_last;
209+
204210
for (w_last = NULL, w = mwf->windows; w; w_last = w, w = w->next) {
205211
if (w->inuse_cnt) {
206212
if (only_unused)
@@ -219,10 +225,11 @@ static bool git_mwindow_scan_recently_used(
219225
(comparison_sign == GIT_MWINDOW__MRU && lru_window->last_used < w->last_used)) {
220226
lru_window = w;
221227
lru_last = w_last;
228+
found = true;
222229
}
223230
}
224231

225-
if (!lru_window)
232+
if (!found)
226233
return false;
227234

228235
*out_window = lru_window;

0 commit comments

Comments
 (0)