Commit Graph

72608 Commits

Author SHA1 Message Date
Johannes Schindelin
dbba5f1376 mingw: try to create symlinks without elevated permissions
With Windows 10 Build 14972 in Developer Mode, a new flag is supported
by CreateSymbolicLink() to create symbolic links even when running
outside of an elevated session (which was previously required).

This new flag is called SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE and
has the numeric value 0x02.

Previous Windows 10 versions will not understand that flag and return an
ERROR_INVALID_PARAMETER, therefore we have to be careful to try passing
that flag only when the build number indicates that it is supported.

For more information about the new flag, see this blog post:
https://blogs.windows.com/buildingapps/2016/12/02/symlinks-windows-10/

This patch is loosely based on the patch submitted by Samuel D. Leslie
as https://github.com/git-for-windows/git/pull/1184.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-30 22:45:56 +02:00
Johannes Schindelin
e8f13ee97e fixup! Win32: implement basic symlink() functionality (file symlinks only)
This patch fixes signature of the CreateSymbolicLinkW() function's
declaratoin. The previous declaration claimed that said function returns
a BOOL, while it really returns a BOOLEAN.

This is not an academic distinction: BOOL is defined as an int (i.e.
32-bit) and BOOLEAN as an unsigned char (i.e. 8-bit). Therefore, the
return value 0 (meaning, the least-significant 8 bits are all zero)
could be mistaken to indicate a successful creation of the symbolic
link (because the remaining 24 bits are undefined, and quite likely
non-zero).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-30 22:44:47 +02:00
Johannes Schindelin
51efe4db88 Merge pull request #1179 from dscho/submodule-in-excluded
status: do not get confused by submodules in excluded directories
2017-05-25 07:24:28 +02:00
Johannes Schindelin
6eb92ce496 status: do not get confused by submodules in excluded directories
We meticulously pass the `exclude` flag to the `treat_directory()`
function so that we can indicate that files in it are excluded rather
than untracked when recursing.

But we did not yet treat submodules the same way.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-25 00:55:26 +02:00
Johannes Schindelin
abd867df20 fixup! mingw: kill unterminated child processes on signals
Let's be careful not to close a handle that has been closed already...

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-24 22:43:43 +02:00
Johannes Schindelin
fe31e2c27c fixup! mingw: kill child processes in a gentler way
Let's make sure that CloseHandle() is called on the process only once.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-24 16:32:15 +02:00
Johannes Schindelin
3603d17801 fixup! mingw: kill child processes in a gentler way
Seems that this maintainer managed to merge a revision without the
last-minute changes.

This fix makes sure that the exit_status is preserved, and that it is
easier to reason about the main_process and why it is terminated and the
handle is closed only once (I am looking at you, Coverity!).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-23 13:15:17 +02:00
Johannes Schindelin
7cf4526635 git-gui: fix exception when trying to stage with empty file list
If there is nothing to stage, there is nothing to stage. Let's not try
to, even if the file list contains nothing at all.

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

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-23 13:08:31 +02:00
Johannes Schindelin
80a6209eb5 Merge pull request #1170 from dscho/mingw-kill-process
Handle Ctrl+C in Git Bash nicely
2017-05-19 15:11:55 +02:00
Johannes Schindelin
780800b1c4 mingw: kill unterminated child processes on signals
Git for Windows' MSYS2 runtime was just adjusted to kill processes
gently, by injecting a thread that calls ExitProcess(). In case of
signals (such as when handling Ctrl+C in a MinTTY window), the exit code
is 128 + sign_no, as expected by Git's source code.

However, as there is no POSIX signal handling on Windows, no signal
handlers are called. Instead, functions registered via atexit() are
called. We work around that by testing the exit code explicitly.

This fixes the Git for Windows side of the bug where  interrupting `git
clone https://...` would send the spawned-off `git remote-https` process
into the background instead of interrupting it, i.e. the clone would
continue and its progress would be reported mercilessly to the console
window without the user being able to do anything about it (short of
firing up the task manager and killing the appropriate task manually).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-19 13:07:58 +02:00
Johannes Schindelin
2dd3603754 squash! Help debugging with MSys2 by optionally executing bash with strace
Also support passing a path to a log file via GIT_STRACE_COMMANDS to
force Git to call strace.exe with the `-o <path>` argument, i.e. to log
into a file rather than print the log directly.

That comes in handy when the output would otherwise misinterpreted by a
calling process as part of Git's output.

