summaryrefslogtreecommitdiff
path: root/examples/for-each-ref.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2019-01-24 11:31:49 +0100
committerPatrick Steinhardt <ps@pks.im>2019-02-15 12:06:54 +0100
commitead10785dcd9e7599a52a0349a69c113c76e650d (patch)
tree14c30c430befd05eb160108fe49a14d72faeb3d7 /examples/for-each-ref.c
parent7562422ab9310b81142986f69964194f491948cc (diff)
downloadlibgit2-ead10785dcd9e7599a52a0349a69c113c76e650d.tar.gz
examples: create common lg2 executable
Inside of our networking example code, we have a git2 executable that acts as an entry point to all the different network examples. As such, it is kind of the same like the normal git(1) executable in that it simply arbitrates to the respective subcommands. Let's extend this approach and merge all examples into a single standalone lg2 executable. Instead of building an executable for all the existing examples we have, we now bundle them all inside of the lg2 one and let them be callable via subcommands. In the process, we can get rid of duplicated library initialization, deinitialization and repository discovery code. Instead of having each subcommand handle these on its own, we simply do it inside of the single main function now.
Diffstat (limited to 'examples/for-each-ref.c')
-rw-r--r--examples/for-each-ref.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/examples/for-each-ref.c b/examples/for-each-ref.c
index 3bc25fcf2..eea73d2fc 100644
--- a/examples/for-each-ref.c
+++ b/examples/for-each-ref.c
@@ -31,19 +31,15 @@ static int show_ref(git_reference *ref, void *data)
return 0;
}
-int main(int argc, char **argv)
+int lg2_for_each_ref(git_repository *repo, int argc, char **argv)
{
- git_repository *repo;
- git_libgit2_init();
+ UNUSED(argv);
- if (argc != 1 || argv[1] /* silence -Wunused-parameter */)
+ if (argc != 1)
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);
- git_libgit2_shutdown();
return 0;
}