git
8 years agot5313: test bounds-checks of corrupted/malicious pack/idx files
Jeff King [Thu, 25 Feb 2016 14:21:12 +0000 (09:21 -0500)] 
t5313: test bounds-checks of corrupted/malicious pack/idx files

Our on-disk .pack and .idx files may reference other data by
offset. We should make sure that we are not fooled by
corrupt data into accessing memory outside of our mmap'd
boundaries.

This patch adds a series of tests for offsets found in .pack
and .idx files. For the most part we get this right, but
there are two tests of .idx files marked as failures: we do
not bounds-check offsets in the v2 index's extended offset
table, nor do we handle .idx offsets that overflow a signed
off_t.

With these tests, we should have good coverage of all
offsets found in these files. Note that this doesn't cover
.bitmap files, which may have similar bugs.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agogit config: report when trying to modify a non-existing repo config
Johannes Schindelin [Wed, 24 Feb 2016 12:48:11 +0000 (13:48 +0100)] 
git config: report when trying to modify a non-existing repo config

It is a pilot error to call `git config section.key value` outside of
any Git worktree. The message

error: could not lock config file .git/config: No such file or
directory

is not very helpful in that situation, though. Let's print a helpful
message instead.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agopush: remove "push.default is unset" warning message
Matthieu Moy [Thu, 25 Feb 2016 09:21:59 +0000 (10:21 +0100)] 
push: remove "push.default is unset" warning message

The warning was important before the 2.0 transition, and remained
important for a while after, so that new users get push.default
explicitly in their configuration and do not experience inconsistent
behavior if they ever used an older version of Git.

The warning has been there since version 1.8.0 (Oct 2012), hence we can
expect the vast majority of current Git users to have been exposed to
it, and most of them have already set push.default explicitly. The
switch from 'matching' to 'simple' was planned for 2.0 (May 2014), but
actually happened only for 2.3 (Feb 2015).

Today, the warning is mostly seen by beginners, who have not set their
push.default configuration (yet). For many of them, the warning is
confusing because it talks about concepts that they have not learned and
asks them a choice that they are not able to make yet. See for example

  http://stackoverflow.com/questions/13148066/warning-push-default-is-unset-its-implicit-value-is-changing-in-git-2-0

(1260 votes for the question, 1824 for the answer as of writing)

Remove the warning completely to avoid disturbing beginners. People who
still occasionally use an older version of Git will be exposed to the
warning through this old version.

Eventually, versions of Git without the warning will be deployed enough
and tutorials will not need to advise setting push.default anymore.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoREADME.md: move down historical explanation about the name
Matthieu Moy [Thu, 25 Feb 2016 08:37:30 +0000 (09:37 +0100)] 
README.md: move down historical explanation about the name

The explanations about why the name was chosen are secondary compared to
the description and link to the documentation.

Some consider these explanations as good computer scientists joke, but
other see it as needlessly offensive vocabulary.

This patch preserves the historical joke, but gives it less importance
by moving it to the end of the README, and makes it clear that it is a
historical explanation, that does not necessarily reflect the state of
mind of current developers.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoREADME.md: don't call git stupid in the title
Matthieu Moy [Thu, 25 Feb 2016 08:37:29 +0000 (09:37 +0100)] 
README.md: don't call git stupid in the title

"the stupid content tracker" was true in the early days of Git, but
hardly applicable these days. "fast, scalable, distributed" describes
Git more accuralety.

Also, "stupid" can be seen as offensive by some people. Let's not use it
in the very first words of the README.

The new formulation is taken from the description of the Debian package.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoREADME.md: move the link to git-scm.com up
Matthieu Moy [Thu, 25 Feb 2016 08:37:28 +0000 (09:37 +0100)] 
README.md: move the link to git-scm.com up

The documentation available on git-scm.com is nicely formatted. It's
better to point users to it than to the source code of the
documentation.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoREADME.md: add hyperlinks on filenames
Matthieu Moy [Thu, 25 Feb 2016 08:37:27 +0000 (09:37 +0100)] 
README.md: add hyperlinks on filenames

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoREADME: use markdown syntax
Matthieu Moy [Thu, 25 Feb 2016 08:37:26 +0000 (09:37 +0100)] 
README: use markdown syntax

This allows repository browsers like GitHub to display the content of
the file nicely formatted.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agotemplates/hooks: fix minor typo in the sample update-hook
Martin Amdisen [Thu, 25 Feb 2016 08:10:12 +0000 (09:10 +0100)] 
templates/hooks: fix minor typo in the sample update-hook

Signed-off-by: Martin Mosegaard Amdisen <martin.amdisen@praqma.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agosubmodule: try harder to fetch needed sha1 by direct fetching sha1
Stefan Beller [Wed, 24 Feb 2016 03:32:13 +0000 (19:32 -0800)] 
submodule: try harder to fetch needed sha1 by direct fetching sha1

When reviewing a change that also updates a submodule in Gerrit, a
common review practice is to download and cherry-pick the patch
locally to test it. However when testing it locally, the 'git
submodule update' may fail fetching the correct submodule sha1 as
the corresponding commit in the submodule is not yet part of the
project history, but also just a proposed change.

If $sha1 was not part of the default fetch, we try to fetch the $sha1
directly. Some servers however do not support direct fetch by sha1,
which leads git-fetch to fail quickly. We can fail ourselves here as
the still missing sha1 would lead to a failure later in the checkout
stage anyway, so failing here is as good as we can get.

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agot3034: test deprecated interface
Felipe Gonçalves Assis [Wed, 24 Feb 2016 01:41:31 +0000 (22:41 -0300)] 
t3034: test deprecated interface

--find-renames= and --rename-threshold= should be aliases.

Signed-off-by: Felipe Gonçalves Assis <felipegassis@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agot3034: test option to disable renames
Felipe Gonçalves Assis [Wed, 24 Feb 2016 01:41:30 +0000 (22:41 -0300)] 
t3034: test option to disable renames

Signed-off-by: Felipe Gonçalves Assis <felipegassis@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agot3034: add rename threshold tests
Felipe Gonçalves Assis [Wed, 24 Feb 2016 01:41:29 +0000 (22:41 -0300)] 
t3034: add rename threshold tests

10ae752 (merge-recursive: option to specify rename threshold,
2010-09-27) introduced this feature but did not include any tests.

The tests use the new option --find-renames, which replaces the then
introduced and now deprecated option --rename-threshold.

Also update name and description of t3032 for consistency:
"merge-recursive options" -> "merge-recursive space options"

Signed-off-by: Felipe Gonçalves Assis <felipegassis@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agosubmodule helper list: respect correct path prefix
Stefan Beller [Wed, 24 Feb 2016 21:15:02 +0000 (13:15 -0800)] 
submodule helper list: respect correct path prefix

