gitweb.git
t5533: make it pass on case-sensitive filesystemsJohannes Schindelin Thu, 4 Aug 2016 14:54:35 +0000 (16:54 +0200)

t5533: make it pass on case-sensitive filesystems

The newly-added test case wants to commit a file "c.t" (note the lower
case) when a previous test case already committed a file "C.t". This
confuses Git to the point that it thinks "c.t" was not staged when "git
add c.t" was called.

Simply make the naming of the test commits consistent with the previous
test cases: use upper-case, and advance in the alphabet.

This came up in local work to rebase the Windows-specific patches to the
current `next` branch. An identical fix was suggested by John Keeping.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

push: allow pushing new branches with --force-with... John Keeping Tue, 26 Jul 2016 20:44:45 +0000 (21:44 +0100)

push: allow pushing new branches with --force-with-lease

If there is no upstream information for a branch, it is likely that it
is newly created and can safely be pushed under the normal fast-forward
rules. Relax the --force-with-lease check so that we do not reject
these branches immediately but rather attempt to push them as new
branches, using the null SHA-1 as the expected value.

In fact, it is already possible to push new branches using the explicit
--force-with-lease=<branch>:<expect> syntax, so all we do here is make
this behaviour the default if no explicit "expect" value is specified.

Signed-off-by: John Keeping <john@keeping.me.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

push: add shorthand for --force-with-lease branch creationJohn Keeping Tue, 26 Jul 2016 20:44:44 +0000 (21:44 +0100)

push: add shorthand for --force-with-lease branch creation

Allow the empty string to stand in for the null SHA-1 when pushing a new
branch, like we do when deleting branches.

This means that the following command ensures that `new-branch` is
created on the remote (that is, is must not already exist):

git push --force-with-lease=new-branch: origin new-branch

Signed-off-by: John Keeping <john@keeping.me.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

Documentation/git-push: fix placeholder formattingJohn Keeping Mon, 25 Jul 2016 21:59:55 +0000 (22:59 +0100)

Documentation/git-push: fix placeholder formatting

Format the placeholder as monospace to match other occurrences in this
file and obey CodingGuidelines.

Signed-off-by: John Keeping <john@keeping.me.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

Merge branch 'jk/war-on-sprintf' into maint-2.7Junio C Hamano Thu, 26 May 2016 17:45:37 +0000 (10:45 -0700)

Merge branch 'jk/war-on-sprintf' into maint-2.7

* jk/war-on-sprintf:
archive-tar: convert snprintf to xsnprintf

archive-tar: convert snprintf to xsnprintfJeff King Thu, 26 May 2016 04:28:08 +0000 (00:28 -0400)

archive-tar: convert snprintf to xsnprintf

Commit f2f0267 (archive-tar: use xsnprintf for trivial
formatting, 2015-09-24) converted cases of "sprintf" to
"xsnprintf", but accidentally left one as just "snprintf".
This meant that we could silently truncate the resulting
buffer instead of flagging an error.

In practice, this is impossible to achieve, as we are
formatting a ustar checksum, which can be at most 7
characters. But the point of xsnprintf is to document and
check for "should be impossible" conditions; this site was
just accidentally mis-converted during f2f0267.

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

Merge branch 'mm/doc-hooks-linkgit-fix' into maintJunio C Hamano Mon, 21 Mar 2016 20:32:18 +0000 (13:32 -0700)

Merge branch 'mm/doc-hooks-linkgit-fix' into maint

* mm/doc-hooks-linkgit-fix:
Documentation: fix broken linkgit to git-config

Documentation: fix broken linkgit to git-configMatthieu Moy Mon, 21 Mar 2016 18:38:34 +0000 (19:38 +0100)

Documentation: fix broken linkgit to git-config

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

Merge branch 'es/st-add4-gcc-4.2-workaround' into maintJunio C Hamano Mon, 21 Mar 2016 16:19:27 +0000 (09:19 -0700)

Merge branch 'es/st-add4-gcc-4.2-workaround' into maint