Note: the values "1", "yes" or "true" are *not* specifying paths, but
tell Git to let strace.exe log directly to the console.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-19 12:34:45 +02:00
Johannes Schindelin
1ada9bfbff mingw: kill child processes in a gentler way
The TerminateProcess() function does not actually leave the child
processes any chance to perform any cleanup operations. This is bad
insofar as Git itself expects its signal handlers to run.

A symptom is e.g. a left-behind .lock file that would not be left behind
if the same operation was run, say, on Linux.

To remedy this situation, we use an obscure trick: we inject a thread
into the process that needs to be killed and to let that thread run the
ExitProcess() function with the desired exit status. Thanks J Wyman for
describing this trick.

The advantage is that the ExitProcess() function lets the atexit
handlers run. While this is still different from what Git expects (i.e.
running a signal handler), in practice Git sets up signal handlers and
atexit handlers that call the same code to clean up after itself.

In case that the gentle method to terminate the process failed, we still
fall back to calling TerminateProcess(), but in that case we now also
make sure that processes spawned by the spawned process are terminated;
TerminateProcess() does not give the spawned process a chance to do so
itself.

Please note that this change only affects how Git for Windows tries to
terminate processes spawned by Git's own executables. Third-party
software that *calls* Git and wants to terminate it *still* need to make
sure to imitate this gentle method, otherwise this patch will not have
any effect.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-19 12:06:34 +02:00
Johannes Schindelin
52a7159fc0 Merge pull request #1165 from asheiduk/config-docu
Align documentation for C:\ProgramData\Git\config
2017-05-18 21:35:50 +02:00
Andreas Heiduk
58daf7ef9a Improve documentation for C:\ProgramData\Git\config
Move the description for the additional Git for Windows configuration file
into the right place, so that the following descriptions of the read priority
also covers this file correctly.

Also make it clear, what file `git config --system` selects.

Signed-off-by: Andreas Heiduk <asheiduk@gmail.com>
2017-05-15 23:49:33 +02:00
Andreas Heiduk
d16aa46269 Remove support for XP specific config location
Current Git for Windows supports an additional configuration location
for system setting. On contemporary versionws of Windows this is
$PROGRAMDATA/Git/config. But XP does not know about $PRORGRAMDATA so
$ALLUSERSPROFILE/Application Data/Git/config was used.

XP itself is EOL for quite some time and Git for Windows ceased to
support it officially with version 2.10.0 (release 3 Sep 2016).

https://github.com/git-for-windows/git/wiki/FAQ#which-versions-of-windows-are-supported
https://git-for-windows.github.io/requirements.html

Signed-off-by: Andreas Heiduk <asheiduk@gmail.com>
2017-05-15 22:26:32 +02:00
Johannes Schindelin
eba7af3dbb Merge branch 'coverity-v4-plus-fixup'
Coverity is a tool to analyze code statically, trying to find common (or
not so common) problems before they occur in production.

Coverity offers its services to Open Source software, and just like
upstream Git, Git for Windows applied and was granted the use.

While Coverity reports a lot of false positives due to Git's (ab-)use of
the FLEX_ARRAY feature (where it declares a 0-byte or 1-byte array at the
end of a struct, and then allocates a variable-length data structure
holding a variable-length string at the end, so that the struct as well as
the string can be released with a single free()), there were a few issues
reported that are true positives, and not all of them were resource leaks
in builtins (for which it is considered kind of okay to not release memory
just before exit() is called anyway).

This topic branch tries to address a couple of those issues.

Note: there are a couple more issues left, either because they are tricky
to resolve (in some cases, the custody of occasionally-allocated memory is
very unclear) or because it is unclear whether they are false positives
(due to the hard-to-reason-about nature of the code). It's a start,
though.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:59 +02:00
Johannes Schindelin
d7631f8cee Merge branch 'drive-prefix'
This topic branch allows us to specify absolute paths without the drive
prefix e.g. when cloning.

Example:

	C:\Users\me> git clone https://github.com/git/git \upstream-git

This will clone into a new directory C:\upstream-git, in line with how
Windows interprets absolute paths.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:50 +02:00
Johannes Schindelin
fd4a85b0cf submodule_uses_worktrees(): plug memory leak
There is really no reason why we would need to hold onto the allocated
string longer than necessary.

Reported by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:49 +02:00
Johannes Schindelin
bb10afa2cc show_worktree(): plug memory leak
The buffer allocated by shorten_unambiguous_ref() needs to be released.

