-
Notifications
You must be signed in to change notification settings - Fork 1
/
index-pack.c
41 lines (32 loc) · 834 Bytes
/
index-pack.c
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
#include <git2.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "common.h"
int index_cb(const git_indexer_stats *stats, void *data)
{
printf("\rProcessing %d of %d", stats->processed, stats->total);
}
int index_pack(git_repository *repo, int argc, char **argv)
{
git_indexer *indexer;
git_indexer_stats stats;
int error;
char hash[GIT_OID_HEXSZ + 1] = {0};
if (argc < 2) {
fprintf(stderr, "I need a packfile\n");
return EXIT_FAILURE;
}
error = git_indexer_new(&indexer, argv[1]);
if (error < GIT_SUCCESS)
return error;
error = git_indexer_run(indexer, &stats);
if (error < GIT_SUCCESS)
return error;
puts("");
error = git_indexer_write(indexer);
git_oid_fmt(hash, git_indexer_hash(indexer));
puts(hash);
git_indexer_free(indexer);
return GIT_SUCCESS;
}