* es/st-add4-gcc-4.2-workaround:
git-compat-util: st_add4: work around gcc 4.2.x compiler crash

git-compat-util: st_add4: work around gcc 4.2.x compile... Eric Sunshine Mon, 21 Mar 2016 04:35:57 +0000 (00:35 -0400)

git-compat-util: st_add4: work around gcc 4.2.x compiler crash

Although changes by 5b442c4 (tree-diff: catch integer overflow in
combine_diff_path allocation, 2016-02-19) are perfectly valid, they
unfortunately trigger an internal compiler error in gcc 4.2.x:

combine-diff.c: In function 'diff_tree_combined':
combine-diff.c:1391: internal compiler error: Segmentation fault: 11

Experimentation reveals that changing st_add4()'s argument evaluation
order is sufficient to sidestep this problem.

Although st_add3() does not trigger the compiler bug, for style
consistency, change its argument evaluation order to match.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

Git 2.7.4 v2.7.4Junio C Hamano Thu, 17 Mar 2016 18:32:13 +0000 (11:32 -0700)

Git 2.7.4

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

Sync with Git 2.6.6Junio C Hamano Thu, 17 Mar 2016 18:28:52 +0000 (11:28 -0700)

Sync with Git 2.6.6

* maint-2.6:
Git 2.6.6
Git 2.5.5
Git 2.4.11

Git 2.6.6 v2.6.6Junio C Hamano Thu, 17 Mar 2016 17:56:06 +0000 (10:56 -0700)

Git 2.6.6

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

Merge branch 'maint-2.5' into maint-2.6Junio C Hamano Thu, 17 Mar 2016 18:26:18 +0000 (11:26 -0700)

Merge branch 'maint-2.5' into maint-2.6

* maint-2.5:
Git 2.5.5
Git 2.4.11
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
tree-diff: catch integer overflow in combine_diff_path allocation
add helpers for detecting size_t overflow

Git 2.5.5 v2.5.5Junio C Hamano Thu, 17 Mar 2016 17:28:50 +0000 (10:28 -0700)

Git 2.5.5

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

Merge branch 'maint-2.4' into maint-2.5Junio C Hamano Thu, 17 Mar 2016 18:24:14 +0000 (11:24 -0700)

Merge branch 'maint-2.4' into maint-2.5

* maint-2.4:
Git 2.4.11
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
tree-diff: catch integer overflow in combine_diff_path allocation
add helpers for detecting size_t overflow

Git 2.4.11 v2.4.11Junio C Hamano Thu, 17 Mar 2016 17:00:44 +0000 (10:00 -0700)

Git 2.4.11

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

Merge branch 'jk/path-name-safety-2.4' into maint-2.4Junio C Hamano Thu, 17 Mar 2016 16:55:54 +0000 (09:55 -0700)

Merge branch 'jk/path-name-safety-2.4' into maint-2.4

Bugfix patches were backported from the 'master' front to plug heap
corruption holes, to catch integer overflow in the computation of
pathname lengths, and to get rid of the name_path API. Both of
these would have resulted in writing over an under-allocated buffer
when formulating pathnames while tree traversal.

* jk/path-name-safety-2.4:
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
tree-diff: catch integer overflow in combine_diff_path allocation
add helpers for detecting size_t overflow

Merge branch 'jk/path-name-safety-2.7' into maintJunio C Hamano Wed, 16 Mar 2016 20:15:04 +0000 (13:15 -0700)

Merge branch 'jk/path-name-safety-2.7' into maint

* jk/path-name-safety-2.7:
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
tree-diff: catch integer overflow in combine_diff_path allocation
add helpers for detecting size_t overflow

Merge branch 'jk/path-name-safety-2.6' into jk/path... Junio C Hamano Wed, 16 Mar 2016 17:42:32 +0000 (10:42 -0700)

Merge branch 'jk/path-name-safety-2.6' into jk/path-name-safety-2.7

* jk/path-name-safety-2.6:
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
tree-diff: catch integer overflow in combine_diff_path allocation
add helpers for detecting size_t overflow

