git
6 years agostring-list.h: move documentation from Documentation/api/ into header
Han-Wen Nienhuys [Tue, 26 Sep 2017 11:21:50 +0000 (13:21 +0200)] 
string-list.h: move documentation from Documentation/api/ into header

This mirrors commit 'bdfdaa497 ("strbuf.h: integrate api-strbuf.txt
documentation, 2015-01-16") which did the same for strbuf.h:

* API documentation uses /** */ to set it apart from other comments.

* Function names were stripped from the comments.

* Ordering of the header was adjusted to follow the one from the text
  file.

* Edited some existing comments from string-list.h for consistency.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoThe ninth batch for 2.15
Junio C Hamano [Mon, 25 Sep 2017 06:28:27 +0000 (15:28 +0900)] 
The ninth batch for 2.15

Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoMerge branch 'ks/test-readme-phrasofix'
Junio C Hamano [Mon, 25 Sep 2017 06:24:10 +0000 (15:24 +0900)] 
Merge branch 'ks/test-readme-phrasofix'

Doc updates.

* ks/test-readme-phrasofix:
  t/README: fix typo and grammatically improve a sentence

6 years agoMerge branch 'ow/rev-parse-is-shallow-repo'
Junio C Hamano [Mon, 25 Sep 2017 06:24:10 +0000 (15:24 +0900)] 
Merge branch 'ow/rev-parse-is-shallow-repo'

"git rev-parse" learned "--is-shallow-repository", that is to be
used in a way similar to existing "--is-bare-repository" and
friends.

* ow/rev-parse-is-shallow-repo:
  rev-parse: rev-parse: add --is-shallow-repository

6 years agoMerge branch 'rj/test-ulimit-on-windows'
Junio C Hamano [Mon, 25 Sep 2017 06:24:09 +0000 (15:24 +0900)] 
Merge branch 'rj/test-ulimit-on-windows'

On Cygwin, "ulimit -s" does not report failure but it does not work
at all, which causes an unexpected success of some tests that
expect failures under a limited stack situation.  This has been
fixed.

* rj/test-ulimit-on-windows:
  t9010-*.sh: skip all tests if the PIPE prereq is missing
  test-lib: use more compact expression in PIPE prerequisite
  test-lib: don't use ulimit in test prerequisites on cygwin

6 years agoMerge branch 'jk/info-alternates-fix'
Junio C Hamano [Mon, 25 Sep 2017 06:24:09 +0000 (15:24 +0900)] 
Merge branch 'jk/info-alternates-fix'

A regression fix for 2.11 that made the code to read the list of
alternate object stores overrun the end of the string.

* jk/info-alternates-fix:
  read_info_alternates: warn on non-trivial errors
  read_info_alternates: read contents into strbuf

6 years agoMerge branch 'mh/for-each-string-list-item-empty-fix'
Junio C Hamano [Mon, 25 Sep 2017 06:24:09 +0000 (15:24 +0900)] 
Merge branch 'mh/for-each-string-list-item-empty-fix'

Code cmp.std.c nitpick.

* mh/for-each-string-list-item-empty-fix:
  for_each_string_list_item: avoid undefined behavior for empty list

6 years agoMerge branch 'tb/test-lint-echo-e'
Junio C Hamano [Mon, 25 Sep 2017 06:24:09 +0000 (15:24 +0900)] 
Merge branch 'tb/test-lint-echo-e'

The test linter has been taught that we do not like "echo -e".

* tb/test-lint-echo-e:
  test-lint: echo -e (or -E) is not portable

6 years agoMerge branch 'jk/revision-remove-cmdline-pathspec'
Junio C Hamano [Mon, 25 Sep 2017 06:24:09 +0000 (15:24 +0900)] 
Merge branch 'jk/revision-remove-cmdline-pathspec'

Code clean-up that also plugs memory leaks.

* jk/revision-remove-cmdline-pathspec:
  pathspec doc: parse_pathspec does not maintain references to args
  revision: replace "struct cmdline_pathspec" with argv_array

6 years agoMerge branch 'ls/travis-scriptify'
Junio C Hamano [Mon, 25 Sep 2017 06:24:09 +0000 (15:24 +0900)] 
Merge branch 'ls/travis-scriptify'

The scripts to drive TravisCI has been reorganized and then an
optimization to avoid spending cycles on a branch whose tip is
tagged has been implemented.

* ls/travis-scriptify:
  travis-ci: fix "skip_branch_tip_with_tag()" string comparison
  travis: dedent a few scripts that are indented overly deeply
  travis-ci: skip a branch build if equal tag is present
  travis-ci: move Travis CI code into dedicated scripts

6 years agoMerge branch 'aw/gc-lockfile-fscanf-fix'
Junio C Hamano [Mon, 25 Sep 2017 06:24:08 +0000 (15:24 +0900)] 
Merge branch 'aw/gc-lockfile-fscanf-fix'

"git gc" tries to avoid running two instances at the same time by
reading and writing pid/host from and to a lock file; it used to
use an incorrect fscanf() format when reading, which has been
corrected.

* aw/gc-lockfile-fscanf-fix:
  gc: call fscanf() with %<len>s, not %<len>c, when reading hostname

6 years agoMerge branch 'hv/mv-nested-submodules-test'
Junio C Hamano [Mon, 25 Sep 2017 06:24:08 +0000 (15:24 +0900)] 
Merge branch 'hv/mv-nested-submodules-test'

A test to demonstrate "git mv" failing to adjust nested submodules
has been added.

* hv/mv-nested-submodules-test:
  add test for bug in git-mv for recursive submodules

6 years agoMerge branch 'bw/git-clang-format'
Junio C Hamano [Mon, 25 Sep 2017 06:24:07 +0000 (15:24 +0900)] 
Merge branch 'bw/git-clang-format'

"make style" runs git-clang-format to help developers by pointing
out coding style issues.

* bw/git-clang-format:
  Makefile: add style build rule
  clang-format: outline the git project's coding style

6 years agoMerge branch 'nm/imap-send-with-curl'
Junio C Hamano [Mon, 25 Sep 2017 06:24:07 +0000 (15:24 +0900)] 
Merge branch 'nm/imap-send-with-curl'

"git imap-send" has our own implementation of the protocol and also
can use more recent libCurl with the imap protocol support.  Update
the latter so that it can use the credential subsystem, and then
make it the default option to use, so that we can eventually
deprecate and remove the former.

* nm/imap-send-with-curl:
  imap-send: use curl by default when possible
  imap_send: setup_curl: retreive credentials if not set in config file
  imap-send: add wrapper to get server credentials if needed
  imap-send: return with error if curl failed

6 years agoMerge branch 'ks/commit-do-not-touch-cut-line'
Junio C Hamano [Mon, 25 Sep 2017 06:24:07 +0000 (15:24 +0900)] 
Merge branch 'ks/commit-do-not-touch-cut-line'

The explanation of the cut-line in the commit log editor has been
slightly tweaked.

* ks/commit-do-not-touch-cut-line:
  commit-template: change a message to be more intuitive

6 years agoMerge branch 'tg/refs-allowed-flags'
Junio C Hamano [Mon, 25 Sep 2017 06:24:07 +0000 (15:24 +0900)] 
Merge branch 'tg/refs-allowed-flags'

API error-proofing which happens to also squelch warnings from GCC.

* tg/refs-allowed-flags:
  refs: strip out not allowed flags from ref_transaction_update

6 years agoMerge branch 'rs/archive-excluded-directory'
Junio C Hamano [Mon, 25 Sep 2017 06:24:07 +0000 (15:24 +0900)] 
Merge branch 'rs/archive-excluded-directory'

