Add Git Blame menu item for tracked files
[git-cheetah/kirill.git] / sha1_file.c
blob35f84e9069fb94c999ca5335b5e98a0d3ac18944
2 #include "cache.h"
4 static unsigned int pack_open_windows;
5 static size_t pack_mapped;
6 struct packed_git *packed_git;
8 static void scan_windows(struct packed_git *p,
9 struct packed_git **lru_p,
10 struct pack_window **lru_w,
11 struct pack_window **lru_l)
13 struct pack_window *w, *w_l;
15 for (w_l = NULL, w = p->windows; w; w = w->next) {
16 if (!w->inuse_cnt) {
17 if (!*lru_w || w->last_used < (*lru_w)->last_used) {
18 *lru_p = p;
19 *lru_w = w;
20 *lru_l = w_l;
23 w_l = w;
27 static int unuse_one_window(struct packed_git *current, int keep_fd)
29 struct packed_git *p, *lru_p = NULL;
30 struct pack_window *lru_w = NULL, *lru_l = NULL;
32 if (current)
33 scan_windows(current, &lru_p, &lru_w, &lru_l);
34 for (p = packed_git; p; p = p->next)
35 scan_windows(p, &lru_p, &lru_w, &lru_l);
36 if (lru_p) {
37 munmap(lru_w->base, lru_w->len);
38 pack_mapped -= lru_w->len;
39 if (lru_l)
40 lru_l->next = lru_w->next;
41 else {
42 lru_p->windows = lru_w->next;
43 if (!lru_p->windows && lru_p->pack_fd != keep_fd) {
44 close(lru_p->pack_fd);
45 lru_p->pack_fd = -1;
48 free(lru_w);
49 pack_open_windows--;
50 return 1;
52 return 0;
55 void release_pack_memory(size_t need, int fd)
57 size_t cur = pack_mapped;
58 while (need >= (cur - pack_mapped) && unuse_one_window(NULL, fd))
59 ; /* nothing */