Blame include/git2/sys/odb_backend.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_odb_backend_h__
Packit Service 20376f
#define INCLUDE_sys_git_odb_backend_h__
Packit Service 20376f
Packit Service 20376f
#include "git2/common.h"
Packit Service 20376f
#include "git2/types.h"
Packit Service 20376f
#include "git2/oid.h"
Packit Service 20376f
#include "git2/odb.h"
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * @file git2/sys/backend.h
Packit Service 20376f
 * @brief Git custom backend implementors functions
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
 * An instance for a custom backend
Packit Service 20376f
 */
Packit Service 20376f
struct git_odb_backend {
Packit Service 20376f
	unsigned int version;
Packit Service 20376f
	git_odb *odb;
Packit Service 20376f
Packit Service 20376f
	/* read and read_prefix each return to libgit2 a buffer which
Packit Service 20376f
	 * will be freed later. The buffer should be allocated using
Packit Service 20376f
	 * the function git_odb_backend_malloc to ensure that it can
Packit Service 20376f
	 * be safely freed later. */
Packit Service 20376f
	int (* read)(
Packit Service 20376f
		void **, size_t *, git_otype *, git_odb_backend *, const git_oid *);
Packit Service 20376f
Packit Service 20376f
	/* To find a unique object given a prefix of its oid.  The oid given
Packit Service 20376f
	 * must be so that the remaining (GIT_OID_HEXSZ - len)*4 bits are 0s.
Packit Service 20376f
	 */
Packit Service 20376f
	int (* read_prefix)(
Packit Service 20376f
		git_oid *, void **, size_t *, git_otype *,
Packit Service 20376f
		git_odb_backend *, const git_oid *, size_t);
Packit Service 20376f
Packit Service 20376f
	int (* read_header)(
Packit Service 20376f
		size_t *, git_otype *, git_odb_backend *, const git_oid *);
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * Write an object into the backend. The id of the object has
Packit Service 20376f
	 * already been calculated and is passed in.
Packit Service 20376f
	 */
Packit Service 20376f
	int (* write)(
Packit Service 20376f
		git_odb_backend *, const git_oid *, const void *, size_t, git_otype);
Packit Service 20376f
Packit Service 20376f
	int (* writestream)(
Packit Service 20376f
		git_odb_stream **, git_odb_backend *, git_off_t, git_otype);
Packit Service 20376f
Packit Service 20376f
	int (* readstream)(
Packit Service 20376f
		git_odb_stream **, git_odb_backend *, const git_oid *);
Packit Service 20376f
Packit Service 20376f
	int (* exists)(
Packit Service 20376f
		git_odb_backend *, const git_oid *);
Packit Service 20376f
Packit Service 20376f
	int (* exists_prefix)(
Packit Service 20376f
		git_oid *, git_odb_backend *, const git_oid *, size_t);
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * If the backend implements a refreshing mechanism, it should be exposed
Packit Service 20376f
	 * through this endpoint. Each call to `git_odb_refresh()` will invoke it.
Packit Service 20376f
	 *
Packit Service 20376f
	 * However, the backend implementation should try to stay up-to-date as much
Packit Service 20376f
	 * as possible by itself as libgit2 will not automatically invoke
Packit Service 20376f
	 * `git_odb_refresh()`. For instance, a potential strategy for the backend
Packit Service 20376f
	 * implementation to achieve this could be to internally invoke this
Packit Service 20376f
	 * endpoint on failed lookups (ie. `exists()`, `read()`, `read_header()`).
Packit Service 20376f
	 */
Packit Service 20376f
	int (* refresh)(git_odb_backend *);
Packit Service 20376f
Packit Service 20376f
	int (* foreach)(
Packit Service 20376f
		git_odb_backend *, git_odb_foreach_cb cb, void *payload);
Packit Service 20376f
Packit Service 20376f
	int (* writepack)(
Packit Service 20376f
		git_odb_writepack **, git_odb_backend *, git_odb *odb,
Packit Service 20376f
		git_transfer_progress_cb progress_cb, void *progress_payload);
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * "Freshens" an already existing object, updating its last-used
Packit Service 20376f
	 * time.  This occurs when `git_odb_write` was called, but the
Packit Service 20376f
	 * object already existed (and will not be re-written).  The
Packit Service 20376f
	 * underlying implementation may want to update last-used timestamps.
Packit Service 20376f
	 *
Packit Service 20376f
	 * If callers implement this, they should return `0` if the object
Packit Service 20376f
	 * exists and was freshened, and non-zero otherwise.
Packit Service 20376f
	 */
Packit Service 20376f
	int (* freshen)(git_odb_backend *, const git_oid *);
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * Frees any resources held by the odb (including the `git_odb_backend`
Packit Service 20376f
	 * itself). An odb backend implementation must provide this function.
Packit Service 20376f
	 */
Packit Service 20376f
	void (* free)(git_odb_backend *);
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
#define GIT_ODB_BACKEND_VERSION 1
Packit Service 20376f
#define GIT_ODB_BACKEND_INIT {GIT_ODB_BACKEND_VERSION}
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Initializes a `git_odb_backend` with default values. Equivalent to
Packit Service 20376f
 * creating an instance with GIT_ODB_BACKEND_INIT.
Packit Service 20376f
 *
Packit Service 20376f
 * @param backend the `git_odb_backend` struct to initialize.
Packit Service 20376f
 * @param version Version the struct; pass `GIT_ODB_BACKEND_VERSION`
Packit Service 20376f
 * @return Zero on success; -1 on failure.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_odb_init_backend(
Packit Service 20376f
	git_odb_backend *backend,
Packit Service 20376f
	unsigned int version);
Packit Service 20376f
Packit Service 20376f
GIT_EXTERN(void *) git_odb_backend_malloc(git_odb_backend *backend, size_t len);
Packit Service 20376f
Packit Service 20376f
GIT_END_DECL
Packit Service 20376f
Packit Service 20376f
#endif