update examples to work on windows
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
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 47533a2..e9972fd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -288,7 +288,11 @@ ENDIF ()
IF (BUILD_EXAMPLES)
FILE(GLOB_RECURSE EXAMPLE_SRC examples/network/*.c)
ADD_EXECUTABLE(cgit2 ${EXAMPLE_SRC})
- TARGET_LINK_LIBRARIES(cgit2 git2 pthread)
+ IF(WIN32)
+ TARGET_LINK_LIBRARIES(cgit2 git2)
+ ELSE()
+ TARGET_LINK_LIBRARIES(cgit2 git2 pthread)
+ ENDIF()
ADD_EXECUTABLE(git-diff examples/diff.c)
TARGET_LINK_LIBRARIES(git-diff git2)
diff --git a/examples/network/clone.c b/examples/network/clone.c
index 9b323ff..63072ee 100644
--- a/examples/network/clone.c
+++ b/examples/network/clone.c
@@ -4,8 +4,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <pthread.h>
-#include <unistd.h>
+#ifndef _WIN32
+# include <pthread.h>
+# include <unistd.h>
+#endif
/* Shamelessly borrowed from http://stackoverflow.com/questions/3417837/ */
#ifdef UNUSED
@@ -94,7 +96,7 @@ int do_clone(git_repository *repo, int argc, char **argv)
}
// Set up options
- checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
+ checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
checkout_opts.progress_cb = checkout_progress;
checkout_opts.progress_payload = &pd;
clone_opts.checkout_opts = checkout_opts;
diff --git a/examples/network/fetch.c b/examples/network/fetch.c
index 416788b..d5caad4 100644
--- a/examples/network/fetch.c
+++ b/examples/network/fetch.c
@@ -3,8 +3,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <pthread.h>
-#include <unistd.h>
+#ifndef _WIN32
+# include <pthread.h>
+# include <unistd.h>
+#endif
struct dl_data {
git_remote *remote;
@@ -68,9 +70,11 @@ int fetch(git_repository *repo, int argc, char **argv)
{
git_remote *remote = NULL;
const git_transfer_progress *stats;
- pthread_t worker;
struct dl_data data;
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
+#ifndef _WIN32
+ pthread_t worker;
+#endif
argc = argc;
// Figure out whether it's a named remote or a URL
@@ -92,6 +96,9 @@ int fetch(git_repository *repo, int argc, char **argv)
stats = git_remote_stats(remote);
+#ifdef _WIN32
+ download(&data);
+#else
pthread_create(&worker, NULL, download, &data);
// Loop while the worker thread is still running. Here we show processed
@@ -111,6 +118,8 @@ int fetch(git_repository *repo, int argc, char **argv)
goto on_error;
pthread_join(worker, NULL);
+#endif
+
printf("\rReceived %d/%d objects in %zu bytes\n",
stats->indexed_objects, stats->total_objects, stats->received_bytes);
diff --git a/examples/network/index-pack.c b/examples/network/index-pack.c
index 4d3dc84..3fc4f32 100644
--- a/examples/network/index-pack.c
+++ b/examples/network/index-pack.c
@@ -5,7 +5,18 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
-#include <unistd.h>
+#ifdef _WIN32
+# include <io.h>
+# include <Windows.h>
+
+# define open _open
+# define read _read
+# define close _close
+
+#define ssize_t unsigned int
+#else
+# include <unistd.h>
+#endif
#include "common.h"
// This could be run in the main loop whilst the application waits for
@@ -22,8 +33,9 @@ int index_pack(git_repository *repo, int argc, char **argv)
{
git_indexer_stream *idx;
git_transfer_progress stats = {0, 0};
- int error, fd;
+ int error;
char hash[GIT_OID_HEXSZ + 1] = {0};
+ int fd;
ssize_t read_bytes;
char buf[512];