Commit Graph

61130 Commits

Author SHA1 Message Date
Nico Rieck
8fb5930ea1 git-wrapper: let git gui run in the background
This fixes https://github.com/git-for-windows/git/issues/172.

Signed-off-by: Nico Rieck <nico.rieck@gmail.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-08-09 15:27:36 +02:00
Karsten Blees
fdbdb1c17a git-wrapper: don't set the console input code page
Using different code pages for console input (SetConsoleCP()) and console
output (SetConsoleOutputCP()) doesn't make much sense and may be hazardous
for native Windows programs.

Git uses UTF-8 internally, so it actually needs 'SetConsoleCP(CP_UTF8)'
rather than 'SetConsoleCP(GetACP())'. However, ReadFile() / ReadConsoleA()
are broken with CP_UTF8 (and thus any higher level APIs such as fgetc(),
getchar() etc.). Unicode-aware console input would have to be implemented
via mingw_* wrappers using ReadConsoleW(). As Git typically launches an
editor for anything more complex than ASCII-only, yes/no-style questions,
this is currently not a problem.

Drop 'SetConsoleCP()' from the git-wrapper, so that input and output code
pages stay in sync.

Signed-off-by: Karsten Blees <blees@dcon.de>
2016-08-09 15:27:36 +02:00
Johannes Schindelin
54ee3c29d7 git-wrapper: support the non-mintty fall-back for Git Bash
When we fall back to starting the Git Bash in the regular Windows
console, we need to show said console's window... So let's introduce yet
another configuration knob for use via string resources.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-08-09 15:27:36 +02:00
Johannes Schindelin
caf51778cd git wrapper: allow _Git Bash_ to run with a newly allocated console
With a recent change in Cygwin (which is the basis of the msys2-runtime),
a GUI process desiring to launch an MSys2 executable needs to allocate a
console for the new process (otherwise the process will just hang on
Windows XP). _Git Bash_ is such a GUI process.

While at it, use correct handles when inheriting the stdin/stdout/stderr
handles: `GetStdHandle()` returns NULL for invalid handles, but the
STARTUPINFO must specify `INVALID_HANDLE_VALUE` instead.

Originally, the hope was that only this `NULL` => `INVALID_HANDLE_VALUE`
conversion would be required to fix the Windows XP issue mentioned above
(extensive debugging revealed that starting _Git Bash_ on Windows XP would
yield invalid handles for `stdin` and `stderr`, but *not* for `stdout`).

However, while _Git Bash_ eventually showed a `mintty` when not allocating
a new console, it took around one second to show it, and several seconds
to close it. So let's just include both fixes.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-08-09 15:27:35 +02:00
Johannes Schindelin
a79479d5bb git-wrapper: prepare to allow more options than MINIMAL_PATH
With the resource-driven command-line configuration, we introduced the
option to ensure that only the PATH environment variable is edited only
minimally, i.e. only /cmd/ is added (as appropriate for _Git CMD_).

We are about to add another option, so let's refactor the equivalent of
Git's `strip_prefix()` function; It is not *quite* the same because we
have to `memmove()` the remainder to the beginning of the buffer.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-08-09 15:27:35 +02:00
Karsten Blees
70c4546b0e git-wrapper: remove redundant TERM initialization
Remove redundant TERM initialization from git-wrapper in favor of TERM
initialization in git itself.

Signed-off-by: Karsten Blees <blees@dcon.de>
2016-08-09 15:27:35 +02:00
Karsten Blees
44cb23c5e2 git-wrapper: fix HOME initialization
git-wrapper fails to initialize HOME correctly if $HOMEDRIVE$HOMEPATH
points to a disconnected network drive.

Check if the directory exists before using $HOMEDRIVE$HOMEPATH.