"git archive", especially when used with pathspec, stored an empty
directory in its output, even though Git itself never does so.
This has been fixed.

* rs/archive-excluded-directory:
  archive: don't add empty directories to archives

6 years agoMerge branch 'ks/help-alias-label'
Junio C Hamano [Mon, 25 Sep 2017 06:24:07 +0000 (15:24 +0900)] 
Merge branch 'ks/help-alias-label'

"git help co" now says "co is aliased to ...", not "git co is".

* ks/help-alias-label:
  help: change a message to be more precise

6 years agoMerge branch 'jn/per-repo-object-store-fixes'
Junio C Hamano [Mon, 25 Sep 2017 06:24:06 +0000 (15:24 +0900)] 
Merge branch 'jn/per-repo-object-store-fixes'

Step #0 of a planned & larger series to make the in-core object
store per in-core repository object.

* jn/per-repo-object-store-fixes:
  replace-objects: evaluate replacement refs without using the object store
  push, fetch: error out for submodule entries not pointing to commits
  pack: make packed_git_mru global a value instead of a pointer

6 years agoMerge branch 'jk/write-in-full-fix'
Junio C Hamano [Mon, 25 Sep 2017 06:24:06 +0000 (15:24 +0900)] 
Merge branch 'jk/write-in-full-fix'

Many codepaths did not diagnose write failures correctly when disks
go full, due to their misuse of write_in_full() helper function,
which have been corrected.

* jk/write-in-full-fix:
  read_pack_header: handle signed/unsigned comparison in read result
  config: flip return value of store_write_*()
  notes-merge: use ssize_t for write_in_full() return value
  pkt-line: check write_in_full() errors against "< 0"
  convert less-trivial versions of "write_in_full() != len"
  avoid "write_in_full(fd, buf, len) != len" pattern
  get-tar-commit-id: check write_in_full() return against 0
  config: avoid "write_in_full(fd, buf, len) < len" pattern

6 years agoMerge branch 'ez/doc-duplicated-words-fix'
Junio C Hamano [Mon, 25 Sep 2017 06:24:06 +0000 (15:24 +0900)] 
Merge branch 'ez/doc-duplicated-words-fix'

Typofix.

* ez/doc-duplicated-words-fix:
  doc: fix minor typos (extra/duplicated words)

6 years agoMerge branch 'kd/doc-for-each-ref'
Junio C Hamano [Mon, 25 Sep 2017 06:24:06 +0000 (15:24 +0900)] 
Merge branch 'kd/doc-for-each-ref'

Doc update.

* kd/doc-for-each-ref:
  doc/for-each-ref: explicitly specify option names
  doc/for-each-ref: consistently use '=' to between argument names and values

6 years agoMerge branch 'cc/subprocess-handshake-missing-capabilities'
Junio C Hamano [Mon, 25 Sep 2017 06:24:06 +0000 (15:24 +0900)] 
Merge branch 'cc/subprocess-handshake-missing-capabilities'

Finishing touches to a topic already in 'master'.

* cc/subprocess-handshake-missing-capabilities:
  subprocess: loudly die when subprocess asks for an unsupported capability

6 years agoMerge branch 'kw/write-index-reduce-alloc'
Junio C Hamano [Mon, 25 Sep 2017 06:24:05 +0000 (15:24 +0900)] 
Merge branch 'kw/write-index-reduce-alloc'

A hotfix to a topic already in 'master'.

* kw/write-index-reduce-alloc:
  read-cache: fix index corruption with index v4
  Add t/helper/test-write-cache to .gitignore

6 years agoMerge branch 'mg/name-rev-tests-with-short-stack'
Junio C Hamano [Mon, 25 Sep 2017 06:24:05 +0000 (15:24 +0900)] 
Merge branch 'mg/name-rev-tests-with-short-stack'

A handful of tests to demonstrates a recursive implementation of
"name-rev" hurts.

* mg/name-rev-tests-with-short-stack:
  t6120: test describe and name-rev with deep repos
  t6120: clean up state after breaking repo
  t6120: test name-rev --all and --stdin
  t7004: move limited stack prereq to test-lib

6 years agotravis-ci: fix "skip_branch_tip_with_tag()" string comparison
Lars Schneider [Thu, 21 Sep 2017 20:48:30 +0000 (22:48 +0200)] 
travis-ci: fix "skip_branch_tip_with_tag()" string comparison

09f5e97 ("travis-ci: skip a branch build if equal tag is present",
2017-09-17) introduced the "skip_branch_tip_with_tag" function with
a broken string comparison. Fix it!

Reported-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Lars Schneider <larsxschneider@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agopathspec doc: parse_pathspec does not maintain references to args
Jonathan Nieder [Thu, 21 Sep 2017 04:41:12 +0000 (21:41 -0700)] 
pathspec doc: parse_pathspec does not maintain references to args

The command line arguments passed to main() are valid for the life of
a program, but the same is not true for all other argv-style arrays
(e.g.  when a caller creates an argv_array).  Clarify that
parse_pathspec does not rely on the argv passed to it to remain valid.

This makes it easier to tell that callers like "git rev-list --stdin"
are safe and ensures that that is more likely to remain true as the
implementation of parse_pathspec evolves.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoMerge branch 'jk/leak-checkers'
Junio C Hamano [Thu, 21 Sep 2017 04:38:37 +0000 (13:38 +0900)] 
Merge branch 'jk/leak-checkers'

Many of our programs consider that it is OK to release dynamic
storage that is used throughout the life of the program by simply
exiting, but this makes it harder to leak detection tools to avoid
reporting false positives.  Plug many existing leaks and introduce
a mechanism for developers to mark that the region of memory
pointed by a pointer is not lost/leaking to help these tools.

* jk/leak-checkers:
  git-compat-util: make UNLEAK less error-prone

6 years agorevision: replace "struct cmdline_pathspec" with argv_array
Jeff King [Wed, 20 Sep 2017 20:36:59 +0000 (16:36 -0400)] 
revision: replace "struct cmdline_pathspec" with argv_array

We assemble an array of strings in a custom struct,
NULL-terminate the result, and then pass it to
parse_pathspec().

But then we never free the array or the individual strings
(nor can we do the latter, as they are heap-allocated when
they come from stdin but not when they come from the
passed-in argv).

Let's swap this out for an argv_array. It does the same
thing with fewer lines of code, and it's safe to call
argv_array_clear() at the end to avoid a memory leak.

Reported-by: Martin Ågren <martin.agren@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agotest-lint: echo -e (or -E) is not portable
Torsten Bögershausen [Sun, 17 Sep 2017 05:43:18 +0000 (07:43 +0200)] 
test-lint: echo -e (or -E) is not portable

Some implementations of `echo` support the '-e' option to enable
backslash interpretation of the following string.
As an addition, they support '-E' to turn it off.

However, none of these are portable, POSIX doesn't even mention them,
and many implementations don't support them.

A check for '-n' is already done in check-non-portable-shell.pl,
extend it to cover '-n', '-e' or '-E'.

Signed-off-by: Torsten Bögershausen <tboegi@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agogit-compat-util: make UNLEAK less error-prone
Jonathan Tan [Tue, 19 Sep 2017 22:10:04 +0000 (15:10 -0700)] 
git-compat-util: make UNLEAK less error-prone

