Commit graph

47896 commits

Author SHA1 Message Date
Jeff King e433749d86 test-terminal: set TERM=vt100
The point of the test-terminal script is to simulate in the
test scripts an environment where output is going to a real
terminal.

But since test-lib.sh also sets TERM=dumb, the simulation
isn't very realistic. The color code will skip auto-coloring
for TERM=dumb, leading to us liberally sprinkling

  test_terminal env TERM=vt100 git ...

through the test suite to convince the tests to actually
generate colors. Let's set TERM for programs run under
test_terminal, which is one less thing for test-writers to
remember.

In most cases the callers can be simplified, but note there
is one interesting case in t4202. It uses test_terminal to
check the auto-enabling of --decorate, but the expected
output _doesn't_ contain colors (because TERM=dumb
suppresses them). Using TERM=vt100 is closer to what the
real world looks like; adjust the expected output to match.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-10-04 11:25:12 +09:00
Jeff King 11b087adfd ref-filter: consult want_color() before emitting colors
When color placeholders like %(color:red) are used in a
ref-filter format, we unconditionally output the colors,
even if the user has asked us for no colors. This usually
isn't a problem when the user is constructing a --format on
the command line, but it means we may do the wrong thing
when the format is fed from a script or alias. For example:

   $ git config alias.b 'branch --format=%(color:green)%(refname)'
   $ git b --no-color

should probably omit the green color. Likewise, running:

   $ git b >branches

should probably also omit the color, just as we would for
all baked-in coloring (and as we recently started to do for
user-specified colors in --pretty formats).

This commit makes both of those cases work by teaching
the ref-filter code to consult want_color() before
outputting any color. The color flag in ref_format defaults
to "-1", which means we'll consult color.ui, which in turn
defaults to the usual isatty() check on stdout. However,
callers like git-branch which support their own color config
(and command-line options) can override that.

The new tests independently cover all three of the callers
of ref-filter (for-each-ref, tag, and branch). Even though
these seem redundant, it confirms that we've correctly
plumbed through all of the necessary config to make colors
work by default.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-07-13 12:42:51 -07:00
Jeff King 18fb7ffc3d pretty: respect color settings for %C placeholders
The color placeholders have traditionally been
unconditional, showing colors even when git is not otherwise
configured to do so. This was not so bad for their original
use, which was on the command-line (and the user could
decide at that moment whether to add colors or not). But
these days we have configured formats via pretty.*, and
those should operate correctly in multiple contexts.

In 3082517 (log --format: teach %C(auto,black) to respect
color config, 2012-12-17), we gave an extended placeholder
that could be used to accomplish this. But it's rather
clunky to use, because you have to specify it individually
for each color (and their matching resets) in the format.
We shied away from just switching the default to auto,
because it is technically breaking backwards compatibility.

However, there's not really a use case for unconditional
colors. The most plausible reason you would want them is to
redirect "git log" output to a file. But there, the right
answer is --color=always, as it does the right thing both
with custom user-format colors and git-generated colors.

So let's switch to the more useful default. In the
off-chance that somebody really does find a use for
unconditional colors without wanting to enable the rest of
git's colors, we provide a new %C(always,...) to enable the
old behavior. And we can remind them of --color=always in
the documentation.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-07-13 12:42:51 -07:00
Jeff King d75dfb1089 rev-list: pass diffopt->use_colors through to pretty-print
When rev-list pretty-prints a commit, it creates a new
pretty_print_context and copies items from the rev_info
struct. We don't currently copy the "use_color" field,
though. Nobody seems to have noticed because the only part
of pretty.c that cares is the %C(auto,...) placeholder, and
presumably not many people use that with the rev-list
plumbing (as opposed to with git-log).

It will become more noticeable in a future patch, though,
when we start treating all user-format colors as auto-colors
(in which case it would become impossible to format colors
with rev-list, even with --color=always).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-07-13 12:42:51 -07:00
Jeff King d8b68686a4 for-each-ref: load config earlier
In most commands we load config before parsing command line
options, since it lets the latter override the former with a
simple variable assignment. In the case of for-each-ref,
though, we do it in the reverse order. This is OK with
the current code, since there's no interaction between the
config and command-line options.

However, as the ref-filter code starts to care about config
during verify_ref_format(), we'll want to make sure the
config is loaded. Let's bump the config to the usual spot
near the top of the function.

