#ifndef INCLUDE_index_h__
#define INCLUDE_index_h__
-#include "fileops.h"
+#include "common.h"
+
+#include "futils.h"
#include "filebuf.h"
#include "vector.h"
+#include "idxmap.h"
#include "tree-cache.h"
#include "git2/odb.h"
#include "git2/index.h"
#define GIT_INDEX_FILE "index"
#define GIT_INDEX_FILE_MODE 0666
+extern bool git_index__enforce_unsaved_safety;
+
struct git_index {
git_refcount rc;
char *index_file_path;
git_futils_filestamp stamp;
+ git_oid checksum; /* checksum at the end of the file */
git_vector entries;
+ git_idxmap *entries_map;
- git_mutex lock; /* lock held while entries is being changed */
git_vector deleted; /* deleted entries if readers > 0 */
- git_atomic readers; /* number of active iterators */
+ git_atomic32 readers; /* number of active iterators */
unsigned int on_disk:1;
unsigned int ignore_case:1;
unsigned int distrust_filemode:1;
unsigned int no_symlinks:1;
+ unsigned int dirty:1; /* whether we have unsaved changes */
git_tree_cache *tree;
git_pool tree_pool;
git_vector_cmp entries_search;
git_vector_cmp entries_search_path;
git_vector_cmp reuc_search;
+
+ unsigned int version;
+};
+
+struct git_index_iterator {
+ git_index *index;
+ git_vector snap;
+ size_t cur;
};
struct git_index_conflict_iterator {
extern int git_index_entry_srch(const void *a, const void *b);
extern int git_index_entry_isrch(const void *a, const void *b);
+/* Index time handling functions */
+GIT_INLINE(bool) git_index_time_eq(const git_index_time *one, const git_index_time *two)
+{
+ if (one->seconds != two->seconds)
+ return false;
+
+#ifdef GIT_USE_NSEC
+ if (one->nanoseconds != two->nanoseconds)
+ return false;
+#endif
+
+ return true;
+}
+
+/*
+ * Test if the given index time is newer than the given existing index entry.
+ * If the timestamps are exactly equivalent, then the given index time is
+ * considered "racily newer" than the existing index entry.
+ */
+GIT_INLINE(bool) git_index_entry_newer_than_index(
+ const git_index_entry *entry, git_index *index)
+{
+ /* If we never read the index, we can't have this race either */
+ if (!index || index->stamp.mtime.tv_sec == 0)
+ return false;
+
+ /* If the timestamp is the same or newer than the index, it's racy */
+#if defined(GIT_USE_NSEC)
+ if ((int32_t)index->stamp.mtime.tv_sec < entry->mtime.seconds)
+ return true;
+ else if ((int32_t)index->stamp.mtime.tv_sec > entry->mtime.seconds)
+ return false;
+ else
+ return (uint32_t)index->stamp.mtime.tv_nsec <= entry->mtime.nanoseconds;
+#else
+ return ((int32_t)index->stamp.mtime.tv_sec) <= entry->mtime.seconds;
+#endif
+}
+
/* Search index for `path`, returning GIT_ENOTFOUND if it does not exist
* (but not setting an error message).
*
extern int git_index__find_pos(
size_t *at_pos, git_index *index, const char *path, size_t path_len, int stage);
+extern int git_index__fill(git_index *index, const git_vector *source_entries);
+
extern void git_index__set_ignore_case(git_index *index, bool ignore_case);
extern unsigned int git_index__create_mode(unsigned int mode);
return &index->stamp;
}
-extern int git_index__changed_relative_to(git_index *index, const git_futils_filestamp *fs);
+extern int git_index__changed_relative_to(git_index *index, const git_oid *checksum);
/* Copy the current entries vector *and* increment the index refcount.
* Call `git_index__release_snapshot` when done.
size_t *at_pos, git_vector *snap, git_vector_cmp entry_srch,
const char *path, size_t path_len, int stage);
+/* Replace an index with a new index */
+int git_index_read_index(git_index *index, const git_index *new_index);
+
+GIT_INLINE(int) git_index_is_dirty(git_index *index)
+{
+ return index->dirty;
+}
+
+extern int git_index_read_safely(git_index *index);
typedef struct {
git_index *index;