Blame src/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_index_h__
Packit Service 20376f
#define INCLUDE_index_h__
Packit Service 20376f
Packit Service 20376f
#include "fileops.h"
Packit Service 20376f
#include "filebuf.h"
Packit Service 20376f
#include "vector.h"
Packit Service 20376f
#include "idxmap.h"
Packit Service 20376f
#include "tree-cache.h"
Packit Service 20376f
#include "git2/odb.h"
Packit Service 20376f
#include "git2/index.h"
Packit Service 20376f
Packit Service 20376f
#define GIT_INDEX_FILE "index"
Packit Service 20376f
#define GIT_INDEX_FILE_MODE 0666
Packit Service 20376f
Packit Service 20376f
struct git_index {
Packit Service 20376f
	git_refcount rc;
Packit Service 20376f
Packit Service 20376f
	char *index_file_path;
Packit Service 20376f
	git_futils_filestamp stamp;
Packit Service 20376f
	git_oid checksum;   /* checksum at the end of the file */
Packit Service 20376f
Packit Service 20376f
	git_vector entries;
Packit Service 20376f
	git_idxmap *entries_map;
Packit Service 20376f
Packit Service 20376f
	git_vector deleted; /* deleted entries if readers > 0 */
Packit Service 20376f
	git_atomic readers; /* number of active iterators */
Packit Service 20376f
Packit Service 20376f
	unsigned int on_disk:1;
Packit Service 20376f
	unsigned int ignore_case:1;
Packit Service 20376f
	unsigned int distrust_filemode:1;
Packit Service 20376f
	unsigned int no_symlinks:1;
Packit Service 20376f
Packit Service 20376f
	git_tree_cache *tree;
Packit Service 20376f
	git_pool tree_pool;
Packit Service 20376f
Packit Service 20376f
	git_vector names;
Packit Service 20376f
	git_vector reuc;
Packit Service 20376f
Packit Service 20376f
	git_vector_cmp entries_cmp_path;
Packit Service 20376f
	git_vector_cmp entries_search;
Packit Service 20376f
	git_vector_cmp entries_search_path;
Packit Service 20376f
	git_vector_cmp reuc_search;
Packit Service 20376f
Packit Service 20376f
	unsigned int version;
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
struct git_index_conflict_iterator {
Packit Service 20376f
	git_index *index;
Packit Service 20376f
	size_t cur;
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
extern void git_index_entry__init_from_stat(
Packit Service 20376f
	git_index_entry *entry, struct stat *st, bool trust_mode);
Packit Service 20376f
Packit Service 20376f
/* Index entry comparison functions for array sorting */
Packit Service 20376f
extern int git_index_entry_cmp(const void *a, const void *b);
Packit Service 20376f
extern int git_index_entry_icmp(const void *a, const void *b);
Packit Service 20376f
Packit Service 20376f
/* Index entry search functions for search using a search spec */
Packit Service 20376f
extern int git_index_entry_srch(const void *a, const void *b);
Packit Service 20376f
extern int git_index_entry_isrch(const void *a, const void *b);
Packit Service 20376f
Packit Service 20376f
/* Index time handling functions */
Packit Service 20376f
GIT_INLINE(bool) git_index_time_eq(const git_index_time *one, const git_index_time *two)
Packit Service 20376f
{
Packit Service 20376f
	if (one->seconds != two->seconds)
Packit Service 20376f
		return false;
Packit Service 20376f
Packit Service 20376f
#ifdef GIT_USE_NSEC
Packit Service 20376f
	if (one->nanoseconds != two->nanoseconds)
Packit Service 20376f
		return false;
Packit Service 20376f
#endif
Packit Service 20376f
Packit Service 20376f
	return true;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
/*
Packit Service 20376f
 * Test if the given index time is newer than the given existing index entry.
Packit Service 20376f
 * If the timestamps are exactly equivalent, then the given index time is
Packit Service 20376f
 * considered "racily newer" than the existing index entry.
Packit Service 20376f
 */
Packit Service 20376f
GIT_INLINE(bool) git_index_entry_newer_than_index(
Packit Service 20376f
	const git_index_entry *entry, git_index *index)
Packit Service 20376f
{
Packit Service 20376f
	/* If we never read the index, we can't have this race either */
Packit Service 20376f
	if (!index || index->stamp.mtime.tv_sec == 0)
Packit Service 20376f
		return false;
Packit Service 20376f
Packit Service 20376f
	/* If the timestamp is the same or newer than the index, it's racy */
Packit Service 20376f
#if defined(GIT_USE_NSEC)
Packit Service 20376f
	if ((int32_t)index->stamp.mtime.tv_sec < entry->mtime.seconds)
Packit Service 20376f
		return true;
Packit Service 20376f
	else if ((int32_t)index->stamp.mtime.tv_sec > entry->mtime.seconds)
Packit Service 20376f
		return false;
Packit Service 20376f
	else
Packit Service 20376f
		return (uint32_t)index->stamp.mtime.tv_nsec <= entry->mtime.nanoseconds;
Packit Service 20376f
#else
Packit Service 20376f
	return ((int32_t)index->stamp.mtime.tv_sec) <= entry->mtime.seconds;
Packit Service 20376f
#endif
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
/* Search index for `path`, returning GIT_ENOTFOUND if it does not exist
Packit Service 20376f
 * (but not setting an error message).
Packit Service 20376f
 *
Packit Service 20376f
 * `at_pos` is set to the position where it is or would be inserted.
Packit Service 20376f
 * Pass `path_len` as strlen of path or 0 to call strlen internally.
Packit Service 20376f
 */
Packit Service 20376f
extern int git_index__find_pos(
Packit Service 20376f
	size_t *at_pos, git_index *index, const char *path, size_t path_len, int stage);
Packit Service 20376f
Packit Service 20376f
extern int git_index__fill(git_index *index, const git_vector *source_entries);
Packit Service 20376f
Packit Service 20376f
extern void git_index__set_ignore_case(git_index *index, bool ignore_case);
Packit Service 20376f
Packit Service 20376f
extern unsigned int git_index__create_mode(unsigned int mode);
Packit Service 20376f
Packit Service 20376f
GIT_INLINE(const git_futils_filestamp *) git_index__filestamp(git_index *index)
Packit Service 20376f
{
Packit Service 20376f
   return &index->stamp;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
extern int git_index__changed_relative_to(git_index *index, const git_oid *checksum);
Packit Service 20376f
Packit Service 20376f
/* Copy the current entries vector *and* increment the index refcount.
Packit Service 20376f
 * Call `git_index__release_snapshot` when done.
Packit Service 20376f
 */
Packit Service 20376f
extern int git_index_snapshot_new(git_vector *snap, git_index *index);
Packit Service 20376f
extern void git_index_snapshot_release(git_vector *snap, git_index *index);
Packit Service 20376f
Packit Service 20376f
/* Allow searching in a snapshot; entries must already be sorted! */
Packit Service 20376f
extern int git_index_snapshot_find(
Packit Service 20376f
	size_t *at_pos, git_vector *snap, git_vector_cmp entry_srch,
Packit Service 20376f
	const char *path, size_t path_len, int stage);
Packit Service 20376f
Packit Service 20376f
/* Replace an index with a new index */
Packit Service 20376f
int git_index_read_index(git_index *index, const git_index *new_index);
Packit Service 20376f
Packit Service 20376f
typedef struct {
Packit Service 20376f
	git_index *index;
Packit Service 20376f
	git_filebuf file;
Packit Service 20376f
	unsigned int should_write:1;
Packit Service 20376f
} git_indexwriter;
Packit Service 20376f
Packit Service 20376f
#define GIT_INDEXWRITER_INIT { NULL, GIT_FILEBUF_INIT }
Packit Service 20376f
Packit Service 20376f
/* Lock the index for eventual writing. */
Packit Service 20376f
extern int git_indexwriter_init(git_indexwriter *writer, git_index *index);
Packit Service 20376f
Packit Service 20376f
/* Lock the index for eventual writing by a repository operation: a merge,
Packit Service 20376f
 * revert, cherry-pick or a rebase.  Note that the given checkout strategy
Packit Service 20376f
 * will be updated for the operation's use so that checkout will not write
Packit Service 20376f
 * the index.
Packit Service 20376f
 */
Packit Service 20376f
extern int git_indexwriter_init_for_operation(
Packit Service 20376f
	git_indexwriter *writer,
Packit Service 20376f
	git_repository *repo,
Packit Service 20376f
	unsigned int *checkout_strategy);
Packit Service 20376f
Packit Service 20376f
/* Write the index and unlock it. */
Packit Service 20376f
extern int git_indexwriter_commit(git_indexwriter *writer);
Packit Service 20376f
Packit Service 20376f
/* Cleanup an index writing session, unlocking the file (if it is still
Packit Service 20376f
 * locked and freeing any data structures.
Packit Service 20376f
 */
Packit Service 20376f
extern void git_indexwriter_cleanup(git_indexwriter *writer);
Packit Service 20376f
Packit Service 20376f
#endif