Commit Graph

56305 Commits

Author SHA1 Message Date
Johannes Schindelin
32d09cfdac fixup! Special-case the MSYS2_TZ environment variable
It is no longer necessary, as Git for Windows' fork of the MSYS2
runtime knows to pass on POSIX-compliant timezones.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-26 16:59:58 +01:00
Johannes Schindelin
e82d9c7bed fixup! criss cross rename failure workaround
This patch has been merged in a slightly different form, and the
left-over patch is bogus (and has not been caught for a long time
by this maintainer).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-26 16:59:58 +01:00
Johannes Schindelin
06d0ace55c squash! Enable support for perl regular expressions (LIBPCRE)
Replace commit message by:

mingw (MSys1): enable support for perl regular expressions

In msysGit, we do have libpcre.

Signed-off-by: Thomas Braun <thomas.braun@byte-physics.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-23 09:32:46 +01:00
Johannes Schindelin
21256564bf squash! Win32: support long paths
[jes: adjusted test number to avoid conflicts, reinstated && chain]
2016-01-21 13:43:43 +01:00
Johannes Schindelin
0070717bd1 Merge 'aslr' into HEAD
Address Space Layout Randomization (ASLR) allows executables' memory
layout to change at random between runs, and therefore offers a quite
decent protection against many attacks.

We enable ASLR because MSYS2's C compiler offers support for ASLR, and
whatever performance impact it has is neglible, according to
https://insights.sei.cmu.edu/cert/2014/02/differences-between-aslr-on-windows-and-linux.html

This merges the part of https://github.com/git-for-windows/git/pull/612
that does not break Git ;-)

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

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-21 13:29:08 +01:00
İsmail Dönmez
dea54431d6 Enable DEP and ASLR
Enable DEP (Data Execution Prevention) and ASLR (Address Space Layout
Randomization) support. This applies to both 32bit and 64bit builds
and makes it substantially harder to exploit security holes in Git by
offering a much more unpredictable attack surface.

Signed-off-by: İsmail Dönmez <ismail@i10z.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-21 13:17:02 +01:00
İsmail Dönmez
bf2d5d8239 Don't let ld strip relocations
This is the first step for enabling ASLR (Address Space Layout
Randomization) support. We want to enable ASLR for better protection
against exploiting security holes in Git.

The problem fixed by this commit is that `ld.exe` seems to be stripping
relocations which in turn will break ASLR support. We just make sure
it's not stripping the main executable entry.

Signed-off-by: İsmail Dönmez <ismail@i10z.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-21 13:15:24 +01:00
Johannes Schindelin
a41b1481ba Merge pull request #606 from skvoboo/issue_598
Use GetFinalPathNameByHandleW instead of GetLongPathNameW to get full path
2016-01-21 13:06:23 +01:00
Anton Serbulov
3700315f0d mingw: fix getcwd when the parent directory cannot be queried
`GetLongPathName()` function may fail when it is unable to query
the parent directory of a path component to determine the long name
for that component. It happens, because of it uses `FindFirstFile()`
function for each next short part of path. The `FindFirstFile()`
requires `List Directory` and `Synchronize` desired access for a calling
process.

In case of lacking such permission for some part of path,
the `GetLongPathName()` returns 0 as result and `GetLastError()`
returns ERROR_ACCESS_DENIED.

`GetFinalPathNameByHandle()` function can help in such cases, because
it requires `Read Attributes` and `Synchronize` desired access to the
target path only.

The `GetFinalPathNameByHandle()` function was introduced on
`Windows Server 2008/Windows Vista`. So we need to load it dynamically.

`CreateFile()` parameters:
    `lpFileName` = path to the current directory
    `dwDesiredAccess` = 0 (it means `Read Attributes` and `Synchronize`)
    `dwShareMode` = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE
                    (it prevents `Sharing Violation`)
    `lpSecurityAttributes` = NULL (default security attributes)
    `dwCreationDisposition` = OPEN_EXISTING
                              (required to obtain a directory handle)
    `dwFlagsAndAttributes` = FILE_FLAG_BACKUP_SEMANTICS
                             (required to obtain a directory handle)
    `hTemplateFile` = NULL (when opening an existing file or directory,
                            `CreateFile` ignores this parameter)

The string that is returned by `GetFinalPathNameByHandle()` function
uses the \\?\ syntax. To skip the prefix and convert backslashes
to slashes, the `normalize_ntpath()` mingw function will be used.

Note: `GetFinalPathNameByHandle()` function returns a final path.
It is the path that is returned when a path is fully resolved.
For example, for a symbolic link named "C:\tmp\mydir" that points to
"D:\yourdir", the final path would be "D:\yourdir".

