Revision c7934306d1504325d26950f35759ad478772e9c3 authored by Shawn O. Pearce on 28 February 2011, 20:52:39 UTC, committed by Junio C Hamano on 28 February 2011, 21:08:31 UTC
Rather than using 'errno == EMFILE' after a failed open() call
to indicate the process is out of file descriptors and an LRU
pack window should be closed, place a hard upper limit on the
number of open packs based on the actual rlimit of the process.

By using a hard upper limit that is below the rlimit of the current
process it is not necessary to check for EMFILE on every single
fd-allocating system call.  Instead reserving 25 file descriptors
makes it safe to assume the system call won't fail due to being over
the filedescriptor limit.  Here 25 is chosen as a WAG, but considers
3 for stdin/stdout/stderr, and at least a few for other Git code
to operate on temporary files.  An additional 20 is reserved as it
is not known what the C library needs to perform other services on
Git's behalf, such as nsswitch or name resolution.

This fixes a case where running `git gc --auto` in a repository
with more than 1024 packs (but an rlimit of 1024 open fds) fails
due to the temporary output file not being able to allocate a
file descriptor.  The output file is opened by pack-objects after
object enumeration and delta compression are done, both of which
have already opened all of the packs and fully populated the file
descriptor table.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 62270f6
Raw File
t7101-reset.sh
#!/bin/sh
#
# Copyright (c) 2006 Shawn Pearce
#

test_description='git reset should cull empty subdirs'
. ./test-lib.sh

test_expect_success \
    'creating initial files' \
    'mkdir path0 &&
     cp "$TEST_DIRECTORY"/../COPYING path0/COPYING &&
     git add path0/COPYING &&
     git commit -m add -a'

test_expect_success \
    'creating second files' \
    'mkdir path1 &&
     mkdir path1/path2 &&
     cp "$TEST_DIRECTORY"/../COPYING path1/path2/COPYING &&
     cp "$TEST_DIRECTORY"/../COPYING path1/COPYING &&
     cp "$TEST_DIRECTORY"/../COPYING COPYING &&
     cp "$TEST_DIRECTORY"/../COPYING path0/COPYING-TOO &&
     git add path1/path2/COPYING &&
     git add path1/COPYING &&
     git add COPYING &&
     git add path0/COPYING-TOO &&
     git commit -m change -a'

test_expect_success \
    'resetting tree HEAD^' \
    'git reset --hard HEAD^'

test_expect_success \
    'checking initial files exist after rewind' \
    'test -d path0 &&
     test -f path0/COPYING'

test_expect_success \
    'checking lack of path1/path2/COPYING' \
    '! test -f path1/path2/COPYING'

test_expect_success \
    'checking lack of path1/COPYING' \
    '! test -f path1/COPYING'

test_expect_success \
    'checking lack of COPYING' \
    '! test -f COPYING'

test_expect_success \
    'checking checking lack of path1/COPYING-TOO' \
    '! test -f path0/COPYING-TOO'

test_expect_success \
    'checking lack of path1/path2' \
    '! test -d path1/path2'

test_expect_success \
    'checking lack of path1' \
    '! test -d path1'

test_done
back to top