Commit 0e5bba5 ("add UNLEAK annotation for reducing leak false
positives", 2017-09-08) introduced an UNLEAK macro to be used as
"UNLEAK(var);", but its existing definitions leave semicolons that act
as empty statements, which will lead to syntax errors, e.g.

if (condition)
UNLEAK(var);
else
something_else(var);

would be broken with two statements between if (condition) and else.
Lose the excess semicolon from the end of the macro replacement text.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agofor_each_string_list_item: avoid undefined behavior for empty list
Michael Haggerty [Wed, 20 Sep 2017 05:27:05 +0000 (22:27 -0700)] 
for_each_string_list_item: avoid undefined behavior for empty list

If you pass a newly initialized or newly cleared `string_list` to
`for_each_string_list_item()`, then the latter does

    for (
            item = (list)->items; /* NULL */
            item < (list)->items + (list)->nr; /* NULL + 0 */
            ++item)

Even though this probably works almost everywhere, it is undefined
behavior, and it could plausibly cause highly-optimizing compilers to
misbehave.  C99 section 6.5.6 paragraph 8 explains:

    If both the pointer operand and the result point to elements
    of the same array object, or one past the last element of the
    array object, the evaluation shall not produce an overflow;
    otherwise, the behavior is undefined.

and (6.3.2.3.3) a null pointer does not point to anything.

Guard the loop with a NULL check to make the intent crystal clear to
even the most pedantic compiler.  A suitably clever compiler could let
the NULL check only run in the first iteration, but regardless, this
overhead is likely to be dwarfed by the work to be done on each item.

This problem was noticed by Coverity.

[jn: using a NULL check instead of a placeholder empty list;
 fleshed out the commit message based on mailing list discussion]

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoread_info_alternates: warn on non-trivial errors
Jeff King [Tue, 19 Sep 2017 19:41:10 +0000 (15:41 -0400)] 
read_info_alternates: warn on non-trivial errors

When we fail to open $GIT_DIR/info/alternates, we silently
assume there are no alternates. This is the right thing to
do for ENOENT, but not for other errors.

A hard error is probably overkill here. If we fail to read
an alternates file then either we'll complete our operation
anyway, or we'll fail to find some needed object. Either
way, a warning is good idea. And we already have a helper
function to handle this pattern; let's just call
warn_on_fopen_error().

Note that technically the errno from strbuf_read_file()
might be from a read() error, not open(). But since read()
would never return ENOENT or ENOTDIR, and since it produces
a generic "unable to access" error, it's suitable for
handling errors from either.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoMerge branch 'jk/info-alternates-fix-2.11' into jk/info-alternates-fix
Junio C Hamano [Wed, 20 Sep 2017 02:33:06 +0000 (11:33 +0900)] 
Merge branch 'jk/info-alternates-fix-2.11' into jk/info-alternates-fix

* jk/info-alternates-fix-2.11:
  read_info_alternates: read contents into strbuf

6 years agoread_info_alternates: read contents into strbuf
Jeff King [Tue, 19 Sep 2017 19:41:07 +0000 (15:41 -0400)] 
read_info_alternates: read contents into strbuf

This patch fixes a regression in v2.11.1 where we might read
past the end of an mmap'd buffer. It was introduced in
cf3c635210.

The link_alt_odb_entries() function has always taken a
ptr/len pair as input. Until cf3c635210 (alternates: accept
double-quoted paths, 2016-12-12), we made a copy of those
bytes in a string. But after that commit, we switched to
parsing the input left-to-right, and we ignore "len"
totally, instead reading until we hit a NUL.

This has mostly gone unnoticed for a few reasons:

  1. All but one caller passes a NUL-terminated string, with
     "len" pointing to the NUL.

  2. The remaining caller, read_info_alternates(), passes in
     an mmap'd file. Unless the file is an exact multiple of
     the page size, it will generally be followed by NUL
     padding to the end of the page, which just works.

The easiest way to demonstrate the problem is to build with:

  make SANITIZE=address NO_MMAP=Nope test

Any test which involves $GIT_DIR/info/alternates will fail,
as the mmap emulation (correctly) does not add an extra NUL,
and ASAN complains about reading past the end of the buffer.

One solution would be to teach link_alt_odb_entries() to
respect "len". But it's actually a bit tricky, since we
depend on unquote_c_style() under the hood, and it has no
ptr/len variant.

We could also just make a NUL-terminated copy of the input
bytes and operate on that. But since all but one caller
already is passing a string, instead let's just fix that
caller to provide NUL-terminated input in the first place,
by swapping out mmap for strbuf_read_file().

There's no advantage to using mmap on the alternates file.
It's not expected to be large (and anyway, we're copying its
contents into an in-memory linked list). Nor is using
git_open() buying us anything here, since we don't keep the
descriptor open for a long period of time.

Let's also drop the "len" parameter entirely from
link_alt_odb_entries(), since it's completely ignored. That
will avoid any new callers re-introducing a similar bug.

Reported-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agot9010-*.sh: skip all tests if the PIPE prereq is missing
Ramsay Jones [Sun, 17 Sep 2017 22:58:18 +0000 (23:58 +0100)] 
t9010-*.sh: skip all tests if the PIPE prereq is missing

Every test in this file, except one, is marked with the PIPE prereq.
However, that lone test ('set up svn repo'), only performs some setup
work and checks whether the following test should be executed (by
setting an additional SVNREPO prerequisite). Since the following test
also requires the PIPE prerequisite, performing the setup test, when the
PIPE preequisite is missing, is simply wasted effort. Use the skip-all
test facility to skip all tests when the PIPE prerequisite is missing.

Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agotest-lib: use more compact expression in PIPE prerequisite
Ramsay Jones [Sun, 17 Sep 2017 22:56:00 +0000 (23:56 +0100)] 
test-lib: use more compact expression in PIPE prerequisite

Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agorev-parse: rev-parse: add --is-shallow-repository
Øystein Walle [Mon, 18 Sep 2017 17:04:29 +0000 (19:04 +0200)] 
rev-parse: rev-parse: add --is-shallow-repository

Running `git fetch --unshallow` on a repo that is not in fact shallow
produces a fatal error message. Add a helper to rev-parse that scripters
can use to determine whether a repo is shallow or not.

Signed-off-by: Øystein Walle <oystwa@gmail.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agot/README: fix typo and grammatically improve a sentence
Kaartic Sivaraam [Sun, 17 Sep 2017 10:18:15 +0000 (10:18 +0000)] 
t/README: fix typo and grammatically improve a sentence

Signed-off-by: Kaartic Sivaraam <kaarticsivaraam91196@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoThe eighth batch for 2.15
Junio C Hamano [Tue, 19 Sep 2017 01:55:19 +0000 (10:55 +0900)] 
The eighth batch for 2.15

Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoMerge branch 'rk/commit-tree-make-F-verbatim'
Junio C Hamano [Tue, 19 Sep 2017 01:47:57 +0000 (10:47 +0900)] 
Merge branch 'rk/commit-tree-make-F-verbatim'

Unlike "git commit-tree < file", "git commit-tree -F file" did not
pass the contents of the file verbatim and instead completed an
incomplete line at the end, if exists.  The latter has been updated
to match the behaviour of the former.

* rk/commit-tree-make-F-verbatim:
  commit-tree: do not complete line in -F input

6 years agoMerge branch 'rs/strbuf-leakfix'
Junio C Hamano [Tue, 19 Sep 2017 01:47:57 +0000 (10:47 +0900)] 
Merge branch 'rs/strbuf-leakfix'

Many leaks of strbuf have been fixed.

