Blame include/git2/object.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_git_object_h__
Packit Service 20376f
#define INCLUDE_git_object_h__
Packit Service 20376f
Packit Service 20376f
#include "common.h"
Packit Service 20376f
#include "types.h"
Packit Service 20376f
#include "oid.h"
Packit Service 20376f
#include "buffer.h"
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * @file git2/object.h
Packit Service 20376f
 * @brief Git revision object management routines
Packit Service 20376f
 * @defgroup git_object Git revision object management routines
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
 * Lookup a reference to one of the objects in a repository.
Packit Service 20376f
 *
Packit Service 20376f
 * The generated reference is owned by the repository and
Packit Service 20376f
 * should be closed with the `git_object_free` method
Packit Service 20376f
 * instead of free'd manually.
Packit Service 20376f
 *
Packit Service 20376f
 * The 'type' parameter must match the type of the object
Packit Service 20376f
 * in the odb; the method will fail otherwise.
Packit Service 20376f
 * The special value 'GIT_OBJ_ANY' may be passed to let
Packit Service 20376f
 * the method guess the object's type.
Packit Service 20376f
 *
Packit Service 20376f
 * @param object pointer to the looked-up object
Packit Service 20376f
 * @param repo the repository to look up the object
Packit Service 20376f
 * @param id the unique identifier for the object
Packit Service 20376f
 * @param type the type of the object
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_object_lookup(
Packit Service 20376f
		git_object **object,
Packit Service 20376f
		git_repository *repo,
Packit Service 20376f
		const git_oid *id,
Packit Service 20376f
		git_otype type);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Lookup a reference to one of the objects in a repository,
Packit Service 20376f
 * given a prefix of its identifier (short id).
Packit Service 20376f
 *
Packit Service 20376f
 * The object obtained will be so that its identifier
Packit Service 20376f
 * matches the first 'len' hexadecimal characters
Packit Service 20376f
 * (packets of 4 bits) of the given 'id'.
Packit Service 20376f
 * 'len' must be at least GIT_OID_MINPREFIXLEN, and
Packit Service 20376f
 * long enough to identify a unique object matching
Packit Service 20376f
 * the prefix; otherwise the method will fail.
Packit Service 20376f
 *
Packit Service 20376f
 * The generated reference is owned by the repository and
Packit Service 20376f
 * should be closed with the `git_object_free` method
Packit Service 20376f
 * instead of free'd manually.
Packit Service 20376f
 *
Packit Service 20376f
 * The 'type' parameter must match the type of the object
Packit Service 20376f
 * in the odb; the method will fail otherwise.
Packit Service 20376f
 * The special value 'GIT_OBJ_ANY' may be passed to let
Packit Service 20376f
 * the method guess the object's type.
Packit Service 20376f
 *
Packit Service 20376f
 * @param object_out pointer where to store the looked-up object
Packit Service 20376f
 * @param repo the repository to look up the object
Packit Service 20376f
 * @param id a short identifier for the object
Packit Service 20376f
 * @param len the length of the short identifier
Packit Service 20376f
 * @param type the type of the object
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_object_lookup_prefix(
Packit Service 20376f
		git_object **object_out,
Packit Service 20376f
		git_repository *repo,
Packit Service 20376f
		const git_oid *id,
Packit Service 20376f
		size_t len,
Packit Service 20376f
		git_otype type);
Packit Service 20376f
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Lookup an object that represents a tree entry.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out buffer that receives a pointer to the object (which must be freed
Packit Service 20376f
 *            by the caller)
Packit Service 20376f
 * @param treeish root object that can be peeled to a tree
Packit Service 20376f
 * @param path relative path from the root object to the desired object
Packit Service 20376f
 * @param type type of object desired
Packit Service 20376f
 * @return 0 on success, or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_object_lookup_bypath(
Packit Service 20376f
		git_object **out,
Packit Service 20376f
		const git_object *treeish,
Packit Service 20376f
		const char *path,
Packit Service 20376f
		git_otype type);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the id (SHA1) of a repository object
Packit Service 20376f
 *
Packit Service 20376f
 * @param obj the repository object
Packit Service 20376f
 * @return the SHA1 id
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(const git_oid *) git_object_id(const git_object *obj);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get a short abbreviated OID string for the object
Packit Service 20376f
 *
Packit Service 20376f
 * This starts at the "core.abbrev" length (default 7 characters) and
Packit Service 20376f
 * iteratively extends to a longer string if that length is ambiguous.
Packit Service 20376f
 * The result will be unambiguous (at least until new objects are added to
Packit Service 20376f
 * the repository).
Packit Service 20376f
 *
Packit Service 20376f
 * @param out Buffer to write string into
Packit Service 20376f
 * @param obj The object to get an ID for
Packit Service 20376f
 * @return 0 on success, <0 for error
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_object_short_id(git_buf *out, const git_object *obj);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the object type of an object
Packit Service 20376f
 *
Packit Service 20376f
 * @param obj the repository object
