4 * This could be run in the main loop whilst the application waits for
5 * the indexing to finish in a worker thread
7 static int index_cb(const git_indexer_progress
*stats
, void *data
)
10 printf("\rProcessing %u of %u", stats
->indexed_objects
, stats
->total_objects
);
15 int lg2_index_pack(git_repository
*repo
, int argc
, char **argv
)
18 git_indexer_progress stats
= {0, 0};
27 fprintf(stderr
, "usage: %s index-pack <packfile>\n", argv
[-1]);
31 if (git_indexer_new(&idx
, ".", 0, NULL
, NULL
) < 0) {
36 if ((fd
= open(argv
[1], 0)) < 0) {
42 read_bytes
= read(fd
, buf
, sizeof(buf
));
46 if ((error
= git_indexer_append(idx
, buf
, read_bytes
, &stats
)) < 0)
49 index_cb(&stats
, NULL
);
50 } while (read_bytes
> 0);
54 perror("failed reading");
58 if ((error
= git_indexer_commit(idx
, &stats
)) < 0)
61 printf("\rIndexing %u of %u\n", stats
.indexed_objects
, stats
.total_objects
);
63 puts(git_indexer_name(idx
));
67 git_indexer_free(idx
);