* rs/strbuf-leakfix: (34 commits)
  wt-status: release strbuf after use in wt_longstatus_print_tracking()
  wt-status: release strbuf after use in read_rebase_todolist()
  vcs-svn: release strbuf after use in end_revision()
  utf8: release strbuf on error return in strbuf_utf8_replace()
  userdiff: release strbuf after use in userdiff_get_textconv()
  transport-helper: release strbuf after use in process_connect_service()
  sequencer: release strbuf after use in save_head()
  shortlog: release strbuf after use in insert_one_record()
  sha1_file: release strbuf on error return in index_path()
  send-pack: release strbuf on error return in send_pack()
  remote: release strbuf after use in set_url()
  remote: release strbuf after use in migrate_file()
  remote: release strbuf after use in read_remote_branches()
  refs: release strbuf on error return in write_pseudoref()
  notes: release strbuf after use in notes_copy_from_stdin()
  merge: release strbuf after use in write_merge_heads()
  merge: release strbuf after use in save_state()
  mailinfo: release strbuf on error return in handle_boundary()
  mailinfo: release strbuf after use in handle_from()
  help: release strbuf on error return in exec_woman_emacs()
  ...

6 years agoMerge branch 'jk/shortlog-ident-cleanup'
Junio C Hamano [Tue, 19 Sep 2017 01:47:56 +0000 (10:47 +0900)] 
Merge branch 'jk/shortlog-ident-cleanup'

Code clean-up.

* jk/shortlog-ident-cleanup:
  shortlog: skip format/parse roundtrip for internal traversal

6 years agoMerge branch 'mh/packed-ref-transactions'
Junio C Hamano [Tue, 19 Sep 2017 01:47:56 +0000 (10:47 +0900)] 
Merge branch 'mh/packed-ref-transactions'

Implement transactional update to the packed-ref representation of
references.

* mh/packed-ref-transactions:
  files_transaction_finish(): delete reflogs before references
  packed-backend: rip out some now-unused code
  files_ref_store: use a transaction to update packed refs
  t1404: demonstrate two problems with reference transactions
  files_initial_transaction_commit(): use a transaction for packed refs
  prune_refs(): also free the linked list
  files_pack_refs(): use a reference transaction to write packed refs
  packed_delete_refs(): implement method
  packed_ref_store: implement reference transactions
  struct ref_transaction: add a place for backends to store data
  packed-backend: don't adjust the reference count on lock/unlock

6 years agoMerge branch 'kw/merge-recursive-cleanup'
Junio C Hamano [Tue, 19 Sep 2017 01:47:56 +0000 (10:47 +0900)] 
Merge branch 'kw/merge-recursive-cleanup'

A leakfix and code clean-up.

* kw/merge-recursive-cleanup:
  merge-recursive: change current file dir string_lists to hashmap
  merge-recursive: remove return value from get_files_dirs
  merge-recursive: fix memory leak

6 years agoMerge branch 'sb/merge-commit-msg-hook'
Junio C Hamano [Tue, 19 Sep 2017 01:47:56 +0000 (10:47 +0900)] 
Merge branch 'sb/merge-commit-msg-hook'

As "git commit" to conclude a conflicted "git merge" honors the
commit-msg hook, "git merge" that recoreds a merge commit that
cleanly auto-merges should, but it didn't.

* sb/merge-commit-msg-hook:
  builtin/merge: honor commit-msg hook for merges

6 years agoMerge branch 'jk/leak-checkers'
Junio C Hamano [Tue, 19 Sep 2017 01:47:55 +0000 (10:47 +0900)] 
Merge branch 'jk/leak-checkers'

Many of our programs consider that it is OK to release dynamic
storage that is used throughout the life of the program by simply
exiting, but this makes it harder to leak detection tools to avoid
reporting false positives.  Plug many existing leaks and introduce
a mechanism for developers to mark that the region of memory
pointed by a pointer is not lost/leaking to help these tools.

* jk/leak-checkers:
  add UNLEAK annotation for reducing leak false positives
  set_git_dir: handle feeding gitdir to itself
  repository: free fields before overwriting them
  reset: free allocated tree buffers
  reset: make tree counting less confusing
  config: plug user_config leak
  update-index: fix cache entry leak in add_one_file()
  add: free leaked pathspec after add_files_to_cache()
  test-lib: set LSAN_OPTIONS to abort by default
  test-lib: --valgrind should not override --verbose-log

6 years agoMerge branch 'nm/pull-submodule-recurse-config'
Junio C Hamano [Tue, 19 Sep 2017 01:47:55 +0000 (10:47 +0900)] 
Merge branch 'nm/pull-submodule-recurse-config'

"git -c submodule.recurse=yes pull" did not work as if the
"--recurse-submodules" option was given from the command line.
This has been corrected.

* nm/pull-submodule-recurse-config:
  pull: honor submodule.recurse config option
  pull: fix cli and config option parsing order

6 years agoMerge branch 'mh/packed-ref-store-prep'
Junio C Hamano [Tue, 19 Sep 2017 01:47:55 +0000 (10:47 +0900)] 
Merge branch 'mh/packed-ref-store-prep'

Fix regression to "gitk --bisect" by a recent update.

* mh/packed-ref-store-prep:
  rev-parse: don't trim bisect refnames

6 years agoMerge branch 'ma/remove-config-maybe-bool'
Junio C Hamano [Tue, 19 Sep 2017 01:47:55 +0000 (10:47 +0900)] 
Merge branch 'ma/remove-config-maybe-bool'

Finishing touches to a recent topic.

* ma/remove-config-maybe-bool:
  config: remove git_config_maybe_bool

6 years agoMerge branch 'jk/system-path-cleanup'
Junio C Hamano [Tue, 19 Sep 2017 01:47:55 +0000 (10:47 +0900)] 
Merge branch 'jk/system-path-cleanup'

Code clean-up.

* jk/system-path-cleanup:
  git_extract_argv0_path: do nothing without RUNTIME_PREFIX
  system_path: move RUNTIME_PREFIX to a sub-function

6 years agoMerge branch 'jh/hashmap-disable-counting'
Junio C Hamano [Tue, 19 Sep 2017 01:47:54 +0000 (10:47 +0900)] 
Merge branch 'jh/hashmap-disable-counting'

Our hashmap implementation in hashmap.[ch] is not thread-safe when
adding a new item needs to expand the hashtable by rehashing; add
an API to disable the automatic rehashing to work it around.

* jh/hashmap-disable-counting:
  hashmap: add API to disable item counting when threaded

6 years agoMerge branch 'bb/doc-eol-dirty'
Junio C Hamano [Tue, 19 Sep 2017 01:47:54 +0000 (10:47 +0900)] 
Merge branch 'bb/doc-eol-dirty'

Doc update.

* bb/doc-eol-dirty:
  Documentation: mention that `eol` can change the dirty status of paths

6 years agoMerge branch 'jt/packmigrate'
Junio C Hamano [Tue, 19 Sep 2017 01:47:53 +0000 (10:47 +0900)] 
Merge branch 'jt/packmigrate'

Remove unneeded file added by a topic already in 'master'.

* jt/packmigrate:
  Remove inadvertently added outgoing/packfile.h

6 years agoMerge branch 'jk/incore-lockfile-removal'
Junio C Hamano [Tue, 19 Sep 2017 01:47:53 +0000 (10:47 +0900)] 
Merge branch 'jk/incore-lockfile-removal'

The long-standing rule that an in-core lockfile instance, once it
is used, must not be freed, has been lifted and the lockfile and
tempfile APIs have been updated to reduce the chance of programming
errors.

* jk/incore-lockfile-removal:
  stop leaking lock structs in some simple cases
  ref_lock: stop leaking lock_files
  lockfile: update lifetime requirements in documentation
  tempfile: auto-allocate tempfiles on heap
  tempfile: remove deactivated list entries
  tempfile: use list.h for linked list
  tempfile: release deactivated strbufs instead of resetting
  tempfile: robustify cleanup handler
  tempfile: factor out deactivation
  tempfile: factor out activation
  tempfile: replace die("BUG") with BUG()
  tempfile: handle NULL tempfile pointers gracefully
  tempfile: prefer is_tempfile_active to bare access
  lockfile: do not rollback lock on failed close
  tempfile: do not delete tempfile on failed close
  always check return value of close_tempfile
  verify_signed_buffer: prefer close_tempfile() to close()
  setup_temporary_shallow: move tempfile struct into function
  setup_temporary_shallow: avoid using inactive tempfile
  write_index_as_tree: cleanup tempfile on error

6 years agoMerge branch 'nd/prune-in-worktree'
Junio C Hamano [Tue, 19 Sep 2017 01:47:53 +0000 (10:47 +0900)] 
Merge branch 'nd/prune-in-worktree'

"git gc" and friends when multiple worktrees are used off of a
single repository did not consider the index and per-worktree refs
of other worktrees as the root for reachability traversal, making
objects that are in use only in other worktrees to be subject to
garbage collection.

* nd/prune-in-worktree:
  refs.c: reindent get_submodule_ref_store()
  refs.c: remove fallback-to-main-store code get_submodule_ref_store()
  rev-list: expose and document --single-worktree
  revision.c: --reflog add HEAD reflog from all worktrees
  files-backend: make reflog iterator go through per-worktree reflog
  revision.c: --all adds HEAD from all worktrees
  refs: remove dead for_each_*_submodule()
  refs.c: move for_each_remote_ref_submodule() to submodule.c
  revision.c: use refs_for_each*() instead of for_each_*_submodule()
  refs: add refs_head_ref()
  refs: move submodule slash stripping code to get_submodule_ref_store
  refs.c: refactor get_submodule_ref_store(), share common free block
  revision.c: --indexed-objects add objects from all worktrees
  revision.c: refactor add_index_objects_to_pending()
  refs.c: use is_dir_sep() in resolve_gitlink_ref()
  revision.h: new flag in struct rev_info wrt. worktree-related refs

6 years agoMerge branch 'ma/split-symref-update-fix'
Junio C Hamano [Tue, 19 Sep 2017 01:47:53 +0000 (10:47 +0900)] 
Merge branch 'ma/split-symref-update-fix'

A leakfix.

* ma/split-symref-update-fix:
  refs/files-backend: add `refname`, not "HEAD", to list
  refs/files-backend: correct return value in lock_ref_for_update
  refs/files-backend: fix memory leak in lock_ref_for_update
  refs/files-backend: add longer-scoped copy of string to list

6 years agoMerge branch 'mh/notes-cleanup'
Junio C Hamano [Tue, 19 Sep 2017 01:47:52 +0000 (10:47 +0900)] 
Merge branch 'mh/notes-cleanup'

Code clean-up.

* mh/notes-cleanup:
  load_subtree(): check that `prefix_len` is in the expected range
  load_subtree(): declare some variables to be `size_t`
  hex_to_bytes(): simpler replacement for `get_oid_hex_segment()`
  get_oid_hex_segment(): don't pad the rest of `oid`
  load_subtree(): combine some common code
  get_oid_hex_segment(): return 0 on success
  load_subtree(): only consider blobs to be potential notes
  load_subtree(): check earlier whether an internal node is a tree entry
  load_subtree(): separate logic for internal vs. terminal entries
  load_subtree(): fix incorrect comment
  load_subtree(): reduce the scope of some local variables
  load_subtree(): remove unnecessary conditional
  notes: make GET_NIBBLE macro more robust

6 years agoMerge branch 'mg/timestamp-t-fix'
Junio C Hamano [Tue, 19 Sep 2017 01:47:52 +0000 (10:47 +0900)] 
Merge branch 'mg/timestamp-t-fix'

A mismerge fix.

* mg/timestamp-t-fix:
  name-rev: change ULONG_MAX to TIME_MAX

6 years agoMerge branch 'ma/pkt-line-leakfix'
Junio C Hamano [Tue, 19 Sep 2017 01:47:52 +0000 (10:47 +0900)] 
Merge branch 'ma/pkt-line-leakfix'

A leakfix.

* ma/pkt-line-leakfix:
  pkt-line: re-'static'-ify buffer in packet_write_fmt_1()

6 years agoMerge branch 'jk/config-lockfile-leak-fix'
Junio C Hamano [Tue, 19 Sep 2017 01:47:51 +0000 (10:47 +0900)] 
Merge branch 'jk/config-lockfile-leak-fix'

A leakfix.

* jk/config-lockfile-leak-fix:
  config: use a static lock_file struct

6 years agoMerge branch 'dw/diff-highlight-makefile-fix'
Junio C Hamano [Tue, 19 Sep 2017 01:47:50 +0000 (10:47 +0900)] 
Merge branch 'dw/diff-highlight-makefile-fix'

Build clean-up.

* dw/diff-highlight-makefile-fix:
  diff-highlight: add clean target to Makefile

6 years agoMerge branch 'ti/external-sha1dc'
Junio C Hamano [Tue, 19 Sep 2017 01:47:50 +0000 (10:47 +0900)] 
Merge branch 'ti/external-sha1dc'

Platforms that ship with a separate sha1 with collision detection
library can link to it instead of using the copy we ship as part of
our source tree.

* ti/external-sha1dc:
  sha1dc: allow building with the external sha1dc library
  sha1dc: build git plumbing code more explicitly

6 years agogc: call fscanf() with %<len>s, not %<len>c, when reading hostname
Junio C Hamano [Sun, 17 Sep 2017 03:16:55 +0000 (12:16 +0900)] 
gc: call fscanf() with %<len>s, not %<len>c, when reading hostname

Earlier in this codepath, we (ab)used "%<len>c" to read the hostname
recorded in the lockfile into locking_host[HOST_NAME_MAX + 1] while
substituting <len> with the actual value of HOST_NAME_MAX.

This turns out to be incorrect, as it is an instruction to read
exactly the specified number of bytes.  Because we are trying to
read at most that many bytes, we should be using "%<len>s" instead.

Helped-by: A. Wilcox <awilfox@adelielinux.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoadd test for bug in git-mv for recursive submodules
Heiko Voigt [Fri, 15 Sep 2017 11:50:21 +0000 (13:50 +0200)] 
add test for bug in git-mv for recursive submodules

When using git-mv with a submodule it will detect that and update the
paths for its configurations (.gitmodules, worktree and gitfile). This
does not work for recursive submodules where a user renames the root
submodule.

We discovered this fact when working on on-demand fetch for renamed
submodules. Lets add a test to document.

Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoimap-send: use curl by default when possible
Nicolas Morey-Chaisemartin [Thu, 14 Sep 2017 07:52:11 +0000 (09:52 +0200)] 
imap-send: use curl by default when possible

Set curl as the runtime default when it is available.
When linked against older curl versions (< 7_34_0) or without curl,
use the legacy imap implementation.

The goal is to validate feature parity between the legacy and
the curl implementation, deprecate the legacy implementation
later on and in the long term, hopefully drop it altogether.

Signed-off-by: Nicolas Morey-Chaisemartin <nicolas@morey-chaisemartin.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoimap_send: setup_curl: retreive credentials if not set in config file
Nicolas Morey-Chaisemartin [Thu, 14 Sep 2017 07:52:06 +0000 (09:52 +0200)] 
imap_send: setup_curl: retreive credentials if not set in config file