Discovered by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:49 +02:00
Johannes Schindelin
994749cac7 name-rev: avoid leaking memory in the deref case
When the `name_rev()` function is asked to dereference the tip name, it
allocates memory. But when it turns out that another tip already
described the commit better than the current one, we forgot to release
the memory.

Pointed out by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:49 +02:00
Johannes Schindelin
11b3c20968 remote: plug memory leak in match_explicit()
The `guess_ref()` returns an allocated buffer of which `make_linked_ref()`
does not take custody (`alloc_ref()` makes a copy), therefore we need to
release the buffer afterwards.

Noticed via Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:49 +02:00
Johannes Schindelin
0dc9d5a6bd add_reflog_for_walk: avoid memory leak
We free()d the `log` buffer when dwim_log() returned 1, but not when it
returned a larger value (which meant that it still allocated the buffer
but we simply ignored it).

While in the vicinity, make sure that the `reflogs` structure as well as
the `branch` variable are released properly, too.

Identified by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:49 +02:00
Johannes Schindelin
4675959312 shallow: avoid memory leak
Reported by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:48 +02:00
Johannes Schindelin
e14dcc04b9 line-log: avoid memory leak
Discovered by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:48 +02:00
Johannes Schindelin
3c02bf45c7 receive-pack: plug memory leak in update()
Reported via Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:48 +02:00
Johannes Schindelin
9192b0d79a fast-export: avoid leaking memory in handle_tag()
Reported by, you guessed it, Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:48 +02:00
Johannes Schindelin
8a37820ec6 mktree: plug memory leaks reported by Coverity
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:48 +02:00
Johannes Schindelin
3569f0f4f6 pack-redundant: plug memory leak
Identified via Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:48 +02:00
Johannes Schindelin
8fa88d8289 setup_discovered_git_dir(): plug memory leak
The setup_explicit_git_dir() function does not take custody of the string
passed as first parameter; we have to release it if we turned the value of
git_dir into an absolute path.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:48 +02:00
Johannes Schindelin
5f14aae7fb setup_bare_git_dir(): help static analysis
Coverity reported a memory leak in this function. However, it can only
be called once, as setup_git_directory() changes global state and hence
is not reentrant.

Mark the variable as static to indicate that this is a singleton.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:47 +02:00
Johannes Schindelin
c862457d41 split_commit_in_progress(): simplify & fix memory leak
This function did a whole lot of unnecessary work, such as reading in
four files just to figure out that, oh, hey, we do not need to look at
them after all because the HEAD is not detached.

Simplify the entire function to return early when possible, to read in
the files only when necessary, and to release the allocated memory
always (there was a leak, reported via Coverity, where we failed to
release the allocated strings if the HEAD is not detached).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:47 +02:00
Johannes Schindelin
00dec0d28d checkout: fix memory leak
This change addresses part of the NEEDSWORK comment above the code,
therefore the comment needs to be adjusted, too.

Discovered via Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:47 +02:00
Johannes Schindelin
05e85c184b cat-file: fix memory leak
Discovered by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:47 +02:00
Johannes Schindelin
f03aefc8f8 mailinfo & mailsplit: check for EOF while parsing
While POSIX states that it is okay to pass EOF to isspace() (and it seems
to be implied that EOF should *not* be treated as whitespace), and also to
pass EOF to ungetc() (which seems to be intended to fail without buffering
the character), it is much better to handle these cases explicitly. Not
only does it reduce head-scratching (and helps static analysis avoid
reporting false positives), it also lets us handle files containing
nothing but whitespace by erroring out.

Reported via Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:47 +02:00
Johannes Schindelin
2d15edc8c7 status: close file descriptor after reading git-rebase-todo
Reported via Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:46 +02:00
Johannes Schindelin
ed16fee588 difftool: address a couple of resource/memory leaks
This change plugs a couple of memory leaks and makes sure that the file
descriptor is closed in run_dir_diff().

Spotted by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:46 +02:00
Johannes Schindelin
698b8c853b get_mail_commit_oid(): avoid resource leak
When we fail to read, or parse, the file, we still want to close the file
descriptor and release the strbuf.

Reported via Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:46 +02:00
Johannes Schindelin
f6dc48eed1 git_config_rename_section_in_file(): avoid resource leak
In case of errors, we really want the file descriptor to be closed.

Discovered by a Coverity scan.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:46 +02:00
Johannes Schindelin
6f33b7db51 add_commit_patch_id(): avoid allocating memory unnecessarily
It would appear that we allocate (and forget to release) memory if the
patch ID is not even defined.

