Commit Graph

54819 Commits

Author SHA1 Message Date
Johannes Schindelin
6fc6a9d187 mingw: enable stack smashing protector
As suggested privately to Brendan Forster by some unnamed person
(suggestion for the future: use the public mailing list, or even the
public GitHub issue tracker, that is a much better place to offer such
suggestions), we should make use of gcc's stack smashing protector that
helps detect stack buffer overruns early.

Rather than using -fstack-protector, we use -fstack-protector-strong
because it strikes a better balance between how much code is affected
and the performance impact.

In a local test (time git log --grep=is -p), best of 5 timings went from
23.009s to 22.997s (i.e. the performance impact was *well* lost in the
noise).

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

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2015-11-09 14:25:25 +01:00
Johannes Schindelin
16b1ba46cf 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>
2015-11-01 19:08:12 +01:00
Johannes Schindelin
1e94972735 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>
2015-11-01 18:59:22 +01:00
Johannes Schindelin
837f72dabd 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>
2015-11-01 18:26:16 +01:00
Johannes Schindelin
2605b386be 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>
2015-11-01 18:15:30 +01:00
Johannes Schindelin
104a5fedf7 squash! git-gui: Use /git-bash.exe if available
Adjust commit message as follows:

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>
2015-10-19 19:36:05 +00:00
Johannes Schindelin
d6681875e6 Merge pull request #492 from tomyy/issue-490
git-gui: Use /git-bash.exe if available
2015-10-19 21:33:47 +02:00
Johannes Schindelin
98a7224215 squash! mingw: use MSys2's libgen.h
mingw-w64-crt provides a basename() function, but it does not do what we
want. For example, it shortens `path0/` to `path`!

So let's not use it (i.e. let's revert commit 00bc8c9ea).

This fixes https://github.com/git-for-windows/git/issues/494
2015-10-19 16:34:04 +02:00
Thomas Klaeger
076a73696a git-gui: Use /git-bash.exe if available
On Windows using /git-bash.exe is preferable over using bash because
/git-bash.exe respects the users preferred terminal
2015-10-18 22:31:36 +02:00
Johannes Schindelin
28413c74cf Merge pull request #487 from dscho/default-username
Improve the default user name & email logic
2015-10-18 13:52:03 +02:00
Johannes Schindelin
3d194cf18a Merge pull request #486 from dscho/mmap-no-error
Better mmap() emulation
2015-10-18 13:52:02 +02:00
Johannes Schindelin
83bf206294 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>
2015-10-18 13:52:00 +02:00
Johannes Schindelin
80c7fb60f3 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>
2015-10-18 13:51:58 +02:00
Johannes Schindelin
8fa8bfbcba getpwuid(mingw): initialize the structure only once
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2015-10-18 13:51:57 +02:00
Johannes Schindelin
f483e6349d Merge branch 'racy-dissociate'
This topic branch replaces the previous patch and will be submitted to
the Git mailing list soon, as reply to:

	http://thread.gmane.org/gmane.comp.version-control.git/278746

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2015-10-18 13:51:33 +02:00
Johannes Schindelin
aff4cb666a t5813: do not use UNC paths
In Windows, a double slash in the beginning of an absolute path denotes
network paths of the form `\\localhost\share\file`. In Git for Windows'
context, the same form is also available with forward slashes.

Let's not start the path in the URL with a double slash (e.g.
`ssh://host//usr/src/git/t/file`) but take pains to use the normalized
form with a single slash, so that Git is not confusing the path for a
UNC one.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2015-10-18 13:49:35 +02:00
Johannes Schindelin
26b448516c 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>
2015-10-18 13:49:34 +02:00
Johannes Schindelin
0ae6ac0b6d 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>
2015-10-18 13:49:32 +02:00
Johannes Schindelin
d18c843a7f 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>
2015-10-18 13:49:31 +02:00
Johannes Schindelin
f10f2c5fca 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>
2015-10-18 13:49:30 +02:00
Johannes Schindelin
e1aa76ec4b clone --dissociate: avoid locking pack files
When `git clone` is asked to dissociate the repository from the
reference repository whose objects were used, it is quite possible that
the pack files need to be repacked. In that case, the pack files need to
be deleted that were originally hard-links to the reference repository's
pack files.

On platforms where a file cannot be deleted if another process still
holds a handle on it, we therefore need to take pains to release all
pack files and indexes before dissociating.

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

The test case to demonstrate the breakage technically does not need to
be run on Linux or MacOSX. It won't hurth, either, though.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2015-10-18 13:47:25 +02:00
Johannes Schindelin
2136f53b9e Add a function to release all packs
On Windows, files that are in use cannot be removed or renamed. That
means that we have to release pack files when we are about to, say,
repack them. Let's introduce a convenient function to close them
pack files.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2015-10-18 13:47:25 +02:00
Johannes Schindelin
f8a0a22fb5 Consolidate code to close a pack's file descriptor
There was a lot of repeated code to close the file descriptor of
a given pack. Let's just refactor this code into a single function.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2015-10-18 13:47:24 +02:00
Johannes Schindelin
dddce2f713 Demonstrate a Windows file locking issue with git clone --dissociate
On Windows, dissociating from a reference can fail very easily due to
pack files that are still in use when they want to be removed.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2015-10-18 13:47:23 +02:00
Johannes Schindelin
c8ca74099a 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>
2015-10-18 13:47:20 +02:00
Johannes Schindelin
746ddfa5a6 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>
2015-10-18 13:47:20 +02:00
Johannes Schindelin
b6c27bd755 Merge branch 'home-bin' 2015-10-18 13:47:18 +02:00
Johannes Schindelin
9898d85c7f Merge branch 'racy-dissociate'
This fixes a file-locking problem with `git clone --dissociate`.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2015-10-18 13:47:16 +02:00
Johannes Schindelin
7d11ed038b 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>
2015-10-18 13:47:14 +02:00
Johannes Schindelin
1ff7b494f8 clone --dissociate: avoid locking pack files
When `git clone` is asked to dissociate the repository from the
reference repository whose objects were used, it is quite possible that
the pack files need to be repacked. In that case, the pack files need to
be deleted that were originally hard-links to the reference repository's
pack files.