Up to this point, the curl mode only supported getting the username
and password from the gitconfig file while the legacy mode could also
fetch them using the credential API.

Signed-off-by: Nicolas Morey-Chaisemartin <nicolas@morey-chaisemartin.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoimap-send: add wrapper to get server credentials if needed
Nicolas Morey-Chaisemartin [Thu, 14 Sep 2017 07:52:02 +0000 (09:52 +0200)] 
imap-send: add wrapper to get server credentials if needed

Signed-off-by: Nicolas Morey-Chaisemartin <nicolas@morey-chaisemartin.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoimap-send: return with error if curl failed
Nicolas Morey-Chaisemartin [Thu, 14 Sep 2017 07:51:57 +0000 (09:51 +0200)] 
imap-send: return with error if curl failed

curl_append_msgs_to_imap always returned 0, whether curl failed or not.
Return a proper status so git imap-send will exit with an error code
if something wrong happened.

Signed-off-by: Nicolas Morey-Chaisemartin <nicolas@morey-chaisemartin.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agocommit-template: change a message to be more intuitive
Kaartic Sivaraam [Wed, 13 Sep 2017 13:05:38 +0000 (13:05 +0000)] 
commit-template: change a message to be more intuitive

It's not good to use the phrase 'do not touch' to convey the
information that the cut-line should not be modified or removed as
it could possibly be mis-interpreted by a person who doesn't know
that the word 'touch' has the meaning of 'tamper with'. Further, it
could make translations a little difficult as it might not have the
intended meaning in a few languages when translated as such.

So, use more intuitive terms in the sentence.

Signed-off-by: Kaartic Sivaraam <kaarticsivaraam91196@gmail.com>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agotest-lib: don't use ulimit in test prerequisites on cygwin
Ramsay Jones [Thu, 14 Sep 2017 17:24:41 +0000 (18:24 +0100)] 
test-lib: don't use ulimit in test prerequisites on cygwin

On cygwin (and MinGW), the 'ulimit' built-in bash command does not have
the desired effect of limiting the resources of new processes, at least
for the stack and file descriptors. However, it always returns success
and leads to several test prerequisites being erroneously set to true.

Add a check for cygwin and MinGW to the prerequisite expressions, using
a 'test_have_prereq !MINGW,!CYGWIN' clause, to guard against using ulimit.
This affects the prerequisite expressions for the ULIMIT_STACK_SIZE,
CMDLINE_LIMIT and ULIMIT_FILE_DESCRIPTORS prerequisites.

Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoread_pack_header: handle signed/unsigned comparison in read result
Jeff King [Wed, 13 Sep 2017 18:47:22 +0000 (14:47 -0400)] 
read_pack_header: handle signed/unsigned comparison in read result

The result of read_in_full() may be -1 if we saw an error.
But in comparing it to a sizeof() result, that "-1" will be
promoted to size_t. In fact, the largest possible size_t
which is much bigger than our struct size. This means that
our "< sizeof(header)" error check won't trigger.

In practice, we'd go on to read uninitialized memory and
compare it to the PACK signature, which is likely to fail.
But we shouldn't get there.

We can fix this by making a direct "!=" comparison to the
requested size, rather than "<". This means that errors get
lumped in with short reads, but that's sufficient for our
purposes here. There's no PH_ERROR tp represent our case.
And anyway, this function reads from pipes and network
sockets. A network error may racily appear as EOF to us
anyway if there's data left in the socket buffers.

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 agoconfig: flip return value of store_write_*()
Jeff King [Wed, 13 Sep 2017 17:17:57 +0000 (13:17 -0400)] 
config: flip return value of store_write_*()

The store_write_section() and store_write_pairs() functions
are basically high-level wrappers around write(). But their
return values are flipped from our usual convention, using
"1" for success and "0" for failure.

Let's flip them to follow the usual write() conventions and
update all callers. As these are local to config.c, it's
unlikely that we'd have new callers in any topics in flight
(which would be silently broken by our change). But just to
be on the safe side, let's rename them to just
write_section() and write_pairs().  That also accentuates
their relationship with write().

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 agonotes-merge: use ssize_t for write_in_full() return value
Jeff King [Wed, 13 Sep 2017 17:17:44 +0000 (13:17 -0400)] 
notes-merge: use ssize_t for write_in_full() return value

We store the return value of write_in_full() in a long,
though the return is actually an ssize_t. This probably
doesn't matter much in practice (since the buffer size is
alredy an unsigned long), but it might if the size if
between what can be represented in "long" and "unsigned
long", and if your size_t is larger than a "long" (as it is
on 64-bit Windows).

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 agopkt-line: check write_in_full() errors against "< 0"
Jeff King [Wed, 13 Sep 2017 17:17:30 +0000 (13:17 -0400)] 
pkt-line: check write_in_full() errors against "< 0"

As with the previous two commits, we prefer to check
write_in_full()'s return value to see if it is negative,
rather than comparing it to the input length.

These cases actually flip the logic to check for success,
making conversion a little different than in other cases. We
could of course write:

  if (write_in_full(...) >= 0)
          return 0;
  return error(...);

But our usual method of spelling write() error checks is
just "< 0". So let's flip the logic for each of these
conditionals to our usual style.

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 agoconvert less-trivial versions of "write_in_full() != len"
Jeff King [Wed, 13 Sep 2017 17:16:28 +0000 (13:16 -0400)] 
convert less-trivial versions of "write_in_full() != len"

The prior commit converted many sites to check the return
value of write_in_full() for negativity, rather than a
mismatch with the input length. This patch covers similar
cases, but where the return value is stored in an
intermediate variable. These should get the same treatment,
but they need to be reviewed more carefully since it would
be a bug if the return value is stored in an unsigned type
(which indeed, it is in one of the cases).

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 agoavoid "write_in_full(fd, buf, len) != len" pattern
Jeff King [Wed, 13 Sep 2017 17:16:03 +0000 (13:16 -0400)] 
avoid "write_in_full(fd, buf, len) != len" pattern

The return value of write_in_full() is either "-1", or the
requested number of bytes[1]. If we make a partial write
before seeing an error, we still return -1, not a partial
value. This goes back to f6aa66cb95 (write_in_full: really
write in full or return error on disk full., 2007-01-11).

So checking anything except "was the return value negative"
is pointless. And there are a couple of reasons not to do
so:

  1. It can do a funny signed/unsigned comparison. If your
     "len" is signed (e.g., a size_t) then the compiler will
     promote the "-1" to its unsigned variant.

     This works out for "!= len" (unless you really were
     trying to write the maximum size_t bytes), but is a
     bug if you check "< len" (an example of which was fixed
     recently in config.c).

     We should avoid promoting the mental model that you
     need to check the length at all, so that new sites are
     not tempted to copy us.

  2. Checking for a negative value is shorter to type,
     especially when the length is an expression.

  3. Linus says so. In d34cf19b89 (Clean up write_in_full()
     users, 2007-01-11), right after the write_in_full()
     semantics were changed, he wrote:

       I really wish every "write_in_full()" user would just
       check against "<0" now, but this fixes the nasty and
       stupid ones.

     Appeals to authority aside, this makes it clear that
     writing it this way does not have an intentional
     benefit. It's a historical curiosity that we never
     bothered to clean up (and which was undoubtedly
     cargo-culted into new sites).

So let's convert these obviously-correct cases (this
includes write_str_in_full(), which is just a wrapper for
write_in_full()).

