git
6 years agoMerge branch 'jk/ref-filter-colors-fix'
Junio C Hamano [Wed, 18 Oct 2017 01:19:08 +0000 (10:19 +0900)] 
Merge branch 'jk/ref-filter-colors-fix'

This is the "theoretically more correct" approach of simply
stepping back to the state before plumbing commands started paying
attention to "color.ui" configuration variable.

Let's run with this one.

* jk/ref-filter-colors-fix:
  tag: respect color.ui config
  Revert "color: check color.ui in git_default_config()"
  Revert "t6006: drop "always" color config tests"
  Revert "color: make "always" the same as "auto" in config"

6 years agoMerge branch 'js/rebase-i-final'
Junio C Hamano [Wed, 18 Oct 2017 01:19:07 +0000 (10:19 +0900)] 
Merge branch 'js/rebase-i-final'

Error message fix.

* js/rebase-i-final:
  sequencer.c: unify an error message

6 years agodoc: list filter-branch subdirectory-filter first
David Glasser [Tue, 17 Oct 2017 09:45:15 +0000 (09:45 +0000)] 
doc: list filter-branch subdirectory-filter first

The docs claim that filters are applied in the listed order, so
subdirectory-filter should come first.

For consistency, apply the same order to the SYNOPSIS and the script's usage, as
well as the switch while parsing arguments.

Add missing --prune-empty to the script's usage.

Signed-off-by: David Glasser <glasser@davidglasser.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agosequencer.c: unify an error message
Ralf Thielow [Tue, 17 Oct 2017 16:20:50 +0000 (18:20 +0200)] 
sequencer.c: unify an error message

Change an error message in sequencer.c for the case that
we could not write to a file to match other instances.

Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agofetch doc: src side of refspec could be full SHA-1
Junio C Hamano [Tue, 17 Oct 2017 02:31:06 +0000 (11:31 +0900)] 
fetch doc: src side of refspec could be full SHA-1

Since a9d34933 ("Merge branch 'fm/fetch-raw-sha1'", 2015-06-01) we
allow to fetch by an object name when the other side accepts such a
request, but we never updated the documentation to match.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agol10n: Update Catalan translation
Jordi Mas [Tue, 17 Oct 2017 12:28:23 +0000 (13:28 +0100)] 
l10n: Update Catalan translation

Signed-off-by: Jordi Mas <jmas@softcatala.org>
6 years agol10n: ko.po: Update Korean translation
Changwoo Ryu [Tue, 17 Oct 2017 07:20:34 +0000 (16:20 +0900)] 
l10n: ko.po: Update Korean translation

Signed-off-by: Changwoo Ryu <cwryu@debian.org>
6 years agotag: respect color.ui config
Jeff King [Fri, 13 Oct 2017 17:26:02 +0000 (13:26 -0400)] 
tag: respect color.ui config

Since 11b087adfd (ref-filter: consult want_color() before
emitting colors, 2017-07-13), we expect that setting
"color.ui" to "always" will enable color tag formats even
without a tty.  As that commit was built on top of
136c8c8b8f (color: check color.ui in git_default_config(),
2017-07-13) from the same series, we didn't need to touch
tag's config parsing at all.

However, since we reverted 136c8c8b8f, we now need to
explicitly call git_color_default_config() to make this
work.

Let's do so, and also restore the test dropped in 0c88bf5050
(provide --color option for all ref-filter users,
2017-10-03). That commit swapped out our "color.ui=always"
test for "--color" in preparation for "always" going away.
But since it is here to stay, we should test both cases.

Note that for-each-ref also lost its color.ui support as
part of reverting 136c8c8b8f. But as a plumbing command, it
should _not_ respect the color.ui config. Since it also
gained a --color option in 0c88bf5050, that's the correct
way to ask it for color. We'll continue to test that, and
confirm that "color.ui" is not respected.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoRevert "color: check color.ui in git_default_config()"
Jeff King [Fri, 13 Oct 2017 17:24:31 +0000 (13:24 -0400)] 
Revert "color: check color.ui in git_default_config()"

This reverts commit 136c8c8b8fa39f1315713248473dececf20f8fe7.

That commit was trying to address a bug caused by 4c7f1819b3
(make color.ui default to 'auto', 2013-06-10), in which
plumbing like diff-tree defaulted to "auto" color, but did
not respect a "color.ui" directive to disable it.

But it also meant that we started respecting "color.ui" set
to "always". This was a known problem, but 4c7f1819b3 argued
that nobody ought to be doing that. However, that turned out
to be wrong, and we got a number of bug reports related to
"add -p" regressing in v2.14.2.

Let's revert 136c8c8b8, fixing the regression to "add -p".
This leaves the problem from 4c7f1819b3 unfixed, but:

  1. It's a pretty obscure problem in the first place. I
     only noticed it while working on the color code, and we
     haven't got a single bug report or complaint about it.

  2. We can make a more moderate fix on top by respecting
     "never" but not "always" for plumbing commands. This
     is just the minimal fix to go back to the working state
     we had before v2.14.2.

Note that this isn't a pure revert. We now have a test in
t3701 which shows off the "add -p" regression. This can be
flipped to success.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoRevert "t6006: drop "always" color config tests"
Jeff King [Fri, 13 Oct 2017 17:23:41 +0000 (13:23 -0400)] 
Revert "t6006: drop "always" color config tests"

This reverts commit c5bdfe677cfab5b2e87771c35565d44d3198efda.

That commit was done primarily to prepare for the weakening
of "always" in 6be4595edb (color: make "always" the same as
"auto" in config, 2017-10-03). But since we've now reverted
6be4595edb, there's no need for us to remove "-c
color.ui=always" from the tests. And in fact it's a good
idea to restore these tests, to make sure that "always"
continues to work.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoRevert "color: make "always" the same as "auto" in config"
Jeff King [Fri, 13 Oct 2017 17:23:24 +0000 (13:23 -0400)] 
Revert "color: make "always" the same as "auto" in config"

This reverts commit 6be4595edb8e5b616c6e8b9fbc78b0f831fa2a87.

That commit weakened the "always" setting of color config so
that it acted as "auto". This was meant to solve regressions
in v2.14.2 in which setting "color.ui=always" in the on-disk
config broke scripts like add--interactive, because the
plumbing diff commands began to generate color output.

This was due to 136c8c8b8f (color: check color.ui in
git_default_config(), 2017-07-13), which was in turn trying
to fix issues caused by 4c7f1819b3 (make color.ui default to
'auto', 2013-06-10). But in weakening "always", we created
even more problems, as people expect to be able to use "git
-c color.ui=always" to force color (especially because some
commands don't have their own --color flag). We can fix that
by special-casing the command-line "-c", but now things are
getting pretty confusing.

Instead of piling hacks upon hacks, let's start peeling off
the hacks. The first step is dropping the weakening of
"always", which this revert does.

Note that we could actually revert the whole series merged
in by da15b78e52642bd45fd5513ab0000fdf2e58a6f4. Most of that
series consists of preparations to the tests to handle the
weakening of "-c color.ui=always". But it's worth keeping
for a few reasons:

  - there are some other preparatory cleanups, like
    e433749d86 (test-terminal: set TERM=vt100, 2017-10-03)

  - it adds "--color" options more consistently in
    0c88bf5050 (provide --color option for all ref-filter
    users, 2017-10-03)

  - some of the cases dropping "-c" end up being more robust
    and realistic tests, as in 01c94e9001 (t7508: use
    test_terminal for color output, 2017-10-03)

  - the preferred tool for overriding config is "--color",
    and we should be modeling that consistently

We can individually revert the few commits necessary to
restore some useful tests (which will be done on top of this
patch).

