Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Run git-daemon on windows without closing socket immediately. #70

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Documentation/git-close-socket.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
git-close-socket(1)
===================

NAME
----
git-close-socket - Close socket like Linux.


SYNOPSIS
--------
[verse]
'git close-socket'

DESCRIPTION
-----------

Emulate to close socket as Linux. Some system, especialy windows, will close
soket immediately. In such system git daemon will not communicate some git
clients well.
This command resovle the problem. Command will sleep some secondes and exit.
Sleep seconds is specified below order.

Windows::
1. 'git-config --int win.sock.time.wait'
2. half of registry value 'HKLM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\TcpTimedWaitDelay'
3. 240


SEE ALSO
--------
http://www.softlab.ntua.gr/facilities/documentation/unix/unix-socket-faq/unix-socket-faq-4.html#ss4.2
http://msdn.microsoft.com/en-us/library/windows/desktop/ms737582.asp
linkgit:git-config[1]

GIT
---
Part of the linkgit:git[1] suite
4 changes: 4 additions & 0 deletions Documentation/git-pack-objects.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ So does `git bundle` (see linkgit:git-bundle[1]) when it creates a bundle.
With this option, parents that are hidden by grafts are packed
nevertheless.

--shutdown-out-socket::
On exit, shutdown outgoing socket if outgoing file descript is
socket.

SEE ALSO
--------
linkgit:git-rev-list[1]
Expand Down
17 changes: 14 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ PROGRAM_OBJS += shell.o
PROGRAM_OBJS += show-index.o
PROGRAM_OBJS += upload-pack.o
PROGRAM_OBJS += remote-testsvn.o
PROGRAM_OBJS += close-socket.o

# Binary suffix, set to .exe for Windows builds
X =
Expand Down Expand Up @@ -532,7 +533,7 @@ TEST_PROGRAMS_NEED_X += test-sigchain
TEST_PROGRAMS_NEED_X += test-string-list
TEST_PROGRAMS_NEED_X += test-subprocess
TEST_PROGRAMS_NEED_X += test-svn-fe

TEST_PROGRAMS_NEED_X += test-env-utils
TEST_PROGRAMS = $(patsubst %,%$X,$(TEST_PROGRAMS_NEED_X))

# List built-in command $C whose implementation cmd_$C() is not in
Expand Down Expand Up @@ -630,6 +631,9 @@ LIB_H += compat/terminal.h
LIB_H += compat/win32/dirent.h
LIB_H += compat/win32/pthread.h
LIB_H += compat/win32/syslog.h
LIB_H += compat/winsock-proc.h
LIB_H += compat/winsock-utils.h
LIB_H += compat/win-fd.h
LIB_H += connected.h
LIB_H += convert.h
LIB_H += credential.h
Expand All @@ -639,6 +643,7 @@ LIB_H += delta.h
LIB_H += diff.h
LIB_H += diffcore.h
LIB_H += dir.h
LIB_H += evn-utils.h
LIB_H += exec_cmd.h
LIB_H += fetch-pack.h
LIB_H += fmt-merge-msg.h
Expand Down Expand Up @@ -688,6 +693,7 @@ LIB_H += sha1-lookup.h
LIB_H += shortlog.h
LIB_H += sideband.h
LIB_H += sigchain.h
LIB_H += socket-utils.h
LIB_H += strbuf.h
LIB_H += streaming.h
LIB_H += string-list.h
Expand Down Expand Up @@ -753,6 +759,7 @@ LIB_OBJS += dir.o
LIB_OBJS += editor.o
LIB_OBJS += entry.o
LIB_OBJS += environment.o
LIB_OBJS += env-utils.o
LIB_OBJS += exec_cmd.o
LIB_OBJS += fetch-pack.o
LIB_OBJS += fsck.o
Expand Down Expand Up @@ -818,6 +825,7 @@ LIB_OBJS += sha1_name.o
LIB_OBJS += shallow.o
LIB_OBJS += sideband.o
LIB_OBJS += sigchain.o
LIB_OBJS += socket-utils.o
LIB_OBJS += strbuf.o
LIB_OBJS += streaming.o
LIB_OBJS += string-list.o
Expand Down Expand Up @@ -1292,7 +1300,7 @@ ifeq ($(uname_S),Windows)
BASIC_CFLAGS = -nologo -I. -I../zlib -Icompat/vcbuild -Icompat/vcbuild/include -DWIN32 -D_CONSOLE -DHAVE_STRING_H -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE
COMPAT_OBJS = compat/msvc.o compat/winansi.o \
compat/win32/pthread.o compat/win32/syslog.o \
compat/win32/dirent.o
compat/win32/dirent.o
COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DNOGDI -DHAVE_STRING_H -DHAVE_ALLOCA_H -Icompat -Icompat/regex -Icompat/win32 -DSTRIP_EXTENSION=\".exe\"
BASIC_LDFLAGS = -IGNORE:4217 -IGNORE:4049 -NOLOGO -SUBSYSTEM:CONSOLE
EXTLIBS = user32.lib advapi32.lib shell32.lib wininet.lib ws2_32.lib
Expand Down Expand Up @@ -1441,12 +1449,15 @@ ifneq (,$(findstring MINGW,$(uname_S)))
COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
COMPAT_OBJS += compat/mingw.o compat/winansi.o \
compat/win32/pthread.o compat/win32/syslog.o \
compat/win32/dirent.o
compat/win32/dirent.o compat/winsock-proc.o \
compat/win-fd.o compat/winsock-utils.o
BASIC_LDFLAGS += -Wl,--large-address-aware
EXTLIBS += -lws2_32
GITLIBS += git.res
PTHREAD_LIBS =
RC = windres -O coff
TEST_PROGRAMS_NEED_X += test-win-fd
TEST_PROGRAMS_NEED_X += test-winsock-utils
X = .exe
SPARSE_FLAGS = -Wno-one-bit-signed-bitfield
ifneq (,$(wildcard ../THIS_IS_MSYSGIT))
Expand Down
11 changes: 8 additions & 3 deletions builtin/pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "refs.h"
#include "streaming.h"
#include "thread-utils.h"

