mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 23:56:24 -04:00
I want an efficient way to get information about the commits of a repo. So far, our Commit model contains a mix of immutable and mutable fields, and this means we need to throw out commits whenever we refresh, because one of the mutable fields may have changed. The commit store will store a new model, ImmutableCommit which never changes so we can just continue adding commits to the store without worrying about invalidating any of it. One use case for this store is the ability to determine if one commit is an ancestor of another, which will help us colour the commits against each of our branches in the local branches view. Without an in-memory store, we would need to make one git call per commit which would be super slow. If this store proves useful, we could switch to using it as the source of truth for our commits, with mutable stuff handled separately.
31 lines
778 B
Go
31 lines
778 B
Go
package models
|
|
|
|
// This model contains the information that is intrinsic to a commit, meaning
|
|
// that we can depend on it not changing over time. Git commits are immutable,
|
|
// but our other Commit model has extra fields added for ease of use.
|
|
type ImmutableCommit struct {
|
|
hash string
|
|
|
|
// hashes of parent commits (will be multiple if it's a merge commit)
|
|
parentHashes []string
|
|
}
|
|
|
|
func NewImmutableCommit(hash string, parentHashes []string) ImmutableCommit {
|
|
return ImmutableCommit{
|
|
hash: hash,
|
|
parentHashes: parentHashes,
|
|
}
|
|
}
|
|
|
|
func (self *ImmutableCommit) Hash() string {
|
|
return self.hash
|
|
}
|
|
|
|
func (self *ImmutableCommit) ParentHashes() []string {
|
|
return self.parentHashes
|
|
}
|
|
|
|
func (self *ImmutableCommit) IsRoot() bool {
|
|
return len(self.parentHashes) == 0
|
|
}
|