Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: libgit2/libgit2
base: 48ecd122ea
...
head fork: libgit2/libgit2
compare: cd58c15c58
  • 5 commits
  • 6 files changed
  • 0 commit comments
  • 2 contributors
Commits on May 05, 2012
@scottjg scottjg Fix clar generated code to compile on MINGW32
MINGW32 does not define _mktemp_s, so we can just use _mktemp instead. See
the non-compressed/non-base64-encoded version of the patch here:
http://gist.github.com/2605249
06ac3e7
@scottjg scottjg Fix gitno_connect() error handling on Windows
gitno_connect() can return an error or socket, which is fine on most
platforms where sockets are file descriptors (signed int), but on Windows,
SOCKET is an unsigned type, which is problematic when we are trying to
test if the socket was actually a negative error code.

This fix seperates the error code and socket in gitno_connect(), and fixes
the error handling in do_connect() functions to compensate. It appears
that git_connect() and the git-transport do_connect() functions had bugs
in the non-windows cases too (leaking sockets, and not properly reporting
connection error, respectively) so I went ahead and fixed those too.
b4b96d5
@scottjg scottjg Fix missing prototype warning in utf-conv.c b47e0a7
@scottjg scottjg Fix unsigned/signed comparison on Windows in commitstagedfile.c 35cdd26
@vmg vmg Merge remote-tracking branch 'scottjg/fix-mingw32' into development
Conflicts:
	src/netops.c
	src/netops.h
	src/transports/http.c
	tests-clar/clar
cd58c15
View
11 src/netops.c
@@ -93,7 +93,7 @@ void gitno_consume_n(gitno_buffer *buf, size_t cons)
buf->offset -= cons;
}
-GIT_SOCKET gitno_connect(const char *host, const char *port)
+int gitno_connect(GIT_SOCKET *sock, const char *host, const char *port)
{
struct addrinfo *info = NULL, *p;
struct addrinfo hints;
@@ -106,7 +106,7 @@ GIT_SOCKET gitno_connect(const char *host, const char *port)
if ((ret = getaddrinfo(host, port, &hints, &info)) < 0) {
giterr_set(GITERR_NET, "Failed to resolve address for %s: %s", host, gai_strerror(ret));
- return INVALID_SOCKET;
+ return -1;
}
for (p = info; p != NULL; p = p->ai_next) {
@@ -125,11 +125,14 @@ GIT_SOCKET gitno_connect(const char *host, const char *port)
}
/* Oops, we couldn't connect to any address */
- if (s == INVALID_SOCKET && p == NULL)
+ if (s == INVALID_SOCKET && p == NULL) {
giterr_set(GITERR_OS, "Failed to connect to %s", host);
+ return -1;
+ }
freeaddrinfo(info);
- return s;
+ *sock = s;
+ return 0;
}
int gitno_send(GIT_SOCKET s, const char *msg, size_t len, int flags)
View
2  src/netops.h
@@ -21,7 +21,7 @@ int gitno_recv(gitno_buffer *buf);
void gitno_consume(gitno_buffer *buf, const char *ptr);
void gitno_consume_n(gitno_buffer *buf, size_t cons);
-GIT_SOCKET gitno_connect(const char *host, const char *port);
+int gitno_connect(GIT_SOCKET *s, const char *host, const char *port);
int gitno_send(GIT_SOCKET s, const char *msg, size_t len, int flags);
int gitno_close(GIT_SOCKET s);
int gitno_send_chunk_size(int s, size_t len);
View
23 src/transports/git.c
@@ -100,10 +100,11 @@ static int send_request(GIT_SOCKET s, const char *cmd, const char *url)
*/
static int do_connect(transport_git *t, const char *url)
{
- GIT_SOCKET s;
char *host, *port;
const char prefix[] = "git://";
- int error, connected = 0;
+ int error;
+
+ t->socket = INVALID_SOCKET;
if (!git__prefixcmp(url, prefix))
url += strlen(prefix);
@@ -111,22 +112,24 @@ static int do_connect(transport_git *t, const char *url)
if (gitno_extract_host_and_port(&host, &port, url, GIT_DEFAULT_PORT) < 0)
return -1;
- s = gitno_connect(host, port);
- connected = 1;
- error = send_request(s, NULL, url);
- t->socket = s;
+ if (gitno_connect(&t->socket, host, port) == 0) {
+ error = send_request(t->socket, NULL, url);
+ }
git__free(host);
git__free(port);
- if (error < GIT_SUCCESS && s > 0)
- gitno_close(s);
- if (!connected) {
+ if (error < 0 && t->socket != INVALID_SOCKET) {
+ gitno_close(t->socket);
+ t->socket = INVALID_SOCKET;
+ }
+
+ if (t->socket == INVALID_SOCKET) {
giterr_set(GITERR_NET, "Failed to connect to the host");
return -1;
}
- return error;
+ return 0;
}
/*
View
4 src/transports/http.c
@@ -85,12 +85,12 @@ static int gen_request(git_buf *buf, const char *url, const char *host, const ch
static int do_connect(transport_http *t, const char *host, const char *port)
{
- GIT_SOCKET s = -1;
+ GIT_SOCKET s;
if (t->parent.connected && http_should_keep_alive(&t->parser))
return 0;
- if ((s = gitno_connect(host, port)) < 0)
+ if (gitno_connect(&s, host, port) < 0)
return -1;
t->socket = s;
View
1  src/win32/utf-conv.c
@@ -7,6 +7,7 @@
#include "common.h"
#include "utf-conv.h"
+#include "git2/windows.h"
/*
* Default codepage value
View
8 tests-clar/object/commit/commitstagedfile.c
@@ -83,8 +83,16 @@ void test_object_commit_commitstagedfile__generate_predictable_object_ids(void)
struct stat st;
cl_must_pass(p_lstat("treebuilder/test.txt", &st));
cl_assert(entry->file_size == st.st_size);
+#ifndef _WIN32
+ /*
+ * Windows doesn't populate these fields, and the signage is
+ * wrong in the Windows version of the struct, so lets avoid
+ * the "comparing signed and unsigned" compilation warning in
+ * that case.
+ */
cl_assert(entry->uid == st.st_uid);
cl_assert(entry->gid == st.st_gid);
+#endif
}
/*

No commit comments for this range

Something went wrong with that request. Please try again.