diff options
| author | Patrick Steinhardt <ps@pks.im> | 2019-01-24 11:31:49 +0100 |
|---|---|---|
| committer | Patrick Steinhardt <ps@pks.im> | 2019-02-15 12:06:54 +0100 |
| commit | ead10785dcd9e7599a52a0349a69c113c76e650d (patch) | |
| tree | 14c30c430befd05eb160108fe49a14d72faeb3d7 /examples/cat-file.c | |
| parent | 7562422ab9310b81142986f69964194f491948cc (diff) | |
| download | libgit2-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/cat-file.c')
| -rw-r--r-- | examples/cat-file.c | 10 |
1 files changed, 1 insertions, 9 deletions
diff --git a/examples/cat-file.c b/examples/cat-file.c index 0fb7d4535..9b14a7048 100644 --- a/examples/cat-file.c +++ b/examples/cat-file.c @@ -120,19 +120,14 @@ static void parse_opts(struct opts *o, int argc, char *argv[]); /** Entry point for this command */ -int main(int argc, char *argv[]) +int lg2_cat_file(git_repository *repo, int argc, char *argv[]) { - git_repository *repo; struct opts o = { ".", NULL, 0, 0 }; git_object *obj = NULL; char oidstr[GIT_OID_HEXSZ + 1]; - git_libgit2_init(); - parse_opts(&o, argc, argv); - check_lg2(git_repository_open_ext(&repo, o.dir, 0, NULL), - "Could not open repository", NULL); check_lg2(git_revparse_single(&obj, repo, o.rev), "Could not resolve", o.rev); @@ -188,9 +183,6 @@ int main(int argc, char *argv[]) } git_object_free(obj); - git_repository_free(repo); - - git_libgit2_shutdown(); return 0; } |
