summaryrefslogtreecommitdiff
path: root/examples/diff.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/diff.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/diff.c')
-rw-r--r--examples/diff.c12
1 files changed, 1 insertions, 11 deletions
diff --git a/examples/diff.c b/examples/diff.c
index 1de0483a3..e8ba918f6 100644
--- a/examples/diff.c
+++ b/examples/diff.c
@@ -67,9 +67,8 @@ static int color_printer(
const git_diff_delta*, const git_diff_hunk*, const git_diff_line*, void*);
static void diff_print_stats(git_diff *diff, struct opts *o);
-int main(int argc, char *argv[])
+int lg2_diff(git_repository *repo, int argc, char *argv[])
{
- git_repository *repo = NULL;
git_tree *t1 = NULL, *t2 = NULL;
git_diff *diff;
struct opts o = {
@@ -77,13 +76,8 @@ int main(int argc, char *argv[])
-1, 0, 0, GIT_DIFF_FORMAT_PATCH, NULL, NULL, "."
};
- git_libgit2_init();
-
parse_opts(&o, argc, argv);
- check_lg2(git_repository_open_ext(&repo, o.dir, 0, NULL),
- "Could not open repository", o.dir);
-
/**
* Possible argument patterns:
*
@@ -157,13 +151,9 @@ int main(int argc, char *argv[])
}
/** Cleanup before exiting. */
-
git_diff_free(diff);
git_tree_free(t1);
git_tree_free(t2);
- git_repository_free(repo);
-
- git_libgit2_shutdown();
return 0;
}