Commit Graph

128 Commits

Author SHA1 Message Date
Steffen Prohaska
d21c3cb9d4 Merge commit 'mingw/master' into devel 2008-06-30 12:26:19 +02:00
Johannes Sixt
ab87ad4c62 Touch-ups in comments and error strings in compat/mingw.c
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-23 10:56:39 +02:00
Johannes Sixt
3c965bf371 Handle getenv("TMPDIR") in a getenv() wrapper.
This removes an #ifdef MINGW in path.c.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-23 10:53:04 +02:00
Johannes Sixt
185fbb49c9 Rename my_mktime() to tm_to_time_t() and make it officially extern.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-23 10:51:19 +02:00
Johannes Sixt
0720c64e56 Fixup whitespace in compat/regex.[ch]
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-23 10:50:01 +02:00
Steffen Prohaska
370dbd0c74 Merge commit 'mingw/master' into devel 2008-06-14 12:05:26 +02:00
Peter
e77b5a4f7c Add ANSI control code emulation for the Windows console
This adds only the minimum necessary to keep git pull/merge's diffstat from
wrapping. Notably absent is support for the K (erase) operation, and support
for POSIX write.

Cygwin does not need the WIN_ANSI define, since it has its own (more complete)
ANSI emulation.

Signed-off-by: Peter Harris <git@peter.is-a-geek.org>
2008-06-12 10:27:00 -04:00
Johannes Sixt
3ec8d36fbf Fix vsnprintf() emulation again.
On Windows, if the native vsnprintf() fills the buffer, it does not add
the terminating NUL. The earlier commit f32edf6b tried to fix the
emulation, but the fix worked only if the formatted string fitted into
the buffer exactly. However, there are callers that do not try to resize
the buffer if it overflows, and in these cases the resulting string
remained without the trailing NUL. This patch adds the NUL in all cases.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-11 15:24:07 +02:00
Steffen Prohaska
e5c520d26d Merge branch 'pha/shbang' into devel 2008-06-08 14:07:19 +02:00
Peter Harris
3ad18f2446 Scan for \r in addition to \n when reading shbang lines
Signed-off-by: Steffen Prohaska <prohaska@zib.de>
2008-06-08 14:05:57 +02:00
raible
b1013825f9 mingw: Quote '{}' to work around an error in MSYS' glob()
MSYS expands '{}' in paths even if the pattern between the
braces does not contain a comma. See
http://article.gmane.org/gmane.comp.version-control.msysgit/2341
for a detailed discussion.

This commit fixes (at least) the case of "git stash apply stash@{1}".
Note that "git-stash apply stash@{1}" works even without this patch
(because it is executed directly by /bin/sh).

Note that git-stash still has a bug whereby it doesn't validate
its final argument ("stash@{1}" in this case).  This commit does
nothing to fix that problem.

Signed-off-by: Steffen Prohaska <prohaska@zib.de>
2008-06-08 13:19:26 +02:00
Johannes Sixt
97809f013c Add #defines for SIGHUP and SIGQUIT.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-04 20:30:54 +02:00
Johannes Sixt
e561672203 Merge branch 'master' of git://repo.or.cz/alt-git.git 2008-05-15 21:46:46 +02:00
Brandon Casey
eb120e699f compat/fopen.c: avoid clobbering the system defined fopen macro
Some systems define fopen as a macro based on compiler settings.
The previous technique for reverting to the system fopen function
by merely undefining fopen is inadequate in this case. Instead,
avoid defining fopen entirely when compiling this source file.

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
Tested-by: Mike Ralphson <mike@abacus.co.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-05-08 17:43:01 -07:00
Johannes Sixt
f32edf6b14 snprintf replacement: Make sure the result is NUL terminated.
On Windows, if the resulting string fits exactly in the provided buffer,
but not the terminating NUL, then the return value of the system's
vsnprintf is the number of characters written. But since we had reserved
an extra byte anyway, we only need to make sure that the result is
NUL terminated.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-04-03 09:47:38 +02:00
Johannes Sixt
04d1197343 Move the utime() wrapper from test-chmtime.c to mingw.c.
The recent commit f746bae84e uses utime() to
adjust time stamps of pack files. We better make sure that we have an
implementation of utime that sets time stamps in a fashion that works with
our stat() implementation. (The system's utime() implemenation has issues
with daylight saving time changes.)

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-03-18 09:18:53 +01:00
Johannes Sixt
c9df829f07 Use the available vsnprintf replacement instead of rolling our own.
But we still have to cater for the strangeness that on Windows the size
parameter is the number of characters to write, not the size of the buffer.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-03-13 13:29:50 +01:00
Johannes Sixt
a76ef1f443 Define is_dir_sep conditionally in compat/mingw.h and git-compat-util.h.
By doing it there we can reduce yet another bunch of conditionals from
setup.c.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-03-13 13:28:17 +01:00
Johannes Sixt
1881ab8876 Move the definition of has_dos_drive_prefix to compat/mingw.c
This cannot easily be an inline function because it uses isalpha(), which
is not yet declared when compat/mingw.c is parsed and so would give a
compiler warning.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-03-13 13:26:46 +01:00
Johannes Sixt
70aa4faf57 Define PATH_SEP to ':' or ';' as needed.
This reduces the number of conditionals in the code.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-03-13 13:25:49 +01:00
Johannes Sixt
9151da6b3b Move mkstemp and PRIuMAX to compat/mingw.h.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-03-13 13:25:04 +01:00
Johannes Sixt
9ce71e6df0 Remove executable mode from compat/fnmatch.c
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-03-13 13:23:36 +01:00
Johannes Sixt
74ea7c5841 Move MinGW specific code from git-compat-util.h to compat/mingw.h.
This was proposed by Dscho, and I agree it makes sense because it really
clutters git-compat-util.h.

