Blame include/git2/index.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_index_h__
Packit Service 20376f
#define INCLUDE_git_index_h__
Packit Service 20376f
Packit Service 20376f
#include "common.h"
Packit Service 20376f
#include "indexer.h"
Packit Service 20376f
#include "types.h"
Packit Service 20376f
#include "oid.h"
Packit Service 20376f
#include "strarray.h"
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * @file git2/index.h
Packit Service 20376f
 * @brief Git index parsing and manipulation routines
Packit Service 20376f
 * @defgroup git_index Git index parsing and manipulation routines
Packit Service 20376f
 * @ingroup Git
Packit Service 20376f
 * @{
Packit Service 20376f
 */
Packit Service 20376f
GIT_BEGIN_DECL
Packit Service 20376f
Packit Service 20376f
/** Time structure used in a git index entry */
Packit Service 20376f
typedef struct {
Packit Service 20376f
	int32_t seconds;
Packit Service 20376f
	/* nsec should not be stored as time_t compatible */
Packit Service 20376f
	uint32_t nanoseconds;
Packit Service 20376f
} git_index_time;
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * In-memory representation of a file entry in the index.
Packit Service 20376f
 *
Packit Service 20376f
 * This is a public structure that represents a file entry in the index.
Packit Service 20376f
 * The meaning of the fields corresponds to core Git's documentation (in
Packit Service 20376f
 * "Documentation/technical/index-format.txt").
Packit Service 20376f
 *
Packit Service 20376f
 * The `flags` field consists of a number of bit fields which can be
Packit Service 20376f
 * accessed via the first set of `GIT_IDXENTRY_...` bitmasks below.  These
Packit Service 20376f
 * flags are all read from and persisted to disk.
Packit Service 20376f
 *
Packit Service 20376f
 * The `flags_extended` field also has a number of bit fields which can be
Packit Service 20376f
 * accessed via the later `GIT_IDXENTRY_...` bitmasks below.  Some of
Packit Service 20376f
 * these flags are read from and written to disk, but some are set aside
Packit Service 20376f
 * for in-memory only reference.
Packit Service 20376f
 *
Packit Service 20376f
 * Note that the time and size fields are truncated to 32 bits. This
Packit Service 20376f
 * is enough to detect changes, which is enough for the index to
Packit Service 20376f
 * function as a cache, but it should not be taken as an authoritative
Packit Service 20376f
 * source for that data.
Packit Service 20376f
 */
Packit Service 20376f
typedef struct git_index_entry {
Packit Service 20376f
	git_index_time ctime;
Packit Service 20376f
	git_index_time mtime;
Packit Service 20376f
Packit Service 20376f
	uint32_t dev;
Packit Service 20376f
	uint32_t ino;
Packit Service 20376f
	uint32_t mode;
Packit Service 20376f
	uint32_t uid;
Packit Service 20376f
	uint32_t gid;
Packit Service 20376f
	uint32_t file_size;
Packit Service 20376f
Packit Service 20376f
	git_oid id;
Packit Service 20376f
Packit Service 20376f
	uint16_t flags;
Packit Service 20376f
	uint16_t flags_extended;
Packit Service 20376f
Packit Service 20376f
	const char *path;
Packit Service 20376f
} git_index_entry;
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Bitmasks for on-disk fields of `git_index_entry`'s `flags`
Packit Service 20376f
 *
Packit Service 20376f
 * These bitmasks match the four fields in the `git_index_entry` `flags`
Packit Service 20376f
 * value both in memory and on disk.  You can use them to interpret the
Packit Service 20376f
 * data in the `flags`.
Packit Service 20376f
 */
Packit Service 20376f
#define GIT_IDXENTRY_NAMEMASK  (0x0fff)
Packit Service 20376f
#define GIT_IDXENTRY_STAGEMASK (0x3000)
Packit Service 20376f
#define GIT_IDXENTRY_STAGESHIFT 12
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Flags for index entries
Packit Service 20376f
 */
Packit Service 20376f
typedef enum {
Packit Service 20376f
	GIT_IDXENTRY_EXTENDED  = (0x4000),
Packit Service 20376f
	GIT_IDXENTRY_VALID     = (0x8000),
Packit Service 20376f
} git_indxentry_flag_t;
Packit Service 20376f
Packit Service 20376f
#define GIT_IDXENTRY_STAGE(E) \
Packit Service 20376f
	(((E)->flags & GIT_IDXENTRY_STAGEMASK) >> GIT_IDXENTRY_STAGESHIFT)
Packit Service 20376f
Packit Service 20376f
#define GIT_IDXENTRY_STAGE_SET(E,S) do { \
Packit Service 20376f
	(E)->flags = ((E)->flags & ~GIT_IDXENTRY_STAGEMASK) | \
