examples: fixup for-each-ref style

parent c924f36a
...@@ -3,42 +3,42 @@ ...@@ -3,42 +3,42 @@
static int show_ref(git_reference *ref, void *data) static int show_ref(git_reference *ref, void *data)
{ {
git_repository *repo = data; git_repository *repo = data;
git_reference *resolved = NULL; git_reference *resolved = NULL;
char hex[GIT_OID_HEXSZ+1]; char hex[GIT_OID_HEXSZ+1];
const git_oid *oid; const git_oid *oid;
git_object *obj; git_object *obj;
if (git_reference_type(ref) == GIT_REFERENCE_SYMBOLIC) if (git_reference_type(ref) == GIT_REFERENCE_SYMBOLIC)
check_lg2(git_reference_resolve(&resolved, ref), check_lg2(git_reference_resolve(&resolved, ref),
"Unable to resolve symbolic reference", "Unable to resolve symbolic reference",
git_reference_name(ref)); git_reference_name(ref));
oid = git_reference_target(resolved ? resolved : ref); oid = git_reference_target(resolved ? resolved : ref);
git_oid_fmt(hex, oid); git_oid_fmt(hex, oid);
hex[GIT_OID_HEXSZ] = 0; hex[GIT_OID_HEXSZ] = 0;
check_lg2(git_object_lookup(&obj, repo, oid, GIT_OBJECT_ANY), check_lg2(git_object_lookup(&obj, repo, oid, GIT_OBJECT_ANY),
"Unable to lookup object", hex); "Unable to lookup object", hex);
printf("%s %-6s\t%s\n", printf("%s %-6s\t%s\n",
hex, hex,
git_object_type2string(git_object_type(obj)), git_object_type2string(git_object_type(obj)),
git_reference_name(ref)); git_reference_name(ref));
if (resolved) if (resolved)
git_reference_free(resolved); git_reference_free(resolved);
return 0; return 0;
} }
int lg2_for_each_ref(git_repository *repo, int argc, char **argv) int lg2_for_each_ref(git_repository *repo, int argc, char **argv)
{ {
UNUSED(argv); UNUSED(argv);
if (argc != 1) if (argc != 1)
fatal("Sorry, no for-each-ref options supported yet", NULL); fatal("Sorry, no for-each-ref options supported yet", NULL);
check_lg2(git_reference_foreach(repo, show_ref, repo), check_lg2(git_reference_foreach(repo, show_ref, repo),
"Could not iterate over references", NULL); "Could not iterate over references", NULL);
return 0; return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment