On Cygwin support both UNIX and DOS style path-names
cover On Cygwin support both UNIX and DOS style path-names
This is the second version of this serie after Theo review. It includes the patch from Theo first and mine after.
Let me know if it looks ok. Thanks.
PATCH 1/2 git-compat-util: add generic find_last_dir_sep that respects is_dir_sep
From: Theo Niessink <[email protected]>
Move MinGW's find_last_dir_sep to git-compat-util.h, so it can also be used on other platforms that define is_dir_sep, e.g. Cygwin.
--- compat/mingw.h | 9 --------- git-compat-util.h | 12 ++++++++++++ 2 files changed, 12 insertions(+), 9 deletions(-)
compat/mingw.h +0 -9
@@ -300,15 +300,6 @@ int winansi_fprintf(FILE *stream, const char *format, ...) __attribute__((format#define has_dos_drive_prefix (path) (isalpha(*(path)) && (path)[1] == ':')#define is_dir_sep (c) ((c) == '/' || (c) == '\\') -static inline char *mingw_find_last_dir_sep (const char *path) -{ -char *ret =NULL ; -for (; *path; ++path) -if (is_dir_sep (*path)) - ret = (char *)path; -return ret; -} -#define find_last_dir_sep mingw_find_last_dir_sep#define PATH_SEP ';'#define PRIuMAX "I64u"
git-compat-util.h +12 -0
@@ -211,6 +211,18 @@ extern char *gitbasename(char *);#define has_dos_drive_prefix (path) 0#endif +#if !defined(find_last_dir_sep) && defined(is_dir_sep) +static inline char *compat_find_last_dir_sep (const char *path) +{ +char *ret =NULL ; +for (; *path; ++path) +if (is_dir_sep (*path)) + ret = (char *)path; +return ret; +} +#define find_last_dir_sep compat_find_last_dir_sep +#endif +#ifndef is_dir_sep#define is_dir_sep (c) ((c) == '/')#endif
Signature · 1 line
1.7.6.404.g5d2fc
PATCH 2/2 On Cygwin support both UNIX and DOS style path-names
In reply to Pascal ObryIn fact Cygwin supports both, so make Git agree with this. The failing case is when a file is committed in a sub-dir of the repository using a log message from a file specified with a DOS style path-name. To reproduce:
$ cd src $ git commit -F c:\tmp\log.txt file.c fatal: could not read log file 'src/c:\tmp\log.txt': No such file \ or directory.
--- compat/cygwin.h | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
compat/cygwin.h +3 -0
@@ -7,3 +7,6 @@ extern stat_fn_t cygwin_lstat_fn;#define stat (path, buf) (*cygwin_stat_fn)(path, buf)#define lstat (path, buf) (*cygwin_lstat_fn)(path, buf) + +#define has_dos_drive_prefix (path) (isalpha(*(path)) && (path)[1] == ':') +#define is_dir_sep (c) ((c) == '/' || (c) == '\\')
Signature · 1 line
1.7.6.404.g5d2fc
Quoted 20 lines · Pascal Obry
In fact Cygwin supports both, so make Git agree with this. The failing case is when a file is committed in a sub-dir of the repository using a log message from a file specified with a DOS style path-name. To reproduce:
$ cd src $ git commit -F c:\tmp\log.txt file.c fatal: could not read log file 'src/c:\tmp\log.txt': No such file \ or directory.Signed-off-by Pascal Obry <[email protected]>--- compat/cygwin.h | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)compat/cygwin.h +0
-0
compat/cygwin.h extern stat_fn_t cygwin_lstat_fn; · line 12
Quoted 6 lines
compat/cygwin.h +3
-0@@ -7,3 +7,6 @@ extern stat_fn_t cygwin_lstat_fn;#define stat (path, buf) (*cygwin_stat_fn)(path, buf)#define lstat (path, buf) (*cygwin_lstat_fn)(path, buf) + +#define has_dos_drive_prefix (path) (isalpha(*(path)) && (path)[1] == ':') +#define is_dir_sep (c) ((c) == '/' || (c) == '\\')
I wonder if these two that are the same as mingw should further be consolidated into one implementation, something like below.
Note that I am just wondering, not suggesting, without knowing which is better.
compat/cygwin.h | 5 ++--- compat/mingw.h | 3 +-- git-compat-util.h | 11 ++++------- 3 files changed, 7 insertions(+), 12 deletions(-)
compat/cygwin.h +2 -3
@@ -1,12 +1,11 @@#include <sys/types.h> #include <sys/stat.h> +#define DOS_STYLE_DIR_SEP 1 +typedef int (*stat_fn_t )(const char *,struct stat *);extern stat_fn_t cygwin_stat_fn;extern stat_fn_t cygwin_lstat_fn;#define stat (path, buf) (*cygwin_stat_fn)(path, buf)#define lstat (path, buf) (*cygwin_lstat_fn)(path, buf) - -#define has_dos_drive_prefix (path) (isalpha(*(path)) && (path)[1] == ':') -#define is_dir_sep (c) ((c) == '/' || (c) == '\\')
compat/mingw.h +1 -2
@@ -298,8 +298,7 @@ int winansi_fprintf(FILE *stream, const char *format, ...) __attribute__((format* git specific compatibility */ -#define has_dos_drive_prefix (path) (isalpha(*(path)) && (path)[1] == ':') -#define is_dir_sep (c) ((c) == '/' || (c) == '\\') +#define DOS_STYLE_DIR_SEP 1#define PATH_SEP ';'#define PRIuMAX "I64u"
git-compat-util.h +4 -7
@@ -211,7 +211,9 @@ extern char *gitbasename(char *);#define has_dos_drive_prefix (path) 0#endif -#if !defined(find_last_dir_sep) && defined(is_dir_sep) +#if defined(DOS_STYLE_DIR_SEP ) +#define has_dos_drive_prefix (path) (isalpha(*(path)) && (path)[1] == ':') +#define is_dir_sep (c) ((c) == '/' || (c) == '\\')static inline char *compat_find_last_dir_sep (const char *path) {char *ret =NULL ;
@@ -221,13 +223,8 @@ static inline char *compat_find_last_dir_sep(const char *path) return ret; }#define find_last_dir_sep compat_find_last_dir_sep -#endif - -#ifndef is_dir_sep +#else #define is_dir_sep (c) ((c) == '/') -#endif - -#ifndef find_last_dir_sep#define find_last_dir_sep (path) strrchr(path, '/')#endif
Quoted 2 lines · Junio C Hamano
I wonder if these two that are the same as mingw should further be consolidated into one implementation, something like below.
Fine with me.
Signature · 8 lines
--|------------------------------------------------------ --| Pascal Obry Team-Ada Member --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE --|------------------------------------------------------ --| http://www.obry.net - http://v2p.fr.eu.org --| "The best way to travel is by means of imagination" --| --| gpg --keyserver keys.gnupg.net --recv-key F949BD3B
Quoted 32 lines · Junio C Hamano
Quoted 20 lines · Pascal Obry
In fact Cygwin supports both, so make Git agree with this. The failing case is when a file is committed in a sub-dir of the repository using a log message from a file specified with a DOS style path-name. To reproduce:
$ cd src $ git commit -F c:\tmp\log.txt file.c fatal: could not read log file 'src/c:\tmp\log.txt': No such file \ or directory.Signed-off-by Pascal Obry <[email protected]>---
compat/cygwin.h | 3 +++1 files changed, 3 insertions(+), 0 deletions(-)compat/cygwin.h +0
-0compat/cygwin.h extern stat_fn_t cygwin_lstat_fn; · line 12
Quoted 6 lines
compat/cygwin.h +3
-0@@ -7,3 +7,6 @@ extern stat_fn_t cygwin_lstat_fn; #define stat(path, buf) (*cygwin_stat_fn)(path, buf) #define lstat(path, buf) (*cygwin_lstat_fn)(path, buf) + +#define has_dos_drive_prefix (path) (isalpha(*(path)) && (path)[1] == ':') +#define is_dir_sep (c) ((c) == '/' || (c) == '\\')I wonder if these two that are the same as mingw should further be consolidated into one implementation, something like below.
Quoted 2 lines
Note that I am just wondering, not suggesting, without knowing which is better.
IMO this becomes a bit hard to read as you have to ping-pong between sources to understand exactly what that flag does. We have compat/win32.h, perhaps we should move the macros there and include it from both compat/mingw.h and compat/cygwin.h instead (given that we're going to do this, of course)?
Quoted 9 lines · Pascal Obry
In fact Cygwin supports both, so make Git agree with this. The failing case is when a file is committed in a sub-dir of the repository using a log message from a file specified with a DOS style path-name. To reproduce:
$ cd src $ git commit -F c:\tmp\log.txt file.c fatal: could not read log file 'src/c:\tmp\log.txt': No such file \ or directory.
Cygwin is a unix-layer on top of Windows, designed to play by the POSIX-rules. So why would you want to support Windows-style paths on Cygwin?
If you want a Git that handles Windows paths, use Git for Windows...
Quoted 3 lines · Erik Faye-Lund
Cygwin is a unix-layer on top of Windows, designed to play by the POSIX-rules. So why would you want to support Windows-style paths on Cygwin?
Because cygwin toolset does support \.
Quoted 1 line
If you want a Git that handles Windows paths, use Git for Windows...
Note that Windows is a special case as even the Win32 API does support \ and /, so every tool on Windows seems to handle nicely this. Why not Git, be it Cygwin/Git. If it does not break anything else.
Signature · 8 lines
--|------------------------------------------------------ --| Pascal Obry Team-Ada Member --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE --|------------------------------------------------------ --| http://www.obry.net - http://v2p.fr.eu.org --| "The best way to travel is by means of imagination" --| --| gpg --keyserver keys.gnupg.net --recv-key F949BD3B
Quoted 8 lines · Pascal Obry
Quoted 4 lines · Erik Faye-Lund
Cygwin is a unix-layer on top of Windows, designed to play by the POSIX-rules. So why would you want to support Windows-style paths on Cygwin?
Because cygwin toolset does support \.
Are you saying that the built-in Cygwin tools (like ls etc) support Windows-style paths (C:\path\to\file)? If that is the case, I completely understand the desire to accept Windows-paths.
Quoted 5 lines
Quoted 1 line
If you want a Git that handles Windows paths, use Git for Windows...
Note that Windows is a special case as even the Win32 API does support \ and /, so every tool on Windows seems to handle nicely this. Why not Git, be it Cygwin/Git. If it does not break anything else.
If the Cygwin-tools does not support drive-prefixes (i.e "C:\") but does support both slashes as path-separators, then I agree with the patch but not with the commit message.
Quoted 3 lines · Erik Faye-Lund
Are you saying that the built-in Cygwin tools (like ls etc) support Windows-style paths (C:\path\to\file)? If that is the case, I completely understand the desire to accept Windows-paths.
Exactly.
Signature · 8 lines
--|------------------------------------------------------ --| Pascal Obry Team-Ada Member --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE --|------------------------------------------------------ --| http://www.obry.net - http://v2p.fr.eu.org --| "The best way to travel is by means of imagination" --| --| gpg --keyserver keys.gnupg.net --recv-key F949BD3B
Quoted 16 lines · Erik Faye-Lund
Quoted 8 lines · Pascal Obry
Quoted 4 lines · Erik Faye-Lund
Cygwin is a unix-layer on top of Windows, designed to play by the POSIX-rules. So why would you want to support Windows-style paths on Cygwin?
Because cygwin toolset does support \.
Are you saying that the built-in Cygwin tools (like ls etc) support Windows-style paths (C:\path\to\file)? If that is the case, I completely understand the desire to accept Windows-paths.
Quoted 2 lines
Quoted 1 line
If you want a Git that handles Windows paths, use Git for Windows...
Quoted 8 lines
Quoted 3 lines
Note that Windows is a special case as even the Win32 API does support \ and /, so every tool on Windows seems to handle nicely this. Why not Git, be it Cygwin/Git. If it does not break anything else.
If the Cygwin-tools does not support drive-prefixes (i.e "C:\") but does support both slashes as path-separators, then I agree with the patch but not with the commit message.
correction: if that is the case, I agree with the is_dir_sep-part, but not the has_dos_drive_prefix-part of the patch (and also not the example from the commit message)
Quoted 6 lines · Pascal Obry
Quoted 3 lines · Erik Faye-Lund
Cygwin is a unix-layer on top of Windows, designed to play by the POSIX-rules. So why would you want to support Windows-style paths on Cygwin?
Because cygwin toolset does support \.
Hmm, if you don't mind escaping it in bash all the time!
Quoted 6 lines
Quoted 2 lines
If you want a Git that handles Windows paths, use Git for Windows...
Note that Windows is a special case as even the Win32 API does support \
and /, so every tool on Windows seems to handle nicely this. Why not Git, be it Cygwin/Git. If it does not break anything else.
Hmm, I wouldn't be too sure of that, either ...
ATB,
Ramsay Jones
Quoted 11 lines · Erik Faye-Lund
Quoted 9 lines · Pascal Obry
In fact Cygwin supports both, so make Git agree with this. The failing case is when a file is committed in a sub-dir of the repository using a log message from a file specified with a DOS style path-name. To reproduce:
$ cd src $ git commit -F c:\tmp\log.txt file.c fatal: could not read log file 'src/c:\tmp\log.txt': No such file \ or directory.
Quoted 5 lines
Cygwin is a unix-layer on top of Windows, designed to play by the POSIX-rules. So why would you want to support Windows-style paths on Cygwin?
If you want a Git that handles Windows paths, use Git for Windows...
Indeed, I have to agree. This takes the cygwin port in the wrong direction ...
ATB,
Ramsay Jones
Quoted 9 lines · Pascal Obry
In fact Cygwin supports both, so make Git agree with this. The failing case is when a file is committed in a sub-dir of the repository using a log message from a file specified with a DOS style path-name. To reproduce:
$ cd src $ git commit -F c:\tmp\log.txt file.c fatal: could not read log file 'src/c:\tmp\log.txt': No such file \ or directory.
Hmm, are you using bash or cmd.exe? Using bash I get the following:
$ cd src
$ git commut -F c:\tmp\log.txt file.c
fatal: could not read file 'src/c:tmplog.txt': No such file or directory
$ Which is what I would expect of (any) posix shell, viz:
$ ls c:\
Quoted 1 line
^C
$ ls c:\\
AUTOEXEC.BAT* NTDETECT.COM* WATCOM/ msysgit/
CMPNENTS/ Program Files/ WINDOWS/ msysgit-old/
CONFIG.SYS* RECYCLER/ boot.ini* ntldr*
Documents and Settings/ SUPPORT/ cygwin/ pagefile.sys
I386/ SWSTAMP.TXT* cygwintemp/ ssl/
IO.SYS* System Volume Information/ dm/ uname/
MSDOS.SYS* TOOLSCD/ dm840/ zlib/
MSOCache/ VALUEADD/ hiberfil.sys
$ If you want to use cmd.exe as your shell, I suspect msysGit (Git For Windows) may be a better fit.
ATB,
Ramsay Jones
Quoted 6 lines · Ramsay Jones
Quoted 5 lines · Pascal Obry
In fact Cygwin supports both, so make Git agree with this. The failing case is when a file is committed in a sub-dir of the repository using a log message from a file specified with a DOS style path-name. To reproduce:
Quoted 6 lines
Quoted 4 lines
$ cd src $ git commit -F c:\tmp\log.txt file.c fatal: could not read log file 'src/c:\tmp\log.txt': No such file \ or directory.Hmm, are you using bash or cmd.exe? Using bash I get the following:
bash.
Quoted 8 lines
$ cd src $ git commut -F c:\tmp\log.txt file.c fatal: could not read file 'src/c:tmplog.txt': No such file or directory $Which is what I would expect of (any) posix shell, viz:
Quoted 11 lines
$ ls c:\
> ^C
$ ls c:\\
AUTOEXEC.BAT* NTDETECT.COM* WATCOM/ msysgit/
CMPNENTS/ Program Files/ WINDOWS/ msysgit-old/
CONFIG.SYS* RECYCLER/ boot.ini* ntldr*
Documents and Settings/ SUPPORT/ cygwin/ pagefile.sys
I386/ SWSTAMP.TXT* cygwintemp/ ssl/
IO.SYS* System Volume Information/ dm/ uname/
MSDOS.SYS* TOOLSCD/ dm840/ zlib/
MSOCache/ VALUEADD/ hiberfil.sysExactly, \\ this is what I have used and this is the bug. Cygwin supports ls c:\\ so should Cygwin/Git. My quoted example was missing the escape \.
Signature · 8 lines
--|------------------------------------------------------ --| Pascal Obry Team-Ada Member --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE --|------------------------------------------------------ --| http://www.obry.net - http://v2p.fr.eu.org --| "The best way to travel is by means of imagination" --| --| gpg --keyserver keys.gnupg.net --recv-key F949BD3B
Quoted 7 lines · Pascal Obry
Quoted 6 lines · Ramsay Jones
Quoted 5 lines · Pascal Obry
In fact Cygwin supports both, so make Git agree with this. The failing case is when a file is committed in a sub-dir of the repository using a log message from a file specified with a DOS style path-name. To reproduce:
Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
$ cd src $ git commit -F c:\tmp\log.txt file.c fatal: could not read log file 'src/c:\tmp\log.txt': No such file \ or directory.Hmm, are you using bash or cmd.exe? Using bash I get the following:
bash.
Ah, OK. The example in your commit message looked odd (ie incorrect) which made me think that you were probably using cnd.exe, so ...
Quoted 19 lines
Quoted 7 lines
$ cd src $ git commut -F c:\tmp\log.txt file.c fatal: could not read file 'src/c:tmplog.txt': No such file or directory $Which is what I would expect of (any) posix shell, viz:
Quoted 11 lines
$ ls c:\ > ^C $ ls c:\\ AUTOEXEC.BAT* NTDETECT.COM* WATCOM/ msysgit/ CMPNENTS/ Program Files/ WINDOWS/ msysgit-old/ CONFIG.SYS* RECYCLER/ boot.ini* ntldr* Documents and Settings/ SUPPORT/ cygwin/ pagefile.sys I386/ SWSTAMP.TXT* cygwintemp/ ssl/ IO.SYS* System Volume Information/ dm/ uname/ MSDOS.SYS* TOOLSCD/ dm840/ zlib/ MSOCache/ VALUEADD/ hiberfil.sys
Quoted 3 lines
Exactly, \\ this is what I have used and this is the bug. Cygwin supports ls c:\\ so should Cygwin/Git. My quoted example was missing the escape \.
... could you please correct your commit message. Thanks!
ATB,
Ramsay Jones
Quoted 1 line · Ramsay Jones
... could you please correct your commit message. Thanks!
Done, thanks for your review.
Pascal.
Signature · 8 lines
--|------------------------------------------------------ --| Pascal Obry Team-Ada Member --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE --|------------------------------------------------------ --| http://www.obry.net - http://v2p.fr.eu.org --| "The best way to travel is by means of imagination" --| --| gpg --keyserver keys.gnupg.net --recv-key F949BD3B
Quoted 22 lines · Ramsay Jones
Quoted 9 lines · Pascal Obry
In fact Cygwin supports both, so make Git agree with this. The failing case is when a file is committed in a sub-dir of the repository using a log message from a file specified with a DOS style path-name. To reproduce:
$ cd src $ git commit -F c:\tmp\log.txt file.c fatal: could not read log file 'src/c:\tmp\log.txt': No such file \ or directory.Hmm, are you using bash or cmd.exe? Using bash I get the following:
$ cd src $ git commut -F c:\tmp\log.txt file.c fatal: could not read file 'src/c:tmplog.txt': No such file or directory $Which is what I would expect of (any) posix shell, viz:
$ ls c:\Quoted 1 line
^C
Quoted 10 lines
$ ls c:\\
AUTOEXEC.BAT* NTDETECT.COM* WATCOM/ msysgit/
CMPNENTS/ Program Files/ WINDOWS/ msysgit-old/
CONFIG.SYS* RECYCLER/ boot.ini* ntldr*
Documents and Settings/ SUPPORT/ cygwin/ pagefile.sys
I386/ SWSTAMP.TXT* cygwintemp/ ssl/
IO.SYS* System Volume Information/ dm/ uname/
MSDOS.SYS* TOOLSCD/ dm840/ zlib/
MSOCache/ VALUEADD/ hiberfil.sys
$ FWIW, I use git on Cygwin and it works quite well. Cygwin supports Windows paths when quoted. So
$ ls 'C:\Users\vijay\Desktop'
works as expected. This is very useful when you're copying paths from, say, Windows Explorer, to Cygwin.
Quoted 7 lines
ATB,
Ramsay Jones--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 4 lines
Cheers ~vijay Gnus should be more complicated.
Am 05.08.2011 18:10, schrieb Pascal Obry:
Quoted 9 lines
In fact Cygwin supports both, so make Git agree with this. The failing case is when a file is committed in a sub-dir of the repository using a log message from a file specified with a DOS style path-name. To reproduce:
$ cd src $ git commit -F c:\tmp\log.txt file.c fatal: could not read log file 'src/c:\tmp\log.txt': No such file \ or directory.
Do you also want to support this:
$ git add src\file.c
i.e., backslash in pathspec? Then you need more than this:
compat/cygwin.h extern stat_fn_t cygwin_lstat_fn; · line 12
Quoted 2 lines
compat/cygwin.h +2
-0+#define has_dos_drive_prefix (path) (isalpha(*(path)) && (path)[1] == ':') +#define is_dir_sep (c) ((c) == '/' || (c) == '\\')
In particular, you have to enable backslash processing in setup.c:prefix_filename(), but then you lose the ability to escape special characters with the backslash.
-- Hannes