This is a regression introduced by 74703a1e4d (submodule: rewrite
`module_list` shell function in C, 2015-09-02).

Add a test to ensure we list the right submodule when giving a
specific pathspec.

Reported-By: Caleb Jorden <cjorden@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoEighth batch for 2.8
Junio C Hamano [Wed, 24 Feb 2016 21:31:57 +0000 (13:31 -0800)] 
Eighth batch for 2.8

Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoMerge branch 'jc/am-i-v-fix'
Junio C Hamano [Wed, 24 Feb 2016 21:26:01 +0000 (13:26 -0800)] 
Merge branch 'jc/am-i-v-fix'

The "v(iew)" subcommand of the interactive "git am -i" command was
broken in 2.6.0 timeframe when the command was rewritten in C.

* jc/am-i-v-fix:
  am -i: fix "v"iew
  pager: factor out a helper to prepare a child process to run the pager
  pager: lose a separate argv[]

8 years agoMerge branch 'nd/worktree-add-B'
Junio C Hamano [Wed, 24 Feb 2016 21:26:00 +0000 (13:26 -0800)] 
Merge branch 'nd/worktree-add-B'

"git worktree add -B <branchname>" did not work.

* nd/worktree-add-B:
  worktree add -B: do the checkout test before update branch
  worktree: fix "add -B"

8 years agoMerge branch 'nd/exclusion-regression-fix'
Junio C Hamano [Wed, 24 Feb 2016 21:25:59 +0000 (13:25 -0800)] 
Merge branch 'nd/exclusion-regression-fix'

Another try to add support to the ignore mechanism that lets you
say "this is excluded" and then later say "oh, no, this part (that
is a subset of the previous part) is not excluded".

* nd/exclusion-regression-fix:
  dir.c: don't exclude whole dir prematurely
  dir.c: support marking some patterns already matched
  dir.c: support tracing exclude
  dir.c: fix match_pathname()

8 years agoMerge branch 'ce/https-public-key-pinning'
Junio C Hamano [Wed, 24 Feb 2016 21:25:58 +0000 (13:25 -0800)] 
Merge branch 'ce/https-public-key-pinning'

You can now set http.[<url>.]pinnedpubkey to specify the pinned
public key when building with recent enough versions of libcURL.

* ce/https-public-key-pinning:
  http: implement public key pinning

8 years agoMerge branch 'bc/http-empty-auth'
Junio C Hamano [Wed, 24 Feb 2016 21:25:57 +0000 (13:25 -0800)] 
Merge branch 'bc/http-empty-auth'

Some authentication methods do not need username or password, but
libcurl needs some hint that it needs to perform authentication.
Supplying an empty username and password string is a valid way to
do so, but you can set the http.[<url>.]emptyAuth configuration
variable to achieve the same, if you find it cleaner.

* bc/http-empty-auth:
  http: add option to try authentication without username

8 years agoMerge branch 'sp/remote-curl-ssl-strerror'
Junio C Hamano [Wed, 24 Feb 2016 21:25:56 +0000 (13:25 -0800)] 
Merge branch 'sp/remote-curl-ssl-strerror'

Help those who debug http(s) part of the system.

* sp/remote-curl-ssl-strerror:
  remote-curl: include curl_errorstr on SSL setup failures

8 years agoMerge branch 'jk/lose-name-path'
Junio C Hamano [Wed, 24 Feb 2016 21:25:55 +0000 (13:25 -0800)] 
Merge branch 'jk/lose-name-path'

The "name_path" API was an attempt to reduce the need to construct
the full path out of a series of path components while walking a
tree hierarchy, but over time made less efficient because the path
needs to be flattened, e.g. to be compared with another path that
is already flat.  The API has been removed and its users have been
rewritten to simplify the overall code complexity.

* jk/lose-name-path:
  list-objects: pass full pathname to callbacks
  list-objects: drop name_path entirely
  list-objects: convert name_path to a strbuf
  show_object_with_name: simplify by using path_name()
  http-push: stop using name_path

8 years agoMerge branch 'ew/force-ipv4'
Junio C Hamano [Wed, 24 Feb 2016 21:25:54 +0000 (13:25 -0800)] 
Merge branch 'ew/force-ipv4'

"git fetch" and friends that make network connections can now be
told to only use ipv4 (or ipv6).

* ew/force-ipv4:
  connect & http: support -4 and -6 switches for remote operations

8 years agoMerge branch 'nd/git-common-dir-fix'
Junio C Hamano [Wed, 24 Feb 2016 21:25:53 +0000 (13:25 -0800)] 
Merge branch 'nd/git-common-dir-fix'

"git rev-parse --git-common-dir" used in the worktree feature
misbehaved when run from a subdirectory.

* nd/git-common-dir-fix:
  rev-parse: take prefix into account in --git-common-dir

8 years agoMerge branch 'nd/dwim-wildcards-as-pathspecs'
Junio C Hamano [Wed, 24 Feb 2016 21:25:52 +0000 (13:25 -0800)] 
Merge branch 'nd/dwim-wildcards-as-pathspecs'

"git show 'HEAD:Foo[BAR]Baz'" did not interpret the argument as a
rev, i.e. the object named by the the pathname with wildcard
characters in a tree object.

* nd/dwim-wildcards-as-pathspecs:
  get_sha1: don't die() on bogus search strings
  check_filename: tighten dwim-wildcard ambiguity
  checkout: reorder check_filename conditional

8 years agomerge-recursive: find-renames resets threshold
Felipe Gonçalves Assis [Sun, 21 Feb 2016 22:59:05 +0000 (19:59 -0300)] 
merge-recursive: find-renames resets threshold

Make the find-renames option follow the behaviour in git-diff, where it
resets the threshold when none is given. So, for instance,
"--find-renames=25 --find-renames" should result in the default
threshold (50%) instead of 25%.

Signed-off-by: Felipe Gonçalves Assis <felipegassis@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agot9200: avoid grep on non-ASCII data
John Keeping [Sun, 21 Feb 2016 17:32:22 +0000 (17:32 +0000)] 
t9200: avoid grep on non-ASCII data

GNU grep 2.23 detects the input used in this test as binary data so it
does not work for extracting lines from a file.  We could add the "-a"
option to force grep to treat the input as text, but not all
implementations support that.  Instead, use sed to extract the desired
lines since it will always treat its input as text.

Signed-off-by: John Keeping <john@keeping.me.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agot8005: avoid grep on non-ASCII data
John Keeping [Sun, 21 Feb 2016 17:32:21 +0000 (17:32 +0000)] 
t8005: avoid grep on non-ASCII data

GNU grep 2.23 detects the input used in this test as binary data so it
does not work for extracting lines from a file.  We could add the "-a"
option to force grep to treat the input as text, but not all
implementations support that.  Instead, use sed to extract the desired
lines since it will always treat its input as text.