Note that this isn't a pure revert; we'll keep the test
added in t3701, but mark it as failure for now.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoMerge branch 'jk/ui-color-always-to-auto-maint' (early part) into jk/ref-filter-color...
Junio C Hamano [Tue, 17 Oct 2017 06:08:31 +0000 (15:08 +0900)] 
Merge branch 'jk/ui-color-always-to-auto-maint' (early part) into jk/ref-filter-colors-fix-maint

* 'jk/ui-color-always-to-auto-maint' (early part):
  color: make "always" the same as "auto" in config
  provide --color option for all ref-filter users
  t3205: use --color instead of color.branch=always
  t3203: drop "always" color test
  t6006: drop "always" color config tests
  t7502: use diff.noprefix for --verbose test
  t7508: use test_terminal for color output
  t3701: use test-terminal to collect color output
  t4015: prefer --color to -c color.diff=always
  test-terminal: set TERM=vt100

6 years agoCrawling towards -rc2
Junio C Hamano [Tue, 17 Oct 2017 04:31:31 +0000 (13:31 +0900)] 
Crawling towards -rc2

Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoMerge branch 'sb/diff-color-move'
Junio C Hamano [Tue, 17 Oct 2017 04:29:19 +0000 (13:29 +0900)] 
Merge branch 'sb/diff-color-move'

A recently added "--color-moved" feature of "diff" fell into
infinite loop when ignoring whitespace changes, which has been
fixed.

* sb/diff-color-move:
  diff: fix infinite loop with --color-moved --ignore-space-change

6 years agoMerge branch 'js/rebase-i-final'
Junio C Hamano [Tue, 17 Oct 2017 04:29:19 +0000 (13:29 +0900)] 
Merge branch 'js/rebase-i-final'

Error message fix.

* js/rebase-i-final:
  sequencer.c: fix and unify error messages in rearrange_squash()

6 years agoMerge branch 'jc/doc-checkout'
Junio C Hamano [Tue, 17 Oct 2017 04:29:19 +0000 (13:29 +0900)] 
Merge branch 'jc/doc-checkout'

Doc update.

* jc/doc-checkout:
  checkout doc: clarify command line args for "checkout paths" mode

6 years agol10n: es.po: v2.15.0 round 2
Christopher Díaz Riveros [Tue, 17 Oct 2017 02:17:30 +0000 (21:17 -0500)] 
l10n: es.po: v2.15.0 round 2

Spanish translation for v2.15.0

Signed-off-by: Christopher Díaz Riveros <chrisadr@gentoo.org>
6 years agol10n: git.pot: v2.15.0 round 2 (2 new, 2 removed)
Jiang Xin [Tue, 17 Oct 2017 01:49:23 +0000 (09:49 +0800)] 
l10n: git.pot: v2.15.0 round 2 (2 new, 2 removed)

Generate po/git.pot from v2.15.0-rc1 for git v2.15.0 l10n round 2.

Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
6 years agoMerge branch 'master' of git://github.com/git-l10n/git-po
Jiang Xin [Tue, 17 Oct 2017 01:44:24 +0000 (09:44 +0800)] 
Merge branch 'master' of git://github.com/git-l10n/git-po

* 'master' of git://github.com/git-l10n/git-po:
  l10n: ru.po: update Russian translation
  l10n: bg.po: Updated Bulgarian translation (3245t)
  l10n: sv.po: Update Swedish translation (3245t0f0u)
  l10n: vi.po(3245t): Updated Vietnamese translation for v2.15.0
  l10n: es.po: Update translation v2.15.0 round 1
  l10n: git.pot: v2.15.0 round 1 (68 new, 36 removed)
  l10n: es.po: spanish added to TEAMS
  l10n: es.po: initial Spanish version git 2.14.0

6 years agodiff: fix infinite loop with --color-moved --ignore-space-change
Jeff King [Fri, 13 Oct 2017 00:18:37 +0000 (20:18 -0400)] 
diff: fix infinite loop with --color-moved --ignore-space-change

The --color-moved code uses next_byte() to advance through
the blob contents. When the user has asked to ignore
whitespace changes, we try to collapse any whitespace change
down to a single space.

However, we enter the conditional block whenever we see the
IGNORE_WHITESPACE_CHANGE flag, even if the next byte isn't
whitespace.

This means that the combination of "--color-moved and
--ignore-space-change" was completely broken. Worse, because
we return from next_byte() without having advanced our
pointer, the function makes no forward progress in the
buffer and loops infinitely.

Fix this by entering the conditional only when we actually
see whitespace. We can apply this also to the
IGNORE_WHITESPACE change. That code path isn't buggy
(because it falls through to returning the next
non-whitespace byte), but it makes the logic more clear if
we only bother to look at whitespace flags after seeing that
the next byte is whitespace.

Reported-by: Orgad Shaneh <orgads@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agosequencer.c: fix and unify error messages in rearrange_squash()
Ralf Thielow [Sun, 15 Oct 2017 17:07:42 +0000 (19:07 +0200)] 
sequencer.c: fix and unify error messages in rearrange_squash()

When the write opertion fails, we write that we could
not read. Change the error message to match the operation
and remove the full stop at the end.

When ftruncate() fails, we write that we couldn't finish
the operation on the todo file. It is more accurate to write
that we couldn't truncate as we do in other calls of ftruncate().

Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agol10n: ru.po: update Russian translation
Dimitriy Ryazantcev [Sun, 15 Oct 2017 10:14:45 +0000 (13:14 +0300)] 
l10n: ru.po: update Russian translation

Signed-off-by: Dimitriy Ryazantcev <dimitriy.ryazantcev@gmail.com>
6 years agoMerge branch 'master' of git://github.com/alshopov/git-po
Jiang Xin [Sat, 14 Oct 2017 13:24:21 +0000 (21:24 +0800)] 
Merge branch 'master' of git://github.com/alshopov/git-po

* 'master' of git://github.com/alshopov/git-po:
  l10n: bg.po: Updated Bulgarian translation (3245t)

6 years agol10n: bg.po: Updated Bulgarian translation (3245t)
Alexander Shopov [Sat, 14 Oct 2017 09:45:28 +0000 (11:45 +0200)] 
l10n: bg.po: Updated Bulgarian translation (3245t)

Signed-off-by: Alexander Shopov <ash@kambanaria.org>
6 years agoDocumentation/merge-options.txt: describe -S/--gpg-sign for 'pull'
W. Trevor King [Thu, 12 Oct 2017 09:02:17 +0000 (02:02 -0700)] 
Documentation/merge-options.txt: describe -S/--gpg-sign for 'pull'

Pull has supported these since ea230d8 (pull: add the --gpg-sign
option, 2014-02-10).  Insert in long-option alphabetical order
following 7c85d274 (Documentation/merge-options.txt: order options
in alphabetical groups, 2009-10-22).

Signed-off-by: W. Trevor King <wking@tremily.us>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agol10n: sv.po: Update Swedish translation (3245t0f0u)
Peter Krefting [Wed, 11 Oct 2017 10:35:11 +0000 (11:35 +0100)] 
l10n: sv.po: Update Swedish translation (3245t0f0u)

Signed-off-by: Peter Krefting <peter@softwolves.pp.se>
6 years agocheckout doc: clarify command line args for "checkout paths" mode
Junio C Hamano [Wed, 11 Oct 2017 02:21:03 +0000 (11:21 +0900)] 
checkout doc: clarify command line args for "checkout paths" mode

There are "git checkout [-p][<tree-ish>][--][<paths>...]" in the
SYNOPSIS section, and "git checkout [-p][<tree-ish>][--]<paths>..."
as the header for the section that explains the "check out paths
from index/tree-ish" mode.  It is unclear if we require at least one
path, or it is entirely optional.

