Commit Graph

97118 Commits

Author SHA1 Message Date
Johannes Schindelin
097e78b166 Vcproj.pm: auto-generate GUIDs
We ran out GUIDs. Again. But there is no need to: we can generate them
semi-randomly from the target file name of the project.

Note: the Vcproj generator is probably only interesting for historical
reasons; nevertheless, the upcoming Vcxproj generator (to support modern
Visual Studio versions) is based on the Vcproj generator and it is
better to fix this here first.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-13 22:36:47 +02:00
Johannes Schindelin
ba53545ba8 msvc: add forgotten source file
In 1cadad6f65 (git clone <url> C:\cygwin\home\USER\repo' is working
(again), 2018-12-15), we introduced a new source file, containing
utility functions on Windows. But we forgot to adjust the MSVC section.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-13 22:36:47 +02:00
Jeff Hostetler
b545a67b18 msvc: ignore .dll and incremental compile output
Ignore .dll files copied into the top-level directory.
Ignore MSVC incremental compiler output files.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-13 22:36:47 +02:00
Johannes Schindelin
42cf976264 msvc: avoid debug assertion windows in Debug Mode
For regular debugging, it is pretty helpful when a debug assertion in a
running application triggers a window that offers to start the debugger.

However, when running the test suite, it is not so helpful, in
particular when the debug assertions are then suppressed anyway because
we disable the invalid parameter checking (via invalidcontinue.obj, see
the comment in config.mak.uname about that object for more information).

So let's simply disable that window in Debug Mode (it is already
disabled in Release Mode).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-13 22:36:47 +02:00
Jeff Hostetler
3bf50026e6 msvc: support building Git using MS Visual C++
With this patch, Git can be built using the Microsoft toolchain, via:

	make MSVC=1 [DEBUG=1]

Third party libraries are built from source using the open source
"vcpkg" tool set. See https://github.com/Microsoft/vcpkg

On a first build, the vcpkg tools and the third party libraries are
automatically downloaded and built. DLLs for the third party libraries
are copied to the top-level (and t/helper) directory to facilitate
debugging. See compat/vcbuild/README.

A series of .bat files are invoked by the Makefile to find the location
of the installed version of Visual Studio and the associated compiler
tools (essentially replicating the environment setup performed by a
"Developer Command Prompt"). This should find the most recent VS2015 or
VS2017 installation. Output from these scripts are used by the Makefile
to define compiler and linker pathnames and -I and -L arguments.

The build produces .pdb files for both debug and release builds.

Note: This commit was squashed from an organic series of commits
developed between 2016 and 2018 in Git for Windows' `master` branch.
This combined commit eliminates the obsolete commits related to fetching
NuGet packages for third party libraries. It is difficult to use NuGet
packages for C/C++ sources because they may be built by earlier versions
of the MSVC compiler and have CRT version and linking issues.
Additionally, the C/C++ NuGet packages that were using tended to not be
updated concurrently with the sources.  And in the case of cURL and
OpenSSL, this could expose us to security issues.

Helped-by: Yue Lin Ho <b8732003@student.nsysu.edu.tw>
Helped-by: Philip Oakley <philipoakley@iee.org>
Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-13 22:36:47 +02:00
Jeff Hostetler
f4775ace48 msvc: do not pretend to support all signals
This special-cases various signals that are not supported on Windows,
such as SIGPIPE. These cause the UCRT to throw asserts (at least in
debug mode).

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
2019-05-13 22:36:47 +02:00
Philip Oakley
545c641bd8 msvc: add pragmas for common warnings
MSVC can be overzealous about some warnings. Disable them.

Signed-off-by: Philip Oakley <philipoakley@iee.org>
2019-05-13 22:36:47 +02:00
Jeff Hostetler
e5e5956dbd msvc: fix detect_msys_tty()
The ntstatus.h header is only available in MINGW.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
2019-05-13 22:36:47 +02:00
Jeff Hostetler
8e6b209d72 msvc: define ftello()
It is just called differently in MSVC's headers.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-13 22:36:47 +02:00
Jeff Hostetler
c79027c39d msvc: do not re-declare the timespec struct
VS2015's headers already declare that struct.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
2019-05-13 22:36:47 +02:00
Jeff Hostetler
1a00f14d23 msvc: mark a variable as non-const
VS2015 complains when using a const pointer in memcpy()/free().

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
2019-05-13 22:36:47 +02:00
Philip Oakley
a2cded0269 msvc: define O_ACCMODE
This constant is not defined in MSVC's headers.

