@@ -186,13 +186,16 @@ int git_mwindow_free_all(git_mwindow_file *mwf)
186186}
187187
188188/*
189- * Check if a window 'win' contains the address 'offset'
189+ * Check if a window 'win' contains both the address 'offset' and 'extra'.
190+ *
191+ * 'extra' is the size of the hash we're using as we always want to make sure
192+ * that it's contained.
190193 */
191- int git_mwindow_contains (git_mwindow * win , off64_t offset )
194+ int git_mwindow_contains (git_mwindow * win , off64_t offset , off64_t extra )
192195{
193196 off64_t win_off = win -> offset ;
194197 return win_off <= offset
195- && offset <= (off64_t )(win_off + win -> window_map .len );
198+ && ( offset + extra ) <= (off64_t )(win_off + win -> window_map .len );
196199}
197200
198201#define GIT_MWINDOW__LRU -1
@@ -237,9 +240,7 @@ static bool git_mwindow_scan_recently_used(
237240 * store it in the output parameter. If lru_window is NULL,
238241 * it's the first loop, so store it as well.
239242 */
240- if (!lru_window ||
241- (comparison_sign == GIT_MWINDOW__LRU && lru_window -> last_used > w -> last_used ) ||
242- (comparison_sign == GIT_MWINDOW__MRU && lru_window -> last_used < w -> last_used )) {
243+ if (!lru_window || (comparison_sign * w -> last_used ) > lru_window -> last_used ) {
243244 lru_window = w ;
244245 lru_last = w_last ;
245246 found = true;
@@ -406,14 +407,13 @@ unsigned char *git_mwindow_open(
406407 return NULL ;
407408 }
408409
409- if (!w || !(git_mwindow_contains (w , offset ) && git_mwindow_contains ( w , offset + extra ))) {
410+ if (!w || !(git_mwindow_contains (w , offset , extra ))) {
410411 if (w ) {
411412 w -> inuse_cnt -- ;
412413 }
413414
414415 for (w = mwf -> windows ; w ; w = w -> next ) {
415- if (git_mwindow_contains (w , offset ) &&
416- git_mwindow_contains (w , offset + extra ))
416+ if (git_mwindow_contains (w , offset , extra ))
417417 break ;
418418 }
419419
0 commit comments