Actually, both are wrong.  Without the "-p(atch)" option, you must
have <pathspec> (otherwise, with a commit that is a <tree-ish>, you
would be checking out that commit to build a new history on top of
it).  With it, it is already clear that you are checking out paths,
it is optional.  In other words, you cannot omit both.

The source of the confusion is that -p(atch) is described as if it
is just another "optional" part and its description is lumped
together with the non patch mode, even though the actual end user
experience is vastly different.

Let's split the entry into two, and describe the regular mode and
the patch mode separately.  This allows us to make it clear that the
regular mode MUST be given at least one pathspec, that the patch
mode can be invoked with either '-p' or '--patch' but one of these
must be given, and that the pathspec is entirely optional in the
patch mode.

Also, revamp the explanation of "checkout paths" by removing
extraneous description at the beginning, that says "checking out
paths is not checking out a branch".  Explaining what it is for and
when the user wants to use it upfront is the most direct way to help
the readers.

Noticed-by: Robert P J Day
Helped-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoGit 2.15-rc1 v2.15.0-rc1
Junio C Hamano [Wed, 11 Oct 2017 05:54:04 +0000 (14:54 +0900)] 
Git 2.15-rc1

Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoMerge branch 'ls/filter-process-delayed'
Junio C Hamano [Wed, 11 Oct 2017 05:52:24 +0000 (14:52 +0900)] 
Merge branch 'ls/filter-process-delayed'

Bugfixes to an already graduated series.

* ls/filter-process-delayed:
  write_entry: untangle symlink and regular-file cases
  write_entry: avoid reading blobs in CE_RETRY case
  write_entry: fix leak when retrying delayed filter
  entry.c: check if file exists after checkout
  entry.c: update cache entry only for existing files

6 years agoMerge branch 'ds/avoid-overflow-in-midpoint-computation'
Junio C Hamano [Wed, 11 Oct 2017 05:52:24 +0000 (14:52 +0900)] 
Merge branch 'ds/avoid-overflow-in-midpoint-computation'

Code clean-up.

* ds/avoid-overflow-in-midpoint-computation:
  cleanup: fix possible overflow errors in binary search

6 years agoMerge branch 'tb/complete-describe'
Junio C Hamano [Wed, 11 Oct 2017 05:52:23 +0000 (14:52 +0900)] 
Merge branch 'tb/complete-describe'

Docfix.

* tb/complete-describe:
  completion: add --broken and --dirty to describe

6 years agoMerge branch 'sb/test-cmp-expect-actual'
Junio C Hamano [Wed, 11 Oct 2017 05:52:23 +0000 (14:52 +0900)] 
Merge branch 'sb/test-cmp-expect-actual'

Test tweak.

* sb/test-cmp-expect-actual:
  tests: fix diff order arguments in test_cmp

6 years agoMerge branch 'jk/refs-df-conflict'
Junio C Hamano [Wed, 11 Oct 2017 05:52:23 +0000 (14:52 +0900)] 
Merge branch 'jk/refs-df-conflict'

An ancient bug that made Git misbehave with creation/renaming of
refs has been fixed.

* jk/refs-df-conflict:
  refs_resolve_ref_unsafe: handle d/f conflicts for writes
  t3308: create a real ref directory/file conflict

6 years agoMerge branch 'rs/rs-mailmap'
Junio C Hamano [Wed, 11 Oct 2017 05:52:23 +0000 (14:52 +0900)] 
Merge branch 'rs/rs-mailmap'

* rs/rs-mailmap:
  .mailmap: normalize name for René Scharfe

6 years agoMerge branch 'rs/fsck-null-return-from-lookup'
Junio C Hamano [Wed, 11 Oct 2017 05:52:23 +0000 (14:52 +0900)] 
Merge branch 'rs/fsck-null-return-from-lookup'

Improve behaviour of "git fsck" upon finding a missing object.

* rs/fsck-null-return-from-lookup:
  fsck: handle NULL return of lookup_blob() and lookup_tree()

6 years agoMerge branch 'jk/sha1-loose-object-info-fix'
Junio C Hamano [Wed, 11 Oct 2017 05:52:22 +0000 (14:52 +0900)] 
Merge branch 'jk/sha1-loose-object-info-fix'

Leakfix and futureproofing.

* jk/sha1-loose-object-info-fix:
  sha1_loose_object_info: handle errors from unpack_sha1_rest

6 years agoMerge branch 'hn/string-list-doc'
Junio C Hamano [Wed, 11 Oct 2017 05:52:22 +0000 (14:52 +0900)] 
Merge branch 'hn/string-list-doc'

Docfix.

* hn/string-list-doc:
  api-argv-array.txt: remove broken link to string-list API

6 years agoMerge branch 'tb/show-trailers-in-ref-filter'
Junio C Hamano [Wed, 11 Oct 2017 05:52:22 +0000 (14:52 +0900)] 
Merge branch 'tb/show-trailers-in-ref-filter'

"git for-each-ref --format=..." learned a new format element,
%(trailers), to show only the commit log trailer part of the log
message.

* tb/show-trailers-in-ref-filter:
  ref-filter.c: parse trailers arguments with %(contents) atom
  ref-filter.c: use trailer_opts to format trailers
  t6300: refactor %(trailers) tests
  doc: use "`<literal>`"-style quoting for literal strings
  doc: 'trailers' is the preferred way to format trailers
  t4205: unfold across multiple lines

6 years agoMerge branch 'jt/oidmap'
Junio C Hamano [Wed, 11 Oct 2017 05:52:22 +0000 (14:52 +0900)] 
Merge branch 'jt/oidmap'

Introduce a new "oidmap" API and rewrite oidset to use it.

* jt/oidmap:
  oidmap: map with OID as key

6 years agoMerge branch 'jr/hash-migration-plan-doc'
Junio C Hamano [Wed, 11 Oct 2017 05:52:22 +0000 (14:52 +0900)] 
Merge branch 'jr/hash-migration-plan-doc'

Lay out plans for weaning us off of SHA-1.

* jr/hash-migration-plan-doc:
  technical doc: add a design doc for hash function transition

6 years agoMerge branch 'master' of https://github.com/vnwildman/git
Jiang Xin [Wed, 11 Oct 2017 00:08:10 +0000 (08:08 +0800)] 
Merge branch 'master' of https://github.com/vnwildman/git

* 'master' of https://github.com/vnwildman/git:
  l10n: vi.po(3245t): Updated Vietnamese translation for v2.15.0

6 years agowrite_entry: untangle symlink and regular-file cases
Jeff King [Mon, 9 Oct 2017 17:50:05 +0000 (13:50 -0400)] 
write_entry: untangle symlink and regular-file cases

The write_entry() function switches on the mode of the entry
we're going to write out. The cases for S_IFLNK and S_IFREG
are lumped together. In earlier versions of the code, this
made some sense. They have a shared preamble (which reads
the blob content), a short type-specific body, and a shared
conclusion (which writes out the file contents; always for
S_IFREG and only sometimes for S_IFLNK).

But over time this has grown to make less sense. The preamble
now has conditional bits for each type, and the S_IFREG body
has grown a lot more complicated. It's hard to follow the
logic of which code is running for which mode.

Let's give each mode its own case arm. We will still share
the conclusion code, which means we now jump to it with a
goto. Ideally we'd pull that shared code into its own
function, but it touches so much internal state in the
write_entry() function that the end result is actually
harder to follow than the goto.

While we're here, we'll touch up a few bits of whitespace to
make the beginning and endings of the cases easier to read.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agowrite_entry: avoid reading blobs in CE_RETRY case
Jeff King [Mon, 9 Oct 2017 17:48:52 +0000 (13:48 -0400)] 
write_entry: avoid reading blobs in CE_RETRY case

