Blame include/git2/odb.h

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_h__
Packit ae9e2a
#define INCLUDE_git_odb_h__
Packit ae9e2a
Packit ae9e2a
#include "common.h"
Packit ae9e2a
#include "types.h"
Packit ae9e2a
#include "oid.h"
Packit ae9e2a
#include "oidarray.h"
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * @file git2/odb.h
Packit ae9e2a
 * @brief Git object database routines
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
 * Function type for callbacks from git_odb_foreach.
Packit ae9e2a
 */
Packit ae9e2a
typedef int (*git_odb_foreach_cb)(const git_oid *id, void *payload);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Create a new object database with no backends.
Packit ae9e2a
 *
Packit ae9e2a
 * Before the ODB can be used for read/writing, a custom database
Packit ae9e2a
 * backend must be manually added using `git_odb_add_backend()`
Packit ae9e2a
 *
Packit ae9e2a
 * @param out location to store the database pointer, if opened.
Packit ae9e2a
 *			Set to NULL if the open failed.
Packit ae9e2a
 * @return 0 or an error code
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_odb_new(git_odb **out);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Create a new object database and automatically add
Packit ae9e2a
 * the two default backends:
Packit ae9e2a
 *
Packit ae9e2a
 *	- git_odb_backend_loose: read and write loose object files
Packit ae9e2a
 *		from disk, assuming `objects_dir` as the Objects folder
Packit ae9e2a
 *
Packit ae9e2a
 *	- git_odb_backend_pack: read objects from packfiles,
Packit ae9e2a
 *		assuming `objects_dir` as the Objects folder which
Packit ae9e2a
 *		contains a 'pack/' folder with the corresponding data
Packit ae9e2a
 *
Packit ae9e2a
 * @param out location to store the database pointer, if opened.
Packit ae9e2a
 *			Set to NULL if the open failed.
Packit ae9e2a
 * @param objects_dir path of the backends' "objects" directory.
Packit ae9e2a
 * @return 0 or an error code
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_odb_open(git_odb **out, const char *objects_dir);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Add an on-disk alternate to an existing Object DB.
Packit ae9e2a
 *
Packit ae9e2a
 * Note that the added path must point to an `objects`, not
Packit ae9e2a
 * to a full repository, to use it as an alternate store.
Packit ae9e2a
 *
Packit ae9e2a
 * Alternate backends are always checked for objects *after*
Packit ae9e2a
 * all the main backends have been exhausted.
Packit ae9e2a
 *
Packit ae9e2a
 * Writing is disabled on alternate backends.
Packit ae9e2a
 *
Packit ae9e2a
 * @param odb database to add the backend to
Packit ae9e2a
 * @param path path to the objects folder for the alternate
Packit ae9e2a
 * @return 0 on success; error code otherwise
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_odb_add_disk_alternate(git_odb *odb, const char *path);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Close an open object database.
Packit ae9e2a
 *
Packit ae9e2a
 * @param db database pointer to close. If NULL no action is taken.
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(void) git_odb_free(git_odb *db);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Read an object from the database.
Packit ae9e2a
 *
Packit ae9e2a
 * This method queries all available ODB backends
Packit ae9e2a
 * trying to read the given OID.
Packit ae9e2a
 *
Packit ae9e2a
 * The returned object is reference counted and
Packit ae9e2a
 * internally cached, so it should be closed
Packit ae9e2a
 * by the user once it's no longer in use.
Packit ae9e2a
 *
Packit ae9e2a
 * @param out pointer where to store the read object
Packit ae9e2a
 * @param db database to search for the object in.
Packit ae9e2a
 * @param id identity of the object to read.
Packit ae9e2a
 * @return
Packit ae9e2a
 * - 0 if the object was read;
Packit ae9e2a
 * - GIT_ENOTFOUND if the object is not in the database.
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_odb_read(git_odb_object **out, git_odb *db, const git_oid *id);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Read an object from the database, given a prefix
Packit ae9e2a
 * of its identifier.
Packit ae9e2a
 *
Packit ae9e2a
 * This method queries all available ODB backends