Merge branch 'jk/path-name-safety-2.5' into jk/path... Junio C Hamano Wed, 16 Mar 2016 17:42:02 +0000 (10:42 -0700)

Merge branch 'jk/path-name-safety-2.5' into jk/path-name-safety-2.6

* jk/path-name-safety-2.5:
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
tree-diff: catch integer overflow in combine_diff_path allocation
add helpers for detecting size_t overflow

Merge branch 'jk/path-name-safety-2.4' into jk/path... Junio C Hamano Wed, 16 Mar 2016 17:41:43 +0000 (10:41 -0700)

Merge branch 'jk/path-name-safety-2.4' into jk/path-name-safety-2.5

* jk/path-name-safety-2.4:
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
tree-diff: catch integer overflow in combine_diff_path allocation
add helpers for detecting size_t overflow

list-objects: pass full pathname to callbacksJeff King Thu, 11 Feb 2016 22:28:36 +0000 (17:28 -0500)

list-objects: pass full pathname to callbacks

When we find a blob at "a/b/c", we currently pass this to
our show_object_fn callbacks as two components: "a/b/" and
"c". Callbacks which want the full value then call
path_name(), which concatenates the two. But this is an
inefficient interface; the path is a strbuf, and we could
simply append "c" to it temporarily, then roll back the
length, without creating a new copy.

So we could improve this by teaching the callsites of
path_name() this trick (and there are only 3). But we can
also notice that no callback actually cares about the
broken-down representation, and simply pass each callback
the full path "a/b/c" as a string. The callback code becomes
even simpler, then, as we do not have to worry about freeing
an allocated buffer, nor rolling back our modification to
the strbuf.

This is theoretically less efficient, as some callbacks
would not bother to format the final path component. But in
practice this is not measurable. Since we use the same
strbuf over and over, our work to grow it is amortized, and
we really only pay to memcpy a few bytes.

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

list-objects: drop name_path entirelyJeff King Thu, 11 Feb 2016 22:26:44 +0000 (17:26 -0500)

list-objects: drop name_path entirely

In the previous commit, we left name_path as a thin wrapper
around a strbuf. This patch drops it entirely. As a result,
every show_object_fn callback needs to be adjusted. However,
none of their code needs to be changed at all, because the
only use was to pass it to path_name(), which now handles
the bare strbuf.

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

list-objects: convert name_path to a strbufJeff King Thu, 11 Feb 2016 22:26:18 +0000 (17:26 -0500)

list-objects: convert name_path to a strbuf

The "struct name_path" data is examined in only two places:
we generate it in process_tree(), and we convert it to a
single string in path_name(). Everyone else just passes it
through to those functions.

We can further note that process_tree() already keeps a
single strbuf with the leading tree path, for use with
tree_entry_interesting().

Instead of building a separate name_path linked list, let's
just use the one we already build in "base". This reduces
the amount of code (especially tricky code in path_name()
which did not check for integer overflows caused by deep
or large pathnames).

It is also more efficient in some instances. Any time we
were using tree_entry_interesting, we were building up the
strbuf anyway, so this is an immediate and obvious win
there. In cases where we were not, we trade off storing
"pathname/" in a strbuf on the heap for each level of the
path, instead of two pointers and an int on the stack (with
one pointer into the tree object). On a 64-bit system, the
latter is 20 bytes; so if path components are less than that
on average, this has lower peak memory usage. In practice
it probably doesn't matter either way; we are already
holding in memory all of the tree objects leading up to each
pathname, and for normal-depth pathnames, we are only
talking about hundreds of bytes.

This patch leaves "struct name_path" as a thin wrapper
around the strbuf, to avoid disrupting callbacks. We should
fix them, but leaving it out makes this diff easier to view.

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

show_object_with_name: simplify by using path_name()Jeff King Thu, 11 Feb 2016 22:24:18 +0000 (17:24 -0500)

show_object_with_name: simplify by using path_name()

When "git rev-list" shows an object with its associated path
name, it does so by walking the name_path linked list and
printing each component (stopping at any embedded NULs or
newlines).