Packit Service 20376f
		(((S) & 0x03) << GIT_IDXENTRY_STAGESHIFT); } while (0)
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Bitmasks for on-disk fields of `git_index_entry`'s `flags_extended`
Packit Service 20376f
 *
Packit Service 20376f
 * In memory, the `flags_extended` fields are divided into two parts: the
Packit Service 20376f
 * fields that are read from and written to disk, and other fields that
Packit Service 20376f
 * in-memory only and used by libgit2.  Only the flags in
Packit Service 20376f
 * `GIT_IDXENTRY_EXTENDED_FLAGS` will get saved on-disk.
Packit Service 20376f
 *
Packit Service 20376f
 * Thee first three bitmasks match the three fields in the
Packit Service 20376f
 * `git_index_entry` `flags_extended` value that belong on disk.  You
Packit Service 20376f
 * can use them to interpret the data in the `flags_extended`.
Packit Service 20376f
 *
Packit Service 20376f
 * The rest of the bitmasks match the other fields in the `git_index_entry`
Packit Service 20376f
 * `flags_extended` value that are only used in-memory by libgit2.
Packit Service 20376f
 * You can use them to interpret the data in the `flags_extended`.
Packit Service 20376f
 *
Packit Service 20376f
 */
Packit Service 20376f
typedef enum {
Packit Service 20376f
Packit Service 20376f
	GIT_IDXENTRY_INTENT_TO_ADD  =  (1 << 13),
Packit Service 20376f
	GIT_IDXENTRY_SKIP_WORKTREE  =  (1 << 14),
Packit Service 20376f
	/** Reserved for future extension */
Packit Service 20376f
	GIT_IDXENTRY_EXTENDED2      =  (1 << 15),
Packit Service 20376f
Packit Service 20376f
	GIT_IDXENTRY_EXTENDED_FLAGS = (GIT_IDXENTRY_INTENT_TO_ADD | GIT_IDXENTRY_SKIP_WORKTREE),
Packit Service 20376f
	GIT_IDXENTRY_UPDATE            =  (1 << 0),
Packit Service 20376f
	GIT_IDXENTRY_REMOVE            =  (1 << 1),
Packit Service 20376f
	GIT_IDXENTRY_UPTODATE          =  (1 << 2),
Packit Service 20376f
	GIT_IDXENTRY_ADDED             =  (1 << 3),
Packit Service 20376f
Packit Service 20376f
	GIT_IDXENTRY_HASHED            =  (1 << 4),
Packit Service 20376f
	GIT_IDXENTRY_UNHASHED          =  (1 << 5),
Packit Service 20376f
	GIT_IDXENTRY_WT_REMOVE         =  (1 << 6), /**< remove in work directory */
Packit Service 20376f
	GIT_IDXENTRY_CONFLICTED        =  (1 << 7),
Packit Service 20376f
Packit Service 20376f
	GIT_IDXENTRY_UNPACKED          =  (1 << 8),
Packit Service 20376f
	GIT_IDXENTRY_NEW_SKIP_WORKTREE =  (1 << 9),
Packit Service 20376f
} git_idxentry_extended_flag_t;
Packit Service 20376f
Packit Service 20376f
/** Capabilities of system that affect index actions. */
Packit Service 20376f
typedef enum {
Packit Service 20376f
	GIT_INDEXCAP_IGNORE_CASE = 1,
Packit Service 20376f
	GIT_INDEXCAP_NO_FILEMODE = 2,
Packit Service 20376f
	GIT_INDEXCAP_NO_SYMLINKS = 4,
Packit Service 20376f
	GIT_INDEXCAP_FROM_OWNER  = -1,
Packit Service 20376f
} git_indexcap_t;
Packit Service 20376f
Packit Service 20376f
/** Callback for APIs that add/remove/update files matching pathspec */
Packit Service 20376f
typedef int (*git_index_matched_path_cb)(
Packit Service 20376f
	const char *path, const char *matched_pathspec, void *payload);
