diff options
author | Russell Belfer <rb@github.com> | 2014-05-08 13:29:09 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2014-05-08 13:29:09 -0700 |
commit | 5ebe18b72c4f84947f8a284749f934fe03815d55 (patch) | |
tree | 2efe44fd64355ec5d01fc537c51306029c6934c2 | |
parent | ed476c236b8328c31acb150ee69eaf00c821b9e3 (diff) | |
parent | 56ec2256f24eb43b09351194d02cd8458ff39708 (diff) | |
download | libgit2-5ebe18b72c4f84947f8a284749f934fe03815d55.tar.gz |
Merge pull request #2332 from libgit2/peff/iconv
iconv debugging aids
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | examples/.gitignore | 1 | ||||
-rw-r--r-- | examples/Makefile | 1 | ||||
-rw-r--r-- | examples/for-each-ref.c | 46 |
4 files changed, 49 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 884c9bcf1..6f731d491 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -207,7 +207,7 @@ ENDIF() # Optional external dependency: iconv IF (USE_ICONV) - FIND_PACKAGE(ICONV) + FIND_PACKAGE(Iconv) ENDIF() IF (ICONV_FOUND) ADD_DEFINITIONS(-DGIT_USE_ICONV) diff --git a/examples/.gitignore b/examples/.gitignore index b652e28b5..083c8835e 100644 --- a/examples/.gitignore +++ b/examples/.gitignore @@ -9,4 +9,5 @@ log rev-parse status tag +for-each-ref *.dSYM diff --git a/examples/Makefile b/examples/Makefile index e866b7fee..11b019984 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -4,6 +4,7 @@ CC = gcc CFLAGS = -g -I../include -I../src -Wall -Wextra -Wmissing-prototypes -Wno-missing-field-initializers LFLAGS = -L../build -lgit2 -lz APPS = general showindex diff rev-list cat-file status log rev-parse init blame tag +APPS += for-each-ref all: $(APPS) diff --git a/examples/for-each-ref.c b/examples/for-each-ref.c new file mode 100644 index 000000000..d6846bb0d --- /dev/null +++ b/examples/for-each-ref.c @@ -0,0 +1,46 @@ +#include <git2.h> +#include <stdio.h> +#include "common.h" + +static int show_ref(git_reference *ref, void *data) +{ + git_repository *repo = data; + git_reference *resolved = NULL; + char hex[GIT_OID_HEXSZ+1]; + const git_oid *oid; + git_object *obj; + + if (git_reference_type(ref) == GIT_REF_SYMBOLIC) + check_lg2(git_reference_resolve(&resolved, ref), + "Unable to resolve symbolic reference", + git_reference_name(ref)); + + oid = git_reference_target(resolved ? resolved : ref); + git_oid_fmt(hex, oid); + hex[GIT_OID_HEXSZ] = 0; + check_lg2(git_object_lookup(&obj, repo, oid, GIT_OBJ_ANY), + "Unable to lookup object", hex); + + printf("%s %-6s\t%s\n", + hex, + git_object_type2string(git_object_type(obj)), + git_reference_name(ref)); + + if (resolved) + git_reference_free(resolved); + return 0; +} + +int main(int argc, char **argv) +{ + git_repository *repo; + + if (argc != 1 || argv[1] /* silence -Wunused-parameter */) + fatal("Sorry, no for-each-ref options supported yet", NULL); + + check_lg2(git_repository_open(&repo, "."), + "Could not open repository", NULL); + check_lg2(git_reference_foreach(repo, show_ref, repo), + "Could not iterate over references", NULL); + return 0; +} |