We can drop the comment there; it's impossible to keep a
"why we load the config" comment like this up to date with
every config option we might be interested in. And indeed,
it's already stale; we'd care about core.abbrev, for
instance, when %(objectname:short) is used.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-07-13 12:42:51 -07:00
Jeff King 136c8c8b8f color: check color.ui in git_default_config()
Back in prehistoric times, our decision on whether or not to
show color by default relied on using a config callback that
either did or didn't load color config like color.diff.
When we introduced color.ui, we put it in the same boat:
commands had to manually respect it by using git_color_config()
or its git_color_default_config() convenience wrapper.

But in 4c7f1819b (make color.ui default to 'auto',
2013-06-10), that changed. Since then, we default color.ui
to auto in all programs, meaning that even plumbing commands
like "git diff-tree --pretty" might colorize the output.
Nobody seems to have complained in the intervening years,
presumably because the "is stdout a tty" check does a good
job of catching the right cases.

But that leaves an interesting curiosity: color.ui defaults
to auto even in plumbing, but you can't actually _disable_
the color via config. So if you really hate color and set
"color.ui" to false, diff-tree will still show color (but
porcelain like git-diff won't).  Nobody noticed that either,
probably because very few people disable color.

One could argue that the plumbing should _always_ disable
color unless an explicit --color option is given on the
command line. But in practice, this creates a lot of
complications for scripts which do want plumbing to show
user-visible output. They can't just pass "--color" blindly;
they need to check the user's config and decide what to
send.

Given that nobody has complained about the current behavior,
let's assume it's a good path, and follow it to its
conclusion: supporting color.ui everywhere.

Note that you can create havoc by setting color.ui=always in
your config, but that's more or less already the case. We
could disallow it entirely, but it is handy for one-offs
like:

  git -c color.ui=always foo >not-a-tty

when "foo" does not take a --color option itself.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-07-13 12:42:51 -07:00
Jeff King ab7ded34d6 ref-filter: pass ref_format struct to atom parsers
The callback for parsing each formatting atom gets to see
only the atom struct (which it's filling in) and the text to
be parsed. This doesn't leave any room for it to behave
differently based on context known only to the ref_format.

We can solve this by passing in the surrounding ref_format
to each parser. Note that this makes things slightly awkward
for sort strings, which parse atoms without having a
ref_format. We'll solve that by using a dummy ref_format
with default parameters.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-07-13 12:42:51 -07:00
Jeff King 29ef53cd36 ref-filter: factor out the parsing of sorting atoms
We parse sort strings as single formatting atoms, and just
build on parse_ref_filter_atom(). Let's pull this idea into
its own function, since it's about to get a little more
complex. As a bonus, we can give the function a slightly
more natural interface, since our single atoms are in their
own strings.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-07-13 12:42:51 -07:00
Jeff King aa8a5d144d ref-filter: make parse_ref_filter_atom a private function
The parse_ref_filter_atom() function really shouldn't be
exposed outside of ref-filter.c; its return value is an
integer index into an array that is private in that file.

Since the previous commit removed the sole external caller
(and replaced it with a public function at a more
appropriately level), we can just make this static.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-07-13 12:42:51 -07:00
Jeff King 18a2565016 ref-filter: provide a function for parsing sort options
The ref-filter module currently provides a callback suitable
for parsing command-line --sort options. But since git-tag
also supports the tag.sort config option, it needs a
function whose implementation is quite similar, but with a
slightly different interface. The end result is that
builtin/tag.c has a copy-paste of parse_opt_ref_sorting().

Instead, let's provide a function to parse an arbitrary
sort string, which we can then trivially wrap to make the
parse_opt variant.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-07-13 12:42:51 -07:00
Jeff King bf285ae6db ref-filter: move need_color_reset_at_eol into ref_format
Calling verify_ref_format() doesn't just confirm that the
format is sane; it actually sets some global variables that
will be used later when formatting the refs. These logically
should belong to the ref_format, which would make it
possible to use multiple formats within a single program
invocation.

Let's move one such flag into the ref_format struct. There
are still others that would need to be moved before it would
be safe to use multiple formats, but this commit gives a
blueprint for how that should look.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-07-13 12:42:50 -07:00
Jeff King 4a68e36d7d ref-filter: abstract ref format into its own struct
The ref-filter module provides routines for formatting a ref
for output. The fundamental interface for the format is a
"const char *" containing the format, and any additional
options need to be passed to each invocation of
show_ref_array_item.

Instead, let's make a ref_format struct that holds the
format, along with any associated format options. That will
make some enhancements easier in the future:

  1. new formatting options can be added without disrupting
     existing callers

  2. some state can be carried in the struct rather than as
     global variables

For now this just has the text format itself along with the
quote_style option, but we'll add more fields in future patches.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-07-13 12:42:50 -07:00
Jeff King 51331aad69 ref-filter: simplify automatic color reset
When the user-format doesn't add the closing color reset, we
add one automatically. But we do so by parsing the "reset"
string. We can just use the baked-in string literal, which
is simpler.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-07-13 12:42:50 -07:00
Jeff King 097b681baa t: use test_decode_color rather than literal ANSI codes
When we put literal ANSI terminal codes into our test
scripts, it makes diffs on those scripts hard to read (the
colors may be indistinguishable from diff coloring, or in
the case of a reset, may not be visible at all).

Some scripts get around this by including human-readable
names and converting to literal codes with a git-config
hack. This makes the actual code diffs look OK, but test_cmp
output suffers from the same problem.

Let's use test_decode_color instead, which turns the codes
into obvious text tags.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-07-13 12:42:50 -07:00
Jeff King 5d3d0681ab docs/for-each-ref: update pointer to color syntax
The documentation for the %(color) placeholder refers to the
color.branch.* config for more details. But those details
moved to their own section in b92c1a28f
(Documentation/config.txt: describe 'color' value type in
the "Values" section, 2015-03-03).  Let's update our
pointer. We can steal the text from 30cfe72d3 (pretty: fix
document link for color specification, 2016-10-11), which
fixed the same problem in a different place.

While we're at it, let's give an example, which makes the
syntax much more clear than just the text.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-07-13 12:42:50 -07:00
Jeff King 2eda0102be check return value of verify_ref_format()
Users of the ref-filter code must call verify_ref_format()
before formatting any refs, but most ignore its return
value. This means we may print an error on a syntactically
bogus pattern, but keep going anyway.

In most cases this results in a fatal error when we actually
try to format a ref. But if you have no refs to show at all,
then the behavior is confusing: git prints the error from
verify_ref_format(), then exits with code 0 without showing
any output.  Let's instead abort immediately if we know we
have a bogus format.

We'll output the usage information if we have it handy (just
like the existing call in cmd_for_each_ref() does), and
otherwise just die().

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-07-13 12:42:50 -07:00
Junio C Hamano 80145b1e41 Sync with v2.13.3 2017-07-12 15:25:14 -07:00
Junio C Hamano 08f9c32463 Git 2.13.3
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-07-12 15:24:15 -07:00
Junio C Hamano 55bdfa022f Merge branch 'kn/ref-filter-branch-list' into maint
The rewrite of "git branch --list" using for-each-ref's internals
that happened in v2.13 regressed its handling of color.branch.local;
this has been fixed.

* kn/ref-filter-branch-list:
  ref-filter.c: drop return from void function
  branch: set remote color in ref-filter branch immediately
  branch: use BRANCH_COLOR_LOCAL in ref-filter format
  branch: only perform HEAD check for local branches
2017-07-12 15:23:09 -07:00
Junio C Hamano ecab58c65f Merge branch 'ks/typofix-commit-c-comment' into maint
Typofix.

* ks/typofix-commit-c-comment:
  builtin/commit.c: fix a typo in the comment
2017-07-12 15:20:49 -07:00
Junio C Hamano 9d21a968b2 Merge branch 'jk/reflog-walk-maint' into maint
After "git branch --move" of the currently checked out branch, the
code to walk the reflog of HEAD via "log -g" and friends
incorrectly stopped at the reflog entry that records the renaming
of the branch.

* jk/reflog-walk-maint:
  reflog-walk: include all fields when freeing complete_reflogs
  reflog-walk: don't free reflogs added to cache
  reflog-walk: duplicate strings in complete_reflogs list
  reflog-walk: skip over double-null oid due to HEAD rename
2017-07-12 15:20:36 -07:00
Junio C Hamano 8ba1d6616f Hopefully the last batch before -rc0
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-07-12 15:19:27 -07:00
Junio C Hamano a5a3c5afcd Merge branch 'ks/fix-rebase-doc-picture'
Doc update.

* ks/fix-rebase-doc-picture:
  doc: correct a mistake in an illustration
2017-07-12 15:18:24 -07:00
Junio C Hamano 094aa09aa5 Merge branch 'rs/wt-status-cleanup'
Code cleanup.

* rs/wt-status-cleanup:
  wt-status: use separate variable for result of shorten_unambiguous_ref
2017-07-12 15:18:23 -07:00
Junio C Hamano f056cde60e Merge branch 'rs/use-div-round-up'
Code cleanup.

* rs/use-div-round-up:
  use DIV_ROUND_UP
2017-07-12 15:18:23 -07:00
Junio C Hamano 768d0fe0da Merge branch 'kn/ref-filter-branch-list'
The rewrite of "git branch --list" using for-each-ref's internals
that happened in v2.13 regressed its handling of color.branch.local;
this has been fixed.

* kn/ref-filter-branch-list:
  ref-filter.c: drop return from void function
  branch: set remote color in ref-filter branch immediately
  branch: use BRANCH_COLOR_LOCAL in ref-filter format
  branch: only perform HEAD check for local branches
2017-07-12 15:18:23 -07:00
Junio C Hamano 536c1ec32a Merge branch 'rs/urlmatch-cleanup'
Code cleanup.

* rs/urlmatch-cleanup:
  urlmatch: use hex2chr() in append_normalized_escapes()
2017-07-12 15:18:22 -07:00
Junio C Hamano 6fee4ca625 Merge branch 'rs/apply-avoid-over-reading'
Code cleanup.

* rs/apply-avoid-over-reading:
  apply: use strcmp(3) for comparing strings in gitdiff_verify_name()
2017-07-12 15:18:22 -07:00
Junio C Hamano b5fe65fe93 Merge branch 'sb/submodule-doc'
Doc update.

* sb/submodule-doc:
  submodules: overhaul documentation
2017-07-12 15:18:21 -07:00
René Scharfe 42c78a216e use DIV_ROUND_UP
Convert code that divides and rounds up to use DIV_ROUND_UP to make the
intent clearer and reduce the number of magic constants.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-07-10 14:24:36 -07:00
Junio C Hamano 117ddefdb4 Sync with maint 2017-07-10 14:06:21 -07:00
Junio C Hamano 699d47e1d2 Prepare for 2.13.3 2017-07-10 14:02:07 -07:00
Junio C Hamano 4aaf5b0b21 Merge branch 'sb/merge-recursive-code-cleanup' into maint
Code clean-up.

* sb/merge-recursive-code-cleanup:
  merge-recursive: use DIFF_XDL_SET macro
2017-07-10 13:59:09 -07:00
Junio C Hamano 127c13aa41 Merge branch 'jc/utf8-fprintf' into maint
Code cleanup.

* jc/utf8-fprintf:
  submodule--helper: do not call utf8_fprintf() unnecessarily
2017-07-10 13:59:09 -07:00
Junio C Hamano 8e7b78a692 Merge branch 'js/fsck-name-object' into maint
Test fix.

* js/fsck-name-object:
  t1450: use egrep for regexp "alternation"
2017-07-10 13:59:08 -07:00
Junio C Hamano 5a24b4e14a Merge branch 'js/t5534-rev-parse-gives-multi-line-output-fix' into maint
A few tests that tried to verify the contents of push certificates
did not use 'git rev-parse' to formulate the line to look for in
the certificate correctly.

* js/t5534-rev-parse-gives-multi-line-output-fix:
  t5534: fix misleading grep invocation
2017-07-10 13:59:07 -07:00
Junio C Hamano 362009f8cf Merge branch 'ab/sha1dc-maint' into maint
Update the sha1dc again to fix portability glitches.

* ab/sha1dc-maint:
  sha1dc: update from upstream
2017-07-10 13:59:06 -07:00
Junio C Hamano 35049a2343 Merge branch 'aw/contrib-subtree-doc-asciidoctor' into maint
The Makefile rule in contrib/subtree for building documentation
learned to honour USE_ASCIIDOCTOR just like the main documentation
set does.

* aw/contrib-subtree-doc-asciidoctor:
  subtree: honour USE_ASCIIDOCTOR when set
2017-07-10 13:59:06 -07:00
Junio C Hamano a9e87e3204 Merge branch 'cc/shared-index-permfix' into maint
The split index code did not honor core.sharedrepository setting
correctly.

* cc/shared-index-permfix:
  t1700: make sure split-index respects core.sharedrepository
  t1301: move modebits() to test-lib-functions.sh
  read-cache: use shared perms when writing shared index
2017-07-10 13:59:05 -07:00
Junio C Hamano 76de71b487 Merge branch 'ah/doc-pretty-color-auto-prefix' into maint
Doc update.

* ah/doc-pretty-color-auto-prefix:
  doc: clarify syntax for %C(auto,...) in pretty formats
2017-07-10 13:59:05 -07:00
Junio C Hamano cf77911ae5 Merge branch 'mb/reword-autocomplete-message' into maint
Message update.

* mb/reword-autocomplete-message:
  auto-correct: tweak phrasing
2017-07-10 13:59:04 -07:00
Junio C Hamano 8f3a16c390 Merge branch 'ks/t7508-indent-fix' into maint
Cosmetic update to a test.

* ks/t7508-indent-fix:
  t7508: fix a broken indentation
2017-07-10 13:59:03 -07:00
Junio C Hamano dbcf77592a Merge branch 'sb/t4005-modernize' into maint
Test clean-up.

* sb/t4005-modernize:
  t4005: modernize style and drop hard coded sha1
2017-07-10 13:59:02 -07:00
Junio C Hamano 33c3c2d368 Merge branch 'rs/apply-validate-input' into maint
Tighten error checks for invalid "git apply" input.

* rs/apply-validate-input:
  apply: check git diffs for mutually exclusive header lines
  apply: check git diffs for invalid file modes
  apply: check git diffs for missing old filenames
2017-07-10 13:59:01 -07:00
Junio C Hamano b944d7c4b5 Merge branch 'jc/pack-bitmap-unaligned' into maint
An unaligned 32-bit access in pack-bitmap code ahs been corrected.

* jc/pack-bitmap-unaligned:
  pack-bitmap: don't perform unaligned memory access
2017-07-10 13:59:00 -07:00
Junio C Hamano 9f6728da31 Merge branch 'pw/rebase-i-regression-fix-tests' into maint
Fix a recent regression to "git rebase -i" and add tests that would
have caught it and others.

* pw/rebase-i-regression-fix-tests:
  t3420: fix under GETTEXT_POISON build
  rebase: add more regression tests for console output
  rebase: add regression tests for console output
  rebase -i: add test for reflog message
  sequencer: print autostash messages to stderr
2017-07-10 13:59:00 -07:00
Junio C Hamano f904494574 Merge branch 'jk/add-p-commentchar-fix' into maint
"git add -p" were updated in 2.12 timeframe to cope with custom
core.commentchar but the implementation was buggy and a
metacharacter like $ and * did not work.

* jk/add-p-commentchar-fix:
  add--interactive: quote commentChar regex
  add--interactive: handle EOF in prompt_yesno
2017-07-10 13:58:59 -07:00
Junio C Hamano 040746c061 Merge branch 'js/alias-early-config' into maint
The code to pick up and execute command alias definition from the
configuration used to switch to the top of the working tree and
then come back when the expanded alias was executed, which was
unnecessarilyl complex.  Attempt to simplify the logic by using the
early-config mechanism that does not chdir around.

* js/alias-early-config:
  alias: use the early config machinery to expand aliases
  t7006: demonstrate a problem with aliases in subdirectories
  t1308: relax the test verifying that empty alias values are disallowed
  help: use early config when autocorrecting aliases
  config: report correct line number upon error
  discover_git_directory(): avoid setting invalid git_dir
2017-07-10 13:58:58 -07:00
Junio C Hamano 49771171e5 Merge branch 'rs/pretty-add-again' into maint
The pretty-format specifiers like '%h', '%t', etc. had an
optimization that no longer works correctly.  In preparation/hope
of getting it correctly implemented, first discard the optimization
that is broken.

* rs/pretty-add-again:
  pretty: recalculate duplicate short hashes
2017-07-10 13:58:57 -07:00
Junio C Hamano 86d51bbe1a Merge branch 'ah/doc-gitattributes-empty-index' into maint
An example in documentation that does not work in multi worktree
configuration has been corrected.

* ah/doc-gitattributes-empty-index:
  doc: do not use `rm .git/index` when normalizing line endings
2017-07-10 13:58:56 -07:00