Reported by the Coverity tool.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:46 +02:00
Johannes Schindelin
a3367f5d41 winansi: avoid buffer overrun
When we could not convert the UTF-8 sequence into Unicode for writing to
the Console, we should not try to write an insanely-long sequence of
invalid wide characters (mistaking the negative return value for an
unsigned length).

Reported by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:46 +02:00
Johannes Schindelin
cb12e9661d winansi: avoid use of uninitialized value
To initialize the foreground color attributes of "plain text", our ANSI
emulation tries to infer them from the currently attached console while
running the is_console() function. This function first tries to detect any
console attached to stdout, then it is called with stderr.

If neither stdout nor stderr has any console attached, it does not
actually matter what we use for "plain text" attributes, as we never need
to output any text to any console in that case.

However, after working on stdout and stderr, is_console() is called with
stdin, and it still tries to initialize the "plain text" attributes if
they had not been initialized earlier. In this case, we cannot detect any
attributes, and we used an uninitialized value for them.

Naturally, Coverity complained about this use case because it could not
reason about the code deeply enough to figure out that we do not even use
those attributes in that case.

Let's just initialize the value to 0 in that case, both to avoid future
Coverity reports, and to help catch future regressions in case anybody
changes the order of the is_console() calls (which would make the text
black on black).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:45 +02:00
Johannes Schindelin
f20366a0ad mingw: avoid memory leak when splitting PATH
In the (admittedly, concocted) case that PATH consists only of path
delimiters, we would leak the duplicated string.

Reported by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:45 +02:00
Johannes Schindelin
b6f1f1a260 Merge pull request #1149 from jeffhostetler/jeffhostetler/do_write_index_mtime
read-cache: close index.lock in do_write_index
2017-05-09 23:43:37 +02:00
Johannes Schindelin
a5a0cddc11 Merge 'case-insensitive-abspath' into HEAD 2017-05-09 23:43:28 +02:00
Johannes Schindelin
2a1277cf41 Merge branch 'skip-gettext-when-possible'
This topic branch allows us to skip the gettext initialization
when the locale directory does not even exist.

This saves 150ms out of 210ms for a simply `git version` call on
Windows, and it most likely will help scripts that call out to
`git.exe` hundreds of times.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:20 +02:00
Johannes Schindelin
be02cce312 mingw: fix isatty() after dup2()
We newly handle isatty() by special-casing the stdin/stdout/stderr file
descriptors, caching the return value. However, we missed the case where
dup2() overrides the respective file descriptor.

That poses a problem e.g. where the `show` builtin asks for a pager very
early, the `setup_pager()` function sets the pager depending on the
return value of `isatty()` and then redirects stdout. Subsequently,
`cmd_log_init_finish()` calls `setup_pager()` *again*. What should
happen now is that `isatty()` reports that stdout is *not* a TTY and
consequently stdout should be left alone.

Let's override dup2() to handle this appropriately.

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

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:20 +02:00
Johannes Schindelin
e1ae3b295a Merge branch 'dup-gui' of PhilipOakley/git-gui.git
This resolves a couple of Git GUI issues that seem not to have been
picked up from https://github.com/patthoyts/git-gui/pull/10 yet.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:11 +02:00
Johannes Schindelin
949a00b6ab Merge branch 'strg-t-in-git-gui'
This does not (yet) resolve the problem that Strg+T with multiple
selected lines fails to (un)stage them all, but it addresses one of
the reported Ctrl+T issues.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:02 +02:00
Johannes Schindelin
9b6f947269 mingw: make is_hidden tests in t0001/t5611 more robust
We should not actually expect the first `attrib.exe` in the PATH to
be the one we are looking for. Or that it is in the PATH, for that
matter.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:02 +02:00
Johannes Schindelin
396cb694bf mingw: ensure valid CTYPE
A change between versions 2.4.1 and 2.6.0 of the MSYS2 runtime modified
how Cygwin's runtime (and hence Git for Windows' MSYS2 runtime
derivative) handles locales: d16a56306d (Consolidate wctomb/mbtowc calls
for POSIX-1.2008, 2016-07-20).

An unintended side-effect is that "cold-calling" into the POSIX
emulation will start with a locale based on the current code page,
something that Git for Windows is very ill-prepared for, as it expects
to be able to pass a command-line containing non-ASCII characters to the
shell without having those characters munged.

One symptom of this behavior: when `git clone` or `git fetch` shell out
to call `git-upload-pack` with a path that contains non-ASCII
characters, the shell tried to interpret the entire command-line
(including command-line parameters) as executable path, which obviously
must fail.

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

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:43:01 +02:00