While touching these lines, modernize the test style to avoid hiding the
exit status of "git blame" and remove a space following a redirection
operator.  Also swap the order of the expected and actual output
files given to test_cmp; we compare expect and actual to show how
actual output differs from what is expected.

Signed-off-by: John Keeping <john@keeping.me.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agocredential-cache--daemon: change to the socket dir on startup
Jon Griffiths [Tue, 23 Feb 2016 07:16:04 +0000 (02:16 -0500)] 
credential-cache--daemon: change to the socket dir on startup

Changing to the socket path stops the daemon holding open
the directory the user was in when it was started,
preventing umount from working. We're already holding open a
socket in that directory, so there's no downside.

Thanks-to: Jeff King <peff@peff.net>
Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoDocumentation/git-push: document that 'simple' is the default
Matthieu Moy [Tue, 23 Feb 2016 21:04:41 +0000 (22:04 +0100)] 
Documentation/git-push: document that 'simple' is the default

The default behavior is well documented already in git-config(1), but
git-push(1) itself did not mention it at all. For users willing to learn
how "git push" works but not how to configure it, this makes the
documentation cumbersome to read.

Make the git-push(1) page self-contained by adding a short summary of
what 'push.default=simple' does, early in the page.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoxdiff/xmerge: fix memory leak in xdl_merge
Patrick Steinhardt [Tue, 23 Feb 2016 11:59:17 +0000 (12:59 +0100)] 
xdiff/xmerge: fix memory leak in xdl_merge

When building the script for the second file that is to be merged
we have already allocated memory for data structures related to
the first file. When we encounter an error in building the second
script we only free allocated memory related to the second file
before erroring out.

Fix this memory leak by also releasing allocated memory related
to the first file.

Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agocredential-cache--daemon: disallow relative socket path
Jon Griffiths [Tue, 23 Feb 2016 07:15:41 +0000 (02:15 -0500)] 
credential-cache--daemon: disallow relative socket path

Relative socket paths are dangerous since the user cannot generally
control when the daemon starts (initially, after a timeout, kill or
crash). Since the daemon creates but does not delete the socket
directory, this could lead to spurious directory creation relative
to the users cwd.

Suggested-by: Jeff King <peff@peff.net>
Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agocredential-cache--daemon: refactor check_socket_directory
Jon Griffiths [Tue, 23 Feb 2016 07:15:15 +0000 (02:15 -0500)] 
credential-cache--daemon: refactor check_socket_directory

This function does an early return, and therefore has to
repeat its cleanup. We can stick the later bit of the
function into an "else" and avoid duplicating the shared
part (which will get bigger in a future patch).

Let's also rename the function to init_socket_directory. It
not only checks the directory but also creates it. Saying
"init" is more accurate.

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agotests: remove no-op full-svn-test target
Eric Wong [Tue, 23 Feb 2016 06:26:59 +0000 (06:26 +0000)] 
tests: remove no-op full-svn-test target

git-svn has not supported GIT_SVN_NO_OPTIMIZE_COMMITS for
the "set-tree" sub-command in 9 years since commit 490f49ea5899
("git-svn: remove optimized commit stuff for set-tree").

So remove this target and TSVN variable to avoid confusion.

ref: http://mid.gmane.org/56C9B7B7.7030406@f2.dion.ne.jp

Helped-by: Kazutoshi Satoda <k_satoda@f2.dion.ne.jp>
Signed-off-by: Eric Wong <normalperson@yhbt.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoconvert.c: correct attr_action()
Torsten Bögershausen [Tue, 23 Feb 2016 17:07:19 +0000 (18:07 +0100)] 
convert.c: correct attr_action()

df747b81 (convert.c: refactor crlf_action, 2016-02-10) introduced a
bug to "git ls-files --eol".

The "text" attribute was shown as "text eol=lf" or "text eol=crlf",
depending on core.autocrlf or core.eol.

Correct this and add test cases in t0027.

Signed-off-by: Torsten Bögershausen <tboegi@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoxdiff: drop XDL_EMIT_COMMON
Jeff King [Tue, 23 Feb 2016 06:07:25 +0000 (01:07 -0500)] 
xdiff: drop XDL_EMIT_COMMON

There are no more callers that use this mode, and none
likely to be added (as our xdl_merge() eliminates the common
use of it for generating 3-way merge bases).

This is effectively a revert of a9ed376 (xdiff: generate
"anti-diffs" aka what is common to two files, 2006-06-28),
though of course trying to revert that ancient commit
directly produces many textual conflicts.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agomerge-tree: drop generate_common strategy
Jeff King [Tue, 23 Feb 2016 06:06:55 +0000 (01:06 -0500)] 
merge-tree: drop generate_common strategy

When merge_blobs sees an add/add conflict, it tries to
create a virtual base object for the 3-way merge that
consists of the common lines of each file. It inherited this
strategy from merge-one-file in 0c79938 (Improved three-way
blob merging code, 2006-06-28), and the point is to minimize
the size of the conflict hunks. That commit talks about "if
libxdiff were to ever grow a compatible three-way merge, it
could probably be directly plugged in".

That has long since happened. So as with merge-one-file in
the previous commit, this extra step is no longer necessary.
Our 3-way merge code is smart enough to do the minimizing
itself if we simply feed it an empty base, which is what the
more modern merge-recursive strategy already does.

Not only does this let us drop some code, but it removes an
overflow bug in generate_common_file(). We allocate a buffer
as large as the smallest of the two blobs, under the
assumption that there cannot be more common content than
what is in the smaller blob. However, xdiff may feed us
more: if neither file ends in a newline, it feeds us the
"\nNo newline at end of file" marker as common content, and
we write it into the output. If the differences between the
files are small than that string, we overflow the output
buffer.  This patch solves it by simply dropping the buggy
code entirely.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agomerge-one-file: use empty blob for add/add base
Jeff King [Tue, 23 Feb 2016 06:04:41 +0000 (01:04 -0500)] 
merge-one-file: use empty blob for add/add base

When we see an add/add conflict on a file, we generate the
conflicted content by doing a 3-way merge with a "virtual"
base consisting of the common lines of the two sides. This
strategy dates back to cb93c19 (merge-one-file: use common
as base, instead of emptiness., 2005-11-09).

Back then, the next step was to call rcs merge to generate
the 3-way conflicts. Using the virtual base produced much
better results, as rcs merge does not attempt to minimize
the hunks. As a result, you'd get a conflict with the
entirety of the files on either side.

Since then, though, we've switched to using git-merge-file,
which uses xdiff's "zealous" merge. This will find the
minimal hunks even with just the simple, empty base.

Let's switch to using that empty base. It's simpler, more
efficient, and reduces our dependencies (we no longer need a
working diff binary). It's also how the merge-recursive
strategy handles this same case.

