aboutsummaryrefslogtreecommitdiffstats
path: root/formats/index/index.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-10-26 15:52:16 +0000
committerGitHub <noreply@github.com>2016-10-26 15:52:16 +0000
commitf5b199f725c4695bbab7b3e202b6fca2a66f6ca3 (patch)
tree29222ec30185a3c9bfc9c05689bbd8e34e3231fb /formats/index/index.go
parentf87b26504f684140edc9eb80258c3f27c91b92be (diff)
downloadgo-git-f5b199f725c4695bbab7b3e202b6fca2a66f6ca3.tar.gz
formats: Index read support (#91)
* utils: fs generic TestSuite * fs: fs.TempFile * utils: fs small changes requested * utils: fs, test fs.Create overwriting files * formats: index, basic v2 reader * formats: index, tree extension support * formats: index, stage decoding * formats: index, extended flags, v3 support * formats: index, v4 support * formats: index, Resolve undo support * formats: index, fix error when decoding invalidated entries * formats: index, fix style issues
Diffstat (limited to 'formats/index/index.go')
-rw-r--r--formats/index/index.go86
1 files changed, 86 insertions, 0 deletions
diff --git a/formats/index/index.go b/formats/index/index.go
new file mode 100644
index 0000000..bea199e
--- /dev/null
+++ b/formats/index/index.go
@@ -0,0 +1,86 @@
+package index
+
+import (
+ "os"
+ "time"
+
+ "gopkg.in/src-d/go-git.v4/core"
+)
+
+type Stage int
+
+const (
+ // Merged is the default stage, fully merged
+ Merged Stage = 1
+ // AncestorMode is the base revision
+ AncestorMode Stage = 1
+ // OurMode is the first tree revision, ours
+ OurMode Stage = 2
+ // TheirMode is the second tree revision, theirs
+ TheirMode Stage = 3
+)
+
+// Index contains the information about which objects are currently checked out
+// in the worktree, having information about the working files. Changes in
+// worktree are detected using this Index. The Index is also used during merges
+type Index struct {
+ Version uint32
+ EntryCount uint32
+ Entries []Entry
+ Cache *Tree
+ ResolveUndo *ResolveUndo
+}
+
+// Entry represents a single file (or stage of a file) in the cache. An entry
+// represents exactly one stage of a file. If a file path is unmerged then
+// multiple Entry instances may appear for the same path name.
+type Entry struct {
+ CreatedAt time.Time
+ ModifiedAt time.Time
+ Dev, Inode uint32
+ Mode os.FileMode
+ UID, GID uint32
+ Size uint32
+ Flags uint16
+ Stage Stage
+
+ SkipWorktree bool
+ IntentToAdd bool
+
+ Hash core.Hash
+ Name string
+}
+
+// Tree contains pre-computed hashes for trees that can be derived from the
+// index. It helps speed up tree object generation from index for a new commit.
+type Tree struct {
+ Entries []TreeEntry
+}
+
+// TreeEntry entry of a cached Tree
+type TreeEntry struct {
+ // Path component (relative to its parent directory)
+ Path string
+ // Entries is the number of entries in the index that is covered by the tree
+ // this entry represents
+ Entries int
+ // Trees is the number that represents the number of subtrees this tree has
+ Trees int
+ // Hash object name for the object that would result from writing this span
+ // of index as a tree.
+ Hash core.Hash
+}
+
+// ResolveUndo when a conflict is resolved (e.g. with "git add path"), these
+// higher stage entries will be removed and a stage-0 entry with proper
+// resolution is added. When these higher stage entries are removed, they are
+// saved in the resolve undo extension
+type ResolveUndo struct {
+ Entries []ResolveUndoEntry
+}
+
+// ResolveUndoEntry contains the information about a conflict when is resolved
+type ResolveUndoEntry struct {
+ Path string
+ Stages map[Stage]core.Hash
+}