Packit Service 20376f
Packit Service 20376f
/** Flags for APIs that add files matching pathspec */
Packit Service 20376f
typedef enum {
Packit Service 20376f
	GIT_INDEX_ADD_DEFAULT = 0,
Packit Service 20376f
	GIT_INDEX_ADD_FORCE = (1u << 0),
Packit Service 20376f
	GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH = (1u << 1),
Packit Service 20376f
	GIT_INDEX_ADD_CHECK_PATHSPEC = (1u << 2),
Packit Service 20376f
} git_index_add_option_t;
Packit Service 20376f
Packit Service 20376f
typedef enum {
Packit Service 20376f
	/**
Packit Service 20376f
	 * Match any index stage.
Packit Service 20376f
	 *
Packit Service 20376f
	 * Some index APIs take a stage to match; pass this value to match
Packit Service 20376f
	 * any entry matching the path regardless of stage.
Packit Service 20376f
	 */
Packit Service 20376f
	GIT_INDEX_STAGE_ANY = -1,
Packit Service 20376f
Packit Service 20376f
	/** A normal staged file in the index. */
Packit Service 20376f
	GIT_INDEX_STAGE_NORMAL = 0,
Packit Service 20376f
Packit Service 20376f
	/** The ancestor side of a conflict. */
Packit Service 20376f
	GIT_INDEX_STAGE_ANCESTOR = 1,
Packit Service 20376f
Packit Service 20376f
	/** The "ours" side of a conflict. */
Packit Service 20376f
	GIT_INDEX_STAGE_OURS = 2,
Packit Service 20376f
Packit Service 20376f
	/** The "theirs" side of a conflict. */
Packit Service 20376f
	GIT_INDEX_STAGE_THEIRS = 3,
Packit Service 20376f
} git_index_stage_t;
Packit Service 20376f
Packit Service 20376f
/** @name Index File Functions
Packit Service 20376f
 *
Packit Service 20376f
 * These functions work on the index file itself.
Packit Service 20376f
 */
Packit Service 20376f
/**@{*/
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Create a new bare Git index object as a memory representation
Packit Service 20376f
 * of the Git index file in 'index_path', without a repository
Packit Service 20376f
 * to back it.
Packit Service 20376f
 *
Packit Service 20376f
 * Since there is no ODB or working directory behind this index,
Packit Service 20376f
 * any Index methods which rely on these (e.g. index_add_bypath)
Packit Service 20376f
 * will fail with the GIT_ERROR error code.
Packit Service 20376f
 *
Packit Service 20376f
 * If you need to access the index of an actual repository,
Packit Service 20376f
 * use the `git_repository_index` wrapper.
Packit Service 20376f
 *
Packit Service 20376f
 * The index must be freed once it's no longer in use.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out the pointer for the new index
Packit Service 20376f
 * @param index_path the path to the index file in disk
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_open(git_index **out, const char *index_path);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Create an in-memory index object.
Packit Service 20376f
 *
Packit Service 20376f
 * This index object cannot be read/written to the filesystem,
Packit Service 20376f
 * but may be used to perform in-memory index operations.
Packit Service 20376f
 *
Packit Service 20376f
 * The index must be freed once it's no longer in use.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out the pointer for the new index
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_new(git_index **out);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Free an existing index object.
Packit Service 20376f
 *
Packit Service 20376f
 * @param index an existing index object
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(void) git_index_free(git_index *index);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the repository this index relates to
Packit Service 20376f
 *
Packit Service 20376f
 * @param index The index
Packit Service 20376f
 * @return A pointer to the repository
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(git_repository *) git_index_owner(const git_index *index);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Read index capabilities flags.
Packit Service 20376f
 *
Packit Service 20376f
 * @param index An existing index object
Packit Service 20376f
 * @return A combination of GIT_INDEXCAP values
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_caps(const git_index *index);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Set index capabilities flags.
Packit Service 20376f
 *
Packit Service 20376f
 * If you pass `GIT_INDEXCAP_FROM_OWNER` for the caps, then the
Packit Service 20376f
 * capabilities will be read from the config of the owner object,
Packit Service 20376f
 * looking at `core.ignorecase`, `core.filemode`, `core.symlinks`.
Packit Service 20376f
 *
Packit Service 20376f
 * @param index An existing index object
Packit Service 20376f
 * @param caps A combination of GIT_INDEXCAP values
Packit Service 20376f
 * @return 0 on success, -1 on failure
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_set_caps(git_index *index, int caps);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get index on-disk version.
Packit Service 20376f
 *
Packit Service 20376f
 * Valid return values are 2, 3, or 4.  If 3 is returned, an index
Packit Service 20376f
 * with version 2 may be written instead, if the extension data in
Packit Service 20376f
 * version 3 is not necessary.
Packit Service 20376f
 *
Packit Service 20376f
 * @param index An existing index object
Packit Service 20376f
 * @return the index version
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(unsigned int) git_index_version(git_index *index);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Set index on-disk version.
Packit Service 20376f
 *
Packit Service 20376f
 * Valid values are 2, 3, or 4.  If 2 is given, git_index_write may
Packit Service 20376f
 * write an index with version 3 instead, if necessary to accurately
Packit Service 20376f
 * represent the index.
Packit Service 20376f
 *
Packit Service 20376f
 * @param index An existing index object
Packit Service 20376f
 * @param version The new version number
Packit Service 20376f
 * @return 0 on success, -1 on failure
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_set_version(git_index *index, unsigned int version);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Update the contents of an existing index object in memory by reading
Packit Service 20376f
 * from the hard disk.
Packit Service 20376f
 *
Packit Service 20376f
 * If `force` is true, this performs a "hard" read that discards in-memory
Packit Service 20376f
 * changes and always reloads the on-disk index data.  If there is no