We'd like to eventually get rid of name_path entirely in
favor of a single buffer, and dropping this custom printing
code is part of that. As a first step, let's use path_name()
to format the list into a single buffer, and print that.
This is strictly less efficient than the original, but it's
a temporary step in the refactoring; our end game will be to
get the fully formatted name in the first place.

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

add helpers for detecting size_t overflowJeff 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>

http-push: stop using name_pathJeff King Thu, 11 Feb 2016 22:23:48 +0000 (17:23 -0500)

http-push: stop using name_path

The graph traversal code here passes along a name_path to
build up the pathname at which we find each blob. But we
never actually do anything with the resulting names, making
it a waste of code and memory.

This usage came in aa1dbc9 (Update http-push functionality,
2006-03-07), and originally the result was passed to
"add_object" (which stored it, but didn't really use it,
either). But we stopped using that function in 1f1e895 (Add
"named object array" concept, 2006-06-19) in favor of
storing just the objects themselves.

Moreover, the generation of the name in process_tree() is
buggy. It sticks "name" onto the end of the name_path linked
list, and then passes it down again as it recurses (instead
of "entry.path"). So it's a good thing this was unused, as
the resulting path for "a/b/c/d" would end up as "a/a/a/a".

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

tree-diff: catch integer overflow in combine_diff_path... 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>

Git 2.7.3 v2.7.3Junio C Hamano Thu, 10 Mar 2016 19:13:13 +0000 (11:13 -0800)

Git 2.7.3

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

Merge branch 'ma/update-hooks-sample-typofix' into... Junio C Hamano Thu, 10 Mar 2016 19:13:50 +0000 (11:13 -0800)

Merge branch 'ma/update-hooks-sample-typofix' into maint

* ma/update-hooks-sample-typofix:
templates/hooks: fix minor typo in the sample update-hook

Merge branch 'dt/initial-ref-xn-commit-doc' into maintJunio C Hamano Thu, 10 Mar 2016 19:13:49 +0000 (11:13 -0800)

Merge branch 'dt/initial-ref-xn-commit-doc' into maint

* dt/initial-ref-xn-commit-doc:
refs: document transaction semantics

Merge branch 'ps/plug-xdl-merge-leak' into maintJunio C Hamano Thu, 10 Mar 2016 19:13:49 +0000 (11:13 -0800)

Merge branch 'ps/plug-xdl-merge-leak' into maint

* ps/plug-xdl-merge-leak:
xdiff/xmerge: fix memory leak in xdl_merge

Merge branch 'ak/git-strip-extension-from-dashed-comman... Junio C Hamano Thu, 10 Mar 2016 19:13:48 +0000 (11:13 -0800)

Merge branch 'ak/git-strip-extension-from-dashed-command' into maint

Code simplification.

* ak/git-strip-extension-from-dashed-command:
git.c: simplify stripping extension of a file in handle_builtin()

Merge branch 'ak/extract-argv0-last-dir-sep' into maintJunio C Hamano Thu, 10 Mar 2016 19:13:47 +0000 (11:13 -0800)

Merge branch 'ak/extract-argv0-last-dir-sep' into maint

Code simplification.

* ak/extract-argv0-last-dir-sep:
exec_cmd.c: use find_last_dir_sep() for code simplification

Merge branch 'jk/pack-idx-corruption-safety' into maintJunio C Hamano Thu, 10 Mar 2016 19:13:46 +0000 (11:13 -0800)

Merge branch 'jk/pack-idx-corruption-safety' into maint

The code to read the pack data using the offsets stored in the pack
idx file has been made more carefully check the validity of the
data in the idx.

* jk/pack-idx-corruption-safety:
sha1_file.c: mark strings for translation
use_pack: handle signed off_t overflow
nth_packed_object_offset: bounds-check extended offset
t5313: test bounds-checks of corrupted/malicious pack/idx files

Merge branch 'js/config-set-in-non-repository' into... Junio C Hamano Thu, 10 Mar 2016 19:13:45 +0000 (11:13 -0800)

