Commit Graph

114 Commits

Author SHA1 Message Date
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
Johannes Sixt
155e6d080b Fix setitimer implementation to register only one cleanup with atexit.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2007-11-13 17:44:08 +01:00
Johannes Sixt
3e0ba4ccdc Clean up cruft from the MINGW32 section of git-compat-util.h
Quite a lot of stuff has accumulated or is now obsolete. The stubs of
POSIX functions that are not implemented or that always fail are now
implemented as inline functions so that they exist in only one place.
2007-11-13 15:44:48 +01:00
Johannes Sixt
6d305e3341 Implement setitimer() and sigaction().
The timer is implemented using a thread.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2007-11-13 10:14:45 +01:00
Johannes Sixt
e0c9a54e11 Clean up some dummy compatibility implementations.
In particular, sync() was never declared and caused a warning.
2007-11-12 14:00:35 +01:00
Johannes Sixt
e569ab2ae7 Use a customized struct stat that also has the st_blocks member.
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>
2007-11-12 14:00:31 +01:00
Johannes Sixt
a23a15abc6 Use Windows's native API instead of stat() in rename()'s error path.
Since we are only interested whether the named entry is a directory, it
is sufficient to use GetFileAttributes() instead of a full stat() call.
2007-11-12 12:52:17 +01:00
Johannes Sixt
50d1c4c745 Fake implementions of getpwuid(), getuid(), and getpwnam().
getpwuid() is kept as simple as possible so that no errors are generated.
Since the information that it returns is not very useful, users are still
required to set up user.name and user.email configuration.

All uses of getpwuid() are like getpwuid(getuid()), hence, the return value
of getpwuid() is irrelevant. getpwnam() is only used to resolve '~' and
'~username' paths, which is an idiom not known on Windows, hence, we
don't implement it, either.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2007-11-12 08:07:00 +01:00
Johannes Sixt
1c01d23a86 Merge branch 'master' of git://repo.or.cz/alt-git 2007-11-11 20:14:20 +01:00
Junio C Hamano
fe61935007 Merge branch 'maint'
* maint:
  Remove a couple of duplicated include
  grep with unmerged index
  git-daemon: fix remote port number in log entry
  git-svn: t9114: verify merge commit message in test
  git-svn: fix dcommit clobbering when committing a series of diffs
2007-11-05 22:03:47 -08:00
Marco Costalba
d8e21ba896 Remove a couple of duplicated include
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-11-05 20:50:38 -08:00
Johannes Sixt
2952476e8e Reimplement execvp() such that it can invoke shell scripts.
We conveniently reuse mingw_execve(), which does the shbang interpretation
as well as other painful Windows compatibility stuff.
2007-11-02 21:38:57 +01:00
Johannes Sixt
36e0147fe5 Move path handling functions from spawn-pipe.c to compat/mingw.c.
Since these functions are MinGW-specific, they better belong into this
compatibility file. They will be needed there in a follow-up change that
reimplements execvp().
2007-11-02 21:34:56 +01:00
Johannes Sixt
ab2ca02541 Merge branch 'js/forkexec'
Note that cmd->err is not treated in run-command.c. In particular, the
pipe end is not inherited by the child process.

THIS IS IMPORTANT!

cmd->err is only required by upload-pack. But in the MinGW case upload-pack
does not support the sideband and the stderr of pack-objects is expected to
be routed to stderr: Since in the MinGW case the stderr pipe is not read
by upload-pack, the stderr of pack-objects must not be connected to the
pipe.
2007-10-28 21:14:04 +01:00
Nguyễn Thái Ngọc Duy
ee05d11762 Rework quote_arg()
MS Windows command line is handled in a weird way. This patch addresses:
 - Quote empty arguments
 - Only escape backslashes and double quotation marks inside quoted arguments
 - Quote arguments if they have asterisk or question marks to prevent expansion

The last one is not documented in the link provided in the patch. I encountered
that behavior on cmd.exe, Windows XP. MSYS not tested.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
2007-10-28 20:50:10 +01:00