Packit Service 20376f
 * on-disk version, the index will be cleared.
Packit Service 20376f
 *
Packit Service 20376f
 * If `force` is false, this does a "soft" read that reloads the index
Packit Service 20376f
 * data from disk only if it has changed since the last time it was
Packit Service 20376f
 * loaded.  Purely in-memory index data will be untouched.  Be aware: if
Packit Service 20376f
 * there are changes on disk, unwritten in-memory changes are discarded.
Packit Service 20376f
 *
Packit Service 20376f
 * @param index an existing index object
Packit Service 20376f
 * @param force if true, always reload, vs. only read if file has changed
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_read(git_index *index, int force);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Write an existing index object from memory back to disk
Packit Service 20376f
 * using an atomic file lock.
Packit Service 20376f
 *
Packit Service 20376f
 * @param index an existing index object
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_write(git_index *index);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the full path to the index file on disk.
Packit Service 20376f
 *
Packit Service 20376f
 * @param index an existing index object
Packit Service 20376f
 * @return path to index file or NULL for in-memory index
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(const char *) git_index_path(const git_index *index);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the checksum of the index
Packit Service 20376f
 *
Packit Service 20376f
 * This checksum is the SHA-1 hash over the index file (except the
Packit Service 20376f
 * last 20 bytes which are the checksum itself). In cases where the
Packit Service 20376f
 * index does not exist on-disk, it will be zeroed out.
Packit Service 20376f
 *
Packit Service 20376f
 * @param index an existing index object
Packit Service 20376f
 * @return a pointer to the checksum of the index
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(const git_oid *) git_index_checksum(git_index *index);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Read a tree into the index file with stats
Packit Service 20376f
 *
Packit Service 20376f
 * The current index contents will be replaced by the specified tree.
Packit Service 20376f
 *
Packit Service 20376f
 * @param index an existing index object
Packit Service 20376f
 * @param tree tree to read
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_read_tree(git_index *index, const git_tree *tree);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Write the index as a tree
Packit Service 20376f
 *
Packit Service 20376f
 * This method will scan the index and write a representation
Packit Service 20376f
 * of its current state back to disk; it recursively creates
Packit Service 20376f
 * tree objects for each of the subtrees stored in the index,
Packit Service 20376f
 * but only returns the OID of the root tree. This is the OID
Packit Service 20376f
 * that can be used e.g. to create a commit.
Packit Service 20376f
 *
Packit Service 20376f
 * The index instance cannot be bare, and needs to be associated
Packit Service 20376f
 * to an existing repository.
Packit Service 20376f
 *
Packit Service 20376f
 * The index must not contain any file in conflict.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out Pointer where to store the OID of the written tree
Packit Service 20376f
 * @param index Index to write
Packit Service 20376f
 * @return 0 on success, GIT_EUNMERGED when the index is not clean
Packit Service 20376f
 * or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_write_tree(git_oid *out, git_index *index);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Write the index as a tree to the given repository
Packit Service 20376f
 *
Packit Service 20376f
 * This method will do the same as `git_index_write_tree`, but
Packit Service 20376f
 * letting the user choose the repository where the tree will
Packit Service 20376f
 * be written.
Packit Service 20376f
 *
Packit Service 20376f
 * The index must not contain any file in conflict.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out Pointer where to store OID of the the written tree
Packit Service 20376f
 * @param index Index to write
Packit Service 20376f
 * @param repo Repository where to write the tree
Packit Service 20376f
 * @return 0 on success, GIT_EUNMERGED when the index is not clean
Packit Service 20376f
 * or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_write_tree_to(git_oid *out, git_index *index, git_repository *repo);
Packit Service 20376f
Packit Service 20376f
/**@}*/
Packit Service 20376f
Packit Service 20376f
/** @name Raw Index Entry Functions
Packit Service 20376f
 *
Packit Service 20376f
 * These functions work on index entries, and allow for raw manipulation
Packit Service 20376f
 * of the entries.
Packit Service 20376f
 */
Packit Service 20376f
/**@{*/
Packit Service 20376f
Packit Service 20376f
/* Index entry manipulation */
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the count of entries currently in the index
Packit Service 20376f
 *
Packit Service 20376f
 * @param index an existing index object
Packit Service 20376f
 * @return integer of count of current entries
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(size_t) git_index_entrycount(const git_index *index);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Clear the contents (all the entries) of an index object.
Packit Service 20376f
 *
Packit Service 20376f
 * This clears the index object in memory; changes must be explicitly
Packit Service 20376f
 * written to disk for them to take effect persistently.
Packit Service 20376f
 *
Packit Service 20376f
 * @param index an existing index object
Packit Service 20376f
 * @return 0 on success, error code < 0 on failure
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_clear(git_index *index);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get a pointer to one of the entries in the index
Packit Service 20376f
 *
