* The LRU pack is the one with the oldest MRU window, preferring packs * with no used windows, or the oldest mtime if it has no windows allocated. */
| 482 | * with no used windows, or the oldest mtime if it has no windows allocated. |
| 483 | */ |
| 484 | static void find_lru_pack(struct packed_git *p, struct packed_git **lru_p, struct pack_window **mru_w, int *accept_windows_inuse) |
| 485 | { |
| 486 | struct pack_window *w, *this_mru_w; |
| 487 | int has_windows_inuse = 0; |
| 488 | |
| 489 | /* |
| 490 | * Reject this pack if it has windows and the previously selected |
| 491 | * one does not. If this pack does not have windows, reject |
| 492 | * it if the pack file is newer than the previously selected one. |
| 493 | */ |
| 494 | if (*lru_p && !*mru_w && (p->windows || p->mtime > (*lru_p)->mtime)) |
| 495 | return; |
| 496 | |
| 497 | for (w = this_mru_w = p->windows; w; w = w->next) { |
| 498 | /* |
| 499 | * Reject this pack if any of its windows are in use, |
| 500 | * but the previously selected pack did not have any |
| 501 | * inuse windows. Otherwise, record that this pack |
| 502 | * has windows in use. |
| 503 | */ |
| 504 | if (w->inuse_cnt) { |
| 505 | if (*accept_windows_inuse) |
| 506 | has_windows_inuse = 1; |
| 507 | else |
| 508 | return; |
| 509 | } |
| 510 | |
| 511 | if (w->last_used > this_mru_w->last_used) |
| 512 | this_mru_w = w; |
| 513 | |
| 514 | /* |
| 515 | * Reject this pack if it has windows that have been |
| 516 | * used more recently than the previously selected pack. |
| 517 | * If the previously selected pack had windows inuse and |
| 518 | * we have not encountered a window in this pack that is |
| 519 | * inuse, skip this check since we prefer a pack with no |
| 520 | * inuse windows to one that has inuse windows. |
| 521 | */ |
| 522 | if (*mru_w && *accept_windows_inuse == has_windows_inuse && |
| 523 | this_mru_w->last_used > (*mru_w)->last_used) |
| 524 | return; |
| 525 | } |
| 526 | |
| 527 | /* |
| 528 | * Select this pack. |
| 529 | */ |
| 530 | *mru_w = this_mru_w; |
| 531 | *lru_p = p; |
| 532 | *accept_windows_inuse = has_windows_inuse; |
| 533 | } |
| 534 | |
| 535 | static int close_one_pack(struct repository *r) |
| 536 | { |