diff --git a/eeshow/Makefile b/eeshow/Makefile index f37033e..9ff2976 100644 --- a/eeshow/Makefile +++ b/eeshow/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/eeshow/git-file.c b/eeshow/git-file.c index 7dc75a5..21810c0 100644 --- a/eeshow/git-file.c +++ b/eeshow/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/eeshow/git-hist.c b/eeshow/git-hist.c index 53e66c5..3367b9d 100644 --- a/eeshow/git-hist.c +++ b/eeshow/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/eeshow/git-util.c b/eeshow/git-util.c new file mode 100644 index 0000000..71cf6cd --- /dev/null +++ b/eeshow/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 + +#include + +#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/eeshow/git-util.h b/eeshow/git-util.h new file mode 100644 index 0000000..601855a --- /dev/null +++ b/eeshow/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 */