Packit ae9e2a
 * trying to match the 'len' first hexadecimal
Packit ae9e2a
 * characters of the 'short_id'.
Packit ae9e2a
 * The remaining (GIT_OID_HEXSZ-len)*4 bits of
Packit ae9e2a
 * 'short_id' must be 0s.
Packit ae9e2a
 * 'len' must be at least GIT_OID_MINPREFIXLEN,
Packit ae9e2a
 * and the prefix must be long enough to identify
Packit ae9e2a
 * a unique object in all the backends; the
Packit ae9e2a
 * method will fail otherwise.
Packit ae9e2a
 *
Packit ae9e2a
 * The returned object is reference counted and
Packit ae9e2a
 * internally cached, so it should be closed
Packit ae9e2a
 * by the user once it's no longer in use.
Packit ae9e2a
 *
Packit ae9e2a
 * @param out pointer where to store the read object
Packit ae9e2a
 * @param db database to search for the object in.
Packit ae9e2a
 * @param short_id a prefix of the id of the object to read.
Packit ae9e2a
 * @param len the length of the prefix
Packit ae9e2a
 * @return
Packit ae9e2a
 * - 0 if the object was read;
Packit ae9e2a
 * - GIT_ENOTFOUND if the object is not in the database.
Packit ae9e2a
 * - GIT_EAMBIGUOUS if the prefix is ambiguous (several objects match the prefix)
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_odb_read_prefix(git_odb_object **out, git_odb *db, const git_oid *short_id, size_t len);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Read the header of an object from the database, without
Packit ae9e2a
 * reading its full contents.
Packit ae9e2a
 *
Packit ae9e2a
 * The header includes the length and the type of an object.
Packit ae9e2a
 *
Packit ae9e2a
 * Note that most backends do not support reading only the header
Packit ae9e2a
 * of an object, so the whole object will be read and then the
Packit ae9e2a
 * header will be returned.
Packit ae9e2a
 *
Packit ae9e2a
 * @param len_out pointer where to store the length
Packit ae9e2a
 * @param type_out pointer where to store the type
Packit ae9e2a
 * @param db database to search for the object in.
Packit ae9e2a
 * @param id identity of the object to read.
Packit ae9e2a
 * @return
Packit ae9e2a
 * - 0 if the object was read;
Packit ae9e2a
 * - GIT_ENOTFOUND if the object is not in the database.
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_odb_read_header(size_t *len_out, git_otype *type_out, git_odb *db, const git_oid *id);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Determine if the given object can be found in the object database.
Packit ae9e2a
 *
Packit ae9e2a
 * @param db database to be searched for the given object.
Packit ae9e2a
 * @param id the object to search for.
Packit ae9e2a
 * @return
Packit ae9e2a
 * - 1, if the object was found
Packit ae9e2a
 * - 0, otherwise
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_odb_exists(git_odb *db, const git_oid *id);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Determine if an object can be found in the object database by an
Packit ae9e2a
 * abbreviated object ID.
Packit ae9e2a
 *
Packit ae9e2a
 * @param out The full OID of the found object if just one is found.
Packit ae9e2a
 * @param db The database to be searched for the given object.
Packit ae9e2a
 * @param short_id A prefix of the id of the object to read.
Packit ae9e2a
 * @param len The length of the prefix.
Packit ae9e2a
 * @return 0 if found, GIT_ENOTFOUND if not found, GIT_EAMBIGUOUS if multiple
Packit ae9e2a
 *         matches were found, other value < 0 if there was a read error.
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_odb_exists_prefix(
Packit ae9e2a
	git_oid *out, git_odb *db, const git_oid *short_id, size_t len);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * The information about object IDs to query in `git_odb_expand_ids`,
Packit ae9e2a
 * which will be populated upon return.
Packit ae9e2a
 */
