prune: factor out loose-object directory traversal
[gitweb.git] / wrapper.c
index dc9c8f4dd32566e9e310682987d212602a2ac16b..5b77d2a1aecd494ea4bb5eb1e6f31afc9c96f82e 100644 (file)
--- a/wrapper.c
+++ b/wrapper.c
@@ -11,19 +11,20 @@ static void (*try_to_free_routine)(size_t size) = do_nothing;
 
 static int memory_limit_check(size_t size, int gentle)
 {
-       static int limit = -1;
-       if (limit == -1) {
-               const char *env = getenv("GIT_ALLOC_LIMIT");
-               limit = env ? atoi(env) * 1024 : 0;
+       static size_t limit = 0;
+       if (!limit) {
+               limit = git_env_ulong("GIT_ALLOC_LIMIT", 0);
+               if (!limit)
+                       limit = SIZE_MAX;
        }
-       if (limit && size > limit) {
+       if (size > limit) {
                if (gentle) {
-                       error("attempting to allocate %"PRIuMAX" over limit %d",
-                             (intmax_t)size, limit);
+                       error("attempting to allocate %"PRIuMAX" over limit %"PRIuMAX,
+                             (uintmax_t)size, (uintmax_t)limit);
                        return -1;
                } else
-                       die("attempting to allocate %"PRIuMAX" over limit %d",
-                           (intmax_t)size, limit);
+                       die("attempting to allocate %"PRIuMAX" over limit %"PRIuMAX,
+                           (uintmax_t)size, (uintmax_t)limit);
        }
        return 0;
 }
@@ -529,3 +530,11 @@ struct passwd *xgetpwuid_self(void)
                    errno ? strerror(errno) : _("no such user"));
        return pw;
 }
+
+char *xgetcwd(void)
+{
+       struct strbuf sb = STRBUF_INIT;
+       if (strbuf_getcwd(&sb))
+               die_errno(_("unable to get current working directory"));
+       return strbuf_detach(&sb, NULL);
+}