summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--git-file.c14
-rw-r--r--git-hist.c5
-rw-r--r--git-util.c35
-rw-r--r--git-util.h18
5 files changed, 59 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index f37033e..9ff2976 100644
--- a/Makefile
+++ b/Makefile
@@ -13,7 +13,7 @@
NAME = eeshow
OBJS = main.o sch-parse.o sch-render.o lib-parse.o lib-render.o \
gui.o gui-over.o gui-aoi.o \
- file.o git-file.o git-hist.o \
+ file.o git-util.o git-file.o git-hist.o \
style.o fig.o record.o cro.o diff.o gfx.o dwg.o text.o misc.o
CFLAGS = -g -Wall -Wextra -Wno-unused-parameter -Wshadow \
diff --git a/git-file.c b/git-file.c
index 7dc75a5..21810c0 100644
--- a/git-file.c
+++ b/git-file.c
@@ -23,6 +23,7 @@
#include "util.h"
#include "main.h"
#include "file.h"
+#include "git-util.h"
#include "git-file.h"
@@ -421,23 +422,12 @@ static bool try_related(struct vcs_git *vcs_git)
}
-void vcs_git_init(void)
-{
- static bool initialized = 0;
-
- if (!initialized) {
- git_libgit2_init();
- initialized = 1;
- }
-}
-
-
struct vcs_git *vcs_git_open(const char *revision, const char *name,
const struct vcs_git *related)
{
struct vcs_git *vcs_git = alloc_type(struct vcs_git);
- vcs_git_init();
+ git_init_once();
vcs_git->name = stralloc(name);
vcs_git->revision = revision ? stralloc(revision) : NULL;
diff --git a/git-hist.c b/git-hist.c
index 53e66c5..3367b9d 100644
--- a/git-hist.c
+++ b/git-hist.c
@@ -17,6 +17,7 @@
#include "util.h"
#include "main.h"
+#include "git-util.h"
#include "git-file.h"
#include "git-hist.h"
@@ -130,7 +131,7 @@ bool vcs_git_try(const char *path)
{
git_repository *repo;
- vcs_git_init();
+ git_init_once();
if (git_repository_open_ext(&repo, path,
GIT_REPOSITORY_OPEN_CROSS_FS, NULL))
@@ -148,7 +149,7 @@ struct hist *vcs_git_hist(const char *path)
head = new_commit(0);
- vcs_git_init();
+ git_init_once();
if (git_repository_open_ext(&repo, path,
GIT_REPOSITORY_OPEN_CROSS_FS, NULL)) {
diff --git a/git-util.c b/git-util.c
new file mode 100644
index 0000000..71cf6cd
--- /dev/null
+++ b/git-util.c
@@ -0,0 +1,35 @@
+/*
+ * git-util.c - Git utility functions
+ *
+ * Written 2016 by Werner Almesberger
+ * Copyright 2016 by Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <stdbool.h>
+
+#include <git2.h>
+
+#include "git-util.h"
+
+
+/*
+ * Git documentation says that git_libgit2_init can be called more then once
+ * but doesn't quite what happens then, e.g., whether references obtained
+ * before an init (except for the first, of course) can still be used after
+ * it. So we play it safe and initialize only once.
+ */
+
+void git_init_once(void)
+{
+ static bool initialized = 0;
+
+ if (!initialized) {
+ git_libgit2_init();
+ initialized = 1;
+ }
+}
diff --git a/git-util.h b/git-util.h
new file mode 100644
index 0000000..601855a
--- /dev/null
+++ b/git-util.h
@@ -0,0 +1,18 @@
+/*
+ * git-util.h - Git utility functions
+ *
+ * Written 2016 by Werner Almesberger
+ * Copyright 2016 by Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#ifndef GIT_UTIL_H
+#define GIT_UTIL_H
+
+void git_init_once(void);
+
+#endif /* !GIT_UTIL_H */