sha1_file.c: introduce GIT_MMAP_LIMIT to limit mmap size

Similar to testing expectations about malloc with GIT_ALLOC_LIMIT
introduced in d41489a6 (Add more large blob test cases, 2012-03-07),
it can be useful to test expectations about mmap.

Introduce a new environment variable GIT_MMAP_LIMIT to limit the
largest allowed mmap length (in KB).  xmmap() is modified to check
the limit.  Together with GIT_ALLOC_LIMIT tests can now easily
confirm expectations about memory consumption.

GIT_MMAP_LIMIT will be used in the next commit to test that data
will be streamed to an external filter without mmaping the entire
file.

Signed-off-by: Steffen Prohaska <prohaska@zib.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
memory_limit_check(): allow a limit that does not fit in "int"

GIT_ALLOC_LIMIT limits xmalloc()'s size, which is of type size_t.
Use ssize_t to store the limit, not "int" which may be smaller.  The
change has no direct practical impact, because we use it primarily
to test small sizes.

The cast of size in the call to die() is changed to uintmax_t to
match the format string PRIuMAX.

Signed-off-by: Steffen Prohaska <prohaska@zib.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
convert: stream from fd to required clean filter instead of mmap

The data is streamed to the filter process anyway.  Better avoid
mapping the file if possible.  This is especially useful if a clean
filter reduces the size, for example if it computes a sha1 for
binary data, like git media.  The file size that the previous
implementation could handle was limited by the available address
space; large files for example could not be handled with (32-bit)
msysgit.  The new implementation can filter files of any size as
long as the filter output is small enough.

The new code path is only taken if the filter is required.  The
filter consumes data directly from the fd.  The original data is not
available to git, so it must fail if the filter fails.

The environment variable GIT_MMAP_LIMIT is used to test that the
expected code path is taken.  A related test that exercises required
filters is modified to verify that the data actually has been
modified on its way from the file system to the object store.

Signed-off-by: Steffen Prohaska <prohaska@zib.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>