Merge branch 'js/config-set-in-non-repository' into maint

"git config section.var value" to set a value in per-repository
configuration file failed when it was run outside any repository,
but didn't say the reason correctly.

* js/config-set-in-non-repository:
git config: report when trying to modify a non-existing repo config

Merge branch 'sb/submodule-module-list-fix' into maintJunio C Hamano Thu, 10 Mar 2016 19:13:45 +0000 (11:13 -0800)

Merge branch 'sb/submodule-module-list-fix' into maint

A helper function "git submodule" uses since v2.7.0 to list the
modules that match the pathspec argument given to its subcommands
(e.g. "submodule add <repo> <path>") has been fixed.

* sb/submodule-module-list-fix:
submodule helper list: respect correct path prefix

Merge branch 'jk/grep-binary-workaround-in-test' into... Junio C Hamano Thu, 10 Mar 2016 19:13:45 +0000 (11:13 -0800)

Merge branch 'jk/grep-binary-workaround-in-test' into maint

Recent versions of GNU grep are pickier when their input contains
arbitrary binary data, which some of our tests uses. Rewrite the
tests to sidestep the problem.

* jk/grep-binary-workaround-in-test:
t9200: avoid grep on non-ASCII data
t8005: avoid grep on non-ASCII data

Merge branch 'mm/push-simple-doc' into maintJunio C Hamano Thu, 10 Mar 2016 19:13:44 +0000 (11:13 -0800)

Merge branch 'mm/push-simple-doc' into maint

The documentation did not clearly state that the 'simple' mode is
now the default for "git push" when push.default configuration is
not set.

* mm/push-simple-doc:
Documentation/git-push: document that 'simple' is the default

Merge branch 'jk/tighten-alloc' into maintJunio C Hamano Thu, 10 Mar 2016 19:13:43 +0000 (11:13 -0800)

Merge branch 'jk/tighten-alloc' into maint

* jk/tighten-alloc: (23 commits)
compat/mingw: brown paper bag fix for 50a6c8e
ewah: convert to REALLOC_ARRAY, etc
convert ewah/bitmap code to use xmalloc
diff_populate_gitlink: use a strbuf
transport_anonymize_url: use xstrfmt
git-compat-util: drop mempcpy compat code
sequencer: simplify memory allocation of get_message
test-path-utils: fix normalize_path_copy output buffer size
fetch-pack: simplify add_sought_entry
fast-import: simplify allocation in start_packfile
write_untracked_extension: use FLEX_ALLOC helper
prepare_{git,shell}_cmd: use argv_array
use st_add and st_mult for allocation size computation
convert trivial cases to FLEX_ARRAY macros
use xmallocz to avoid size arithmetic
convert trivial cases to ALLOC_ARRAY
convert manual allocations to argv_array
argv-array: add detach function
add helpers for allocating flex-array structs
harden REALLOC_ARRAY and xcalloc against size_t overflow
...

Merge branch 'jk/more-comments-on-textconv' into maintJunio C Hamano Thu, 10 Mar 2016 19:13:42 +0000 (11:13 -0800)

Merge branch 'jk/more-comments-on-textconv' into maint

The memory ownership rule of fill_textconv() API, which was a bit
tricky, has been documented a bit better.

* jk/more-comments-on-textconv:
diff: clarify textconv interface

Merge branch 'jk/no-diff-emit-common' into maintJunio C Hamano Thu, 10 Mar 2016 19:13:41 +0000 (11:13 -0800)

Merge branch 'jk/no-diff-emit-common' into maint

"git merge-tree" used to mishandle "both sides added" conflict with
its own "create a fake ancestor file that has the common parts of
what both sides have added and do a 3-way merge" logic; this has
been updated to use the usual "3-way merge with an empty blob as
the fake common ancestor file" approach used in the rest of the
system.

* jk/no-diff-emit-common:
xdiff: drop XDL_EMIT_COMMON
merge-tree: drop generate_common strategy
merge-one-file: use empty blob for add/add base

