Tidy up the readloose tests Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> 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
diff --git a/tests/t0201-readloose.c b/tests/t0201-readloose.c
index 1b61137..4f6eade 100644
--- a/tests/t0201-readloose.c
+++ b/tests/t0201-readloose.c
@@ -1,14 +1,15 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
#include "test_lib.h"
#include <git/odb.h>
#include "fileops.h"
+/*
+ * read loose objects from the object directory. The objects are
+ * written using the current object encoding, using an zlib
+ * compression level of Z_DEFAULT_COMPRESSION (6). See also
+ * t0202-readloose.c.
+ */
+
static char *odb_dir = "test-objects";
typedef struct object_data {
@@ -548,7 +549,7 @@ static int write_object_data(char *file, void *data, size_t len)
static int write_object_files(object_data *d)
{
- if (mkdir(odb_dir, 0755) < 0) {
+ if (gitfo_mkdir(odb_dir, 0755) < 0) {
if (errno == EEXIST) {
fprintf(stderr, "odb directory \"%s\" already exists!\n", odb_dir);
return -1;
@@ -557,7 +558,7 @@ static int write_object_files(object_data *d)
return -1;
}
- if ((mkdir(d->dir, 0755) < 0) && (errno != EEXIST)) {
+ if ((gitfo_mkdir(d->dir, 0755) < 0) && (errno != EEXIST)) {
fprintf(stderr, "can't make object directory \"%s\"\n", d->dir);
return -1;
}
@@ -571,16 +572,16 @@ static int write_object_files(object_data *d)
static int remove_object_files(object_data *d)
{
- if (unlink(d->file) < 0) {
+ if (gitfo_unlink(d->file) < 0) {
fprintf(stderr, "can't delete object file \"%s\"\n", d->file);
return -1;
}
- if ((rmdir(d->dir) < 0) && (errno != ENOTEMPTY)) {
+ if ((gitfo_rmdir(d->dir) < 0) && (errno != ENOTEMPTY)) {
fprintf(stderr, "can't remove object directory \"%s\"\n", d->dir);
return -1;
}
- if (rmdir(odb_dir) < 0) {
+ if (gitfo_rmdir(odb_dir) < 0) {
fprintf(stderr, "can't remove odb directory \"%s\"\n", odb_dir);
return -1;
}
diff --git a/tests/t0202-readloose.c b/tests/t0202-readloose.c
index c4c1992..ae31ebb 100644
--- a/tests/t0202-readloose.c
+++ b/tests/t0202-readloose.c
@@ -1,14 +1,21 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
#include "test_lib.h"
#include <git/odb.h>
#include "fileops.h"
+/*
+ * read loose objects from the object directory. The objects are
+ * written using the "in-pack" object encoding, using an zlib
+ * compression level of Z_BEST_SPEED (1). See also
+ * t0201-readloose.c.
+ *
+ * Note that the tree and tag objects are not actually stored in
+ * the "in-pack" format. This is due to a bug in git v1.5.2, since
+ * git-write-tree and git-mktag did not call git_default_config()
+ * and, therefore, did not honor the "core.legacyheaders" config
+ * variable.
+ */
+
static char *odb_dir = "test-objects";
typedef struct object_data {
@@ -543,7 +550,7 @@ static int write_object_data(char *file, void *data, size_t len)
static int write_object_files(object_data *d)
{
- if (mkdir(odb_dir, 0755) < 0) {
+ if (gitfo_mkdir(odb_dir, 0755) < 0) {
if (errno == EEXIST) {
fprintf(stderr, "odb directory \"%s\" already exists!\n", odb_dir);
return -1;
@@ -552,7 +559,7 @@ static int write_object_files(object_data *d)
return -1;
}
- if ((mkdir(d->dir, 0755) < 0) && (errno != EEXIST)) {
+ if ((gitfo_mkdir(d->dir, 0755) < 0) && (errno != EEXIST)) {
fprintf(stderr, "can't make object directory \"%s\"\n", d->dir);
return -1;
}
@@ -566,16 +573,16 @@ static int write_object_files(object_data *d)
static int remove_object_files(object_data *d)
{
- if (unlink(d->file) < 0) {
+ if (gitfo_unlink(d->file) < 0) {
fprintf(stderr, "can't delete object file \"%s\"\n", d->file);
return -1;
}
- if ((rmdir(d->dir) < 0) && (errno != ENOTEMPTY)) {
+ if ((gitfo_rmdir(d->dir) < 0) && (errno != ENOTEMPTY)) {
fprintf(stderr, "can't remove object directory \"%s\"\n", d->dir);
return -1;
}
- if (rmdir(odb_dir) < 0) {
+ if (gitfo_rmdir(odb_dir) < 0) {
fprintf(stderr, "can't remove odb directory \"%s\"\n", odb_dir);
return -1;
}