mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-29 19:59:43 +02:00
eeshow/git-util.c, git-util.h: new place for things like git_*init*
This commit is contained in:
parent
3eaf4567fa
commit
7dc1211cfd
@ -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 \
|
||||
|
@ -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;
|
||||
|
@ -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)) {
|
||||
|
35
eeshow/git-util.c
Normal file
35
eeshow/git-util.c
Normal file
@ -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;
|
||||
}
|
||||
}
|
18
eeshow/git-util.h
Normal file
18
eeshow/git-util.h
Normal file
@ -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 */
|
Loading…
Reference in New Issue
Block a user