Packit ae9e2a
typedef struct git_odb_expand_id {
Packit ae9e2a
	/** The object ID to expand */
Packit ae9e2a
	git_oid id;
Packit ae9e2a
Packit ae9e2a
	/**
Packit ae9e2a
	 * The length of the object ID (in nibbles, or packets of 4 bits; the
Packit ae9e2a
	 * number of hex characters)
Packit ae9e2a
	 * */
Packit ae9e2a
	unsigned short length;
Packit ae9e2a
Packit ae9e2a
	/**
Packit ae9e2a
	 * The (optional) type of the object to search for; leave as `0` or set
Packit ae9e2a
	 * to `GIT_OBJ_ANY` to query for any object matching the ID.
Packit ae9e2a
	 */
Packit ae9e2a
	git_otype type;
Packit ae9e2a
} git_odb_expand_id;
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Determine if one or more objects can be found in the object database
Packit ae9e2a
 * by their abbreviated object ID and type.  The given array will be
Packit ae9e2a
 * updated in place:  for each abbreviated ID that is unique in the
Packit ae9e2a
 * database, and of the given type (if specified), the full object ID,
Packit ae9e2a
 * object ID length (`GIT_OID_HEXSZ`) and type will be written back to
Packit ae9e2a
 * the array.  For IDs that are not found (or are ambiguous), the
Packit ae9e2a
 * array entry will be zeroed.
Packit ae9e2a
 *
Packit ae9e2a
 * Note that since this function operates on multiple objects, the
Packit ae9e2a
 * underlying database will not be asked to be reloaded if an object is
Packit ae9e2a
 * not found (which is unlike other object database operations.)
Packit ae9e2a
 *
Packit ae9e2a
 * @param db The database to be searched for the given objects.
Packit ae9e2a
 * @param ids An array of short object IDs to search for
Packit ae9e2a
 * @param count The length of the `ids` array
Packit ae9e2a
 * @return 0 on success or an error code on failure
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_odb_expand_ids(
Packit ae9e2a
	git_odb *db,
Packit ae9e2a
	git_odb_expand_id *ids,
Packit ae9e2a
	size_t count);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Refresh the object database to load newly added files.
Packit ae9e2a
 *
Packit ae9e2a
 * If the object databases have changed on disk while the library
Packit ae9e2a
 * is running, this function will force a reload of the underlying
Packit ae9e2a
 * indexes.
Packit ae9e2a
 *
Packit ae9e2a
 * Use this function when you're confident that an external
Packit ae9e2a
 * application has tampered with the ODB.
Packit ae9e2a
 *
Packit ae9e2a
 * NOTE that it is not necessary to call this function at all. The
Packit ae9e2a
 * library will automatically attempt to refresh the ODB
Packit ae9e2a
 * when a lookup fails, to see if the looked up object exists
Packit ae9e2a
 * on disk but hasn't been loaded yet.
Packit ae9e2a
 *
Packit ae9e2a
 * @param db database to refresh
Packit ae9e2a
 * @return 0 on success, error code otherwise
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_odb_refresh(struct git_odb *db);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * List all objects available in the database
Packit ae9e2a
 *
Packit ae9e2a
 * The callback will be called for each object available in the
Packit ae9e2a
 * database. Note that the objects are likely to be returned in the index
Packit ae9e2a
 * order, which would make accessing the objects in that order inefficient.
Packit ae9e2a
 * Return a non-zero value from the callback to stop looping.
Packit ae9e2a
 *
Packit ae9e2a
 * @param db database to use
Packit ae9e2a
 * @param cb the callback to call for each object
Packit ae9e2a
 * @param payload data to pass to the callback
Packit ae9e2a
 * @return 0 on success, non-zero callback return value, or error code
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_odb_foreach(git_odb *db, git_odb_foreach_cb cb, void *payload);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Write an object directly into the ODB
Packit ae9e2a
 *
Packit ae9e2a
 * This method writes a full object straight into the ODB.
Packit ae9e2a
 * For most cases, it is preferred to write objects through a write
Packit ae9e2a
 * stream, which is both faster and less memory intensive, specially
Packit ae9e2a
 * for big objects.
Packit ae9e2a
 *
Packit ae9e2a
 * This method is provided for compatibility with custom backends
Packit ae9e2a
 * which are not able to support streaming writes
Packit ae9e2a
 *
