MCPcopy Create free account
hub / github.com/JordanCoin/codemap / NewDaemon

Function NewDaemon

watch/daemon.go:29–67  ·  view source on GitHub ↗

NewDaemon creates a new watch daemon for the given root

(root string, verbose bool)

Source from the content-addressed store, hash-verified

27
28// NewDaemon creates a new watch daemon for the given root
29func NewDaemon(root string, verbose bool) (*Daemon, error) {
30 absRoot, err := filepath.Abs(root)
31 if err != nil {
32 return nil, fmt.Errorf("invalid root path: %w", err)
33 }
34
35 watcher, err := fsnotify.NewWatcher()
36 if err != nil {
37 return nil, fmt.Errorf("failed to create watcher: %w", err)
38 }
39
40 gitCache := scanner.NewGitIgnoreCache(root)
41
42 // Check if git repo (fast, one-time)
43 isGitRepo := false
44 if _, err := os.Stat(filepath.Join(absRoot, ".git")); err == nil {
45 isGitRepo = true
46 }
47
48 d := &Daemon{
49 root: absRoot,
50 watcher: watcher,
51 gitCache: gitCache,
52 verbose: verbose,
53 done: make(chan struct{}),
54 eventLog: filepath.Join(absRoot, ".codemap", "events.log"),
55 graph: &Graph{
56 Root: absRoot,
57 Files: make(map[string]*scanner.FileInfo),
58 DepCtx: make(map[string]*DepContext),
59 State: make(map[string]*FileState),
60 Events: make([]Event, 0),
61 WorkingSet: NewWorkingSet(),
62 IsGitRepo: isGitRepo,
63 },
64 }
65
66 return d, nil
67}
68
69// Start begins watching and returns immediately
70func (d *Daemon) Start() error {

Callers 12

main.goFile · 0.92
handleStartWatchFunction · 0.92
TestDaemonStartStopFunction · 0.85
TestEventDetectionFunction · 0.85
TestLineDeltaFunction · 0.85
TestNewFileCreationFunction · 0.85
TestFileRemovalFunction · 0.85
TestDebounceFunction · 0.85
TestNonSourceFileIgnoredFunction · 0.85

Calls 2

NewGitIgnoreCacheFunction · 0.92
NewWorkingSetFunction · 0.85

Tested by 10

TestDaemonStartStopFunction · 0.68
TestEventDetectionFunction · 0.68
TestLineDeltaFunction · 0.68
TestNewFileCreationFunction · 0.68
TestFileRemovalFunction · 0.68
TestDebounceFunction · 0.68
TestNonSourceFileIgnoredFunction · 0.68