Packit Service 20376f
 * The entry is not modifiable and should not be freed.  Because the
Packit Service 20376f
 * `git_index_entry` struct is a publicly defined struct, you should
Packit Service 20376f
 * be able to make your own permanent copy of the data if necessary.
Packit Service 20376f
 *
Packit Service 20376f
 * @param index an existing index object
Packit Service 20376f
 * @param n the position of the entry
Packit Service 20376f
 * @return a pointer to the entry; NULL if out of bounds
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(const git_index_entry *) git_index_get_byindex(
Packit Service 20376f
	git_index *index, size_t n);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get a pointer to one of the entries in the index
Packit Service 20376f
 *
Packit Service 20376f
 * The entry is not modifiable and should not be freed.  Because the
Packit Service 20376f
 * `git_index_entry` struct is a publicly defined struct, you should
Packit Service 20376f
 * be able to make your own permanent copy of the data if necessary.
Packit Service 20376f
 *
Packit Service 20376f
 * @param index an existing index object
Packit Service 20376f
 * @param path path to search
Packit Service 20376f
 * @param stage stage to search
Packit Service 20376f
 * @return a pointer to the entry; NULL if it was not found
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(const git_index_entry *) git_index_get_bypath(
Packit Service 20376f
	git_index *index, const char *path, int stage);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Remove an entry from the index
Packit Service 20376f
 *
Packit Service 20376f
 * @param index an existing index object
Packit Service 20376f
 * @param path path to search
Packit Service 20376f
 * @param stage stage to search
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_remove(git_index *index, const char *path, int stage);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Remove all entries from the index under a given directory
Packit Service 20376f
 *
Packit Service 20376f
 * @param index an existing index object
Packit Service 20376f
 * @param dir container directory path
Packit Service 20376f
 * @param stage stage to search
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_remove_directory(
Packit Service 20376f
	git_index *index, const char *dir, int stage);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Add or update an index entry from an in-memory struct
Packit Service 20376f
 *
Packit Service 20376f
 * If a previous index entry exists that has the same path and stage
Packit Service 20376f
 * as the given 'source_entry', it will be replaced.  Otherwise, the
Packit Service 20376f
 * 'source_entry' will be added.
Packit Service 20376f
 *
Packit Service 20376f
 * A full copy (including the 'path' string) of the given
Packit Service 20376f
 * 'source_entry' will be inserted on the index.
Packit Service 20376f
 *
Packit Service 20376f
 * @param index an existing index object
Packit Service 20376f
 * @param source_entry new entry object
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_add(git_index *index, const git_index_entry *source_entry);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Return the stage number from a git index entry
Packit Service 20376f
 *
Packit Service 20376f
 * This entry is calculated from the entry's flag attribute like this:
Packit Service 20376f
 *
Packit Service 20376f
 *    (entry->flags & GIT_IDXENTRY_STAGEMASK) >> GIT_IDXENTRY_STAGESHIFT
Packit Service 20376f
 *
Packit Service 20376f
 * @param entry The entry
Packit Service 20376f
 * @return the stage number
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_entry_stage(const git_index_entry *entry);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Return whether the given index entry is a conflict (has a high stage
Packit Service 20376f
 * entry).  This is simply shorthand for `git_index_entry_stage > 0`.
Packit Service 20376f
 *
Packit Service 20376f
 * @param entry The entry
Packit Service 20376f
 * @return 1 if the entry is a conflict entry, 0 otherwise
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_entry_is_conflict(const git_index_entry *entry);
Packit Service 20376f
Packit Service 20376f
/**@}*/
Packit Service 20376f
Packit Service 20376f
/** @name Workdir Index Entry Functions
Packit Service 20376f
 *
Packit Service 20376f
 * These functions work on index entries specifically in the working
Packit Service 20376f
 * directory (ie, stage 0).
Packit Service 20376f
 */
Packit Service 20376f
/**@{*/
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Add or update an index entry from a file on disk
Packit Service 20376f
 *
Packit Service 20376f
 * The file `path` must be relative to the repository's
Packit Service 20376f
 * working folder and must be readable.
Packit Service 20376f
 *
Packit Service 20376f
 * This method will fail in bare index instances.
Packit Service 20376f
 *
Packit Service 20376f
 * This forces the file to be added to the index, not looking
Packit Service 20376f
 * at gitignore rules.  Those rules can be evaluated through
Packit Service 20376f
 * the git_status APIs (in status.h) before calling this.
Packit Service 20376f
 *
Packit Service 20376f
 * If this file currently is the result of a merge conflict, this
Packit Service 20376f
 * file will no longer be marked as conflicting.  The data about
Packit Service 20376f
 * the conflict will be moved to the "resolve undo" (REUC) section.
Packit Service 20376f
 *
Packit Service 20376f
 * @param index an existing index object
