rev-list.c example: use common utils, reorganize
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
diff --git a/examples/rev-list.c b/examples/rev-list.c
index 1fb7ebf..9330c64 100644
--- a/examples/rev-list.c
+++ b/examples/rev-list.c
@@ -1,17 +1,35 @@
-#include <stdio.h>
-#include <string.h>
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
-#include <git2.h>
+#include "common.h"
-static void check_error(int error_code, const char *action)
+static int revwalk_parseopts(git_repository *repo, git_revwalk *walk, int nopts, char **opts);
+
+int main (int argc, char **argv)
{
- if (!error_code)
- return;
+ git_repository *repo;
+ git_revwalk *walk;
+ git_oid oid;
+ char buf[41];
+
+ git_threads_init();
- const git_error *error = giterr_last();
- fprintf(stderr, "Error %d %s: %s\n", -error_code, action,
- (error && error->message) ? error->message : "???");
- exit(1);
+ check_lg2(git_repository_open_ext(&repo, ".", 0, NULL), "opening repository", NULL);
+ check_lg2(git_revwalk_new(&walk, repo), "allocating revwalk", NULL);
+ check_lg2(revwalk_parseopts(repo, walk, argc-1, argv+1), "parsing options", NULL);
+
+ while (!git_revwalk_next(&oid, walk)) {
+ git_oid_fmt(buf, &oid);
+ buf[40] = '\0';
+ printf("%s\n", buf);
+ }
+
+ git_threads_shutdown();
+ return 0;
}
static int push_commit(git_revwalk *walk, const git_oid *oid, int hide)
@@ -93,27 +111,3 @@ static int revwalk_parseopts(git_repository *repo, git_revwalk *walk, int nopts,
return 0;
}
-int main (int argc, char **argv)
-{
- int error;
- git_repository *repo;
- git_revwalk *walk;
- git_oid oid;
- char buf[41];
-
- error = git_repository_open_ext(&repo, ".", 0, NULL);
- check_error(error, "opening repository");
-
- error = git_revwalk_new(&walk, repo);
- check_error(error, "allocating revwalk");
- error = revwalk_parseopts(repo, walk, argc-1, argv+1);
- check_error(error, "parsing options");
-
- while (!git_revwalk_next(&oid, walk)) {
- git_oid_fmt(buf, &oid);
- buf[40] = '\0';
- printf("%s\n", buf);
- }
-
- return 0;
-}