Commit Graph

111 Commits

Author SHA1 Message Date
Brian Downing
bc8e453867 mingw-compat: Add simplified merge sort implementation from glibc
qsort in Windows 2000 (and possibly other older Windows' 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.

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]

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>
2007-12-30 14:06:47 +01:00
Steffen Prohaska
8da335b3fa Merge commit 'mingw/master' into work/merge-mingw
Conflicts:

	setup.c
2007-12-08 12:49:42 +01: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
Steffen Prohaska
9467c5ac39 Merge commit 'mingw/master' into work/merge-mingw
Conflicts:

	Makefile
	git-compat-util.h
2007-12-07 00:45:00 +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
Steffen Prohaska
dd9da2f011 Merge commit 'mingw/master' into work/merge-mingw 2007-12-01 16:21:43 +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
Steffen Prohaska
fd2641ab2e Merge commit 'mingw/master' into work/merge-mingw-master-2
Signed-off-by: Steffen Prohaska <prohaska@zib.de>
2007-11-25 22:09:14 +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
Steffen Prohaska
b4389a3758 Merge commit 'mingw/master' into work/merge-mingw-master 2007-11-24 11:31:37 +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
Steffen Prohaska
b3c41bf395 Merge commit 'mingw/master' into work/towards-mingw
Conflicts:

	compat/mingw.c
	exec_cmd.c
	git-compat-util.h
	run-command.c
	spawn-pipe.c
2007-11-21 21:54:43 +01:00
Steffen Prohaska
31023be999 compat/pread.c: Add foward decl to fix warning
read_in_full()'s is used in compat/pread.c.  read_in_full() is
declared in cache.h. But we can't include cache.h because too
many macros are defined there.  Using read_in_full() without
including cache.h is dangerous because we wouldn't recognize if
its prototyp changed.  gcc issues a warning about that.

This commit adds a forward decl to git-compat-util.h.
git-compat-util.h is included by compat/pread.c _and_ cache.h.
Hence, changes in cache.h would be detected.

Signed-off-by: Steffen Prohaska <prohaska@zib.de>
2007-11-21 20:31:10 +01:00
Steffen Prohaska
af18e7d9d3 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

Note, spawnvpe uses a different type for argv and envp
than execve.  So at some point we need to cast.  This
commit shifts the cast into the compat functions.  From
the outside, execve and execvp match Posix.

Signed-off-by: Steffen Prohaska <prohaska@zib.de>
2007-11-21 20:05:43 +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
Steffen Prohaska
fcdd78c3c3 Merge commit 'mingw/master' into work/merge-mingw-master
Conflicts:

	git-compat-util.h
	help.c
	pager.c

Signed-off-by: Steffen Prohaska <prohaska@zib.de>
2007-11-17 12:17:45 +01:00
Steffen Prohaska
16df3f7e4c Merge commit 'mingw/master' into work/merge-mingw-master
Remove getpagesize() from sha1_file.c because is it now
included in git-compat-util.h.

Conflicts:

	Makefile
	compat/mingw.c
	git-compat-util.h

