package core /* Revision represents a single commit in the repository. * Uses SVN-style sequential numbering (r1, r2, ...) with global counter. * Supports branching with global revision numbers across all branches. */ type Revision struct { Number int64 `json:"number"` // r1, r2, etc. - globally unique Timestamp int64 `json:"timestamp"` // Unix timestamp Author string `json:"author"` // username Message string `json:"message"` // commit message Branch string `json:"branch"` // "port", "feature/foo" Parent int64 `json:"parent"` // parent revision number (0 for initial) MergeParent int64 `json:"merge_parent"` // second parent for merges (0 if none) TreeHash string `json:"tree_hash"` // hash of tree manifest } // EntryKind represents the type of a tree entry type EntryKind uint8 const ( EntryKindFile EntryKind = iota // regular file EntryKindDir // directory EntryKindSymlink // symbolic link ) func (k EntryKind) String() string { switch k { case EntryKindFile: return "file" case EntryKindDir: return "dir" case EntryKindSymlink: return "symlink" default: return "unknown" } } /* TreeEntry represents a single file/directory in a tree manifest. * BlobHash uses xxhash64 for speed (16 hex chars). */ type TreeEntry struct { Path string `json:"path"` // relative path from repo root Mode uint32 `json:"mode"` // file permissions (unix mode) Size int64 `json:"size"` // file size in bytes BlobHash string `json:"blob_hash"` // content hash (xxhash64) Kind EntryKind `json:"kind"` // file, directory, symlink } /* Tree is a snapshot of the directory structure at a specific revision. * Hash is xxhash64 of the serialized entries. */ type Tree struct { Hash string `json:"hash"` Entries []TreeEntry `json:"entries"` } // NewTree creates a new tree and computes its hash func NewTree(entries []TreeEntry, computeHash func([]byte) string) (*Tree, error) { t := &Tree{Entries: entries} /* NOTE(kroot): hash is computed from JSON serialization of entries * this ensures consistent hashing across different runs */ return t, nil } // ChangeType represents the type of change between two trees type ChangeType uint8 const ( ChangeAdded ChangeType = iota // new file ChangeModified // file content changed ChangeDeleted // file removed ChangeModeOnly // only permissions changed ) func (c ChangeType) String() string { switch c { case ChangeAdded: return "added" case ChangeModified: return "modified" case ChangeDeleted: return "deleted" case ChangeModeOnly: return "mode" default: return "unknown" } } // Change represents a single file change between revisions type Change struct { Path string `json:"path"` Type ChangeType `json:"type"` OldRef *TreeEntry `json:"old_ref,omitempty"` // nil for added NewRef *TreeEntry `json:"new_ref,omitempty"` // nil for deleted }