Commit Graph

87587 Commits

Author SHA1 Message Date
Johannes Schindelin
bd522cfec0 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>
2018-08-28 16:19:45 -04:00
Johannes Schindelin
1181037e36 t5505,t5516: create .git/branches/ when needed
It is a real old anachronism from the Cogito days to have a
.git/branches/ directory. And to have tests that ensure that Cogito
users can migrate away from using that directory.

But so be it, let's continue testing it.

Let's make sure, however, that git init does not need to create that
directory.

This bug was noticed when testing with templates that had been
pre-committed, skipping the empty branches/ directory of course because
Git does not track empty directories.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2018-08-28 16:19:41 -04:00
Johannes Schindelin
dc2f860b6f windows: clarify the need for invalidcontinue.obj
Git's source code wants to be able to close() the same file descriptor
multiple times, ignoring the error returned by the second call (and the
ones after that), or to access the osfhandle of an already-closed stdout,
among other things that the UCRT does not like.

Simply linking invalidcontinue.obj allows such usage without resorting to
Debug Assertions (or exiting with exit code 9 in Release Mode).

Let's add a note so we don't forget, as suggested by Jeff Hostetler.

See https://msdn.microsoft.com/en-us/library/ms235330.aspx for more
details.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2018-08-28 16:19:41 -04:00
Johannes Schindelin
9130318fc6 Ensure that bin-wrappers/* targets adds .exe if necessary
When compiling with Visual Studio, the projects' names are identical to
the executables modulo the extensions. Which means that the bin-wrappers
*need* to target the .exe files lest they try to execute directories.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2018-08-28 16:19:41 -04:00
Johannes Schindelin
a230c2a764 terminal.c: guard the inclusion of inttypes.h
We do have a lovely Makefile option to state that that header file is
not available. Let's use it everywhere...

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2018-08-28 16:19:40 -04:00
Johannes Schindelin
03f536ff18 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>
2018-08-28 16:19:40 -04:00
Johannes Schindelin
ad297025bf compat/vcbuild: possibly reuse Git for Windows' SDK's NuGet
In Git for Windows' SDK, there is already a script to package Git for
Windows as a NuGet package, downloading nuget.exe if needed.

Let's just fall back to using that executable (if it is there) if
nuget.exe was not found in the PATH.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2018-08-28 16:19:37 -04:00
Jeff Hostetler
1384a8db8e vs2015: remove todo list item from README_vs2015.txt
Remove todo list item for vs2015 build notes regarding
the third party DLLs.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
2018-08-28 16:19:37 -04:00
Jeff Hostetler
c59f3ac59e vs2015: teach 'make clean' to delete PDBs
Teach main Makefile to also delete the generated PDB files
as well as the PDB files for the various EXE files during
"make MSVC=1 clean".

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
2018-08-28 16:19:37 -04:00
Jeff Hostetler
dd9a9754f0 vs2015: turn on optimize-for-speed in release build
Set -O2 (maximize speed) rather than -Os (favor small code)
for non-debug builds.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
2018-08-28 16:19:36 -04:00
Johannes Schindelin
71511b32a1 t7800: fix quoting
When passing a command-line to call an external diff command to the
difftool, we must be prepared for paths containing special characters,
e.g. backslashes in the temporary directory's path on Windows.

This has been caught by running the test suite with an MSVC-built Git:
in contrast to the MINGW one, it does not rewrite `$TMP` to use forward
slashes instead of backslashes.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2018-08-28 16:19:36 -04:00
Johannes Schindelin
3622558b79 msvc: work around iconv() not setting errno
When compiling with MSVC, we rely on NuPkgs to provide the binaries of
dependencies such as libiconv. The libiconv 1.14.0.11 package available
from https://www.nuget.org/packages/libiconv seems to have a bug where
it does not set errno (when we would expect it to be E2BIG).

Let's simulate the error condition by taking less than 16 bytes
remaining in the out buffer as an indicator that we ran out of space.
While 16 might seem a bit excessive (when converting from, say, any
encoding to UTF-8, 8 bytes should be fine), it is designed to be a safe
margin.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2018-08-28 16:19:36 -04:00
Johannes Schindelin
e41afded07 msvc: use libiconv
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2018-08-28 16:19:36 -04:00
Jeff Hostetler
c616053910 msvc: use OpenSSL's SHA-1 routines
Just like 1e2ce1d (sha1: Use OpenSSL SHA1 routines on MINGW, 2016-10-12),
we now use OpenSSL's SHA-1 routines instead of Git's own because OpenSSL
is substantially faster as of version 1.0.2: it now uses hardware
acceleration on Intel processors much more effectively.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2018-08-28 16:19:36 -04:00
Johannes Schindelin
2a5134615b msvc: respect the quiet-by-default output
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2018-08-28 16:19:36 -04:00
Jeff Hostetler
9bbb96a95c msvc: release mode PDBs and library DLLs
Install required third-party DLLs next to EXEs.

Build and install release mode PDBs for git
executables allowing detailed stack traces
in the event of crash.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
2018-08-28 16:19:36 -04:00
Jeff Hostetler
0134a3dea6 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>
2018-08-28 16:19:36 -04:00
Jeff Hostetler
bf791e57e2 msvc: fix detect_msys_tty()
The ntstatus.h header is only available in MINGW.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
2018-08-28 16:19:15 -04:00
Jeff Hostetler
2f9013decb msvc: define ftello()
It is just called different in MSVC's headers.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
2018-08-28 16:19:03 -04:00
Jeff Hostetler
a4e18bc97b msvc: do not re-declare the timespec struct
VS2015's headers already declare that struct.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
2018-08-28 16:19:03 -04:00
Jeff Hostetler
3d4428b7b2 msvc: provide a main() wrapper similar to mingw_main()
The MINGW version of the main() wrapper gets away with declaring symbols
that were intentionally not exported. However, some of these symbols do
not actually exist in MSVC's UCRT.

So let's add an MSVC version of the main() wrapper that uses wmain() and
imports the UNICODE argv and environment. While at it, we pass our UTF-8
version of ARGV to the real main -- rather than overwriting __argv as is
done in the MINGW Version.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
2018-08-28 16:18:46 -04:00
Jeff Hostetler
987cf920cf 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>
2018-08-28 16:18:13 -04:00
Jeff Hostetler
fdd46b6e2f 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>
2018-08-28 16:18:13 -04:00
Jeff Hostetler
0d25f4e6ec msvc: convert environment from/to UTF-16 on the fly
This adds MSVC versions of getenv() and friends. These take UTF-8
arguments and return UTF-8 values, but use the UNICODE versions
of the CRT routines.  This avoids the need to write to __environ
(which is only visible if you statically link to the CRT).  This
also avoids the CP_ACP conversions performed inside the CRT.
It also avoids various memory leaks and problems.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
2018-08-28 16:18:13 -04:00
Philip Oakley
ee2328da06 msvc: fix the declaration of the _REPARSE_DATA_BUFFER structure
GCC and MSVC disagree about using the GCC extension _ANONYMOUS_UNION.
Simply skip that offending keyword when compiling with MSVC.

Signed-off-by: Philip Oakley <philipoakley@iee.org>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2018-08-28 16:18:12 -04:00
Philip Oakley
a2074789f1 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>
2018-08-28 16:18:12 -04:00
Philip Oakley
bb18847b65 msvc: include sigset_t definition
On MSVC (VS2008) sigset_t is not defined.

Signed-off-by: Philip Oakley <philipoakley@iee.org>
2018-08-28 16:18:12 -04:00
Jeff Hostetler
faefa36828 msvc: update Makefile and compiler settings for VS2015
Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
2018-08-28 16:18:12 -04:00
Jeff Hostetler
b86dcc0592 msvc: update compile helper for VS2015
Support -Z flags ("specify PDB options"), only include -l args on link
commands, and force PDBs to be created.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
2018-08-28 16:18:12 -04:00
Jeff Hostetler
ec0610e6c8 msvc: add NuGet scripts for building with VS2015
This commit contains a GNU Makefile and NuGet configuration scripts to
download and install the various third-party libraries that we will need
to build/link with when using VS2015 to build Git.

The file "compat/vcbuild/README_VS2015.txt" contains instructions for
using this.

In this commit, "compat/vcbuild/Makefile" contains hard-coded version
numbers of the packages we require.  These are set to the current
versions as of the time of this commit.  We use "nuget restore" to
install them explicitly using a "package.config".  A future improvement
would try to use some of the automatic package management functions and
eliminate the need to specify exact versions.  I tried, but could not
get this to work.  NuGet was happy dowload "minimum requirements" rather
than "lastest" for dependencies -- and only look at one package at a
time.  For example, both curl and openssl depend upon zlib and have
different minimums.  It was unclear which version of zlib would be
installed and seemed to be dependent on the order of the top-level
packages.  So, I'm skipping that for now.

We need to be very precise when specifying NuGet package versions: while
nuget.exe auto-completes a version, say, 1.0.2 to 1.0.2.0, we will want
to parse packages.config ourselves, to generate the Visual Studio
solution, and there we need the exact version number to be able to
generate the exact path to the correct .targets file.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
2018-08-28 16:18:12 -04:00
Jeff Hostetler
28b0e43148 msvc: ignore VS2015 trash files
Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
2018-08-28 16:18:12 -04:00
Johannes Schindelin
d634c1b738 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>
2018-08-28 16:18:11 -04:00
Karsten Blees
52096e4e8a Win32: implement nanosecond-precision file times
We no longer use any of MSVCRT's stat-functions, so there's no need to
stick to a CRT-compatible 'struct stat' either.

Define and use our own POSIX-2013-compatible 'struct stat' with nanosecond-
precision file times.

Note: Due to performance issues when using git variants with different file
time resolutions, this patch does *not* yet enable nanosecond precision in
the Makefile (use 'make USE_NSEC=1').

Signed-off-by: Karsten Blees <blees@dcon.de>
2018-08-28 16:18:09 -04:00
Karsten Blees
78e94d9df4 Win32: replace MSVCRT's fstat() with a Win32-based implementation
fstat() is the only stat-related CRT function for which we don't have a
full replacement yet (and thus the only reason to stick with MSVCRT's
'struct stat' definition).

Fully implement fstat(), in preparation of implementing a POSIX 2013
compatible 'struct stat' with nanosecond-precision file times.

Signed-off-by: Karsten Blees <blees@dcon.de>
2018-08-28 16:18:08 -04:00
Loris Chiocca
4a06b56e77 The stat() function should be independent of core.symlinks
The contract for the stat() and lstat() function is:
> stat():  stats the file pointed to by path and fills in buf.
> lstat(): is identical to stat(), except that if path is a symbolic link,
>          then the link itself is stat-ed, not the file that it refers to.

stat() should always return the statistics of the file or directory a
symbolic link is pointing to. The lstat() function is used to get the
stats for the symlink. Hence the check should not be there.

Signed-off-by: Loris Chiocca <loris@chiocca.ch>
2018-08-28 16:17:50 -04:00
Johannes Schindelin
1d1e9a350f mingw: keep trailing slashes for _wchdir() and readlink()
This is needed so that `_wchdir()` can be used with drive root
directories, e.g. C:\ (`_wchdir("C:")` fails to switch the directory
to the root directory).

This fixes https://github.com/msysgit/git/issues/359 (in Git for Windows
2.x only, though).

Likewise, `readlink()`'s semantics require a trailing slash for symbolic
links pointing to directories. Otherwise all checked out symbolic links
pointing to directories would be marked as modified even directly after a
fresh clone.

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

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2018-08-28 16:16:40 -04:00
Karsten Blees
466c3e844f Win32: symlink: add support for symlinks to directories
Symlinks on Windows have a flag that indicates whether the target is a file
or a directory. Symlinks of wrong type simply don't work. This even affects
core Win32 APIs (e.g. DeleteFile() refuses to delete directory symlinks).

However, CreateFile() with FILE_FLAG_BACKUP_SEMANTICS doesn't seem to care.
Check the target type by first creating a tentative file symlink, opening
it, and checking the type of the resulting handle. If it is a directory,
recreate the symlink with the directory flag set.

It is possible to create symlinks before the target exists (or in case of
symlinks to symlinks: before the target type is known). If this happens,
create a tentative file symlink and postpone the directory decision: keep
a list of phantom symlinks to be processed whenever a new directory is
created in mingw_mkdir().

Limitations: This algorithm may fail if a link target changes from file to
directory or vice versa, or if the target directory is created in another
process.

Signed-off-by: Karsten Blees <blees@dcon.de>
2018-08-28 16:16:40 -04:00
Karsten Blees
59e7a2ac5e Win32: implement basic symlink() functionality (file symlinks only)
Implement symlink() that always creates file symlinks. Fails with ENOSYS
if symlinks are disabled or unsupported.

Note: CreateSymbolicLinkW() was introduced with symlink support in Windows
Vista. For compatibility with Windows XP, we need to load it dynamically
and fail gracefully if it isnt's available.

Signed-off-by: Karsten Blees <blees@dcon.de>
2018-08-28 16:16:39 -04:00
Karsten Blees
4967a67c4b Win32: implement readlink()
Implement readlink() by reading NTFS reparse points. Works for symlinks
and directory junctions. If symlinks are disabled, fail with ENOSYS.

Signed-off-by: Karsten Blees <blees@dcon.de>
2018-08-28 16:16:39 -04:00
Karsten Blees
4713566672 Win32: mingw_chdir: change to symlink-resolved directory
If symlinks are enabled, resolve all symlinks when changing directories,
as required by POSIX.

Note: Git's real_path() function bases its link resolution algorithm on
this property of chdir(). Unfortunately, the current directory on Windows
is limited to only MAX_PATH (260) characters. Therefore using symlinks and
long paths in combination may be problematic.

Note: GetFinalPathNameByHandleW() was introduced with symlink support in
Windows Vista. Thus, for compatibility with Windows XP, we need to load it
dynamically and behave gracefully if it isnt's available.

Signed-off-by: Karsten Blees <blees@dcon.de>
2018-08-28 16:16:39 -04:00
Karsten Blees
64b35811a6 Win32: mingw_rename: support renaming symlinks
MSVCRT's _wrename() cannot rename symlinks over existing files: it returns
success without doing anything. Newer MSVCR*.dll versions probably do not
have this problem: according to CRT sources, they just call MoveFileEx()
with the MOVEFILE_COPY_ALLOWED flag.

Get rid of _wrename() and call MoveFileEx() with proper error handling.

Signed-off-by: Karsten Blees <blees@dcon.de>
2018-08-28 16:16:39 -04:00
Karsten Blees
37a26a8a21 Win32: mingw_unlink: support symlinks to directories
_wunlink() / DeleteFileW() refuses to delete symlinks to directories. If
_wunlink() fails with ERROR_ACCESS_DENIED, try _wrmdir() as well.

Signed-off-by: Karsten Blees <blees@dcon.de>
2018-08-28 16:16:39 -04:00
Karsten Blees
ca365f470b Win32: add symlink-specific error codes
Signed-off-by: Karsten Blees <blees@dcon.de>
2018-08-28 16:16:39 -04:00
Karsten Blees
4c6502c35e Win32: change default of 'core.symlinks' to false
Symlinks on Windows don't work the same way as on Unix systems. E.g. there
are different types of symlinks for directories and files, creating
symlinks requires administrative privileges etc.

By default, disable symlink support on Windows. I.e. users explicitly have
to enable it with 'git config [--system|--global] core.symlinks true'.

The test suite ignores system / global config files. Allow testing *with*
symlink support by checking if native symlinks are enabled in MSys2 (via
'MSYS=winsymlinks:nativestrict').

Reminder: This would need to be changed if / when we find a way to run the
test suite in a non-MSys-based shell (e.g. dash).

Signed-off-by: Karsten Blees <blees@dcon.de>
2018-08-28 16:16:39 -04:00
Karsten Blees
0cb5c52372 Win32: factor out retry logic
The retry pattern is duplicated in three places. It also seems to be too
hard to use: mingw_unlink() and mingw_rmdir() duplicate the code to retry,
and both of them do so incompletely. They also do not restore errno if the
user answers 'no'.

Introduce a retry_ask_yes_no() helper function that handles retry with
small delay, asking the user, and restoring errno.

mingw_unlink: include _wchmod in the retry loop (which may fail if the
file is locked exclusively).

mingw_rmdir: include special error handling in the retry loop.

Signed-off-by: Karsten Blees <blees@dcon.de>
2018-08-28 16:16:39 -04:00
Karsten Blees
df3028e814 Win32: lstat(): return adequate stat.st_size for symlinks
Git typically doesn't trust the stat.st_size member of symlinks (e.g. see
strbuf_readlink()). However, some functions take shortcuts if st_size is 0
(e.g. diff_populate_filespec()).

In mingw_lstat() and fscache_lstat(), make sure to return an adequate size.

The extra overhead of opening and reading the reparse point to calculate
the exact size is not necessary, as git doesn't rely on the value anyway.

Signed-off-by: Karsten Blees <blees@dcon.de>
2018-08-28 16:16:39 -04:00
Karsten Blees
4602d72b99 Win32: teach fscache and dirent about symlinks
Move S_IFLNK detection to file_attr_to_st_mode() and reuse it in fscache.

Implement DT_LNK detection in dirent.c and the fscache readdir version.

Signed-off-by: Karsten Blees <blees@dcon.de>
2018-08-28 16:15:31 -04:00
Karsten Blees
a89dc21d82 Win32: let mingw_lstat() error early upon problems with reparse points
When obtaining lstat information for reparse points, we need to call
FindFirstFile() in addition to GetFileInformationEx() to obtain the type
of the reparse point (symlink, mount point etc.). However, currently there
is no error handling whatsoever if FindFirstFile() fails.

Call FindFirstFile() before modifying the stat *buf output parameter and
error out if the call fails.

Note: The FindFirstFile() return value includes all the data that we get
from GetFileAttributesEx(), so we could replace GetFileAttributesEx() with
FindFirstFile(). We don't do that because GetFileAttributesEx() is about
twice as fast for single files. I.e. we only pay the extra cost of calling
FindFirstFile() in the rare case that we encounter a reparse point.

Note: The indentation of the remaining reparse point code will be fixed in
the next patch.

Signed-off-by: Karsten Blees <blees@dcon.de>
2018-08-28 16:13:33 -04:00
Karsten Blees
3e0f0012b6 Win32: remove separate do_lstat() function
With the new mingw_stat() implementation, do_lstat() is only called from
mingw_lstat() (with follow == 0). Remove the extra function and the old
mingw_stat()-specific (follow == 1) logic.

Signed-off-by: Karsten Blees <blees@dcon.de>
2018-08-28 16:13:33 -04:00
Karsten Blees
0a31c8c481 Win32: implement stat() with symlink support
With respect to symlinks, the current stat() implementation is almost the
same as lstat(): except for the file type (st_mode & S_IFMT), it returns
information about the link rather than the target.

Implement stat by opening the file with as little permissions as possible
and calling GetFileInformationByHandle on it. This way, all link resoltion
is handled by the Windows file system layer.

If symlinks are disabled, use lstat() as before, but fail with ELOOP if a
symlink would have to be resolved.

Signed-off-by: Karsten Blees <blees@dcon.de>
2018-08-28 16:13:33 -04:00