[1] A careful reader may notice there is one way that
    write_in_full() can return a different value. If we ask
    write() to write N bytes and get a return value that is
    _larger_ than N, we could return a larger total. But
    besides the fact that this would imply a totally broken
    version of write(), it would already invoke undefined
    behavior. Our internal remaining counter is an unsigned
    size_t, which means that subtracting too many byte will
    wrap it around to a very large number. So we'll instantly
    begin reading off the end of the buffer, trying to write
    gigabytes (or petabytes) of data.

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 agoget-tar-commit-id: check write_in_full() return against 0
Jeff King [Wed, 13 Sep 2017 17:11:28 +0000 (13:11 -0400)] 
get-tar-commit-id: check write_in_full() return against 0

We ask to write 41 bytes and make sure that the return value
is at least 41. This is the same "dangerous" pattern that
was fixed in the prior commit (wherein a negative return
value is promoted to unsigned), though it is not dangerous
here because our "41" is a constant, not an unsigned
variable.

But we should convert it anyway to avoid modeling a
dangerous construct.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoconfig: avoid "write_in_full(fd, buf, len) < len" pattern
Jeff King [Wed, 13 Sep 2017 18:15:16 +0000 (14:15 -0400)] 
config: avoid "write_in_full(fd, buf, len) < len" pattern

The return type of write_in_full() is a signed ssize_t,
because we may return "-1" on failure (even if we succeeded
in writing some bytes). But "len" itself is may be an
unsigned type (the function takes a size_t, but of course we
may have something else in the calling function). So while
it seems like:

  if (write_in_full(fd, buf, len) < len)
die_errno("write error");

would trigger on error, it won't if "len" is unsigned.  The
compiler sees a signed/unsigned comparison and promotes the
signed value, resulting in (size_t)-1, the highest possible
size_t (or again, whatever type the caller has). This cannot
possibly be smaller than "len", and so the conditional can
never trigger.

I scoured the code base for cases of this, but it turns out
that these two in git_config_set_multivar_in_file_gently()
are the only ones. Here our "len" is the difference between
two size_t variables, making the result an unsigned size_t.
We can fix this by just checking for a negative return value
directly, as write_in_full() will never return any value
except -1 or the full count.

There's no addition to the test suite here, since you need
to convince write() to fail in order to see the problem. The
simplest reproduction recipe I came up with is to trigger
ENOSPC:

  # make a limited-size filesystem
  dd if=/dev/zero of=small.disk bs=1M count=1
  mke2fs small.disk
  mkdir mnt
  sudo mount -o loop small.disk mnt
  cd mnt
  sudo chown $USER:$USER .

  # make a config file with some content
  git config --file=config one.key value
  git config --file=config two.key value

  # now fill up the disk
  dd if=/dev/zero of=fill

  # and try to delete a key, which requires copying the rest
  # of the file to config.lock, and will fail on write()
  git config --file=config --unset two.key

That final command should (and does after this patch)
produce an error message due to the failed write, and leave
the file intact. Instead, it silently ignores the failure
and renames config.lock into place, leaving you with a
totally empty config file!

Reported-by: demerphq <demerphq@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 agodoc: fix minor typos (extra/duplicated words)
Evan Zacks [Tue, 12 Sep 2017 22:58:39 +0000 (15:58 -0700)] 
doc: fix minor typos (extra/duplicated words)

Following are several fixes for duplicated words ("of of") and one
case where an extra article ("a") slipped in.

Signed-off-by: Evan Zacks <zackse@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoarchive: don't add empty directories to archives
René Scharfe [Tue, 12 Sep 2017 22:43:57 +0000 (00:43 +0200)] 
archive: don't add empty directories to archives

While git doesn't track empty directories, git archive can be tricked
into putting some into archives.  One way is to construct an empty tree
object, as t5004 does.  While that is supported by the object database,
it can't be represented in the index and thus it's unlikely to occur in
the wild.

Another way is using the literal name of a directory in an exclude
pathspec -- its contents are are excluded, but the directory stub is
included.  That's inconsistent: exclude pathspecs containing wildcards
don't leave empty directories in the archive.

Yet another way is have a few levels of nested subdirectories (e.g.
d1/d2/d3/file1) and ignoring the entries at the leaves (e.g. file1).
The directories with the ignored content are ignored as well (e.g. d3),
but their empty parents are included (e.g. d2).

As empty directories are not supported by git, they should also not be
written into archives.  If an empty directory is really needed then it
can be tracked and archived by placing an empty .gitignore file in it.

There already is a mechanism in place for suppressing empty directories.
When read_tree_recursive() encounters a directory excluded by a pathspec
then it enters it anyway because it might contain included entries.  It
calls the callback function before it is able to decide if the directory
is actually needed.  For that reason git archive adds directories to a
queue and writes entries for them only when it encounters the first
child item -- but currently only if pathspecs with wildcards are used.

Queue *all* directories, no matter if there even are pathspecs present.
This prevents git archive from writing entries for empty directories in
all cases.

Suggested-by: Jeff King <peff@peff.net>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoreplace-objects: evaluate replacement refs without using the object store
Stefan Beller [Tue, 12 Sep 2017 17:31:40 +0000 (10:31 -0700)] 
replace-objects: evaluate replacement refs without using the object store

Pass DO_FOR_EACH_INCLUDE_BROKEN when iterating over replacement refs
so that the iteration does not require opening the named objects from
the object store. This avoids a dependency cycle between object access
and replace ref iteration.

Moreover the ref subsystem has not been migrated yet to access the
object store via passed in repository objects.  As a result, without
this patch, iterating over replace refs in a repository other than
the_repository it produces errors:

   error: refs/replace/3afabef75c627b894cccc3bcae86837abc7c32fe does not point to a valid object!

Noticed while adapting the object store (and in particular its
evaluation of replace refs) to handle arbitrary repositories.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agopush, fetch: error out for submodule entries not pointing to commits
Stefan Beller [Tue, 12 Sep 2017 17:30:27 +0000 (10:30 -0700)] 
push, fetch: error out for submodule entries not pointing to commits

The check_has_commit helper uses resolves a submodule entry to a
commit, when validating its existence. As a side effect this means
tolerates a submodule entry pointing to a tag, which is not a valid
submodule entry that git commands would know how to cope with.

Tighten the check to require an actual commit, not a tag pointing to a
commit.

Also improve the error handling when a submodule entry points to
non-commit (e.g., a blob) to error out instead of warning and
pretending the pointed to object doesn't exist.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agopack: make packed_git_mru global a value instead of a pointer
Jonathan Nieder [Tue, 12 Sep 2017 17:28:39 +0000 (10:28 -0700)] 
pack: make packed_git_mru global a value instead of a pointer

The MRU cache that keeps track of recently used packs is represented
using two global variables:

struct mru packed_git_mru_storage;
struct mru *packed_git_mru = &packed_git_mru_storage;

Callers never assign to the packed_git_mru pointer, though, so we can
simplify by eliminating it and using &packed_git_mru_storage (renamed
to &packed_git_mru) directly.  This variable is only used by the
packfile subsystem, making this a relatively uninvasive change (and
any new unadapted callers would trigger a compile error).

Noticed while moving these globals to the object_store struct.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agohelp: change a message to be more precise
Kaartic Sivaraam [Tue, 12 Sep 2017 11:14:06 +0000 (16:44 +0530)] 
help: change a message to be more precise

When the user tries to use '--help' option on an aliased command
information about the alias is printed as sshown below,

    $ git co --help
    `git co' is aliased to `checkout'

This doesn't seem correct as the user has aliased only 'co' and not
'git co'. This might even be incorrect in cases in which the user has
used an alias like 'tgit'.

    $ tgit co --help
    `git co' is aliased to `checkout'

