summaryrefslogtreecommitdiff
path: root/compat/mingw.c
AgeCommit message (Collapse)AuthorFilesLines
2008-11-27Merge branch 'js/mingw-rename-fix'Libravatar Junio C Hamano1-3/+12
* js/mingw-rename-fix: compat/mingw.c: Teach mingw_rename() to replace read-only files
2008-11-23compat/mingw.c: Teach mingw_rename() to replace read-only filesLibravatar Johannes Sixt1-3/+12
On POSIX, rename() can replace files that are not writable. On Windows, however, read-only files cannot be replaced without additional efforts: We have to make the destination writable first. Since the situations where the destination is read-only are rare, we do not make the destination writable on every invocation, but only if the first try to rename a file failed with an "access denied" error. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-11-06Windows: Make OpenSSH properly detect tty detachment.Libravatar Alexander Gavrilov1-2/+6
Apparently, CREATE_NO_WINDOW makes the OS tell the process that it has a console, but without actually creating the window. As a result, when git is started from GUI, ssh tries to ask its questions on the invisible console. This patch uses DETACHED_PROCESS instead, which clearly means that the process should be left without a console. The downside is that if the process manually calls AllocConsole, the window will appear. A similar thing might occur if it calls another console executable. Signed-off-by: Alexander Gavrilov <angavrilov@gmail.com> Acked-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-09-30mingw: move common functionality to win32.hLibravatar Dmitry Potapov1-38/+4
Some small Win32 specific functions will be shared by MinGW and Cygwin compatibility layer. Place them into a separate header. Signed-off-by: Dmitry Potapov <dpotapov@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-09-29mingw: remove use of _getdrive() from lstat/fstatLibravatar Dmitry Potapov1-3/+2
The field device is not used by Git, and putting the number of the current device is meaningless anyway. Signed-off-by: Dmitry Potapov <dpotapov@gmail.com> Acked-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-09-29compat/mingw: Support a timeout in the poll emulation if no fds are givenLibravatar Johannes Sixt1-1/+6
Our poll() emulation did not support the timeout argument. With this patch we support it for the simple case where poll() does not need to wait on file descriptors as well because this case amounts to a mere Sleep(). This is needed if the user sets help.autocorrect is set to a positive value. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-08-18Revert "Windows: Use a customized struct stat that also has the st_blocks ↵Libravatar Johannes Sixt1-20/+8
member." This reverts commit fc2ded5b08e071beed974117c0148781b1acc94a. As we do not need the member in struct stat, we do not need to have a custom "struct mingw_stat" anymore. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-08-18compat: introduce on_disk_bytes()Libravatar Junio C Hamano1-8/+0
Some platforms do not have st_blocks member in "struct stat"; mingw already emulates it by rounding it up to closest 512-byte blocks (even though it could overcount when a file has holes). The reason to use the member is only to figure out how many kilobytes the files occupy on-disk, so give a helper function in git-compat-util.h to compute this value. Signed-off-by: Junio C Hamano <gitster@pobox.com> Acked-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-07-19Teach lookup_prog not to select directoriesLibravatar Eric Raible1-1/+2
Without this simple fix "git gui" in the git source directory finds the git-gui directory instead of the tcl script in /usr/bin. Signed-off-by: Eric Raible <raible@gmail.com> Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-07-13help (Windows): Display HTML in default browser using Windows' shell APILibravatar Steffen Prohaska1-0/+22
The system's default browser for displaying HTML help pages is now used directly on Windows, instead of launching git-web--browser, which requires a Unix shell. Avoiding MSYS' bash when possible is good because it avoids potential path translation issues. In this case it is not too hard to avoid launching a shell, so let's avoid it. The Windows-specific code is implemented in compat/mingw.c to avoid platform-specific code in the main code base. On Windows, open_html is provided as a define. If open_html is not defined, git-web--browse is used. This approach avoids platform-specific ifdefs by using per-function ifdefs. The "ifndef open_html" together with the introductory comment should sufficiently warn developers, so that they hopefully will not break this mechanism. Signed-off-by: Steffen Prohaska <prohaska@zib.de> Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-06-26Windows: TMP and TEMP environment variables specify a temporary directory.Libravatar Johannes Sixt1-0/+13
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-26Windows: Use a customized struct stat that also has the st_blocks member.Libravatar Johannes Sixt1-8/+28
Windows's struct stat does not have a st_blocks member. Since we already have our own stat/lstat/fstat implementations, we can just as well use a customized struct stat. This patch introduces just that, and also fills in the st_blocks member. On the other hand, we don't provide members that are never used. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-26Windows: Add a custom implementation for utime().Libravatar Johannes Sixt1-0/+27
This is a necessary pendant to our lstat implementation: MSVCRT's implementations of lstat and utime do some adjustments if daylight saving time is in effect, but our lstat implementation doesn't do these adjustments and report the correct UTC time. With this implementation we omit the adjustments in utime() as well and always write UTC. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-26Windows: Add a new lstat and fstat implementation based on Win32 API.Libravatar Marius Storm-Olsen1-0/+132
This gives us a significant speedup when adding, committing and stat'ing files. Also, since Windows doesn't really handle symlinks, we let stat just uses lstat. We also need to replace fstat, since our implementation and the standard stat() functions report slightly different timestamps, possibly due to timezones. We simply report UTC in our implementation, and do our FILETIME to time_t conversion based on the document at http://support.microsoft.com/kb/167296. With Moe's repo structure (100K files in 100 dirs, containing 2-4 bytes) mkdir bummer && cd bummer; for ((i=0;i<100;i++)); do mkdir $i && pushd $i; for ((j=0;j<1000;j++)); do echo "$j" >$j; done; popd; done We get the following performance boost: With normal lstat & stat Custom lstat/fstat ------------------------ ------------------------ Command: git init Command: git init ------------------------ ------------------------ real 0m 0.047s real 0m 0.063s user 0m 0.031s user 0m 0.015s sys 0m 0.000s sys 0m 0.015s ------------------------ ------------------------ Command: git add . Command: git add . ------------------------ ------------------------ real 0m19.390s real 0m12.031s 1.6x user 0m 0.015s user 0m 0.031s sys 0m 0.030s sys 0m 0.000s ------------------------ ------------------------ Command: git commit -a.. Command: git commit -a.. ------------------------ ------------------------ real 0m30.812s real 0m16.875s 1.8x user 0m 0.015s user 0m 0.015s sys 0m 0.000s sys 0m 0.015s ------------------------ ------------------------ 3x Command: git-status 3x Command: git-status ------------------------ ------------------------ real 0m11.860s real 0m 5.266s 2.2x user 0m 0.015s user 0m 0.015s sys 0m 0.015s sys 0m 0.015s real 0m11.703s real 0m 5.234s user 0m 0.015s user 0m 0.015s sys 0m 0.000s sys 0m 0.000s real 0m11.672s real 0m 5.250s user 0m 0.031s user 0m 0.015s sys 0m 0.000s sys 0m 0.000s ------------------------ ------------------------ Command: git commit... Command: git commit... (single file) (single file) ------------------------ ------------------------ real 0m14.234s real 0m 7.735s 1.8x user 0m 0.015s user 0m 0.031s sys 0m 0.000s sys 0m 0.000s Signed-off-by: Marius Storm-Olsen <mstormo_git@storm-olsen.com> Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-26Windows: Implement a custom spawnve().Libravatar Johannes Sixt1-6/+197
The problem with Windows's own implementation is that it tries to be clever when a console program is invoked from a GUI application: In this case it sometimes automatically allocates a new console window. As a consequence, the IO channels of the spawned program are directed to the console, but the invoking application listens on channels that are now directed to nowhere. In this implementation we use the lowlevel facilities of CreateProcess(), which offers a flag to tell the system not to open a console. As a side effect, only stdin, stdout, and stderr channels will be accessible from C programs that are spawned. Other channels (file handles, pipe handles, etc.) are still inherited by the spawned program, but it doesn't get enough information to access them. Johannes Schindelin integrated path quoting and unified the various *execv* and *spawnv* helpers. Eric Raible suggested to also quote '{'. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-26Windows: Implement wrappers for gethostbyname(), socket(), and connect().Libravatar Johannes Sixt1-0/+46
gethostbyname() is the first function that calls into the Winsock library, and it is wrapped only to initialize the library. socket() is wrapped for two reasons: - Windows's socket() creates things that are like low-level file handles, and they must be converted into file descriptors first. - And these handles cannot be used with plain ReadFile()/WriteFile() because they are opened for "overlapped IO". We have to use WSASocket() to create non-overlapped IO sockets. connect() must be wrapped because Windows's connect() expects the low-level sockets, not file descriptors, and we must first unwrap the file descriptor before we can pass it on to Windows's connect(). Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-26Windows: A rudimentary poll() emulation.Libravatar Johannes Sixt1-1/+56
This emulation of poll() is by far not general. It assumes that the fds that are to be waited for are connected to pipes. The pipes are polled in a loop until data becomes available in at least one of them. If only a single fd is waited for, the implementation actually does not wait at all, but assumes that a subsequent read() will block. In order not to needlessly burn CPU time, the CPU is yielded to other processes before the next round in the poll loop using Sleep(0). Note that any sleep timeout greater than zero will reduce the efficiency by a magnitude. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-23Windows: Implement start_command().Libravatar Johannes Sixt1-0/+62
On Windows, we have spawnv() variants to run a child process instead of fork()/exec(). In order to attach pipe ends to stdin, stdout, and stderr, we have to use this idiom: save1 = dup(1); dup2(pipe[1], 1); spawnv(); dup2(save1, 1); close(pipe[1]); assuming that the descriptors created by pipe() are not inheritable. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-23Windows: A pipe() replacement whose ends are not inherited to children.Libravatar Johannes Sixt1-0/+45
On Unix the idiom to use a pipe is as follows: pipe(fd); pid = fork(); if (!pid) { dup2(fd[1], 1); close(fd[1]); close(fd[0]); ... } close(fd[1]); i.e. the child process closes the both pipe ends after duplicating one to the file descriptors where they are needed. On Windows, which does not have fork(), we never have an opportunity to (1) duplicate a pipe end in the child, (2) close unused pipe ends. Instead, we must use this idiom: save1 = dup(1); pipe(fd); dup2(fd[1], 1); spawn(...); dup2(save1, 1); close(fd[1]); i.e. save away the descriptor at the destination slot, replace by the pipe end, spawn process, restore the saved file. But there is a problem: Notice that the child did not only inherit the dup2()ed descriptor, but also *both* original pipe ends. Although the one end that was dup()ed could be closed before the spawn(), we cannot close the other end - the child inherits it, no matter what. The solution is to generate non-inheritable pipes. At the first glance, this looks strange: The purpose of pipes is usually to be inherited to child processes. But notice that in the course of actions as outlined above, the pipe descriptor that we want to inherit to the child is dup2()ed, and as it so happens, Windows's dup2() creates inheritable duplicates. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-23Windows: Wrap execve so that shell scripts can be invoked.Libravatar Johannes Sixt1-0/+184
When an external git command is invoked, it can be a Bourne shell script. This patch looks into the command file to see whether it is one. In this case, the command line is rearranged to invoke the shell with the proper arguments. With this change, scripted git commands work. Command line arguments to those scripts cannot be complex (contain spaces or double-quotes), yet. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-23Windows: Implement setitimer() and sigaction().Libravatar Johannes Sixt1-2/+110
The timer is implemented using a thread that calls the signal handler at regular intervals. We also replace Windows's signal() function because we must intercept that SIGALRM is set (which is used when a timer is canceled). Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-23Windows: Implement gettimeofday().Libravatar Johannes Sixt1-1/+14
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-23Windows: Work around misbehaved rename().Libravatar Johannes Sixt1-0/+25
Windows's rename() is based on the MoveFile() API, which fails if the destination exists. Here we work around the problem by using MoveFileEx(). Furthermore, the posixly correct error is returned if the destination is a directory. The implementation is still slightly incomplete, however, because of the missing error code translation: We assume that the failure is due to permissions. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-23Windows: A minimal implemention of getpwuid().Libravatar Johannes Sixt1-0/+8
getpwuid() is implemented just enough that GIT does not issue errors. Since the information that it returns is not very useful, users are required to set up user.name and user.email configuration. All uses of getpwuid() are like getpwuid(getuid()), hence, the return value of getuid() is irrelevant and the uid parameter is not even looked at. Side note: getpwnam() is only used to resolve '~' and '~username' paths, which is an idiom not known on Windows, hence, we don't implement it. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-23Windows: Implement a wrapper of the open() function.Libravatar Johannes Sixt1-0/+20
The wrapper does two things: - Requests to open /dev/null are redirected to open the nul pseudo file. - A request to open a file that currently exists as a directory on Windows fails with EACCES; this is changed to EISDIR. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-23Windows: Treat Windows style path names.Libravatar Johannes Sixt1-0/+13
GIT's guts work with a forward slash as a path separators. We do not change that. Rather we make sure that only "normalized" paths enter the depths of the machinery. We have to translate backslashes to forward slashes in the prefix and in command line arguments. Fortunately, all of them are passed through functions in setup.c. A macro has_dos_drive_path() is defined that checks whether a path begins with a drive letter+colon combination. This predicate is always false on Unix. Another macro is_dir_sep() abstracts that a backslash is also a directory separator on Windows. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-22Add target architecture MinGW.Libravatar Johannes Sixt1-0/+57
With this change GIT can be compiled and linked using MinGW. Builtins that only read the repository such as the log family and grep already work. Simple stubs are provided for a number of functions that the Windows C runtime does not offer. They will be completed in later patches. However, a fix for the snprintf/vsnprintf replacement is applied here to avoid buffer overflows. Dmitry Kakurin pointed out that access(..., X_OK) would always fails on Vista and suggested the -D__USE_MINGW_ACCESS workaround. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>