Packit Service 20376f
 * @param path filename to add
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_add_bypath(git_index *index, const char *path);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Add or update an index entry from a buffer in memory
Packit Service 20376f
 *
Packit Service 20376f
 * This method will create a blob in the repository that owns the
Packit Service 20376f
 * index and then add the index entry to the index.  The `path` of the
Packit Service 20376f
 * entry represents the position of the blob relative to the
Packit Service 20376f
 * repository's root folder.
Packit Service 20376f
 *
Packit Service 20376f
 * If a previous index entry exists that has the same path as the
Packit Service 20376f
 * given 'entry', it will be replaced.  Otherwise, the 'entry' will be
Packit Service 20376f
 * added. The `id` and the `file_size` of the 'entry' are updated with the
Packit Service 20376f
 * real value of the blob.
Packit Service 20376f
 *
Packit Service 20376f
 * This forces the file to be added to the index, not looking
Packit Service 20376f
 * at gitignore rules.  Those rules can be evaluated through
Packit Service 20376f
 * the git_status APIs (in status.h) before calling this.
Packit Service 20376f
 *
Packit Service 20376f
 * If this file currently is the result of a merge conflict, this
Packit Service 20376f
 * file will no longer be marked as conflicting.  The data about
Packit Service 20376f
 * the conflict will be moved to the "resolve undo" (REUC) section.
Packit Service 20376f
 *
Packit Service 20376f
 * @param index an existing index object
Packit Service 20376f
 * @param entry filename to add
Packit Service 20376f
 * @param buffer data to be written into the blob
Packit Service 20376f
 * @param len length of the data
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_add_frombuffer(
Packit Service 20376f
	git_index *index,
Packit Service 20376f
	const git_index_entry *entry,
Packit Service 20376f
	const void *buffer, size_t len);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Remove an index entry corresponding to a file on disk
Packit Service 20376f
 *
Packit Service 20376f
 * The file `path` must be relative to the repository's
Packit Service 20376f
 * working folder.  It may exist.
Packit Service 20376f
 *
Packit Service 20376f
 * If this file currently is the result of a merge conflict, this
Packit Service 20376f
 * file will no longer be marked as conflicting.  The data about
Packit Service 20376f
 * the conflict will be moved to the "resolve undo" (REUC) section.
Packit Service 20376f
 *
Packit Service 20376f
 * @param index an existing index object
Packit Service 20376f
 * @param path filename to remove
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_remove_bypath(git_index *index, const char *path);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Add or update index entries matching files in the working directory.
Packit Service 20376f
 *
Packit Service 20376f
 * This method will fail in bare index instances.
Packit Service 20376f
 *
Packit Service 20376f
 * The `pathspec` is a list of file names or shell glob patterns that will
Packit Service 20376f
 * be matched against files in the repository's working directory.  Each
Packit Service 20376f
 * file that matches will be added to the index (either updating an
Packit Service 20376f
 * existing entry or adding a new entry).  You can disable glob expansion
Packit Service 20376f
 * and force exact matching with the `GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH`
Packit Service 20376f
 * flag.
Packit Service 20376f
 *
Packit Service 20376f
 * Files that are ignored will be skipped (unlike `git_index_add_bypath`).
Packit Service 20376f
 * If a file is already tracked in the index, then it *will* be updated
Packit Service 20376f
 * even if it is ignored.  Pass the `GIT_INDEX_ADD_FORCE` flag to skip
Packit Service 20376f
 * the checking of ignore rules.
Packit Service 20376f
 *
Packit Service 20376f
 * To emulate `git add -A` and generate an error if the pathspec contains
Packit Service 20376f
 * the exact path of an ignored file (when not using FORCE), add the
Packit Service 20376f
 * `GIT_INDEX_ADD_CHECK_PATHSPEC` flag.  This checks that each entry
Packit Service 20376f
 * in the `pathspec` that is an exact match to a filename on disk is
Packit Service 20376f
 * either not ignored or already in the index.  If this check fails, the
Packit Service 20376f
 * function will return GIT_EINVALIDSPEC.
Packit Service 20376f
 *
Packit Service 20376f
 * To emulate `git add -A` with the "dry-run" option, just use a callback
Packit Service 20376f
 * function that always returns a positive value.  See below for details.
Packit Service 20376f
 *
Packit Service 20376f
 * If any files are currently the result of a merge conflict, those files
Packit Service 20376f
 * will no longer be marked as conflicting.  The data about the conflicts
Packit Service 20376f
 * will be moved to the "resolve undo" (REUC) section.
Packit Service 20376f
 *
Packit Service 20376f
 * If you provide a callback function, it will be invoked on each matching
Packit Service 20376f
 * item in the working directory immediately *before* it is added to /
Packit Service 20376f
 * updated in the index.  Returning zero will add the item to the index,
Packit Service 20376f
 * greater than zero will skip the item, and less than zero will abort the
