]>
git.proxmox.com Git - libgit2.git/blob - examples/network/index-pack.c
11 // This could be run in the main loop whilst the application waits for
12 // the indexing to finish in a worker thread
13 static int index_cb(const git_indexer_stats
*stats
, void *data
)
16 printf("\rProcessing %d of %d", stats
->processed
, stats
->total
);
21 int index_pack(git_repository
*repo
, int argc
, char **argv
)
23 git_indexer_stream
*idx
;
24 git_indexer_stats stats
= {0, 0};
26 char hash
[GIT_OID_HEXSZ
+ 1] = {0};
32 fprintf(stderr
, "I need a packfile\n");
36 if (git_indexer_stream_new(&idx
, ".", NULL
, NULL
) < 0) {
41 if ((fd
= open(argv
[1], 0)) < 0) {
47 read_bytes
= read(fd
, buf
, sizeof(buf
));
51 if ((error
= git_indexer_stream_add(idx
, buf
, read_bytes
, &stats
)) < 0)
54 index_cb(&stats
, NULL
);
55 } while (read_bytes
> 0);
59 perror("failed reading");
63 if ((error
= git_indexer_stream_finalize(idx
, &stats
)) < 0)
66 printf("\rIndexing %d of %d\n", stats
.processed
, stats
.total
);
68 git_oid_fmt(hash
, git_indexer_stream_hash(idx
));
73 git_indexer_stream_free(idx
);