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