Blame include/git2/sys/config.h

Packit Service 20376f
/*
Packit Service 20376f
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit Service 20376f
 *
Packit Service 20376f
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit Service 20376f
 * a Linking Exception. For full terms see the included COPYING file.
Packit Service 20376f
 */
Packit Service 20376f
#ifndef INCLUDE_sys_git_config_backend_h__
Packit Service 20376f
#define INCLUDE_sys_git_config_backend_h__
Packit Service 20376f
Packit Service 20376f
#include "git2/common.h"
Packit Service 20376f
#include "git2/types.h"
Packit Service 20376f
#include "git2/config.h"
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * @file git2/sys/config.h
Packit Service 20376f
 * @brief Git config backend routines
Packit Service 20376f
 * @defgroup git_backend Git custom backend APIs
Packit Service 20376f
 * @ingroup Git
Packit Service 20376f
 * @{
Packit Service 20376f
 */
Packit Service 20376f
GIT_BEGIN_DECL
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Every iterator must have this struct as its first element, so the
Packit Service 20376f
 * API can talk to it. You'd define your iterator as
Packit Service 20376f
 *
Packit Service 20376f
 *     struct my_iterator {
Packit Service 20376f
 *             git_config_iterator parent;
Packit Service 20376f
 *             ...
Packit Service 20376f
 *     }
Packit Service 20376f
 *
Packit Service 20376f
 * and assign `iter->parent.backend` to your `git_config_backend`.
Packit Service 20376f
 */
Packit Service 20376f
struct git_config_iterator {
Packit Service 20376f
	git_config_backend *backend;
Packit Service 20376f
	unsigned int flags;
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * Return the current entry and advance the iterator. The
Packit Service 20376f
	 * memory belongs to the library.
Packit Service 20376f
	 */
Packit Service 20376f
	int (*next)(git_config_entry **entry, git_config_iterator *iter);
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * Free the iterator
Packit Service 20376f
	 */
Packit Service 20376f
	void (*free)(git_config_iterator *iter);
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Generic backend that implements the interface to
Packit Service 20376f
 * access a configuration file
Packit Service 20376f
 */
Packit Service 20376f
struct git_config_backend {
Packit Service 20376f
	unsigned int version;
Packit Service 20376f
	/** True if this backend is for a snapshot */
Packit Service 20376f
	int readonly;
Packit Service 20376f
	struct git_config *cfg;
Packit Service 20376f
Packit Service 20376f
	/* Open means open the file/database and parse if necessary */
Packit Service 20376f
	int (*open)(struct git_config_backend *, git_config_level_t level);
Packit Service 20376f
	int (*get)(struct git_config_backend *, const char *key, git_config_entry **entry);
Packit Service 20376f
	int (*set)(struct git_config_backend *, const char *key, const char *value);
Packit Service 20376f
	int (*set_multivar)(git_config_backend *cfg, const char *name, const char *regexp, const char *value);
Packit Service 20376f
	int (*del)(struct git_config_backend *, const char *key);
Packit Service 20376f
	int (*del_multivar)(struct git_config_backend *, const char *key, const char *regexp);
Packit Service 20376f
	int (*iterator)(git_config_iterator **, struct git_config_backend *);
Packit Service 20376f
	/** Produce a read-only version of this backend */
Packit Service 20376f
	int (*snapshot)(struct git_config_backend **, struct git_config_backend *);
Packit Service 20376f
	/**
Packit Service 20376f
	 * Lock this backend.
Packit Service 20376f
	 *
Packit Service 20376f
	 * Prevent any writes to the data store backing this
Packit Service 20376f
	 * backend. Any updates must not be visible to any other
Packit Service 20376f
	 * readers.
Packit Service 20376f
	 */
Packit Service 20376f
	int (*lock)(struct git_config_backend *);
Packit Service 20376f
	/**
Packit Service 20376f
	 * Unlock the data store backing this backend. If success is
Packit Service 20376f
	 * true, the changes should be committed, otherwise rolled
Packit Service 20376f
	 * back.
Packit Service 20376f
	 */
Packit Service 20376f
	int (*unlock)(struct git_config_backend *, int success);
Packit Service 20376f
	void (*free)(struct git_config_backend *);
Packit Service 20376f
};
Packit Service 20376f
#define GIT_CONFIG_BACKEND_VERSION 1
Packit Service 20376f
#define GIT_CONFIG_BACKEND_INIT {GIT_CONFIG_BACKEND_VERSION}
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Initializes a `git_config_backend` with default values. Equivalent to
Packit Service 20376f
 * creating an instance with GIT_CONFIG_BACKEND_INIT.
Packit Service 20376f
 *
Packit Service 20376f
 * @param backend the `git_config_backend` struct to initialize.
Packit Service 20376f
 * @param version Version of struct; pass `GIT_CONFIG_BACKEND_VERSION`
Packit Service 20376f
 * @return Zero on success; -1 on failure.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_init_backend(
Packit Service 20376f
	git_config_backend *backend,
Packit Service 20376f
	unsigned int version);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Add a generic config file instance to an existing config
Packit Service 20376f
 *
Packit Service 20376f
 * Note that the configuration object will free the file
Packit Service 20376f
 * automatically.
Packit Service 20376f
 *
Packit Service 20376f
 * Further queries on this config object will access each
Packit Service 20376f
 * of the config file instances in order (instances with
Packit Service 20376f
 * a higher priority level will be accessed first).
Packit Service 20376f
 *
Packit Service 20376f
 * @param cfg the configuration to add the file to
Packit Service 20376f
 * @param file the configuration file (backend) to add
Packit Service 20376f
 * @param level the priority level of the backend
Packit Service 20376f
 * @param force if a config file already exists for the given
Packit Service 20376f
 *  priority level, replace it
Packit Service 20376f
 * @return 0 on success, GIT_EEXISTS when adding more than one file
Packit Service 20376f
 *  for a given priority level (and force_replace set to 0), or error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_config_add_backend(
Packit Service 20376f
	git_config *cfg,
Packit Service 20376f
	git_config_backend *file,
Packit Service 20376f
	git_config_level_t level,
Packit Service 20376f
	int force);
Packit Service 20376f
Packit Service 20376f
/** @} */
Packit Service 20376f
GIT_END_DECL
Packit Service 20376f
#endif