Merge branch 'jc/am-i-v-fix' into maintJunio C Hamano Thu, 10 Mar 2016 19:13:40 +0000 (11:13 -0800)

Merge branch 'jc/am-i-v-fix' into maint

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[]

Merge branch 'nd/git-common-dir-fix' into maintJunio C Hamano Thu, 10 Mar 2016 19:13:39 +0000 (11:13 -0800)

Merge branch 'nd/git-common-dir-fix' into maint

"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

Merge branch 'nd/dwim-wildcards-as-pathspecs' into... Junio C Hamano Thu, 10 Mar 2016 19:13:39 +0000 (11:13 -0800)

Merge branch 'nd/dwim-wildcards-as-pathspecs' into maint

"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

Merge branch 'jk/epipe-in-async' into maintJunio C Hamano Thu, 10 Mar 2016 19:13:38 +0000 (11:13 -0800)

Merge branch 'jk/epipe-in-async' into maint

Handling of errors while writing into our internal asynchronous
process has been made more robust, which reduces flakiness in our
tests.

* jk/epipe-in-async:
t5504: handle expected output from SIGPIPE death
test_must_fail: report number of unexpected signal
fetch-pack: ignore SIGPIPE in sideband demuxer
write_or_die: handle EPIPE in async threads

Merge branch 'ps/config-error' into maintJunio C Hamano Thu, 10 Mar 2016 19:13:38 +0000 (11:13 -0800)

Merge branch 'ps/config-error' into maint

Many codepaths forget to check return value from git_config_set();
the function is made to die() to make sure we do not proceed when
setting a configuration variable failed.

* ps/config-error:
config: rename git_config_set_or_die to git_config_set
config: rename git_config_set to git_config_set_gently
compat: die when unable to set core.precomposeunicode
sequencer: die on config error when saving replay opts
init-db: die on config errors when initializing empty repo
clone: die on config error in cmd_clone
remote: die on config error when manipulating remotes
remote: die on config error when setting/adding branches
remote: die on config error when setting URL
submodule--helper: die on config error when cloning module
submodule: die on config error when linking modules
branch: die on config error when editing branch description
branch: die on config error when unsetting upstream
branch: report errors in tracking branch setup
config: introduce set_or_die wrappers

Merge branch 'mg/work-tree-tests' into maintJunio C Hamano Thu, 10 Mar 2016 19:13:38 +0000 (11:13 -0800)

Merge branch 'mg/work-tree-tests' into maint

Traditionally, the tests that try commands that work on the
contents in the working tree were named with "worktree" in their
filenames, but with the recent addition of "git worktree"
subcommand, whose tests are also named similarly, it has become
harder to tell them apart. The traditional tests have been renamed
to use "work-tree" instead in an attempt to differentiate them.

* mg/work-tree-tests:
tests: rename work-tree tests to *work-tree*

Merge branch 'sp/remote-curl-ssl-strerror' into maintJunio C Hamano Thu, 10 Mar 2016 19:13:37 +0000 (11:13 -0800)

Merge branch 'sp/remote-curl-ssl-strerror' into maint

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

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

compat/mingw: brown paper bag fix for 50a6c8eJeff King Mon, 29 Feb 2016 10:02:59 +0000 (05:02 -0500)

compat/mingw: brown paper bag fix for 50a6c8e

Commit 50a6c8e (use st_add and st_mult for allocation size
computation, 2016-02-22) fixed up many xmalloc call-sites
including ones in compat/mingw.c.

But I screwed up one of them, which was half-converted to
ALLOC_ARRAY, using a very early prototype of the function.
And I never caught it because I don't build on Windows.

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

sha1_file.c: mark strings for translationNguyễn Thái Ngọc Duy Sat, 27 Feb 2016 07:49:33 +0000 (14:49 +0700)

sha1_file.c: mark strings for translation

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

t5504: handle expected output from SIGPIPE deathJeff King Wed, 24 Feb 2016 07:48:36 +0000 (02:48 -0500)

