From bad1505609068de0d57cba1584590e9084afe9d6 Mon Sep 17 00:00:00 2001 From: "U-Poseidon\\Chris" Date: Tue, 5 Jun 2012 11:41:43 +0100 Subject: [PATCH 01/31] Force not to use openssl, as confusing cross-compiler t to use openssl, as confusing cross-compiler t to use openssl, as confusing cross-compiler ss Changes to be committed: (use "git reset HEAD ..." to unstage) modified: CMakeLists.txt --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index acac2a6de..567ac10e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,8 @@ # Install: # > cmake --build . --target install +SET(CMAKE_SYSTEM_NAME "Generic") + PROJECT(libgit2 C) CMAKE_MINIMUM_REQUIRED(VERSION 2.6) @@ -25,7 +27,7 @@ SET(LIBGIT2_VERSION_STRING "${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}.${ INCLUDE_DIRECTORIES(deps/zlib src include) # Try finding openssl -FIND_PACKAGE(OpenSSL) +#FIND_PACKAGE(OpenSSL) IF (OPENSSL_CRYPTO_LIBRARIES) SET(SHA1_TYPE "openssl" CACHE STRING "Which SHA1 implementation to use: builtin, ppc, openssl") ELSEIF () From d0517805d84f0fdd6c1311eb00a0d4ff257b4e47 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Tue, 5 Jun 2012 11:47:17 +0100 Subject: [PATCH 02/31] Required include for OS4 to typedef int64_t --- include/git2/types.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/git2/types.h b/include/git2/types.h index b569e83c1..8fdfd7fc8 100644 --- a/include/git2/types.h +++ b/include/git2/types.h @@ -48,6 +48,9 @@ GIT_BEGIN_DECL * stat() functions, for all platforms. */ #include +#ifdef __amigaos4__ +#include +#endif #if defined(_MSC_VER) From 82c23c58708acd1370a129f712207ce60e7e6199 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Tue, 5 Jun 2012 12:06:40 +0100 Subject: [PATCH 03/31] Assume this is irrelevant for now --- src/unix/map.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/unix/map.c b/src/unix/map.c index 9bc6178ed..1613152a0 100644 --- a/src/unix/map.c +++ b/src/unix/map.c @@ -1,11 +1,14 @@ #include "map.h" +#ifndef __amigaos4__ #include +#endif #include int git__mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset) { +#ifndef __amigaos4__ int mprot = 0; int mflag = 0; @@ -42,19 +45,20 @@ int git__mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t o if (!out->data || out->data == MAP_FAILED) return git__throw(GIT_EOSERR, "Failed to mmap. Could not write data"); out->len = len; - +#endif return GIT_SUCCESS; } int git__munmap(git_map *map) { +#ifndef __amigaos4__ assert(map != NULL); if (!map) return git__throw(GIT_ERROR, "Failed to munmap. Map does not exist"); munmap(map->data, map->len); - +#endif return GIT_SUCCESS; } From cada414a8044307b28f7a4c75986e5473bb4bc1c Mon Sep 17 00:00:00 2001 From: Chris Young Date: Tue, 5 Jun 2012 12:07:08 +0100 Subject: [PATCH 04/31] OS4 is PPC --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 567ac10e9..93747bb64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,7 @@ INCLUDE_DIRECTORIES(deps/zlib src include) IF (OPENSSL_CRYPTO_LIBRARIES) SET(SHA1_TYPE "openssl" CACHE STRING "Which SHA1 implementation to use: builtin, ppc, openssl") ELSEIF () - SET(SHA1_TYPE "builtin" CACHE STRING "Which SHA1 implementation to use: builtin, ppc") + SET(SHA1_TYPE "ppc" CACHE STRING "Which SHA1 implementation to use: builtin, ppc") ENDIF () INCLUDE(FindPkgConfig) From fb0b1523c40e843fd3bdae539e7382acd4a5c06b Mon Sep 17 00:00:00 2001 From: Chris Young Date: Thu, 7 Jun 2012 20:40:03 +0100 Subject: [PATCH 05/31] force disable of openssl, confusing cross-compiler --- CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9bff1ba0a..d3ab19ce3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,12 +91,12 @@ IF (NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE) ENDIF () -FIND_PACKAGE(OpenSSL) -IF (OPENSSL_FOUND) - ADD_DEFINITIONS(-DGIT_SSL) - INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) - SET(SSL_LIBRARIES ${OPENSSL_LIBRARIES}) -ENDIF() +#FIND_PACKAGE(OpenSSL) +#IF (OPENSSL_FOUND) +# ADD_DEFINITIONS(-DGIT_SSL) +# INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) +# SET(SSL_LIBRARIES ${OPENSSL_LIBRARIES}) +#ENDIF() IF (THREADSAFE) IF (NOT WIN32) From 2774ccb8515354c2c6b9e9e4da09115ca44ecbd5 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Thu, 7 Jun 2012 20:40:34 +0100 Subject: [PATCH 06/31] no fnmatch.h --- src/unix/posix.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unix/posix.h b/src/unix/posix.h index 48b492941..83fd8a189 100644 --- a/src/unix/posix.h +++ b/src/unix/posix.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_posix__w32_h__ #define INCLUDE_posix__w32_h__ -#ifndef __sun +#if !defined(__sun) && !defined(__amigaos4__) # include # define p_fnmatch(p, s, f) fnmatch(p, s, f) #else From c41fc47512ed78697122de7a2b628676e3e08726 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Thu, 7 Jun 2012 21:26:39 +0100 Subject: [PATCH 07/31] horrid gethostbyname compatibility --- src/netops.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/netops.c b/src/netops.c index e6f3e5627..fdbd965b1 100644 --- a/src/netops.c +++ b/src/netops.c @@ -376,11 +376,17 @@ static int ssl_setup(git_transport *t, const char *host) int gitno_connect(git_transport *t, const char *host, const char *port) { +#ifndef __amigaos4__ struct addrinfo *info = NULL, *p; struct addrinfo hints; +#else + int p; + struct hostent *hent; + struct sockaddr_in saddr; +#endif int ret; GIT_SOCKET s = INVALID_SOCKET; - +#ifndef __amigaos4__ memset(&hints, 0x0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; @@ -389,15 +395,29 @@ int gitno_connect(git_transport *t, const char *host, const char *port) giterr_set(GITERR_NET, "Failed to resolve address for %s: %s", host, gai_strerror(ret)); return -1; } +#else + hent = gethostbyname(host); +#endif +#ifndef __amigaos4__ for (p = info; p != NULL; p = p->ai_next) { s = socket(p->ai_family, p->ai_socktype, p->ai_protocol); +#else + for (p = 0; hent->h_addr_list[p] != NULL; p++) { + s = socket(hent->h_addrtype, SOCK_STREAM, 0); +#endif if (s == INVALID_SOCKET) { net_set_error("error creating socket"); break; } - +#ifndef __amigaos4__ if (connect(s, p->ai_addr, (socklen_t)p->ai_addrlen) == 0) +#else + saddr.sin_addr.s_addr = *hent->h_addr_list[p]; + saddr.sin_family = hent->h_addrtype; + saddr.sin_port = port; + if (connect(s, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in)) == 0) +#endif break; /* If we can't connect, try the next one */ @@ -406,14 +426,20 @@ int gitno_connect(git_transport *t, const char *host, const char *port) } /* Oops, we couldn't connect to any address */ - if (s == INVALID_SOCKET && p == NULL) { + if (s == INVALID_SOCKET && +#ifndef __amigaos4__ + p == NULL) { +#else + hent->h_addr_list[p] == NULL) { +#endif giterr_set(GITERR_OS, "Failed to connect to %s", host); return -1; } t->socket = s; +#ifndef __amigaos4__ freeaddrinfo(info); - +#endif if (t->encrypt && ssl_setup(t, host) < 0) return -1; From 6b5db63c159ea1d2112fe8dc535b877da03a6848 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Thu, 7 Jun 2012 21:40:07 +0100 Subject: [PATCH 08/31] random page size for os4 --- src/pool.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pool.c b/src/pool.c index 641292d06..c5414b3b6 100644 --- a/src/pool.c +++ b/src/pool.c @@ -275,6 +275,8 @@ uint32_t git_pool__system_page_size(void) SYSTEM_INFO info; GetSystemInfo(&info); size = (uint32_t)info.dwPageSize; +#elif defined(__amigaos4__) + size = (uint32_t)1000000; // random value #else size = (uint32_t)sysconf(_SC_PAGE_SIZE); #endif From 0f5e1f3b68eb68c257eb45b72650e8a653451a1d Mon Sep 17 00:00:00 2001 From: Chris Young Date: Thu, 7 Jun 2012 21:56:19 +0100 Subject: [PATCH 09/31] Network byte order is big-endian - the way it should be :) --- include/git2/common.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/git2/common.h b/include/git2/common.h index 0e9379804..4e6c2a57e 100644 --- a/include/git2/common.h +++ b/include/git2/common.h @@ -55,6 +55,14 @@ #define GIT_WIN32 1 #endif +#ifdef __amigaos4__ +/* Network byte order is big-endian... so is PPC, so these functions are NOP */ +#define htonl(x) x +#define ntohl(x) x +#define htons(x) x +#define ntohs(x) x +#endif + /** * @file git2/common.h * @brief Git common platform definitions From 519757279eb25fe4075f65b86da5ce52d352b454 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Thu, 7 Jun 2012 23:13:39 +0100 Subject: [PATCH 10/31] Fix double-defines when using GIT_OLD_ERRORS --- include/git2/errors.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/git2/errors.h b/include/git2/errors.h index ccbc9fcf4..b4809fe15 100644 --- a/include/git2/errors.h +++ b/include/git2/errors.h @@ -20,6 +20,7 @@ GIT_BEGIN_DECL #ifdef GIT_OLD_ERRORS enum { GIT_SUCCESS = 0, + GIT_ERROR = -1, GIT_ENOTOID = -2, GIT_ENOTFOUND = -3, GIT_ENOMEM = -4, @@ -52,7 +53,7 @@ enum { GIT_ENOMATCH = -31, GIT_ESHORTBUFFER = -32, }; -#endif +#else /** Generic return codes */ enum { @@ -66,6 +67,7 @@ enum { GIT_PASSTHROUGH = -30, GIT_REVWALKOVER = -31, }; +#endif typedef struct { char *message; From aa5a92d121d4fcc56d9661ce1c76534b410784c7 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Fri, 8 Jun 2012 18:57:35 +0100 Subject: [PATCH 11/31] OS4 compatibility --- include/git2/common.h | 2 ++ src/path.c | 4 ++-- src/posix.h | 6 +++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/git2/common.h b/include/git2/common.h index 4e6c2a57e..b692c67e2 100644 --- a/include/git2/common.h +++ b/include/git2/common.h @@ -107,6 +107,8 @@ GIT_EXTERN(int) git_strarray_copy(git_strarray *tgt, const git_strarray *src); */ GIT_EXTERN(void) git_libgit2_version(int *major, int *minor, int *rev); +GIT_EXTERN(int) p_fnmatch(const char *pattern, const char *string, int flags); + /** @} */ GIT_END_DECL #endif diff --git a/src/path.c b/src/path.c index 84edf6d89..056b6b910 100644 --- a/src/path.c +++ b/src/path.c @@ -512,7 +512,7 @@ int git_path_direach( de_buf = git__malloc(sizeof(struct dirent)); #endif - while (p_readdir_r(dir, de_buf, &de) == 0 && de != NULL) { + while (p_readdir_r(dir, de_buf, de) == 0 && de != NULL) { int result; if (is_dot_or_dotdot(de->d_name)) @@ -570,7 +570,7 @@ int git_path_dirload( path_len -= prefix_len; need_slash = (path_len > 0 && path[path_len-1] != '/') ? 1 : 0; - while ((error = p_readdir_r(dir, de_buf, &de)) == 0 && de != NULL) { + while ((error = p_readdir_r(dir, de_buf, de)) == 0 && de != NULL) { char *entry_path; size_t entry_len; diff --git a/src/posix.h b/src/posix.h index d020d94ac..8e8b394c8 100644 --- a/src/posix.h +++ b/src/posix.h @@ -74,6 +74,10 @@ typedef SOCKET GIT_SOCKET; # include "unix/posix.h" #endif -#define p_readdir_r(d,e,r) readdir_r(d,e,r) +#ifndef __amigaos4__ +#define p_readdir_r(d,e,r) readdir_r(d,e,&r) +#else +#define p_readdir_r(d,e,r) r = readdir(d) +#endif #endif From fa56478fb8d5e19d64bf43b51372ab3315cb1884 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Fri, 8 Jun 2012 19:15:11 +0100 Subject: [PATCH 12/31] Generic needs compat files --- CMakeLists.txt | 2 +- include/git2/common.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d3ab19ce3..7d3df285e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,7 +115,7 @@ FILE(GLOB SRC_H include/git2/*.h) IF (WIN32 AND NOT CYGWIN) ADD_DEFINITIONS(-DWIN32 -D_DEBUG -D_WIN32_WINNT=0x0501) FILE(GLOB SRC src/*.c src/transports/*.c src/xdiff/*.c src/win32/*.c src/compat/*.c) -ELSEIF (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") +ELSEIF (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS|Generic)") FILE(GLOB SRC src/*.c src/transports/*.c src/xdiff/*.c src/unix/*.c src/compat/*.c) ELSE() FILE(GLOB SRC src/*.c src/transports/*.c src/xdiff/*.c src/unix/*.c) diff --git a/include/git2/common.h b/include/git2/common.h index b692c67e2..045ba85c4 100644 --- a/include/git2/common.h +++ b/include/git2/common.h @@ -107,7 +107,7 @@ GIT_EXTERN(int) git_strarray_copy(git_strarray *tgt, const git_strarray *src); */ GIT_EXTERN(void) git_libgit2_version(int *major, int *minor, int *rev); -GIT_EXTERN(int) p_fnmatch(const char *pattern, const char *string, int flags); +/* GIT_EXTERN(int) p_fnmatch(const char *pattern, const char *string, int flags); */ /** @} */ GIT_END_DECL From c3f7a9386d1f244a5442a1be484e1093b1698a02 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Fri, 8 Jun 2012 19:37:24 +0100 Subject: [PATCH 13/31] Re-add the ability to select the PowerPC SHA1 function --- CMakeLists.txt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d3df285e..c6254efda 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,11 +23,22 @@ STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_V STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_REV "${GIT2_HEADER}") SET(LIBGIT2_VERSION_STRING "${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}.${LIBGIT2_VERSION_REV}") +# Comment out the line below to use OpenSSL SHA1 +SET(SHA1_TYPE "ppc") + # Find required dependencies INCLUDE_DIRECTORIES(src include deps/http-parser) FILE(GLOB SRC_HTTP deps/http-parser/*.c) +# Specify sha1 implementation +IF (SHA1_TYPE STREQUAL "ppc") + ADD_DEFINITIONS(-DPPC_SHA1) + FILE(GLOB SRC_SHA1 src/ppc/*.c) +ELSE () + SET (SRC_SHA1) +ENDIF() + IF (NOT WIN32) FIND_PACKAGE(ZLIB) ELSE() @@ -122,7 +133,7 @@ ELSE() ENDIF () # Compile and link libgit2 -ADD_LIBRARY(git2 ${SRC} ${SRC_ZLIB} ${SRC_HTTP} ${SRC_REGEX} ${WIN_RC}) +ADD_LIBRARY(git2 ${SRC} ${SRC_ZLIB} ${SRC_HTTP} ${SRC_REGEX} ${SRC_SHA1} ${WIN_RC}) IF (WIN32) TARGET_LINK_LIBRARIES(git2 ws2_32) From 4c650c2b80d1b38759f0e7b6a782ed88d78648d5 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Fri, 8 Jun 2012 19:55:04 +0100 Subject: [PATCH 14/31] Don't use the PPC native SHA1 :( CMake is refusing to acknowledge the sha1ppc.S ppc asm code. --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6254efda..041553fd0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,8 +23,8 @@ STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_V STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_REV "${GIT2_HEADER}") SET(LIBGIT2_VERSION_STRING "${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}.${LIBGIT2_VERSION_REV}") -# Comment out the line below to use OpenSSL SHA1 -SET(SHA1_TYPE "ppc") +# Uncomment out the line below to use PowerPC SHA1 +#SET(SHA1_TYPE "ppc") # Find required dependencies INCLUDE_DIRECTORIES(src include deps/http-parser) @@ -34,7 +34,7 @@ FILE(GLOB SRC_HTTP deps/http-parser/*.c) # Specify sha1 implementation IF (SHA1_TYPE STREQUAL "ppc") ADD_DEFINITIONS(-DPPC_SHA1) - FILE(GLOB SRC_SHA1 src/ppc/*.c) + FILE(GLOB SRC_SHA1 src/ppc/*.c src/ppc/*.S) ELSE () SET (SRC_SHA1) ENDIF() From bb502fa803605bcfce08da5467e52813eff4d38d Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 9 Jun 2012 12:52:49 +0100 Subject: [PATCH 15/31] Fix makefile --- examples/network/Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/network/Makefile b/examples/network/Makefile index c21869ac9..0cffe855b 100644 --- a/examples/network/Makefile +++ b/examples/network/Makefile @@ -1,8 +1,9 @@ default: all -CC = gcc +CC = ppc-amigaos-gcc CFLAGS += -g -CFLAGS += -I../../include -L../../ -lgit2 -lpthread +CFLAGS += -I../../include -L../../build +LIBS += -lgit2 -lpthread -lregex OBJECTS = \ git2.o \ @@ -11,4 +12,4 @@ OBJECTS = \ index-pack.o all: $(OBJECTS) - $(CC) $(CFLAGS) -o git2 $(OBJECTS) + $(CC) $(CFLAGS) -o git2 $(OBJECTS) $(LIBS) From 5c0fd7b976b8fb1271dbe61b9ea456672ab5b370 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 9 Jun 2012 13:20:07 +0100 Subject: [PATCH 16/31] allow disabling pthreads for testing --- examples/network/fetch.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/network/fetch.c b/examples/network/fetch.c index 8dcb81b1f..fc4e94cfd 100644 --- a/examples/network/fetch.c +++ b/examples/network/fetch.c @@ -36,7 +36,9 @@ static void *download(void *ptr) exit: data->finished = 1; +#ifndef NO_PTHREADS pthread_exit(&data->ret); +#endif } int update_cb(const char *refname, const git_oid *a, const git_oid *b) @@ -81,6 +83,9 @@ int fetch(git_repository *repo, int argc, char **argv) data.finished = 0; memset(&stats, 0, sizeof(stats)); +#ifdef NO_PTHREADS + download(&data); +#else pthread_create(&worker, NULL, download, &data); // Loop while the worker thread is still running. Here we show processed @@ -91,6 +96,7 @@ int fetch(git_repository *repo, int argc, char **argv) usleep(10000); printf("\rReceived %d/%d objects in %d bytes", stats.processed, stats.total, bytes); } while (!data.finished); +#endif printf("\rReceived %d/%d objects in %d bytes\n", stats.processed, stats.total, bytes); // Disconnect the underlying connection to prevent from idling. From b9bfc7684b94bf052203034cbddfdf01e26205e5 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 9 Jun 2012 17:33:08 +0100 Subject: [PATCH 17/31] pre-compiled sha1ppc.S.obj file with nasty CMake hack instructions as the cross-compile process refuses to build and link this file itself. --- CMakeLists.txt | 2 +- README.amiga | 4 ++++ src/ppc/sha1ppc.S.obj | Bin 0 -> 4471 bytes 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100755 README.amiga create mode 100644 src/ppc/sha1ppc.S.obj diff --git a/CMakeLists.txt b/CMakeLists.txt index 041553fd0..d245109bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" SET(LIBGIT2_VERSION_STRING "${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}.${LIBGIT2_VERSION_REV}") # Uncomment out the line below to use PowerPC SHA1 -#SET(SHA1_TYPE "ppc") +SET(SHA1_TYPE "ppc") # Find required dependencies INCLUDE_DIRECTORIES(src include deps/http-parser) diff --git a/README.amiga b/README.amiga new file mode 100755 index 000000000..97414dda2 --- /dev/null +++ b/README.amiga @@ -0,0 +1,4 @@ +Nasty build hack: +When setting SHA1 to ppc in CMakeLists.txt, after running initial CMake, +copy src/ppc/sha1ppc.S.obj to build/CMakeFiles/git2.dir/src/ppc/ +Add CMakeFiles/git2.dir/src/ppc/sha1ppc.S.obj to the list in build/CMakeFiles/git2.dir/link.txt diff --git a/src/ppc/sha1ppc.S.obj b/src/ppc/sha1ppc.S.obj new file mode 100644 index 0000000000000000000000000000000000000000..a7dad600fee80b062086f352aa62b87b1755e7ac GIT binary patch literal 4471 zcma)=L1-M;8ONU$(Qct&8Rnpp9Aq%mD}s?i3S(o;Vv-_;QdAMGL6_KT2aHUUAn7o1 zXLc*qml#7q=u*>zBjVBu48h<-)P|}eY(WPfL{TX%LD0}W|Nrm%wuyRZ z1*>@)y*E3*|NDOP-fr*JAN}yy$gwp1IhHcCzjk8G{`ImBr_;C7=*Gz}KltdqH2V9i zDOJCF?l-H~QaXQcVXgPCFUr+hX|(s}&&%F#KPy+?PmRm>-}zPV-G7#=AE)p37XMyW z{e`SLoGI($GkMh?$>v+9FU&WeUa0yvvnowytDmMZp05U-tWL9KJvEzGgOTjD9rP>E zZ?L9*YoiH$MzXrGnAHyl$Z1;pq#n^`Bm-8@H|BsWi^>b#p1JTX|XS=Xu@4 z`zG`opkH&{`n{4~;Q6}1eeAT#>ho4!7w9*E_idnGao74?OA|a_^>H8M$c}PsTEAQA zlyTfPjvpN5*s^}_r_;u33<$~bTzDJ?nQWX`ZUVL*qDilw;rey^_uw$95);8@r|Mw*{UXch%{iGw4nuL(iZ+jWNn#Nf~tK$ciz@pgU)IFoW(KGDHUF@4fjq=FpzQ zIP|-G|Fiex+hI|5myNkf7tyv{m_>Ja%W^>$?PYSUA&0rLyJ5Ul!q^SVggJCKkR#Zc zLwkcvsQZbR%I+g$tvL3P<)I87ZCg#C4%&~%gZgisE4v5AStX1;uq?!Xfc(JB8fYJo z13vEHo}U?Gl`!_1@?KgXFFXNnO;0ed9=anbLu6X4L=9Ij0gp8PLIpVx@r0Va9mwp5<{Rm$Ap*CwBepG{f@yZS7l^f10 zH=LJl)D3t6-Wpy6FTDs}dZ9KwhZl7dPH=wdg!9S?=amyNzjUHlwE3kE&MP0BS3Wo| zeW?0yf%Oa*f|o7?FI@;;dQc5+T0OJ=omchmysCfaW&PI;)IWGx|G~@p4_?-P@T&fs zsDJXZ{)3nGAH1yp;AQ<6>&DCam$ScoUNubzf|(8kGaR^l{}2DD`taazCZ`AFQwH$B zGQjfy9z+Ihd4PK1dOO$z|7xd1U8Vm=72Sx9bMHn3&4x1$kBT@WL{| z_25NhVqT#BxgIy+M=Q_e2e_Gy{7^Qy9{uoa%nx(DF0iicw6KO4JDry&s)-!uk*Vin zp5Q+5tgHI)1-a0d$c4T{F7zdGF<&B=J>?>AJQsQ6xyT#O#k`4J;16=4KamUliCpMU zo{RkQT;!MMVtz#~@C>!^`A{X;4a#>R@^38LRZ=Q>M z^IXig$mO=>Lhm9MdKbCSyU0b};XYL_@Q=B`zhN$LZ zXQ~B^<$C3{AkUmv`?x;*0x$gvUanWcOTU7bepQ1-@yaXbl~>Lyubfx=w+4Iyul8=v ztG%1^YVYQ}+P5{~5qRa1^U5RVl}FAikBT*WCUCuSUiss^^2d4UPt}Jv>rz!+GV0 z^U9B6OT6;JdF6%k$_wYE7gZlVfR{c5FMSAJx)8i{A-|Pc)nHr9^f#D;m&dw+ng^qO z{-h&wLq4+AP1HD;>~kmok9v0=xm@gvfzP9uvtfPW-g{rZl=VJ2m-RlnnDu^LWWArw zWf#-aTYtpo@DK5MJU^LcfBf?_kCCk&D_7E)&hql` zWB>orcpiQDy}-A;FTN2te$U%H#CHZKz5Sg1@AzNrIQ$*`zK=5vy#80e6aVSMYv_6} zvgJQ Date: Sat, 9 Jun 2012 18:13:07 +0100 Subject: [PATCH 18/31] Fix gethostbyname compatibility --- include/git2/common.h | 6 +----- src/netops.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/git2/common.h b/include/git2/common.h index 045ba85c4..99018d4f5 100644 --- a/include/git2/common.h +++ b/include/git2/common.h @@ -56,11 +56,7 @@ #endif #ifdef __amigaos4__ -/* Network byte order is big-endian... so is PPC, so these functions are NOP */ -#define htonl(x) x -#define ntohl(x) x -#define htons(x) x -#define ntohs(x) x +#include #endif /** diff --git a/src/netops.c b/src/netops.c index fdbd965b1..6808c8ee7 100644 --- a/src/netops.c +++ b/src/netops.c @@ -382,7 +382,9 @@ int gitno_connect(git_transport *t, const char *host, const char *port) #else int p; struct hostent *hent; + struct servent *sent; struct sockaddr_in saddr; + long port_num = 0; #endif int ret; GIT_SOCKET s = INVALID_SOCKET; @@ -397,6 +399,12 @@ int gitno_connect(git_transport *t, const char *host, const char *port) } #else hent = gethostbyname(host); + sent = getservbyname(port, 0); + + if(sent) + port_num = sent->s_port; + else + port_num = atol(port); #endif #ifndef __amigaos4__ @@ -413,9 +421,9 @@ int gitno_connect(git_transport *t, const char *host, const char *port) #ifndef __amigaos4__ if (connect(s, p->ai_addr, (socklen_t)p->ai_addrlen) == 0) #else - saddr.sin_addr.s_addr = *hent->h_addr_list[p]; + memcpy(&saddr.sin_addr, hent->h_addr_list[p], hent->h_length); saddr.sin_family = hent->h_addrtype; - saddr.sin_port = port; + saddr.sin_port = port_num; if (connect(s, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in)) == 0) #endif break; From 7d1983ebc2312c526057ecedd4cef628a4c33974 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 9 Jun 2012 18:58:11 +0100 Subject: [PATCH 19/31] stop readdir parsing crashing --- src/path.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/path.c b/src/path.c index 056b6b910..eb9bc06f3 100644 --- a/src/path.c +++ b/src/path.c @@ -482,9 +482,14 @@ int git_path_cmp( /* Taken from git.git */ GIT_INLINE(int) is_dot_or_dotdot(const char *name) { +#ifdef __amigaos4__ + /* This is irrelevant on AmigaOS */ + return 0; +#else return (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))); +#endif } int git_path_direach( @@ -512,7 +517,11 @@ int git_path_direach( de_buf = git__malloc(sizeof(struct dirent)); #endif +#ifdef __amigaos4__ + while (de = readdir(dir)) { +#else while (p_readdir_r(dir, de_buf, de) == 0 && de != NULL) { +#endif int result; if (is_dot_or_dotdot(de->d_name)) From 41cbbea8fe0aa56dc33027ba24249f69d831fe03 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 9 Jun 2012 23:03:27 +0100 Subject: [PATCH 20/31] Let platform 'Generic' get the regex deps so we don't need to use our external ones --- CMakeLists.txt | 23 +++++++++++++++-------- examples/network/Makefile | 4 ++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 041553fd0..2591fccbf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,10 @@ ENDIF() IF (NOT WIN32) FIND_PACKAGE(ZLIB) + IF (CMAKE_SYSTEM_NAME MATCHES "Generic") + INCLUDE_DIRECTORIES(deps/regex) + SET(SRC_REGEX deps/regex/regex.c) + ENDIF() ELSE() # Windows doesn't understand POSIX regex on its own INCLUDE_DIRECTORIES(deps/regex) @@ -54,7 +58,7 @@ ELSE (ZLIB_FOUND) INCLUDE_DIRECTORIES(deps/zlib) ADD_DEFINITIONS(-DNO_VIZ -DSTDC -DNO_GZIP) FILE(GLOB SRC_ZLIB deps/zlib/*.c) -ENDIF() +#ENDIF() # Installation paths SET(INSTALL_BIN bin CACHE PATH "Where to install binaries to.") @@ -62,7 +66,7 @@ SET(INSTALL_LIB lib CACHE PATH "Where to install libraries to.") SET(INSTALL_INC include CACHE PATH "Where to install headers to.") # Build options -OPTION (BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON) +OPTION (BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" OFF) OPTION (THREADSAFE "Build libgit2 as threadsafe" OFF) OPTION (BUILD_CLAR "Build Tests using the Clar suite" ON) OPTION (BUILD_EXAMPLES "Build library usage example apps" OFF) @@ -102,12 +106,15 @@ IF (NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE) ENDIF () -#FIND_PACKAGE(OpenSSL) -#IF (OPENSSL_FOUND) -# ADD_DEFINITIONS(-DGIT_SSL) -# INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) -# SET(SSL_LIBRARIES ${OPENSSL_LIBRARIES}) -#ENDIF() +IF (CMAKE_SYSTEM_NAME MATCHES "Generic") +ELSE () + FIND_PACKAGE(OpenSSL) + IF (OPENSSL_FOUND) + ADD_DEFINITIONS(-DGIT_SSL) + INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) + SET(SSL_LIBRARIES ${OPENSSL_LIBRARIES}) + ENDIF() +ENDIF() IF (THREADSAFE) IF (NOT WIN32) diff --git a/examples/network/Makefile b/examples/network/Makefile index 0cffe855b..708a6b1b3 100644 --- a/examples/network/Makefile +++ b/examples/network/Makefile @@ -1,9 +1,9 @@ default: all -CC = ppc-amigaos-gcc +CC = gcc CFLAGS += -g CFLAGS += -I../../include -L../../build -LIBS += -lgit2 -lpthread -lregex +LIBS += -lgit2 -lpthread #-lregex OBJECTS = \ git2.o \ From c9f79972baefb00e3c86a96e7a448c124bde7693 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 9 Jun 2012 23:13:21 +0100 Subject: [PATCH 21/31] remove errorneous comment --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e52c74b9..969a5e682 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,7 +58,7 @@ ELSE (ZLIB_FOUND) INCLUDE_DIRECTORIES(deps/zlib) ADD_DEFINITIONS(-DNO_VIZ -DSTDC -DNO_GZIP) FILE(GLOB SRC_ZLIB deps/zlib/*.c) -#ENDIF() +ENDIF() # Installation paths SET(INSTALL_BIN bin CACHE PATH "Where to install binaries to.") From 90490113af9cef092b36c5ee0231c11675ed9f51 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 10 Jun 2012 18:08:15 +0100 Subject: [PATCH 22/31] Basic mmap/munmap compatiblity --- src/map.h | 4 ++++ src/pack.c | 4 ++-- src/unix/map.c | 19 ++++++++++++++++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/map.h b/src/map.h index 96d879547..6ce6d3685 100644 --- a/src/map.h +++ b/src/map.h @@ -23,6 +23,10 @@ #define GIT_MAP_TYPE 0xf #define GIT_MAP_FIXED 0x10 +#ifdef __amigaos4__ +#define MAP_FAILED 0 +#endif + typedef struct { /* memory mapped buffer */ void *data; /* data bytes */ size_t len; /* data length */ diff --git a/src/pack.c b/src/pack.c index 0db1069de..85bc6707e 100644 --- a/src/pack.c +++ b/src/pack.c @@ -215,7 +215,7 @@ static int packfile_unpack_header1( unsigned shift; unsigned long size, c; unsigned long used = 0; - +printf("[pack 218] buf = %lx, used = %ld, len = %ld\n", buf, used, len); c = buf[used++]; *type = (c >> 4) & 7; size = c & 15; @@ -261,7 +261,7 @@ int git_packfile_unpack_header( base = git_mwindow_open(mwf, w_curs, *curpos, 20, &left); if (base == NULL) return GIT_EBUFS; - +printf("[pack 264] base = %lx, mwf = %lx\n", base, mwf); ret = packfile_unpack_header1(&used, size_p, type_p, base, left); git_mwindow_close(w_curs); if (ret == GIT_EBUFS) diff --git a/src/unix/map.c b/src/unix/map.c index 65f4ac91c..8e853b9be 100644 --- a/src/unix/map.c +++ b/src/unix/map.c @@ -16,7 +16,6 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset) { -#ifndef __amigaos4__ int mprot = 0; int mflag = 0; @@ -25,6 +24,7 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs out->data = NULL; out->len = 0; +#ifndef __amigaos4__ if (prot & GIT_PROT_WRITE) mprot = PROT_WRITE; else if (prot & GIT_PROT_READ) @@ -36,21 +36,34 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs mflag = MAP_PRIVATE; out->data = mmap(NULL, len, mprot, mflag, fd, offset); +#else + if ((prot & GIT_PROT_WRITE) && ((flags & GIT_MAP_TYPE) == GIT_MAP_SHARED)) { + printf("Trying to map shared-writeable file!!!\n"); + + if(out->data = malloc(len)) { + lseek(fd, offset, SEEK_SET); + p_read(fd, out->data, len); + } + } +#endif + if (!out->data || out->data == MAP_FAILED) { giterr_set(GITERR_OS, "Failed to mmap. Could not write data"); return -1; } out->len = len; -#endif + return 0; } int p_munmap(git_map *map) { -#ifndef __amigaos4__ assert(map != NULL); +#ifndef __amigaos4__ munmap(map->data, map->len); +#else + free(map->data); #endif return 0; } From 2aeadb9c78df4b463ffb3293e242e19a7e0d17a9 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Tue, 12 Jun 2012 19:25:09 +0100 Subject: [PATCH 23/31] Actually do the mmap... unsurprisingly, this makes the indexer work on SFS On RAM: the .idx and .pack files become links to a .lock and the original download respectively. Assume some feature (such as record locking) supported by SFS but not JXFS or RAM: is required. --- src/indexer.c | 2 +- src/mwindow.c | 1 + src/pack.c | 6 +++--- src/unix/map.c | 8 ++++---- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/indexer.c b/src/indexer.c index f0e0a6381..5542bfeba 100644 --- a/src/indexer.c +++ b/src/indexer.c @@ -363,11 +363,11 @@ int git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t siz if (error < 0) { idx->off = entry_start; error = store_delta(idx); + if (error == GIT_EBUFS) return 0; if (error < 0) return error; - continue; } diff --git a/src/mwindow.c b/src/mwindow.c index 57adabd48..74fbf7834 100644 --- a/src/mwindow.c +++ b/src/mwindow.c @@ -158,6 +158,7 @@ static git_mwindow *new_window( git_mwindow *w; w = git__malloc(sizeof(*w)); + if (w == NULL) return NULL; diff --git a/src/pack.c b/src/pack.c index 85bc6707e..9b5e0e18f 100644 --- a/src/pack.c +++ b/src/pack.c @@ -215,7 +215,7 @@ static int packfile_unpack_header1( unsigned shift; unsigned long size, c; unsigned long used = 0; -printf("[pack 218] buf = %lx, used = %ld, len = %ld\n", buf, used, len); + c = buf[used++]; *type = (c >> 4) & 7; size = c & 15; @@ -261,8 +261,8 @@ int git_packfile_unpack_header( base = git_mwindow_open(mwf, w_curs, *curpos, 20, &left); if (base == NULL) return GIT_EBUFS; -printf("[pack 264] base = %lx, mwf = %lx\n", base, mwf); - ret = packfile_unpack_header1(&used, size_p, type_p, base, left); + + ret = packfile_unpack_header1(&used, size_p, type_p, base, left); git_mwindow_close(w_curs); if (ret == GIT_EBUFS) return ret; diff --git a/src/unix/map.c b/src/unix/map.c index 8e853b9be..b04e95a76 100644 --- a/src/unix/map.c +++ b/src/unix/map.c @@ -39,11 +39,11 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs #else if ((prot & GIT_PROT_WRITE) && ((flags & GIT_MAP_TYPE) == GIT_MAP_SHARED)) { printf("Trying to map shared-writeable file!!!\n"); + } - if(out->data = malloc(len)) { - lseek(fd, offset, SEEK_SET); - p_read(fd, out->data, len); - } + if(out->data = malloc(len)) { + lseek(fd, offset, SEEK_SET); + p_read(fd, out->data, len); } #endif From 96ef3d84629ef72fb662d95abbab3de634921678 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Wed, 13 Jun 2012 23:16:14 +0100 Subject: [PATCH 24/31] Make this more generic and mergeable. Needs AmigaOS.cmake now from CMake package at OS4Depot, or contents below: --8<-- SET(AMIGA 1) SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC") SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared") --8<-- --- CMakeLists.txt | 34 ++++++++++++++++--------------- src/amiga/map.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ src/netops.c | 12 +++++------ src/path.c | 2 +- src/posix.h | 2 +- src/unix/map.c | 18 +---------------- 6 files changed, 80 insertions(+), 41 deletions(-) create mode 100755 src/amiga/map.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 969a5e682..fdc103e8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ # Install: # > cmake --build . --target install -SET(CMAKE_SYSTEM_NAME "Generic") +SET(CMAKE_SYSTEM_NAME "AmigaOS") PROJECT(libgit2 C) CMAKE_MINIMUM_REQUIRED(VERSION 2.6) @@ -23,8 +23,10 @@ STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_V STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_REV "${GIT2_HEADER}") SET(LIBGIT2_VERSION_STRING "${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}.${LIBGIT2_VERSION_REV}") -# Uncomment out the line below to use PowerPC SHA1 -SET(SHA1_TYPE "ppc") +IF (AMIGA) + # Default AmigaOS to use the PowerPC SHA1 + SET(SHA1_TYPE "ppc") +ENDIF() # Find required dependencies INCLUDE_DIRECTORIES(src include deps/http-parser) @@ -33,15 +35,15 @@ FILE(GLOB SRC_HTTP deps/http-parser/*.c) # Specify sha1 implementation IF (SHA1_TYPE STREQUAL "ppc") - ADD_DEFINITIONS(-DPPC_SHA1) - FILE(GLOB SRC_SHA1 src/ppc/*.c src/ppc/*.S) + ADD_DEFINITIONS(-DPPC_SHA1) + FILE(GLOB SRC_SHA1 src/ppc/*.c src/ppc/*.S) ELSE () SET (SRC_SHA1) ENDIF() IF (NOT WIN32) FIND_PACKAGE(ZLIB) - IF (CMAKE_SYSTEM_NAME MATCHES "Generic") + IF (CMAKE_SYSTEM_NAME STREQUAL "AmigaOS") INCLUDE_DIRECTORIES(deps/regex) SET(SRC_REGEX deps/regex/regex.c) ENDIF() @@ -68,7 +70,7 @@ SET(INSTALL_INC include CACHE PATH "Where to install headers to.") # Build options OPTION (BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" OFF) OPTION (THREADSAFE "Build libgit2 as threadsafe" OFF) -OPTION (BUILD_CLAR "Build Tests using the Clar suite" ON) +OPTION (BUILD_CLAR "Build Tests using the Clar suite" OFF) OPTION (BUILD_EXAMPLES "Build library usage example apps" OFF) OPTION (TAGS "Generate tags" OFF) OPTION (PROFILE "Generate profiling information" OFF) @@ -106,14 +108,11 @@ IF (NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE) ENDIF () -IF (CMAKE_SYSTEM_NAME MATCHES "Generic") -ELSE () - FIND_PACKAGE(OpenSSL) - IF (OPENSSL_FOUND) - ADD_DEFINITIONS(-DGIT_SSL) - INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) - SET(SSL_LIBRARIES ${OPENSSL_LIBRARIES}) - ENDIF() +FIND_PACKAGE(OpenSSL) +IF (OPENSSL_FOUND) + ADD_DEFINITIONS(-DGIT_SSL) + INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) + SET(SSL_LIBRARIES ${OPENSSL_LIBRARIES}) ENDIF() IF (THREADSAFE) @@ -133,8 +132,11 @@ FILE(GLOB SRC_H include/git2/*.h) IF (WIN32 AND NOT CYGWIN) ADD_DEFINITIONS(-DWIN32 -D_DEBUG -D_WIN32_WINNT=0x0501) FILE(GLOB SRC src/*.c src/transports/*.c src/xdiff/*.c src/win32/*.c src/compat/*.c) -ELSEIF (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS|Generic)") +ELSEIF (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") FILE(GLOB SRC src/*.c src/transports/*.c src/xdiff/*.c src/unix/*.c src/compat/*.c) +ELSEIF (AMIGA) + ADD_DEFINITIONS(-DNO_ADDRINFO -DNO_READDIR_R) + FILE(GLOB SRC src/*.c src/transports/*.c src/xdiff/*.c src/amiga/*.c src/compat/*.c) ELSE() FILE(GLOB SRC src/*.c src/transports/*.c src/xdiff/*.c src/unix/*.c) ENDIF () diff --git a/src/amiga/map.c b/src/amiga/map.c new file mode 100755 index 000000000..d36bcbc9c --- /dev/null +++ b/src/amiga/map.c @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2009-2012 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ +#include + +#ifndef GIT_WIN32 + +#include "posix.h" +#include "map.h" +#include + +int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset) +{ + int mprot = 0; + int mflag = 0; + + GIT_MMAP_VALIDATE(out, len, prot, flags); + + out->data = NULL; + out->len = 0; + + if ((prot & GIT_PROT_WRITE) && ((flags & GIT_MAP_TYPE) == GIT_MAP_SHARED)) { + printf("Trying to map shared-writeable file!!!\n"); + } + + if(out->data = malloc(len)) { + p_lseek(fd, offset, SEEK_SET); + p_read(fd, out->data, len); + } + + if (!out->data || out->data == MAP_FAILED) { + giterr_set(GITERR_OS, "Failed to mmap. Could not write data"); + return -1; + } + + out->len = len; + + return 0; +} + +int p_munmap(git_map *map) +{ + assert(map != NULL); + free(map->data); + + return 0; +} + +#endif + diff --git a/src/netops.c b/src/netops.c index 6808c8ee7..11295c5cd 100644 --- a/src/netops.c +++ b/src/netops.c @@ -376,7 +376,7 @@ static int ssl_setup(git_transport *t, const char *host) int gitno_connect(git_transport *t, const char *host, const char *port) { -#ifndef __amigaos4__ +#ifndef NO_ADDRINFO struct addrinfo *info = NULL, *p; struct addrinfo hints; #else @@ -388,7 +388,7 @@ int gitno_connect(git_transport *t, const char *host, const char *port) #endif int ret; GIT_SOCKET s = INVALID_SOCKET; -#ifndef __amigaos4__ +#ifndef NO_ADDRINFO memset(&hints, 0x0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; @@ -407,7 +407,7 @@ int gitno_connect(git_transport *t, const char *host, const char *port) port_num = atol(port); #endif -#ifndef __amigaos4__ +#ifndef NO_ADDRINFO for (p = info; p != NULL; p = p->ai_next) { s = socket(p->ai_family, p->ai_socktype, p->ai_protocol); #else @@ -418,7 +418,7 @@ int gitno_connect(git_transport *t, const char *host, const char *port) net_set_error("error creating socket"); break; } -#ifndef __amigaos4__ +#ifndef NO_ADDRINFO if (connect(s, p->ai_addr, (socklen_t)p->ai_addrlen) == 0) #else memcpy(&saddr.sin_addr, hent->h_addr_list[p], hent->h_length); @@ -435,7 +435,7 @@ int gitno_connect(git_transport *t, const char *host, const char *port) /* Oops, we couldn't connect to any address */ if (s == INVALID_SOCKET && -#ifndef __amigaos4__ +#ifndef NO_ADDRINFO p == NULL) { #else hent->h_addr_list[p] == NULL) { @@ -445,7 +445,7 @@ int gitno_connect(git_transport *t, const char *host, const char *port) } t->socket = s; -#ifndef __amigaos4__ +#ifndef NO_ADDRINFO freeaddrinfo(info); #endif if (t->encrypt && ssl_setup(t, host) < 0) diff --git a/src/path.c b/src/path.c index eb9bc06f3..596dad164 100644 --- a/src/path.c +++ b/src/path.c @@ -517,7 +517,7 @@ int git_path_direach( de_buf = git__malloc(sizeof(struct dirent)); #endif -#ifdef __amigaos4__ +#ifdef NO_READDIR_R while (de = readdir(dir)) { #else while (p_readdir_r(dir, de_buf, de) == 0 && de != NULL) { diff --git a/src/posix.h b/src/posix.h index 8e8b394c8..35118f968 100644 --- a/src/posix.h +++ b/src/posix.h @@ -74,7 +74,7 @@ typedef SOCKET GIT_SOCKET; # include "unix/posix.h" #endif -#ifndef __amigaos4__ +#ifndef NO_READDIR_R #define p_readdir_r(d,e,r) readdir_r(d,e,&r) #else #define p_readdir_r(d,e,r) r = readdir(d) diff --git a/src/unix/map.c b/src/unix/map.c index b04e95a76..9dcae5845 100644 --- a/src/unix/map.c +++ b/src/unix/map.c @@ -9,9 +9,7 @@ #ifndef GIT_WIN32 #include "map.h" -#ifndef __amigaos4__ #include -#endif #include int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset) @@ -24,7 +22,6 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs out->data = NULL; out->len = 0; -#ifndef __amigaos4__ if (prot & GIT_PROT_WRITE) mprot = PROT_WRITE; else if (prot & GIT_PROT_READ) @@ -36,16 +33,6 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs mflag = MAP_PRIVATE; out->data = mmap(NULL, len, mprot, mflag, fd, offset); -#else - if ((prot & GIT_PROT_WRITE) && ((flags & GIT_MAP_TYPE) == GIT_MAP_SHARED)) { - printf("Trying to map shared-writeable file!!!\n"); - } - - if(out->data = malloc(len)) { - lseek(fd, offset, SEEK_SET); - p_read(fd, out->data, len); - } -#endif if (!out->data || out->data == MAP_FAILED) { giterr_set(GITERR_OS, "Failed to mmap. Could not write data"); @@ -60,11 +47,8 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs int p_munmap(git_map *map) { assert(map != NULL); -#ifndef __amigaos4__ munmap(map->data, map->len); -#else - free(map->data); -#endif + return 0; } From 17b45d801d6dd40566ec1b876b108eb033e6779a Mon Sep 17 00:00:00 2001 From: Chris Young Date: Wed, 13 Jun 2012 23:43:25 +0100 Subject: [PATCH 25/31] Removed hardcoded CMAKE_SYSTEM_NAME --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f260f025..657544938 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,8 +11,6 @@ # Install: # > cmake --build . --target install -SET(CMAKE_SYSTEM_NAME "AmigaOS") - PROJECT(libgit2 C) CMAKE_MINIMUM_REQUIRED(VERSION 2.6) From a8df98c6fb07b8ddff18a01d7f2f607d9493dd7c Mon Sep 17 00:00:00 2001 From: Chris Young Date: Thu, 14 Jun 2012 18:57:24 +0100 Subject: [PATCH 26/31] Updates from comments on OS4 compatibility pull request http://github.com/libgit2/libgit2/pull/766 --- examples/network/Makefile | 3 +-- examples/network/fetch.c | 7 +----- include/git2/common.h | 2 -- src/amiga/map.c | 3 ++- src/netops.c | 45 ++++++++++++++++++++++----------------- src/path.c | 9 -------- src/pool.c | 2 +- src/posix.h | 7 +++++- 8 files changed, 37 insertions(+), 41 deletions(-) diff --git a/examples/network/Makefile b/examples/network/Makefile index 708a6b1b3..17efcfdb3 100644 --- a/examples/network/Makefile +++ b/examples/network/Makefile @@ -3,7 +3,6 @@ default: all CC = gcc CFLAGS += -g CFLAGS += -I../../include -L../../build -LIBS += -lgit2 -lpthread #-lregex OBJECTS = \ git2.o \ @@ -12,4 +11,4 @@ OBJECTS = \ index-pack.o all: $(OBJECTS) - $(CC) $(CFLAGS) -o git2 $(OBJECTS) $(LIBS) + $(CC) $(CFLAGS) -o git2 $(OBJECTS) diff --git a/examples/network/fetch.c b/examples/network/fetch.c index fc4e94cfd..d2752124d 100644 --- a/examples/network/fetch.c +++ b/examples/network/fetch.c @@ -36,9 +36,7 @@ static void *download(void *ptr) exit: data->finished = 1; -#ifndef NO_PTHREADS pthread_exit(&data->ret); -#endif } int update_cb(const char *refname, const git_oid *a, const git_oid *b) @@ -83,9 +81,6 @@ int fetch(git_repository *repo, int argc, char **argv) data.finished = 0; memset(&stats, 0, sizeof(stats)); -#ifdef NO_PTHREADS - download(&data); -#else pthread_create(&worker, NULL, download, &data); // Loop while the worker thread is still running. Here we show processed @@ -96,7 +91,7 @@ int fetch(git_repository *repo, int argc, char **argv) usleep(10000); printf("\rReceived %d/%d objects in %d bytes", stats.processed, stats.total, bytes); } while (!data.finished); -#endif + printf("\rReceived %d/%d objects in %d bytes\n", stats.processed, stats.total, bytes); // Disconnect the underlying connection to prevent from idling. diff --git a/include/git2/common.h b/include/git2/common.h index 99018d4f5..1af045cff 100644 --- a/include/git2/common.h +++ b/include/git2/common.h @@ -103,8 +103,6 @@ GIT_EXTERN(int) git_strarray_copy(git_strarray *tgt, const git_strarray *src); */ GIT_EXTERN(void) git_libgit2_version(int *major, int *minor, int *rev); -/* GIT_EXTERN(int) p_fnmatch(const char *pattern, const char *string, int flags); */ - /** @} */ GIT_END_DECL #endif diff --git a/src/amiga/map.c b/src/amiga/map.c index d36bcbc9c..643e6c65d 100755 --- a/src/amiga/map.c +++ b/src/amiga/map.c @@ -23,7 +23,8 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs out->len = 0; if ((prot & GIT_PROT_WRITE) && ((flags & GIT_MAP_TYPE) == GIT_MAP_SHARED)) { - printf("Trying to map shared-writeable file!!!\n"); + giterr_set(GITERR_OS, "Trying to map shared-writeable"); + return -1; } if(out->data = malloc(len)) { diff --git a/src/netops.c b/src/netops.c index 11295c5cd..166c97162 100644 --- a/src/netops.c +++ b/src/netops.c @@ -33,6 +33,16 @@ #include "buffer.h" #include "transport.h" +#ifdef NO_ADDRINFO +struct addrinfo { + struct hostent *ai_hostent; + struct servent *ai_servent; + struct sockaddr_in ai_addr; + int ai_socktype; + long ai_port; +}; +#endif + #ifdef GIT_WIN32 static void net_set_error(const char *str) { @@ -378,41 +388,38 @@ int gitno_connect(git_transport *t, const char *host, const char *port) { #ifndef NO_ADDRINFO struct addrinfo *info = NULL, *p; - struct addrinfo hints; #else int p; - struct hostent *hent; - struct servent *sent; - struct sockaddr_in saddr; - long port_num = 0; #endif + struct addrinfo hints; int ret; GIT_SOCKET s = INVALID_SOCKET; -#ifndef NO_ADDRINFO + memset(&hints, 0x0, sizeof(struct addrinfo)); - hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; +#ifndef NO_ADDRINFO + hints.ai_family = AF_UNSPEC; if ((ret = getaddrinfo(host, port, &hints, &info)) < 0) { giterr_set(GITERR_NET, "Failed to resolve address for %s: %s", host, gai_strerror(ret)); return -1; } #else - hent = gethostbyname(host); - sent = getservbyname(port, 0); + hints.ai_hostent = gethostbyname(host); + hints.ai_servent = getservbyname(port, 0); - if(sent) - port_num = sent->s_port; + if(hints.ai_servent) + hints.ai_port = hints.ai_servent->s_port; else - port_num = atol(port); + hints.ai_port = atol(port); #endif #ifndef NO_ADDRINFO for (p = info; p != NULL; p = p->ai_next) { s = socket(p->ai_family, p->ai_socktype, p->ai_protocol); #else - for (p = 0; hent->h_addr_list[p] != NULL; p++) { - s = socket(hent->h_addrtype, SOCK_STREAM, 0); + for (p = 0; hints.ai_hostent->h_addr_list[p] != NULL; p++) { + s = socket(hints.ai_hostent->h_addrtype, hints.ai_socktype, 0); #endif if (s == INVALID_SOCKET) { net_set_error("error creating socket"); @@ -421,10 +428,10 @@ int gitno_connect(git_transport *t, const char *host, const char *port) #ifndef NO_ADDRINFO if (connect(s, p->ai_addr, (socklen_t)p->ai_addrlen) == 0) #else - memcpy(&saddr.sin_addr, hent->h_addr_list[p], hent->h_length); - saddr.sin_family = hent->h_addrtype; - saddr.sin_port = port_num; - if (connect(s, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in)) == 0) + memcpy(&hints.ai_addr.sin_addr, hints.ai_hostent->h_addr_list[p], hints.ai_hostent->h_length); + hints.ai_addr.sin_family = hints.ai_hostent->h_addrtype; + hints.ai_addr.sin_port = honts.ai_port; + if (connect(s, (struct sockaddr *)&hints.ai_addr, sizeof(struct sockaddr_in)) == 0) #endif break; @@ -438,7 +445,7 @@ int gitno_connect(git_transport *t, const char *host, const char *port) #ifndef NO_ADDRINFO p == NULL) { #else - hent->h_addr_list[p] == NULL) { + hints.ai_hostent->h_addr_list[p] == NULL) { #endif giterr_set(GITERR_OS, "Failed to connect to %s", host); return -1; diff --git a/src/path.c b/src/path.c index d48435bd8..bd659f815 100644 --- a/src/path.c +++ b/src/path.c @@ -486,14 +486,9 @@ int git_path_cmp( /* Taken from git.git */ GIT_INLINE(int) is_dot_or_dotdot(const char *name) { -#ifdef __amigaos4__ - /* This is irrelevant on AmigaOS */ - return 0; -#else return (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))); -#endif } int git_path_direach( @@ -521,11 +516,7 @@ int git_path_direach( de_buf = git__malloc(sizeof(struct dirent)); #endif -#ifdef NO_READDIR_R - while (de = readdir(dir)) { -#else while (p_readdir_r(dir, de_buf, de) == 0 && de != NULL) { -#endif int result; if (is_dot_or_dotdot(de->d_name)) diff --git a/src/pool.c b/src/pool.c index c5414b3b6..63bf09cee 100644 --- a/src/pool.c +++ b/src/pool.c @@ -276,7 +276,7 @@ uint32_t git_pool__system_page_size(void) GetSystemInfo(&info); size = (uint32_t)info.dwPageSize; #elif defined(__amigaos4__) - size = (uint32_t)1000000; // random value + size = (uint32_t)4096; /* 4K as there is no global value we can query */ #else size = (uint32_t)sysconf(_SC_PAGE_SIZE); #endif diff --git a/src/posix.h b/src/posix.h index 6b6c53db1..cc35c52e3 100644 --- a/src/posix.h +++ b/src/posix.h @@ -86,7 +86,12 @@ extern int p_gettimeofday(struct timeval *tv, struct timezone *tz); #ifndef NO_READDIR_R #define p_readdir_r(d,e,r) readdir_r(d,e,&r) #else -#define p_readdir_r(d,e,r) r = readdir(d) +GIT_INLINE(int) p_readdir_r(DIR *dirp, struct dirent *entry, struct direct **result) +{ + GIT_UNUSED(entry); + *result = readdir(dirp); + return 0; +} #endif #endif From d043013fea859f5eb6f677cad28319d093f1dbda Mon Sep 17 00:00:00 2001 From: Chris Young Date: Thu, 14 Jun 2012 19:09:42 +0100 Subject: [PATCH 27/31] More changes resulting from pull request --- README.amiga | 4 ---- src/amiga/map.c | 7 ++----- src/netops.c | 2 +- src/path.c | 4 ++-- src/posix.h | 5 +++-- src/ppc/sha1ppc.S.obj | Bin 4471 -> 0 bytes 6 files changed, 8 insertions(+), 14 deletions(-) delete mode 100755 README.amiga delete mode 100644 src/ppc/sha1ppc.S.obj diff --git a/README.amiga b/README.amiga deleted file mode 100755 index 97414dda2..000000000 --- a/README.amiga +++ /dev/null @@ -1,4 +0,0 @@ -Nasty build hack: -When setting SHA1 to ppc in CMakeLists.txt, after running initial CMake, -copy src/ppc/sha1ppc.S.obj to build/CMakeFiles/git2.dir/src/ppc/ -Add CMakeFiles/git2.dir/src/ppc/sha1ppc.S.obj to the list in build/CMakeFiles/git2.dir/link.txt diff --git a/src/amiga/map.c b/src/amiga/map.c index 643e6c65d..2fb065c8b 100755 --- a/src/amiga/map.c +++ b/src/amiga/map.c @@ -14,9 +14,6 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset) { - int mprot = 0; - int mflag = 0; - GIT_MMAP_VALIDATE(out, len, prot, flags); out->data = NULL; @@ -27,12 +24,12 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs return -1; } - if(out->data = malloc(len)) { + if((out->data = malloc(len))) { p_lseek(fd, offset, SEEK_SET); p_read(fd, out->data, len); } - if (!out->data || out->data == MAP_FAILED) { + if (!out->data || (out->data == MAP_FAILED)) { giterr_set(GITERR_OS, "Failed to mmap. Could not write data"); return -1; } diff --git a/src/netops.c b/src/netops.c index 166c97162..98b5035ff 100644 --- a/src/netops.c +++ b/src/netops.c @@ -430,7 +430,7 @@ int gitno_connect(git_transport *t, const char *host, const char *port) #else memcpy(&hints.ai_addr.sin_addr, hints.ai_hostent->h_addr_list[p], hints.ai_hostent->h_length); hints.ai_addr.sin_family = hints.ai_hostent->h_addrtype; - hints.ai_addr.sin_port = honts.ai_port; + hints.ai_addr.sin_port = hints.ai_port; if (connect(s, (struct sockaddr *)&hints.ai_addr, sizeof(struct sockaddr_in)) == 0) #endif break; diff --git a/src/path.c b/src/path.c index bd659f815..1d85559a9 100644 --- a/src/path.c +++ b/src/path.c @@ -516,7 +516,7 @@ int git_path_direach( de_buf = git__malloc(sizeof(struct dirent)); #endif - while (p_readdir_r(dir, de_buf, de) == 0 && de != NULL) { + while (p_readdir_r(dir, de_buf, &de) == 0 && de != NULL) { int result; if (is_dot_or_dotdot(de->d_name)) @@ -574,7 +574,7 @@ int git_path_dirload( path_len -= prefix_len; need_slash = (path_len > 0 && path[path_len-1] != '/') ? 1 : 0; - while ((error = p_readdir_r(dir, de_buf, de)) == 0 && de != NULL) { + while ((error = p_readdir_r(dir, de_buf, &de)) == 0 && de != NULL) { char *entry_path; size_t entry_len; diff --git a/src/posix.h b/src/posix.h index cc35c52e3..d423b7e07 100644 --- a/src/posix.h +++ b/src/posix.h @@ -84,9 +84,10 @@ extern int p_gettimeofday(struct timeval *tv, struct timezone *tz); #endif #ifndef NO_READDIR_R -#define p_readdir_r(d,e,r) readdir_r(d,e,&r) +#define p_readdir_r(d,e,r) readdir_r(d,e,r) #else -GIT_INLINE(int) p_readdir_r(DIR *dirp, struct dirent *entry, struct direct **result) +#include +GIT_INLINE(int) p_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) { GIT_UNUSED(entry); *result = readdir(dirp); diff --git a/src/ppc/sha1ppc.S.obj b/src/ppc/sha1ppc.S.obj deleted file mode 100644 index a7dad600fee80b062086f352aa62b87b1755e7ac..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4471 zcma)=L1-M;8ONU$(Qct&8Rnpp9Aq%mD}s?i3S(o;Vv-_;QdAMGL6_KT2aHUUAn7o1 zXLc*qml#7q=u*>zBjVBu48h<-)P|}eY(WPfL{TX%LD0}W|Nrm%wuyRZ z1*>@)y*E3*|NDOP-fr*JAN}yy$gwp1IhHcCzjk8G{`ImBr_;C7=*Gz}KltdqH2V9i zDOJCF?l-H~QaXQcVXgPCFUr+hX|(s}&&%F#KPy+?PmRm>-}zPV-G7#=AE)p37XMyW z{e`SLoGI($GkMh?$>v+9FU&WeUa0yvvnowytDmMZp05U-tWL9KJvEzGgOTjD9rP>E zZ?L9*YoiH$MzXrGnAHyl$Z1;pq#n^`Bm-8@H|BsWi^>b#p1JTX|XS=Xu@4 z`zG`opkH&{`n{4~;Q6}1eeAT#>ho4!7w9*E_idnGao74?OA|a_^>H8M$c}PsTEAQA zlyTfPjvpN5*s^}_r_;u33<$~bTzDJ?nQWX`ZUVL*qDilw;rey^_uw$95);8@r|Mw*{UXch%{iGw4nuL(iZ+jWNn#Nf~tK$ciz@pgU)IFoW(KGDHUF@4fjq=FpzQ zIP|-G|Fiex+hI|5myNkf7tyv{m_>Ja%W^>$?PYSUA&0rLyJ5Ul!q^SVggJCKkR#Zc zLwkcvsQZbR%I+g$tvL3P<)I87ZCg#C4%&~%gZgisE4v5AStX1;uq?!Xfc(JB8fYJo z13vEHo}U?Gl`!_1@?KgXFFXNnO;0ed9=anbLu6X4L=9Ij0gp8PLIpVx@r0Va9mwp5<{Rm$Ap*CwBepG{f@yZS7l^f10 zH=LJl)D3t6-Wpy6FTDs}dZ9KwhZl7dPH=wdg!9S?=amyNzjUHlwE3kE&MP0BS3Wo| zeW?0yf%Oa*f|o7?FI@;;dQc5+T0OJ=omchmysCfaW&PI;)IWGx|G~@p4_?-P@T&fs zsDJXZ{)3nGAH1yp;AQ<6>&DCam$ScoUNubzf|(8kGaR^l{}2DD`taazCZ`AFQwH$B zGQjfy9z+Ihd4PK1dOO$z|7xd1U8Vm=72Sx9bMHn3&4x1$kBT@WL{| z_25NhVqT#BxgIy+M=Q_e2e_Gy{7^Qy9{uoa%nx(DF0iicw6KO4JDry&s)-!uk*Vin zp5Q+5tgHI)1-a0d$c4T{F7zdGF<&B=J>?>AJQsQ6xyT#O#k`4J;16=4KamUliCpMU zo{RkQT;!MMVtz#~@C>!^`A{X;4a#>R@^38LRZ=Q>M z^IXig$mO=>Lhm9MdKbCSyU0b};XYL_@Q=B`zhN$LZ zXQ~B^<$C3{AkUmv`?x;*0x$gvUanWcOTU7bepQ1-@yaXbl~>Lyubfx=w+4Iyul8=v ztG%1^YVYQ}+P5{~5qRa1^U5RVl}FAikBT*WCUCuSUiss^^2d4UPt}Jv>rz!+GV0 z^U9B6OT6;JdF6%k$_wYE7gZlVfR{c5FMSAJx)8i{A-|Pc)nHr9^f#D;m&dw+ng^qO z{-h&wLq4+AP1HD;>~kmok9v0=xm@gvfzP9uvtfPW-g{rZl=VJ2m-RlnnDu^LWWArw zWf#-aTYtpo@DK5MJU^LcfBf?_kCCk&D_7E)&hql` zWB>orcpiQDy}-A;FTN2te$U%H#CHZKz5Sg1@AzNrIQ$*`zK=5vy#80e6aVSMYv_6} zvgJQ Date: Thu, 14 Jun 2012 19:15:46 +0100 Subject: [PATCH 28/31] Fix incorrect revert --- examples/network/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/network/Makefile b/examples/network/Makefile index 17efcfdb3..298b1dc86 100644 --- a/examples/network/Makefile +++ b/examples/network/Makefile @@ -2,7 +2,7 @@ default: all CC = gcc CFLAGS += -g -CFLAGS += -I../../include -L../../build +CFLAGS += -I../../include -L../../build -lgit2 -lpthread OBJECTS = \ git2.o \ From abd6d52c724a97bf183ed41d3efa5408087d5856 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Wed, 20 Jun 2012 19:27:17 +0100 Subject: [PATCH 29/31] revert defaults --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 657544938..a8e646d06 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,9 +66,9 @@ SET(INSTALL_LIB lib CACHE PATH "Where to install libraries to.") SET(INSTALL_INC include CACHE PATH "Where to install headers to.") # Build options -OPTION (BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" OFF) +OPTION (BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON) OPTION (THREADSAFE "Build libgit2 as threadsafe" OFF) -OPTION (BUILD_CLAR "Build Tests using the Clar suite" OFF) +OPTION (BUILD_CLAR "Build Tests using the Clar suite" ON) OPTION (BUILD_EXAMPLES "Build library usage example apps" OFF) OPTION (TAGS "Generate tags" OFF) OPTION (PROFILE "Generate profiling information" OFF) From 8d18f1f72375bab73029f3f755b9a8e5e57e1edc Mon Sep 17 00:00:00 2001 From: Chris Young Date: Wed, 20 Jun 2012 20:12:30 +0100 Subject: [PATCH 30/31] getaddrinfo() replacement functions --- src/netops.c | 121 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 86 insertions(+), 35 deletions(-) diff --git a/src/netops.c b/src/netops.c index 98b5035ff..67c631cd0 100644 --- a/src/netops.c +++ b/src/netops.c @@ -37,10 +37,91 @@ struct addrinfo { struct hostent *ai_hostent; struct servent *ai_servent; - struct sockaddr_in ai_addr; + struct sockaddr_in ai_addr_in; + struct sockaddr *ai_addr; + size_t ai_addrlen; + int ai_family; int ai_socktype; + int ai_protocol; long ai_port; + struct addrinfo *ai_next; }; + +static int getaddrinfo(const char *host, const char *port, struct addrinfo *hints, struct addrinfo **info) { + GIT_UNUSED(hints); + + struct addrinfo *ainfo, *ai; + int p = 0; + + if((ainfo = malloc(sizeof(struct addrinfo))) == NULL) + return -1; + + if((ainfo->ai_hostent = gethostbyname(host)) == NULL) + return -2; + + ainfo->ai_servent = getservbyname(port, 0); + + if(ainfo->ai_servent) + ainfo->ai_port = ainfo->ai_servent->s_port; + else + ainfo->ai_port = atol(port); + + ainfo->ai_addrlen = ainfo->ai_hostent->h_length; + + memcpy(&ainfo->ai_addr_in.sin_addr, ainfo->ai_hostent->h_addr_list[0], ainfo->ai_hostent->h_length); + ainfo->ai_addr_in.sin_family = ainfo->ai_hostent->h_addrtype; + ainfo->ai_addr_in.sin_port = ainfo->ai_port; + ainfo->ai_addr = (struct addrinfo *)&ainfo->ai_addr_in; + + *info = ainfo; + + if(ainfo->ai_hostent->h_addr_list[1] == NULL) { + ainfo->ai_next = NULL; + return 0; + } + + ai = ainfo; + + for (p = 1; ainfo->ai_hostent->h_addr_list[p] != NULL; p++) { + ai->ai_next = malloc(sizeof(struct addrinfo)); + memcpy(&ai->ai_next, ainfo, sizeof(struct addrinfo)); + memcpy(&ai->ai_next->ai_addr_in.sin_addr, ainfo->ai_hostent->h_addr_list[p], ainfo->ai_hostent->h_length); + ai->ai_next->ai_addr = (struct addrinfo *)&ai->ai_next->ai_addr_in; + ainfo->ai_addrlen = ainfo->ai_hostent->h_length; + ai = ai->ai_next; + } + + ai->ai_next = NULL; + return 0; +} + +static void freeaddrinfo(struct addrinfo *info) { + struct addrinfo *p, *next; + + p = info; + + while(p != NULL) { + next = p->ai_next; + free(p); + p = next; + } +} + +static const char *gai_strerror(int ret) { + switch(ret) { + case -1: + return "Out of memory"; + break; + + case -2: + return "Address lookup failed"; + break; + + default: + return "Unknown error"; + break; + } +} #endif #ifdef GIT_WIN32 @@ -386,53 +467,29 @@ static int ssl_setup(git_transport *t, const char *host) int gitno_connect(git_transport *t, const char *host, const char *port) { -#ifndef NO_ADDRINFO struct addrinfo *info = NULL, *p; -#else - int p; -#endif struct addrinfo hints; int ret; GIT_SOCKET s = INVALID_SOCKET; memset(&hints, 0x0, sizeof(struct addrinfo)); hints.ai_socktype = SOCK_STREAM; -#ifndef NO_ADDRINFO hints.ai_family = AF_UNSPEC; if ((ret = getaddrinfo(host, port, &hints, &info)) < 0) { giterr_set(GITERR_NET, "Failed to resolve address for %s: %s", host, gai_strerror(ret)); return -1; } -#else - hints.ai_hostent = gethostbyname(host); - hints.ai_servent = getservbyname(port, 0); - - if(hints.ai_servent) - hints.ai_port = hints.ai_servent->s_port; - else - hints.ai_port = atol(port); -#endif -#ifndef NO_ADDRINFO for (p = info; p != NULL; p = p->ai_next) { s = socket(p->ai_family, p->ai_socktype, p->ai_protocol); -#else - for (p = 0; hints.ai_hostent->h_addr_list[p] != NULL; p++) { - s = socket(hints.ai_hostent->h_addrtype, hints.ai_socktype, 0); -#endif + if (s == INVALID_SOCKET) { net_set_error("error creating socket"); break; } -#ifndef NO_ADDRINFO + if (connect(s, p->ai_addr, (socklen_t)p->ai_addrlen) == 0) -#else - memcpy(&hints.ai_addr.sin_addr, hints.ai_hostent->h_addr_list[p], hints.ai_hostent->h_length); - hints.ai_addr.sin_family = hints.ai_hostent->h_addrtype; - hints.ai_addr.sin_port = hints.ai_port; - if (connect(s, (struct sockaddr *)&hints.ai_addr, sizeof(struct sockaddr_in)) == 0) -#endif break; /* If we can't connect, try the next one */ @@ -441,20 +498,14 @@ int gitno_connect(git_transport *t, const char *host, const char *port) } /* Oops, we couldn't connect to any address */ - if (s == INVALID_SOCKET && -#ifndef NO_ADDRINFO - p == NULL) { -#else - hints.ai_hostent->h_addr_list[p] == NULL) { -#endif + if (s == INVALID_SOCKET && p == NULL) { giterr_set(GITERR_OS, "Failed to connect to %s", host); return -1; } t->socket = s; -#ifndef NO_ADDRINFO freeaddrinfo(info); -#endif + if (t->encrypt && ssl_setup(t, host) < 0) return -1; From b6423939d5a40dc282f0f58c175f63015c4c229f Mon Sep 17 00:00:00 2001 From: Chris Young Date: Wed, 20 Jun 2012 20:35:13 +0100 Subject: [PATCH 31/31] more getaddrinfo compatibility --- src/netops.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/netops.c b/src/netops.c index 67c631cd0..2161dfab9 100644 --- a/src/netops.c +++ b/src/netops.c @@ -66,13 +66,16 @@ static int getaddrinfo(const char *host, const char *port, struct addrinfo *hint else ainfo->ai_port = atol(port); - ainfo->ai_addrlen = ainfo->ai_hostent->h_length; memcpy(&ainfo->ai_addr_in.sin_addr, ainfo->ai_hostent->h_addr_list[0], ainfo->ai_hostent->h_length); - ainfo->ai_addr_in.sin_family = ainfo->ai_hostent->h_addrtype; + ainfo->ai_protocol = 0; + ainfo->ai_socktype = hints->ai_socktype; + ainfo->ai_family = ainfo->ai_hostent->h_addrtype; + ainfo->ai_addr_in.sin_family = ainfo->ai_family; ainfo->ai_addr_in.sin_port = ainfo->ai_port; ainfo->ai_addr = (struct addrinfo *)&ainfo->ai_addr_in; - + ainfo->ai_addrlen = sizeof(struct sockaddr_in); + *info = ainfo; if(ainfo->ai_hostent->h_addr_list[1] == NULL) { @@ -87,7 +90,6 @@ static int getaddrinfo(const char *host, const char *port, struct addrinfo *hint memcpy(&ai->ai_next, ainfo, sizeof(struct addrinfo)); memcpy(&ai->ai_next->ai_addr_in.sin_addr, ainfo->ai_hostent->h_addr_list[p], ainfo->ai_hostent->h_length); ai->ai_next->ai_addr = (struct addrinfo *)&ai->ai_next->ai_addr_in; - ainfo->ai_addrlen = ainfo->ai_hostent->h_length; ai = ai->ai_next; }