Packit Service 20376f
 * @return the object's type
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(git_otype) git_object_type(const git_object *obj);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the repository that owns this object
Packit Service 20376f
 *
Packit Service 20376f
 * Freeing or calling `git_repository_close` on the
Packit Service 20376f
 * returned pointer will invalidate the actual object.
Packit Service 20376f
 *
Packit Service 20376f
 * Any other operation may be run on the repository without
Packit Service 20376f
 * affecting the object.
Packit Service 20376f
 *
Packit Service 20376f
 * @param obj the object
Packit Service 20376f
 * @return the repository who owns this object
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(git_repository *) git_object_owner(const git_object *obj);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Close an open object
Packit Service 20376f
 *
Packit Service 20376f
 * This method instructs the library to close an existing
Packit Service 20376f
 * object; note that git_objects are owned and cached by the repository
Packit Service 20376f
 * so the object may or may not be freed after this library call,
Packit Service 20376f
 * depending on how aggressive is the caching mechanism used
Packit Service 20376f
 * by the repository.
Packit Service 20376f
 *
Packit Service 20376f
 * IMPORTANT:
Packit Service 20376f
 * It *is* necessary to call this method when you stop using
Packit Service 20376f
 * an object. Failure to do so will cause a memory leak.
Packit Service 20376f
 *
Packit Service 20376f
 * @param object the object to close
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(void) git_object_free(git_object *object);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Convert an object type to its string representation.
Packit Service 20376f
 *
Packit Service 20376f
 * The result is a pointer to a string in static memory and
Packit Service 20376f
 * should not be free()'ed.
Packit Service 20376f
 *
Packit Service 20376f
 * @param type object type to convert.
Packit Service 20376f
 * @return the corresponding string representation.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(const char *) git_object_type2string(git_otype type);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Convert a string object type representation to it's git_otype.
Packit Service 20376f
 *
Packit Service 20376f
 * @param str the string to convert.
Packit Service 20376f
 * @return the corresponding git_otype.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(git_otype) git_object_string2type(const char *str);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Determine if the given git_otype is a valid loose object type.
Packit Service 20376f
 *
Packit Service 20376f
 * @param type object type to test.
Packit Service 20376f
 * @return true if the type represents a valid loose object type,
Packit Service 20376f
 * false otherwise.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_object_typeisloose(git_otype type);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the size in bytes for the structure which
Packit Service 20376f
 * acts as an in-memory representation of any given
Packit Service 20376f
 * object type.
Packit Service 20376f
 *
Packit Service 20376f
 * For all the core types, this would the equivalent
Packit Service 20376f
 * of calling `sizeof(git_commit)` if the core types
Packit Service 20376f
 * were not opaque on the external API.
Packit Service 20376f
 *
Packit Service 20376f
 * @param type object type to get its size
Packit Service 20376f
 * @return size in bytes of the object
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(size_t) git_object__size(git_otype type);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Recursively peel an object until an object of the specified type is met.
Packit Service 20376f
 *
Packit Service 20376f
 * If the query cannot be satisfied due to the object model,
Packit Service 20376f
 * GIT_EINVALIDSPEC will be returned (e.g. trying to peel a blob to a
Packit Service 20376f
 * tree).
Packit Service 20376f
 *
Packit Service 20376f
 * If you pass `GIT_OBJ_ANY` as the target type, then the object will
Packit Service 20376f
 * be peeled until the type changes. A tag will be peeled until the
Packit Service 20376f
 * referenced object is no longer a tag, and a commit will be peeled
Packit Service 20376f
 * to a tree. Any other object type will return GIT_EINVALIDSPEC.
Packit Service 20376f
 *
Packit Service 20376f
 * If peeling a tag we discover an object which cannot be peeled to
Packit Service 20376f
 * the target type due to the object model, GIT_EPEEL will be
Packit Service 20376f
 * returned.
Packit Service 20376f
 *
Packit Service 20376f
 * You must free the returned object.
Packit Service 20376f
 *
Packit Service 20376f
 * @param peeled Pointer to the peeled git_object
Packit Service 20376f
 * @param object The object to be processed
Packit Service 20376f
 * @param target_type The type of the requested object (a GIT_OBJ_ value)
Packit Service 20376f
 * @return 0 on success, GIT_EINVALIDSPEC, GIT_EPEEL, or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_object_peel(
Packit Service 20376f
	git_object **peeled,
Packit Service 20376f
	const git_object *object,
Packit Service 20376f
	git_otype target_type);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Create an in-memory copy of a Git object. The copy must be
Packit Service 20376f
 * explicitly free'd or it will leak.
Packit Service 20376f
 *
Packit Service 20376f
 * @param dest Pointer to store the copy of the object
Packit Service 20376f
 * @param source Original object to copy
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_object_dup(git_object **dest, git_object *source);
Packit Service 20376f
Packit Service 20376f
/** @} */
Packit Service 20376f
GIT_END_DECL
Packit Service 20376f
Packit Service 20376f
#endif