Commit ec250c6e18e56d12714f9010e1b15e5feec5f473

Andreas Ericsson 2008-11-23T22:37:55

Remove config.h and make fileops an internal API Since it doesn't make sense to make the disk access stuff portable *AND* public (that's a job for each application imo), we can take a shortcut and just support unixy stuff for now and get away with coding most of it as macros. Since we go with an internal API for starters and only provide higher-level API's to the libgit users, we'll be ok with this approach. Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

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
diff --git a/Makefile b/Makefile
index 71628d1..4ea481c 100644
--- a/Makefile
+++ b/Makefile
@@ -14,11 +14,6 @@ OBJS = $(patsubst %.c,%.o,$(SRC_C))
 HDRS = $(wildcard src/*.h)
 PUBLIC_HEADERS = $(wildcard src/git/*.h)
 HDRS += $(PUBLIC_HEADERS)
-CONFIG_H = src/git/config.h
-
-OBJS += src/os/$(OS).o
-HDRS += src/git/config.h
-HDRS += src/git/os/$(OS).h
 
 GIT_LIB = libgit2.a
 
@@ -42,7 +37,7 @@ apidocs:
 
 test: $(TEST_RUN)
 
-sparse: $(CONFIG_H)
+sparse:
 	sparse -DSPARSE_IS_RUNNING $(ALL_CFLAGS) $(SPARSE_FLAGS) $(SRC_C)
 
 install-headers: $(PUBLIC_HEADERS)
@@ -52,10 +47,6 @@ install-headers: $(PUBLIC_HEADERS)
 .c.o:
 	$(CC) $(ALL_CFLAGS) -c $< -o $@
 
-$(CONFIG_H): $(CONFIG_H).in
-	sed 's/@@OS@@/$(OS)/g' $< >$@+
-	mv $@+ $@
-
 $(OBJS): $(HDRS)
 $(GIT_LIB): $(OBJS)
 	rm -f $(LIB)
diff --git a/src/errors.h b/src/errors.h
index e323fc5..6909925 100644
--- a/src/errors.h
+++ b/src/errors.h
@@ -1,6 +1,7 @@
 #ifndef INCLUDE_errors_h__
 #define INCLUDE_errors_h__
 #include "git/errors.h"
+#include <stdlib.h>
 
 /* convenience functions */
 static inline int git_int_error(int code)
diff --git a/src/fileops.c b/src/fileops.c
new file mode 100644
index 0000000..1ca0fbb
--- /dev/null
+++ b/src/fileops.c
@@ -0,0 +1,49 @@
+#include "fileops.h"
+
+int gitfo_read(git_file fd, void *buf, size_t cnt)
+{
+	char *b = buf;
+	while (cnt) {
+		ssize_t r = read(fd, b, cnt);
+		if (r < 0) {
+			if (errno == EINTR || errno == EAGAIN)
+				continue;
+			return -1;
+		}
+		if (!r) {
+			errno = EPIPE;
+			return -1;
+		}
+		cnt -= r;
+		b += r;
+	}
+	return GIT_SUCCESS;
+}
+
+int gitfo_write(git_file fd, void *buf, size_t cnt)
+{
+	char *b = buf;
+	while (cnt) {
+		ssize_t r = write(fd, b, cnt);
+		if (r < 0) {
+			if (errno == EINTR || errno == EAGAIN)
+				continue;
+			return -1;
+		}
+		if (!r) {
+			errno = EPIPE;
+			return -1;
+		}
+		cnt -= r;
+		b += r;
+	}
+	return GIT_SUCCESS;
+}
+
+off_t gitfo_size(git_file fd)
+{
+	gitfo_statbuf sb;
+	if (fstat(fd, &sb))
+		return -1;
+	return sb.st_size;
+}
diff --git a/src/fileops.h b/src/fileops.h
new file mode 100644
index 0000000..32d6b91
--- /dev/null
+++ b/src/fileops.h
@@ -0,0 +1,37 @@
+/*
+ * fileops.h - OS agnostic disk io operations
+ *
+ * This header describes the strictly internal part of the api
+ */
+#ifndef INCLUDE_fileops_h__
+#define INCLUDE_fileops_h__
+
+/** Force 64 bit off_t size on POSIX. */
+#define _FILE_OFFSET_BITS 64
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <time.h>
+#include <stdlib.h>
+#include <string.h>
+#include "errors.h"
+
+typedef int git_file;
+typedef struct stat gitfo_statbuf;
+
+#define gitfo_open(path, flags) open(path, flags)
+#define gitfo_close(fd) close(fd)
+
+extern int gitfo_read(git_file fd, void *buf, size_t cnt);
+extern int gitfo_write(git_file fd, void *buf, size_t cnt);
+
+extern off_t gitfo_size(git_file fd);
+#define gitfo_lstat(path, buf) lstat(path, buf)
+#define gitfo_fstat(fd, buf) fstat(fd, buf)
+#define gitfo_stat(path, buf) stat(path, buf)
+#define gitfo_fsync(fd) fsync(fd)
+
+#endif /* INCLUDE_fileops_h__ */
diff --git a/src/git/common.h b/src/git/common.h
index 91f3b51..87f7f37 100644
--- a/src/git/common.h
+++ b/src/git/common.h
@@ -55,8 +55,6 @@
 /** Input does not exist in the scope searched. */
 #define GIT_ENOTFOUND (GIT_ERROR - 2)
 
-#include "git/config.h"
-
 GIT_BEGIN_DECL
 
 /** A revision traversal pool. */
diff --git a/src/git/config.h.in b/src/git/config.h.in
deleted file mode 100644
index 76d5067..0000000
--- a/src/git/config.h.in
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef INCLUDE_git_config_h__
-#define INCLUDE_git_config_h__
-
-#include "git/os/@@OS@@.h"
-
-#endif
diff --git a/src/git/odb.h b/src/git/odb.h
index 37eb3fa..ca98405 100644
--- a/src/git/odb.h
+++ b/src/git/odb.h
@@ -3,6 +3,7 @@
 
 #include "common.h"
 #include "oid.h"
+#include <stdlib.h>
 
 /**
  * @file git/odb.h
diff --git a/src/git/oid.h b/src/git/oid.h
index 8b9579b..9e90ed0 100644
--- a/src/git/oid.h
+++ b/src/git/oid.h
@@ -2,6 +2,7 @@
 #define INCLUDE_git_oid_h__
 
 #include "common.h"
+#include <string.h>
 
 /**
  * @file git/oid.h
diff --git a/src/git/os/unix.h b/src/git/os/unix.h
deleted file mode 100644
index 475fe13..0000000
--- a/src/git/os/unix.h
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
- *
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file.  (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING.  If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef INCLUDE_git_os_abstraction_h__
-#define INCLUDE_git_os_abstraction_h__
-
-/** Force 64 bit off_t size on POSIX. */
-#define _FILE_OFFSET_BITS 64
-
-#include <errno.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <time.h>
-#include <stdlib.h>
-#include <string.h>
-
-/**
- * @file git/os/unix.h
- * @brief Portable operating system abstractions
- * @defgroup git_os_abstraction Portable operating system abstractions
- * @ingroup Git
- * @{
- */
-GIT_BEGIN_DECL
-
-/** Descriptor to an open file in the filesystem. */
-typedef int git_file;
-
-/**
- * Open a file by path name.
- *
- * Valid flags are:
- * - O_CREAT: Create the file if it does not yet exist.
- * - O_RDONLY: Open the file for reading.
- * - O_WRONLY: Open the file for writing.
- * - O_RDWR: Open the file for both reading and writing.
- *
- * @param out descriptor storage to populate on success.
- * @param path path name of the file to open.
- * @param flags bitmask of access requested to the file.
- * @return
- * - On success, GIT_SUCCESS.
- * - On error, <0.
- */
-GIT_EXTERN(int) git_fopen(git_file *out, const char *path, int flags);
-
-/**
- * Read from an open file descriptor at the current position.
- *
- * Exactly the requested number of bytes is read.  If the stream
- * ends early, an error is indicated, and the exact number of bytes
- * transferred is unspecified.
- *
- * @param fd open descriptor.
- * @param buf buffer to store the read data into.
- * @param cnt number of bytes to transfer.
- * @return
- * - On success, GIT_SUCCESS.
- * - On error, <0.
- */
-GIT_EXTERN(int) git_fread(git_file fd, void *buf, size_t cnt);
-
-/**
- * Write to an open file descriptor at the current position.
- *
- * Exactly the requested number of bytes is written.  If the stream
- * ends early, an error is indicated, and the exact number of bytes
- * transferred is unspecified.
- *
- * @param fd open descriptor.
- * @param buf buffer to write data from.
- * @param cnt number of bytes to transfer.
- * @return
- * - On success, GIT_SUCCESS.
- * - On error, <0.
- */
-GIT_EXTERN(int) git_fwrite(git_file fd, void *buf, size_t cnt);
-
-/**
- * Get the current size of an open file.
- * @param fd open descriptor.
- * @return
- * - On success, >= 0, indicating the file size in bytes.
- * - On error, <0.
- */
-GIT_EXTERN(off_t) git_fsize(git_file fd);
-
-/**
- * Close an open file descriptor.
- * @param fd descriptor to close.
- * @return
- * - On success, GIT_SUCCESS.
- * - On error, <0.
- */
-#define git_fclose(fd) close(fd)
-
-/** @} */
-GIT_END_DECL
-#endif
diff --git a/src/os/unix.c b/src/os/unix.c
deleted file mode 100644
index 8a20884..0000000
--- a/src/os/unix.c
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
- *
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file.  (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING.  If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "git/common.h"
-
-int git_fopen(git_file *out, const char *path, int flags)
-{
-	int r = open(path, flags);
-	if (r < 0)
-		return -1;
-	*out = r;
-	return GIT_SUCCESS;
-}
-
-int git_fread(git_file fd, void *buf, size_t cnt)
-{
-	char *b = buf;
-	while (cnt) {
-		ssize_t r = read(fd, b, cnt);
-		if (r < 0) {
-			if (errno == EINTR || errno == EAGAIN)
-				continue;
-			return -1;
-		}
-		if (!r) {
-			errno = EPIPE;
-			return -1;
-		}
-		cnt -= r;
-		b += r;
-	}
-	return GIT_SUCCESS;
-}
-
-int git_fwrite(git_file fd, void *buf, size_t cnt)
-{
-	char *b = buf;
-	while (cnt) {
-		ssize_t r = write(fd, b, cnt);
-		if (r < 0) {
-			if (errno == EINTR || errno == EAGAIN)
-				continue;
-			return -1;
-		}
-		if (!r) {
-			errno = EPIPE;
-			return -1;
-		}
-		cnt -= r;
-		b += r;
-	}
-	return GIT_SUCCESS;
-}
-
-off_t git_fsize(git_file fd)
-{
-	struct stat sb;
-	if (fstat(fd, &sb))
-		return -1;
-	return sb.st_size;
-}