indexer: clearer stats for thin packs Don't increase the number of total objects, as it can produce suprising progress output. The only addition compared to pre-thin is the addition of local_objects to allow an output similar to git's "completed with %d local objects".
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
diff --git a/include/git2/types.h b/include/git2/types.h
index 3939353..4ff2ba4 100644
--- a/include/git2/types.h
+++ b/include/git2/types.h
@@ -212,6 +212,13 @@ typedef struct git_remote_callbacks git_remote_callbacks;
/**
* This is passed as the first argument to the callback to allow the
* user to see the progress.
+ *
+ * - total_objects: number of objects in the packfile being downloaded
+ * - indexed_objects: received objects that have been hashed
+ * - received_objects: objects which have been downloaded
+ * - local_objects: locally-available objects that have been injected
+ * in order to fix a thin pack.
+ * - received-bytes: size of the packfile received up to now
*/
typedef struct git_transfer_progress {
unsigned int total_objects;
diff --git a/src/indexer.c b/src/indexer.c
index 2cda1a6..93ad116 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -733,7 +733,6 @@ static int fix_thin_pack(git_indexer_stream *idx, git_transfer_progress *stats)
if (inject_object(idx, &base) < 0)
return -1;
- stats->total_objects++;
stats->local_objects++;
return 0;
@@ -798,7 +797,7 @@ static int update_header_and_rehash(git_indexer_stream *idx, git_transfer_progre
git_mwindow_free_all(mwf);
/* Update the header to include the numer of local objects we injected */
- idx->hdr.hdr_entries = htonl(stats->total_objects);
+ idx->hdr.hdr_entries = htonl(stats->total_objects + stats->local_objects);
if (p_lseek(idx->pack_file.fd, 0, SEEK_SET) < 0) {
giterr_set(GITERR_OS, "failed to seek to the beginning of the pack");
return -1;
@@ -870,7 +869,7 @@ int git_indexer_stream_finalize(git_indexer_stream *idx, git_transfer_progress *
if (resolve_deltas(idx, stats) < 0)
return -1;
- if (stats->indexed_objects + stats->local_objects != stats->total_objects) {
+ if (stats->indexed_objects != stats->total_objects) {
giterr_set(GITERR_INDEXER, "early EOF");
return -1;
}
diff --git a/tests-clar/pack/indexer.c b/tests-clar/pack/indexer.c
index fd16160..17ec7b3 100644
--- a/tests-clar/pack/indexer.c
+++ b/tests-clar/pack/indexer.c
@@ -79,7 +79,7 @@ void test_pack_indexer__fix_thin(void)
cl_git_pass(git_indexer_stream_add(idx, thin_pack, thin_pack_len, &stats));
cl_git_pass(git_indexer_stream_finalize(idx, &stats));
- cl_assert_equal_i(stats.total_objects, 3);
+ cl_assert_equal_i(stats.total_objects, 2);
cl_assert_equal_i(stats.received_objects, 2);
cl_assert_equal_i(stats.indexed_objects, 2);
cl_assert_equal_i(stats.local_objects, 1);