summaryrefslogtreecommitdiff
path: root/examples/showindex.c
diff options
context:
space:
mode:
authorScott Chacon <schacon@gmail.com>2011-06-14 09:27:46 -0700
committerScott Chacon <schacon@gmail.com>2011-06-14 14:18:13 -0700
commit388f37b37b50937666733185e3860b89c87e78c3 (patch)
tree5804a6633551f5b89edbc7dde9c0b865e20479b8 /examples/showindex.c
parent742e3fc92ee24a6ddfc29aad5a82905ed0050de7 (diff)
downloadlibgit2-388f37b37b50937666733185e3860b89c87e78c3.tar.gz
add examples for docs
Diffstat (limited to 'examples/showindex.c')
-rw-r--r--examples/showindex.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/examples/showindex.c b/examples/showindex.c
new file mode 100644
index 000000000..908a114f4
--- /dev/null
+++ b/examples/showindex.c
@@ -0,0 +1,43 @@
+#include <git2.h>
+#include <stdio.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, "/tmp/gittalk/.git");
+
+ git_index_open_inrepo(&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);
+}
+