We can almost get rid of git-sh-setup's create_virtual_base,
but we don't here, for two reasons:

  1. The functions in git-sh-setup are part of our public
     interface, so it's possible somebody is depending on
     it. We'd at least need to deprecate it first.

  2. It's also used by mergetool's p4merge driver. It's
     unknown whether its 3-way merge is as capable as git's;
     if not, then it is benefiting from the function.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoewah: convert to REALLOC_ARRAY, etc
Jeff King [Mon, 22 Feb 2016 22:45:15 +0000 (17:45 -0500)] 
ewah: convert to REALLOC_ARRAY, etc

Now that we're built around xmalloc and friends, we can use
helpers like REALLOC_ARRAY, ALLOC_GROW, and so on to make
the code shorter and protect against integer overflow.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoconvert ewah/bitmap code to use xmalloc
Jeff King [Mon, 22 Feb 2016 22:45:12 +0000 (17:45 -0500)] 
convert ewah/bitmap code to use xmalloc

This code was originally written with the idea that it could
be spun off into its own ewah library, and uses the
overrideable ewah_malloc to do allocations.

We plug in xmalloc as our ewah_malloc, of course. But over
the years the ewah code itself has become more entangled
with git, and the return value of many ewah_malloc sites is
not checked.

Let's just drop the level of indirection and use xmalloc and
friends directly. This saves a few lines, and will let us
adapt these sites to our more advanced malloc helpers.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agodiff_populate_gitlink: use a strbuf
Jeff King [Mon, 22 Feb 2016 22:45:08 +0000 (17:45 -0500)] 
diff_populate_gitlink: use a strbuf

We allocate 100 bytes to hold the "Submodule commit ..."
text. This is enough, but it's not immediately obvious that
this is the case, and we have to repeat the magic 100 twice.

We could get away with xstrfmt here, but we want to know the
size, as well, so let's use a real strbuf. And while we're
here, we can clean up the logic around size_only. It
currently sets and clears the "data" field pointlessly, and
leaves the "should_free" flag on even after we have cleared
the data.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agotransport_anonymize_url: use xstrfmt
Jeff King [Mon, 22 Feb 2016 22:45:05 +0000 (17:45 -0500)] 
transport_anonymize_url: use xstrfmt

This function uses xcalloc and two memcpy calls to
concatenate two strings. We can do this as an xstrfmt
one-liner, and then it is more clear that we are allocating
the correct amount of memory.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agogit-compat-util: drop mempcpy compat code
Jeff King [Mon, 22 Feb 2016 22:45:01 +0000 (17:45 -0500)] 
git-compat-util: drop mempcpy compat code

There are no callers of this left, as the last one was
dropped in the previous patch. And there are not likely to
be new ones, as the function has been around since 2010
without gaining any new callers.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agosequencer: simplify memory allocation of get_message
Jeff King [Mon, 22 Feb 2016 22:44:57 +0000 (17:44 -0500)] 
sequencer: simplify memory allocation of get_message

For a commit with sha1 "1234abcd" and subject "foo", this
function produces a struct with three strings:

 1. "foo"

 2. "1234abcd... foo"

 3. "parent of 1234abcd... foo"

It takes advantage of the fact that these strings are
subsets of each other, and allocates only _one_ string, with
pointers into the various parts. Unfortunately, this makes
the string allocation complicated and hard to follow.

Since we keep only one of these in memory at a time, we can
afford to simply allocate three strings. This lets us build
on tools like xstrfmt and avoid manual computation.

While we're here, we can also drop the ad-hoc
reimplementation of get_git_commit_encoding(), and simply
call that function.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agotest-path-utils: fix normalize_path_copy output buffer size
Jeff King [Mon, 22 Feb 2016 22:44:54 +0000 (17:44 -0500)] 
test-path-utils: fix normalize_path_copy output buffer size

The normalize_path_copy function needs an output buffer that
is at least as long as its input (it may shrink the path,
but never expand it). However, this test program feeds it
static PATH_MAX-sized buffers, which have no relation to the
input size.

In the normalize_ceiling_entry case, we do at least check
the size against PATH_MAX and die(), but that case is even
more convoluted. We normalize into a fixed-size buffer, free
the original, and then replace it with a strdup'd copy of
the result. But normalize_path_copy explicitly allows
normalizing in-place, so we can simply do that.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agofetch-pack: simplify add_sought_entry
Jeff King [Mon, 22 Feb 2016 22:44:50 +0000 (17:44 -0500)] 
fetch-pack: simplify add_sought_entry

We have two variants of this function, one that takes a
string and one that takes a ptr/len combo. But we only call
the latter with the length of a NUL-terminated string, so
our first simplification is to drop it in favor of the
string variant.

Since we know we have a string, we can also replace the
manual memory computation with a call to alloc_ref().

Furthermore, we can rely on get_oid_hex() to complain if it
hits the end of the string. That means we can simplify the
check for "<sha1> <ref>" versus just "<ref>". Rather than
manage the ptr/len pair, we can just bump the start of our
string forward. The original code over-allocated based on
the original "namelen" (which wasn't _wrong_, but was simply
wasteful and confusing).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agofast-import: simplify allocation in start_packfile
Jeff King [Mon, 22 Feb 2016 22:44:46 +0000 (17:44 -0500)] 
fast-import: simplify allocation in start_packfile

This function allocate a packed_git flex-array, and adds a
mysterious 2 bytes to the length of the pack_name field. One
is for the trailing NUL, but the other has no purpose. This
is probably cargo-culted from add_packed_git, which gets the
".idx" path and needed to allocate enough space to hold the
matching ".pack" (though since 48bcc1c, we calculate the
size there differently).

This site, however, is using the raw path of a tempfile, and
does not need the extra byte. We can just replace the
allocation with FLEX_ALLOC_STR, which handles the allocation
and the NUL for us.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agowrite_untracked_extension: use FLEX_ALLOC helper
Jeff King [Mon, 22 Feb 2016 22:44:42 +0000 (17:44 -0500)] 
write_untracked_extension: use FLEX_ALLOC helper

We perform unchecked additions when computing the size of a
"struct ondisk_untracked_cache". This is unlikely to have an
integer overflow in practice, but we'd like to avoid this
dangerous pattern to make further audits easier.

Note that there's one subtlety here, though.  We protect
ourselves against a NULL exclude_per_dir entry in our
source, and avoid calling strlen() on it, keeping "len" at
0. But later, we unconditionally memcpy "len + 1" bytes to
get the trailing NUL byte. If we did have a NULL
exclude_per_dir, we would read from bogus memory.

As it turns out, though, we always create this field
pointing to a string literal, so there's no bug. We can just
get rid of the pointless extra conditional.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoprepare_{git,shell}_cmd: use argv_array
Jeff King [Mon, 22 Feb 2016 22:44:39 +0000 (17:44 -0500)] 
prepare_{git,shell}_cmd: use argv_array

