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>
upload-pack: keep poll(2)'s timeout to -1

Keep poll's timeout at -1 when uploadpack.keepalive = 0, instead of
setting it to -1000, since some pedantic old systems (eg HP-UX) and
the gnulib compat/poll will treat only -1 as the valid value for
an infinite timeout.

Signed-off-by: Edward Thomson <ethomson@microsoft.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Merge branch 'et/spell-poll-infinite-with-minus-one-only' into jch

* et/spell-poll-infinite-with-minus-one-only:
  upload-pack: keep poll(2)'s timeout to -1
Merge branch 'sp/stream-clean-filter' into jch

* sp/stream-clean-filter:
  convert: stream from fd to required clean filter instead of mmap
  memory_limit_check(): allow a limit that does not fit in "int"
  sha1_file.c: introduce GIT_MMAP_LIMIT to limit mmap size
  convert: drop arguments other than 'path' from would_convert_to_git()
Merge branch 'rr/mergetool-temporary-filename-tweak' into pu

* rr/mergetool-temporary-filename-tweak:
  Allow the user to change the temporary file name for mergetool
Merge branch 'rh/prompt-tests' into pu

to be broken with older zsh that are still in the field ($gmane/251231).

* rh/prompt-tests:
  t9904: new __git_ps1 tests for Zsh
  test-lib: make it possible to override how test code is eval'd
  lib-prompt-tests.sh: add variable for string that encodes percent in PS1
  lib-prompt-tests.sh: put all tests inside a function
  t9903: move prompt tests to a new lib-prompt-tests.sh file
  t9903: move PS1 color code variable definitions to lib-bash.sh
  t9903: include "Bash" in test names via new $shellname var
  t9903: run pc mode tests again with PS1 expansion disabled
  t9903: move test name prefix to a separate variable
  t9903: put the Bash pc mode prompt test cases in a function
  t9903: remove Zsh test from the suite of Bash prompt tests
Merge branch 'bg/rebase-off-of-previous-branch' into pu

Teach "git rebase -" to report the concrete name of the branch
(i.e. the previous one).

But it stops short and does not do the same for "git rebase @{-1}".

* bg/rebase-off-of-previous-branch:
  git-rebase: print name of rev when using shorthand
Merge branch 'rb/merge-prepare-commit-msg-hook' into pu

Expose more merge states (e.g. $GIT_DIR/MERGE_MODE) to hooks that
run during "git merge".  The log message stresses too much on one
hook, prepare-commit-msg, but it would equally apply to other hooks
like post-merge, I think.

* rb/merge-prepare-commit-msg-hook:
  merge: drop unused arg from abort_commit method signature
  merge: make prepare_to_commit responsible for write_merge_state
  t7505: ensure cleanup after hook blocks merge
  t7505: add missing &&

# Conflicts:
# 	builtin/merge.c
# 	t/t7505-prepare-commit-msg-hook.sh
Merge branch 'jc/show-branch' into pu

* jc/show-branch:
  show-branch: use commit slab to represent bitflags of arbitrary width
  show-branch.c: remove "all_mask"
  show-branch.c: abstract out "flags" operation
  show-branch.c: lift all_mask/all_revs to a global static
  show-branch.c: update comment style
Merge branch 'tr/merge-recursive-index-only' into pu

* tr/merge-recursive-index-only:
  merge-recursive: -Xindex-only to leave worktree unchanged
  merge-recursive: internal flag to avoid touching the worktree
  merge-recursive: remove dead conditional in update_stages()
Merge branch 'tg/perf-lib-test-perf-cleanup' into pu

Add test_perf_cleanup shell function to the perf suite, that allows
the script writers to define a test with a clean-up action.

Will hold.

* tg/perf-lib-test-perf-cleanup:
  perf-lib: add test_perf_cleanup target
  perf-lib: split starting the test from the execution
Merge branch 'ab/add-interactive-show-diff-func-name' into pu

* ab/add-interactive-show-diff-func-name:
  SQUASH??? git-add--interactive: Preserve diff heading when splitting hunks
  git-add--interactive: Preserve diff heading when splitting hunks
Merge branch 'ss/userdiff-update-csharp-java' into pu

Reviews sent; waiting for a response.

* ss/userdiff-update-csharp-java:
  userdiff: support Java try keyword
  userdiff: support C# async methods and correct C# keywords
Merge branch 'jn/gitweb-utf8-in-links' into pu

$gmane/250758?

* jn/gitweb-utf8-in-links:
  gitweb: Harden UTF-8 handling in generated links
### broken or came too late for the day's cycle
Merge branch 'jc/graph-post-root-gap' into pu

This was primarily a RFH ($gmane/239580).

* jc/graph-post-root-gap:
  WIP: document what we want at the end
  graph: remove unused code a bit
  graph: stuff the current commit into graph->columns[]
receive-pack: do not overallocate command structure

An "update" command in the protocol exchange consists of 40-hex old
object name, SP, 40-hex new object name, SP, and a refname, but the
first instance is further followed by a NUL with feature requests.

The command structure, which has a flex-array member that stores the
refname at the end, was allocated based on the whole length of the
update command, without excluding the trailing feature requests.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
receive-pack: parse feature request a bit earlier

Ideally, we should have also allowed the first "shallow" to carry
the feature request trailer, but that is water under the bridge
now.  This makes the next step to factor out the queuing of commands
easier to review.

Signed-off-by: Junio C Hamano <gitster@pobox.com>