Fix various cross-platform build issues This fixes a number of warnings and problems with cross-platform builds. Among other things, it's not safe to name a member of a structure "strcmp" because that may be #defined.
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
diff --git a/examples/network/Makefile b/examples/network/Makefile
index 835be24..ef3cec6 100644
--- a/examples/network/Makefile
+++ b/examples/network/Makefile
@@ -2,7 +2,8 @@ default: all
CC = gcc
CFLAGS += -g
-CFLAGS += -I../../include -L../../build -L../.. -lgit2 -lpthread
+CFLAGS += -I../../include
+LDFLAGS += -L../../build -L../.. -lgit2 -lpthread
OBJECTS = \
git2.o \
@@ -12,4 +13,4 @@ OBJECTS = \
index-pack.o
all: $(OBJECTS)
- $(CC) $(CFLAGS) -o git2 $(OBJECTS)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o git2 $(OBJECTS)
diff --git a/examples/network/clone.c b/examples/network/clone.c
index 7916001..30a4944 100644
--- a/examples/network/clone.c
+++ b/examples/network/clone.c
@@ -22,12 +22,14 @@ static void print_progress(const progress_data *pd)
? (100 * pd->completed_steps) / pd->total_steps
: 0.f;
int kbytes = pd->fetch_progress.received_bytes / 1024;
- printf("net %3d%% (%4d kb, %5d/%5d) / idx %3d%% (%5d/%5d) / chk %3d%% (%4lu/%4lu) %s\n",
- network_percent, kbytes,
- pd->fetch_progress.received_objects, pd->fetch_progress.total_objects,
- index_percent, pd->fetch_progress.indexed_objects, pd->fetch_progress.total_objects,
- checkout_percent, pd->completed_steps, pd->total_steps,
- pd->path);
+
+ printf("net %3d%% (%4d kb, %5d/%5d) / idx %3d%% (%5d/%5d) / chk %3d%% (%4" PRIuZ "/%4" PRIuZ ") %s\n",
+ network_percent, kbytes,
+ pd->fetch_progress.received_objects, pd->fetch_progress.total_objects,
+ index_percent, pd->fetch_progress.indexed_objects, pd->fetch_progress.total_objects,
+ checkout_percent,
+ pd->completed_steps, pd->total_steps,
+ pd->path);
}
static void fetch_progress(const git_transfer_progress *stats, void *payload)
@@ -47,13 +49,15 @@ static void checkout_progress(const char *path, size_t cur, size_t tot, void *pa
int do_clone(git_repository *repo, int argc, char **argv)
{
- progress_data pd = {0};
+ progress_data pd;
git_repository *cloned_repo = NULL;
- git_checkout_opts checkout_opts = {0};
+ git_checkout_opts checkout_opts;
const char *url = argv[1];
const char *path = argv[2];
int error;
+ (void)repo; // unused
+
// Validate args
if (argc < 3) {
printf ("USAGE: %s <url> <path>\n", argv[0]);
@@ -61,8 +65,10 @@ int do_clone(git_repository *repo, int argc, char **argv)
}
// Set up options
- checkout_opts.checkout_strategy = GIT_CHECKOUT_CREATE_MISSING;
+ memset(&checkout_opts, 0, sizeof(checkout_opts));
+ checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
checkout_opts.progress_cb = checkout_progress;
+ memset(&pd, 0, sizeof(pd));
checkout_opts.progress_payload = &pd;
// Do the clone
diff --git a/examples/network/common.h b/examples/network/common.h
index c82eaa1..a4cfa1a 100644
--- a/examples/network/common.h
+++ b/examples/network/common.h
@@ -12,4 +12,13 @@ int fetch(git_repository *repo, int argc, char **argv);
int index_pack(git_repository *repo, int argc, char **argv);
int do_clone(git_repository *repo, int argc, char **argv);
+#ifndef PRIuZ
+/* Define the printf format specifer to use for size_t output */
+#if defined(_MSC_VER) || defined(__MINGW32__)
+# define PRIuZ "Iu"
+#else
+# define PRIuZ "zu"
+#endif
+#endif
+
#endif /* __COMMON_H__ */
diff --git a/examples/network/fetch.c b/examples/network/fetch.c
index 496498e..9d1404a 100644
--- a/examples/network/fetch.c
+++ b/examples/network/fetch.c
@@ -103,9 +103,9 @@ int fetch(git_repository *repo, int argc, char **argv)
usleep(10000);
if (stats->total_objects > 0)
- printf("Received %d/%d objects (%d) in %d bytes\r",
+ printf("Received %d/%d objects (%d) in %" PRIuZ " bytes\r",
stats->received_objects, stats->total_objects,
- stats->indexed_objects, stats->received_bytes);
+ stats->indexed_objects, stats->received_bytes);
} while (!data.finished);
if (data.ret < 0)
diff --git a/include/git2/checkout.h b/include/git2/checkout.h
index a9314c2..d444450 100644
--- a/include/git2/checkout.h
+++ b/include/git2/checkout.h
@@ -124,16 +124,20 @@ typedef enum {
/** Only update existing files, don't create new ones */
GIT_CHECKOUT_UPDATE_ONLY = (1u << 6),
- /** Allow checkout to skip unmerged files */
+ /**
+ * THE FOLLOWING OPTIONS ARE NOT YET IMPLEMENTED
+ */
+
+ /** Allow checkout to skip unmerged files (NOT IMPLEMENTED) */
GIT_CHECKOUT_SKIP_UNMERGED = (1u << 10),
- /** For unmerged files, checkout stage 2 from index */
+ /** For unmerged files, checkout stage 2 from index (NOT IMPLEMENTED) */
GIT_CHECKOUT_USE_OURS = (1u << 11),
- /** For unmerged files, checkout stage 3 from index */
+ /** For unmerged files, checkout stage 3 from index (NOT IMPLEMENTED) */
GIT_CHECKOUT_USE_THEIRS = (1u << 12),
- /** Recursively checkout submodule with same options */
+ /** Recursively checkout submodules with same options (NOT IMPLEMENTED) */
GIT_CHECKOUT_UPDATE_SUBMODULES = (1u << 16),
- /** Recursively checkout submodules only if HEAD moved in super repo */
+ /** Recursively checkout submodules if HEAD moved in super repo (NOT IMPLEMENTED) */
GIT_CHECKOUT_UPDATE_SUBMODULES_IF_CHANGED = (1u << 17),
} git_checkout_strategy_t;
diff --git a/src/checkout.c b/src/checkout.c
index 2bad065..8d164cf 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -449,7 +449,7 @@ static int checkout_get_actions(
if ((diff->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0 &&
!hiter->ignore_case &&
(error = git_iterator_spoolandsort(
- &hiter, hiter, diff->entrycmp, true)) < 0)
+ &hiter, hiter, diff->entrycomp, true)) < 0)
goto fail;
if ((error = git_iterator_current(hiter, &he)) < 0)
@@ -470,8 +470,8 @@ static int checkout_get_actions(
/* try to track HEAD entries parallel to deltas */
while (he) {
cmp = S_ISDIR(delta->new_file.mode) ?
- diff->prefixcmp(he->path, delta->new_file.path) :
- diff->strcmp(he->path, delta->old_file.path);
+ diff->pfxcomp(he->path, delta->new_file.path) :
+ diff->strcomp(he->path, delta->old_file.path);
if (cmp >= 0)
break;
if (git_iterator_advance(hiter, &he) < 0)
diff --git a/src/diff.c b/src/diff.c
index ea19d47..6f48d72 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -528,7 +528,7 @@ static bool entry_is_prefixed(
{
size_t pathlen;
- if (!prefix_item || diff->prefixcmp(prefix_item->path, item->path))
+ if (!prefix_item || diff->pfxcomp(prefix_item->path, item->path))
return false;
pathlen = strlen(item->path);
@@ -551,17 +551,17 @@ static int diff_list_init_from_iterators(
if (!old_iter->ignore_case && !new_iter->ignore_case) {
diff->opts.flags &= ~GIT_DIFF_DELTAS_ARE_ICASE;
- diff->strcmp = strcmp;
- diff->strncmp = strncmp;
- diff->prefixcmp = git__prefixcmp;
- diff->entrycmp = git_index_entry__cmp;
+ diff->strcomp = strcmp;
+ diff->strncomp = strncmp;
+ diff->pfxcomp = git__prefixcmp;
+ diff->entrycomp = git_index_entry__cmp;
} else {
diff->opts.flags |= GIT_DIFF_DELTAS_ARE_ICASE;
- diff->strcmp = strcasecmp;
- diff->strncmp = strncasecmp;
- diff->prefixcmp = git__prefixcmp_icase;
- diff->entrycmp = git_index_entry__cmp_icase;
+ diff->strcomp = strcasecmp;
+ diff->strncomp = strncasecmp;
+ diff->pfxcomp = git__prefixcmp_icase;
+ diff->entrycomp = git_index_entry__cmp_icase;
}
return 0;
@@ -592,12 +592,12 @@ static int diff_from_iterators(
* merge join to the other iterator that is icase sorted */
if (!old_iter->ignore_case &&
git_iterator_spoolandsort(
- &old_iter, old_iter, diff->entrycmp, true) < 0)
+ &old_iter, old_iter, diff->entrycomp, true) < 0)
goto fail;
if (!new_iter->ignore_case &&
git_iterator_spoolandsort(
- &new_iter, new_iter, diff->entrycmp, true) < 0)
+ &new_iter, new_iter, diff->entrycomp, true) < 0)
goto fail;
}
@@ -609,7 +609,7 @@ static int diff_from_iterators(
while (oitem || nitem) {
/* create DELETED records for old items not matched in new */
- if (oitem && (!nitem || diff->entrycmp(oitem, nitem) < 0)) {
+ if (oitem && (!nitem || diff->entrycomp(oitem, nitem) < 0)) {
if (diff_delta__from_one(diff, GIT_DELTA_DELETED, oitem) < 0)
goto fail;
@@ -634,12 +634,12 @@ static int diff_from_iterators(
/* create ADDED, TRACKED, or IGNORED records for new items not
* matched in old (and/or descend into directories as needed)
*/
- else if (nitem && (!oitem || diff->entrycmp(oitem, nitem) > 0)) {
+ else if (nitem && (!oitem || diff->entrycomp(oitem, nitem) > 0)) {
git_delta_t delta_type = GIT_DELTA_UNTRACKED;
/* check if contained in ignored parent directory */
if (git_buf_len(&ignore_prefix) &&
- diff->prefixcmp(nitem->path, git_buf_cstr(&ignore_prefix)) == 0)
+ diff->pfxcomp(nitem->path, git_buf_cstr(&ignore_prefix)) == 0)
delta_type = GIT_DELTA_IGNORED;
if (S_ISDIR(nitem->mode)) {
@@ -730,7 +730,7 @@ static int diff_from_iterators(
* (or ADDED and DELETED pair if type changed)
*/
else {
- assert(oitem && nitem && diff->entrycmp(oitem, nitem) == 0);
+ assert(oitem && nitem && diff->entrycomp(oitem, nitem) == 0);
if (maybe_modified(old_iter, oitem, new_iter, nitem, diff) < 0 ||
git_iterator_advance(old_iter, &oitem) < 0 ||
diff --git a/src/diff.h b/src/diff.h
index e9d8fd5..1e3be75 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -42,10 +42,10 @@ struct git_diff_list {
git_iterator_type_t new_src;
uint32_t diffcaps;
- int (*strcmp)(const char *, const char *);
- int (*strncmp)(const char *, const char *, size_t);
- int (*prefixcmp)(const char *str, const char *pfx);
- int (*entrycmp)(const void *a, const void *b);
+ int (*strcomp)(const char *, const char *);
+ int (*strncomp)(const char *, const char *, size_t);
+ int (*pfxcomp)(const char *str, const char *pfx);
+ int (*entrycomp)(const void *a, const void *b);
};
extern void git_diff__cleanup_modes(
diff --git a/src/diff_output.c b/src/diff_output.c
index 2f61540..46a9e02 100644
--- a/src/diff_output.c
+++ b/src/diff_output.c
@@ -120,7 +120,7 @@ static int diff_delta_is_binary_by_attr(
return -1;
mirror_new = (delta->new_file.path == delta->old_file.path ||
- strcmp(delta->new_file.path, delta->old_file.path) == 0);
+ ctxt->diff->strcomp(delta->new_file.path, delta->old_file.path) == 0);
if (mirror_new)
delta->new_file.flags |= (delta->old_file.flags & KNOWN_BINARY_FLAGS);
else
@@ -1002,7 +1002,7 @@ static int print_compact(
git_buf_clear(pi->buf);
if (delta->old_file.path != delta->new_file.path &&
- strcmp(delta->old_file.path,delta->new_file.path) != 0)
+ pi->diff->strcomp(delta->old_file.path,delta->new_file.path) != 0)
git_buf_printf(pi->buf, "%c\t%s%c -> %s%c\n", code,
delta->old_file.path, old_suffix, delta->new_file.path, new_suffix);
else if (delta->old_file.mode != delta->new_file.mode &&