Merge pull request #791 from carlosmn/index-path indexer: don't use '/objects/pack/' unconditionally
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
diff --git a/examples/network/Makefile b/examples/network/Makefile
index 298b1dc..9afd49e 100644
--- a/examples/network/Makefile
+++ b/examples/network/Makefile
@@ -2,7 +2,7 @@ default: all
CC = gcc
CFLAGS += -g
-CFLAGS += -I../../include -L../../build -lgit2 -lpthread
+CFLAGS += -I../../include -L../../build -L../.. -lgit2 -lpthread
OBJECTS = \
git2.o \
diff --git a/examples/network/index-pack.c b/examples/network/index-pack.c
index 5824fc5..ef5a359 100644
--- a/examples/network/index-pack.c
+++ b/examples/network/index-pack.c
@@ -25,7 +25,7 @@ int index_pack(git_repository *repo, int argc, char **argv)
return EXIT_FAILURE;
}
- if (git_indexer_stream_new(&idx, ".git") < 0) {
+ if (git_indexer_stream_new(&idx, ".") < 0) {
puts("bad idx");
return -1;
}
diff --git a/include/git2/indexer.h b/include/git2/indexer.h
index 6263777..d300ba0 100644
--- a/include/git2/indexer.h
+++ b/include/git2/indexer.h
@@ -29,9 +29,9 @@ typedef struct git_indexer_stream git_indexer_stream;
* Create a new streaming indexer instance
*
* @param out where to store the indexer instance
- * @param path to the gitdir (metadata directory)
+ * @param path to the directory where the packfile should be stored
*/
-GIT_EXTERN(int) git_indexer_stream_new(git_indexer_stream **out, const char *gitdir);
+GIT_EXTERN(int) git_indexer_stream_new(git_indexer_stream **out, const char *path);
/**
* Add data to the indexer
diff --git a/src/fetch.c b/src/fetch.c
index 96b263f..6032848 100644
--- a/src/fetch.c
+++ b/src/fetch.c
@@ -118,7 +118,8 @@ int git_fetch__download_pack(
int recvd;
char buff[1024];
gitno_buffer buf;
- git_indexer_stream *idx;
+ git_buf path = GIT_BUF_INIT;
+ git_indexer_stream *idx = NULL;
gitno_buffer_setup(t, &buf, buff, sizeof(buff));
@@ -127,9 +128,12 @@ int git_fetch__download_pack(
return -1;
}
- if (git_indexer_stream_new(&idx, git_repository_path(repo)) < 0)
+ if (git_buf_joinpath(&path, git_repository_path(repo), "objects/pack") < 0)
return -1;
+ if (git_indexer_stream_new(&idx, git_buf_cstr(&path)) < 0)
+ goto on_error;
+
memset(stats, 0, sizeof(git_indexer_stats));
if (git_indexer_stream_add(idx, buffered, buffered_size, stats) < 0)
goto on_error;
@@ -154,6 +158,7 @@ int git_fetch__download_pack(
return 0;
on_error:
+ git_buf_free(&path);
git_indexer_stream_free(idx);
return -1;
}
diff --git a/src/indexer.c b/src/indexer.c
index 1b0a203..b4312e1 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -142,7 +142,7 @@ int git_indexer_stream_new(git_indexer_stream **out, const char *prefix)
{
git_indexer_stream *idx;
git_buf path = GIT_BUF_INIT;
- static const char suff[] = "/objects/pack/pack-received";
+ static const char suff[] = "/pack";
int error;
idx = git__calloc(1, sizeof(git_indexer_stream));
diff --git a/src/transports/http.c b/src/transports/http.c
index 4139a2f..f25d639 100644
--- a/src/transports/http.c
+++ b/src/transports/http.c
@@ -545,6 +545,7 @@ static int http_download_pack(git_transport *transport, git_repository *repo, gi
http_parser_settings settings;
char buffer[1024];
gitno_buffer buf;
+ git_buf path = GIT_BUF_INIT;
git_indexer_stream *idx = NULL;
download_pack_cbdata data;
@@ -555,7 +556,10 @@ static int http_download_pack(git_transport *transport, git_repository *repo, gi
return -1;
}
- if (git_indexer_stream_new(&idx, git_repository_path(repo)) < 0)
+ if (git_buf_joinpath(&path, git_repository_path(repo), "objects/pack") < 0)
+ return -1;
+
+ if (git_indexer_stream_new(&idx, git_buf_cstr(&path)) < 0)
return -1;
/*
@@ -600,6 +604,7 @@ static int http_download_pack(git_transport *transport, git_repository *repo, gi
on_error:
git_indexer_stream_free(idx);
+ git_buf_free(&path);
return -1;
}