Signed-off-by: Anton Serbulov <aserbulov@plesk.com>
2016-01-21 12:57:42 +06:00
Johannes Schindelin
78ce6bc19e fixup! Provide a dirname() function when NO_LIBGEN_H=YesPlease 2016-01-12 08:54:19 +01:00
Johannes Schindelin
8a71fd7ab0 Merge branch 'libgen-win'
This topic branch squashes the annoying compiler warning claiming that
`dirname()` was not declared.

For some strange reason, changing `basename()` to conform to POSIX does
not re-introduce https://github.com/git-for-windows/git/issues/494. This
developer assumes that the problem in the test suite were somehow fixed
in the meantime, but lacks the time to verify that claim...

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-08 15:33:25 +01:00
Johannes Schindelin
7270857abc t0060: verify that basename() and dirname() work as expected
Unfortunately, some libgen implementations yield outcomes different from
what Git expects. For example, mingw-w64-crt provides a basename()
function, that shortens `path0/` to `path`!

So let's verify that the basename() and dirname() functions we use conform
to what Git expects.

Derived-from-code-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-06 16:01:45 +01:00
Johannes Schindelin
64cdd7c832 Provide a dirname() function when NO_LIBGEN_H=YesPlease
When there is no `libgen.h` to our disposal, we miss the `dirname()`
function.

So far, we only had one user of that function: credential-cache--daemon
(which was only compiled when Unix sockets are available, anyway). But
now we also have `builtin/am.c` as user, so we need it.

Since `dirname()` is a sibling of `basename()`, we simply put our very
own `gitdirname()` implementation next to `gitbasename()` and use it
if `NO_LIBGEN_H` has been set.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-06 16:01:44 +01:00
Johannes Schindelin
51c8f38fbc compat/basename: make basename() conform to POSIX
According to POSIX, basename("/path/") should return "path", not
"path/". Likewise, basename(NULL) and basename("abc") should both
return ".".

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-06 16:01:43 +01:00
Johannes Schindelin
ffcd315739 Refactor skipping DOS drive prefixes
Junio Hamano pointed out that there is an implicit assumption in pretty
much all the code calling has_dos_drive_prefix(): it assumes that the
DOS drive prefix is always two bytes long.

While this assumption is pretty safe, we can still make the code more
readable and less error-prone by introducing a function that skips the
DOS drive prefix safely.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-06 14:58:59 +01:00
Johannes Schindelin
eb5624e7fa fixup! fast-export: do not refer to non-existing marks 2016-01-05 15:02:07 +01:00
Johannes Schindelin
c6bfb28a9d Windows: force-recompile git.res for differing architectures
When git.rc is compiled into git.res, the result is actually dependent
on the architecture. That is, you cannot simply link a 32-bit git.res
into a 64-bit git.exe.

Therefore, to allow 32-bit and 64-bit builds in the same directory, we
let git.res depend on GIT-PREFIX so that it gets recompiled when
compiling for a different architecture (this works because the exec path
changes based on the architecture: /mingw32/libexec/git-core for 32-bit
and /mingw64/libexec/git-core for 64-bit).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-05 14:52:10 +01:00
Johannes Schindelin
b7006a8229 Merge branch 'rebase-i'
This works around the problem described in
https://github.com/git-for-windows/git/issues/542

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-05 14:51:17 +01:00
Johannes Schindelin
cfdb4c7d68 t3404: fix typo
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-05 14:51:15 +01:00
Johannes Schindelin
5dca2ea2bd Merge pull request #552 from duncansmart/fix-vcproj-gen
Fix Visual Studio .sln/.vcproj generation.
2016-01-05 14:51:13 +01:00
Philip Oakley
0846f91e59 engine.pl: ignore invalidcontinue.obj which is known to MSVC
Commit 4b623d8 (MSVC: link in invalidcontinue.obj for better
POSIX compatibility, 2014-03-29) introduced invalidcontinue.obj
into the Makefile output, which was not parsed correctly by the
buildsystem. Ignore it, as it is known to Visual Studio and,
there is no matching source file.

Only substitute filenames ending with .o when generating the
source .c filename, otherwise a .cbj file may be expected.

Split the .o and .obj processing; 'make' does not produce .obj
files.

In the future there may be source files that produce .obj files
so keep the two issues (.obj files with & without source files)
separate.

Signed-off-by: Philip Oakley <philipoakley@iee.org>
Signed-off-by: Duncan Smart <duncan.smart@gmail.com>

(cherry picked from commit d01d71fe1aed67f4e3a5ab80eeadeaf525ad0846)
2016-01-05 14:51:10 +01:00
Johannes Schindelin
4a3bac0598 Merge branch 'git-wrapper-interpolate'
There was a bug in the wrapper where it would interpolate incorrectly if
the name of the environment variable to expand was longer than the value.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-05 14:51:08 +01:00
Johannes Schindelin
d913aeafbe git-wrapper: fix interpolation with short values
To be precise: when the value of the environment variable is shorter than
its name, we have to move the remaining bytes *after* expanding the
environment variable: we would look for the wrong name otherwise.