t5504: handle expected output from SIGPIPE death

Commit 8bf4bec (add "ok=sigpipe" to test_must_fail and use
it to fix flaky tests, 2015-11-27) taught t5504 to handle
"git push" racily exiting with SIGPIPE rather than failing.

However, one of the tests checks the output of the command,
as well. In the SIGPIPE case, we will not have produced any
output. If we want the test to be truly non-flaky, we have
to accept either output.

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

test_must_fail: report number of unexpected signalJeff King Wed, 24 Feb 2016 07:45:49 +0000 (02:45 -0500)

test_must_fail: report number of unexpected signal

If a command is marked as test_must_fail but dies with a
signal, we consider that a problem and report the error to
stderr. However, we don't say _which_ signal; knowing that
can make debugging easier. Let's share as much as we know.

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

fetch-pack: ignore SIGPIPE in sideband demuxerJeff King Wed, 24 Feb 2016 07:44:58 +0000 (02:44 -0500)

fetch-pack: ignore SIGPIPE in sideband demuxer

If the other side feeds us a bogus pack, index-pack (or
unpack-objects) may die early, before consuming all of its
input. As a result, the sideband demuxer may get SIGPIPE
(racily, depending on whether our data made it into the pipe
buffer or not). If this happens and we are compiled with
pthread support, it will take down the main thread, too.

This isn't the end of the world, as the main process will
just die() anyway when it sees index-pack failed. But it
does mean we don't get a chance to say "fatal: index-pack
failed" or similar. And it also means that we racily fail
t5504, as we sometimes die() and sometimes are killed by
SIGPIPE.

So let's ignore SIGPIPE while demuxing the sideband. We are
already careful to check the return value of write(), so we
won't waste time writing to a broken pipe. The caller will
notice the error return from the async thread, though in
practice we don't even get that far, as we die() as soon as
we see that index-pack failed.

The non-sideband case is already fine; we let index-pack
read straight from the socket, so there is no SIGPIPE at
all. Technically the non-threaded async case is also OK
without this (the forked async process gets SIGPIPE), but
it's not worth distinguishing from the threaded case here.

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

write_or_die: handle EPIPE in async threadsJeff King Wed, 24 Feb 2016 07:40:16 +0000 (02:40 -0500)

write_or_die: handle EPIPE in async threads

When write_or_die() sees EPIPE, it treats it specially by
converting it into a SIGPIPE death. We obviously cannot
ignore it, as the write has failed and the caller expects us
to die. But likewise, we cannot just call die(), because
printing any message at all would be a nuisance during
normal operations.

However, this is a problem if write_or_die() is called from
a thread. Our raised signal ends up killing the whole
process, when logically we just need to kill the thread
(after all, if we are ignoring SIGPIPE, there is good reason
to think that the main thread is expecting to handle it).

Inside an async thread, the die() code already does the
right thing, because we use our custom die_async() routine,
which calls pthread_join(). So ideally we would piggy-back
on that, and simply call:

die_quietly_with_code(141);

or similar. But refactoring the die code to do this is
surprisingly non-trivial. The die_routines themselves handle
both printing and the decision of the exit code. Every one
of them would have to be modified to take new parameters for
the code, and to tell us to be quiet.

Instead, we can just teach write_or_die() to check for the
async case and handle it specially. We do have to build an
interface to abstract the async exit, but it's simple and
self-contained. If we had many call-sites that wanted to do
this die_quietly_with_code(), this approach wouldn't scale
as well, but we don't. This is the only place where do this
weird exit trick.

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

refs: document transaction semanticsDavid Turner Thu, 25 Feb 2016 20:05:46 +0000 (15:05 -0500)

refs: document transaction semantics

Add some comments on ref transaction semantics to refs.h

Signed-off-by: David Turner <dturner@twopensource.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

use_pack: handle signed off_t overflowJeff King Thu, 25 Feb 2016 14:23:26 +0000 (09:23 -0500)

use_pack: handle signed off_t overflow

