diff --git a/examples/network/Makefile b/examples/network/Makefile index 835be24cc..ef3cec659 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 791600171..30a4944c2 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 \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 c82eaa1c8..a4cfa1a7e 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 496498e8c..9d1404ab4 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 a9314c2cb..d444450f3 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 2bad06501..8d164cfca 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 ea19d4799..6f48d72a2 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 e9d8fd5a7..1e3be7593 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 2f61540ff..46a9e02bf 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 &&