Signed-off-by: Karsten Blees <blees@dcon.de>
2016-08-09 15:27:35 +02:00
Vitaly Takmazov
c181f00358 git-wrapper: case-insensitive path comparison 2016-08-09 15:27:34 +02:00
Johannes Schindelin
92dfdcd9e6 git-wrapper: interpret --cd=<directory> when configured via resources
This change accompanies the `--no-cd` option when configured via
resources. It is required to support `Git Bash Here`: when
right-clicking an icon in the Explorer to start a Bash, the working
directory is actually the directory that is displayed in the Explorer.
That means if the clicked icon actually refers to a directory, the
working directory would be its *parent* directory.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-08-09 15:27:34 +02:00
Johannes Schindelin
b90546048b git-wrapper: serve as git-gui.exe, too
To avoid that ugly Console window when calling \cmd\git.exe gui...

To avoid confusion with builtins, we need to move the code block
handling gitk (and now git-gui, too) to intercept before git-gui is
mistaken for a builtin.

Unfortunately, git-gui is in libexec/git-core/ while gitk is in bin/,
therefore we need slightly more adjustments than just moving and
augmenting the gitk case.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-08-09 15:27:34 +02:00
nalla
2863b0b499 git-wrapper: support git.exe and gitk.exe to be in a spaced dir
When *Git for Windows* is installed into a directory that has spaces in
it, e.g. `C:\Program Files\Git`, the `git-wrapper` appends this directory
unquoted when fixing up the command line. To resolve this, just quote the
provided `execpath`.

Signed-off-by: nalla <nalla@hamal.uberspace.de>
2016-08-09 15:27:34 +02:00
Johannes Schindelin
a5c3577232 git-wrapper: Allow git-cmd.exe to add only /cmd/ to the PATH
The idea of having the Git wrapper in the /cmd/ directory is to allow
adding only a *tiny* set of executables to the search path, to allow
minimal interference with other software applications. It is quite
likely, for example, that other software applications require their own
version of zlib1.dll and would not be overly happy to find the version
Git for Windows ships.

The /cmd/ directory also gives us the opportunity to let the Git wrapper
handle the `gitk` script. It is a Tcl/Tk script that is not recognized
by Windows, therefore calling `gitk` in `cmd.exe` would not work, even
if we add all of Git for Windows' bin/ directories.

So let's use the /cmd/ directory instead of adding /mingw??/bin/ and
/usr/bin/ to the PATH when launching Git CMD.

The way we implemented Git CMD is to embed the appropriate command line
as string resource into a copy of the Git wrapper. Therefore we extended
that syntax to allow for configuring a minimal search path.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-08-09 15:27:34 +02:00
Johannes Schindelin
2e0e99ae9d git-wrapper: optionally skip cd $HOME when configured via resources
We recently added the ability to configure copies of the Git wrapper to
launch custom command-lines, configured via plain old Windows resources.
The main user is Git for Windows' `git-bash.exe`, of course. When the
user double-clicks the `git bash` icon, it makes sense to start the Bash
in the user's home directory.

Third-party software, such as TortoiseGit or GitHub for Windows, may
want to start the Git Bash in another directory, though.

Now, when third-party software wants to call Git, they already have to
construct a command-line, and can easily pass a command-line option
`--no-cd` (which this commit introduces), and since that option is not
available when the user double-clicks an icon on the Desktop or in the
Explorer, let's keep the default to switch to the home directory if the
`--no-cd` flag was not passed along.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-08-09 15:27:33 +02:00
Johannes Schindelin
3fb3feb40d git-wrapper: make command-line argument skipping more robust
When we rewrite the command-line to call the *real* Git, we want to skip
the first command-line parameter. The previous code worked in most
circumstances, but was a bit fragile because it assumed that no fancy
quoting would take place.