A v2 pack index file can specify an offset within a packfile
of up to 2^64-1 bytes. On a system with a signed 64-bit
off_t, we can represent only up to 2^63-1. This means that a
corrupted .idx file can end up with a negative offset in the
pack code. Our bounds-checking use_pack function looks for
too-large offsets, but not for ones that have wrapped around
to negative. Let's do so, which fixes an out-of-bounds
access demonstrated in t5313.

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

nth_packed_object_offset: bounds-check extended offsetJeff King Thu, 25 Feb 2016 14:22:52 +0000 (09:22 -0500)

nth_packed_object_offset: bounds-check extended offset

If a pack .idx file has a corrupted offset for an object, we
may try to access an offset in the .idx or .pack file that
is larger than the file's size. For the .pack case, we have
use_pack() to protect us, which realizes the access is out
of bounds. But if the corrupted value asks us to look in the
.idx file's secondary 64-bit offset table, we blindly add it
to the mmap'd index data and access arbitrary memory.

We can fix this with a simple bounds-check compared to the
size we found when we opened the .idx file.

Note that there's similar code in index-pack that is
triggered only during "index-pack --verify". To support
both, we pull the bounds-check into a separate function,
which dies when it sees a corrupted file.

It would be nice if we could return an error, so that the
pack code could try to find a good copy of the object
elsewhere. Currently nth_packed_object_offset doesn't have
any way to return an error, but it could probably use "0" as
a sentinel value (since no object can start there). This is
the minimal fix, and we can improve the resilience later on
top.

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

t5313: test bounds-checks of corrupted/malicious pack... 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>

git config: report when trying to modify a non-existing... 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>

templates/hooks: fix minor typo in the sample update... 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>

submodule helper list: respect correct path prefixStefan 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>

t9200: avoid grep on non-ASCII dataJohn 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>

t8005: avoid grep on non-ASCII dataJohn 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>

Documentation/git-push: document that 'simple' is the... 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>

xdiff/xmerge: fix memory leak in xdl_mergePatrick 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>

xdiff: drop XDL_EMIT_COMMONJeff 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>

merge-tree: drop generate_common strategyJeff 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>

merge-one-file: use empty blob for add/add baseJeff 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>

ewah: convert to REALLOC_ARRAY, etcJeff 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>

convert ewah/bitmap code to use xmallocJeff 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>

diff_populate_gitlink: use a strbufJeff 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>

transport_anonymize_url: use xstrfmtJeff 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>

git-compat-util: drop mempcpy compat codeJeff 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>

sequencer: simplify memory allocation of get_messageJeff 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>

test-path-utils: fix normalize_path_copy output buffer... 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>

fetch-pack: simplify add_sought_entryJeff 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>

fast-import: simplify allocation in start_packfileJeff 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>

write_untracked_extension: use FLEX_ALLOC helperJeff 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>

prepare_{git,shell}_cmd: use argv_arrayJeff 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>

use st_add and st_mult for allocation size computationJeff 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>

convert trivial cases to FLEX_ARRAY macrosJeff 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>

use xmallocz to avoid size arithmeticJeff 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>

convert trivial cases to ALLOC_ARRAYJeff 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>

convert manual allocations to argv_arrayJeff 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>

argv-array: add detach functionJeff 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>

add helpers for allocating flex-array structsJeff 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>

harden REALLOC_ARRAY and xcalloc against size_t overflowJeff 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>

Git 2.7.2 v2.7.2Junio 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>

Merge branch 'nd/ita-cleanup' into maintJunio 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

Merge branch 'pw/completion-stash' into maintJunio 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()

Merge branch 'mm/clean-doc-fix' into maintJunio 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/*

Merge branch 'dw/mergetool-vim-window-shuffle' into... 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

Merge branch 'ah/stripspace-optstring' into maintJunio 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"

diff: clarify textconv interfaceJeff 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>

completion: 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>

config: rename git_config_set_or_die to git_config_setPatrick 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>

config: rename git_config_set to git_config_set_gentlyPatrick 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>

compat: die when unable to set core.precomposeunicodePatrick 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>