summaryrefslogtreecommitdiff
path: root/examples/network
diff options
context:
space:
mode:
Diffstat (limited to 'examples/network')
-rw-r--r--examples/network/Makefile5
-rw-r--r--examples/network/clone.c24
-rw-r--r--examples/network/common.h9
-rw-r--r--examples/network/fetch.c4
4 files changed, 29 insertions, 13 deletions
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 <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 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)