]>
git.proxmox.com Git - libgit2.git/blob - examples/show-index.c
2 * libgit2 "showindex" example - shows how to extract data from the index
4 * Written by the libgit2 contributors
6 * To the extent possible under law, the author(s) have dedicated all copyright
7 * and related and neighboring rights to this software to the public domain
8 * worldwide. This software is distributed without any warranty.
10 * You should have received a copy of the CC0 Public Domain Dedication along
11 * with this software. If not, see
12 * <http://creativecommons.org/publicdomain/zero/1.0/>.
17 int lg2_show_index(git_repository
*repo
, int argc
, char **argv
)
23 char out
[GIT_OID_HEXSZ
+1];
24 out
[GIT_OID_HEXSZ
] = '\0';
27 fatal("usage: showindex [<repo-dir>]", NULL
);
32 if (dirlen
> 5 && strcmp(dir
+ dirlen
- 5, "index") == 0) {
33 check_lg2(git_index_open(&index
, dir
), "could not open index", dir
);
35 check_lg2(git_repository_open_ext(&repo
, dir
, 0, NULL
), "could not open repository", dir
);
36 check_lg2(git_repository_index(&index
, repo
), "could not open repository index", NULL
);
37 git_repository_free(repo
);
40 git_index_read(index
, 0);
42 ecount
= git_index_entrycount(index
);
44 printf("Empty index\n");
46 for (i
= 0; i
< ecount
; ++i
) {
47 const git_index_entry
*e
= git_index_get_byindex(index
, i
);
49 git_oid_fmt(out
, &e
->id
);
51 printf("File Path: %s\n", e
->path
);
52 printf(" Stage: %d\n", git_index_entry_stage(e
));
53 printf(" Blob SHA: %s\n", out
);
54 printf("File Mode: %07o\n", e
->mode
);
55 printf("File Size: %d bytes\n", (int)e
->file_size
);
56 printf("Dev/Inode: %d/%d\n", (int)e
->dev
, (int)e
->ino
);
57 printf(" UID/GID: %d/%d\n", (int)e
->uid
, (int)e
->gid
);
58 printf(" ctime: %d\n", (int)e
->ctime
.seconds
);
59 printf(" mtime: %d\n", (int)e
->mtime
.seconds
);
63 git_index_free(index
);