This is the first step of this cleanup and is a mere code move.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-03-13 13:21:34 +01:00
Johannes Sixt
5c499964de Merge branch 'master' of git://repo.or.cz/alt-git 2008-03-09 20:14:15 +01:00
Michal Rokos
c4582f93a2 Add compat/snprintf.c for systems that return bogus
Some systems (namely HPUX and Windows) return -1 when maxsize in snprintf()
and in vsnprintf() is reached. So replace snprintf() and vsnprintf()
functions with our own ones that return correct value upon overflow.

[jc: verified that review comments by J6t have been incorporated, and
 tightened the check to verify the resulting buffer contents, suggested
 by Wayne Davison]

Signed-off-by: Michal Rokos <michal.rokos@nextsoft.cz>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-03-05 13:12:07 -08:00
Johannes Sixt
3031522444 Introduce has_dos_drive_prefix() and use it.
This function tests whether there is a C: style prefix in the argument.
It returns always 0 on Unix.

With this functions a number of conditionals #ifdef __MINGW32__/#endif
can be removed.

The getcwd() replacement was simplified: It tried to elide the translation
of backslashes to slashes if there was no drive prfix, but this
optimization is wrong: We could be looking at an UNC path, which we also
want to translate.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-03-02 21:54:30 +01:00
Johannes Sixt
792d7e9b0e A bit of comment and whitespace cleanup in compat/mingw.c.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-02-26 10:42:01 +01:00
Johannes Sixt
7d9a058247 Merge branch 'master' of git://repo.or.cz/alt-git 2008-02-23 20:54:51 +01:00
Junio C Hamano
c0284cea31 Merge branch 'bc/fopen'
* bc/fopen:
  Add compat/fopen.c which returns NULL on attempt to open directory
2008-02-20 16:13:19 -08:00
Johannes Sixt
8221a4b1fb Merge branch 'master' of git://repo.or.cz/alt-git 2008-02-17 21:54:08 +01:00
Brandon Casey
cba22528fa Add compat/fopen.c which returns NULL on attempt to open directory
Some systems do not fail as expected when fread et al. are called on
a directory stream. Replace fopen on such systems which will fail
when the supplied path is a directory.

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-02-11 18:25:10 -08:00
Brian Downing
43fe901b71 compat: Add simplified merge sort implementation from glibc
qsort in Windows 2000 (and various other C libraries) is a Quicksort
with the usual O(n^2) worst case.  Unfortunately, sorting Git trees
seems to get very close to that worst case quite often:

    $ /git/gitbad runstatus
    # On branch master
    qsort, nmemb = 30842
    done, 237838087 comparisons.

This patch adds a simplified version of the merge sort that is glibc's
qsort(3).  As a merge sort, this needs a temporary array equal in size
to the array that is to be sorted, but has a worst-case performance of
O(n log n).

The complexity that was removed is:

* Doing direct stores for word-size and -aligned data.
* Falling back to quicksort if the allocation required to perform the
  merge sort would likely push the machine into swap.

