run_hook(): enhance the interface to pass arbitrary environment

Originally "run_hook()" that used to live in builtin/commit.c had a
perfectly appropriate API and name for a private function to spawn a
hook from "git commit" command. The only necessary tweak in the
context was to optionally specify which file to use as the index
file.

But then we stupidly moved this private API to run-command.c without
making the interface suitable for general consumption, and there is
no way to tweak environment variables other than GIT_INDEX_FILE when
running a hook.

Correct this mistake by adding run_hook_e() that takes an array of
environment variables.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
index-pack: support multithreaded delta resolving

This puts delta resolving on each base on a separate thread, one base
cache per thread. Per-thread data is grouped in struct thread_local.
When running with nr_threads == 1, no pthreads calls are made. The
system essentially runs in non-thread mode.

An experiment on a Xeon 24 core machine with linux-2.6.git shows that
performance does not increase proportional to the number of cores. So
by default, we use maximum 3 cores. Some numbers with --threads from 1
to 16:

1..4
real    1m16.310s  0m48.183s  0m37.866s  0m32.834s
user    1m13.773s  1m15.537s  1m15.781s  1m16.233s
sys     0m2.480s   0m3.936s   0m4.448s   0m4.852s

5..8
real    0m33.170s  0m30.369s  0m28.406s  0m26.968s
user    1m31.474s  1m30.322s  1m29.562s  1m28.694s
sys     0m6.096s   0m6.268s   0m6.684s   0m7.172s

9..12
real    0m26.288s  0m26.207s  0m26.239s  0m24.945s
user    1m29.530s  1m36.146s  1m43.134s  1m34.182s
sys     0m8.129s   0m8.437s   0m9.697s   0m10.201s

13..16
real    0m25.110s  0m25.043s  0m23.955s  0m25.746s
user    1m39.262s  1m43.598s  1m38.350s  1m59.775s
sys     0m10.997s  0m11.553s  0m11.949s  0m13.689s

Thanks to Ramsay Jones for troubleshooting on MinGW platform.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
test: use test_i18ncmp when checking --stat output

Ever since v1.7.9.2~13 (2012-02-01), git's diffstat-style summary line
produced by "git apply --stat", "git diff --stat", and "git commit"
varies by locale, producing test failures when GETTEXT_POISON is set.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
test: use numstat instead of diffstat in funny-names test

This test script checks that git's plumbing commands quote filenames
with special characters like space, tab, and double-quote
appropriately in their input and output.

Since commit v1.7.9.2~13 (Use correct grammar in diffstat summary
line, 2012-02-01), the final "1 file changed, 1 insertion(+)" line
from diffstats is translatable, meaning tests that rely on exact "git
apply --stat" output have to be skipped when git is not configured to
produce output in the C locale (for example, when GETTEXT_POISON is
enabled).  So:

 - Tweak the three "git apply --stat" tests that check "git apply"'s
   input parsing to use --numstat instead.

   --numstat output is more reliable, does not vary with locale, and
   is itself easier to parse.  These tests are mainly about how "git
   apply" parses its input so this should not result in much loss of
   coverage.

 - Add a new "apply --stat" test to check the quoting in --stat output
   format.

This wins back a little of the test coverage lost with the patch
"test: use test_i18ncmp to check --stat output" when GETTEXT_POISON is
enabled.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
test: modernize funny-names test style

This is one of the early tests, so it uses a style that by modern
standards can be hard to read.  Tweak it to:

 - clearly declare what assertion each test is designed to check

 - mark tests that create state later tests will depend on with the
   word "setup" so people writing or running tests know the others
   can be skipped or reordered safely

 - put commands that populate a file with expected output inside
   the corresponding test stanza, so it is easier to see by eye
   where each test begins and ends

 - instead of pipelines, use commands that read and write a
   temporary file, so bugs causing commands to segfault or produce
   the wrong exit status can be caught.

More cosmetic changes:

 - put the opening quote starting each test on the same line as the
   test_expect_* invocation, and indent the commands in each test
   with a single tab

 - end the test early if the underlying filesystem cannot
   accomodate the filenames we use, instead of marking all tests
   with the same TABS_IN_FILENAMES prerequisite.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
test: test cherry-pick functionality and output separately

Since v1.7.3-rc0~26^2~9 (revert: report success when using option
--strategy, 2010-07-14), the cherry-pick-many-commits test checks the
format of output written to the terminal during a cherry-pick sequence
in addition to the functionality.  There is no reason those have to
be checked in the same test, though, and it has some downsides:

 - when progress output is broken, the test result does not convey
   whether the functionality was also broken or not

 - it is not immediately obvious when reading that these checks are
   meant to prevent regressions in details of the output format and
   are not just a roundabout way to check functional details like the
   number of commits produced

 - there is a temptation to include the same kind of output checking
   for every new cherry-pick test, which would make future changes
   to the output unnecessarily difficult