These functions transform an existing argv into one suitable
for exec-ing or spawning via git or a shell. We can use an
argv_array in each to avoid dealing with manual counting and
allocation.

This also makes the memory allocation more clear and fixes
some leaks. In prepare_shell_cmd, we would sometimes
allocate a new string with "$@" in it and sometimes not,
meaning the caller could not correctly free it. On the
non-Windows side, we are in a child process which will
exec() or exit() immediately, so the leak isn't a big deal.
On Windows, though, we use spawn() from the parent process,
and leak a string for each shell command we run. On top of
that, the Windows code did not free the allocated argv array
at all (but does for the prepare_git_cmd case!).

By switching both of these functions to write into an
argv_array, we can consistently free the result as
appropriate.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agouse st_add and st_mult for allocation size computation
Jeff King [Mon, 22 Feb 2016 22:44:35 +0000 (17:44 -0500)] 
use st_add and st_mult for allocation size computation

If our size computation overflows size_t, we may allocate a
much smaller buffer than we expected and overflow it. It's
probably impossible to trigger an overflow in most of these
sites in practice, but it is easy enough convert their
additions and multiplications into overflow-checking
variants. This may be fixing real bugs, and it makes
auditing the code easier.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoconvert trivial cases to FLEX_ARRAY macros
Jeff King [Mon, 22 Feb 2016 22:44:32 +0000 (17:44 -0500)] 
convert trivial cases to FLEX_ARRAY macros

Using FLEX_ARRAY macros reduces the amount of manual
computation size we have to do. It also ensures we don't
overflow size_t, and it makes sure we write the same number
of bytes that we allocated.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agouse xmallocz to avoid size arithmetic
Jeff King [Mon, 22 Feb 2016 22:44:28 +0000 (17:44 -0500)] 
use xmallocz to avoid size arithmetic

We frequently allocate strings as xmalloc(len + 1), where
the extra 1 is for the NUL terminator. This can be done more
simply with xmallocz, which also checks for integer
overflow.

There's no case where switching xmalloc(n+1) to xmallocz(n)
is wrong; the result is the same length, and malloc made no
guarantees about what was in the buffer anyway. But in some
cases, we can stop manually placing NUL at the end of the
allocated buffer. But that's only safe if it's clear that
the contents will always fill the buffer.

In each case where this patch does so, I manually examined
the control flow, and I tried to err on the side of caution.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoconvert trivial cases to ALLOC_ARRAY
Jeff King [Mon, 22 Feb 2016 22:44:25 +0000 (17:44 -0500)] 
convert trivial cases to ALLOC_ARRAY

Each of these cases can be converted to use ALLOC_ARRAY or
REALLOC_ARRAY, which has two advantages:

  1. It automatically checks the array-size multiplication
     for overflow.

  2. It always uses sizeof(*array) for the element-size,
     so that it can never go out of sync with the declared
     type of the array.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoconvert manual allocations to argv_array
Jeff King [Mon, 22 Feb 2016 22:44:21 +0000 (17:44 -0500)] 
convert manual allocations to argv_array