Packit Service 20376f
 * scan and return that value to the caller.
Packit Service 20376f
 *
Packit Service 20376f
 * @param index an existing index object
Packit Service 20376f
 * @param pathspec array of path patterns
Packit Service 20376f
 * @param flags combination of git_index_add_option_t flags
Packit Service 20376f
 * @param callback notification callback for each added/updated path (also
Packit Service 20376f
 *                 gets index of matching pathspec entry); can be NULL;
Packit Service 20376f
 *                 return 0 to add, >0 to skip, <0 to abort scan.
Packit Service 20376f
 * @param payload payload passed through to callback function
Packit Service 20376f
 * @return 0 on success, negative callback return value, or error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_add_all(
Packit Service 20376f
	git_index *index,
Packit Service 20376f
	const git_strarray *pathspec,
Packit Service 20376f
	unsigned int flags,
Packit Service 20376f
	git_index_matched_path_cb callback,
Packit Service 20376f
	void *payload);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Remove all matching index entries.
Packit Service 20376f
 *
Packit Service 20376f
 * If you provide a callback function, it will be invoked on each matching
Packit Service 20376f
 * item in the index immediately *before* it is removed.  Return 0 to
Packit Service 20376f
 * remove the item, > 0 to skip the item, and < 0 to abort the scan.
Packit Service 20376f
 *
Packit Service 20376f
 * @param index An existing index object
Packit Service 20376f
 * @param pathspec array of path patterns
Packit Service 20376f
 * @param callback notification callback for each removed path (also
Packit Service 20376f
 *                 gets index of matching pathspec entry); can be NULL;
Packit Service 20376f
 *                 return 0 to add, >0 to skip, <0 to abort scan.
Packit Service 20376f
 * @param payload payload passed through to callback function
Packit Service 20376f
 * @return 0 on success, negative callback return value, or error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_remove_all(
Packit Service 20376f
	git_index *index,
Packit Service 20376f
	const git_strarray *pathspec,
Packit Service 20376f
	git_index_matched_path_cb callback,
Packit Service 20376f
	void *payload);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Update all index entries to match the working directory
Packit Service 20376f
 *
Packit Service 20376f
 * This method will fail in bare index instances.
Packit Service 20376f
 *
Packit Service 20376f
 * This scans the existing index entries and synchronizes them with the
Packit Service 20376f
 * working directory, deleting them if the corresponding working directory
Packit Service 20376f
 * file no longer exists otherwise updating the information (including
Packit Service 20376f
 * adding the latest version of file to the ODB if needed).
Packit Service 20376f
 *
Packit Service 20376f
 * If you provide a callback function, it will be invoked on each matching
Packit Service 20376f
 * item in the index immediately *before* it is updated (either refreshed
Packit Service 20376f
 * or removed depending on working directory state).  Return 0 to proceed
Packit Service 20376f
 * with updating the item, > 0 to skip the item, and < 0 to abort the scan.
Packit Service 20376f
 *
Packit Service 20376f
 * @param index An existing index object
Packit Service 20376f
 * @param pathspec array of path patterns
Packit Service 20376f
 * @param callback notification callback for each updated path (also
Packit Service 20376f
 *                 gets index of matching pathspec entry); can be NULL;
Packit Service 20376f
 *                 return 0 to add, >0 to skip, <0 to abort scan.
Packit Service 20376f
 * @param payload payload passed through to callback function
Packit Service 20376f
 * @return 0 on success, negative callback return value, or error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_update_all(
Packit Service 20376f
	git_index *index,
Packit Service 20376f
	const git_strarray *pathspec,
Packit Service 20376f
	git_index_matched_path_cb callback,
Packit Service 20376f
	void *payload);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Find the first position of any entries which point to given
Packit Service 20376f
 * path in the Git index.
Packit Service 20376f
 *
Packit Service 20376f
 * @param at_pos the address to which the position of the index entry is written (optional)
Packit Service 20376f
 * @param index an existing index object
Packit Service 20376f
 * @param path path to search
Packit Service 20376f
 * @return a zero-based position in the index if found; GIT_ENOTFOUND otherwise
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_find(size_t *at_pos, git_index *index, const char *path);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Find the first position of any entries matching a prefix. To find the first position
Packit Service 20376f
 * of a path inside a given folder, suffix the prefix with a '/'.
Packit Service 20376f
 *
Packit Service 20376f
 * @param at_pos the address to which the position of the index entry is written (optional)
Packit Service 20376f
 * @param index an existing index object
Packit Service 20376f
 * @param prefix the prefix to search for
Packit Service 20376f
 * @return 0 with valid value in at_pos; an error code otherwise
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_find_prefix(size_t *at_pos, git_index *index, const char *prefix);
Packit Service 20376f
Packit Service 20376f
/**@}*/
Packit Service 20376f
Packit Service 20376f
/** @name Conflict Index Entry Functions
Packit Service 20376f
 *
Packit Service 20376f
 * These functions work on conflict index entries specifically (ie, stages 1-3)
Packit Service 20376f
 */