In the next commit, we will want to have the option to skip more than
just one command-line parameter, so we have to be much more careful with
the command-line handling.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-08-09 15:27:33 +02:00
Johannes Schindelin
daa37c73c2 git-wrapper: remove 'gui' and 'citool' handling
In the meantime, Git for Windows learned to handle those subcommands
quite well itself; There is no longer a need to special-case them in the
wrapper.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-08-09 15:27:33 +02:00
Johannes Schindelin
2d7cd8a7ae Let the Git wrapper replace cmd\gitk.cmd, too
In a push to polish Git for Windows more, we are moving away from
scripts toward proper binaries.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-08-09 15:27:33 +02:00
Johannes Schindelin
3a27a43d72 Git wrapper: allow overriding what executable is called
The Git wrapper does one thing, and does it well: setting up the
environment required to run Git and its scripts, and then hand off to
another program.

We already do this for the Git executable itself; in Git for Windows'
context, we have exactly the same need also when calling the Git Bash or
Git CMD. However, both are tied to what particular shell environment you
use, though: MSys or MSys2 (or whatever else cunning developers make
work for them). This means that the Git Bash and Git CMD need to be
compiled in the respective context (e.g. when compiling the
mingw-w64-git package in the MSys2 context).

Happily, Windows offers a way to configure compiled executables:
resources. So let's just look whether the current executable has a
string resource and use it as the command-line to execute after the
environment is set up. To support MSys2's Git Bash better (where
`mintty` should, but might not, be available), we verify whether the
specified executable exists, and keep looking for string resources if it
does not.

For even more flexibility, we expand environment variables specified as
`@@<VARIABLE-NAME>@@`, and for convenience `@@EXEPATH@@` expands into
the directory in which the executable resides.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-08-09 15:27:33 +02:00
Johannes Schindelin
de286cb3a8 git-wrapper: inherit stdin/stdout/stderr even without a console
Otherwise the output of Git commands cannot be caught by, say, Git GUI
(because it is running detached from any console, which would make
`git.exe` inherit the standard handles implicitly).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-08-09 15:27:32 +02:00
Johannes Schindelin
e653d7d7d8 git-wrapper: prepare for executing configurable command-lines
We are about to use the Git wrapper to call the Git Bash of Git for
Windows. All the wrapper needs to do for that is to set up the
environment variables, use the home directory as working directory and
then hand off to a user-specified command-line.

We prepare the existing code for this change by introducing flags to set
up the environment variables, to launch a non-Git program, and to use
the home directory as working directory.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-08-09 15:27:32 +02:00
Johannes Schindelin
4779e181c9 git-wrapper: support MSys2
The original purpose of the Git wrapper is to run from inside Git for
Windows' /cmd/ directory, to allow setting up some environment variables
before Git is allowed to take over.

Due to differences in the file system layout, MSys2 requires some
changes for that to work.

In addition, we must take care to set the `MSYSTEM` environment variable
to `MINGW32` or `MINGW64`, respectively, to allow MSys2 to be configured
correctly in case Git launches a shell or Perl script.

We also need to change the `TERM` variable to `cygwin` instead of
`msys`, otherwise the pager `less.exe` (spawned e.g. by `git log`) will
simply crash with a message similar to this one:

	1 [main] less 9832 cygwin_exception::open_stackdumpfile:
	Dumping stack trace to less.exe.stackdump

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-08-09 15:27:32 +02:00
Johannes Schindelin
5ee0ec8c70 mingw: Use the Git wrapper for builtins
This reduces the disk footprint of a full Git for Windows setup
dramatically because on Windows, one cannot assume that hard links are
supported.

The net savings are calculated easily: the 32-bit `git.exe` file weighs
in with 7662 kB while the `git-wrapper.exe` file (modified to serve as a
drop-in replacement for builtins) weighs a scant 21 kB. At this point,
there are 109 builtins which results in a total of 813 MB disk space
being freed up by this commit.

Yes, that is really more than half a gigabyte.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-08-09 15:27:32 +02:00
Johannes Schindelin
d00df74d30 Let the Git wrapper serve as a drop-in replacement for builtins
Git started out as a bunch of separate commands, in the true Unix spirit.
Over time, more and more functionality was shared between the different
Git commands, though, so it made sense to introduce the notion of
"builtins": programs that are actually integrated into the main Git
executable.