Packit ae9e2a
 * @param out pointer to store the OID result of the write
Packit ae9e2a
 * @param odb object database where to store the object
Packit ae9e2a
 * @param data buffer with the data to store
Packit ae9e2a
 * @param len size of the buffer
Packit ae9e2a
 * @param type type of the data to store
Packit ae9e2a
 * @return 0 or an error code
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_odb_write(git_oid *out, git_odb *odb, const void *data, size_t len, git_otype type);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Open a stream to write an object into the ODB
Packit ae9e2a
 *
Packit ae9e2a
 * The type and final length of the object must be specified
Packit ae9e2a
 * when opening the stream.
Packit ae9e2a
 *
Packit ae9e2a
 * The returned stream will be of type `GIT_STREAM_WRONLY`, and it
Packit ae9e2a
 * won't be effective until `git_odb_stream_finalize_write` is called
Packit ae9e2a
 * and returns without an error
Packit ae9e2a
 *
Packit ae9e2a
 * The stream must always be freed when done with `git_odb_stream_free` or
Packit ae9e2a
 * will leak memory.
Packit ae9e2a
 *
Packit ae9e2a
 * @see git_odb_stream
Packit ae9e2a
 *
Packit ae9e2a
 * @param out pointer where to store the stream
Packit ae9e2a
 * @param db object database where the stream will write
Packit ae9e2a
 * @param size final size of the object that will be written
Packit ae9e2a
 * @param type type of the object that will be written
Packit ae9e2a
 * @return 0 if the stream was created; error code otherwise
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_odb_open_wstream(git_odb_stream **out, git_odb *db, git_off_t size, git_otype type);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Write to an odb stream
Packit ae9e2a
 *
Packit ae9e2a
 * This method will fail if the total number of received bytes exceeds the
Packit ae9e2a
 * size declared with `git_odb_open_wstream()`
Packit ae9e2a
 *
Packit ae9e2a
 * @param stream the stream
Packit ae9e2a
 * @param buffer the data to write
Packit ae9e2a
 * @param len the buffer's length
Packit ae9e2a
 * @return 0 if the write succeeded; error code otherwise
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_odb_stream_write(git_odb_stream *stream, const char *buffer, size_t len);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Finish writing to an odb stream
Packit ae9e2a
 *
Packit ae9e2a
 * The object will take its final name and will be available to the
Packit ae9e2a
 * odb.
Packit ae9e2a
 *
Packit ae9e2a
 * This method will fail if the total number of received bytes
Packit ae9e2a
 * differs from the size declared with `git_odb_open_wstream()`
Packit ae9e2a
 *
Packit ae9e2a
 * @param out pointer to store the resulting object's id
Packit ae9e2a
 * @param stream the stream
Packit ae9e2a
 * @return 0 on success; an error code otherwise
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_odb_stream_finalize_write(git_oid *out, git_odb_stream *stream);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Read from an odb stream
Packit ae9e2a
 *
Packit ae9e2a
 * Most backends don't implement streaming reads
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_odb_stream_read(git_odb_stream *stream, char *buffer, size_t len);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Free an odb stream
Packit ae9e2a
 *
Packit ae9e2a
 * @param stream the stream to free
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(void) git_odb_stream_free(git_odb_stream *stream);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Open a stream to read an object from the ODB
Packit ae9e2a
 *
Packit ae9e2a
 * Note that most backends do *not* support streaming reads
Packit ae9e2a
 * because they store their objects as compressed/delta'ed blobs.
Packit ae9e2a
 *
Packit ae9e2a
 * It's recommended to use `git_odb_read` instead, which is
Packit ae9e2a
 * assured to work on all backends.
Packit ae9e2a
 *
Packit ae9e2a
 * The returned stream will be of type `GIT_STREAM_RDONLY` and
Packit ae9e2a
 * will have the following methods:
Packit ae9e2a
 *
Packit ae9e2a
 *		- stream->read: read `n` bytes from the stream
Packit ae9e2a
 *		- stream->free: free the stream
Packit ae9e2a
 *
Packit ae9e2a
 * The stream must always be free'd or will leak memory.