There are many manual argv allocations that predate the
argv_array API. Switching to that API brings a few
advantages:

  1. We no longer have to manually compute the correct final
     array size (so it's one less thing we can screw up).

  2. In many cases we had to make a separate pass to count,
     then allocate, then fill in the array. Now we can do it
     in one pass, making the code shorter and easier to
     follow.

  3. argv_array handles memory ownership for us, making it
     more obvious when things should be free()d and and when
     not.

Most of these cases are pretty straightforward. In some, we
switch from "run_command_v" to "run_command" which lets us
directly use the argv_array embedded in "struct
child_process".

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoargv-array: add detach function
Jeff King [Mon, 22 Feb 2016 22:44:15 +0000 (17:44 -0500)] 
argv-array: add detach function

The usual pattern for an argv array is to initialize it,
push in some strings, and then clear it when done. Very
occasionally, though, we must do other exotic things with
the memory, like freeing the list but keeping the strings.
Let's provide a detach function so that callers can make use
of our API to build up the array, and then take ownership of
it.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoadd helpers for allocating flex-array structs
Jeff King [Mon, 22 Feb 2016 22:43:25 +0000 (17:43 -0500)] 
add helpers for allocating flex-array structs

Allocating a struct with a flex array is pretty simple in
practice: you over-allocate the struct, then copy some data
into the over-allocation. But it can be a slight pain to
make sure you're allocating and copying the right amounts.

This patch adds a few helpers to turn simple cases of
flex-array struct allocation into a one-liner that properly
checks for overflow. See the embedded documentation for
details.

Ideally we could provide a more flexible version that could
handle multiple strings, like:

  FLEX_ALLOC_FMT(ref, name, "%s%s", prefix, name);

But we have to implement this as a macro (because of the
offset calculation of the flex member), which means we would
need all compilers to support variadic macros.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoharden REALLOC_ARRAY and xcalloc against size_t overflow
Jeff King [Mon, 22 Feb 2016 22:43:18 +0000 (17:43 -0500)] 
harden REALLOC_ARRAY and xcalloc against size_t overflow

REALLOC_ARRAY inherently involves a multiplication which can
overflow size_t, resulting in a much smaller buffer than we
think we've allocated. We can easily harden it by using
st_mult() to check for overflow.  Likewise, we can add
ALLOC_ARRAY to do the same thing for xmalloc calls.

xcalloc() should already be fine, because it takes the two
factors separately, assuming the system calloc actually
checks for overflow. However, before we even hit the system
calloc(), we do our memory_limit_check, which involves a
multiplication. Let's check for overflow ourselves so that
this limit cannot be bypassed.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoSync with 2.7.2
Junio C Hamano [Mon, 22 Feb 2016 21:16:12 +0000 (13:16 -0800)] 
Sync with 2.7.2

8 years agoMerge branch 'js/git-remote-add-url-insteadof-test'
Junio C Hamano [Mon, 22 Feb 2016 21:15:01 +0000 (13:15 -0800)] 
Merge branch 'js/git-remote-add-url-insteadof-test'

* js/git-remote-add-url-insteadof-test:
  t5505: 'remote add x y' should work when url.y.insteadOf = x

8 years agoMerge branch 'jk/config-include'
Junio C Hamano [Mon, 22 Feb 2016 21:14:48 +0000 (13:14 -0800)] 
Merge branch 'jk/config-include'

* jk/config-include:
  git-config: better document default behavior for `--include`

8 years agoMerge branch 'ew/connect-verbose'
Junio C Hamano [Mon, 22 Feb 2016 21:14:33 +0000 (13:14 -0800)] 
Merge branch 'ew/connect-verbose'

* ew/connect-verbose:
  t5570: add tests for "git {clone,fetch,pull} -v"

8 years agoGit 2.7.2 v2.7.2
Junio C Hamano [Mon, 22 Feb 2016 21:12:56 +0000 (13:12 -0800)] 
Git 2.7.2

Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoMerge branch 'nd/ita-cleanup' into maint
Junio C Hamano [Mon, 22 Feb 2016 21:10:21 +0000 (13:10 -0800)] 
Merge branch 'nd/ita-cleanup' into maint

Paths that have been told the index about with "add -N" are not
quite yet in the index, but a few commands behaved as if they
already are in a harmful way.

* nd/ita-cleanup:
  grep: make it clear i-t-a entries are ignored
  add and use a convenience macro ce_intent_to_add()
  blame: remove obsolete comment

8 years agoMerge branch 'pw/completion-stash' into maint
Junio C Hamano [Mon, 22 Feb 2016 21:10:20 +0000 (13:10 -0800)] 
Merge branch 'pw/completion-stash' into maint

* pw/completion-stash:
  completion: fix mis-indentation in _git_stash()

8 years agoMerge branch 'mm/clean-doc-fix' into maint
Junio C Hamano [Mon, 22 Feb 2016 21:10:20 +0000 (13:10 -0800)] 
Merge branch 'mm/clean-doc-fix' into maint

The documentation for "git clean" has been corrected; it mentioned
that .git/modules/* are removed by giving two "-f", which has never
been the case.

* mm/clean-doc-fix:
  Documentation/git-clean.txt: don't mention deletion of .git/modules/*

8 years agoMerge branch 'dw/mergetool-vim-window-shuffle' into maint
Junio C Hamano [Mon, 22 Feb 2016 21:10:19 +0000 (13:10 -0800)] 
Merge branch 'dw/mergetool-vim-window-shuffle' into maint

The vimdiff backend for "git mergetool" has been tweaked to arrange
and number buffers in the order that would match the expectation of
majority of people who read left to right, then top down and assign
buffers 1 2 3 4 "mentally" to local base remote merge windows based
on that order.

* dw/mergetool-vim-window-shuffle:
  mergetool: reorder vim/gvim buffers in three-way diffs

8 years agoMerge branch 'ah/stripspace-optstring' into maint
Junio C Hamano [Mon, 22 Feb 2016 21:10:19 +0000 (13:10 -0800)] 
Merge branch 'ah/stripspace-optstring' into maint

* ah/stripspace-optstring:
  stripspace: call U+0020 a "space" instead of a "blank"

8 years agomerge-strategies.txt: fix typo
Felipe Gonçalves Assis [Sun, 21 Feb 2016 22:59:01 +0000 (19:59 -0300)] 
merge-strategies.txt: fix typo

Signed-off-by: Felipe Gonçalves Assis <felipegassis@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agodiff: clarify textconv interface
Jeff King [Mon, 22 Feb 2016 18:28:54 +0000 (13:28 -0500)] 
diff: clarify textconv interface

The memory allocation scheme for the textconv interface is a
bit tricky, and not well documented. It was originally
designed as an internal part of diff.c (matching
fill_mmfile), but gradually was made public.

Refactoring it is difficult, but we can at least improve the
situation by documenting the intended flow and enforcing it
with an in-code assertion.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoMerge branch 'ks/svn-pathnameencoding-4' of git://git.bogomips.org/git-svn
Junio C Hamano [Mon, 22 Feb 2016 18:29:46 +0000 (10:29 -0800)] 
Merge branch 'ks/svn-pathnameencoding-4' of git://git.bogomips.org/git-svn

* 'ks/svn-pathnameencoding-4' of git://git.bogomips.org/git-svn:
  git-svn: apply "svn.pathnameencoding" before URL encoding
  git-svn: enable "svn.pathnameencoding" on dcommit
  git-svn: hoist out utf8 prep from t9129 to lib-git-svn

8 years agoMerge branch 'pw/completion-stash'
Junio C Hamano [Mon, 22 Feb 2016 18:27:24 +0000 (10:27 -0800)] 
Merge branch 'pw/completion-stash'

* pw/completion-stash:
  completion: fix mis-indentation in _git_stash()

8 years agocompletion: fix mis-indentation in _git_stash()
SZEDER Gábor [Mon, 22 Feb 2016 13:02:50 +0000 (14:02 +0100)] 
completion: fix mis-indentation in _git_stash()

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoconfig: rename git_config_set_or_die to git_config_set
Patrick Steinhardt [Mon, 22 Feb 2016 11:23:36 +0000 (12:23 +0100)] 
config: rename git_config_set_or_die to git_config_set

Rename git_config_set_or_die functions to git_config_set, leading
to the new default behavior of dying whenever a configuration
error occurs.

By now all callers that shall die on error have been transitioned
to the _or_die variants, thus making this patch a simple rename
of the functions.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoconfig: rename git_config_set to git_config_set_gently
Patrick Steinhardt [Mon, 22 Feb 2016 11:23:35 +0000 (12:23 +0100)] 
config: rename git_config_set to git_config_set_gently

The desired default behavior for `git_config_set` is to die
whenever an error occurs. Dying is the default for a lot of
internal functions when failures occur and is in this case the
right thing to do for most callers as otherwise we might run into
inconsistent repositories without noticing.

As some code may rely on the actual return values for
`git_config_set` we still require the ability to invoke these
functions without aborting. Rename the existing `git_config_set`
functions to `git_config_set_gently` to keep them available for
those callers.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agocompat: die when unable to set core.precomposeunicode
Patrick Steinhardt [Mon, 22 Feb 2016 11:23:34 +0000 (12:23 +0100)] 
compat: die when unable to set core.precomposeunicode

When calling `git_config_set` to set 'core.precomposeunicode' we
ignore the return value of the function, which may indicate that
we were unable to write the value back to disk. As the function
is only called by init-db we can and should die when an error
occurs.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agosequencer: die on config error when saving replay opts
Patrick Steinhardt [Mon, 22 Feb 2016 11:23:33 +0000 (12:23 +0100)] 
sequencer: die on config error when saving replay opts

When we start picking a range of revisions we save the replay
options that are required to restore state when interrupting and
later continuing picking the revisions. However, we do not check
the return values of the `git_config_set` functions, which may
lead us to store incomplete information. As this may lead us to
fail when trying to continue the sequence the error can be fatal.

Fix this by dying immediately when we are unable to write back
any replay option.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoinit-db: die on config errors when initializing empty repo
Patrick Steinhardt [Mon, 22 Feb 2016 11:23:32 +0000 (12:23 +0100)] 
init-db: die on config errors when initializing empty repo

When creating an empty repository with `git init-db` we do not
check for error codes returned by `git_config_set` functions.
This may cause the user to end up with an inconsistent repository
without any indication for the user.

Fix this problem by dying early with an error message when we are
unable to write the configuration files to disk.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoclone: die on config error in cmd_clone
Patrick Steinhardt [Mon, 22 Feb 2016 11:23:31 +0000 (12:23 +0100)] 
clone: die on config error in cmd_clone

The clone command does not check for error codes returned by
`git_config_set` functions. This may cause the user to end up
with an inconsistent repository without any indication with what
went wrong.

Fix this problem by dying with an error message when we are
unable to write the configuration files to disk.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoremote: die on config error when manipulating remotes
Patrick Steinhardt [Mon, 22 Feb 2016 11:23:30 +0000 (12:23 +0100)] 
remote: die on config error when manipulating remotes

When manipulating remotes we try to set various configuration
values without checking if the values were persisted correctly,
possibly leaving the remote in an inconsistent state.

Fix this issue by dying early and notifying the user about the
error.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoremote: die on config error when setting/adding branches
Patrick Steinhardt [Mon, 22 Feb 2016 11:23:29 +0000 (12:23 +0100)] 
remote: die on config error when setting/adding branches

When we add or set new branches (e.g. by `git remote add -f` or
`git remote set-branches`) we do not check for error codes when
writing the branches to the configuration file. When persisting
the configuration failed we are left with a remote that has none
or not all of the branches that should have been set without
notifying the user.

Fix this issue by dying early on configuration error.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoremote: die on config error when setting URL
Patrick Steinhardt [Mon, 22 Feb 2016 11:23:28 +0000 (12:23 +0100)] 
remote: die on config error when setting URL

When invoking `git-remote --set-url` we do not check the return
value when writing the actual new URL to the configuration file,
pretending to the user that the configuration has been set while
it was in fact not persisted.

Fix this problem by dying early when setting the config fails.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agosubmodule--helper: die on config error when cloning module
Patrick Steinhardt [Mon, 22 Feb 2016 11:23:27 +0000 (12:23 +0100)] 
submodule--helper: die on config error when cloning module

When setting the 'core.worktree' option for a newly cloned
submodule we ignore the return value of `git_config_set_in_file`.
As this leaves the submodule in an inconsistent state, we instead
want to inform the user that something has gone wrong by printing
an error and aborting the program.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agosubmodule: die on config error when linking modules
Patrick Steinhardt [Mon, 22 Feb 2016 11:23:26 +0000 (12:23 +0100)] 
submodule: die on config error when linking modules

When trying to connect a submodule with its corresponding
repository in '.git/modules' we try to set the core.worktree
setting in the submodule, which may fail due to an error
encountered in `git_config_set_in_file`.

The function is used in the git-mv command when trying to move a
submodule to another location. We already die when renaming a
file fails but do not pay attention to the case where updating
the connection between submodule and its repository fails. As
this leaves the repository in an inconsistent state, as well,
abort the program by dying early and presenting the failure to
the user.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agobranch: die on config error when editing branch description
Patrick Steinhardt [Mon, 22 Feb 2016 11:23:25 +0000 (12:23 +0100)] 
branch: die on config error when editing branch description

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agobranch: die on config error when unsetting upstream
Patrick Steinhardt [Mon, 22 Feb 2016 11:23:24 +0000 (12:23 +0100)] 
branch: die on config error when unsetting upstream

When we try to unset upstream configurations we do not check
return codes for the `git_config_set` functions. As those may
indicate that we were unable to unset the respective
configuration we may exit successfully without any error message
while in fact the upstream configuration was not unset.

Fix this by dying with an error message when we cannot unset the
configuration.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agobranch: report errors in tracking branch setup
Patrick Steinhardt [Mon, 22 Feb 2016 11:23:23 +0000 (12:23 +0100)] 
branch: report errors in tracking branch setup

When setting up a new tracking branch fails due to issues with
the configuration file we do not report any errors to the user
and pretend setting the tracking branch succeeded.

Setting up the tracking branch is handled by the
`install_branch_config` function. We do not want to simply die
there as the function is not only invoked when explicitly setting
upstream information with `git branch --set-upstream-to=`, but
also by `git push --set-upstream` and `git clone`. While it is
reasonable to die in the explict first case, we would lose
information in the latter two cases, so we only print the error
message but continue the program as usual.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoconfig: add '--show-origin' option to print the origin of a config value
Lars Schneider [Fri, 19 Feb 2016 09:16:02 +0000 (10:16 +0100)] 
config: add '--show-origin' option to print the origin of a config value

If config values are queried using 'git config' (e.g. via --get,
--get-all, --get-regexp, or --list flag) then it is sometimes hard to
find the configuration file where the values were defined.

Teach 'git config' the '--show-origin' option to print the source
configuration file for every printed value.

Based-on-patch-by: Jeff King <peff@peff.net>
Signed-off-by: Lars Schneider <larsxschneider@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoconfig: add 'origin_type' to config_source struct
Lars Schneider [Fri, 19 Feb 2016 09:16:01 +0000 (10:16 +0100)] 
config: add 'origin_type' to config_source struct

Use the config origin_type to print more detailed error messages that
inform the user about the origin of a config error (file, stdin, blob).

Helped-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
Signed-off-by: Lars Schneider <larsxschneider@gmail.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agogit.c: simplify stripping extension of a file in handle_builtin()
Alexander Kuleshov [Mon, 22 Feb 2016 07:18:29 +0000 (13:18 +0600)] 
git.c: simplify stripping extension of a file in handle_builtin()

The handle_builtin() starts from stripping of command extension if
STRIP_EXTENSION is enabled. Actually STRIP_EXTENSION does not used
anywhere else.

This patch introduces strip_extension() helper to strip STRIP_EXTENSION
extension from argv[0] with the strip_suffix() instead of manually
stripping.

Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agogit-svn: apply "svn.pathnameencoding" before URL encoding
Kazutoshi Satoda [Mon, 8 Feb 2016 15:21:02 +0000 (00:21 +0900)] 
git-svn: apply "svn.pathnameencoding" before URL encoding

The conversion from "svn.pathnameencoding" to UTF-8 should be applied
first, and then URL encoding should be applied on the resulting UTF-8
path. The reversed order of these transforms (used before this fix)
makes non-UTF-8 URL which causes error from Subversion such as
"Filesystem has no item: '...' path not found" when sending a rename (or
a copy) from non-ASCII path.

[ew: t9115 test case added (requires SVN_HTTPD_PORT set to test),
 squash LC_ALL=$a_utf8_locale export from Kazutoshi for Cygwin]

Signed-off-by: Kazutoshi SATODA <k_satoda@f2.dion.ne.jp>
Signed-off-by: Eric Wong <normalperson@yhbt.net>
8 years agogit-svn: enable "svn.pathnameencoding" on dcommit
Kazutoshi Satoda [Mon, 8 Feb 2016 15:20:31 +0000 (00:20 +0900)] 
git-svn: enable "svn.pathnameencoding" on dcommit

Without the initialization of $self->{pathnameencoding}, conversion in
repo_path() is always skipped as $self->{pathnameencoding} is undefined
even if "svn.pathnameencoding" is configured.

The lack of conversion results in mysterious failure of dcommit (e.g.
"Malformed XML") which happen only when a commit involves a change on
non-ASCII path.

[ew: add test case to t9115,
 squash LC_ALL=$a_utf8_locale export from Kazutoshi for Cygwin]

Signed-off-by: Kazutoshi SATODA <k_satoda@f2.dion.ne.jp>
Signed-off-by: Eric Wong <normalperson@yhbt.net>
8 years agogit-svn: hoist out utf8 prep from t9129 to lib-git-svn
Eric Wong [Mon, 22 Feb 2016 02:17:51 +0000 (02:17 +0000)] 
git-svn: hoist out utf8 prep from t9129 to lib-git-svn

We will be reusing this in t9115.

Suggested-by: Kazutoshi Satoda <k_satoda@f2.dion.ne.jp>
Signed-off-by: Eric Wong <normalperson@yhbt.net>
8 years agotests: rename work-tree tests to *work-tree*
Michael J Gruber [Sat, 20 Feb 2016 16:18:41 +0000 (17:18 +0100)] 
tests: rename work-tree tests to *work-tree*

"Work tree" or "working tree" is the name of a checked out tree,
"worktree" the name of the command which manages several working trees.
The naming of tests mixes these two, currently:

$ls t/*worktree*
t/t1501-worktree.sh
t/t1509-root-worktree.sh
t/t2025-worktree-add.sh
t/t2026-worktree-prune.sh
t/t2027-worktree-list.sh
t/t2104-update-index-skip-worktree.sh
t/t3320-notes-merge-worktrees.sh
t/t7011-skip-worktree-reading.sh
t/t7012-skip-worktree-writing.sh
t/t7409-submodule-detached-worktree.sh

$grep -l "git worktree" t/*.sh
t/t0002-gitfile.sh
t/t1400-update-ref.sh
t/t2025-worktree-add.sh
t/t2026-worktree-prune.sh
t/t2027-worktree-list.sh
t/t3320-notes-merge-worktrees.sh
t/t7410-submodule-checkout-to.sh

Rename t1501, t1509 and t7409 to make it clear on first glance that they
test work tree related behavior, rather than the worktree command.

t2104, t7011 and t7012 are about the "skip-worktree" flag so that their
name should remain unchanged.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoexec_cmd.c: use find_last_dir_sep() for code simplification
Alexander Kuleshov [Fri, 19 Feb 2016 08:44:48 +0000 (14:44 +0600)] 
exec_cmd.c: use find_last_dir_sep() for code simplification

We are trying to extract dirname from argv0 in the git_extract_argv0_path().
But in the same time, the <git-compat-util.h> provides find_last_dir_sep()
to get dirname from a given path.  Let's use it instead of loop for the code
simplification.

Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agorename git_config_from_buf to git_config_from_mem
Lars Schneider [Fri, 19 Feb 2016 09:16:00 +0000 (10:16 +0100)] 
rename git_config_from_buf to git_config_from_mem

This matches the naming used in the index_{fd,mem,...} functions.

Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Lars Schneider <larsxschneider@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agotree-diff: catch integer overflow in combine_diff_path allocation
Jeff King [Fri, 19 Feb 2016 11:21:30 +0000 (06:21 -0500)] 
tree-diff: catch integer overflow in combine_diff_path allocation

A combine_diff_path struct has two "flex" members allocated
alongside the struct: a string to hold the pathname, and an
array of parent pointers. We use an "int" to compute this,
meaning we may easily overflow it if the pathname is
extremely long.

We can fix this by using size_t, and checking for overflow
with the st_add helper.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoadd helpers for detecting size_t overflow
Jeff King [Fri, 19 Feb 2016 11:21:19 +0000 (06:21 -0500)] 
add helpers for detecting size_t overflow

Performing computations on size_t variables that we feed to
xmalloc and friends can be dangerous, as an integer overflow
can cause us to allocate a much smaller chunk than we
realized.

We already have unsigned_add_overflows(), but let's add
unsigned_mult_overflows() to that. Furthermore, rather than
have each site manually check and die on overflow, we can
provide some helpers that will:

  - promote the arguments to size_t, so that we know we are
    doing our computation in the same size of integer that
    will ultimately be fed to xmalloc

  - check and die on overflow

  - return the result so that computations can be done in
    the parameter list of xmalloc.

These functions are a lot uglier to use than normal
arithmetic operators (you have to do "st_add(foo, bar)"
instead of "foo + bar"). To at least limit the damage, we
also provide multi-valued versions. So rather than:

  st_add(st_add(a, b), st_add(c, d));

you can write:

  st_add4(a, b, c, d);

This isn't nearly as elegant as a varargs function, but it's
a lot harder to get it wrong. You don't have to remember to
add a sentinel value at the end, and the compiler will
complain if you get the number of arguments wrong. This
patch adds only the numbered variants required to convert
the current code base; we can easily add more later if
needed.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoreflog_expire_cfg: NUL-terminate pattern field
Jeff King [Fri, 19 Feb 2016 11:21:08 +0000 (06:21 -0500)] 
reflog_expire_cfg: NUL-terminate pattern field

You can tweak the reflog expiration for a particular subset
of refs by configuring gc.foo.reflogexpire. We keep a linked
list of reflog_expire_cfg structs, each of which holds the
pattern and a "len" field for the length of the pattern. The
pattern itself is _not_ NUL-terminated.

However, we feed the pattern directly to wildmatch(), which
expects a NUL-terminated string, meaning it may keep reading
random junk after our struct.

We can fix this by allocating an extra byte for the NUL
(which is already zero because we use xcalloc). Let's also
drop the misleading "len" field, which is no longer
necessary. The existing use of "len" can be converted to use
strncmp().

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoref-filter: introduce objectname_atom_parser()
Karthik Nayak [Wed, 17 Feb 2016 18:06:19 +0000 (23:36 +0530)] 
ref-filter: introduce objectname_atom_parser()

Introduce objectname_atom_parser() which will parse the
'%(objectname)' atom and store information into the 'used_atom'
structure based on the modifiers used along with the atom.

Helped-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Karthik Nayak <Karthik.188@gmail.com>
Reviewed-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 years agoref-filter: introduce contents_atom_parser()
Karthik Nayak [Wed, 17 Feb 2016 18:06:18 +0000 (23:36 +0530)] 
ref-filter: introduce contents_atom_parser()

Introduce contents_atom_parser() which will parse the '%(contents)'
atom and store information into the 'used_atom' structure based on the
modifiers used along with the atom. Also introduce body_atom_parser()
and subject_atom_parser() for parsing atoms '%(body)' and '%(subject)'
respectively.

Helped-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Karthik Nayak <Karthik.188@gmail.com>
Reviewed-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>