Skip to content

Commit

Permalink
msys2-runtime: backport Git for Windows' pathconv improvements
Browse files Browse the repository at this point in the history
This combines the patches introduced via
msys2/msys2-runtime#181 and
msys2/msys2-runtime#182.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Dec 19, 2023
1 parent 0ab7e94 commit a26a0b0
Show file tree
Hide file tree
Showing 11 changed files with 738 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
From 4f2214a1d6349884135f0485a36e3bfad31350a2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=EB=A7=88=EB=88=84=EC=97=98?= <nalla@hamal.uberspace.de>
Date: Wed, 17 Jun 2015 09:30:41 +0200
Subject: [PATCH 39/N] path-conversion: Introduce ability to switch off
conversion.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When calling windows native apps from MSYS2, the runtime tries to
convert commandline arguments by a specific set of rules. This idea was
inherited from the MSys/MinGW project (which is now seemingly stale, yet
must be credited with championing this useful feature, see MinGW wiki
https://web.archive.org/web/20201112005258/http://www.mingw.org/wiki/Posix_path_conversion).

If the user does not want that behavior on a big scale, e.g. inside a
Bash script, with the changes introduced in this commit, the user can
now set the the environment variable `MSYS_NO_PATHCONV` when calling
native windows commands.

This is a feature that has been introduced in Git for Windows via
https://github.com/git-for-windows/msys2-runtime/pull/11 and it predates
support for the `MSYS2_ENV_CONV_EXCL` and `MSYS2_ARG_CONV_EXCL`
environment variables in the MSYS2 runtime; Many users find the
simplicity of `MSYS_NO_PATHCONV` appealing.

So let's teach MSYS2 proper this simple trick that still allows using
the sophisticated `MSYS2_*_CONV_EXCL` facilities but also offers a
convenient catch-all "just don't convert anything" knob.

Signed-off-by: 마누엘 <nalla@hamal.uberspace.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
winsup/cygwin/msys2_path_conv.cc | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/winsup/cygwin/msys2_path_conv.cc b/winsup/cygwin/msys2_path_conv.cc
index 5c59291..875be6f 100644
--- a/winsup/cygwin/msys2_path_conv.cc
+++ b/winsup/cygwin/msys2_path_conv.cc
@@ -341,6 +341,14 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en

if (*it == '\0' || it == end) return NONE;

+ /*
+ * Skip path mangling when environment indicates it.
+ */
+ const char *no_pathconv = getenv ("MSYS_NO_PATHCONV");
+
+ if (no_pathconv)
+ return NONE;
+
while (!isalnum(*it) && *it != '/' && *it != '\\' && *it != ':' && *it != '-' && *it != '.') {
recurse = true;
it = ++*src;
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
From 7f5ce2cb55bf18020a68f88c2861ea862feb8178 Mon Sep 17 00:00:00 2001
From: Johannes Schindelin <johannes.schindelin@gmx.de>
Date: Sun, 15 Feb 2015 11:45:48 +0000
Subject: [PATCH 40/N] fixup! Add functionality for converting UNIX paths in
arguments and environment variables to Windows form for native Win32
applications.

This teaches MSYS2's path conversion to leave arguments starting with a
tilde or quote alone: It is not a good idea to expand, say, ~/.gitconfig
partially: replacing it by ~C:\msys64\.gitconfig is most likely the
wrong thing to do!

This addresses the expectations of the following test cases in the test
suite of https://github.com/git/git/tree/v2.43.0:

-t0001.19 init with init.templatedir using ~ expansion
-t0003.12 core.attributesfile
-t0003.13 attribute test: read paths from stdin
-t0003.15 attribute test: --all option
-t0003.16 attribute test: --cached option
-t0003.17 root subdir attribute test
-t0003.18 negative patterns
-t0003.19 patterns starting with exclamation
-t0003.20 "**" test
-t0003.21 "**" with no slashes test
-t0003.23 using --source
-t0003.32 bare repository: check that --cached honors index
-t0003.34 binary macro expanded by -a
-t0003.35 query binary macro directly
-t0003.40 large attributes line ignored in tree
-t0003.41 large attributes line ignores trailing content in tree
-t0003.43 large attributes line ignored in index
-t0003.44 large attributes line ignores trailing content in index
-t0068.1 run based on configured value

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
winsup/cygwin/msys2_path_conv.cc | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/winsup/cygwin/msys2_path_conv.cc b/winsup/cygwin/msys2_path_conv.cc
index 875be6f..35b7757 100644
--- a/winsup/cygwin/msys2_path_conv.cc
+++ b/winsup/cygwin/msys2_path_conv.cc
@@ -349,6 +349,13 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
if (no_pathconv)
return NONE;

+ /* Let's not convert ~/.file to ~C:\msys64\.file */
+ if (*it == '~') {
+skip_p2w:
+ *src = end;
+ return NONE;
+ }
+
while (!isalnum(*it) && *it != '/' && *it != '\\' && *it != ':' && *it != '-' && *it != '.') {
recurse = true;
it = ++*src;
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
From 4b20e4fc67735ce82bb47c60a6e8f46bbcb33127 Mon Sep 17 00:00:00 2001
From: Johannes Schindelin <johannes.schindelin@gmx.de>
Date: Wed, 18 Feb 2015 11:07:17 +0000
Subject: [PATCH 41/N] fixup! Add functionality for converting UNIX paths in
arguments and environment variables to Windows form for native Win32
applications.

Let's teach MSYS2's path conversion to leave Git's :name and :/message
arguments alone, please. These arguments start with colons and are hence
unlikely to contain a path list (a path list starting with a colon would
start with an empty item?!?).

Without this patch, you will see this:

$ GIT_TRACE=1 /c/Program\ Files/Git/cmd/git version :/message
13:48:44.258390 exec-cmd.c:244 trace: resolved executable dir: C:/Program Files/Git/mingw64/bin
13:48:44.269314 git.c:463 trace: built-in: git version ';C:\msys64\message'
git version 2.43.0.windows.1

In other words, the argument `:/message` is mangled in an undesired way.

This addresses the expectations of the following test cases in the test
suite of https://github.com/git/git/tree/v2.43.0:

-t0060.81 <drive-letter>:\\abc is an absolute path
-t1501.35 Auto discovery
-t1501.36 $GIT_DIR/common overrides core.worktree
-t1501.37 $GIT_WORK_TREE overrides $GIT_DIR/common
-t1506.3 correct relative file objects (0)
-t1506.8 correct relative file objects (5)
-t1506.9 correct relative file objects (6)
-t2070.7 restore --staged uses HEAD as source
-t3013.16 git ls-files --format with relative path
-t3400.6 rebase, with <onto> and <upstream> specified as :/quuxery
-t3404.84 rebase -i, with <onto> and <upstream> specified as :/quuxery
-t3703.2 add :/
-t3703.3 add :/anothersub
-t4202.8 oneline
-t4202.22 git log --no-walk <commits> sorts by commit time
-t4202.23 git log --no-walk=sorted <commits> sorts by commit time
-t4202.24 git log --line-prefix="=== " --no-walk <commits> sorts by commit time
-t4202.25 git log --no-walk=unsorted <commits> leaves list of commits as given
-t4202.26 git show <commits> leaves list of commits as given
-t4202.138 log --source paints branch names
-t4202.139 log --source paints tag names
-t4202.140 log --source paints symmetric ranges
-t4208.2 "git log :/" should not be ambiguous
-t4208.3 "git log :/a" should be ambiguous (applied both rev and worktree)
-t4208.4 "git log :/a -- " should not be ambiguous
-t4208.5 "git log :/detached -- " should find a commit only in HEAD
-t4208.7 "git log :/detached -- " should find HEAD only of own worktree
-t4208.10 "git log :/in" should not be ambiguous
-t4208.13 git log HEAD -- :/
-t5616.43 lazy-fetch in submodule succeeds
-t6132.7 t_e_i() exclude sub2 from sub
-t6132.14 m_p_d() exclude sub2 from sub
-t6132.19 grep --untracked PATTERN
-t6132.21 grep --untracked PATTERN :(exclude)*FILE
-t6133.6 :/*.t from a subdir dwims to a pathspec
-t7201.14 checkout to detach HEAD with :/message
-t9903.37 prompt - untracked files status indicator - untracked files
-t9903.39 prompt - untracked files status indicator - non-empty untracked dir
-t9903.40 prompt - untracked files status indicator - untracked files outside cwd
-t9903.44 prompt - untracked files status indicator - shell variable set with config enabled
-t9903.56 prompt - bash color pc mode - untracked files status indicator

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
winsup/cygwin/msys2_path_conv.cc | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/winsup/cygwin/msys2_path_conv.cc b/winsup/cygwin/msys2_path_conv.cc
index 35b7757..8870d38 100644
--- a/winsup/cygwin/msys2_path_conv.cc
+++ b/winsup/cygwin/msys2_path_conv.cc
@@ -356,6 +356,12 @@ skip_p2w:
return NONE;
}

+ /*
+ * Prevent Git's :file.txt and :/message syntax from beeing modified.
+ */
+ if (*it == ':')
+ goto skip_p2w;
+
while (!isalnum(*it) && *it != '/' && *it != '\\' && *it != ':' && *it != '-' && *it != '.') {
recurse = true;
it = ++*src;
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
From cfc7696e0825563fb4245377ab70887cde160cd1 Mon Sep 17 00:00:00 2001
From: Johannes Schindelin <johannes.schindelin@gmx.de>
Date: Sun, 22 Feb 2015 18:33:48 +0100
Subject: [PATCH 42/N] fixup! Add functionality for converting UNIX paths in
arguments and environment variables to Windows form for native Win32
applications.

With this change, MSYS2's path conversion leaves paths containing any
special characters alone.

This addresses the expectations of the following test cases in the test
suite of https://github.com/git/git/tree/v2.43.0:

-t1091.13 set sparse-checkout using builtin
-t1092.82 grep sparse directory within submodules
-t1402.56 ref name '*/foo' is valid with options --refspec-pattern
-t1402.57 ref name '*/foo' is valid with options --refspec-pattern --allow-onelevel
-t1402.59 ref name '*/foo' is valid with options --refspec-pattern --normalize
-t3001.25 ls-files with "**" patterns
-t3001.26 ls-files with "**" patterns and --directory
-t3070.423 wildmatch: match 'foo' '**/foo'
-t3070.425 iwildmatch: match 'foo' '**/foo'
-t3070.433 wildmatch: match 'XXX/foo' '**/foo'
-t3070.435 iwildmatch: match 'XXX/foo' '**/foo'
-t3070.437 pathmatch: match 'XXX/foo' '**/foo'
-t3070.439 ipathmatch: match 'XXX/foo' '**/foo'
-t3070.443 wildmatch: match 'bar/baz/foo' '**/foo'
-t3070.445 iwildmatch: match 'bar/baz/foo' '**/foo'
-t3070.447 pathmatch: match 'bar/baz/foo' '**/foo'
-t3070.449 ipathmatch: match 'bar/baz/foo' '**/foo'
-t3070.457 pathmatch: match 'bar/baz/foo' '*/foo'
-t3070.459 ipathmatch: match 'bar/baz/foo' '*/foo'
-t3070.467 pathmatch: match 'foo/bar/baz' '**/bar*'
-t3070.469 ipathmatch: match 'foo/bar/baz' '**/bar*'
-t3070.473 wildmatch: match 'deep/foo/bar/baz' '**/bar/*'
-t3070.475 iwildmatch: match 'deep/foo/bar/baz' '**/bar/*'
-t3070.477 pathmatch: match 'deep/foo/bar/baz' '**/bar/*'
-t3070.479 ipathmatch: match 'deep/foo/bar/baz' '**/bar/*'
-t3070.487 pathmatch: match 'deep/foo/bar/baz/' '**/bar/*'
-t3070.489 ipathmatch: match 'deep/foo/bar/baz/' '**/bar/*'
-t3070.493 wildmatch: match 'deep/foo/bar/baz/' '**/bar/**'
-t3070.495 iwildmatch: match 'deep/foo/bar/baz/' '**/bar/**'
-t3070.497 pathmatch: match 'deep/foo/bar/baz/' '**/bar/**'
-t3070.499 ipathmatch: match 'deep/foo/bar/baz/' '**/bar/**'
-t3070.513 wildmatch: match 'deep/foo/bar/' '**/bar/**'
-t3070.515 iwildmatch: match 'deep/foo/bar/' '**/bar/**'
-t3070.517 pathmatch: match 'deep/foo/bar/' '**/bar/**'
-t3070.519 ipathmatch: match 'deep/foo/bar/' '**/bar/**'
-t3070.527 pathmatch: match 'foo/bar/baz' '**/bar**'
-t3070.529 ipathmatch: match 'foo/bar/baz' '**/bar**'
-t3070.533 wildmatch: match 'foo/bar/baz/x' '*/bar/**'
-t3070.535 iwildmatch: match 'foo/bar/baz/x' '*/bar/**'
-t3070.537 pathmatch: match 'foo/bar/baz/x' '*/bar/**'
-t3070.539 ipathmatch: match 'foo/bar/baz/x' '*/bar/**'
-t3070.547 pathmatch: match 'deep/foo/bar/baz/x' '*/bar/**'
-t3070.549 ipathmatch: match 'deep/foo/bar/baz/x' '*/bar/**'
-t3070.553 wildmatch: match 'deep/foo/bar/baz/x' '**/bar/*/*'
-t3070.555 iwildmatch: match 'deep/foo/bar/baz/x' '**/bar/*/*'
-t3070.557 pathmatch: match 'deep/foo/bar/baz/x' '**/bar/*/*'
-t3070.559 ipathmatch: match 'deep/foo/bar/baz/x' '**/bar/*/*'
-t3070.633 wildmatch: match 'XXX/\' '*/\\'
-t3070.635 iwildmatch: match 'XXX/\' '*/\\'
-t3070.637 pathmatch: match 'XXX/\' '*/\\'
-t3070.639 ipathmatch: match 'XXX/\' '*/\\'
-t3070.763 wildmatch: match 'foo/bar/baz/to' '**/t[o]'
-t3070.765 iwildmatch: match 'foo/bar/baz/to' '**/t[o]'
-t3070.767 pathmatch: match 'foo/bar/baz/to' '**/t[o]'
-t3070.769 ipathmatch: match 'foo/bar/baz/to' '**/t[o]'
-t3070.1493 wildmatch: match 'abcd/abcdefg/abcdefghijk/abcdefghijklmnop.txt' '**/*a*b*g*n*t'
-t3070.1495 iwildmatch: match 'abcd/abcdefg/abcdefghijk/abcdefghijklmnop.txt' '**/*a*b*g*n*t'
-t3070.1497 pathmatch: match 'abcd/abcdefg/abcdefghijk/abcdefghijklmnop.txt' '**/*a*b*g*n*t'
-t3070.1499 ipathmatch: match 'abcd/abcdefg/abcdefghijk/abcdefghijklmnop.txt' '**/*a*b*g*n*t'
-t3070.1533 wildmatch: match 'foo/bba/arr' '*/*/*'
-t3070.1535 iwildmatch: match 'foo/bba/arr' '*/*/*'
-t3070.1537 pathmatch: match 'foo/bba/arr' '*/*/*'
-t3070.1539 ipathmatch: match 'foo/bba/arr' '*/*/*'
-t3070.1547 pathmatch: match 'foo/bb/aa/rr' '*/*/*'
-t3070.1549 ipathmatch: match 'foo/bb/aa/rr' '*/*/*'
-t3070.1553 wildmatch: match 'foo/bb/aa/rr' '**/**/**'
-t3070.1555 iwildmatch: match 'foo/bb/aa/rr' '**/**/**'
-t3070.1557 pathmatch: match 'foo/bb/aa/rr' '**/**/**'
-t3070.1559 ipathmatch: match 'foo/bb/aa/rr' '**/**/**'
-t3070.1583 wildmatch: match 'ab/cXd/efXg/hi' '*/*X*/*/*i'
-t3070.1585 iwildmatch: match 'ab/cXd/efXg/hi' '*/*X*/*/*i'
-t3070.1587 pathmatch: match 'ab/cXd/efXg/hi' '*/*X*/*/*i'
-t3070.1589 ipathmatch: match 'ab/cXd/efXg/hi' '*/*X*/*/*i'
-t3070.1593 wildmatch: match 'ab/cXd/efXg/hi' '**/*X*/**/*i'
-t3070.1595 iwildmatch: match 'ab/cXd/efXg/hi' '**/*X*/**/*i'
-t3070.1597 pathmatch: match 'ab/cXd/efXg/hi' '**/*X*/**/*i'
-t3070.1599 ipathmatch: match 'ab/cXd/efXg/hi' '**/*X*/**/*i'
-t5500.154 fetch-pack --diag-url ./[::1]:repo
-t5500.156 fetch-pack --diag-url ./[::1]:23:repo
-t5500.165 fetch-pack --diag-url [::1]:/~repo
-t5500.251 fetch-pack --diag-url ./[::1]:re:po
-t5500.253 fetch-pack --diag-url ./[::1]:23:re:po
-t5500.262 fetch-pack --diag-url [::1]:/~re:po
-t5500.348 fetch-pack --diag-url ./[::1]:re/po
-t5500.350 fetch-pack --diag-url ./[::1]:23:re/po
-t5500.358 fetch-pack --diag-url [::1]:re/po
-t5500.359 fetch-pack --diag-url [::1]:/~re/po
-t5601.63 clone [::1]:rep/home/project
-t5601.66 clone [::1]:/~repo
-t6018.17 rev-parse --exclude with --branches
-t6018.85 rev-list --exclude with --branches
-t6130.20 **/ works with --glob-pathspecs
-t7817.1 setup
-t7817.2 working tree grep honors sparse checkout
-t7817.3 grep searches unmerged file despite not matching sparsity patterns
-t7817.5 grep --recurse-submodules honors sparse checkout in submodule
-t7817.7 working tree grep does not search the index with CE_VALID and SKIP_WORKTREE
-t9902.55 __git_refs - full refs
-t9902.58 __git_refs - remote on local file system - full refs
-t9902.75 __git refs - excluding full refs

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
winsup/cygwin/msys2_path_conv.cc | 15 +++++++++++++++
1 file changed, 15 insertions(+)

diff --git a/winsup/cygwin/msys2_path_conv.cc b/winsup/cygwin/msys2_path_conv.cc
index 8870d38..2646dc0 100644
--- a/winsup/cygwin/msys2_path_conv.cc
+++ b/winsup/cygwin/msys2_path_conv.cc
@@ -362,6 +362,21 @@ skip_p2w:
if (*it == ':')
goto skip_p2w;

+ while (it != end && *it) {
+ switch (*it) {
+ case '`':
+ case '\'':
+ case '"':
+ case '*':
+ case '?':
+ case '[':
+ case ']':
+ goto skip_p2w;
+ }
+ ++it;
+ }
+ it = *src;
+
while (!isalnum(*it) && *it != '/' && *it != '\\' && *it != ':' && *it != '-' && *it != '.') {
recurse = true;
it = ++*src;
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
From 6ed5a4279665baad20f30017adb38c6fcec3c2d3 Mon Sep 17 00:00:00 2001
From: Johannes Schindelin <johannes.schindelin@gmx.de>
Date: Wed, 18 Feb 2015 11:07:17 +0000
Subject: [PATCH 43/N] fixup! Add functionality for converting UNIX paths in
arguments and environment variables to Windows form for native Win32
applications.

We do not perform tilde expansion in the MSys2 runtime; let's leave
paths containing '/~' intact for programs that want to expand such paths
themselves.

This addresses the expectations of the following test cases in the test
suite of https://github.com/git/git/tree/v2.43.0:

-t5500.163 fetch-pack --diag-url host:/~repo
-t5500.260 fetch-pack --diag-url host:/~re:po
-t5500.357 fetch-pack --diag-url host:/~re/po
-t5601.65 clone host:/~repo

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
winsup/cygwin/msys2_path_conv.cc | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/winsup/cygwin/msys2_path_conv.cc b/winsup/cygwin/msys2_path_conv.cc
index 2646dc0..b292add 100644
--- a/winsup/cygwin/msys2_path_conv.cc
+++ b/winsup/cygwin/msys2_path_conv.cc
@@ -372,6 +372,10 @@ skip_p2w:
case '[':
case ']':
goto skip_p2w;
+ case '/':
+ if (it + 1 < end && it[1] == '~')
+ goto skip_p2w;
+ break;
}
++it;
}
Loading

0 comments on commit a26a0b0

Please sign in to comment.