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>
column: support grouping entries

If many entries share the same prefix (e.g. "git ls-files Documentation/"),
cutting out the prefix helps put more information on the same space.

If "group" is specified, the list of entries will be searched for
largest non-overlapping rectangles of text. Estimation is done on each
rectangle to see if there are any savings in rows if we group them.
Groups are printed first, then the remaining as the last group.

Handling the remaining part this way may not be ideal but I don't want
to split all directories like "ls -R". That takes too many lines.
Maybe I should prepend ".../" to all grouped items to make it clear
they are grouped.  There's also problem with ansi escape codes that
I'll need to handle if this sounds like a good way to go.

This code may be used for diffstat too (e.g. when most of the diff is
in Documentation/).

For demonstration, this is what
"COLUMNS=80 git ls-files --column=group -- '*.[ch]'" looks like

builtin/:
add.c                gc.c                 read-tree.c
annotate.c           grep.c               receive-pack.c
<snip>
for-each-ref.c       prune.c              verify-tag.c
fsck.c               push.c               write-tree.c

compat/:
basename.c                  regex/regexec.c
bswap.h                     setenv.c
<snip>
regex/regex_internal.c      win32mmap.c
regex/regex_internal.h      winansi.c

contrib/:
convert-objects/convert-objects.c
credential/osxkeychain/git-credential-osxkeychain.c
examples/builtin-fetch--tool.c
svn-fe/svn-fe.c

vcs-svn/:
fast_export.c    line_buffer.h    sliding_window.c svndiff.h
fast_export.h    repo_tree.c      sliding_window.h svndump.c
line_buffer.c    repo_tree.h      svndiff.c        svndump.h

xdiff/:
xdiff.h      xemit.c      xinclude.h   xpatience.c  xtypes.h
xdiffi.c     xemit.h      xmacros.h    xprepare.c   xutils.c
xdiffi.h     xhistogram.c xmerge.c     xprepare.h   xutils.h

...:
abspath.c                  pack-check.c
advice.c                   pack-refs.c
<snip>
object.c                   xdiff-interface.h
object.h                   zlib.c

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
fmt-merge-msg: show those involved in a merged series

As we already walk the history of the branch that gets merged to
come up with a short log, let's label it with names of the primary
authors, so that the user who summarizes the merge can easily give
credit to them in the log message.

Also infer the names of "lieutents" to help integrators at higher
level of the food-chain to give credit to them, by counting:

 * The committer of the 'tip' commit that is merged
 * The committer of merge commits that are merged

Often the first one gives the owner of the history being pulled, but
his last pull from his sublieutenants may have been a fast-forward,
in which case the first one would not be.  The latter rule will
count the integrator of the history, so together it might be a
reasonable heuristics.

There are two special cases:

 - The "author" credit is omitted when the series is written solely
   by the same author who is making the merge. The name can be seen
   on the "Author" line of the "git log" output to view the log
   message anyway.

 - The "lieutenant" credit is omitted when there is only one key
   committer in the merged branch and it is the committer who is
   making the merge. Typically this applies to the case where the
   developer merges his own branch.

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