forked from AndreyG/libgit2cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshowindex.cpp
More file actions
55 lines (43 loc) · 1.35 KB
/
Copy pathshowindex.cpp
File metadata and controls
55 lines (43 loc) · 1.35 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <string.h>
#include <git2/index.h>
#include "git2cpp/initializer.h"
#include "git2cpp/repo.h"
using namespace git;
int main(int argc, char ** argv)
{
const char * dir = ".";
Initializer threads_initalizer;
if (argc > 1)
dir = argv[1];
if (!dir || argc > 2)
{
fprintf(stderr, "usage: showindex [<repo-dir>]\n");
return 1;
}
size_t dirlen = strlen(dir);
Index index = (dirlen > 5 && strcmp(dir + dirlen - 5, "index") == 0)
? Index(dir)
: Repository(dir).index();
size_t ecount = index.entrycount();
if (!ecount)
printf("Empty index\n");
for (size_t i = 0; i < ecount; ++i)
{
auto e = index[i];
char out[41];
out[40] = '\0';
git_oid_fmt(out, &e->id);
printf("File Path: %s\n", e->path);
printf(" Stage: %d\n", git_index_entry_stage(e));
printf(" Blob SHA: %s\n", out);
printf("File Mode: %07o\n", e->mode);
printf("File Size: %d bytes\n", (int)e->file_size);
printf("Dev/Inode: %d/%d\n", (int)e->dev, (int)e->ino);
printf(" UID/GID: %d/%d\n", (int)e->uid, (int)e->gid);
printf(" ctime: %d\n", (int)e->ctime.seconds);
printf(" mtime: %d\n", (int)e->mtime.seconds);
printf("\n");
}
return 0;
}