In UCRT's fcntl.h, _O_RDONLY, _O_WRONLY and _O_RDWR are defined as 0, 1
and 2, respectively. Yes, that means that UCRT breaks with the tradition
that O_RDWR == O_RDONLY | O_WRONLY.

It is a perfectly legal way to define those constants, though, therefore
we need to take care of defining O_ACCMODE accordingly.

This is particularly important in order to keep our "open() can set
errno to EISDIR" emulation working: it tests that (flags & O_ACCMODE) is
not identical to O_RDONLY before going on to test specifically whether
the file for which open() reported EACCES is, in fact, a directory.

Signed-off-by: Philip Oakley <philipoakley@iee.org>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-13 22:36:47 +02:00
Philip Oakley
da2784c10f msvc: include sigset_t definition
On MSVC (VS2008) sigset_t is not defined.

Signed-off-by: Philip Oakley <philipoakley@iee.org>
2019-05-13 22:36:47 +02:00
Johannes Schindelin
09a8bedb5e msvc: fix dependencies of compat/msvc.c
The file compat/msvc.c includes compat/mingw.c, which means that we have
to recompile compat/msvc.o if compat/mingw.c changes.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-13 22:36:46 +02:00
Johannes Schindelin
e35f69c170 mingw: replace mingw_startup() hack
Git for Windows has special code to retrieve the command-line parameters
(and even the environment) in UTF-16 encoding, so that they can be
converted to UTF-8. This is necessary because Git for Windows wants to
use UTF-8 encoded strings throughout its code, and the main() function
does not get the parameters in that encoding.

To do that, we used the __wgetmainargs() function, which is not even a
Win32 API function, but provided by the MINGW "runtime" instead.

Obviously, this method would not work with any other compiler than GCC,
and in preparation for compiling with Visual C++, we would like to avoid
that.

Lucky us, there is a much more elegant way: we simply implement wmain()
and link with -municode. The command-line parameters are passed to
wmain() encoded in UTF-16, as desired, and this method also works with
Visual C++ after adjusting the MSVC linker flags to force it to use
wmain().

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-13 22:36:46 +02:00
Johannes Schindelin
2200b1bab3 obstack: fix compiler warning
MS Visual C suggests that the construct

	condition ? (int) i : (ptrdiff_t) d

is incorrect. Let's fix this by casting to ptrdiff_t also for the
positive arm of the conditional.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-13 22:36:46 +02:00
Jeff Hostetler
3ca14bb9d8 cache-tree.c: avoid reusing the DEBUG constant
In MSVC, the DEBUG constant is set automatically whenever compiling with
debug information.

This is clearly not what was intended in cache-tree.c, so let's use a less
ambiguous constant there.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
2019-05-13 22:36:46 +02:00
Johannes Schindelin
a6fd847a35 t0001 (mingw): do not expect specific order of stdout/stderr
When redirecting stdout/stderr to the same file, we cannot guarantee
that stdout will come first.

In fact, in this test case, it seems that an MSVC build always prints
stderr first.

In any case, this test case does not want to verify the *order* but
the *presence* of both outputs, so let's relax the test a little.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-13 22:36:46 +02:00
Johannes Schindelin
7dd79193c8 Mark .bat files as requiring CR/LF endings
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-13 22:36:46 +02:00
Johannes Schindelin
08f5629871 Start the merging-rebase to 7dcd3d86d4
In preparation for v2.22.0-rc0, we rearrange quite a few topics in this
branch thicket.

Apart from a reworded comment, this does not introduce any new change.