Packit ae9e2a
 *
Packit ae9e2a
 * @see git_odb_stream
Packit ae9e2a
 *
Packit ae9e2a
 * @param out pointer where to store the stream
Packit ae9e2a
 * @param db object database where the stream will read from
Packit ae9e2a
 * @param oid oid of the object the stream will read from
Packit ae9e2a
 * @return 0 if the stream was created; error code otherwise
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_odb_open_rstream(git_odb_stream **out, git_odb *db, const git_oid *oid);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Open a stream for writing a pack file to the ODB.
Packit ae9e2a
 *
Packit ae9e2a
 * If the ODB layer understands pack files, then the given
Packit ae9e2a
 * packfile will likely be streamed directly to disk (and a
Packit ae9e2a
 * corresponding index created).  If the ODB layer does not
Packit ae9e2a
 * understand pack files, the objects will be stored in whatever
Packit ae9e2a
 * format the ODB layer uses.
Packit ae9e2a
 *
Packit ae9e2a
 * @see git_odb_writepack
Packit ae9e2a
 *
Packit ae9e2a
 * @param out pointer to the writepack functions
Packit ae9e2a
 * @param db object database where the stream will read from
Packit ae9e2a
 * @param progress_cb function to call with progress information.
Packit ae9e2a
 * Be aware that this is called inline with network and indexing operations,
Packit ae9e2a
 * so performance may be affected.
Packit ae9e2a
 * @param progress_payload payload for the progress callback
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_odb_write_pack(
Packit ae9e2a
	git_odb_writepack **out,
Packit ae9e2a
	git_odb *db,
Packit ae9e2a
	git_transfer_progress_cb progress_cb,
Packit ae9e2a
	void *progress_payload);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Determine the object-ID (sha1 hash) of a data buffer
Packit ae9e2a
 *
Packit ae9e2a
 * The resulting SHA-1 OID will be the identifier for the data
Packit ae9e2a
 * buffer as if the data buffer it were to written to the ODB.
Packit ae9e2a
 *
Packit ae9e2a
 * @param out the resulting object-ID.
Packit ae9e2a
 * @param data data to hash
Packit ae9e2a
 * @param len size of the data
Packit ae9e2a
 * @param type of the data to hash
Packit ae9e2a
 * @return 0 or an error code
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_odb_hash(git_oid *out, const void *data, size_t len, git_otype type);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Read a file from disk and fill a git_oid with the object id
Packit ae9e2a
 * that the file would have if it were written to the Object
Packit ae9e2a
 * Database as an object of the given type (w/o applying filters).
Packit ae9e2a
 * Similar functionality to git.git's `git hash-object` without
Packit ae9e2a
 * the `-w` flag, however, with the --no-filters flag.
Packit ae9e2a
 * If you need filters, see git_repository_hashfile.
Packit ae9e2a
 *
Packit ae9e2a
 * @param out oid structure the result is written into.
Packit ae9e2a
 * @param path file to read and determine object id for
Packit ae9e2a
 * @param type the type of the object that will be hashed
Packit ae9e2a
 * @return 0 or an error code
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_odb_hashfile(git_oid *out, const char *path, git_otype type);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Create a copy of an odb_object
Packit ae9e2a
 *
Packit ae9e2a
 * The returned copy must be manually freed with `git_odb_object_free`.
Packit ae9e2a
 * Note that because of an implementation detail, the returned copy will be
Packit ae9e2a
 * the same pointer as `source`: the object is internally refcounted, so the
Packit ae9e2a
 * copy still needs to be freed twice.
Packit ae9e2a
 *
Packit ae9e2a
 * @param dest pointer where to store the copy
Packit ae9e2a
 * @param source object to copy
Packit ae9e2a
 * @return 0 or an error code
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_odb_object_dup(git_odb_object **dest, git_odb_object *source);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Close an ODB object
Packit ae9e2a
 *
Packit ae9e2a
 * This method must always be called once a `git_odb_object` is no
Packit ae9e2a
 * longer needed, otherwise memory will leak.
