16 #define ssize_t unsigned int
23 * This could be run in the main loop whilst the application waits for
24 * the indexing to finish in a worker thread
26 static int index_cb(const git_transfer_progress
*stats
, void *data
)
29 printf("\rProcessing %d of %d", stats
->indexed_objects
, stats
->total_objects
);
34 int index_pack(git_repository
*repo
, int argc
, char **argv
)
37 git_transfer_progress stats
= {0, 0};
39 char hash
[GIT_OID_HEXSZ
+ 1] = {0};
47 fprintf(stderr
, "usage: %s index-pack <packfile>\n", argv
[-1]);
51 if (git_indexer_new(&idx
, ".", 0, NULL
, NULL
) < 0) {
56 if ((fd
= open(argv
[1], 0)) < 0) {
62 read_bytes
= read(fd
, buf
, sizeof(buf
));
66 if ((error
= git_indexer_append(idx
, buf
, read_bytes
, &stats
)) < 0)
69 index_cb(&stats
, NULL
);
70 } while (read_bytes
> 0);
74 perror("failed reading");
78 if ((error
= git_indexer_commit(idx
, &stats
)) < 0)
81 printf("\rIndexing %d of %d\n", stats
.indexed_objects
, stats
.total_objects
);
83 git_oid_fmt(hash
, git_indexer_hash(idx
));
88 git_indexer_free(idx
);