On platforms where a file cannot be deleted if another process still
holds a handle on it, we therefore need to take pains to release all
pack files and indexes before dissociating.

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

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2015-10-18 13:46:08 +02:00
Johannes Schindelin
2a7953ebc2 Merge pull request #443 from kblees/kb/nanosecond-file-times-v2.5.3
nanosecond file times for v2.5.3
2015-10-18 13:46:07 +02:00
Johannes Schindelin
160840df2b Merge branch 'conhost-git-bash' 2015-10-18 13:46:05 +02:00
Karsten Blees
3d04ebcccc 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>
2015-10-18 13:46:03 +02:00
Karsten Blees
43f7044543 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>
2015-10-18 13:46:02 +02:00
Johannes Schindelin
273d32c040 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>
2015-10-18 13:46:00 +02:00
Johannes Schindelin
61f6bf36bf 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>
2015-10-18 13:45:58 +02:00
Johannes Schindelin
5f095b3e3e 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>
2015-10-18 13:45:58 +02:00
Johannes Schindelin
4dbe0e0cf6 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>
2015-10-18 13:45:55 +02:00
Johannes Schindelin
ccab258463 Merge pull request #305 from dscho/msysgit_issues_182
Allow `add -p` and `add -i` with a large number of files
2015-10-18 13:45:54 +02:00
Johannes Schindelin
4fdd993c73 t3701: verify that we can add *lots* of files interactively
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2015-10-18 13:45:52 +02:00
Kelly Heller
f3e9069a30 Allow add -p and add -i with a large number of files
This fixes https://github.com/msysgit/git/issues/182.

Inspired by Pull Request 218 using code from @PhilipDavis.

[jes: simplified code quite a bit]

Signed-off-by: Kelly Heller <kkheller@cedrus.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2015-10-18 13:45:51 +02:00
Johannes Schindelin
fd6f15be9f Merge branch 'bash-redirector' 2015-10-18 13:45:50 +02:00
Johannes Schindelin
2b90a22e66 Merge pull request #286 from dscho/unc-alternates
Make alternates work on UNC paths
2015-10-18 13:45:49 +02:00
Johannes Schindelin
9682ac7802 Merge branch 'issue-231'
This branch hopefully addresses

	https://github.com/git-for-windows/git/issues/231

where `git repack` could not delete the object directory because there
was still an open handle on it.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2015-10-18 13:45:48 +02:00
Johannes Schindelin
d1c2a73b6b Merge pull request #275 from cs96and/cygwin_fixes
winansi.c: Fix colourization on Cygwin pseudo terminals.
2015-10-18 13:45:47 +02:00
Johannes Schindelin
cc9594165e Merge branch 'pinnable'
Part 2/3 of fixing https://github.com/git-for-windows/git/issues/263

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2015-10-18 13:45:46 +02:00
Johannes Schindelin
f469fe235d Merge pull request #276 from dscho/issue-0xff
mingw: Suppress warning that <commit>:.gitattributes does not exist
2015-10-18 13:45:46 +02:00
Johannes Schindelin
30817f3f6f mingw: let the Git wrapper determine the top-level directory
The Git wrapper is also used as a redirector for Git for Windows'
bin\bash.exe dropin: for backwards-compatibility, bin\bash.exe exists
and simply sets up the environment variables before executing the
*real* bash.

However, due to our logic to use the directory in which the `.exe`
lives as top-level directory (or one directory below for certain, known
basenames such as `git.exe` and `gitk.exe`), the `PATH` environment
variable was prefixed with the `/bin/bin` and `/bin/mingw/bin`
directories -- which makes no sense.

Instead, let's just auto-detect the top-level directory in the common
case.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2015-10-18 13:45:43 +02:00
Johannes Schindelin
d7b9c52265 mingw: clean up the Git wrapper a bit
We should not conflate the 'exepath' with the 'top-level
directory'. The former should be the directory in which the executable
lives while the latter should be the top-level directory ("POSIX root
directory") as far as Git is concerned.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2015-10-18 13:45:42 +02:00
Johannes Schindelin
f88b635c0e mingw: support UNC alternates
Just like we support having alternates pointing to different drives, we
want to support alternates pointing to network shares, i.e. UNC paths.

Technically, what we do in this patch is not to support UNC alternates,
but to support UNC paths when normalizing paths. But the latter implies
the former, and the former really was the motivation for this patch.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2015-10-18 13:45:40 +02:00