Packit ae9e2a
 *
Packit ae9e2a
 * @param object object to close
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(void) git_odb_object_free(git_odb_object *object);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Return the OID of an ODB object
Packit ae9e2a
 *
Packit ae9e2a
 * This is the OID from which the object was read from
Packit ae9e2a
 *
Packit ae9e2a
 * @param object the object
Packit ae9e2a
 * @return a pointer to the OID
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(const git_oid *) git_odb_object_id(git_odb_object *object);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Return the data of an ODB object
Packit ae9e2a
 *
Packit ae9e2a
 * This is the uncompressed, raw data as read from the ODB,
Packit ae9e2a
 * without the leading header.
Packit ae9e2a
 *
Packit ae9e2a
 * This pointer is owned by the object and shall not be free'd.
Packit ae9e2a
 *
Packit ae9e2a
 * @param object the object
Packit ae9e2a
 * @return a pointer to the data
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(const void *) git_odb_object_data(git_odb_object *object);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Return the size of an ODB object
Packit ae9e2a
 *
Packit ae9e2a
 * This is the real size of the `data` buffer, not the
Packit ae9e2a
 * actual size of the object.
Packit ae9e2a
 *
Packit ae9e2a
 * @param object the object
Packit ae9e2a
 * @return the size
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(size_t) git_odb_object_size(git_odb_object *object);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Return the type of an ODB object
Packit ae9e2a
 *
Packit ae9e2a
 * @param object the object
Packit ae9e2a
 * @return the type
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(git_otype) git_odb_object_type(git_odb_object *object);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Add a custom backend to an existing Object DB
Packit ae9e2a
 *
Packit ae9e2a
 * The backends are checked in relative ordering, based on the
Packit ae9e2a
 * value of the `priority` parameter.
Packit ae9e2a
 *
Packit ae9e2a
 * Read <sys/odb_backend.h> for more information.
Packit ae9e2a
 *
Packit ae9e2a
 * @param odb database to add the backend to
Packit ae9e2a
 * @param backend pointer to a git_odb_backend instance
Packit ae9e2a
 * @param priority Value for ordering the backends queue
Packit ae9e2a
 * @return 0 on success; error code otherwise
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_odb_add_backend(git_odb *odb, git_odb_backend *backend, int priority);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Add a custom backend to an existing Object DB; this
Packit ae9e2a
 * backend will work as an alternate.
Packit ae9e2a
 *
Packit ae9e2a
 * Alternate backends are always checked for objects *after*
Packit ae9e2a
 * all the main backends have been exhausted.
Packit ae9e2a
 *
Packit ae9e2a
 * The backends are checked in relative ordering, based on the
Packit ae9e2a
 * value of the `priority` parameter.
Packit ae9e2a
 *
Packit ae9e2a
 * Writing is disabled on alternate backends.
Packit ae9e2a
 *
Packit ae9e2a
 * Read <sys/odb_backend.h> for more information.
Packit ae9e2a
 *
Packit ae9e2a
 * @param odb database to add the backend to
Packit ae9e2a
 * @param backend pointer to a git_odb_backend instance
Packit ae9e2a
 * @param priority Value for ordering the backends queue
Packit ae9e2a
 * @return 0 on success; error code otherwise
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, int priority);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Get the number of ODB backend objects
Packit ae9e2a
 *
Packit ae9e2a
 * @param odb object database
Packit ae9e2a
 * @return number of backends in the ODB
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(size_t) git_odb_num_backends(git_odb *odb);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Lookup an ODB backend object by index
Packit ae9e2a
 *
Packit ae9e2a
 * @param out output pointer to ODB backend at pos
Packit ae9e2a
 * @param odb object database
Packit ae9e2a
 * @param pos index into object database backend list
Packit ae9e2a
 * @return 0 on success; GIT_ENOTFOUND if pos is invalid; other errors < 0
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_odb_get_backend(git_odb_backend **out, git_odb *odb, size_t pos);
Packit ae9e2a
Packit ae9e2a
/** @} */
Packit ae9e2a
GIT_END_DECL
Packit ae9e2a
#endif