]>
git.proxmox.com Git - libgit2.git/blob - examples/network/index-pack.c
7 // This could be run in the main loop whilst the application waits for
8 // the indexing to finish in a worker thread
9 int index_cb(const git_indexer_stats
*stats
, void *data
)
11 printf("\rProcessing %d of %d", stats
->processed
, stats
->total
);
14 int index_pack(git_repository
*repo
, int argc
, char **argv
)
16 git_indexer_stream
*idx
;
17 git_indexer_stats stats
= {0, 0};
19 char hash
[GIT_OID_HEXSZ
+ 1] = {0};
24 fprintf(stderr
, "I need a packfile\n");
28 if (git_indexer_stream_new(&idx
, ".") < 0) {
33 if ((fd
= open(argv
[1], 0)) < 0) {
39 read_bytes
= read(fd
, buf
, sizeof(buf
));
43 if ((error
= git_indexer_stream_add(idx
, buf
, read_bytes
, &stats
)) < 0)
46 printf("\rIndexing %d of %d", stats
.processed
, stats
.total
);
47 } while (read_bytes
> 0);
51 perror("failed reading");
55 if ((error
= git_indexer_stream_finalize(idx
, &stats
)) < 0)
58 printf("\rIndexing %d of %d\n", stats
.processed
, stats
.total
);
60 git_oid_fmt(hash
, git_indexer_stream_hash(idx
));
65 git_indexer_stream_free(idx
);
69 int index_pack_old(git_repository
*repo
, int argc
, char **argv
)
72 git_indexer_stats stats
;
74 char hash
[GIT_OID_HEXSZ
+ 1] = {0};
77 fprintf(stderr
, "I need a packfile\n");
81 // Create a new indexer
82 error
= git_indexer_new(&indexer
, argv
[1]);
86 // Index the packfile. This function can take a very long time and
87 // should be run in a worker thread.
88 error
= git_indexer_run(indexer
, &stats
);
92 // Write the information out to an index file
93 error
= git_indexer_write(indexer
);
95 // Get the packfile's hash (which should become it's filename)
96 git_oid_fmt(hash
, git_indexer_hash(indexer
));
99 git_indexer_free(indexer
);