These builtins can be called in two ways: either by specifying a
subcommand as the first command-line argument, or -- for backwards
compatibility -- by calling the Git executable hardlinked to a filename
of the form "git-<subcommand>". Example: the "log" command can be called
via "git log <parameters>" or via "git-log <parameters>". The latter
form is actually deprecated and only supported for scripts; calling
"git-log" interactively will not even work by default because the
libexec/git-core/ directory is not in the PATH.

All of this is well and groovy as long as hard links are supported.

Sadly, this is not the case in general on Windows. So it actually hurts
quite a bit when you have to fall back to copying all of git.exe's
currently 7.5MB 109 times, just for backwards compatibility.

The simple solution would be to install really trivial shell script
wrappers in place of the builtins:

	for builtin in $BUILTINS
	do
		rm git-$builtin.exe
		printf '#!/bin/sh\nexec git %s "$@"\n' $builtin > git-builtin
		chmod a+x git-builtin
	done

This method would work -- even on Windows because Git for Windows ships a
full-fledged Bash. However, the Windows Bash comes at a price: it needs to
spin up a full-fledged POSIX emulation layer everytime it starts.
Therefore, the shell script solution would incur a significant performance
penalty.

The best solution the Git for Windows team could come up with is to extend
the Git wrapper -- that is needed to call Git from cmd.exe anyway, and
that weighs in with a scant 19KB -- to also serve as a drop-in replacement
for the builtins so that the following workaround is satisfactory:

	for builtin in $BUILTINS
	do
		cp git-wrapper.exe git-$builtin.exe
	done

This commit allows for this, by extending the module file parsing to
turn builtin command names like `git-log.exe ...` into calls to the main
Git executable: `git.exe log ...`.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-08-09 15:27:32 +02:00
Johannes Schindelin
d7f5eb495a Refactor git-wrapper into more functions
This prepares the wrapper for modifications to serve as a drop-in
replacement for the builtins.

This commit's diff is best viewed with the `-w` flag.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-08-09 15:27:31 +02:00
Johannes Schindelin
9e870e13c3 mingw: Compile the Git wrapper
We take care to embed the manifest, too, because we will modify the
wrapper in the next few commits to serve as a drop-in replacement for
the built-ins, i.e. we will want to call the wrapper under names such
as 'git-patch-id.exe', too.

To allow 32-bit and 64-bit builds in the same directory, we let
git-wrapper.o depend on GIT-PREFIX so that it gets recompiled when
compiling for a different architecture.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-08-09 15:27:31 +02:00
Johannes Schindelin
2d41315cb6 Add Git for Windows' wrapper executable
On Windows, Git is faced by the challenge that it has to set up certain
environment variables before running Git under special circumstances
such as when Git is called directly from cmd.exe (i.e. outside any
Bash environment).

This source code was taken from msysGit's commit 74a198d:

https://github.com/msysgit/msysgit/blob/74a198d/src/git-wrapper/git-wrapper.c

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-08-09 15:27:31 +02:00
Johannes Schindelin
7b3d14e0be Start the merging-rebase to junio/maint
In preparation for v2.9.3, let's perform an intermediate rebase. This
rebase not only updated Git for Windows' `master` branch to upstream
Git's current `maint` branch, but also rearranges a couple of commits.

Most notably, a couple of patches that were previously not in topic
branches now are, and the recently merged Pull Requests are now rooted
in the upstream revision, not some semi-random Windows-specific patch.