This commit starts the rebase of 7dcd3d86d4 to 7dcd3d86d4

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-13 21:22:22 +02:00
Johannes Schindelin
d4e5e1ea92 Merge pull request #2191 from dscho/add-p-fixups
A couple of fixups for add-i-in-c-status-and-help
2019-05-13 19:33:22 +02:00
Johannes Schindelin
c6746a4f41 fixup! Add a function to determine unique prefixes for a list of strings
Let's not walk off the end of the array. Also, avoid an early `malloc()`
in `add_prefix_entry()` (avoiding reuse of the same data structure for
lookup as for adding a new item), and strengthen the condition for the
bug condition.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-13 14:56:18 +02:00
Johannes Schindelin
f159d0dd18 fixup! built-in add -i: implement the main loop
Clarify the role of the "magic" `-1` and `-2` return values of the
`list_and_choose()` function.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-13 14:56:12 +02:00
Johannes Schindelin
e3538d8eb3 Merge pull request #2185 from dscho/fix-status-with-rebase-ir
Fix `git status`' display of `git rebase -ir`'s `label` commands
2019-05-10 22:55:48 +02:00
Johannes Schindelin
ec9eed5c88 status: fix display of rebase -ir's label command
The argument of a `label` command does *not* want to be turned into an
abbreviated SHA-1.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-10 21:32:17 +02:00
Johannes Schindelin
81a060a4d1 Merge pull request #2127 from dscho/fix-fsmonitor
Do query the fsmonitor again after the index has been discarded
2019-05-09 23:04:27 +02:00
Johannes Schindelin
912cfd3f9e fsmonitor: force a refresh after the index was discarded
With this change, the `index_state` struct becomes the new home for the
flag that says whether the fsmonitor hook has been run, i.e. it is now
per-index.

It also gets re-set when the index is discarded, fixing the bug
demonstrated by the "test_expect_failure" test added in the preceding
commit. In that case fsmonitor-enabled Git would miss updates under
certain circumstances, see that preceding commit for details.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-09 21:04:25 +02:00
Johannes Schindelin
328b4a2b06 fsmonitor: demonstrate that it is not refreshed after discard_index()
This one is tricky.

When `core.fsmonitor` is set, a `refresh_index()` will not perform a
full scan of files that might be modified, but will query the fsmonitor
and refresh only the ones that have been actually touched.

Due to implementation details, the fsmonitor is queried in
`refresh_cache_ent()`, but of course it only has to be queried once, so
we set a flag when we did that. But when the index was discarded, we did
not re-set that flag.

So far, this is only covered by our test suite when running with
GIT_TEST_FSMONITOR=$PWD/t7519/fsmonitor-all, and only due to the way the
built-in stash interacts with the recursive merge machinery.

Let's introduce a straight-forward regression test for this.

We simply extend the "read & discard index" loop in `test-tool
read-cache` to optionally refresh the index, report on a given file's
status, and then modify that file. Due to the bug described above, only
the first refresh will actually query the fsmonitor; subsequent loop
iterations will not.

This problem was reported by Ævar Arnfjörð Bjarmason.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-09 21:04:20 +02:00
Johannes Schindelin
2ac5f424d8 Merge pull request #2184 from dscho/address-coverity-report
Fix some issues reported by Coverity
2019-05-09 16:31:19 +02:00
Johannes Schindelin
32b5d74642 Merge branch 'address-coverity-reports'
Coverity pointed out a couple of bugs, and here are fixes for some of
them.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-09 14:51:29 +02:00
Johannes Schindelin
52ac616bd3 fixup! fscache: teach fscache to use NtQueryDirectoryFile
The return value of that function is not actually we are currently able
to translate to an `errno`-style value easily. So let's just not.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-09 14:51:29 +02:00
Johannes Schindelin
2a85ba50fe fixup! fscache: update fscache to be thread specific instead of global
We do fall back to not enabling the FSCache when we're out of
Thread-Local indexes, but we failed to unlock the mutex.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-09 14:51:29 +02:00
Johannes Schindelin
0ccd8caa6a fixup! Introduce helper to create symlinks that knows about index_state
We do not actually need to test for `state != NULL`, as
`state->delayed_checkout` had already been accessed before this.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-09 14:51:28 +02:00
Johannes Schindelin
ea7a305a45 squash! ci: also test with MS Visual C on Azure Pipelines
We specifically reduce the number of parallel links for MSVC, as RAM
usage is an issue with MSVC's parallel mode, manifested in the symptom:

	fatal error LNK1318: Unexpected PDB error; OK (0) ''

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-09 14:51:28 +02:00
Johannes Schindelin
28f28c03fd fixup! built-in add -p: offer a helpful error message when hunk navigation failed
Just an obvious fix for an obvious varargs mistake.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-09 14:50:57 +02:00
Johannes Schindelin
2a2d648516 sequencer: check return value of get_oid()
Just a little defensive coding.