When retrying a delayed filter-process request, we don't
need to send the blob to the filter a second time. However,
we read it unconditionally into a buffer, only to later
throw away that buffer. We can make this more efficient by
skipping the read in the first place when it isn't
necessary.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agowrite_entry: fix leak when retrying delayed filter
Jeff King [Mon, 9 Oct 2017 17:48:24 +0000 (13:48 -0400)] 
write_entry: fix leak when retrying delayed filter

When write_entry() retries a delayed filter request, we
don't need to send the blob content to the filter again, and
set the pointer to NULL. But doing so means we leak the
contents we read earlier from read_blob_entry(). Let's make
sure to free it before dropping the pointer.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agocleanup: fix possible overflow errors in binary search
Derrick Stolee [Sun, 8 Oct 2017 18:29:37 +0000 (14:29 -0400)] 
cleanup: fix possible overflow errors in binary search

A common mistake when writing binary search is to allow possible
integer overflow by using the simple average:

mid = (min + max) / 2;

Instead, use the overflow-safe version:

mid = min + (max - min) / 2;

This translation is safe since the operation occurs inside a loop
conditioned on "min < max". The included changes were found using
the following git grep:

git grep '/ *2;' '*.c'

Making this cleanup will prevent future review friction when a new
binary search is contructed based on existing code.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoMerge branch 'js/rebase-i-final'
Junio C Hamano [Mon, 9 Oct 2017 09:59:16 +0000 (18:59 +0900)] 
Merge branch 'js/rebase-i-final'

* js/rebase-i-final:
  i18n: add a missing space in message

6 years agoi18n: add a missing space in message
Jean-Noel Avila [Sun, 8 Oct 2017 12:18:39 +0000 (14:18 +0200)] 
i18n: add a missing space in message

The message spans over 2 lines but the C conconcatenation does not add
the needed space between the two lines.

Signed-off-by: Jean-Noel Avila <jn.avila@free.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agol10n: vi.po(3245t): Updated Vietnamese translation for v2.15.0
Tran Ngoc Quan [Mon, 9 Oct 2017 08:13:05 +0000 (15:13 +0700)] 
l10n: vi.po(3245t): Updated Vietnamese translation for v2.15.0

Signed-off-by: Tran Ngoc Quan <vnwildman@gmail.com>
6 years agol10n: es.po: Update translation v2.15.0 round 1
Christopher Díaz [Sun, 8 Oct 2017 16:30:11 +0000 (11:30 -0500)] 
l10n: es.po: Update translation v2.15.0 round 1

Signed-off-by: Christopher Díaz <christopher.diaz.riv@gmail.com>
6 years agoMerge branch 'maint' of git://github.com/git-l10n/git-po
Jiang Xin [Sun, 8 Oct 2017 07:21:22 +0000 (15:21 +0800)] 
Merge branch 'maint' of git://github.com/git-l10n/git-po

* 'maint' of git://github.com/git-l10n/git-po:
  l10n: es.po: spanish added to TEAMS
  l10n: es.po: initial Spanish version git 2.14.0

6 years agol10n: git.pot: v2.15.0 round 1 (68 new, 36 removed)
Jiang Xin [Sun, 8 Oct 2017 07:12:45 +0000 (15:12 +0800)] 
l10n: git.pot: v2.15.0 round 1 (68 new, 36 removed)

Generate po/git.pot from commit d35688db19 ("Prepare for -rc1",
2017-10-07) for git v2.15.0 l10n round 1.

Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
6 years agoPrepare for -rc1
Junio C Hamano [Sat, 7 Oct 2017 07:29:03 +0000 (16:29 +0900)] 
Prepare for -rc1

Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoMerge branch 'tb/ref-filter-empty-modifier'
Junio C Hamano [Sat, 7 Oct 2017 07:27:56 +0000 (16:27 +0900)] 
Merge branch 'tb/ref-filter-empty-modifier'

In the "--format=..." option of the "git for-each-ref" command (and
its friends, i.e. the listing mode of "git branch/tag"), "%(atom:)"
(e.g. "%(refname:)", "%(body:)" used to error out.  Instead, treat
them as if the colon and an empty string that follows it were not
there.

* tb/ref-filter-empty-modifier:
  ref-filter.c: pass empty-string as NULL to atom parsers

6 years agoMerge branch 'ks/verify-filename-non-option-error-message-tweak'
Junio C Hamano [Sat, 7 Oct 2017 07:27:55 +0000 (16:27 +0900)] 
Merge branch 'ks/verify-filename-non-option-error-message-tweak'

Error message tweak.

* ks/verify-filename-non-option-error-message-tweak:
  setup: update error message to be more meaningful

6 years agoMerge branch 'ks/branch-tweak-error-message-for-extra-args'
Junio C Hamano [Sat, 7 Oct 2017 07:27:55 +0000 (16:27 +0900)] 
Merge branch 'ks/branch-tweak-error-message-for-extra-args'

Error message tweak.

* ks/branch-tweak-error-message-for-extra-args:
  branch: change the error messages to be more meaningful

6 years agoMerge branch 'jk/ui-color-always-to-auto'
Junio C Hamano [Sat, 7 Oct 2017 07:27:55 +0000 (16:27 +0900)] 
Merge branch 'jk/ui-color-always-to-auto'

Fix regression of "git add -p" for users with "color.ui = always"
in their configuration, by merging the topic below and adjusting it
for the 'master' front.

* jk/ui-color-always-to-auto:
  t7301: use test_terminal to check color
  t4015: use --color with --color-moved
  color: make "always" the same as "auto" in config
  provide --color option for all ref-filter users
  t3205: use --color instead of color.branch=always
  t3203: drop "always" color test
  t6006: drop "always" color config tests
  t7502: use diff.noprefix for --verbose test
  t7508: use test_terminal for color output
  t3701: use test-terminal to collect color output
  t4015: prefer --color to -c color.diff=always
  test-terminal: set TERM=vt100

6 years agoMerge branch 'ma/builtin-unleak'
Junio C Hamano [Sat, 7 Oct 2017 07:27:55 +0000 (16:27 +0900)] 
Merge branch 'ma/builtin-unleak'

Many variables that points at a region of memory that will live
throughout the life of the program have been marked with UNLEAK
marker to help the leak checkers concentrate on real leaks..

* ma/builtin-unleak:
  builtin/: add UNLEAKs

6 years agoMerge branch 'rb/compat-poll-fix'
Junio C Hamano [Sat, 7 Oct 2017 07:27:55 +0000 (16:27 +0900)] 
Merge branch 'rb/compat-poll-fix'

Backports a moral equivalent of 2015 fix to the poll emulation from
the upstream gnulib to fix occasional breakages on HPE NonStop.

* rb/compat-poll-fix:
  poll.c: always set revents, even if to zero

6 years agoMerge branch 'tg/memfixes'
Junio C Hamano [Sat, 7 Oct 2017 07:27:54 +0000 (16:27 +0900)] 
Merge branch 'tg/memfixes'

Fixes for a handful memory access issues identified by valgrind.

* tg/memfixes:
  sub-process: use child_process.args instead of child_process.argv
  http-push: fix construction of hex value from path
  path.c: fix uninitialized memory access

6 years agoMerge branch 'sb/branch-avoid-repeated-strbuf-release'
Junio C Hamano [Sat, 7 Oct 2017 07:27:54 +0000 (16:27 +0900)] 
Merge branch 'sb/branch-avoid-repeated-strbuf-release'

* sb/branch-avoid-repeated-strbuf-release:
  branch: reset instead of release a strbuf

6 years agoMerge branch 'rs/qsort-s'
Junio C Hamano [Sat, 7 Oct 2017 07:27:53 +0000 (16:27 +0900)] 
Merge branch 'rs/qsort-s'

* rs/qsort-s:
  test-stringlist: avoid buffer underrun when sorting nothing

6 years agoMerge branch 'jn/strbuf-doc-re-reuse'
Junio C Hamano [Sat, 7 Oct 2017 07:27:53 +0000 (16:27 +0900)] 
Merge branch 'jn/strbuf-doc-re-reuse'

* jn/strbuf-doc-re-reuse:
  strbuf doc: reuse after strbuf_release is fine

6 years agoMerge branch 'tb/delimit-pretty-trailers-args-with-comma'
Junio C Hamano [Sat, 7 Oct 2017 07:27:52 +0000 (16:27 +0900)] 
Merge branch 'tb/delimit-pretty-trailers-args-with-comma'

The feature that allows --pretty='%(trailers)' to take modifiers
like "fold" and "only" used to separate these modifiers with a
comma, i.e. "%(trailers:fold:only)", but we changed our mind and
use a comma, i.e. "%(trailers:fold,only)".  Fast track this change
before this new feature becomes part of any official release.

* tb/delimit-pretty-trailers-args-with-comma:
  pretty.c: delimit "%(trailers)" arguments with ","

6 years agocompletion: add --broken and --dirty to describe
Thomas Braun [Fri, 6 Oct 2017 18:02:47 +0000 (20:02 +0200)] 
completion: add --broken and --dirty to describe

When the flags for broken and dirty were implemented in
b0176ce6b5 (builtin/describe: introduce --broken flag, 2017-03-21)
and 9f67d2e827 (Teach "git describe" --dirty option, 2009-10-21)
the completion was not updated, although these flags are useful
completions. Add them.

Signed-off-by: Thomas Braun <thomas.braun@virtuell-zuhause.de>
Helped-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agotests: fix diff order arguments in test_cmp
Stefan Beller [Fri, 6 Oct 2017 19:00:06 +0000 (12:00 -0700)] 
tests: fix diff order arguments in test_cmp

Fix the argument order for test_cmp. When given the expected
result first the diff shows the actual output with '+' and the
expectation with '-', which is the convention for our tests.

Signed-off-by: Stefan Beller <sbeller@google.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agorefs_resolve_ref_unsafe: handle d/f conflicts for writes
Jeff King [Fri, 6 Oct 2017 14:42:17 +0000 (10:42 -0400)] 
refs_resolve_ref_unsafe: handle d/f conflicts for writes

If our call to refs_read_raw_ref() fails, we check errno to
see if the ref is simply missing, or if we encountered a
more serious error. If it's just missing, then in "write"
mode (i.e., when RESOLVE_REFS_READING is not set), this is
perfectly fine.

However, checking for ENOENT isn't sufficient to catch all
missing-ref cases. In the filesystem backend, we may also
see EISDIR when we try to resolve "a" and "a/b" exists.
Likewise, we may see ENOTDIR if we try to resolve "a/b" and
"a" exists. In both of those cases, we know that our
resolved ref doesn't exist, but we return an error (rather
than reporting the refname and returning a null sha1).