Even with these simplifications, this seems to outperform the Windows
qsort(3) implementation, even in Windows XP (where it is "fixed" and
doesn't trigger O(n^2) complexity on trees).

[jes: moved into compat/qsort.c, as per Johannes Sixt's suggestion]
[bcd: removed gcc-ism, thanks to Edgar Toernig.  renamed make variable
      per Junio's comment.]

Signed-off-by: Brian Downing <bdowning@lavos.net>
Signed-off-by: Steffen Prohaska <prohaska@zib.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-02-06 22:35:28 -08:00
Johannes Sixt
d63abd8dc5 Fixup the clean-up of environment handling.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2007-12-07 22:45:20 +01:00
Johannes Sixt
9a930a2ecb Implement setting of environment variables in spawned programs.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2007-12-05 21:41:40 +01:00
Johannes Sixt
f6df056f6c Rework environment manipulation.
A lookup routine is extracted from env_unsetenv() because we will need it
for env_setenv(). The environment data is now released, too.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2007-12-05 21:41:40 +01:00
Johannes Sixt
dfc991a98a Clean up compat/mingw.c.
The PATH related functions are now static and can lose the mingw_ prefix.

path_lookup() no longer looks in the current directory, and it will now
actually return NULL. Previously, it returned the input program name
as a fallback.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2007-12-05 19:35:00 +01:00
Johannes Sixt
2bd3a118a7 Clean up the MINGW section in git-compat-util.h.
The entries are now arranged in categories.

inet_ntop(), kill(), and openlog() are unused and, hence, removed.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2007-12-01 21:36:07 +01:00
Johannes Sixt
bfe13b6357 Fix setitimer implementation.
Although we made sure that in->it_interval is either zero or equal to
in->it_value, we were still using in->it_interval to compute the timeout,
which could be zero, for example, with git-log's --early-output flag.
Use in->it_value instead.

On the otherhand, we used in->it_value to check for a single-shot timer.
Use in->it_interval instead.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2007-11-26 13:16:40 +01:00
Johannes Sixt
3920a6b76b Look up interpreters only as .exe files.
After a program was determined to be a script (which implies that it did
not have a file extension), then the interpreter is looked up. This change
makes sure that we will only find .exe files when we are looking for an
interpreter. Otherwise, we could find a directory 'perl' that is somewhere
earlier in the path than 'perl.exe'.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2007-11-25 20:21:55 +01:00
Johannes Sixt
72d58fde99 Implement a custom spawnve() on Windows.
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 windows. 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.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2007-11-25 20:18:37 +01:00
Johannes Sixt
a020210cc8 Move MinGW specific path lookup into compat/mingw.c.
By doing so the only external user of the path handling and functions
is removed, and these functions can be made static.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2007-11-25 20:13:28 +01:00
Johannes Sixt
ec848b1965 Shuffle path lookup functions.
We want to make them static later, and we need them in the proper order
for this. There is otherwise no code change.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2007-11-24 23:26:08 +01:00
Johannes Sixt
60db5000ab Implement wrappers for gethostbyname(), socket(), and connect().
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>
2007-11-21 22:47:00 +01:00
Johannes Sixt
a6ed49cf52 Fix error messages in timer implementation.
There were some references to the progress indicator, where this
implementation originally appeared.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2007-11-21 09:28:59 +01:00
Dmitry Kakurin
ad0b9993f9 compat/regex.c: Fix warnings
In general, we don't add unnecessary braces.  But in this case
gcc warns about them.  So this commit adds a few braces.

The commit suppresses warnings about unitialized variables
by initializing them to NULL.

The change of bcmp_translate()'s parameter declaration is needed
to avoid warnings about "discards qualifiers from pointer target
type".

[sp: split original commit; more detailed commit message. ]

Signed-off-by: Dmitry Kakurin <Dmitry.Kakurin@gmail.com>
Signed-off-by: Steffen Prohaska <prohaska@zib.de>
2007-11-21 07:34:44 +01:00
Johannes Sixt
f801325ed5 Implement a rudimentary poll() emulation for Windows.
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 to not burn CPU time, it 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>
2007-11-19 12:36:32 +01:00
Steffen Prohaska
a8d8425ec6 Fix prototypes for mingw_execve and mingw_execvp to match Posix
This changes the prototypes to match
http://www.opengroup.org/onlinepubs/7990989775/xsh/exec.html

[js: updated message]

Signed-off-by: Steffen Prohaska <prohaska@zib.de>
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2007-11-18 20:40:35 +01:00
Steffen Prohaska
8ddaf895a8 compat/mingw.c: Add cast of handle to fix warning
[js: whitespace removed]

Signed-off-by: Steffen Prohaska <prohaska@zib.de>
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2007-11-18 20:35:57 +01:00
Johannes Sixt
f8fd915d0c Move environment functions from spawn-pipe.c to compat/mingw.c
We want to get rid of spawn-pipe.*, but these functions will be needed.

On the way, the function signature was changed to avoid warnings about
incompatible pointer types when the argument is the global variable
"environ".
2007-11-18 20:22:04 +01:00
Johannes Sixt
fab21181f4 Implement a wrapper of the open() function.
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, then
  Windows's open fails with EACCES; this is changed to EISDIR.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2007-11-15 22:27:09 +01:00