Signed-off-by: Steffen Prohaska <prohaska@zib.de>
2007-11-16 07:33:14 +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
Steffen Prohaska
69cadd4e60 Merge commit 'mingw/master' into msysgit/merge-mingw-v2
Conflicts:

	Makefile
	RelNotes
	builtin-ls-files.c
	builtin-tag.c
	cache.h
	compat/mingw.c
	config.c
	connect.c
	cpio.sh
	diff.c
	exec_cmd.c
	git-gui/Makefile
	git-gui/lib/commit.tcl
	git-gui/lib/console.tcl
	git-mergetool.sh
	lockfile.c
	path.c
	rsh.c
	run-command.c
	setup.c
	show-index.c
	spawn-pipe.c
	t/Makefile
	t/t0000-basic.sh
	t/t1300-repo-config.sh
	t/t7501-commit.sh
	t/test-lib.sh

    Resolve as follows
    --- Makefile
    - mingw/devel removes
        SHELL_PATH = /bin/sh
        PERL_PATH = /bin/perl

    This looks ok. Both are set early in the Makefile to sensible values.
    mingw accepts to execute /usr/bin/perl.

    - NO_SYMLINKS is no longer needed. Should be auto-detected.

    - According to our 0e2bdc35af
      we want

    NO_R_TO_GCC_LINKER = YesPlease

      take our before their change.

    - Conflict prefix, SCRIPT_SH:
    our 7999f434d7 set prefix =
    their 4a7c98dbaf removes cpio emulator

    resolve to achieve both.

    - Conflict NO_MEMMEM, THREADED_DELTA_SEARCH: take theirs

    --- RelNotes
    take our: removed file

    --- builtin-ls-files.c
    Conflict write_name_quoted: take their change.

    --- builtin-tag.c
    Conflict strip CR

    our 7734ad404c adds strip CR
    their fd17f5b5f7 modifies code to use strbuf

    resolve by removing our code. TODO: we probably need a replacement?

    --- cache.h
    Conflict is_absolute_path()
    our ef5af72062 ifdef
    their 637fc51696 ifndef
    both achieve the same.

    our is a bit more strict but we take their code because we want
    to reduce differences to mingw.

    --- compat/mingw.c
    Conflict at end of file:
    our 194c1dbb5a adds git_exit()

    resolve by taking their first, followed by our.

    --- config.c
    Conflict 'fd ='
    our 0a453a237e merge junio/master
    introduced strange 'fd ='. Resolve by removing 'fd ='.

    --- connect.c
    - Conflict 'host must have at least 2 chars ...' take their code.

    - git_connect(): take their implementation.

    --- cpio.sh
    Accepted their delete file.

    --- diff.c
    Resolve using their implementation.

    --- exec_cmd.c
    Resolve using their implementation.

    --- git-gui/**
    Resolve using our implementation.

    --- git-mergetool.sh
    Resolve using their implementation

    --- lockfile.c
    trivial resolution (empty line removed)

    --- path.c
    Conflict 'tmp': accepting their implementation, trying TMP, TEMP on all platforms.

    --- rsh.c
    Accept their delete file.

    --- run-command.c
    Resolve using their implementation

    --- setup.c
    Resolve using their implementation

    --- show-index.c
    Conflict PRIuMAX
    our 89697a4c15 fix warning
    their 5be507fc95 PRIuMAX

    resolve fixing warning in their code.

    --- spawn-pipe.c
    Conflict environ vs lookup_prog: resolve taking neither

    --- t/Makefile
    our d1f83218dc --no-hardlinks
    their c603988c10 automtically detect symlink support

    Resolve using our --no-hardlinks but removing --no-symlinks.

    --- t/0000-basic.sh
    Resolve using their implementation.

    --- t/t1300-repo-config.sh
    Resolve using their implementation.

    --- t/t7501-commit.sh
    Resolve using their implementation.

    --- t/test-lib.sh
    our d1f83218dc --no-hardlink
    their c603988c10 automatically detect symlink support

    Resolve using our --no-hardlinks but removing --no-symlinks.

Signed-off-by: Steffen Prohaska <prohaska@zib.de>
2007-11-05 21:55:44 +01: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
Johannes Sixt
e88aa8cbe8 Fix off-by-one error in the vsnprintf wrapper.
Windows's vsnprintf() receives the number of characters to write, which
does not include the trailing NUL byte. But our vsnprintf() users pass
the available space, including the trailing NUL.
2007-10-23 16:34:09 +02:00
Johannes Sixt
5fd41ffacd Implement a work-around for a mis-behaved vsnprintf on Windows.
On Windows, vsnprintf returns -1 if the buffer is too small instead of
the number of characters needed. This wrapper computes the needed buffer
size by trying various sizes with exponential growth. A large growth
factor is used so as only few trials are required if a really large
result needs to be stored.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2007-10-22 14:01:27 +02:00
Shawn O. Pearce
ca5bb5d539 Define compat version of mkdtemp for systems lacking it
Solaris 9 doesn't have mkdtemp() so we need to emulate it for the
rsync transport implementation.  Since Solaris 9 is lacking this
function we can also reasonably assume it is not available on
Solaris 8 either.  The new Makfile definition NO_MKDTEMP can be
set to enable the git compat version.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2007-10-20 22:52:21 -04:00
Johannes Sixt
89afdd6d62 Merge commit 'spearce/master' 2007-10-19 22:50:43 +02:00
Johannes Sixt
fbb7b31c45 Fix invocation of external git commands with arguments with spaces.
If an external git command (not a shell script) was invoked with arguments
that contain spaces, these arguments would be split into separate
arguments. They must be quoted. This also affected installations where
$prefix contained a space, as in "C:\Program Files\GIT". Both errors can
be triggered by invoking

     git hash-object "a b"

where "a b" is an existing file.
2007-10-17 00:06:18 +02:00
Johannes Sixt
524344cdf5 Fix invocation of external git commands with arguments with spaces.
If an external git command (not a shell script) was invoked with arguments
that contain spaces, these arguments would be split into separate
arguments. They must be quoted. This also affected installations where
$prefix contained a space, as in "C:\Program Files\GIT". Both errors can
be triggered by invoking

    git hash-object "a b"

where "a b" is an existing file.
2007-10-10 09:00:39 +02:00