This has been broken for a long time, but nobody really
noticed because the next step after resolving without the
READING flag is usually to lock the ref and write it. But in
both of those cases, the write will fail with the same
errno due to the directory/file conflict.

There are two cases where we can notice this, though:

  1. If we try to write "a" and there's a leftover directory
     already at "a", even though there is no ref "a/b". The
     actual write is smart enough to move the empty "a" out
     of the way.

     This is reasonably rare, if only because the writing
     code has to do an independent resolution before trying
     its write (because the actual update_ref() code handles
     this case fine). The notes-merge code does this, and
     before the fix in the prior commit t3308 erroneously
     expected this case to fail.

  2. When resolving symbolic refs, we typically do not use
     the READING flag because we want to resolve even
     symrefs that point to unborn refs. Even if those unborn
     refs could not actually be written because of d/f
     conflicts with existing refs.

     You can see this by asking "git symbolic-ref" to report
     the target of a symref pointing past a d/f conflict.

We can fix the problem by recognizing the other "missing"
errnos and treating them like ENOENT. This should be safe to
do even for callers who are then going to actually write the
ref, because the actual writing process will fail if the d/f
conflict is a real one (and t1404 checks these cases).

Arguably this should be the responsibility of the
files-backend to normalize all "missing ref" errors into
ENOENT (since something like EISDIR may not be meaningful at
all to a database backend). However other callers of
refs_read_raw_ref() may actually care about the distinction;
putting this into resolve_ref() is the minimal fix for now.

The new tests in t1401 use git-symbolic-ref, which is the
most direct way to check the resolution by itself.
Interestingly we actually had a test that setup this case
already, but we only used it to verify that the funny state
could be overwritten, not that it could be resolved.

We also add a new test in t3200, as "branch -m" was the
original motivation for looking into this. What happens is
this:

  0. HEAD is pointing to branch "a"

  1. The user asks to rename "a" to "a/b".

  2. We create "a/b" and delete "a".

  3. We then try to update any worktree HEADs that point to
     the renamed ref (including the main repo HEAD). To do
     that, we have to resolve each HEAD. But now our HEAD is
     pointing at "a", and we get EISDIR due to the loose
     "a/b". As a result, we think there is no HEAD, and we
     do not update it. It now points to the bogus "a".

Interestingly this case used to work, but only accidentally.
Before 31824d180d (branch: fix branch renaming not updating
HEADs correctly, 2017-08-24), we'd update any HEAD which we
couldn't resolve. That was wrong, but it papered over the
fact that we were incorrectly failing to resolve HEAD.

So while the bug demonstrated by the git-symbolic-ref is
quite old, the regression to "branch -m" is recent.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agot3308: create a real ref directory/file conflict
Jeff King [Fri, 6 Oct 2017 14:38:30 +0000 (10:38 -0400)] 
t3308: create a real ref directory/file conflict

A test in t3308 wants to make sure that we don't
accidentally merge into "refs/notes/dir" when it exists as a
directory, so it does:

  mkdir .git/refs/notes/dir
  git -c core.notesRef=refs/notes/dir merge ...

and expects the second command to fail. But that
understimates the refs code, which is smart enough to remove
useless directories in the refs hierarchy. The test
succeeded only because of a bug which prevented resolving
refs/notes/dir for writing, even though an actual ref update
would succeed.

In preparation for fixing that bug, let's switch to creating
a real ref in refs/notes/dir, which is a more realistic
situation.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoapi-argv-array.txt: remove broken link to string-list API
Todd Zullinger [Fri, 6 Oct 2017 03:14:56 +0000 (23:14 -0400)] 
api-argv-array.txt: remove broken link to string-list API

In 4f665f2cf3 (string-list.h: move documentation from Documentation/api/
into header, 2017-09-26) the string-list API documentation was moved to
string-list.h.  The argv-array API documentation may follow a similar
course in the future.  Until then, prevent the broken link from making
it to the end-user documentation.

Signed-off-by: Todd Zullinger <tmz@pobox.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoentry.c: check if file exists after checkout
Lars Schneider [Thu, 5 Oct 2017 10:44:07 +0000 (12:44 +0200)] 
entry.c: check if file exists after checkout

If we are checking out a file and somebody else racily deletes our file,
then we would write garbage to the cache entry. Fix that by checking
the result of the lstat() call on that file. Print an error to the user
if the file does not exist.

Reported-by: Jeff King <peff@peff.net>
Signed-off-by: Lars Schneider <larsxschneider@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agosha1_loose_object_info: handle errors from unpack_sha1_rest
Jeff King [Thu, 5 Oct 2017 05:59:52 +0000 (01:59 -0400)] 
sha1_loose_object_info: handle errors from unpack_sha1_rest

When a caller of sha1_object_info_extended() sets the
"contentp" field in object_info, we call unpack_sha1_rest()
but do not check whether it signaled an error.

