Blame include/git2/reflog.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_reflog_h__
Packit ae9e2a
#define INCLUDE_git_reflog_h__
Packit ae9e2a
Packit ae9e2a
#include "common.h"
Packit ae9e2a
#include "types.h"
Packit ae9e2a
#include "oid.h"
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * @file git2/reflog.h
Packit ae9e2a
 * @brief Git reflog management routines
Packit ae9e2a
 * @defgroup git_reflog Git reflog management routines
Packit ae9e2a
 * @ingroup Git
Packit ae9e2a
 * @{
Packit ae9e2a
 */
Packit ae9e2a
GIT_BEGIN_DECL
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Read the reflog for the given reference
Packit ae9e2a
 *
Packit ae9e2a
 * If there is no reflog file for the given
Packit ae9e2a
 * reference yet, an empty reflog object will
Packit ae9e2a
 * be returned.
Packit ae9e2a
 *
Packit ae9e2a
 * The reflog must be freed manually by using
Packit ae9e2a
 * git_reflog_free().
Packit ae9e2a
 *
Packit ae9e2a
 * @param out pointer to reflog
Packit ae9e2a
 * @param repo the repostiory
Packit ae9e2a
 * @param name reference to look up
Packit ae9e2a
 * @return 0 or an error code
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_reflog_read(git_reflog **out, git_repository *repo,  const char *name);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Write an existing in-memory reflog object back to disk
Packit ae9e2a
 * using an atomic file lock.
Packit ae9e2a
 *
Packit ae9e2a
 * @param reflog an existing reflog object
Packit ae9e2a
 * @return 0 or an error code
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_reflog_write(git_reflog *reflog);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Add a new entry to the in-memory reflog.
Packit ae9e2a
 *
Packit ae9e2a
 * `msg` is optional and can be NULL.
Packit ae9e2a
 *
Packit ae9e2a
 * @param reflog an existing reflog object
Packit ae9e2a
 * @param id the OID the reference is now pointing to
Packit ae9e2a
 * @param committer the signature of the committer
Packit ae9e2a
 * @param msg the reflog message
Packit ae9e2a
 * @return 0 or an error code
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_reflog_append(git_reflog *reflog, const git_oid *id, const git_signature *committer, const char *msg);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Rename a reflog
Packit ae9e2a
 *
Packit ae9e2a
 * The reflog to be renamed is expected to already exist
Packit ae9e2a
 *
Packit ae9e2a
 * The new name will be checked for validity.
Packit ae9e2a
 * See `git_reference_create_symbolic()` for rules about valid names.
Packit ae9e2a
 *
Packit ae9e2a
 * @param repo the repository
Packit ae9e2a
 * @param old_name the old name of the reference
Packit ae9e2a
 * @param name the new name of the reference
Packit ae9e2a
 * @return 0 on success, GIT_EINVALIDSPEC or an error code
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_reflog_rename(git_repository *repo, const char *old_name, const char *name);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Delete the reflog for the given reference
Packit ae9e2a
 *
Packit ae9e2a
 * @param repo the repository
Packit ae9e2a
 * @param name the reflog to delete
Packit ae9e2a
 * @return 0 or an error code
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_reflog_delete(git_repository *repo, const char *name);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Get the number of log entries in a reflog
Packit ae9e2a
 *
Packit ae9e2a
 * @param reflog the previously loaded reflog
Packit ae9e2a
 * @return the number of log entries
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(size_t) git_reflog_entrycount(git_reflog *reflog);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Lookup an entry by its index
Packit ae9e2a
 *
Packit ae9e2a
 * Requesting the reflog entry with an index of 0 (zero) will
Packit ae9e2a
 * return the most recently created entry.
Packit ae9e2a
 *
Packit ae9e2a
 * @param reflog a previously loaded reflog
Packit ae9e2a
 * @param idx the position of the entry to lookup. Should be greater than or
Packit ae9e2a
 * equal to 0 (zero) and less than `git_reflog_entrycount()`.
Packit ae9e2a
 * @return the entry; NULL if not found
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(const git_reflog_entry *) git_reflog_entry_byindex(const git_reflog *reflog, size_t idx);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Remove an entry from the reflog by its index
Packit ae9e2a
 *
Packit ae9e2a
 * To ensure there's no gap in the log history, set `rewrite_previous_entry`
Packit ae9e2a
 * param value to 1. When deleting entry `n`, member old_oid of entry `n-1`
Packit ae9e2a
 * (if any) will be updated with the value of member new_oid of entry `n+1`.
Packit ae9e2a
 *
Packit ae9e2a
 * @param reflog a previously loaded reflog.
Packit ae9e2a
 *
Packit ae9e2a
 * @param idx the position of the entry to remove. Should be greater than or
Packit ae9e2a
 * equal to 0 (zero) and less than `git_reflog_entrycount()`.
Packit ae9e2a
 *
Packit ae9e2a
 * @param rewrite_previous_entry 1 to rewrite the history; 0 otherwise.
Packit ae9e2a
 *
Packit ae9e2a
 * @return 0 on success, GIT_ENOTFOUND if the entry doesn't exist
Packit ae9e2a
 * or an error code.
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_reflog_drop(
Packit ae9e2a
	git_reflog *reflog,
Packit ae9e2a
	size_t idx,
Packit ae9e2a
	int rewrite_previous_entry);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Get the old oid
Packit ae9e2a
 *
Packit ae9e2a
 * @param entry a reflog entry
Packit ae9e2a
 * @return the old oid
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(const git_oid *) git_reflog_entry_id_old(const git_reflog_entry *entry);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Get the new oid
Packit ae9e2a
 *
Packit ae9e2a
 * @param entry a reflog entry
Packit ae9e2a
 * @return the new oid at this time
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(const git_oid *) git_reflog_entry_id_new(const git_reflog_entry *entry);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Get the committer of this entry
Packit ae9e2a
 *
Packit ae9e2a
 * @param entry a reflog entry
Packit ae9e2a
 * @return the committer
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(const git_signature *) git_reflog_entry_committer(const git_reflog_entry *entry);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Get the log message
Packit ae9e2a
 *
Packit ae9e2a
 * @param entry a reflog entry
Packit ae9e2a
 * @return the log msg
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(const char *) git_reflog_entry_message(const git_reflog_entry *entry);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Free the reflog
Packit ae9e2a
 *
Packit ae9e2a
 * @param reflog reflog to free
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(void) git_reflog_free(git_reflog *reflog);
Packit ae9e2a
Packit ae9e2a
/** @} */
Packit ae9e2a
GIT_END_DECL
Packit ae9e2a
#endif