git
6 years agohash: create union for hash context allocation
brian m. carlson [Thu, 1 Feb 2018 02:18:38 +0000 (02:18 +0000)] 
hash: create union for hash context allocation

In various parts of our code, we want to allocate a structure
representing the internal state of a hash algorithm.  The original
implementation of the hash algorithm abstraction assumed we would do
that using heap allocations, and added a context size element to struct
git_hash_algo.  However, most of the existing code uses stack
allocations and conversion would needlessly complicate various parts of
the code.  Add a union for the purpose of allocating hash contexts on
the stack and a typedef for ease of use.  Use this union for defining
the init, update, and final functions to avoid casts.  Remove the ctxsz
element for struct git_hash_algo, which is no longer very useful.

This does mean that stack allocations will grow slightly as additional
hash functions are added, but this should not be a significant problem,
since we don't allocate many hash contexts.  The improved usability and
benefits from avoiding dynamic allocation outweigh this small downside.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agohash: move SHA-1 macros to hash.h
brian m. carlson [Thu, 1 Feb 2018 02:18:37 +0000 (02:18 +0000)] 
hash: move SHA-1 macros to hash.h

Most of the other code dealing with SHA-1 and other hashes is located in
hash.h, which is in turn loaded by cache.h.  Move the SHA-1 macros to
hash.h as well, so we can use them in additional hash-related items in
the future.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agotrace: measure where the time is spent in the index-heavy operations
Nguyễn Thái Ngọc Duy [Sat, 27 Jan 2018 12:27:56 +0000 (19:27 +0700)] 
trace: measure where the time is spent in the index-heavy operations

All the known heavy code blocks are measured (except object database
access). This should help identify if an optimization is effective or
not. An unoptimized git-status would give something like below:

    0.001791141 s: read cache ...
    0.004011363 s: preload index
    0.000516161 s: refresh index
    0.003139257 s: git command: ... 'status' '--porcelain=2'
    0.006788129 s: diff-files
    0.002090267 s: diff-index
    0.001885735 s: initialize name hash
    0.032013138 s: read directory
    0.051781209 s: git command: './git' 'status'

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agogitignore.txt: elaborate shell glob syntax
Duy Nguyen [Thu, 1 Feb 2018 09:59:15 +0000 (16:59 +0700)] 
gitignore.txt: elaborate shell glob syntax

`fnmatch(3)` is a great mention if the intended audience is
programmers. For normal users it's probably better to spell out what
a shell glob is.

This paragraph is updated to roughly tell (or remind) what the main
wildcards are supposed to do. All the details are still hidden away
behind the `fnmatch(3)` wall because bringing the whole specification
here may be too much.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoformat-patch: reduce patch diffstat width to 72
Nguyễn Thái Ngọc Duy [Thu, 1 Feb 2018 12:47:50 +0000 (19:47 +0700)] 
format-patch: reduce patch diffstat width to 72

Patches generated by format-patch are meant to be exchanged as emails,
most of the time. And since it's generally agreed that text in mails
should be wrapped around 70 columns or so, make sure these diffstat
follow the convention (especially when used with --cover-letter since we
already defaults to wrapping 72 columns). The default can still be
overriden with command line options.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agodir.c: stop ignoring opendir() error in open_cached_dir()
Nguyễn Thái Ngọc Duy [Wed, 24 Jan 2018 09:30:23 +0000 (16:30 +0700)] 
dir.c: stop ignoring opendir() error in open_cached_dir()

A follow-up to the recently fixed bugs in the untracked
invalidation. If opendir() fails it should show a warning, perhaps
this should die, but if this ever happens the error is probably
recoverable for the user, and dying would just make things worse.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agowildmatch test: mark test as EXPENSIVE_ON_WINDOWS
Ævar Arnfjörð Bjarmason [Tue, 30 Jan 2018 21:21:24 +0000 (21:21 +0000)] 
wildmatch test: mark test as EXPENSIVE_ON_WINDOWS

Mark the newly added test which creates test files on-disk as
EXPENSIVE_ON_WINDOWS. According to [1] it takes almost ten minutes to
run this test file on Windows after this recent change, but just a few
seconds on Linux as noted in my [2].

This could be done faster by exiting earlier, however by using this
pattern we'll emit "skip" lines for each skipped test, making it clear
we're not running a lot of them in the TAP output, at the cost of some
overhead.

