|
Packit |
ae9e2a |
/*
|
|
Packit |
ae9e2a |
* Copyright (C) the libgit2 contributors. All rights reserved.
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
|
Packit |
ae9e2a |
* a Linking Exception. For full terms see the included COPYING file.
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
#ifndef INCLUDE_git_odb_backend_h__
|
|
Packit |
ae9e2a |
#define INCLUDE_git_odb_backend_h__
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
#include "common.h"
|
|
Packit |
ae9e2a |
#include "types.h"
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/**
|
|
Packit |
ae9e2a |
* @file git2/backend.h
|
|
Packit |
ae9e2a |
* @brief Git custom backend functions
|
|
Packit |
ae9e2a |
* @defgroup git_odb Git object database routines
|
|
Packit |
ae9e2a |
* @ingroup Git
|
|
Packit |
ae9e2a |
* @{
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
GIT_BEGIN_DECL
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/*
|
|
Packit |
ae9e2a |
* Constructors for in-box ODB backends.
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/**
|
|
Packit |
ae9e2a |
* Create a backend for the packfiles.
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* @param out location to store the odb backend pointer
|
|
Packit |
ae9e2a |
* @param objects_dir the Git repository's objects directory
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* @return 0 or an error code
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **out, const char *objects_dir);
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/**
|
|
Packit |
ae9e2a |
* Create a backend for loose objects
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* @param out location to store the odb backend pointer
|
|
Packit |
ae9e2a |
* @param objects_dir the Git repository's objects directory
|
|
Packit |
ae9e2a |
* @param compression_level zlib compression level to use
|
|
Packit |
ae9e2a |
* @param do_fsync whether to do an fsync() after writing
|
|
Packit |
ae9e2a |
* @param dir_mode permissions to use creating a directory or 0 for defaults
|
|
Packit |
ae9e2a |
* @param file_mode permissions to use creating a file or 0 for defaults
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* @return 0 or an error code
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
GIT_EXTERN(int) git_odb_backend_loose(
|
|
Packit |
ae9e2a |
git_odb_backend **out,
|
|
Packit |
ae9e2a |
const char *objects_dir,
|
|
Packit |
ae9e2a |
int compression_level,
|
|
Packit |
ae9e2a |
int do_fsync,
|
|
Packit |
ae9e2a |
unsigned int dir_mode,
|
|
Packit |
ae9e2a |
unsigned int file_mode);
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/**
|
|
Packit |
ae9e2a |
* Create a backend out of a single packfile
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* This can be useful for inspecting the contents of a single
|
|
Packit |
ae9e2a |
* packfile.
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* @param out location to store the odb backend pointer
|
|
Packit |
ae9e2a |
* @param index_file path to the packfile's .idx file
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* @return 0 or an error code
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
GIT_EXTERN(int) git_odb_backend_one_pack(git_odb_backend **out, const char *index_file);
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/** Streaming mode */
|
|
Packit |
ae9e2a |
typedef enum {
|
|
Packit |
ae9e2a |
GIT_STREAM_RDONLY = (1 << 1),
|
|
Packit |
ae9e2a |
GIT_STREAM_WRONLY = (1 << 2),
|
|
Packit |
ae9e2a |
GIT_STREAM_RW = (GIT_STREAM_RDONLY | GIT_STREAM_WRONLY),
|
|
Packit |
ae9e2a |
} git_odb_stream_t;
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/**
|
|
Packit |
ae9e2a |
* A stream to read/write from a backend.
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* This represents a stream of data being written to or read from a
|
|
Packit |
ae9e2a |
* backend. When writing, the frontend functions take care of
|
|
Packit |
ae9e2a |
* calculating the object's id and all `finalize_write` needs to do is
|
|
Packit |
ae9e2a |
* store the object with the id it is passed.
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
struct git_odb_stream {
|
|
Packit |
ae9e2a |
git_odb_backend *backend;
|
|
Packit |
ae9e2a |
unsigned int mode;
|
|
Packit |
ae9e2a |
void *hash_ctx;
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
git_off_t declared_size;
|
|
Packit |
ae9e2a |
git_off_t received_bytes;
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/**
|
|
Packit |
ae9e2a |
* Write at most `len` bytes into `buffer` and advance the stream.
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
int (*read)(git_odb_stream *stream, char *buffer, size_t len);
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/**
|
|
Packit |
ae9e2a |
* Write `len` bytes from `buffer` into the stream.
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
int (*write)(git_odb_stream *stream, const char *buffer, size_t len);
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/**
|
|
Packit |
ae9e2a |
* Store the contents of the stream as an object with the id
|
|
Packit |
ae9e2a |
* specified in `oid`.
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* This method might not be invoked if:
|
|
Packit |
ae9e2a |
* - an error occurs earlier with the `write` callback,
|
|
Packit |
ae9e2a |
* - the object referred to by `oid` already exists in any backend, or
|
|
Packit |
ae9e2a |
* - the final number of received bytes differs from the size declared
|
|
Packit |
ae9e2a |
* with `git_odb_open_wstream()`
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
int (*finalize_write)(git_odb_stream *stream, const git_oid *oid);
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/**
|
|
Packit |
ae9e2a |
* Free the stream's memory.
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* This method might be called without a call to `finalize_write` if
|
|
Packit |
ae9e2a |
* an error occurs or if the object is already present in the ODB.
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
void (*free)(git_odb_stream *stream);
|
|
Packit |
ae9e2a |
};
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/** A stream to write a pack file to the ODB */
|
|
Packit |
ae9e2a |
struct git_odb_writepack {
|
|
Packit |
ae9e2a |
git_odb_backend *backend;
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
int (*append)(git_odb_writepack *writepack, const void *data, size_t size, git_transfer_progress *stats);
|
|
Packit |
ae9e2a |
int (*commit)(git_odb_writepack *writepack, git_transfer_progress *stats);
|
|
Packit |
ae9e2a |
void (*free)(git_odb_writepack *writepack);
|
|
Packit |
ae9e2a |
};
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
GIT_END_DECL
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
#endif
|