Packit Service 20376f
/**@{*/
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Add or update index entries to represent a conflict.  Any staged
Packit Service 20376f
 * entries that exist at the given paths will be removed.
Packit Service 20376f
 *
Packit Service 20376f
 * The entries are the entries from the tree included in the merge.  Any
Packit Service 20376f
 * entry may be null to indicate that that file was not present in the
Packit Service 20376f
 * trees during the merge.  For example, ancestor_entry may be NULL to
Packit Service 20376f
 * indicate that a file was added in both branches and must be resolved.
Packit Service 20376f
 *
Packit Service 20376f
 * @param index an existing index object
Packit Service 20376f
 * @param ancestor_entry the entry data for the ancestor of the conflict
Packit Service 20376f
 * @param our_entry the entry data for our side of the merge conflict
Packit Service 20376f
 * @param their_entry the entry data for their side of the merge conflict
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_conflict_add(
Packit Service 20376f
	git_index *index,
Packit Service 20376f
	const git_index_entry *ancestor_entry,
Packit Service 20376f
	const git_index_entry *our_entry,
Packit Service 20376f
	const git_index_entry *their_entry);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the index entries that represent a conflict of a single file.
Packit Service 20376f
 *
Packit Service 20376f
 * The entries are not modifiable and should not be freed.  Because the
Packit Service 20376f
 * `git_index_entry` struct is a publicly defined struct, you should
Packit Service 20376f
 * be able to make your own permanent copy of the data if necessary.
Packit Service 20376f
 *
Packit Service 20376f
 * @param ancestor_out Pointer to store the ancestor entry
Packit Service 20376f
 * @param our_out Pointer to store the our entry
Packit Service 20376f
 * @param their_out Pointer to store the their entry
Packit Service 20376f
 * @param index an existing index object
Packit Service 20376f
 * @param path path to search
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_conflict_get(
Packit Service 20376f
	const git_index_entry **ancestor_out,
Packit Service 20376f
	const git_index_entry **our_out,
Packit Service 20376f
	const git_index_entry **their_out,
Packit Service 20376f
	git_index *index,
Packit Service 20376f
	const char *path);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Removes the index entries that represent a conflict of a single file.
Packit Service 20376f
 *
Packit Service 20376f
 * @param index an existing index object
Packit Service 20376f
 * @param path path to remove conflicts for
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_conflict_remove(git_index *index, const char *path);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Remove all conflicts in the index (entries with a stage greater than 0).
Packit Service 20376f
 *
Packit Service 20376f
 * @param index an existing index object
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_conflict_cleanup(git_index *index);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Determine if the index contains entries representing file conflicts.
Packit Service 20376f
 *
Packit Service 20376f
 * @return 1 if at least one conflict is found, 0 otherwise.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_has_conflicts(const git_index *index);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Create an iterator for the conflicts in the index.
Packit Service 20376f
 *
Packit Service 20376f
 * The index must not be modified while iterating; the results are undefined.
Packit Service 20376f
 *
Packit Service 20376f
 * @param iterator_out The newly created conflict iterator
Packit Service 20376f
 * @param index The index to scan
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_conflict_iterator_new(
Packit Service 20376f
	git_index_conflict_iterator **iterator_out,
Packit Service 20376f
	git_index *index);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Returns the current conflict (ancestor, ours and theirs entry) and
Packit Service 20376f
 * advance the iterator internally to the next value.
Packit Service 20376f
 *
Packit Service 20376f
 * @param ancestor_out Pointer to store the ancestor side of the conflict
Packit Service 20376f
 * @param our_out Pointer to store our side of the conflict
Packit Service 20376f
 * @param their_out Pointer to store their side of the conflict
Packit Service 20376f
 * @return 0 (no error), GIT_ITEROVER (iteration is done) or an error code
Packit Service 20376f
 *         (negative value)
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_index_conflict_next(
Packit Service 20376f
	const git_index_entry **ancestor_out,
Packit Service 20376f
	const git_index_entry **our_out,
Packit Service 20376f
	const git_index_entry **their_out,
Packit Service 20376f
	git_index_conflict_iterator *iterator);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Frees a `git_index_conflict_iterator`.
Packit Service 20376f
 *
Packit Service 20376f
 * @param iterator pointer to the iterator
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(void) git_index_conflict_iterator_free(
Packit Service 20376f
	git_index_conflict_iterator *iterator);
Packit Service 20376f
Packit Service 20376f
/**@}*/
Packit Service 20376f
Packit Service 20376f
/** @} */
Packit Service 20376f
GIT_END_DECL
Packit Service 20376f
#endif