Found by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-09 14:44:14 +02:00
Johannes Schindelin
840b754ed4 bisect--helper: verify HEAD could be parsed before continuing
In 06f5608c14 (bisect--helper: `bisect_start` shell function partially
in C, 2019-01-02), we introduced a call to `get_oid()` and did not check
whether it succeeded before using its output.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-09 14:08:52 +02:00
Johannes Schindelin
d451e84f20 rebase -i: watch out for invalid upstream arguments
This was overlooked in 53bbcfbde7 (rebase -i: implement the main part
of interactive rebase as a builtin, 2018-09-27).

Found by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-09 12:26:46 +02:00
Johannes Schindelin
fd442be344 rebase: replace incorrect logical negation by correct bitwise one
In bff014dac7 (builtin rebase: support the `verbose` and `diffstat`
options, 2018-09-04), we added a line that wanted to remove the
`REBASE_DIFFSTAT` bit from the flags, but it used an incorrect negation.

Found by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-09 12:26:46 +02:00
Johannes Schindelin
65f1570624 Merge pull request #2175 from dscho/difftool-no-index
Allow `git difftool --no-index` to run outside of a worktree
2019-05-08 23:54:15 +02:00
Johannes Schindelin
a930c5a836 Merge pull request #2150 from dscho/add-p-gfw
Offer a built-in version of `git add -i` and `git add -p`
2019-05-08 21:30:53 +02:00
Johannes Schindelin
290a66692c Merge branch 'difftool-no-index-extra'
This patch addresses the segmentation faults in `git difftool --no-index
--dir-diff`: surprisingly, those two options don't make no sense
together.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-08 21:01:39 +02:00
Johannes Schindelin
860e6522f7 Merge branch 'difftool-no-index'
This fixes https://github.com/git-for-windows/git/issues/2123

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-08 21:01:38 +02:00
Johannes Schindelin
cac7f0a6c9 difftool --no-index: error out on --dir-diff (and don't crash)
In `--no-index` mode, we now no longer require a worktree nor a
repository. But some code paths in `difftool` expect those to be
present.

The most notable such code path is the `--dir-diff` one: we use the
existing checkout machinery to copy the files, and that machinery looks
up replacement refs, looks at alternate ODBs, wants to use the worktree
path, etc.

Rather than running into segmentation faults, let's die with an
informative error message.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-08 21:01:37 +02:00
Johannes Schindelin
89dfd5daf2 difftool: allow running outside Git worktrees with --no-index
As far as this developer can tell, the conversion from a Perl script to
a built-in caused the regression in the difftool that it no longer runs
outside of a Git worktree (with `--no-index`, of course).

It is a bit embarrassing that it took over two years after retiring the
Perl version to discover this regression, but at least we now know, and
can do something, about it.

This fixes https://github.com/git-for-windows/git/issues/2123

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-08 21:01:37 +02:00
Johannes Schindelin
9732ed19da parse-options: make OPT_ARGUMENT() more useful
`OPT_ARGUMENT()` is intended to keep the specified long option in `argv`
and not to do anything else.

However, it would make a lot of sense for the caller to know whether
this option was seen at all or not. For example, we want to teach `git
difftool` to work outside of any Git worktree, but only when
`--no-index` was specified.

Note: nothing in Git uses OPT_ARGUMENT(). Even worse, looking through
the commit history, one can easily see that nothing even
ever used it, apart from the regression test.

So not only do we make `OPT_ARGUMENT()` more useful, we are also about
to introduce its first real user!

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-08 21:01:29 +02:00
Johannes Schindelin
ee7778868f Merge branch 'built-in-stash-and-add-p'
Now that we have a built-in `git add -p` and a built-in `git stash`,
make them play nicely together.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-08 16:20:22 +02:00
Johannes Schindelin
d8850d4e39 Merge branch 'stash-p-corner-case'
This topic branch fixes a corner case that is amazingly common in this
developer's workflow: in a `git stash -p`, splitting a hunk and stashing
only part of it runs into a (known) bug where the partial hunk cannot be
applied in reverse.

It is one of those "good enough" fixes, not a full fix, though, as the
full fix would require a 3-way merge between `stash^` and the *worktree*
(not `HEAD`), with `stash` as merge base (i.e. a `git revert`, but on
top of the current worktree).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-08 16:17:59 +02:00
Johannes Schindelin
b85a6f8009 stash -p: (partially) fix bug concerning split hunks
When trying to stash part of the worktree changes by splitting a hunk
and then only partially accepting the split bits and pieces, the user
is presented with a rather cryptic error:

	error: patch failed: <file>:<line>
	error: test: patch does not apply
	Cannot remove worktree changes

and the command would fail to stash the desired parts of the worktree
changes (even if the `stash` ref was actually updated correctly).

We even have a test case demonstrating that failure, carrying it for
four years already.

The explanation: when splitting a hunk, the changed lines are no longer
separated by more than 3 lines (which is the amount of context lines
Git's diffs use by default), but less than that. So when staging only
part of the diff hunk for stashing, the resulting diff that we want to
apply to the worktree in reverse will contain those changes to be
dropped surrounded by three context lines, but since the diff is
relative to HEAD rather than to the worktree, these context lines will
not match.

Example time. Let's assume that the file README contains these lines:

	We
	the
	people

and the worktree added some lines so that it contains these lines
instead:

	We
	are
	the
	kind
	people

and the user tries to stash the line containing "are", then the command
will internally stage this line to a temporary index file and try to
revert the diff between HEAD and that index file. The diff hunk that
`git stash` tries to revert will look somewhat like this:

	@@ -1776,3 +1776,4
	 We
	+are
	 the
	 people

It is obvious, now, that the trailing context lines overlap with the
part of the original diff hunk that the user did *not* want to stash.

Keeping in mind that context lines in diffs serve the primary purpose of
finding the exact location when the diff does not apply precisely (but
when the exact line number in the file to be patched differs from the
line number indicated in the diff), we work around this by reducing the
amount of context lines: the diff was just generated.

Note: this is not a *full* fix for the issue. Just as demonstrated in
t3701's 'add -p works with pathological context lines' test case, there
are ambiguities in the diff format. It is very rare in practice, of
course, to encounter such repeated lines.

The full solution for such cases would be to replace the approach of
generating a diff from the stash and then applying it in reverse by
emulating `git revert` (i.e. doing a 3-way merge). However, in `git
stash -p` it would not apply to `HEAD` but instead to the worktree,
which makes this non-trivial to implement as long as we also maintain a
scripted version of `add -i`.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-08 16:17:58 +02:00
Johannes Schindelin
9c4ed70beb t3904: fix incorrect demonstration of a bug
In 7e9e048661 (stash -p: demonstrate failure of split with mixed y/n,
2015-04-16), a regression test for a known breakage that was added to
the test script `t3904-stash-patch.sh` that demonstrated that splitting
a hunk and trying to stash only part of that split hunk fails (but
shouldn't).

As expected, it still fails, but for the wrong reason: once the bug is
fixed, we would expect stderr to show nothing, yet the regression test
expects stderr to show something.

Let's fix that by telling that regression test case to expect nothing to
be printed to stderr.

While at it, also drop the obvious left-over from debugging where the
regression test did not mind `git stash -p` to return a non-zero exit
status.

Of course, the regression test still fails, but this time for the
correct reason.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-05-08 16:17:58 +02:00