1 /* 2 * libgit2 "showindex" example - shows how to extract data from the index 3 * 4 * Written by the libgit2 contributors 5 * 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. 9 * 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/>. 13 */ 14 module libgit2_d.example.show_index; 15 16 17 private static import core.stdc.stdio; 18 private static import core.stdc.string; 19 private static import libgit2_d.example.common; 20 private static import libgit2_d.index; 21 private static import libgit2_d.oid; 22 private static import libgit2_d.repository; 23 private static import libgit2_d.types; 24 25 package: 26 27 extern (C) 28 nothrow @nogc 29 public int lg2_show_index(libgit2_d.types.git_repository* repo, int argc, char** argv) 30 31 in 32 { 33 } 34 35 do 36 { 37 char[libgit2_d.oid.GIT_OID_HEXSZ + 1] out_ = '\0'; 38 39 if (argc > 2) { 40 libgit2_d.example.common.fatal("usage: showindex [<repo-dir>]", null); 41 } 42 43 const char* dir = (argc > 1) ? (argv[1]) : ("."); 44 size_t dirlen = core.stdc..string.strlen(dir); 45 46 libgit2_d.types.git_index* index; 47 48 if ((dirlen > 5) && (core.stdc..string.strcmp(dir + dirlen - 5, "index") == 0)) { 49 libgit2_d.example.common.check_lg2(libgit2_d.index.git_index_open(&index, dir), "could not open index", dir); 50 } else { 51 libgit2_d.example.common.check_lg2(libgit2_d.repository.git_repository_open_ext(&repo, dir, 0, null), "could not open repository", dir); 52 libgit2_d.example.common.check_lg2(libgit2_d.repository.git_repository_index(&index, repo), "could not open repository index", null); 53 libgit2_d.repository.git_repository_free(repo); 54 } 55 56 libgit2_d.index.git_index_read(index, 0); 57 58 size_t ecount = libgit2_d.index.git_index_entrycount(index); 59 60 if (!ecount) { 61 core.stdc.stdio.printf("Empty index\n"); 62 } 63 64 for (size_t i = 0; i < ecount; ++i) { 65 const (libgit2_d.index.git_index_entry)* e = libgit2_d.index.git_index_get_byindex(index, i); 66 67 libgit2_d.oid.git_oid_fmt(&(out_[0]), &e.id); 68 69 core.stdc.stdio.printf("File Path: %s\n", e.path); 70 core.stdc.stdio.printf(" Stage: %d\n", libgit2_d.index.git_index_entry_stage(e)); 71 core.stdc.stdio.printf(" Blob SHA: %s\n", &(out_[0])); 72 core.stdc.stdio.printf("File Mode: %07o\n", e.mode); 73 core.stdc.stdio.printf("File Size: %d bytes\n", cast(int)(e.file_size)); 74 core.stdc.stdio.printf("Dev/Inode: %d/%d\n", cast(int)(e.dev), cast(int)(e.ino)); 75 core.stdc.stdio.printf(" UID/GID: %d/%d\n", cast(int)(e.uid), cast(int)(e.gid)); 76 core.stdc.stdio.printf(" ctime: %d\n", cast(int)(e.ctime.seconds)); 77 core.stdc.stdio.printf(" mtime: %d\n", cast(int)(e.mtime.seconds)); 78 core.stdc.stdio.printf("\n"); 79 } 80 81 libgit2_d.index.git_index_free(index); 82 83 return 0; 84 }