This causes two problems:

  1. We pass back NULL to the caller via the contentp field,
     but the function returns "0" for success. A caller
     might reasonably expect after a successful return that
     it can access contentp without a NULL check and
     segfault.

     As it happens, this is impossible to trigger in the
     current code. There is exactly one caller which uses
     contentp, read_object(). And the only thing it does
     after a successful call is to return the content
     pointer to its caller, using NULL as a sentinel for
     errors. So in effect it converts the success code from
     sha1_object_info_extended() back into an error!

     But this is still worth addressing avoid problems for
     future users of "contentp".

  2. Callers of unpack_sha1_rest() are expected to close the
     zlib stream themselves on error. Which means that we're
     leaking the stream.

The problem in (1) comes from from c84a1f3ed4 (sha1_file:
refactor read_object, 2017-06-21), which added the contentp
field.  Before that, we called unpack_sha1_rest() via
unpack_sha1_file(), which directly used the NULL to signal
an error.

But note that the leak in (2) is actually older than that.
The original unpack_sha1_file() directly returned the result
of unpack_sha1_rest() to its caller, when it should have
been closing the zlib stream itself on error.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years ago.mailmap: normalize name for René Scharfe
René Scharfe [Thu, 5 Oct 2017 19:41:31 +0000 (21:41 +0200)] 
.mailmap: normalize name for René Scharfe

Reported-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Reported-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agofsck: handle NULL return of lookup_blob() and lookup_tree()
René Scharfe [Thu, 5 Oct 2017 19:41:26 +0000 (21:41 +0200)] 
fsck: handle NULL return of lookup_blob() and lookup_tree()

lookup_blob() and lookup_tree() can return NULL if they find an object
of an unexpected type.  Accessing the object member is undefined in that
case.  Cast the result to a struct object pointer instead; we can do
that because object is the first member of all object types.  This trick
is already used in other places in the code.

An error message is already shown by object_as_type(), which is called
by the lookup functions.  The walk callback functions are expected to
handle NULL object pointers passed to them, but put_object_name() needs
a valid object, so avoid calling it without one.

Suggested-by: SZEDER Gábor <szeder.dev@gmail.com>
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoentry.c: update cache entry only for existing files
Lars Schneider [Thu, 5 Oct 2017 10:44:06 +0000 (12:44 +0200)] 
entry.c: update cache entry only for existing files

In 2841e8f ("convert: add "status=delayed" to filter process protocol",
2017-06-30) we taught the filter process protocol to delay responses.

That means an external filter might answer in the first write_entry()
call on a file that requires filtering  "I got your request, but I
can't answer right now. Ask again later!". As Git got no answer, we do
not write anything to the filesystem. Consequently, the lstat() call in
the finish block of the function writes garbage to the cache entry.
The garbage is eventually overwritten when the filter answers with
the final file content in a subsequent write_entry() call.

Fix the brief time window of garbage in the cache entry by adding a
special finish block that does nothing for delayed responses. The cache
entry is written properly in a subsequent write_entry() call where
the filter responds with the final file content.

Reported-by: Jeff King <peff@peff.net>
Signed-off-by: Lars Schneider <larsxschneider@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoGit 2.15-rc0 v2.15.0-rc0
Junio C Hamano [Thu, 5 Oct 2017 04:49:07 +0000 (13:49 +0900)] 
Git 2.15-rc0

Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoMerge branch 'ar/request-pull-phrasofix'
Junio C Hamano [Thu, 5 Oct 2017 04:48:21 +0000 (13:48 +0900)] 
Merge branch 'ar/request-pull-phrasofix'

Spell the name of our system as "Git" in the output from
request-pull script.

* ar/request-pull-phrasofix:
  request-pull: capitalise "Git" to make it a proper noun

6 years agoMerge branch 'rs/run-command-use-alloc-array'
Junio C Hamano [Thu, 5 Oct 2017 04:48:20 +0000 (13:48 +0900)] 
Merge branch 'rs/run-command-use-alloc-array'

Code clean-up.

* rs/run-command-use-alloc-array:
  run-command: use ALLOC_ARRAY

6 years agoMerge branch 'sb/git-clang-format'
Junio C Hamano [Thu, 5 Oct 2017 04:48:20 +0000 (13:48 +0900)] 
Merge branch 'sb/git-clang-format'

Add comment to clarify that the style file is meant to be used with
clang-5 and the rules are still work in progress.

* sb/git-clang-format:
  clang-format: add a comment about the meaning/status of the

6 years agoMerge branch 'rs/use-free-and-null'
Junio C Hamano [Thu, 5 Oct 2017 04:48:20 +0000 (13:48 +0900)] 
Merge branch 'rs/use-free-and-null'

Code clean-up.

* rs/use-free-and-null:
  repository: use FREE_AND_NULL

6 years agoMerge branch 'rs/tag-null-pointer-arith-fix'
Junio C Hamano [Thu, 5 Oct 2017 04:48:19 +0000 (13:48 +0900)] 
Merge branch 'rs/tag-null-pointer-arith-fix'

Code clean-up.

* rs/tag-null-pointer-arith-fix:
  tag: avoid NULL pointer arithmetic

6 years agoMerge branch 'rs/cocci-de-paren-call-params'
Junio C Hamano [Thu, 5 Oct 2017 04:48:19 +0000 (13:48 +0900)] 
Merge branch 'rs/cocci-de-paren-call-params'

Code clean-up.

* rs/cocci-de-paren-call-params:
  coccinelle: remove parentheses that become unnecessary

6 years agoMerge branch 'rs/cleanup-strbuf-users'
Junio C Hamano [Thu, 5 Oct 2017 04:48:19 +0000 (13:48 +0900)] 
Merge branch 'rs/cleanup-strbuf-users'

Code clean-up.

* rs/cleanup-strbuf-users:
  graph: use strbuf_addchars() to add spaces
  use strbuf_addstr() for adding strings to strbufs
  path: use strbuf_add_real_path()

6 years agoMerge branch 'rs/resolve-ref-optional-result'
Junio C Hamano [Thu, 5 Oct 2017 04:48:19 +0000 (13:48 +0900)] 
Merge branch 'rs/resolve-ref-optional-result'

Code clean-up.

* rs/resolve-ref-optional-result:
  refs: pass NULL to resolve_refdup() if hash is not needed
  refs: pass NULL to refs_resolve_refdup() if hash is not needed

6 years agoMerge branch 'er/fast-import-dump-refs-on-checkpoint'
Junio C Hamano [Thu, 5 Oct 2017 04:48:19 +0000 (13:48 +0900)] 
Merge branch 'er/fast-import-dump-refs-on-checkpoint'

The checkpoint command "git fast-import" did not flush updates to
refs and marks unless at least one object was created since the
last checkpoint, which has been corrected, as these things can
happen without any new object getting created.

* er/fast-import-dump-refs-on-checkpoint:
  fast-import: checkpoint: dump branches/tags/marks even if object_count==0

6 years agoref-filter.c: pass empty-string as NULL to atom parsers
Taylor Blau [Mon, 2 Oct 2017 16:10:34 +0000 (09:10 -0700)] 
ref-filter.c: pass empty-string as NULL to atom parsers

Peff points out that different atom parsers handle the empty
"sub-argument" list differently. An example of this is the format
"%(refname:)".

Since callers often use `string_list_split` (which splits the empty
string with any delimiter as a 1-ary string_list containing the empty
string), this makes handling empty sub-argument strings non-ergonomic.

Let's fix this by declaring that atom parser implementations must
not care about distinguishing between the empty string "%(refname:)"
and no sub-arguments "%(refname)".  Current code aborts, either with
"unrecognised arg" (e.g. "refname:") or "does not take args"
(e.g. "body:") as an error message.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Reviewed-by: Jeff King <peff@peff.net>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agostrbuf doc: reuse after strbuf_release is fine
Jonathan Nieder [Wed, 4 Oct 2017 02:39:54 +0000 (19:39 -0700)] 
strbuf doc: reuse after strbuf_release is fine