When the value is longer than the name, we still need to move the bytes
out of the way first, to avoid overwriting them with the interpolated
text.

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

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-05 14:51:06 +01:00
Johannes Schindelin
239f03df24 git-wrapper: make the interpolation code easier to understand
When moving bytes (because the name and the value of the environment
variable to interpolate differ in length), we introduce a variable to
unclutter the code and make it more obvious what is happening.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-05 14:51:05 +01:00
Johannes Schindelin
56740a8e82 git-wrapper: simplify interpolation code
After we found the `@@` marker after the key to interpolate, we pretty
much only need the offset *after* the marker. So let's just advance it
instead of adding 2 in many places.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-05 14:51:04 +01:00
Johannes Schindelin
919e1b6970 Merge pull request #492 from tomyy/issue-490
git-gui: Use /git-bash.exe if available
2016-01-05 14:51:02 +01:00
Johannes Schindelin
8f50d424e4 Merge pull request #487 from dscho/default-username
Improve the default user name & email logic
2016-01-05 14:51:01 +01:00
Johannes Schindelin
074f54e37c Merge pull request #486 from dscho/mmap-no-error
Better mmap() emulation
2016-01-05 14:51:00 +01:00
Thomas Klaeger
3887ae4e2a git-gui (Windows): use git-bash.exe if it is available
Git for Windows 2.x ships with an executable that starts the Git Bash
with all the environment variables and what not properly set up. It is
also adjusted according to the Terminal emulator option chosen when
installing Git for Windows (while `bash.exe --login -i` would always
launch with Windows' default console).

So let's use that executable (usually C:\Program Files\Git\git-bash.exe)
instead of `bash.exe --login -i` if its presence was detected.

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

Signed-off-by: Thomas Kläger <thomas.klaeger@10a.ch>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-05 14:50:57 +01:00
Johannes Schindelin
a894849b39 mingw: use domain information for default email
When a user is registered in a Windows domain, it is really easy to
obtain the email address. So let's do that.

Suggested by Lutz Roeder.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-05 14:50:52 +01:00
Johannes Schindelin
96f58de39d getpwuid(mingw): provide a better default for the user name
We do have the excellent GetUserInfoEx() function to obtain more
detailed information of the current user (if the user is part of a
Windows domain); Let's use it.

Suggested by Lutz Roeder.

To avoid the cost of loading Secur32.dll (even lazily, loading DLLs
takes a non-neglibile amount of time), we use the established technique
to load DLLs only when, and if, needed.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-05 14:49:14 +01:00
Johannes Schindelin
841933d046 getpwuid(mingw): initialize the structure only once
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-05 14:49:13 +01:00
Johannes Schindelin
73ba9ee74b Merge branch 'msys2-git-gui'
This topic branch addresses the bug where Git for Windows 2.x' Git GUI
failed to generate a working shortcut via Repository>Create Desktop
Shortcut.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-05 14:49:12 +01:00
Johannes Schindelin
536da3415c mmap(win32): avoid expensive fstat() call
On Windows, we have to emulate the fstat() call to fill out information
that takes extra effort to obtain, such as the file permissions/type.

If all we want is the file size, we can use the much cheaper
GetFileSizeEx() function (available since Windows XP).

Suggested by Philip Kelley.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-05 14:49:09 +01:00
Johannes Schindelin
8c60826940 mmap(win32): avoid copy-on-write when it is unnecessary
Often we are mmap()ing read-only. In those cases, it is wasteful to map in
copy-on-write mode. Even worse: it can cause errors where we run out of
space in the page file.

So let's be extra careful to map files in read-only mode whenever
possible.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-05 14:49:08 +01:00
Johannes Schindelin
e759ce5283 win32mmap: set errno appropriately
It is not really helpful when a `git fetch` fails with the message:

	fatal: mmap failed: No error

In the particular instance encountered by a colleague of yours truly,
the Win32 error code was ERROR_COMMITMENT_LIMIT which means that the
page file is not big enough.

Let's make the message

	fatal: mmap failed: File too large

instead, which is only marginally better, but which can be associated
with the appropriate work-around: setting `core.packedGitWindowSize` to
a relatively small value.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-05 14:49:08 +01:00
Johannes Schindelin
6d0f404001 git-gui (Windows): use git-gui.exe in Create Desktop Shortcut
When calling `Repository>Create Desktop Shortcut`, Git GUI assumes
that it is okay to call `wish.exe` directly on Windows. However, in
Git for Windows 2.x' context, that leaves several crucial environment
variables uninitialized, resulting in a shortcut that does not work.

To fix those environment variable woes, Git for Windows comes with a
convenient `git-gui.exe`, so let's just use it when it is available.

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

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-05 14:49:05 +01:00
Johannes Schindelin
924c115721 git-gui: fix detection of Cygwin
MSys2 might *look* like Cygwin, but it is *not* Cygwin... Unless it
is run with `MSYSTEM=MSYS`, that is.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-05 14:49:04 +01:00
Johannes Schindelin
adb5d8e651 Merge branch 'home-bin' 2016-01-05 14:49:03 +01:00
Johannes Schindelin
d88b8f461d Merge pull request #443 from kblees/kb/nanosecond-file-times-v2.5.3
nanosecond file times for v2.5.3
2016-01-05 14:49:02 +01:00
Johannes Schindelin
f77bc6492c git-wrapper: append $HOME/bin to the PATH
`$HOME/bin/` is quite convenient a place to put user-specific Git
helpers, such as credential or remote helpers.

When run in Git Bash, it is therefore already appended to the PATH;
Let's do the equivalent when run in Git CMD: when `git.exe` is
called, Git is told to look also for scripts and programs in
`$HOME/bin` (this does not modify Git CMD's `PATH`, of course).

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

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-05 14:48:59 +01:00
Johannes Schindelin
63a627f0b2 Merge branch 'conhost-git-bash' 2016-01-05 14:48:58 +01:00
Karsten Blees
cc5b1b595f 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>
2016-01-05 14:48:55 +01:00
Karsten Blees
837bced435 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>
2016-01-05 14:48:54 +01:00
Johannes Schindelin
07b8dcd8ec git-wrapper: support COMSPEC better
The quoting rules of `cmd.exe` are really, really quirky. In particular,
if there are more than two quotes, the entire set of rules changes. That
is the reason why

	CMD /C "C:\Program Files\Git\usr\bin\bash.exe" -l -i

works, but

	CMD /C "C:\Program Files\Git\usr\bin\bash.exe" -l -i "test.sh"

fails with this error message:

	'C:\Program' is not recognized as an internal or external command,
	operable program or batch file.

The recommended fix is to pass the /S option to `cmd.exe` and surround
the entire command-line by an extra set of quotes. And here lies the
rub: for that to work, we have to append an extra quote. At the end of
the command-line. *After* the last argument was appended, if any.

This commit supports that use case by introducing the option
"APPEND_QUOTE". The intended usage is to use the following string
resource:

	SHOW_CONSOLE=1 APPEND_QUOTE=1
	@@COMSPEC@@ /S /C \"\"@@EXEPATH@@\\usr\\bin\\bash.exe\" --login -i

(Note that there are only three quotes on that command-line, the fourth
to be appended due to the `APPEND_QUOTE` setting.)

This is (1/3) to fix https://github.com/git-for-windows/git/issues/396

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-05 14:48:51 +01:00
Johannes Schindelin
2f10b45a94 Merge branch 'getcwd-fix-case'
This makes sure that Git's idea of the current working directory matches
what is recorded on disk (which should be the same as Git's idea).

This helps in particular PowerShell users where the current working
directory can differ in case from what's stored on disk.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-05 14:48:50 +01:00
Johannes Schindelin
f1df6462d8 t0302: add forgotten quotes
This was probably missed because nobody had a left-over `trash/`
directory and the `-f` flag made sure that no error message was
produced when the file was not found that *actually* wanted to
be removed.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-05 14:48:49 +01:00
Johannes Schindelin
723b463ad5 mingw: ensure getcwd() reports the correct case
When switching the current working directory, say, in PowerShell, it is
quite possible to use a different capitalization than the one that is
recorded on disk. While doing the same in `cmd.exe` adjusts the
capitalization magically, that does not happen in PowerShell so that
`getcwd()` returns the current directory in a different way than is
recorded on disk.

Typically this creates no problems except when you call

	git log .

in a subdirectory called, say, "GIT/" but you switched to "Git/" and
your `getcwd()` reports the latter, then Git won't understand that you
wanted to see the history as per the `GIT/` subdirectory but it thinks you
wanted to see the history of some directory that may have existed in the
past (but actually never did).

So let's be extra careful to adjust the capitalization of the current
directory before working with it.

Reported by a few PowerShell power users ;-)

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-05 14:48:46 +01:00
Johannes Schindelin
9c929154d5 Merge pull request #305 from dscho/msysgit_issues_182
Allow `add -p` and `add -i` with a large number of files
2016-01-05 14:48:45 +01:00
Johannes Schindelin
d7e3cc05ec t3701: verify that we can add *lots* of files interactively
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-01-05 14:48:42 +01:00