1. nycvar.QRO.7.76.6.1801061337020.1337@wbunaarf-fpuvaqryva.tvgsbejvaqbjf.bet
   (https://public-inbox.org/git/nycvar.QRO.7.76.6.1801061337020.1337@wbunaarf-fpuvaqryva.tvgsbejvaqbjf.bet/)

2. 87mv1raz9p.fsf@evledraar.gmail.com
   (https://public-inbox.org/git/87mv1raz9p.fsf@evledraar.gmail.com/)

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agotest-lib: add an EXPENSIVE_ON_WINDOWS prerequisite
Ævar Arnfjörð Bjarmason [Tue, 30 Jan 2018 21:21:23 +0000 (21:21 +0000)] 
test-lib: add an EXPENSIVE_ON_WINDOWS prerequisite

Add an EXPENSIVE_ON_WINDOWS prerequisite to mark those tests which are
very expensive to run on Windows, but cheap elsewhere.

Certain tests that heavily stress the filesystem or run a lot of shell
commands are disproportionately expensive on Windows, this
prerequisite will later be used by a tests that runs in 4-8 seconds on
a modern Linux system, but takes almost 10 minutes on Windows.

There's no reason to skip such tests by default on other platforms,
but Windows users shouldn't need to wait around while they finish.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agowildmatch test: create & test files on disk in addition to in-memory
Ævar Arnfjörð Bjarmason [Tue, 30 Jan 2018 21:21:22 +0000 (21:21 +0000)] 
wildmatch test: create & test files on disk in addition to in-memory

There has never been any full roundtrip testing of what git-ls-files
and other commands that use wildmatch() actually do, rather we've been
satisfied with just testing the underlying C function.

Due to git-ls-files and friends having their own codepaths before they
call wildmatch() there's sometimes differences in the behavior between
the two. Even when we test for those (as with [1]), there was no one
place where you can review how these two modes differ.

Now there is. We now attempt to create a file called $haystack and
match $needle against it for each pair of $needle and $haystack that
we were passing to test-wildmatch.

If we can't create the file we skip the test. This ensures that we can
run this on all platforms and not maintain some infinitely growing
whitelist of e.g. platforms that don't support certain characters in
filenames.

A notable exception to this is Windows, where due to the reasons
explained in [2] the shellscript emulation layer might fake the
creation of a file such as "*", and "test -e" for it will succeed
since it just got created with some character that maps to "*", but
git ls-files won't be fooled by this.

Thus we need to skip creating certain filenames entirely on Windows,
the list here might be overly aggressive. I don't have access to a
Windows system to test this.

As a result of doing these tests we can now see the cases where these
two ways of testing wildmatch differ:

 * Creating a file called 'a[]b' and running ls-files 'a[]b' will show
   that file, but wildmatch("a[]b", "a[]b") will not match

 * wildmatch() won't match a file called \ against \, but ls-files
   will.

 * `git --glob-pathspecs ls-files 'foo**'` will match a file
   'foo/bba/arr', but wildmatch won't, however pathmatch will.

   This seems like a bug to me, the two are otherwise equivalent as
   these tests show.

This also reveals the case discussed in [1], since 2.16.0 '' is now an
error as far as ls-files is concerned, but wildmatch() itself happily
accepts it.

1. 9e4e8a64c2 ("pathspec: die on empty strings as pathspec",
   2017-06-06)

2. nycvar.QRO.7.76.6.1801052133380.1337@wbunaarf-fpuvaqryva.tvgsbejvaqbjf.bet
   (https://public-inbox.org/git/?q=nycvar.QRO.7.76.6.1801052133380.1337%40wbunaarf-fpuvaqryva.tvgsbejvaqbjf.bet)

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agowildmatch test: perform all tests under all wildmatch() modes
Ævar Arnfjörð Bjarmason [Tue, 30 Jan 2018 21:21:21 +0000 (21:21 +0000)] 
wildmatch test: perform all tests under all wildmatch() modes

Rewrite the wildmatch() test suite so that each test now tests all
combinations of the wildmatch() WM_CASEFOLD and WM_PATHNAME flags.

Before this change some test inputs were not tested on
e.g. WM_PATHNAME. Now the function is stress tested on all possible
inputs, and for each input we declare what the result should be if the
mode is case-insensitive, or pathname matching, or case-sensitive or
not matching pathnames.

Also before this change, nothing was testing case-insensitive
non-pathname matching, so I've added that to test-wildmatch.c and made
use of it.

This yields a rather scary patch, but there are no functional changes
here, just more test coverage. Some now-redundant tests were deleted
as a result of this change, since they were now duplicating an earlier
test.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agowildmatch test: use test_must_fail, not ! for test-wildmatch
Ævar Arnfjörð Bjarmason [Tue, 30 Jan 2018 21:21:20 +0000 (21:21 +0000)] 
wildmatch test: use test_must_fail, not ! for test-wildmatch

Use of ! should be reserved for non-git programs that are assumed not
to fail, see README. With this change only
t/t0110-urlmatch-normalization.sh is still using this anti-pattern.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agowildmatch test: remove dead fnmatch() test code
Ævar Arnfjörð Bjarmason [Tue, 30 Jan 2018 21:21:19 +0000 (21:21 +0000)] 
wildmatch test: remove dead fnmatch() test code

Remove the unused fnmatch() test parameter from the wildmatch
test. The code that used to test this was removed in 70a8fc999d ("stop
using fnmatch (either native or compat)", 2014-02-15).

As a --word-diff shows the only change to the body of the tests is the
removal of the second out of four parameters passed to match().

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agowildmatch test: use a paranoia pattern from nul_match()
Ævar Arnfjörð Bjarmason [Tue, 30 Jan 2018 21:21:18 +0000 (21:21 +0000)] 
wildmatch test: use a paranoia pattern from nul_match()

Use a pattern from the nul_match() function in t7008-grep-binary.sh to
make sure that we don't just fall through to the "else" if there's an
unknown parameter.

This is something I added in commit 77f6f4406f ("grep: add a test
helper function for less verbose -f \0 tests", 2017-05-20) to grep
tests, which were modeled on these wildmatch tests, and I'm now
porting back to the original wildmatch tests.

I am not using the "say '...'; exit 1" pattern from t0000-basic.sh
because if I fail I want to run the rest of the tests (unless under
-i), and doing this makes sure we do that and don't exit right away
without fully reporting our errors.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agowildmatch test: don't try to vertically align our output
Ævar Arnfjörð Bjarmason [Tue, 30 Jan 2018 21:21:17 +0000 (21:21 +0000)] 
wildmatch test: don't try to vertically align our output

Don't try to vertically align the test output, which is futile anyway
under the TAP output where we're going to be emitting a number for
each test without aligning the test count.

This makes subsequent changes of mine where I'm not going to be
aligning this output as I add new tests easier.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agowildmatch test: use more standard shell style
Ævar Arnfjörð Bjarmason [Tue, 30 Jan 2018 21:21:16 +0000 (21:21 +0000)] 
wildmatch test: use more standard shell style

Change the wildmatch test to use more standard shell style, usually we
use "if test" not "if [".

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agowildmatch test: indent with tabs, not spaces
Ævar Arnfjörð Bjarmason [Tue, 30 Jan 2018 21:21:15 +0000 (21:21 +0000)] 
wildmatch test: indent with tabs, not spaces

Replace the 4-width mixed space & tab indentation in this file with
indentation with tabs as we do in most of the rest of our tests.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agotravis-ci: don't fail if user already exists on 32 bit Linux build job
SZEDER Gábor [Mon, 29 Jan 2018 17:17:13 +0000 (18:17 +0100)] 
travis-ci: don't fail if user already exists on 32 bit Linux build job

The 32 bit Linux build job runs in a Docker container, which lends
itself to running and debugging locally, too.  Especially during
debugging one usually doesn't want to start with a fresh container
every time, to save time spent on installing a bunch of dependencies.
However, that doesn't work quite smootly, because the script running
in the container always creates a new user, which then must be removed
every time before subsequent executions, or the build script fails.

Make this process more convenient and don't try to create that user if
it already exists and has the right user ID in the container, so
developers don't have to bother with running a 'userdel' each time
before they run the build script.

The build job on Travis CI always starts with a fresh Docker
container, so this change doesn't make a difference there.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agotravis-ci: don't run the test suite as root in the 32 bit Linux build
SZEDER Gábor [Mon, 29 Jan 2018 17:17:12 +0000 (18:17 +0100)] 
travis-ci: don't run the test suite as root in the 32 bit Linux build

Travis CI runs the 32 bit Linux build job in a Docker container, where
all commands are executed as root by default.  Therefore, ever since
we added this build job in 88dedd5e7 (Travis: also test on 32-bit
Linux, 2017-03-05), we have a bit of code to create a user in the
container matching the ID of the host user and then to run the test
suite as this user.  Matching the host user ID is important, because
otherwise the host user would have no access to any files written by
processes running in the container, notably the logs of failed tests
couldn't be included in the build job's trace log.

Alas, this piece of code never worked, because it sets the variable
holding the user name ($CI_USER) in a subshell, meaning it doesn't
have any effect by the time we get to the point to actually use the
variable to switch users with 'su'.  So all this time we were running
the test suite as root.

Reorganize that piece of code in 'ci/run-linux32-build.sh' a bit to
avoid that problematic subshell and to ensure that we switch to the
right user.  Furthermore, make the script's optional host user ID
option mandatory, so running the build accidentally as root will
become harder when debugging locally.  If someone really wants to run
the test suite as root, whatever the reasons might be, it'll still be
possible to do so by explicitly passing '0' as host user ID.

Finally, one last catch: since commit 7e72cfcee (travis-ci: save prove
state for the 32 bit Linux build, 2017-12-27) the 'prove' test harness
has been writing its state to the Travis CI cache directory from
within the Docker container while running as root.  After this patch
'prove' will run as a regular user, so in future build jobs it won't
be able overwrite a previously written, still root-owned state file,
resulting in build job failures.  To resolve this we should manually
delete caches containing such root-owned files, but that would be a
hassle.  Instead, work this around by changing the owner of the whole
contents of the cache directory to the host user ID.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agotravis-ci: don't repeat the path of the cache directory
SZEDER Gábor [Mon, 29 Jan 2018 17:17:11 +0000 (18:17 +0100)] 
travis-ci: don't repeat the path of the cache directory

Some of our 'ci/*' scripts repeat the name or full path of the Travis
CI cache directory, and the following patches will add new places
using that path.

Use a variable to refer to the path of the cache directory instead, so
it's hard-coded only in a single place.

Pay extra attention to the 32 bit Linux build: it runs in a Docker
container, so pass the path of the cache directory from the host to
the container in an environment variable.  Note that an environment
variable passed this way is exported inside the container, therefore
its value is directly available in the 'su' snippet even though that
snippet is single quoted.  Furthermore, use the variable in the
container only if it's been assigned a non-empty value, to prevent
errors when someone is running or debugging the Docker build locally,
because in that case the variable won't be set as there won't be any
Travis CI cache.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agotravis-ci: use 'set -e' in the 32 bit Linux build job
SZEDER Gábor [Mon, 29 Jan 2018 17:17:10 +0000 (18:17 +0100)] 
travis-ci: use 'set -e' in the 32 bit Linux build job

The script 'ci/run-linux32-build.sh' running inside the Docker
container of the 32 bit Linux build job uses an && chain to break the
build if one of the commands fails.  This is problematic for two
reasons:

  - The && chain is broken, because there is this in the middle:

    test -z $HOST_UID || (CI_USER="ci" && useradd -u $HOST_UID $CI_USER) &&

    Luckily it is broken in a way that it didn't lead to false
    successes.  If installing dependencies fails, then the rest of the
    first && chain is skipped and execution resumes  after the ||
    operator.  At that point $HOST_UID is still unset, causing
    'useradd' to error out with "invalid user ID 'ci'", which in turn
    causes the second && chain to abort the script and thus break the
    build.

  - All other 'ci/*' scripts use 'set -e' to break the build if one of
    the commands fails.  This inconsistency among these scripts is
    asking for trouble: I forgot about the && chain more than once
    while working on this patch series.

Enable 'set -e' for the whole script and for the commands executed
under 'su' as well.

While touching every line in the 'su' command block anyway, change
their indentation to use a tab instead of spaces.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agotravis-ci: use 'set -x' for the commands under 'su' in the 32 bit Linux build
SZEDER Gábor [Mon, 29 Jan 2018 17:17:09 +0000 (18:17 +0100)] 
travis-ci: use 'set -x' for the commands under 'su' in the 32 bit Linux build

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agogit-svn: control destruction order to avoid segfault
Eric Wong [Mon, 29 Jan 2018 23:11:07 +0000 (23:11 +0000)] 
git-svn: control destruction order to avoid segfault

It seems necessary to control destruction ordering to avoid a
segfault with SVN 1.9.5 when using "git svn branch".  I've also
reported the problem against libsvn-perl to Debian [Bug #888791],
but releasing the SVN::Client instance can be beneficial anyways to
save memory.

ref: https://bugs.debian.org/888791
Tested-by: Todd Zullinger <tmz@pobox.com>
Reported-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Eric Wong <e@80x24.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agodoc: mention 'git show' defaults to HEAD
Todd Zullinger [Sun, 28 Jan 2018 19:16:07 +0000 (14:16 -0500)] 
doc: mention 'git show' defaults to HEAD

When 'git show' is called without any object it defaults to HEAD.  This
has been true since d4ed9793fd ("Simplify common default options setup
for built-in log family.", 2006-04-16).

The SYNOPSIS suggests that the object argument is required.  Clarify
that it is not required and note the default.

Signed-off-by: Todd Zullinger <tmz@pobox.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agosha1_file: rename hash_sha1_file_literally
Patryk Obara [Sun, 28 Jan 2018 00:13:22 +0000 (01:13 +0100)] 
sha1_file: rename hash_sha1_file_literally

This function was already converted to use struct object_id earlier.

Signed-off-by: Patryk Obara <patryk.obara@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agosha1_file: convert write_loose_object to object_id
Patryk Obara [Sun, 28 Jan 2018 00:13:21 +0000 (01:13 +0100)] 
sha1_file: convert write_loose_object to object_id

Convert the definition and declaration of static write_loose_object
function to struct object_id.

Signed-off-by: Patryk Obara <patryk.obara@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agosha1_file: convert force_object_loose to object_id
Patryk Obara [Sun, 28 Jan 2018 00:13:20 +0000 (01:13 +0100)] 
sha1_file: convert force_object_loose to object_id

Convert the definition and declaration of force_object_loose to
struct object_id and adjust usage of this function.

Signed-off-by: Patryk Obara <patryk.obara@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agosha1_file: convert write_sha1_file to object_id
Patryk Obara [Sun, 28 Jan 2018 00:13:19 +0000 (01:13 +0100)] 
sha1_file: convert write_sha1_file to object_id

Convert the definition and declaration of write_sha1_file to
struct object_id and adjust usage of this function.

This commit also converts static function write_sha1_file_prepare, as it
is closely related.

Rename these functions to write_object_file and
write_object_file_prepare respectively.

Replace sha1_to_hex, hashcpy and hashclr with their oid equivalents
wherever possible.

Signed-off-by: Patryk Obara <patryk.obara@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agonotes: convert write_notes_tree to object_id
Patryk Obara [Sun, 28 Jan 2018 00:13:18 +0000 (01:13 +0100)] 
notes: convert write_notes_tree to object_id

Convert the definition and declaration of write_notes_tree to
struct object_id and adjust usage of this function.

Additionally, improve style of small part of this function, as old
formatting made it hard to understand at glance what this part of
code is doing.

Signed-off-by: Patryk Obara <patryk.obara@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agonotes: convert combine_notes_* to object_id
Patryk Obara [Sun, 28 Jan 2018 00:13:17 +0000 (01:13 +0100)] 
notes: convert combine_notes_* to object_id

Convert the definition and declarations of combine_notes_* functions
to struct object_id and adjust usage of these functions.

Signed-off-by: Patryk Obara <patryk.obara@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agocommit: convert commit_tree* to object_id
Patryk Obara [Sun, 28 Jan 2018 00:13:16 +0000 (01:13 +0100)] 
commit: convert commit_tree* to object_id

Convert the definitions and declarations of commit_tree and
commit_tree_extended to use struct object_id and adjust all usages of
these functions.

Signed-off-by: Patryk Obara <patryk.obara@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agomatch-trees: convert splice_tree to object_id
Patryk Obara [Sun, 28 Jan 2018 00:13:15 +0000 (01:13 +0100)] 
match-trees: convert splice_tree to object_id

Convert the definition of static recursive splice_tree function to use
struct object_id and adjust single caller.

Signed-off-by: Patryk Obara <patryk.obara@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agocache: clear whole hash buffer with oidclr
Patryk Obara [Sun, 28 Jan 2018 00:13:14 +0000 (01:13 +0100)] 
cache: clear whole hash buffer with oidclr

As long as GIT_SHA1_RAWSZ is equal to GIT_MAX_RAWSZ there's no problem,
but when new hashing algorithm will be in place this memset will clear
only 20-byte prefix of hash buffer.

Alternatively, hashclr implementation could be adjusted, but this
function is almost removed from codebase already.  Separate
implementation of oidclr prevents potential buffer overrun in case
someone incorrectly used hashclr on object_id in future.

Signed-off-by: Patryk Obara <patryk.obara@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agosha1_file: convert hash_sha1_file to object_id
Patryk Obara [Sun, 28 Jan 2018 00:13:13 +0000 (01:13 +0100)] 
sha1_file: convert hash_sha1_file to object_id

Convert the declaration and definition of hash_sha1_file to use
struct object_id and adjust all function calls.

Rename this function to hash_object_file.

Signed-off-by: Patryk Obara <patryk.obara@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agodir: convert struct sha1_stat to use object_id
Patryk Obara [Sun, 28 Jan 2018 00:13:12 +0000 (01:13 +0100)] 
dir: convert struct sha1_stat to use object_id

Convert the declaration of struct sha1_stat. Adjust all usages of this
struct and replace hash{clr,cmp,cpy} with oid{clr,cmp,cpy} wherever
possible.  Rename it to struct oid_stat.

Rename static function load_sha1_stat to load_oid_stat.

Remove macro EMPTY_BLOB_SHA1_BIN, as it's no longer used.

Signed-off-by: Patryk Obara <patryk.obara@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agosha1_file: convert pretend_sha1_file to object_id
Patryk Obara [Sun, 28 Jan 2018 00:13:11 +0000 (01:13 +0100)] 
sha1_file: convert pretend_sha1_file to object_id

Convert the declaration and definition of pretend_sha1_file to use
struct object_id and adjust all usages of this function.  Rename it to
pretend_object_file.

Signed-off-by: Patryk Obara <patryk.obara@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agocompletion: fix completing merge strategies on non-C locales
Duy Nguyen [Fri, 26 Jan 2018 01:31:42 +0000 (08:31 +0700)] 
completion: fix completing merge strategies on non-C locales

The anchor string "Available strategies are:" is translatable so
__git_list_merge_strategies may fail to collect available strategies
from 'git merge' on non-C locales. Force C locale on this command.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agodaemon: fix length computation in newline stripping
Jeff King [Thu, 25 Jan 2018 00:58:54 +0000 (19:58 -0500)] 
daemon: fix length computation in newline stripping

When git-daemon gets a pktline request, we strip off any
trailing newline, replacing it with a NUL. Clients prior to
5ad312bede (in git v1.4.0) would send:

  git-upload-pack repo.git\n

and we need to strip it off to understand their request.
After 5ad312bede, we send the host attribute but no newline,
like:

  git-upload-pack repo.git\0host=example.com\0

Both of these are parsed correctly by git-daemon. But if
some client were to combine the two:

  git-upload-pack repo.git\n\0host=example.com\0

we don't parse it correctly. The problem is that we use the
"len" variable to record the position of the NUL separator,
but then decrement it when we strip the newline. So we start
with:

  git-upload-pack repo.git\n\0host=example.com\0
                             ^-- len

and end up with:

  git-upload-pack repo.git\0\0host=example.com\0
                           ^-- len

This is arguably correct, since "len" tells us the length of
the initial string, but we don't actually use it for that.
What we do use it for is finding the offset of the extended
attributes; they used to be at len+1, but are now at len+2.

We can solve that by just leaving "len" where it is. We
don't have to care about the length of the shortened string,
since we just treat it like a C string.

No version of Git ever produced such a string, but it seems
like the daemon code meant to handle this case (and it seems
like a reasonable thing for somebody to do in a 3rd-party
implementation).

Reported-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agot/lib-git-daemon: add network-protocol helpers
Jeff King [Thu, 25 Jan 2018 00:58:19 +0000 (19:58 -0500)] 
t/lib-git-daemon: add network-protocol helpers

All of our git-protocol tests rely on invoking the client
and having it make a request of a server. That gives a nice
real-world test of how the two behave together, but it
doesn't leave any room for testing how a server might react
to _other_ clients.

Let's add a few test helper functions which can be used to
manually conduct a git-protocol conversation with a remote
git-daemon:

  1. To connect to a remote git-daemon, we need something
     like "netcat". But not everybody will have netcat. And
     even if they do, the behavior with respect to
     half-duplex shutdowns is not portable (openbsd netcat
     has "-N", with others you must rely on "-q 1", which is
     racy).

     Here we provide a "fake_nc" that is capable of doing
     a client-side netcat, with sane half-duplex semantics.
     It relies on perl's IO::Socket::INET. That's been in
     the base distribution since 5.6.0, so it's probably
     available everywhere. But just to be on the safe side,
     we'll add a prereq.

  2. To help tests speak and read pktline, this patch adds
     packetize() and depacketize() functions.

I've put fake_nc() into lib-git-daemon.sh, since that's
really the only server where we'd need to use a network
socket.  Whereas the pktline helpers may be of more general
use, so I've added them to test-lib-functions.sh. Programs
like upload-pack speak pktline, but can talk directly over
stdio without a network socket.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agodaemon: handle NULs in extended attribute string
Jeff King [Thu, 25 Jan 2018 00:56:20 +0000 (19:56 -0500)] 
daemon: handle NULs in extended attribute string

If we receive a request with extended attributes after the
NUL, we try to write those attributes to the log. We do so
with a "%s" format specifier, which will only show
characters up to the first NUL.

That's enough for printing a "host=" specifier. But since
dfe422d04d (daemon: recognize hidden request arguments,
2017-10-16) we may have another NUL, followed by protocol
parameters, and those are not logged at all.

Let's cut out the attempt to show the whole string, and
instead log when we parse individual attributes. We could
leave the "extended attributes (%d bytes) exist" part of the
log, which in theory could alert us to attributes that fail
to parse. But anything we don't parse as a "host=" parameter
gets blindly added to the "protocol" attribute, so we'd see
it in that part of the log.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agodaemon: fix off-by-one in logging extended attributes
Jeff King [Thu, 25 Jan 2018 00:56:07 +0000 (19:56 -0500)] 
daemon: fix off-by-one in logging extended attributes

If receive a request like:

  git-upload-pack /foo.git\0host=localhost

we mark the offset of the NUL byte as "len", and then log
the bytes after the NUL with a "%.*s" placeholder, using
"pktlen - len" as the length, and "line + len + 1" as the
start of the string.

This is off-by-one, since the start of the string skips past
the separating NUL byte, but the adjusted length includes
it. Fortunately this doesn't actually read past the end of
the buffer, since "%.*s" will stop when it hits a NUL. And
regardless of what is in the buffer, packet_read() will
always add an extra NUL terminator for safety.

As an aside, the git.git client sends an extra NUL after a
"host" field, too, so we'd generally hit that one first, not
the one added by packet_read(). You can see this in the test
output which reports 15 bytes, even though the string has
only 14 bytes of visible data. But the point is that even a
client sending unusual data could not get us to read past
the end of the buffer, so this is purely a cosmetic fix.

Reported-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agot/lib-git-daemon: record daemon log
Jeff King [Thu, 25 Jan 2018 19:16:41 +0000 (14:16 -0500)] 
t/lib-git-daemon: record daemon log

When we start git-daemon for our tests, we send its stderr
log stream to a named pipe. We synchronously read the first
line to make sure that the daemon started, and then dump the
rest to descriptor 4. This is handy for debugging test
output with "--verbose", but the tests themselves can't
access the log data.

Let's dump the log into a file, as well, so that future
tests can check the log. There are a few subtleties worth
calling out here:

  - we'll continue to send output to descriptor 4 for
    viewing/debugging, which would imply swapping out "cat"
    for "tee". But we want to ensure that there's no
    buffering, and "tee" doesn't have a standard way to
    ask for that. So we'll use a shell loop around "read"
    and "printf" instead. That ensures that after a request
    has been served, the matching log entries will have made
    it to the file.

  - the existing first-line shell loop used read/echo. We'll
    switch to consistently using "read -r" and "printf" to
    relay data as faithfully as possible.

  - we open the logfile for append, rather than just output.
    That makes it OK for tests to truncate the logfile
    without restarting the daemon (the OS will atomically
    seek to the end of the file when outputting each line).
    That allows tests to look at the log without worrying
    about pollution from earlier tests.

Helped-by: Lucas Werkmeister <mail@lucaswerkmeister.de>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoDocs: split out long-running subprocess handshake
Jonathan Tan [Thu, 25 Jan 2018 18:53:24 +0000 (10:53 -0800)] 
Docs: split out long-running subprocess handshake

Separating out the implementation of the handshake when starting a
long-running subprocess (for example, as is done for a clean/smudge
filter) was done in commit fa64a2fdbeed ("sub-process: refactor
handshake to common function", 2017-07-26), but its documentation still
resides in gitattributes. Split out the documentation as well.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agobuiltin/pull: respect verbosity settings in submodules
Stefan Beller [Thu, 25 Jan 2018 19:08:17 +0000 (11:08 -0800)] 
builtin/pull: respect verbosity settings in submodules

In a6d7eb2c7a (pull: optionally rebase submodules (remote submodule
changes only), 2017-06-23), we taught Git how to rebase submodules in
a pull. However we missed to pass on the verbosity settings.

Reported-by: Robin H. Johnson <robbat2@gentoo.org>
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoformat-patch: keep cover-letter diffstat wrapped in 72 columns
Nguyễn Thái Ngọc Duy [Thu, 25 Jan 2018 11:59:26 +0000 (18:59 +0700)] 
format-patch: keep cover-letter diffstat wrapped in 72 columns

We already wrap shortlog around 72 columns in cover letters. Do the same
for diffstat (also in cover letters).

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agot5570: use ls-remote instead of clone for interp tests
Jeff King [Thu, 25 Jan 2018 00:55:05 +0000 (19:55 -0500)] 
t5570: use ls-remote instead of clone for interp tests

We don't actually care about the clone operation here; we
just want to know if we were able to actually contact the
remote repository. Using ls-remote does that more
efficiently, and without us having to worry about managing
the tmp.git directory.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agohttp-push: improve error log
Patryk Obara [Wed, 24 Jan 2018 11:11:53 +0000 (12:11 +0100)] 
http-push: improve error log

When git push fails due to server-side WebDAV error, it's not easy to
point to the main culprit.  Additional information about exact cURL
error and HTTP server response is helpful for debugging purpose.

New error log helped me pinpoint failing test t5540-http-push-webdav
to a missing Apache dependency in Fedora 27:
https://bugzilla.redhat.com/show_bug.cgi?id=1491151

Signed-off-by: Patryk Obara <patryk.obara@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoclang-format: adjust penalty for return type line break
Patryk Obara [Wed, 24 Jan 2018 11:11:54 +0000 (12:11 +0100)] 
clang-format: adjust penalty for return type line break

The penalty of 5 makes clang-format very eager to put even short type
declarations (e.g. "extern int") into a separate line, even when
breaking parameters list is sufficient.

Signed-off-by: Patryk Obara <patryk.obara@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agopacked_ref_cache: don't use mmap() for small files
Kim Gybels [Wed, 24 Jan 2018 11:14:16 +0000 (12:14 +0100)] 
packed_ref_cache: don't use mmap() for small files

Take a hint from commit ea68b0ce9f8 (hash-object: don't use mmap() for
small files, 2010-02-21) and use read() instead of mmap() for small
packed-refs files.

Signed-off-by: Kim Gybels <kgybels@infogroep.be>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoload_contents(): don't try to mmap an empty file
Michael Haggerty [Wed, 24 Jan 2018 11:14:15 +0000 (12:14 +0100)] 
load_contents(): don't try to mmap an empty file

We don't actually create zero-length `packed-refs` files, but they are
valid and we should handle them correctly. The old code `xmmap()`ed
such files, which led to an error when `munmap()` was called. So, if
the `packed-refs` file is empty, leave the snapshot at its zero values
and return 0 without trying to read or mmap the file.

Returning 0 also makes `create_snapshot()` exit early, which avoids
the technically undefined comparison `NULL < NULL`.

Reported-by: Kim Gybels <kgybels@infogroep.be>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agopacked_ref_iterator_begin(): make optimization more general
Michael Haggerty [Wed, 24 Jan 2018 11:14:14 +0000 (12:14 +0100)] 
packed_ref_iterator_begin(): make optimization more general

We can return an empty iterator not only if the `packed-refs` file is
missing, but also if it is empty or if there are no references whose
names succeed `prefix`. Optimize away those cases as well by moving
the call to `find_reference_location()` higher in the function and
checking whether the determined start position is the same as
`snapshot->eof`. (This is possible now because the previous commit
made `find_reference_location()` robust against empty snapshots.)

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agofind_reference_location(): make function safe for empty snapshots
Michael Haggerty [Wed, 24 Jan 2018 11:14:13 +0000 (12:14 +0100)] 
find_reference_location(): make function safe for empty snapshots

This function had two problems if called for an empty snapshot (i.e.,
`snapshot->start == snapshot->eof == NULL`):

* It checked `NULL < NULL`, which is undefined by C (albeit highly
  unlikely to fail in the real world).

* (Assuming the above comparison behaved as expected), it returned
  NULL when `mustexist` was false, contrary to its docstring.

Change the check and fix the docstring.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agocreate_snapshot(): use `xmemdupz()` rather than a strbuf
Michael Haggerty [Wed, 24 Jan 2018 11:14:12 +0000 (12:14 +0100)] 
create_snapshot(): use `xmemdupz()` rather than a strbuf

It's lighter weight.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agostruct snapshot: store `start` rather than `header_len`
Michael Haggerty [Wed, 24 Jan 2018 11:14:11 +0000 (12:14 +0100)] 
struct snapshot: store `start` rather than `header_len`

Store a pointer to the start of the actual references within the
`packed-refs` contents rather than storing the length of the header.
This is more convenient for most users of this field.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agodir.c: fix missing dir invalidation in untracked code
Nguyễn Thái Ngọc Duy [Wed, 24 Jan 2018 09:30:21 +0000 (16:30 +0700)] 
dir.c: fix missing dir invalidation in untracked code

Let's start with how create a new directory cache after the last one
becomes invalid (e.g. because its dir mtime has changed...). In
open_cached_dir():

1. We start out with valid_cached_dir() returning false, which should
   call invalidate_directory() to put a directory state back to
   initial state, no untracked entries (untracked_nr zero), no sub
   directory traversal (dirs[].recurse zero).

2. Since the cache cannot be used, we go the slow path opendir() and
   go through items one by one via readdir(). All the directories on
   disk will be added back to the cache (if not already exist in
   dirs[]) and its flag "recurse" gets changed to one to note that
   it's part of the cached dir travesal next time.

3. By the time we reach close_cached_dir() we should have a good
   subdir list in dirs[]. Those with "recurse" flag set are the ones
   present in the on-disk directory. The directory is now marked
   "valid".

Next time read_directory() is called, since the directory is marked
valid, it will skip readdir(), go fast path and traverse through
dirs[] array instead.

Steps one and two need some tight cooperation. If a subdir is removed,
readdir() will not find it and of course we cannot examine/invalidate
it. To make sure removed directories on disk are gone from the cache,
step one must make sure recurse flag of all subdirs are zero.

But that's not true. If "valid" flag is already false, there is a
chance we go straight to the end of valid_cached_dir() without calling
invalidate_directory(). Or we fail to meet the "if (untracked-valid)"
condition and skip over the invalidate_directory().

After step 3, we mark the cache valid. Any stale subdir with incorrect
recurse flag becomes a real subdir next time we traverse the directory
using dirs[] array.

We could avoid this by making sure invalidate_directory() is always
called (therefore dirs[].recurse cleared) at the beginning of
open_cached_dir(). Which is what this patch does.

As to how we get into this situation, the key in the test is this
command

    git checkout master

where "one/file" is replaced with "one" in the index. This index
update triggers untracked_cache_invalidate_path(), which clears valid
flag of the root directory while keeping "recurse" flag on the subdir
"one" on. On the next git-status, we go through steps 1-3 above and
save an incorrect cache on disk. The second git-status blindly follows
the bad cache data and shows the problem.

This is arguably because of a bad design where "recurse" flag plays
double roles: whether a directory should be saved on disk, and whether
it is part of a directory traversal.

We need to keep recurse flag set at "checkout master" because of the
first role: we need to keep subdir caches (dir "two" for example has
not been touched at all, no reason to throw its cache away).

As long as we make sure to ignore/reset "recurse" flag at the
beginning of a directory traversal, we're good. But maybe eventually
we should separate these two roles.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agodir.c: avoid stat() in valid_cached_dir()
Nguyễn Thái Ngọc Duy [Wed, 24 Jan 2018 09:30:20 +0000 (16:30 +0700)] 
dir.c: avoid stat() in valid_cached_dir()

stat() may follow a symlink and return stat data of the link's target
instead of the link itself. We are concerned about the link itself.

It's kind of hard to demonstrate the bug. I think when path->buf is a
symlink, we most likely find that its target's stat data does not
match our cached one, which means we ignore the cache and fall back to
slow path.

This is performance issue, not correctness (though we could still
catch it by verifying test-dump-untracked-cache. The less unlikely
case is, link target stat data matches the cached version and we
incorrectly go fast path, ignoring real data on disk. A test for this
may involve manipulating stat data, which may be not portable.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agostatus: add a failing test showing a core.untrackedCache bug
Ævar Arnfjörð Bjarmason [Wed, 24 Jan 2018 09:30:19 +0000 (16:30 +0700)] 
status: add a failing test showing a core.untrackedCache bug

The untracked cache gets confused when a directory is swapped out for
a file. It is easiest to reproduce this by swapping out a directory
with a symlink to another directory, and as the tests show the symlink
case is the only case we've found where "git status" will subsequently
report incorrect information, even though it's possible to otherwise
get the untracked cache into a state where its internal data
structures don't reflect reality.

In the symlink case, whatever files are inside the target of the
symlink will be incorrectly shown as untracked. This issue does not
happen if the symlink links to another file, only if it links to
another directory.

A stand-alone testcase for copying into a terminal:

    (
        rm -rf /tmp/testrepo &&
        git init /tmp/testrepo &&
        cd /tmp/testrepo &&
        mkdir x y &&
        touch x/a y/b &&
        git add x/a y/b &&
        git commit -msnap &&
        git rm -rf y &&
        ln -s x y &&
        git add y &&
        git commit -msnap2 &&
        git checkout HEAD~ &&
        git status &&
        git checkout master &&
        sleep 1 &&
        git status &&
        git status
    )

This will incorrectly show y/a as an untracked file. Both the "git
status" call right before "git checkout master" and the "sleep 1"
after the "checkout master" are needed to reproduce this, presumably
due to the untracked cache tracking on the basis of cached whole
seconds from stat(2).

When git gets into this state, a workaround to fix it is to issue a
one-off:

    git -c core.untrackedCache=false status

For the non-symlink case, the bug is that the output of
test-dump-untracked-cache should not include:

   /one/ 0000000000000000000000000000000000000000 recurse valid

It being in the output implies that cached traversal of root includes
the directory "one" which does not exist on disk anymore.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agosequencer: run 'prepare-commit-msg' hook
Phillip Wood [Wed, 24 Jan 2018 12:34:22 +0000 (12:34 +0000)] 
sequencer: run 'prepare-commit-msg' hook

Commit 356ee4659b ("sequencer: try to commit without forking 'git
commit'", 2017-11-24) forgot to run the 'prepare-commit-msg' hook when
creating the commit. Fix this by writing the commit message to a
different file and running the hook. Using a different file means that
if the commit is cancelled the original message file is
unchanged. Also move the checks for an empty commit so the order
matches 'git commit'.

Reported-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Helped-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agot7505: add tests for cherry-pick and rebase -i/-p
Phillip Wood [Wed, 24 Jan 2018 12:34:21 +0000 (12:34 +0000)] 
t7505: add tests for cherry-pick and rebase -i/-p

Check that cherry-pick and rebase call the 'prepare-commit-msg' hook
correctly. The expected values for the hook arguments are taken to
match the current master branch. I think there is scope for improving
the arguments passed so they make a bit more sense - for instance
cherry-pick currently passes different arguments depending on whether
the commit message is being edited. Also the arguments for rebase
could be improved. Commit 7c4188360ac ("rebase -i: proper
prepare-commit-msg hook argument when squashing", 2008-10-3) apparently
changed things so that when squashing rebase would pass 'squash' as
the argument to the hook but that has been lost.

I think that it would make more sense to pass 'message' for revert and
cherry-pick -x/-s (i.e. cases where there is a new message or the
current message in modified by the command), 'squash' when squashing
with a new message and 'commit HEAD/CHERRY_PICK_HEAD'
otherwise (picking and squashing without a new message).

Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agot7505: style fixes
Phillip Wood [Wed, 24 Jan 2018 12:34:20 +0000 (12:34 +0000)] 
t7505: style fixes

Fix the indentation and style of the hook script in preparation for
further changes.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agomailinfo: avoid segfault when can't open files
Juan F. Codagnone [Wed, 24 Jan 2018 16:56:47 +0000 (13:56 -0300)] 
mailinfo: avoid segfault when can't open files

If <msg> or <patch> files can't be opened, then mailinfo() returns an
error before it even initializes mi->p_hdr_data or mi->s_hdr_data.
When cmd_mailinfo() then calls clear_mailinfo(), we dereference the
NULL pointers trying to free their contents.

Signed-off-by: Juan F. Codagnone <jcodagnone@gmail.com>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoread-cache: don't write index twice if we can't write shared index
Nguyễn Thái Ngọc Duy [Wed, 24 Jan 2018 09:38:29 +0000 (16:38 +0700)] 
read-cache: don't write index twice if we can't write shared index

In a0a967568e ("update-index --split-index: do not split if $GIT_DIR is
read only", 2014-06-13), we tried to make sure we can still write an
index, even if the shared index can not be written.

We did so by just calling 'do_write_locked_index()' just before
'write_shared_index()'.  'do_write_locked_index()' always at least
closes the tempfile nowadays, and used to close or commit the lockfile
if COMMIT_LOCK or CLOSE_LOCK were given at the time this feature was
introduced.  COMMIT_LOCK or CLOSE_LOCK is passed in by most callers of
'write_locked_index()'.

After calling 'write_shared_index()', we call 'write_split_index()',
which calls 'do_write_locked_index()' again, which then tries to use the
closed lockfile again, but in fact fails to do so as it's already
closed. This eventually leads to a segfault.

Make sure to write the main index only once.

[nd: most of the commit message and investigation done by Thomas, I only
tweaked the solution a bit]

Helped-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agomru: Replace mru.[ch] with list.h implementation
Gargi Sharma [Tue, 23 Jan 2018 23:46:51 +0000 (18:46 -0500)] 
mru: Replace mru.[ch] with list.h implementation

Replace the custom calls to mru.[ch] with calls to list.h. This patch is
the final step in removing the mru API completely and inlining the logic.
This patch leads to significant code reduction and the mru API hence, is
not a useful abstraction anymore.

Signed-off-by: Gargi Sharma <gs051095@gmail.com>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoFirst batch after 2.16
Junio C Hamano [Tue, 23 Jan 2018 21:21:10 +0000 (13:21 -0800)] 
First batch after 2.16

Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoMerge branch 'nd/add-i-ignore-submodules'
Junio C Hamano [Tue, 23 Jan 2018 21:16:41 +0000 (13:16 -0800)] 
Merge branch 'nd/add-i-ignore-submodules'

"git add -p" was taught to ignore local changes to submodules as
they do not interfere with the partial addition of regular changes
anyway.

* nd/add-i-ignore-submodules:
  add--interactive: ignore submodule changes except HEAD

6 years agoMerge branch 'mm/send-email-fallback-to-local-mail-address'
Junio C Hamano [Tue, 23 Jan 2018 21:16:41 +0000 (13:16 -0800)] 
Merge branch 'mm/send-email-fallback-to-local-mail-address'

Instead of maintaining home-grown email address parsing code, ship
a copy of reasonably recent Mail::Address to be used as a fallback
in 'git send-email' when the platform lacks it.

* mm/send-email-fallback-to-local-mail-address:
  send-email: add test for Linux's get_maintainer.pl
  perl/Git: remove now useless email-address parsing code
  send-email: add and use a local copy of Mail::Address

6 years agoMerge branch 'ab/doc-cat-file-e-still-shows-errors'
Junio C Hamano [Tue, 23 Jan 2018 21:16:41 +0000 (13:16 -0800)] 
Merge branch 'ab/doc-cat-file-e-still-shows-errors'

Doc update.

* ab/doc-cat-file-e-still-shows-errors:
  cat-file doc: document that -e will return some output

6 years agoMerge branch 'as/read-tree-prefix-doc-fix'
Junio C Hamano [Tue, 23 Jan 2018 21:16:41 +0000 (13:16 -0800)] 
Merge branch 'as/read-tree-prefix-doc-fix'

Doc update.

* as/read-tree-prefix-doc-fix:
  doc/read-tree: remove obsolete remark

6 years agoMerge branch 'ys/bisect-object-id-missing-conversion-fix'
Junio C Hamano [Tue, 23 Jan 2018 21:16:40 +0000 (13:16 -0800)] 
Merge branch 'ys/bisect-object-id-missing-conversion-fix'

Fix for a commented-out code to adjust it to a rather old API change.

* ys/bisect-object-id-missing-conversion-fix:
  bisect: debug: convert struct object to object_id

6 years agoMerge branch 'tg/stash-with-pathspec-fix'
Junio C Hamano [Tue, 23 Jan 2018 21:16:39 +0000 (13:16 -0800)] 
Merge branch 'tg/stash-with-pathspec-fix'

"git stash -- <pathspec>" incorrectly blew away untracked files in
the directory that matched the pathspec, which has been corrected.

* tg/stash-with-pathspec-fix:
  stash: don't delete untracked files that match pathspec

6 years agoMerge branch 'sb/submodule-update-reset-fix'
Junio C Hamano [Tue, 23 Jan 2018 21:16:39 +0000 (13:16 -0800)] 
Merge branch 'sb/submodule-update-reset-fix'

When resetting the working tree files recursively, the working tree
of submodules are now also reset to match.

* sb/submodule-update-reset-fix:
  submodule: submodule_move_head omits old argument in forced case
  unpack-trees: oneway_merge to update submodules
  t/lib-submodule-update.sh: fix test ignoring ignored files in submodules
  t/lib-submodule-update.sh: clarify test

6 years agoMerge branch 'bw/oidmap-autoinit'
Junio C Hamano [Tue, 23 Jan 2018 21:16:39 +0000 (13:16 -0800)] 
Merge branch 'bw/oidmap-autoinit'

Code clean-up.

* bw/oidmap-autoinit:
  oidmap: ensure map is initialized

6 years agoMerge branch 'ab/commit-m-with-fixup'
Junio C Hamano [Tue, 23 Jan 2018 21:16:38 +0000 (13:16 -0800)] 
Merge branch 'ab/commit-m-with-fixup'

"git commit --fixup" did not allow "-m<message>" option to be used
at the same time; allow it to annotate resulting commit with more
text.

* ab/commit-m-with-fixup:
  commit: add support for --fixup <commit> -m"<extra message>"
  commit doc: document that -c, -C, -F and --fixup with -m error

6 years agoMerge branch 'cc/codespeed'
Junio C Hamano [Tue, 23 Jan 2018 21:16:38 +0000 (13:16 -0800)] 
Merge branch 'cc/codespeed'

"perf" test output can be sent to codespeed server.

* cc/codespeed:
  perf/run: read GIT_PERF_REPO_NAME from perf.repoName
  perf/run: learn to send output to codespeed server
  perf/run: learn about perf.codespeedOutput
  perf/run: add conf_opts argument to get_var_from_env_or_config()
  perf/aggregate: implement codespeed JSON output
  perf/aggregate: refactor printing results
  perf/aggregate: fix checking ENV{GIT_PERF_SUBSECTION}

6 years agoMerge branch 'ab/perf-grep-threads'
Junio C Hamano [Tue, 23 Jan 2018 21:16:37 +0000 (13:16 -0800)] 
Merge branch 'ab/perf-grep-threads'

More perf tests for threaded grep

* ab/perf-grep-threads:
  perf: amend the grep tests to test grep.threads

6 years agoMerge branch 'sb/diff-blobfind-pickaxe'
Junio C Hamano [Tue, 23 Jan 2018 21:16:37 +0000 (13:16 -0800)] 
Merge branch 'sb/diff-blobfind-pickaxe'

"diff" family of commands learned "--find-object=<object-id>" option
to limit the findings to changes that involve the named object.

* sb/diff-blobfind-pickaxe:
  diff: use HAS_MULTI_BITS instead of counting bits manually
  diff: properly error out when combining multiple pickaxe options
  diffcore: add a pickaxe option to find a specific blob
  diff: introduce DIFF_PICKAXE_KINDS_MASK
  diff: migrate diff_flags.pickaxe_ignore_case to a pickaxe_opts bit
  diff.h: make pickaxe_opts an unsigned bit field

6 years agoMerge branch 'jk/abort-clone-with-existing-dest'
Junio C Hamano [Tue, 23 Jan 2018 21:16:37 +0000 (13:16 -0800)] 
Merge branch 'jk/abort-clone-with-existing-dest'

"git clone $there $here" is allowed even when here directory exists
as long as it is an empty directory, but the command incorrectly
removed it upon a failure of the operation.

* jk/abort-clone-with-existing-dest:
  clone: do not clean up directories we didn't create
  clone: factor out dir_exists() helper
  t5600: modernize style
  t5600: fix outdated comment about unborn HEAD

6 years agoMerge branch 'jc/merge-symlink-ours-theirs'
Junio C Hamano [Tue, 23 Jan 2018 21:16:37 +0000 (13:16 -0800)] 
Merge branch 'jc/merge-symlink-ours-theirs'

"git merge -Xours/-Xtheirs" learned to use our/their version when
resolving a conflicting updates to a symbolic link.

* jc/merge-symlink-ours-theirs:
  merge: teach -Xours/-Xtheirs to symbolic link merge

6 years agoMerge branch 'rs/lose-leak-pending'
Junio C Hamano [Tue, 23 Jan 2018 21:16:36 +0000 (13:16 -0800)] 
Merge branch 'rs/lose-leak-pending'

API clean-up around revision traversal.

* rs/lose-leak-pending:
  commit: remove unused function clear_commit_marks_for_object_array()
  revision: remove the unused flag leak_pending
  checkout: avoid using the rev_info flag leak_pending
  bundle: avoid using the rev_info flag leak_pending
  bisect: avoid using the rev_info flag leak_pending
  object: add clear_commit_marks_all()
  ref-filter: use clear_commit_marks_many() in do_merge_filter()
  commit: use clear_commit_marks_many() in remove_redundant()
  commit: avoid allocation in clear_commit_marks_many()

6 years agoMerge branch 'jm/svn-pushmergeinfo-fix'
Junio C Hamano [Tue, 23 Jan 2018 21:16:36 +0000 (13:16 -0800)] 
Merge branch 'jm/svn-pushmergeinfo-fix'

"git svn dcommit" did not take into account the fact that a
svn+ssh:// URL with a username@ (typically used for pushing) refers
to the same SVN repository without the username@ and failed when
svn.pushmergeinfo option is set.

* jm/svn-pushmergeinfo-fix:
  git-svn: fix svn.pushmergeinfo handling of svn+ssh usernames.

6 years agoMerge branch 'nd/ita-wt-renames-in-status'
Junio C Hamano [Tue, 23 Jan 2018 21:16:28 +0000 (13:16 -0800)] 
Merge branch 'nd/ita-wt-renames-in-status'

"git status" after moving a path in the working tree (hence making
it appear "removed") and then adding with the -N option (hence
making that appear "added") detected it as a rename, but did not
report the  old and new pathnames correctly.

* nd/ita-wt-renames-in-status:
  wt-status.c: handle worktree renames
  wt-status.c: rename rename-related fields in wt_status_change_data
  wt-status.c: catch unhandled diff status codes
  wt-status.c: coding style fix
  Use DIFF_DETECT_RENAME for detect_rename assignments
  t2203: test status output with porcelain v2 format

6 years agoMerge branch 'dk/describe-all-output-fix'
Junio C Hamano [Tue, 23 Jan 2018 21:16:28 +0000 (13:16 -0800)] 
Merge branch 'dk/describe-all-output-fix'

An old regression in "git describe --all $annotated_tag^0" has been
fixed.

* dk/describe-all-output-fix:
  describe: prepend "tags/" when describing tags with embedded name

6 years agofsck: fix leak when traversing trees
Eric Wong [Sat, 20 Jan 2018 07:43:51 +0000 (07:43 +0000)] 
fsck: fix leak when traversing trees

While fsck_walk/fsck_walk_tree/parse_tree populates "struct tree"
idempotently, it is still up to the fsck_walk caller to call
free_tree_buffer.

Fixes: ad2db4030e42890e ("fsck: remove redundant parse_tree() invocation")

Signed-off-by: Eric Wong <e@80x24.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoUse MOVE_ARRAY
SZEDER Gábor [Mon, 22 Jan 2018 17:50:09 +0000 (18:50 +0100)] 
Use MOVE_ARRAY

Use the helper macro MOVE_ARRAY to move arrays.  This is shorter and
safer, as it automatically infers the size of elements.

Patch generated by Coccinelle and contrib/coccinelle/array.cocci in
Travis CI's static analysis build job.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoSync with v2.16.1
Junio C Hamano [Mon, 22 Jan 2018 05:14:54 +0000 (21:14 -0800)] 
Sync with v2.16.1

* maint:
  Git 2.16.1
  t5601-clone: test case-conflicting files on case-insensitive filesystem
  repository: pre-initialize hash algo pointer

6 years agoGit 2.16.1 v2.16.1
Junio C Hamano [Mon, 22 Jan 2018 05:14:25 +0000 (21:14 -0800)] 
Git 2.16.1

Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoStart 2.17 cycle
Junio C Hamano [Mon, 22 Jan 2018 05:14:09 +0000 (21:14 -0800)] 
Start 2.17 cycle

Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoMerge branch 'bc/hash-algo' into maint
Junio C Hamano [Mon, 22 Jan 2018 05:12:37 +0000 (21:12 -0800)] 
Merge branch 'bc/hash-algo' into maint

* bc/hash-algo:
  t5601-clone: test case-conflicting files on case-insensitive filesystem
  repository: pre-initialize hash algo pointer

6 years agot5601-clone: test case-conflicting files on case-insensitive filesystem
Eric Sunshine [Sun, 21 Jan 2018 08:07:28 +0000 (03:07 -0500)] 
t5601-clone: test case-conflicting files on case-insensitive filesystem

A recently introduced regression caused a segfault at clone time on
case-insensitive filesystems when filenames differing only in case are
present. This bug has already been fixed (repository: pre-initialize
hash algo pointer, 2018-01-18), but it's not the first time similar
problems have arisen. Therefore, introduce a test to catch this case and
protect against future regressions.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agomerge-recursive: add explanation for src_entry and dst_entry
Elijah Newren [Fri, 5 Jan 2018 20:20:01 +0000 (12:20 -0800)] 
merge-recursive: add explanation for src_entry and dst_entry

If I have to walk through the debugger and inspect the values found in
here in order to figure out their meaning, despite having known these
things inside and out some years back, then they probably need a comment
for the casual reader to explain their purpose.

Reviewed-By: Stefan Beller <sbeller@google.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agomerge-recursive: fix logic ordering issue
Elijah Newren [Fri, 5 Jan 2018 20:20:00 +0000 (12:20 -0800)] 
merge-recursive: fix logic ordering issue

merge_trees() did a variety of work, including:
  * Calling get_unmerged() to get unmerged entries
  * Calling record_df_conflict_files() with all unmerged entries to
    do some work to ensure we could handle D/F conflicts correctly
  * Calling get_renames() to check for renames.

An easily overlooked issue is that get_renames() can create more
unmerged entries and add them to the list, which have the possibility of
being involved in D/F conflicts.  So the call to
record_df_conflict_files() should really be moved after all the rename
detection.  I didn't come up with any testcases demonstrating any bugs
with the old ordering, but I suspect there were some for both normal
renames and for directory renames.  Fix the ordering.

Reviewed-By: Stefan Beller <sbeller@google.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agoTighten and correct a few testcases for merging and cherry-picking
Elijah Newren [Fri, 5 Jan 2018 20:19:59 +0000 (12:19 -0800)] 
Tighten and correct a few testcases for merging and cherry-picking

t3501 had a testcase originally added in 05f2dfb965 (cherry-pick:
demonstrate a segmentation fault, 2016-11-26) to ensure cherry-pick
wouldn't segfault when working with a dirty file involved in a rename.
While the segfault was fixed, there was another problem this test
demonstrated: namely, that git would overwrite a dirty file involved in a
rename.  Further, the test encoded a "successful merge" and overwriting of
this file as correct behavior.  Modify the test so that it would still
catch the segfault, but to require the correct behavior.  Mark it as
test_expect_failure for now too, since this second bug is not yet fixed.

t7607 had a test added in 30fd3a5425 (merge overwrites unstaged changes in
renamed file, 2012-04-15) specific to looking for a merge overwriting a
dirty file involved in a rename, but it too actually encoded what I would
term incorrect behavior: it expected the merge to succeed.  Fix that, and
add a few more checks to make sure that the merge really does produce the
expected results.

Reviewed-By: Stefan Beller <sbeller@google.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agorepository: pre-initialize hash algo pointer
brian m. carlson [Fri, 19 Jan 2018 04:18:25 +0000 (04:18 +0000)] 
repository: pre-initialize hash algo pointer

There are various git subcommands (among them, clone) which don't set up
the repository (that is, they lack RUN_SETUP or RUN_SETUP_GENTLY) but
end up needing to have information about the hash algorithm in use.
Because the hash algorithm is part of struct repository and it's only
initialized in repository setup, we can end up dereferencing a NULL
pointer in some cases if we call one of these subcommands and look up
the empty blob or empty tree values.

A "git clone" of a project that has two paths that differ only in
case suffers from this if it is run on a case insensitive platform.
When the command attempts to check out one of these two paths after
checking out the other one, the checkout codepath needs to see if
the version that is already on the filesystem (which should not
happen if the FS were case sensitive) is dirty, and it needs to
exercise the hashing code at that point.

In the future, we can add a command line option for this or read it
from the configuration, but until we're ready to expose that
functionality to the user, simply initialize the repository
structure to use the current hash algorithm, SHA-1.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agofiles_initial_transaction_commit(): only unlock if locked
Mathias Rav [Thu, 18 Jan 2018 13:38:41 +0000 (14:38 +0100)] 
files_initial_transaction_commit(): only unlock if locked

Running git clone --single-branch --mirror -b TAGNAME previously
triggered the following error message:

fatal: multiple updates for ref 'refs/tags/TAGNAME' not allowed.

This error condition is handled in files_initial_transaction_commit().

42c7f7ff9 ("commit_packed_refs(): remove call to `packed_refs_unlock()`", 2017-06-23)
introduced incorrect unlocking in the error path of this function,
which changes the error message to

fatal: BUG: packed_refs_unlock() called when not locked

Move the call to packed_refs_unlock() above the "cleanup:" label
since the unlocking should only be done in the last error path.

Signed-off-by: Mathias Rav <m@git.strova.dk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agosha1_file: improve sha1_file_name() perfs
Christian Couder [Thu, 18 Jan 2018 10:08:54 +0000 (11:08 +0100)] 
sha1_file: improve sha1_file_name() perfs

As sha1_file_name() could be performance sensitive, let's
make it faster by using strbuf_addstr() and strbuf_addc()
instead of strbuf_addf().

Helped-by: Derrick Stolee <stolee@gmail.com>
Helped-by: Jeff Hostetler <git@jeffhostetler.com>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agohttp: support omitting data from traces
Jonathan Tan [Fri, 19 Jan 2018 00:28:02 +0000 (16:28 -0800)] 
http: support omitting data from traces

GIT_TRACE_CURL provides a way to debug what is being sent and received
over HTTP, with automatic redaction of sensitive information. But it
also logs data transmissions, which significantly increases the log file
size, sometimes unnecessarily. Add an option "GIT_TRACE_CURL_NO_DATA" to
allow the user to omit such data transmissions.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agohttp: support cookie redaction when tracing
Jonathan Tan [Fri, 19 Jan 2018 00:28:01 +0000 (16:28 -0800)] 
http: support cookie redaction when tracing

When using GIT_TRACE_CURL, Git already redacts the "Authorization:" and
"Proxy-Authorization:" HTTP headers. Extend this redaction to a
user-specified list of cookies, specified through the
"GIT_REDACT_COOKIES" environment variable.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agococci: use format keyword instead of a literal string
René Scharfe [Fri, 19 Jan 2018 17:05:59 +0000 (18:05 +0100)] 
cocci: use format keyword instead of a literal string

There's a rule in strbuf.cocci for converting trivial uses of
strbuf_addf() to strbuf_addstr() in order to simplify the code and
improve performance a bit.  Coccinelle 1.0.0~rc19.deb-3 on Travis CI
lets the "%s" in that rule match format strings like "%d" as well for
some reason, though, leading to invalid proposed patches.

Use the "format" keyword to let Coccinelle parse the format string and
match the conversion specifier with a trivial regular expression
instead.  This works fine with both Coccinelle 1.0.0~rc19.deb-3 and
1.0.4.deb-3+b3 (the current version on Debian testing).

Reported-by: SZEDER Gábor <szeder.dev@gmail.com>
Tested-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agopackfile: use get_be64() for large offsets
Derrick Stolee [Wed, 17 Jan 2018 19:08:23 +0000 (14:08 -0500)] 
packfile: use get_be64() for large offsets

The pack-index version 2 format uses two 4-byte integers in
network-byte order to represent one 8-byte value. The current
implementation has several code clones for stitching these integers
together.

Use get_be64() to create an 8-byte integer from two 4-byte integers
represented this way.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agorun-command.c: print new cwd in trace_run_command()
Nguyễn Thái Ngọc Duy [Thu, 18 Jan 2018 09:45:12 +0000 (16:45 +0700)] 
run-command.c: print new cwd in trace_run_command()

If a command sets a new env variable GIT_DIR=.git, we need more context
to know where that '.git' is related to.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
6 years agorun-command.c: print env vars in trace_run_command()
Nguyễn Thái Ngọc Duy [Thu, 18 Jan 2018 09:45:11 +0000 (16:45 +0700)] 
run-command.c: print env vars in trace_run_command()

Occasionally submodule code could execute new commands with GIT_DIR set
to some submodule. GIT_TRACE prints just the command line which makes it
hard to tell that it's not really executed on this repository.

Print the env delta (compared to parent environment) in this case.

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