util: add the code path to "cachefunc()" for the function taking no arguments

Before this patch, "util.cachefunc()" caches the value returned by the
specified function into dictionary "cache", even if the specified
function takes no arguments.

In such case, "cache" has at most one entry, and distinction between
entries in "cache" is meaningless.

This patch adds the code path to "cachefunc()" for the function taking
no arguments for efficiency: to store only one cached value, using
list "cache" is a little faster than using dictionary "cache".
grep: reuse the first "util.binary()" result for efficiency

Before this patch, to check whether the file in the specified revision
is binary or not, "util.binary()" is invoked via internal function
"binary()" of "hg grep" once per a line of "hg grep" output, even
though binary-ness is not changed in the same file.

This patch reuses the first "util.binary()" invocation result by
annotating internal function "binary()" with "@util.cachefunc".

Performance improvement measured by "hgperf grep -r 88d8e568add1 vfs
mercurial/scmutil.py":

  before this patch:
    ! wall 0.024000 comb 0.015600 user 0.015600 sys 0.000000 (best of 118)

  after this patch:
    ! wall 0.023000 comb 0.015600 user 0.015600 sys 0.000000 (best of 123)

Status of recent(88d8e568add1) "mercurial/scmutil.py":

  # of lines:     919 (may affect cost of search)
  # of bytes:   29633 (may affect cost of "util.binary()")
  # of matches:    22 (may affect frequency of "util.binary()")
grep: use "found" instead of "filerevmatches" examination for efficiency

Before this patch, internal function "display()" of "hg grep" stores
whether matching is already found or not into the dictionary
"filerevmatches" by "(fn, rev)" tuple as the key.

But this is redundant, because:

  - "filerevmatches" is local variable of "display()", so each
    "display()" invocations don't affect others

  - both "fn" and "rev" (gotten from "ctx" argument) are never changed
    in each "display()" invocations

Then, "filerevmatches" should have only one entry at most, and "(fn,
rev) in filerevmatches" should be equal to "found".

This patch uses "found" instead of "filerevmatches" examination for
efficiency.
grep: exit loop immediately, if matching is found in the file for "hg grep -l"

Before this patch, internal function "display()" of "hg grep" is not
efficient for "-l"/"--files-with-matches", because loop is continued,
even after the first matching is found in the specified file.

This patch exits loop immediately, if matching is found for
"--files-with-matches".

In this case, "before is None" is equal to "opts.get('files_with_matches')".
contrib: add "hgperf" command to measure performance of commands easily

Newly added "hgperf" command repeats "dispatch.runcommand()" for
specified Mercurial command and measure performance of it in the same
manner of "contrib/perf.py" extension.

Users (mainly developers) can examine performance of the target
command easily, without adding new entry for it to "contrib/perf.py"
extension.
subrepo: factor out Git version check to add doctests

Followup to 6a2acb0d9352::e5641536e4d5.

--HG--
extra : rebase_source : 70bb91949c74806ce794f4af025711699cd52c91