This commit is contained in:
2025-08-15 07:09:40 +02:00
parent e77f923cd2
commit e030309b7f
27 changed files with 167 additions and 285 deletions

View File

@@ -1,69 +1,58 @@
module gittools
// GitRepo holds information about a single Git repository.
// GitRepo represents a single git repository.
@[heap]
pub struct GitRepo {
// a git repo is always part of a git structure
mut:
gs &GitStructure
last_load int // epoch when last loaded
pub mut:
gs &GitStructure @[skip; str: skip] // Reference to the parent GitStructure
provider string // e.g., github.com, shortened to 'github'
account string // Git account name
name string // Repository name
status_remote GitRepoStatusRemote // Remote repository status
status_local GitRepoStatusLocal // Local repository status
status_wanted GitRepoStatusWanted // what is the status we want?
config GitRepoConfig // Repository-specific configuration
last_load int // Epoch timestamp of the last load from reality
deploysshkey string // to use with git
has_changes bool
provider string // e.g., github.com
account string // Git account name
name string // Repository name
deploysshkey string // SSH key for git operations
config GitRepoConfig
status GitStatus
}
// this is the status we want, we need to work towards off
pub struct GitRepoStatusWanted {
// GitStatus holds the unified status information for a repository.
// It reflects the CURRENT state, not a desired state.
pub struct GitStatus {
pub mut:
branch string
tag string
url string // Remote repository URL, is basically the one we want
readonly bool // if read only then we cannot push or commit, all changes will be reset when doing pull
// Combined local & remote state (from fetch)
branches map[string]string // All branch names -> commit hash
tags map[string]string // All tag names -> commit hash
// Current local state
branch string // The current checked-out branch.
tag string // The current checked-out tag (if any).
ahead int // Commits ahead of remote.
behind int // Commits behind remote.
// Combined status
has_changes bool // True if there are uncommitted local changes.
error string // Error message if any status update fails.
}
// GitRepoStatusRemote holds remote status information for a repository.
pub struct GitRepoStatusRemote {
pub mut:
ref_default string // is the default branch hash
branches map[string]string // Branch name -> commit hash
tags map[string]string // Tag name -> commit hash
error string // Error message if remote status update fails
}
// GitRepoStatusLocal holds local status information for a repository.
pub struct GitRepoStatusLocal {
pub mut:
branches map[string]string // Branch name -> commit hash
branch string // the current branch
tag string // If the local branch is not set, the tag may be set
ahead int // Commits ahead of remote
behind int // Commits behind remote
error string // Error message if local status update fails
}
// GitRepoConfig holds repository-specific configuration options.
pub struct GitRepoConfig {
pub mut:
remote_check_period int = 3600 * 24 * 7 // Seconds to wait between remote checks (0 = check every time), default 7 days
remote_check_period int = 300 // seconds, 5 min
}
// just some initialization mechanism
fn (mut gitstructure GitStructure) repo_new_from_gitlocation(git_location GitLocation) !&GitRepo {
mut repo := GitRepo{
provider: git_location.provider
name: git_location.name
account: git_location.account
gs: &gitstructure
status_remote: GitRepoStatusRemote{}
status_local: GitRepoStatusLocal{}
status_wanted: GitRepoStatusWanted{}
}
gitstructure.repos[repo.cache_key()] = &repo
// // just some initialization mechanism
// fn (mut gitstructure GitStructure) repo_new_from_gitlocation(git_location GitLocation) !&GitRepo {
// mut repo := GitRepo{
// provider: git_location.provider
// name: git_location.name
// account: git_location.account
// gs: &gitstructure
// status_remote: GitRepoStatusRemote{}
// status_local: GitRepoStatusLocal{}
// status_wanted: GitRepoStatusWanted{}
// }
// gitstructure.repos[repo.cache_key()] = &repo
return &repo
}
// return &repo
// }