]> git.proxmox.com Git - libgit2.git/blobdiff - examples/network/index-pack.c
New upstream version 0.28.4+dfsg.1
[libgit2.git] / examples / network / index-pack.c
index 4d3dc84d66ae365b400d8ce6e7d3a3fa2079996d..128c7ebf5a25d9d761ce8fb461aa85244257668f 100644 (file)
@@ -5,14 +5,27 @@
 #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
-// the indexing to finish in a worker thread
+/*
+ * This could be run in the main loop whilst the application waits for
+ * the indexing to finish in a worker thread
+ */
 static int index_cb(const git_transfer_progress *stats, void *data)
 {
-       data = data;
+       (void)data;
        printf("\rProcessing %d of %d", stats->indexed_objects, stats->total_objects);
 
        return 0;
@@ -20,20 +33,22 @@ static int index_cb(const git_transfer_progress *stats, void *data)
 
 int index_pack(git_repository *repo, int argc, char **argv)
 {
-       git_indexer_stream *idx;
+       git_indexer *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];
 
-       repo = repo;
+       (void)repo;
+
        if (argc < 2) {
-               fprintf(stderr, "I need a packfile\n");
+               fprintf(stderr, "usage: %s index-pack <packfile>\n", argv[-1]);
                return EXIT_FAILURE;
        }
 
-       if (git_indexer_stream_new(&idx, ".", NULL, NULL) < 0) {
+       if (git_indexer_new(&idx, ".", 0, NULL, NULL) < 0) {
                puts("bad idx");
                return -1;
        }
@@ -48,7 +63,7 @@ int index_pack(git_repository *repo, int argc, char **argv)
                if (read_bytes < 0)
                        break;
 
-               if ((error = git_indexer_stream_add(idx, buf, read_bytes, &stats)) < 0)
+               if ((error = git_indexer_append(idx, buf, read_bytes, &stats)) < 0)
                        goto cleanup;
 
                index_cb(&stats, NULL);
@@ -60,16 +75,16 @@ int index_pack(git_repository *repo, int argc, char **argv)
                goto cleanup;
        }
 
-       if ((error = git_indexer_stream_finalize(idx, &stats)) < 0)
+       if ((error = git_indexer_commit(idx, &stats)) < 0)
                goto cleanup;
 
        printf("\rIndexing %d of %d\n", stats.indexed_objects, stats.total_objects);
 
-       git_oid_fmt(hash, git_indexer_stream_hash(idx));
+       git_oid_fmt(hash, git_indexer_hash(idx));
        puts(hash);
 
  cleanup:
        close(fd);
-       git_indexer_stream_free(idx);
+       git_indexer_free(idx);
        return error;
 }