Blame include/git2/sys/mempack.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_mempack_h__
Packit Service 20376f
#define INCLUDE_sys_git_odb_mempack_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
#include "git2/buffer.h"
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * @file git2/sys/mempack.h
Packit Service 20376f
 * @brief Custom ODB backend that permits packing objects in-memory
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
 *	Instantiate a new mempack backend.
Packit Service 20376f
 *
Packit Service 20376f
 *	The backend must be added to an existing ODB with the highest
Packit Service 20376f
 *	priority.
Packit Service 20376f
 *
Packit Service 20376f
 *		git_mempack_new(&mempacker);
Packit Service 20376f
 *		git_repository_odb(&odb, repository);
Packit Service 20376f
 *		git_odb_add_backend(odb, mempacker, 999);
Packit Service 20376f
 *
Packit Service 20376f
 *	Once the backend has been loaded, all writes to the ODB will
Packit Service 20376f
 *	instead be queued in memory, and can be finalized with
Packit Service 20376f
 *	`git_mempack_dump`.
Packit Service 20376f
 *
Packit Service 20376f
 *	Subsequent reads will also be served from the in-memory store
Packit Service 20376f
 *	to ensure consistency, until the memory store is dumped.
Packit Service 20376f
 *
Packit Service 20376f
 *	@param out Pointer where to store the ODB backend
Packit Service 20376f
 *	@return 0 on success; error code otherwise
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_mempack_new(git_odb_backend **out);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 *	Dump all the queued in-memory writes to a packfile.
Packit Service 20376f
 *
Packit Service 20376f
 *	The contents of the packfile will be stored in the given buffer.
Packit Service 20376f
 *	It is the caller's responsibility to ensure that the generated
Packit Service 20376f
 *	packfile is available to the repository (e.g. by writing it
Packit Service 20376f
 *	to disk, or doing something crazy like distributing it across
Packit Service 20376f
 *	several copies of the repository over a network).
Packit Service 20376f
 *
Packit Service 20376f
 *	Once the generated packfile is available to the repository,
Packit Service 20376f
 *	call `git_mempack_reset` to cleanup the memory store.
Packit Service 20376f
 *
Packit Service 20376f
 *	Calling `git_mempack_reset` before the packfile has been
Packit Service 20376f
 *	written to disk will result in an inconsistent repository
Packit Service 20376f
 *	(the objects in the memory store won't be accessible).
Packit Service 20376f
 *
Packit Service 20376f
 *	@param pack Buffer where to store the raw packfile
Packit Service 20376f
 *	@param repo The active repository where the backend is loaded
Packit Service 20376f
 *	@param backend The mempack backend
Packit Service 20376f
 *	@return 0 on success; error code otherwise
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_mempack_dump(git_buf *pack, git_repository *repo, git_odb_backend *backend);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 *	Reset the memory packer by clearing all the queued objects.
Packit Service 20376f
 *
Packit Service 20376f
 *	This assumes that `git_mempack_dump` has been called before to
Packit Service 20376f
 *	store all the queued objects into a single packfile.
Packit Service 20376f
 *
Packit Service 20376f
 *	Alternatively, call `reset` without a previous dump to "undo"
Packit Service 20376f
 *	all the recently written objects, giving transaction-like
Packit Service 20376f
 *	semantics to the Git repository.
Packit Service 20376f
 *
Packit Service 20376f
 *	@param backend The mempack backend
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(void) git_mempack_reset(git_odb_backend *backend);
Packit Service 20376f
Packit Service 20376f
GIT_END_DECL
Packit Service 20376f
Packit Service 20376f
#endif