#include "socket-utils.h"
static const char *pack_usage[] = {
N_("git pack-objects --stdout [options...] [< ref-list | < object-list]"),
N_("git pack-objects [options...] base-name [< ref-list | < object-list]"),
Expand Down Expand Up @@ -811,7 +811,6 @@ static void write_pack_file(void)
die("wrote %"PRIu32" objects while expecting %"PRIu32,
written, nr_result);
}

static int locate_object_entry_hash(const unsigned char *sha1)
{
int i;
Expand Down Expand Up @@ -2433,7 +2432,6 @@ static int option_parse_ulong(const struct option *opt,
#define OPT_ULONG(s, l, v, h) \
{ OPTION_CALLBACK, (s), (l), (v), "n", (h), \
PARSE_OPT_NONEG, option_parse_ulong }

int cmd_pack_objects(int argc, const char **argv, const char *prefix)
{
int use_internal_rev_list = 0;
Expand Down Expand Up @@ -2598,5 +2596,12 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
fprintf(stderr, "Total %"PRIu32" (delta %"PRIu32"),"
" reused %"PRIu32" (delta %"PRIu32")\n",
written, written_delta, reused, reused_delta);
#ifdef EMULATE_TIME_WAIT_SOCKET


if (pack_to_stdout && is_socket(1)) {
set_socket_to_time_wait(1, 1);
}
#endif
return 0;
}
33 changes: 33 additions & 0 deletions close-socket.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "cache.h"
#include <time.h>
#ifdef WIN32
#include "winsock-utils.h"
#endif

#ifdef EMULATE_TIME_WAIT_SOCKET
#ifdef WIN32
static int wait_for_time_out(void)
{
time_t start_time;
time_t wait_time;
start_time = time(NULL);
wait_time = get_socket_time_wait();
while (time(NULL) - start_time < wait_time) {
sleep(1);
}
return 0;
}
#endif
#else
static int wait_for_time_out(void)
{
return 0;
}
#endif
int main(int argc, char** argv)
{
int result;

result = wait_for_time_out();
return result;
}
5 changes: 5 additions & 0 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
static const int delay[] = { 0, 1, 10, 20, 40 };
unsigned int _CRT_fmode = _O_BINARY;


int err_win_to_posix(DWORD winerr)
{
int error = ENOSYS;
Expand Down Expand Up @@ -1471,6 +1472,7 @@ static void socket_cleanup(void)
ipv6_getnameinfo = getnameinfo_stub;
}


static void ensure_socket_initialization(void)
{
WSADATA wsa;
Expand Down Expand Up @@ -1515,6 +1517,9 @@ static void ensure_socket_initialization(void)
atexit(socket_cleanup);
initialized = 1;
}
void mingw_ensure_socket_initialization(void) {
ensure_socket_initialization();
}

#undef gethostname
int mingw_gethostname(char *name, int namelen)
Expand Down
4 changes: 4 additions & 0 deletions compat/mingw.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,3 +467,7 @@ extern int err_win_to_posix(DWORD winerr);

extern const char *get_windows_home_directory();
#define get_home_directory() get_windows_home_directory()

#define EMULATE_TIME_WAIT_SOCKET
extern void mingw_ensure_socket_initialization();

Loading