1 module libgit2.example.for_each_ref; 2 3 4 private static import core.stdc.stdio; 5 private static import libgit2.example.common; 6 private static import libgit2.object; 7 private static import libgit2.oid; 8 private static import libgit2.refs; 9 private static import libgit2.types; 10 11 extern (C) 12 nothrow @nogc 13 private int show_ref(libgit2.types.git_reference* ref_, void* data) 14 15 in 16 { 17 } 18 19 do 20 { 21 libgit2.types.git_reference* resolved = null; 22 23 if (libgit2.refs.git_reference_type(ref_) == libgit2.types.git_reference_t.GIT_REFERENCE_SYMBOLIC) { 24 libgit2.example.common.check_lg2(libgit2.refs.git_reference_resolve(&resolved, ref_), "Unable to resolve symbolic reference", libgit2.refs.git_reference_name(ref_)); 25 } 26 27 const (libgit2.oid.git_oid)* oid = libgit2.refs.git_reference_target((resolved) ? (resolved) : (ref_)); 28 char[libgit2.oid.GIT_OID_SHA1_HEXSIZE + 1] hex; 29 libgit2.oid.git_oid_fmt(&(hex[0]), oid); 30 hex[libgit2.oid.GIT_OID_SHA1_HEXSIZE] = 0; 31 libgit2.types.git_object* obj; 32 libgit2.types.git_repository* repo = cast(libgit2.types.git_repository*)(data); 33 libgit2.example.common.check_lg2(libgit2.object.git_object_lookup(&obj, repo, oid, libgit2.types.git_object_t.GIT_OBJECT_ANY), "Unable to lookup object", &(hex[0])); 34 35 core.stdc.stdio.printf("%s %-6s\t%s\n", &(hex[0]), libgit2.object.git_object_type2string(libgit2.object.git_object_type(obj)), libgit2.refs.git_reference_name(ref_)); 36 37 if (resolved) { 38 libgit2.refs.git_reference_free(resolved); 39 } 40 41 return 0; 42 } 43 44 extern (C) 45 nothrow @nogc 46 public int lg2_for_each_ref(libgit2.types.git_repository* repo, int argc, char** argv) 47 48 in 49 { 50 } 51 52 do 53 { 54 //cast(void)(argv); 55 56 if (argc != 1) { 57 libgit2.example.common.fatal("Sorry, no for-each-ref options supported yet", null); 58 } 59 60 libgit2.example.common.check_lg2(libgit2.refs.git_reference_foreach(repo, &.show_ref, repo), "Could not iterate over references", null); 61 62 return 0; 63 }