Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2013-04-16 19:46:41 +0400
committerVicent Marti <tanoku@gmail.com>2013-04-16 19:46:41 +0400
commita50086d174658914d4d6462afbc83b02825b1f5b (patch)
treee8daa1c7bf678222cf351445179837bed7db3a72 /examples/showindex.c
parent5b9fac39d8a76b9139667c26a63e6b3f204b3977 (diff)
parentf124ebd457bfbf43de3516629aaba5a279636e04 (diff)
Merge branch 'development'v0.18.0
Diffstat (limited to 'examples/showindex.c')
-rw-r--r--examples/showindex.c96
1 files changed, 60 insertions, 36 deletions
diff --git a/examples/showindex.c b/examples/showindex.c
index 7f2130b90..e92a9c8de 100644
--- a/examples/showindex.c
+++ b/examples/showindex.c
@@ -1,43 +1,67 @@
#include <git2.h>
#include <stdio.h>
+#include <string.h>
int main (int argc, char** argv)
{
- git_repository *repo;
- git_index *index;
- unsigned int i, e, ecount;
- git_index_entry **entries;
- git_oid oid;
-
- char out[41];
- out[40] = '\0';
-
- git_repository_open(&repo, "/opt/libgit2-test/.git");
-
- git_repository_index(&index, repo);
- git_index_read(index);
-
- ecount = git_index_entrycount(index);
- for (i = 0; i < ecount; ++i) {
- git_index_entry *e = git_index_get(index, i);
-
- oid = e->oid;
- git_oid_fmt(out, &oid);
-
- printf("File Path: %s\n", e->path);
- printf(" Blob SHA: %s\n", out);
- printf("File Size: %d\n", (int)e->file_size);
- printf(" Device: %d\n", (int)e->dev);
- printf(" Inode: %d\n", (int)e->ino);
- printf(" UID: %d\n", (int)e->uid);
- printf(" GID: %d\n", (int)e->gid);
- printf(" ctime: %d\n", (int)e->ctime.seconds);
- printf(" mtime: %d\n", (int)e->mtime.seconds);
- printf("\n");
- }
-
- git_index_free(index);
-
- git_repository_free(repo);
+ git_repository *repo = NULL;
+ git_index *index;
+ unsigned int i, ecount;
+ char *dir = ".";
+ size_t dirlen;
+ char out[41];
+ out[40] = '\0';
+
+ if (argc > 1)
+ dir = argv[1];
+ if (!dir || argc > 2) {
+ fprintf(stderr, "usage: showindex [<repo-dir>]\n");
+ return 1;
+ }
+
+ dirlen = strlen(dir);
+ if (dirlen > 5 && strcmp(dir + dirlen - 5, "index") == 0) {
+ if (git_index_open(&index, dir) < 0) {
+ fprintf(stderr, "could not open index: %s\n", dir);
+ return 1;
+ }
+ } else {
+ if (git_repository_open_ext(&repo, dir, 0, NULL) < 0) {
+ fprintf(stderr, "could not open repository: %s\n", dir);
+ return 1;
+ }
+ if (git_repository_index(&index, repo) < 0) {
+ fprintf(stderr, "could not open repository index\n");
+ return 1;
+ }
+ }
+
+ git_index_read(index);
+
+ ecount = git_index_entrycount(index);
+ if (!ecount)
+ printf("Empty index\n");
+
+ for (i = 0; i < ecount; ++i) {
+ const git_index_entry *e = git_index_get_byindex(index, i);
+
+ git_oid_fmt(out, &e->oid);
+
+ 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");
+ }
+
+ git_index_free(index);
+ git_repository_free(repo);
+
+ return 0;
}