So, make the message more precise.

Signed-off-by: Kaartic Sivaraam <kaarticsivaraam91196@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agorefs: strip out not allowed flags from ref_transaction_update
Thomas Gummerer [Tue, 12 Sep 2017 22:59:21 +0000 (23:59 +0100)] 
refs: strip out not allowed flags from ref_transaction_update

Callers are only allowed to pass certain flags into
ref_transaction_update, other flags are internal to it.  To prevent
mistakes from the callers, strip the internal only flags out before
continuing.

This was noticed because of a compiler warning gcc 7.1.1 issued about
passing a NULL parameter as second parameter to memcpy (through
hashcpy):

In file included from refs.c:5:0:
refs.c: In function ‘ref_transaction_verify’:
cache.h:948:2: error: argument 2 null where non-null expected [-Werror=nonnull]
  memcpy(sha_dst, sha_src, GIT_SHA1_RAWSZ);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from git-compat-util.h:165:0,
                 from cache.h:4,
                 from refs.c:5:
/usr/include/string.h:43:14: note: in a call to function ‘memcpy’ declared here
 extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
              ^~~~~~

The call to hascpy in ref_transaction_add_update is protected by the
passed in flags, but as we only add flags there, gcc notices
REF_HAVE_NEW or REF_HAVE_OLD flags could be passed in from the outside,
which would potentially result in passing in NULL as second parameter to
memcpy.

Fix both the compiler warning, and make the interface safer for its
users by stripping the internal flags out.

Suggested-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agodoc/for-each-ref: explicitly specify option names
Kevin Daudt [Mon, 11 Sep 2017 19:33:38 +0000 (21:33 +0200)] 
doc/for-each-ref: explicitly specify option names

For count, sort and format, only the argument names were listed under
OPTIONS, not the option names.

Add the option names to make it clear the options exist

Signed-off-by: Kevin Daudt <me@ikke.info>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agodoc/for-each-ref: consistently use '=' to between argument names and values
Kevin Daudt [Mon, 11 Sep 2017 19:33:37 +0000 (21:33 +0200)] 
doc/for-each-ref: consistently use '=' to between argument names and values

The synopsis and description inconsistently add a '=' between the
argument name and it's value. Make this consistent.

Signed-off-by: Kevin Daudt <me@ikke.info>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agosubprocess: loudly die when subprocess asks for an unsupported capability
Junio C Hamano [Mon, 11 Sep 2017 03:21:29 +0000 (12:21 +0900)] 
subprocess: loudly die when subprocess asks for an unsupported capability

The handshake_capabilities() function first advertises the set of
capabilities it supports, so that the other side can pick and choose
which ones to use and ask us to enable in its response.  Then we
read the response that tells us what choice the other side made.  If
we saw something that we never advertised, that indicates one of two
things.  The other side, i.e. the "upgraded" filter, is not paying
attention of the capabilities advertisement, and asking something
its correct operation relies on, but we are not capable of giving
that unknown feature and operate without it, so after that point the
exchange of data is a garbage-in-garbage-out.  Or the other side
wanted to ask for one of the capabilities we advertised, but the
code has typo and their wish to enable a capability that its correct
operation relies on is not understood on this end.  The result is
the same garbage-in-garbage-out.

Instead of sweeping such a potential bug under the rug, die loudly
when we see a request for an unsupported capability in order to
force sloppily-written filter scripts to get corrected.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agotravis: dedent a few scripts that are indented overly deeply
Junio C Hamano [Mon, 11 Sep 2017 01:18:29 +0000 (10:18 +0900)] 
travis: dedent a few scripts that are indented overly deeply

Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agotravis-ci: skip a branch build if equal tag is present
Lars Schneider [Sun, 10 Sep 2017 14:44:29 +0000 (16:44 +0200)] 
travis-ci: skip a branch build if equal tag is present

If we push a branch and a tag pointing to the HEAD of this branch,
then Travis CI would run the build twice. This wastes resources and
slows the testing.

Add a function to detect this situation and skip the build the branch
if appropriate. Invoke this function on every build.

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Lars Schneider <larsxschneider@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agotravis-ci: move Travis CI code into dedicated scripts
Lars Schneider [Sun, 10 Sep 2017 14:44:28 +0000 (16:44 +0200)] 
travis-ci: move Travis CI code into dedicated scripts

Most of the Travis CI commands are in the '.travis.yml'. The yml format
does not support functions and therefore code duplication is necessary
to run commands across all builds.

To fix this, add a library for common CI functions. Move all Travis CI
code into dedicated scripts and make them call the library first.

Signed-off-by: Lars Schneider <larsxschneider@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoSync with maint
Junio C Hamano [Sun, 10 Sep 2017 08:15:43 +0000 (17:15 +0900)] 
Sync with maint

* maint:
  RelNotes: further fixes for 2.14.2 from the master front

6 years agoThe seventh batch post 2.14
Junio C Hamano [Sun, 10 Sep 2017 08:15:09 +0000 (17:15 +0900)] 
The seventh batch post 2.14

Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoMerge branch 'rs/apply-epoch'
Junio C Hamano [Sun, 10 Sep 2017 08:08:25 +0000 (17:08 +0900)] 
Merge branch 'rs/apply-epoch'

Code simplification.

* rs/apply-epoch:
  apply: remove epoch date from regex
  apply: check date of potential epoch timestamps first

6 years agoMerge branch 'jk/drop-sha1-entry-pos'
Junio C Hamano [Sun, 10 Sep 2017 08:08:25 +0000 (17:08 +0900)] 
Merge branch 'jk/drop-sha1-entry-pos'

Code clean-up.

* jk/drop-sha1-entry-pos:
  sha1-lookup: remove sha1_entry_pos() from header file

6 years agoMerge branch 'nd/worktree-kill-parse-ref'
Junio C Hamano [Sun, 10 Sep 2017 08:08:23 +0000 (17:08 +0900)] 
Merge branch 'nd/worktree-kill-parse-ref'

"git branch -M a b" while on a branch that is completely unrelated
to either branch a or branch b misbehaved when multiple worktree
was in use.  This has been fixed.

* nd/worktree-kill-parse-ref:
  branch: fix branch renaming not updating HEADs correctly

6 years agoMerge branch 'mm/send-email-cc-cruft'
Junio C Hamano [Sun, 10 Sep 2017 08:08:22 +0000 (17:08 +0900)] 
Merge branch 'mm/send-email-cc-cruft'

In addition to "cc: <a@dd.re.ss> # cruft", "cc: a@dd.re.ss # cruft"
was taught to "git send-email" as a valid way to tell it that it
needs to also send a carbon copy to <a@dd.re.ss> in the trailer
section.

* mm/send-email-cc-cruft:
  send-email: don't use Mail::Address, even if available
  send-email: fix garbage removal after address

6 years agoMerge branch 'ls/convert-filter-progress'
Junio C Hamano [Sun, 10 Sep 2017 08:08:22 +0000 (17:08 +0900)] 
Merge branch 'ls/convert-filter-progress'

The codepath to call external process filter for smudge/clean
operation learned to show the progress meter.

* ls/convert-filter-progress:
  convert: display progress for filtered objects that have been delayed

6 years agoMerge branch 'ma/up-to-date'
Junio C Hamano [Sun, 10 Sep 2017 08:08:22 +0000 (17:08 +0900)] 
Merge branch 'ma/up-to-date'

Message and doc updates.

* ma/up-to-date:
  treewide: correct several "up-to-date" to "up to date"
  Documentation/user-manual: update outdated example output