Documentation
¶
Index ¶
- func EnsureWatcherService(homeDir, binPath string) error
- func IsDaemonRunning(homeDir string) (bool, int, error)
- func IsProcessAlive(pid int) bool
- func LoadGitignorePatterns(repoDir string) []string
- func PIDPath(homeDir string) string
- func ReadPID(homeDir string) (int, error)
- func RemovePID(homeDir string) error
- func RemoveState(homeDir string) error
- func ServiceFileContent(binPath string) string
- func ShouldIgnore(repoDir, filePath string) bool
- func ShouldIgnoreWithPatterns(repoDir, filePath string, patterns []string) bool
- func StatePath(homeDir string) string
- func WritePID(homeDir string) error
- type Daemon
- type DaemonConfig
- type EntryWriter
- type RepoDebouncer
- type RepoState
- type ServiceManager
- type WatchState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureWatcherService ¶
EnsureWatcherService checks if the watcher service should be installed or removed based on whether any project has precise mode enabled. binPath is the path to the hourgit binary.
func IsDaemonRunning ¶
IsDaemonRunning checks if the daemon is running by reading the PID file and verifying the process is alive.
func IsProcessAlive ¶
IsProcessAlive checks if a process with the given PID is running.
func LoadGitignorePatterns ¶
LoadGitignorePatterns reads .gitignore from the repo root and returns patterns.
func ServiceFileContent ¶
ServiceFileContent generates the systemd service unit content.
func ShouldIgnore ¶
ShouldIgnore checks if a file path should be ignored based on the repo's .gitignore patterns and built-in exclusions. Reads .gitignore from disk on each call — use ShouldIgnoreWithPatterns for the hot path.
func ShouldIgnoreWithPatterns ¶
ShouldIgnoreWithPatterns checks if a file path should be ignored using pre-loaded gitignore patterns. Use this on the hot path to avoid re-reading .gitignore from disk on every event.
Types ¶
type Daemon ¶
type Daemon struct {
// contains filtered or unexported fields
}
Daemon is the central background watcher that monitors repos with precise mode.
func NewDaemon ¶
func NewDaemon(homeDir string, writer EntryWriter) *Daemon
NewDaemon creates a new daemon instance.
type DaemonConfig ¶
DaemonConfig holds the daemon's runtime configuration for a single repo.
type EntryWriter ¶
type EntryWriter interface {
WriteActivityStop(homeDir, slug string, e entry.ActivityStopEntry) error
WriteActivityStart(homeDir, slug string, e entry.ActivityStartEntry) error
}
EntryWriter abstracts entry writing for testability.
func DefaultEntryWriter ¶
func DefaultEntryWriter() EntryWriter
DefaultEntryWriter returns the real entry writer.
type RepoDebouncer ¶
type RepoDebouncer struct {
// contains filtered or unexported fields
}
RepoDebouncer manages the debounce state machine for a single repo.
func NewRepoDebouncer ¶
func NewRepoDebouncer(repo, slug, homeDir string, threshold time.Duration, writer EntryWriter, state *WatchState) *RepoDebouncer
NewRepoDebouncer creates a debouncer for a single repo.
func (*RepoDebouncer) IsIdle ¶
func (d *RepoDebouncer) IsIdle() bool
IsIdle returns whether the debouncer is in idle state.
func (*RepoDebouncer) LastActivity ¶
func (d *RepoDebouncer) LastActivity() time.Time
LastActivity returns the last observed file change time.
func (*RepoDebouncer) OnFileEvent ¶
func (d *RepoDebouncer) OnFileEvent(now time.Time)
OnFileEvent is called when a file change is detected in the repo.
func (*RepoDebouncer) Shutdown ¶
func (d *RepoDebouncer) Shutdown()
Shutdown writes activity_stop if currently active and stops the timer.
type ServiceManager ¶
type ServiceManager interface {
Install(binPath string) error
Remove() error
Start() error
Stop() error
IsInstalled() bool
IsRunning() bool
}
ServiceManager manages the daemon as an OS service.
func NewServiceManager ¶
func NewServiceManager(homeDir string) (ServiceManager, error)
NewServiceManager returns the Linux (systemd) service manager.
type WatchState ¶
type WatchState struct {
Repos map[string]RepoState `json:"repos"`
// contains filtered or unexported fields
}
WatchState holds the daemon's state, flushed periodically to disk.
func LoadWatchState ¶
func LoadWatchState(homeDir string) (*WatchState, error)
LoadWatchState reads the state from disk. Returns a new empty state if the file doesn't exist.
func (*WatchState) Flush ¶
func (s *WatchState) Flush(homeDir string) error
Flush writes the state to disk.
func (*WatchState) GetLastActivity ¶
func (s *WatchState) GetLastActivity(repo string) (time.Time, bool)
GetLastActivity returns the last activity time for a repo.
func (*WatchState) RemoveRepo ¶
func (s *WatchState) RemoveRepo(repo string)
RemoveRepo removes a repo from the state.
func (*WatchState) SetLastActivity ¶
func (s *WatchState) SetLastActivity(repo string, t time.Time)
SetLastActivity updates the last activity time for a repo.