Commit 2ae052d1b1574d1a4de402c91ebb98f061c997d4

Vicent Marti 2012-06-22T20:48:50

Merge branch 'pull-req' of https://github.com/chris-y/libgit2 into amigaos

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6db1826..a8e646d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -21,13 +21,30 @@ 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}")
 
+IF (AMIGA)
+	# Default AmigaOS to use the PowerPC SHA1
+	SET(SHA1_TYPE "ppc")
+ENDIF()
+
 # 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 src/ppc/*.S)
+ELSE ()
+	SET (SRC_SHA1)
+ENDIF()
+
 IF (NOT WIN32)
 	FIND_PACKAGE(ZLIB)
+	IF (CMAKE_SYSTEM_NAME STREQUAL "AmigaOS")
+		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)
@@ -115,12 +132,15 @@ IF (WIN32 AND NOT CYGWIN)
 	FILE(GLOB SRC src/*.c src/transports/*.c src/xdiff/*.c src/win32/*.c src/compat/*.c)
 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 ()
 
 # 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)
diff --git a/examples/network/Makefile b/examples/network/Makefile
index c21869a..298b1dc 100644
--- a/examples/network/Makefile
+++ b/examples/network/Makefile
@@ -2,7 +2,7 @@ default: all
 
 CC = gcc
 CFLAGS += -g
-CFLAGS += -I../../include -L../../ -lgit2 -lpthread
+CFLAGS += -I../../include -L../../build -lgit2 -lpthread
 
 OBJECTS = \
   git2.o \
diff --git a/examples/network/fetch.c b/examples/network/fetch.c
index 8dcb81b..d275212 100644
--- a/examples/network/fetch.c
+++ b/examples/network/fetch.c
@@ -91,6 +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);
+
 	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 0e93798..1af045c 100644
--- a/include/git2/common.h
+++ b/include/git2/common.h
@@ -55,6 +55,10 @@
 #define GIT_WIN32 1
 #endif
 
+#ifdef __amigaos4__
+#include <netinet/in.h>
+#endif
+
 /**
  * @file git2/common.h
  * @brief Git common platform definitions
diff --git a/include/git2/errors.h b/include/git2/errors.h
index ccbc9fc..b4809fe 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;
diff --git a/include/git2/types.h b/include/git2/types.h
index b4b48af..6919030 100644
--- a/include/git2/types.h
+++ b/include/git2/types.h
@@ -32,6 +32,9 @@ GIT_BEGIN_DECL
  * stat() functions, for all platforms.
  */
 #include <sys/types.h>
+#ifdef __amigaos4__
+#include <stdint.h>
+#endif
 
 #if defined(_MSC_VER)
 
diff --git a/src/amiga/map.c b/src/amiga/map.c
new file mode 100755
index 0000000..2fb065c
--- /dev/null
+++ b/src/amiga/map.c
@@ -0,0 +1,51 @@
+/*
+ * 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 <git2/common.h>
+
+#ifndef GIT_WIN32
+
+#include "posix.h"
+#include "map.h"
+#include <errno.h>
+
+int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset)
+{
+	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)) {
+		giterr_set(GITERR_OS, "Trying to map shared-writeable");
+		return -1;
+	}
+
+	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/indexer.c b/src/indexer.c
index 5ae66c9..565d9ea 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -365,11 +365,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/map.h b/src/map.h
index 96d8795..6ce6d36 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/mwindow.c b/src/mwindow.c
index 57adabd..74fbf78 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/netops.c b/src/netops.c
index 3255474..0342d7f 100644
--- a/src/netops.c
+++ b/src/netops.c
@@ -32,6 +32,99 @@
 #include "buffer.h"
 #include "transport.h"
 
+#ifdef NO_ADDRINFO
+struct addrinfo {
+	struct hostent *ai_hostent;
+	struct servent *ai_servent;
+	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);
+
+
+	memcpy(&ainfo->ai_addr_in.sin_addr, ainfo->ai_hostent->h_addr_list[0], ainfo->ai_hostent->h_length);
+	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) {
+		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;
+		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
 static void net_set_error(const char *str)
 {
@@ -381,8 +474,8 @@ int gitno_connect(git_transport *t, const char *host, const char *port)
 	GIT_SOCKET s = INVALID_SOCKET;
 
 	memset(&hints, 0x0, sizeof(struct addrinfo));
-	hints.ai_family = AF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
+	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));
@@ -391,6 +484,7 @@ int gitno_connect(git_transport *t, const char *host, const char *port)
 
 	for (p = info; p != NULL; p = p->ai_next) {
 		s = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
+
 		if (s == INVALID_SOCKET) {
 			net_set_error("error creating socket");
 			break;
diff --git a/src/pack.c b/src/pack.c
index 0db1069..9b5e0e1 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -262,7 +262,7 @@ int git_packfile_unpack_header(
 	if (base == NULL)
 		return GIT_EBUFS;
 
-	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/pool.c b/src/pool.c
index 641292d..63bf09c 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)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 5799c04..d423b7e 100644
--- a/src/posix.h
+++ b/src/posix.h
@@ -83,6 +83,16 @@ extern int p_gettimeofday(struct timeval *tv, struct timezone *tz);
 #	include "unix/posix.h"
 #endif
 
+#ifndef NO_READDIR_R
 #define p_readdir_r(d,e,r) readdir_r(d,e,r)
+#else
+#include <dirent.h>
+GIT_INLINE(int) p_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
+{
+	GIT_UNUSED(entry);
+	*result = readdir(dirp);
+	return 0;
+}
+#endif
 
 #endif
diff --git a/src/unix/map.c b/src/unix/map.c
index 772f4e2..9dcae58 100644
--- a/src/unix/map.c
+++ b/src/unix/map.c
@@ -33,6 +33,7 @@ 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);
+
 	if (!out->data || out->data == MAP_FAILED) {
 		giterr_set(GITERR_OS, "Failed to mmap. Could not write data");
 		return -1;
@@ -47,6 +48,7 @@ int p_munmap(git_map *map)
 {
 	assert(map != NULL);
 	munmap(map->data, map->len);
+
 	return 0;
 }
 
diff --git a/src/unix/posix.h b/src/unix/posix.h
index 48b4929..83fd8a1 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 <fnmatch.h>
 #	define p_fnmatch(p, s, f) fnmatch(p, s, f)
 #else