Put the tests from v1.7.3-rc0~26^2~9 in separate assertions, following
the principle "test one feature at a time".

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
test: use --numstat instead of --stat in "git stash show" tests

git's diff --stat output is intended for human consumption and
since v1.7.9.2~13 (2012-02-01) varies by locale.  Add a test checking
that git stash show defaults to --stat and tweak the rest of the
"stash show" tests that showed a diffstat to use numstat.

This way, there are fewer tests to tweak if the diffstat format
changes again.  This also improves test coverage when running tests
with git configured not to write its output in the C locale (e.g.,
via GETTEXT_POISON=Yes).

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
test: use numstat instead of diffstat in binary-diff test

git's --stat output is intended for humans and since v1.7.9.2~13
(2012-02-01) varies by locale.  The tests in this script using "apply
--stat" are meant to check two things:

 - how binary file changes are accounted for and printed in
   git's diffstat format

 - that "git apply" can parse the various forms of binary diff

Split these two kinds of check into separate tests, and use --numstat
instead of --stat in the latter.  This way, we lose less test coverage
when git is being run without writing its output in the C locale (for
example because GETTEXT_POISON is enabled) and there are fewer tests
to change if the --stat output needs to be tweaked again.

While at it, use commands separated by && that read and write to
temporary files in place of pipelines so segfaults and other failures
in the upstream of the processing pipeline don't get hidden.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diffstat summary line varies by locale: miscellany

These changes are in the same spirit as the six patches that
precede them, but they haven't been split into individually
justifiable patches yet.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Add column layout skeleton and git-column

A column option string consists of many token separated by either
a space or a  comma. A token belongs to one of three groups:

 - enabling: always, never and auto
 - layout mode: currently plain (which does not layout at all)
 - other future tuning flags

git-column can be used to pipe output to from a command that wants
column layout, but not to mess with its own output code. Simpler output
code can be changed to use column layout code directly.

Thanks-to: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stop starting pager recursively

git-column can be used as a pager for other git commands, something
like this:

    GIT_PAGER="git -p column --mode='dense color'" git -p branch

The problem with this is that "git -p column" also has $GIT_PAGER set so
the pager runs itself again as another pager. The end result is an
infinite loop of forking. Other git commands have the same problem if
being abused this way.

Check if $GIT_PAGER is already set and stop launching another pager.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
column: add columnar layout

COL_COLUMN and COL_ROW fill column by column (or row by row
respectively), given the terminal width and how many space between
columns. All cells have equal width.

Strings are supposed to be in UTF-8. Valid ANSI escape strings are OK.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
column: add dense layout support

Normally all cells (and in turn columns) share the same width. This
layout mode can waste space because one long item can stretch our all
columns.

With COL_DENSE enabled, column width is calculated indepdendently. All
columns are shrunk to minimum, then it attempts to push cells of the
last row over to the next column with hope that everything still fits
even there's one row less. The process is repeated until the new layout
cannot fit in given width any more, or there's only one row left
(perfect!).

Apparently, this mode consumes more cpu than the old one, but it makes
better use of terminal space. For layouting one or two screens, cpu
usage should not be detectable.

This patch introduces option handling code besides layout modes and
enable/disable to expose this feature as "dense". The feature can be
turned off by specifying "nodense".

Thanks-to: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
help: reuse print_columns() for help -a

"help -a" also respects column.ui (and column.help if presents)

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
branch: add --column

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
status: add --column

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
column: support piping stdout to external git-column process

For too complicated output handling, it'd be easier to just spawn
git-column and redirect stdout to it. This patch provides helpers
to do that.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
tag: add --column

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
ls-files: support --column

.. because ls-files is a good show case to the next patches..

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
column: support "denser" mode

Sometimes a few long entries in the listing would stretch out columns,
wasting space. If these entries are cut out, the columns could become
smaller, hence more columns.

This new mode does that by looking for the longest entry, if cutting the
list before that entry results in much denser layout, then the entry
will be cut out and printed in a separate line. The remaining will put
in a new layout.

Multiple tables with different column width might be unpleasant to
look at, especially if the tables are really short. But on the other
hand it could be quite handy. For example,
"COLUMNS=80 ./git ls-files --column=dense -- '*.[ch]'" takes 415
lines, while "denser" only takes 223 because it break the layout at
contrib/credential/osxkeychain/git-credential-osxkeychain.c
and relayout again:

abspath.c                  builtin/rm.c
advice.c                   builtin/send-pack.c
<snip>
builtin/rev-parse.c        connected.h
builtin/revert.c           contrib/convert-objects/convert-objects.c

contrib/credential/osxkeychain/git-credential-osxkeychain.c

contrib/examples/builtin-fetch--tool.c refs.c                   xdiff/xutils.c
contrib/svn-fe/svn-fe.c                refs.h                   xdiff/xutils.h
convert.c                              remote-curl.c            zlib.c
convert.h                              remote.c
<snip>
reflog-walk.c                          xdiff/xprepare.h
reflog-walk.h                          xdiff/xtypes.h

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>