strbuf_release leaves the strbuf in a valid, initialized state, so
there is no need to call strbuf_init after it.

Moreover, this is not likely to change in the future: strbuf_release
leaving the strbuf in a valid state has been easy to maintain and has
been very helpful for Git's robustness and simplicity (e.g.,
preventing use-after-free vulnerabilities).

Document the semantics so the next generation of Git developers can
become familiar with them without reading the implementation.  It is
still not advisable to call strbuf_release too often because it is
wasteful, so add a note pointing to strbuf_reset for that.

The same semantics apply to strbuf_detach.  Add a similar note to its
docstring to make that clear.

Improved-by: Jeff King <peff@peff.net>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agobranch: reset instead of release a strbuf
Stefan Beller [Tue, 3 Oct 2017 22:17:40 +0000 (15:17 -0700)] 
branch: reset instead of release a strbuf

Our documentation advises to not re-use a strbuf, after strbuf_release
has been called on it. Use the proper reset instead.

Currently 'strbuf_release' releases and re-initializes the strbuf, so it
is safe, but slow. 'strbuf_reset' only resets the internal length variable,
such that this could also be accounted for as a micro-optimization.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agosub-process: use child_process.args instead of child_process.argv
Johannes Sixt [Tue, 3 Oct 2017 20:24:57 +0000 (22:24 +0200)] 
sub-process: use child_process.args instead of child_process.argv

Currently the argv is only allocated on the stack, and then assigned to
process->argv.  When the start_subprocess function goes out of scope,
the local argv variable is eliminated from the stack, but the pointer is
still kept around in process->argv.

Much later when we try to access the same process->argv in
finish_command, this leads us to access a memory location that no longer
contains what we want.  As argv0 is only used for printing errors, this
is not easily noticed in normal git operations.  However when running
t0021-conversion.sh through valgrind, valgrind rightfully complains:

==21024== Invalid read of size 8
==21024==    at 0x2ACF64: finish_command (run-command.c:869)
==21024==    by 0x2D6B18: subprocess_exit_handler (sub-process.c:72)
==21024==    by 0x2AB41E: cleanup_children (run-command.c:45)
==21024==    by 0x2AB526: cleanup_children_on_exit (run-command.c:81)
==21024==    by 0x54AD487: __run_exit_handlers (in /usr/lib/libc-2.26.so)
==21024==    by 0x54AD4D9: exit (in /usr/lib/libc-2.26.so)
==21024==    by 0x11A9EF: handle_builtin (git.c:550)
==21024==    by 0x11ABCC: run_argv (git.c:602)
==21024==    by 0x11AD8E: cmd_main (git.c:679)
==21024==    by 0x1BF125: main (common-main.c:43)
==21024==  Address 0x1ffeffec00 is on thread 1's stack
==21024==  1504 bytes below stack pointer
==21024==

These days, the child_process structure has its own args array, and
the standard way to set up its argv[] is to use that one, instead of
assigning to process->argv to point at an array that is outside.
Use that facility automatically fixes this issue.

Reported-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agohttp-push: fix construction of hex value from path
Thomas Gummerer [Tue, 3 Oct 2017 19:57:12 +0000 (20:57 +0100)] 
http-push: fix construction of hex value from path

The get_oid_hex_from_objpath takes care of creating a oid from a
pathname.  It does this by memcpy'ing the first two bytes of the path to
the "hex" string, then skipping the '/', and then copying the rest of the
path to the "hex" string.  Currently it fails to increase the pointer to
the hex string, so the second memcpy invocation just mashes over what
was copied in the first one, and leaves the last two bytes in the string
uninitialized.

This breaks valgrind in t5540, although the test passes without
valgrind:

==5490== Use of uninitialised value of size 8
==5490==    at 0x13C6B5: hexval (cache.h:1238)
==5490==    by 0x13C6DB: hex2chr (cache.h:1247)
==5490==    by 0x13C734: get_sha1_hex (hex.c:42)
==5490==    by 0x13C78E: get_oid_hex (hex.c:53)
==5490==    by 0x118BDA: get_oid_hex_from_objpath (http-push.c:1023)
==5490==    by 0x118C92: process_ls_object (http-push.c:1038)
==5490==    by 0x118E5B: handle_remote_ls_ctx (http-push.c:1077)
==5490==    by 0x118227: xml_end_tag (http-push.c:815)
==5490==    by 0x50C1448: ??? (in /usr/lib/libexpat.so.1.6.6)
==5490==    by 0x50C221B: ??? (in /usr/lib/libexpat.so.1.6.6)
==5490==    by 0x50BFBF2: ??? (in /usr/lib/libexpat.so.1.6.6)
==5490==    by 0x50C0B24: ??? (in /usr/lib/libexpat.so.1.6.6)
==5490==  Uninitialised value was created by a stack allocation
==5490==    at 0x118B63: get_oid_hex_from_objpath (http-push.c:1012)
==5490==

Fix this by correctly incrementing the pointer to the "hex" variable, so
the first two bytes are left untouched by the memcpy call, and the last
two bytes are correctly initialized.

Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agopath.c: fix uninitialized memory access
Jeff King [Tue, 3 Oct 2017 23:30:40 +0000 (19:30 -0400)] 
path.c: fix uninitialized memory access

In cleanup_path we're passing in a char array, run a memcmp on it, and
run through it without ever checking if something is in the array in the
first place.  This can lead us to access uninitialized memory, for
example in t5541-http-push-smart.sh test 7, when run under valgrind:

==4423== Conditional jump or move depends on uninitialised value(s)
==4423==    at 0x242FA9: cleanup_path (path.c:35)
==4423==    by 0x242FA9: mkpath (path.c:456)
==4423==    by 0x256CC7: refname_match (refs.c:364)
==4423==    by 0x26C181: count_refspec_match (remote.c:1015)
==4423==    by 0x26C181: match_explicit_lhs (remote.c:1126)
==4423==    by 0x26C181: check_push_refs (remote.c:1409)
==4423==    by 0x2ABB4D: transport_push (transport.c:870)
==4423==    by 0x186703: push_with_options (push.c:332)
==4423==    by 0x18746D: do_push (push.c:409)
==4423==    by 0x18746D: cmd_push (push.c:566)
==4423==    by 0x1183E0: run_builtin (git.c:352)
==4423==    by 0x11973E: handle_builtin (git.c:539)
==4423==    by 0x11973E: run_argv (git.c:593)
==4423==    by 0x11973E: main (git.c:698)
==4423==  Uninitialised value was created by a heap allocation
==4423==    at 0x4C2CD8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==4423==    by 0x4C2F195: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==4423==    by 0x2C196B: xrealloc (wrapper.c:137)
==4423==    by 0x29A30B: strbuf_grow (strbuf.c:66)
==4423==    by 0x29A30B: strbuf_vaddf (strbuf.c:277)
==4423==    by 0x242F9F: mkpath (path.c:454)
==4423==    by 0x256CC7: refname_match (refs.c:364)
==4423==    by 0x26C181: count_refspec_match (remote.c:1015)
==4423==    by 0x26C181: match_explicit_lhs (remote.c:1126)
==4423==    by 0x26C181: check_push_refs (remote.c:1409)
==4423==    by 0x2ABB4D: transport_push (transport.c:870)
==4423==    by 0x186703: push_with_options (push.c:332)
==4423==    by 0x18746D: do_push (push.c:409)
==4423==    by 0x18746D: cmd_push (push.c:566)
==4423==    by 0x1183E0: run_builtin (git.c:352)
==4423==    by 0x11973E: handle_builtin (git.c:539)
==4423==    by 0x11973E: run_argv (git.c:593)
==4423==    by 0x11973E: main (git.c:698)
==4423==