In addition, these two topic branches (which both require the "Win32:
simplify loading of DLL functions" patch) were moved so that the code
actually compiles not only at the very end, but also when checking out
these revisions individually:

mingw/default-ident
	mingw: use domain information for default email
	getpwuid(mingw): provide a better default for the user name
	getpwuid(mingw): initialize the structure only once

mingw/getcwd
	mingw: fix getcwd when the parent directory cannot be queried
	mingw: ensure `getcwd()` reports the correct case

Finally, the patch "credential-store: avoid assertion" was replaced by a
merge of Jeff King's "common-main" branch that was already merged into
upstream Git's `master` branch.

This commit starts the rebase of b71d344 to 00f27fe

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-08-09 15:20:12 +02:00
Johannes Schindelin
837fdf38a5 TODO when rebasing
These two topics:

> 37a5a2a mingw: use domain information for default email
> 4273e68 getpwuid(mingw): provide a better default for the user name
> dbed828 getpwuid(mingw): initialize the structure only once

and:

> 0d1995a mingw: fix getcwd when the parent directory cannot be queried
> b8552a2 mingw: ensure `getcwd()` reports the correct case

both rely on a51dc28 (Win32: simplify loading of DLL functions,
2014-08-25), and must therefore be moved (at the moment, those commits do
not compile because of the absence of `DECLARE_PROC_ADDR`).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-08-09 14:24:52 +02:00
Junio C Hamano
00f27feb6a Hopefully final batch for 2.9.3
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-08-08 14:22:36 -07:00
Junio C Hamano
593be730f2 Merge branch 'sb/pack-protocol-doc-nak' into maint
A doc update.

* sb/pack-protocol-doc-nak:
  Documentation: pack-protocol correct NAK response
2016-08-08 14:21:47 -07:00
Junio C Hamano
f7b01d3eb7 Merge branch 'rs/submodule-config-code-cleanup' into maint
Code cleanup.

* rs/submodule-config-code-cleanup:
  submodule-config: fix test binary crashing when no arguments given
  submodule-config: combine early return code into one goto
  submodule-config: passing name reference for .gitmodule blobs
  submodule-config: use explicit empty string instead of strbuf in config_from()
2016-08-08 14:21:46 -07:00
Junio C Hamano
6a024a249f Merge branch 'sb/submodule-deinit-all' into maint
A comment update for a topic that was merged to Git v2.8.

* sb/submodule-deinit-all:
  submodule deinit: remove outdated comment
2016-08-08 14:21:46 -07:00
Junio C Hamano
5131967e4a Merge branch 'rs/worktree-use-strbuf-absolute-path' into maint
Code simplification.

* rs/worktree-use-strbuf-absolute-path:
  worktree: use strbuf_add_absolute_path() directly
2016-08-08 14:21:45 -07:00
Junio C Hamano
2f8c654edb Merge branch 'jc/doc-diff-filter-exclude' into maint
Belated doc update for a feature added in v1.8.5.

* jc/doc-diff-filter-exclude:
  diff: document diff-filter exclusion
2016-08-08 14:21:44 -07:00
Junio C Hamano
970994deb1 Merge branch 'nd/test-helpers' into maint
Build clean-up.

* nd/test-helpers:
  t/test-lib.sh: fix running tests with --valgrind
  Makefile: use VCSSVN_LIB to refer to svn library
  Makefile: drop extra dependencies for test helpers
2016-08-08 14:21:43 -07:00
Junio C Hamano
48aa37ed42 Merge branch 'rs/use-strbuf-addbuf' into maint
Code cleanup.

* rs/use-strbuf-addbuf:
  strbuf: avoid calling strbuf_grow() twice in strbuf_addbuf()
  use strbuf_addbuf() for appending a strbuf to another
2016-08-08 14:21:42 -07:00
Junio C Hamano
ee7fd70edf Merge branch 'lf/recv-sideband-cleanup' into maint
Code simplification.

* lf/recv-sideband-cleanup:
  sideband.c: small optimization of strbuf usage
  sideband.c: refactor recv_sideband()
2016-08-08 14:21:41 -07:00
Junio C Hamano
e69771c3af Merge branch 'ah/unpack-trees-advice-messages' into maint
Grammofix.

* ah/unpack-trees-advice-messages:
  unpack-trees: fix English grammar in do-this-before-that messages
2016-08-08 14:21:40 -07:00
Junio C Hamano
26256c017f Merge branch 'lf/sideband-returns-void' into maint
A small internal API cleanup.

* lf/sideband-returns-void:
  upload-pack.c: make send_client_data() return void
  sideband.c: make send_sideband() return void
2016-08-08 14:21:40 -07:00
Junio C Hamano
1e274ef2ba Merge branch 'jk/send-pack-stdio' into maint
Code clean-up.

* jk/send-pack-stdio:
  write_or_die: remove the unused write_or_whine() function
  send-pack: use buffered I/O to talk to pack-objects
2016-08-08 14:21:39 -07:00
Junio C Hamano
a220e2bbbf Merge branch 'pb/commit-editmsg-path' into maint
Code clean-up.

* pb/commit-editmsg-path:
  builtin/commit.c: memoize git-path for COMMIT_EDITMSG
2016-08-08 14:21:38 -07:00
Junio C Hamano
8d64216807 Merge branch 'ew/find-perl-on-freebsd-in-local' into maint
Recent FreeBSD stopped making perl available at /usr/bin/perl;
switch the default the built-in path to /usr/local/bin/perl on not
too ancient FreeBSD releases.

* ew/find-perl-on-freebsd-in-local:
  config.mak.uname: correct perl path on FreeBSD
2016-08-08 14:21:38 -07:00
Junio C Hamano
172b811322 Merge branch 'ew/daemon-socket-keepalive' into maint
Recent update to "git daemon" tries to enable the socket-level
KEEPALIVE, but when it is spawned via inetd, the standard input
file descriptor may not necessarily be connected to a socket.
Suppress an ENOTSOCK error from setsockopt().

* ew/daemon-socket-keepalive:
  Windows: add missing definition of ENOTSOCK
  daemon: ignore ENOTSOCK from setsockopt
2016-08-08 14:21:37 -07:00
Junio C Hamano
aa9136a87e Merge branch 'nd/pack-ofs-4gb-limit' into maint
"git pack-objects" and "git index-pack" mostly operate with off_t
when talking about the offset of objects in a packfile, but there
were a handful of places that used "unsigned long" to hold that
value, leading to an unintended truncation.

* nd/pack-ofs-4gb-limit:
  fsck: use streaming interface for large blobs in pack
  pack-objects: do not truncate result in-pack object size on 32-bit systems
  index-pack: correct "offset" type in unpack_entry_data()
  index-pack: report correct bad object offsets even if they are large
  index-pack: correct "len" type in unpack_data()
  sha1_file.c: use type off_t* for object_info->disk_sizep
  pack-objects: pass length to check_pack_crc() without truncation
2016-08-08 14:21:36 -07:00
Junio C Hamano
743fba85f7 Merge branch 'rs/notes-merge-no-toctou' into maint
"git notes merge" had a code to see if a path exists (and fails if
it does) and then open the path for writing (when it doesn't).
Replace it with open with O_EXCL.

* rs/notes-merge-no-toctou:
  notes-merge: use O_EXCL to avoid overwriting existing files
2016-08-08 14:21:35 -07:00
Junio C Hamano
a52fb9b8f3 Merge branch 'js/ignore-space-at-eol' into maint
An age old bug that caused "git diff --ignore-space-at-eol"
misbehave has been fixed.

* js/ignore-space-at-eol:
  diff: fix a double off-by-one with --ignore-space-at-eol
  diff: demonstrate a bug with --patience and --ignore-space-at-eol
2016-08-08 14:21:35 -07:00
Junio C Hamano
71076e11cd Merge branch 'jk/push-scrub-url' into maint
"git fetch http://user:pass@host/repo..." scrubbed the userinfo
part, but "git push" didn't.

* jk/push-scrub-url:
  t5541: fix url scrubbing test when GPG is not set
  push: anonymize URL in status output
2016-08-08 14:21:34 -07:00
Junio C Hamano
880b3fee51 Merge branch 'nd/cache-tree-ita' into maint
"git add -N dir/file && git write-tree" produced an incorrect tree
when there are other paths in the same directory that sorts after
"file".

* nd/cache-tree-ita:
  cache-tree: do not generate empty trees as a result of all i-t-a subentries
  cache-tree.c: fix i-t-a entry skipping directory updates sometimes
  test-lib.sh: introduce and use $EMPTY_BLOB
  test-lib.sh: introduce and use $EMPTY_TREE
2016-08-08 14:21:33 -07:00
Junio C Hamano
327b3f8459 Merge branch 'mh/blame-worktree' into maint
"git blame file" allowed the lineage of lines in the uncommitted,
unadded contents of "file" to be inspected, but it refused when
"file" did not appear in the current commit.  When "file" was
created by renaming an existing file (but the change has not been
committed), this restriction was unnecessarily tight.

* mh/blame-worktree:
  t/t8003-blame-corner-cases.sh: Use here documents
  blame: allow to blame paths freshly added to the index
2016-08-08 14:21:32 -07:00
Karsten Blees
d7aafa6acc squash! Win32: support long paths
Win32: support long paths

Windows paths are typically limited to MAX_PATH = 260 characters, even
though the underlying NTFS file system supports paths up to 32,767 chars.
This limitation is also evident in Windows Explorer, cmd.exe and many
other applications (including IDEs).

Particularly annoying is that most Windows APIs return bogus error codes
if a relative path only barely exceeds MAX_PATH in conjunction with the
current directory, e.g. ERROR_PATH_NOT_FOUND / ENOENT instead of the
infinitely more helpful ERROR_FILENAME_EXCED_RANGE / ENAMETOOLONG.

Many Windows wide char APIs support longer than MAX_PATH paths through the
file namespace prefix ('\\?\' or '\\?\UNC\') followed by an absolute path.
Notable exceptions include functions dealing with executables and the
current directory (CreateProcess, LoadLibrary, Get/SetCurrentDirectory) as
well as the entire shell API (ShellExecute, SHGetSpecialFolderPath...).

Introduce a handle_long_path function to check the length of a specified
path properly (and fail with ENAMETOOLONG), and to optionally expand long
paths using the '\\?\' file namespace prefix. Short paths will not be
modified, so we don't need to worry about device names (NUL, CON, AUX).

Contrary to MSDN docs, the GetFullPathNameW function doesn't seem to be
limited to MAX_PATH (at least not on Win7), so we can use it to do the
heavy lifting of the conversion (translate '/' to '\', eliminate '.' and
'..', and make an absolute path).

Add long path error checking to xutftowcs_path for APIs with hard MAX_PATH
limit.

Add a new MAX_LONG_PATH constant and xutftowcs_long_path function for APIs
that support long paths.

While improved error checking is always active, long paths support must be
explicitly enabled via 'core.longpaths' option. This is to prevent end
users to shoot themselves in the foot by checking out files that Windows
Explorer, cmd/bash or their favorite IDE cannot handle.

Test suite:
Test the case is when the full pathname length of a dir is close
to 260 (MAX_PATH).
Bug report and an original reproducer by Andrey Rogozhnikov:
https://github.com/msysgit/git/pull/122#issuecomment-43604199

Note that the test cannot rely on the presence of short names, as they
are not enabled by default except on the system drive.

[jes: adjusted test number to avoid conflicts, reinstated && chain,
adjusted test to work without short names]

Thanks-to: Martin W. Kirst <maki@bitkings.de>
Thanks-to: Doug Kelly <dougk.ff7@gmail.com>
Signed-off-by: Karsten Blees <blees@dcon.de>
Original-test-by: Andrey Rogozhnikov <rogozhnikov.andrey@gmail.com>
Signed-off-by: Stepan Kasal <kasal@ucw.cz>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2016-08-04 16:00:33 +02:00
Johannes Schindelin
dd60b1c7da fixup! Win32: support long paths 2016-08-04 15:19:33 +02:00