]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pack: move release_pack_memory()
authorJonathan Tan <jonathantanmy@google.com>
Fri, 18 Aug 2017 22:20:20 +0000 (15:20 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 Aug 2017 22:12:06 +0000 (15:12 -0700)
The function unuse_one_window() needs to be temporarily made global. Its
scope will be restored to static in a subsequent commit.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-compat-util.h
packfile.c
packfile.h
sha1_file.c

index 7d2c0ca75922ea1ca8c67ec798ff8ce1249c925f..6678b488cc73851d468094deb5352d311ab310d0 100644 (file)
@@ -749,8 +749,6 @@ const char *inet_ntop(int af, const void *src, char *dst, size_t size);
 extern int git_atexit(void (*handler)(void));
 #endif
 
-extern void release_pack_memory(size_t);
-
 typedef void (*try_to_free_t)(size_t);
 extern try_to_free_t set_try_to_free_routine(try_to_free_t);
 
index 6edc432288b40d8f378e2bab5b9f0182b4c4bea9..8daa74ad11b5d473235fba9fa5270aaaf81689e6 100644 (file)
@@ -208,3 +208,52 @@ struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path)
 
        return p;
 }
+
+static void scan_windows(struct packed_git *p,
+       struct packed_git **lru_p,
+       struct pack_window **lru_w,
+       struct pack_window **lru_l)
+{
+       struct pack_window *w, *w_l;
+
+       for (w_l = NULL, w = p->windows; w; w = w->next) {
+               if (!w->inuse_cnt) {
+                       if (!*lru_w || w->last_used < (*lru_w)->last_used) {
+                               *lru_p = p;
+                               *lru_w = w;
+                               *lru_l = w_l;
+                       }
+               }
+               w_l = w;
+       }
+}
+
+int unuse_one_window(struct packed_git *current)
+{
+       struct packed_git *p, *lru_p = NULL;
+       struct pack_window *lru_w = NULL, *lru_l = NULL;
+
+       if (current)
+               scan_windows(current, &lru_p, &lru_w, &lru_l);
+       for (p = packed_git; p; p = p->next)
+               scan_windows(p, &lru_p, &lru_w, &lru_l);
+       if (lru_p) {
+               munmap(lru_w->base, lru_w->len);
+               pack_mapped -= lru_w->len;
+               if (lru_l)
+                       lru_l->next = lru_w->next;
+               else
+                       lru_p->windows = lru_w->next;
+               free(lru_w);
+               pack_open_windows--;
+               return 1;
+       }
+       return 0;
+}
+
+void release_pack_memory(size_t need)
+{
+       size_t cur = pack_mapped;
+       while (need >= (cur - pack_mapped) && unuse_one_window(NULL))
+               ; /* nothing */
+}
index 703887d41ba8315d45feb301de4e16d1f4d5ac0d..f6fe1c74184266a66e026718ff1f90dc4fa1a176 100644 (file)
@@ -43,4 +43,8 @@ extern void pack_report(void);
  */
 extern int open_pack_index(struct packed_git *);
 
+extern int unuse_one_window(struct packed_git *current);
+
+extern void release_pack_memory(size_t);
+
 #endif
index 084fe291d382169031c9506861c7cabf5b279836..dce232fb5c6c5eed4fd92bea103cc9d9fe271ad0 100644 (file)
@@ -681,55 +681,6 @@ static int has_loose_object(const unsigned char *sha1)
        return check_and_freshen(sha1, 0);
 }
 
-static void scan_windows(struct packed_git *p,
-       struct packed_git **lru_p,
-       struct pack_window **lru_w,
-       struct pack_window **lru_l)
-{
-       struct pack_window *w, *w_l;
-
-       for (w_l = NULL, w = p->windows; w; w = w->next) {
-               if (!w->inuse_cnt) {
-                       if (!*lru_w || w->last_used < (*lru_w)->last_used) {
-                               *lru_p = p;
-                               *lru_w = w;
-                               *lru_l = w_l;
-                       }
-               }
-               w_l = w;
-       }
-}
-
-static int unuse_one_window(struct packed_git *current)
-{
-       struct packed_git *p, *lru_p = NULL;
-       struct pack_window *lru_w = NULL, *lru_l = NULL;
-
-       if (current)
-               scan_windows(current, &lru_p, &lru_w, &lru_l);
-       for (p = packed_git; p; p = p->next)
-               scan_windows(p, &lru_p, &lru_w, &lru_l);
-       if (lru_p) {
-               munmap(lru_w->base, lru_w->len);
-               pack_mapped -= lru_w->len;
-               if (lru_l)
-                       lru_l->next = lru_w->next;
-               else
-                       lru_p->windows = lru_w->next;
-               free(lru_w);
-               pack_open_windows--;
-               return 1;
-       }
-       return 0;
-}
-
-void release_pack_memory(size_t need)
-{
-       size_t cur = pack_mapped;
-       while (need >= (cur - pack_mapped) && unuse_one_window(NULL))
-               ; /* nothing */
-}
-
 static void mmap_limit_check(size_t length)
 {
        static size_t limit = 0;