summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorEtienne Samson <samson.etienne@gmail.com>2018-01-31 00:02:00 +0000
committerEtienne Samson <samson.etienne@gmail.com>2018-07-07 13:10:50 +0200
commit8a629afedc947a2a693955b36550f27fb74891d4 (patch)
tree8ace259a87a97bc70c204d58d7d0381feb9c857f /examples
parent698b44639e499b23d882f8a26f3ca5fd4d94f22e (diff)
downloadlibgit2-8a629afedc947a2a693955b36550f27fb74891d4.tar.gz
examples: move refish resolution function in common
Diffstat (limited to 'examples')
-rw-r--r--examples/common.c24
-rw-r--r--examples/common.h5
-rw-r--r--examples/merge.c23
3 files changed, 29 insertions, 23 deletions
diff --git a/examples/common.c b/examples/common.c
index 118072044..2b4a062e8 100644
--- a/examples/common.c
+++ b/examples/common.c
@@ -12,6 +12,8 @@
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
+#include <assert.h>
+
#include "common.h"
void check_lg2(int error, const char *message, const char *extra)
@@ -245,3 +247,25 @@ void *xrealloc(void *oldp, size_t newsz)
return p;
}
+int resolve_refish(git_annotated_commit **commit, git_repository *repo, const char *refish)
+{
+ git_reference *ref;
+ int err = 0;
+ git_oid oid;
+
+ assert(commit != NULL);
+
+ err = git_reference_dwim(&ref, repo, refish);
+ if (err == GIT_OK) {
+ git_annotated_commit_from_ref(commit, repo, ref);
+ git_reference_free(ref);
+ return 0;
+ }
+
+ err = git_oid_fromstr(&oid, refish);
+ if (err == GIT_OK) {
+ err = git_annotated_commit_lookup(commit, repo, &oid);
+ }
+
+ return err;
+}
diff --git a/examples/common.h b/examples/common.h
index af42324c2..503c8fbbf 100644
--- a/examples/common.h
+++ b/examples/common.h
@@ -108,3 +108,8 @@ extern void treeish_to_tree(
* A realloc that exits on failure
*/
extern void *xrealloc(void *oldp, size_t newsz);
+
+/**
+ * Convert a refish to an annotated commit.
+ */
+extern int resolve_refish(git_annotated_commit **commit, git_repository *repo, const char *refish);
diff --git a/examples/merge.c b/examples/merge.c
index 59982cb9b..c819ad208 100644
--- a/examples/merge.c
+++ b/examples/merge.c
@@ -87,29 +87,6 @@ static void parse_options(const char **repo_path, merge_options *opts, int argc,
}
}
-static int resolve_refish(git_annotated_commit **commit, git_repository *repo, const char *refish)
-{
- git_reference *ref;
- int err = 0;
- git_oid oid;
-
- assert(commit != NULL);
-
- err = git_reference_dwim(&ref, repo, refish);
- if (err == GIT_OK) {
- git_annotated_commit_from_ref(commit, repo, ref);
- git_reference_free(ref);
- return 0;
- }
-
- err = git_oid_fromstr(&oid, refish);
- if (err == GIT_OK) {
- err = git_annotated_commit_lookup(commit, repo, &oid);
- }
-
- return err;
-}
-
static int resolve_heads(git_repository *repo, merge_options *opts)
{
git_annotated_commit **annotated = calloc(opts->heads_count, sizeof(git_annotated_commit *));