Avoid this by using skip_prefix(), which knows not to go beyond the
end of the string.

Reported-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agotest-stringlist: avoid buffer underrun when sorting nothing
René Scharfe [Tue, 3 Oct 2017 14:36:40 +0000 (16:36 +0200)] 
test-stringlist: avoid buffer underrun when sorting nothing

Check if the strbuf containing data to sort is empty before attempting
to trim a trailing newline character.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agosetup: update error message to be more meaningful
Kaartic Sivaraam [Mon, 2 Oct 2017 17:30:02 +0000 (23:00 +0530)] 
setup: update error message to be more meaningful

The error message shown when a flag is found when expecting a
filename wasn't clear as it didn't communicate what was wrong
using the 'suitable' words in *all* cases.

        $ git ls-files
        README.md
        test-file

Correct case,

        $ git rev-parse README.md --flags
        README.md
        --flags
        fatal: bad flag '--flags' used after filename

Incorrect case,

        $ git grep "some random regex" -n
        fatal: bad flag '-n' used after filename

The above case is incorrect as "some random regex" isn't a filename
in this case.

Change the error message to be general and communicative. This results
in the following output,

        $ git rev-parse README.md --flags
        README.md
        --flags
        fatal: option '--flags' must come before non-option arguments

        $ git grep "some random regex" -n
        fatal: option '-n' must come before non-option arguments

Signed-off-by: Kaartic Sivaraam <kaarticsivaraam91196@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agobranch: change the error messages to be more meaningful
Kaartic Sivaraam [Mon, 21 Aug 2017 13:36:08 +0000 (19:06 +0530)] 
branch: change the error messages to be more meaningful

The error messages shown when the branch command is misused
by supplying it wrong number of parameters wasn't meaningful.
That's because it used the the phrase "too many branches"
assuming all parameters to be "valid" branch names. It's not
always the case as exemplified below,

        $ git branch
          foo
        * master

        $ git branch -m foo foo old
        fatal: too many branches for a rename operation

Change the messages to be more general thus making no assumptions
about the "parameters".

Signed-off-by: Kaartic Sivaraam <kaarticsivaraam91196@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoMerge branch 'jk/ui-color-always-to-auto-maint' into jk/ui-color-always-to-auto
Junio C Hamano [Wed, 4 Oct 2017 03:03:05 +0000 (12:03 +0900)] 
Merge branch 'jk/ui-color-always-to-auto-maint' into jk/ui-color-always-to-auto

* jk/ui-color-always-to-auto-maint:
  color: make "always" the same as "auto" in config
  provide --color option for all ref-filter users
  t3205: use --color instead of color.branch=always
  t3203: drop "always" color test
  t6006: drop "always" color config tests
  t7502: use diff.noprefix for --verbose test
  t7508: use test_terminal for color output
  t3701: use test-terminal to collect color output
  t4015: prefer --color to -c color.diff=always
  test-terminal: set TERM=vt100

6 years agot7301: use test_terminal to check color
Jeff King [Tue, 3 Oct 2017 13:44:58 +0000 (09:44 -0400)] 
t7301: use test_terminal to check color

This test wants to confirm that "clean -i" shows color
output. Using test_terminal gives us a more realistic
environment than "color.ui=always", and prepares us for the
behavior of "always" changing in a future patch.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agot4015: use --color with --color-moved
Jeff King [Tue, 3 Oct 2017 13:41:51 +0000 (09:41 -0400)] 
t4015: use --color with --color-moved

The tests for --color-moved write their output to a file,
but doing so suppresses color output under "auto". Right now
this is solved by running the whole script under
"color.diff=always". In preparation for the behavior of
"always" changing, let's explicitly enable color.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agocolor: make "always" the same as "auto" in config
Jeff King [Tue, 3 Oct 2017 13:46:06 +0000 (09:46 -0400)] 
color: make "always" the same as "auto" in config

It can be handy to use `--color=always` (or it's synonym
`--color`) on the command-line to convince a command to
produce color even if it's stdout isn't going to the
terminal or a pager.

What's less clear is whether it makes sense to set config
variables like color.ui to `always`. For a one-shot like:

  git -c color.ui=always ...

it's potentially useful (especially if the command doesn't
directly support the `--color` option). But setting `always`
in your on-disk config is much muddier, as you may be
surprised when piped commands generate colors (and send them
to whatever is consuming the pipe downstream).

Some people have done this anyway, because:

  1. The documentation for color.ui makes it sound like
     using `always` is a good idea, when you almost
     certainly want `auto`.

  2. Traditionally not every command (and especially not
     plumbing) respected color.ui in the first place. So
     the confusion came up less frequently than it might
     have.

The situation changed in 136c8c8b8f (color: check color.ui
in git_default_config(), 2017-07-13), which negated point
(2): now scripts using only plumbing commands (like
add-interactive) are broken by this setting.

That commit was fixing real issues (e.g., by making
`color.ui=never` work, since `auto` is the default), so we
don't want to just revert it.  We could turn `always` into a
noop in plumbing commands, but that creates a hard-to-explain
inconsistency between the plumbing and other commands.

Instead, let's just turn `always` into `auto` for all config.
This does break the "one-shot" config shown above, but again,
we're probably better to have simple and consistent rules than
to try to special-case command-line config.

There is one place where `always` should retain its meaning:
on the command line, `--color=always` should continue to be
the same as `--color`, overriding any isatty checks. Since the
command-line parser also depends on git_config_colorbool(), we
can use the existence of the "var" string to deterine whether
we are serving the command-line or the config.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoprovide --color option for all ref-filter users
Jeff King [Tue, 3 Oct 2017 13:45:47 +0000 (09:45 -0400)] 
provide --color option for all ref-filter users

When ref-filter learned about want_color() in 11b087adfd
(ref-filter: consult want_color() before emitting colors,
2017-07-13), it became useful to be able to turn colors off
and on for specific commands. For git-branch, you can do so
with --color/--no-color.

But for git-for-each-ref and git-tag, the other users of
ref-filter, you have no option except to tweak the
"color.ui" config setting. Let's give both of these commands
the usual color command-line options.

This is a bit more obvious as a method for overriding the
config. And it also prepares us for the behavior of "always"
changing (so that we are still left with a way of forcing
color when our output goes to a non-terminal).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agot3205: use --color instead of color.branch=always
Jeff King [Tue, 3 Oct 2017 13:45:18 +0000 (09:45 -0400)] 
t3205: use --color instead of color.branch=always

To test the color output, we must convince "git branch" to
write colors to a non-terminal. We do that now by setting
the color config to "always".  In preparation for the
behavior of "always" changing, let's switch to using the
"--color" command-line option, which is more direct.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agot3203: drop "always" color test
Jeff King [Tue, 3 Oct 2017 13:44:39 +0000 (09:44 -0400)] 
t3203: drop "always" color test

In preparation for the behavior of "always" changing to
match "auto", we can simply drop this test. We already check
other forms (like "--color") independently.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agot6006: drop "always" color config tests
Jeff King [Tue, 3 Oct 2017 13:44:27 +0000 (09:44 -0400)] 
t6006: drop "always" color config tests

We test the %C() format placeholders with a variety of
color-inducing options, including "--color" and
"-c color.ui=always". In preparation for the behavior of
"always" changing, we need to do something with those
"always" tests.

We can drop ones that expect "always" to turn on color even
to a file, as that will become a synonym for "auto", which
is already tested.

For the "--no-color" test, we need to make sure that color
would otherwise be shown. To do this, we can use
test_terminal, which enables colors in the default setup.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>