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

Function BuildFileDetail

handoff/detail.go:15–66  ·  view source on GitHub ↗

BuildFileDetail resolves detailed context for one changed file stub.

(root string, artifact *Artifact, targetPath string, state *watch.State)

Source from the content-addressed store, hash-verified

13
14// BuildFileDetail resolves detailed context for one changed file stub.
15func BuildFileDetail(root string, artifact *Artifact, targetPath string, state *watch.State) (*FileDetail, error) {
16 if artifact == nil {
17 return nil, fmt.Errorf("handoff artifact is nil")
18 }
19 normalizeArtifact(artifact)
20
21 target := filepath.ToSlash(strings.TrimSpace(targetPath))
22 if target == "" {
23 return nil, fmt.Errorf("file path is required")
24 }
25
26 var selected *FileStub
27 for i := range artifact.Delta.Changed {
28 if artifact.Delta.Changed[i].Path == target {
29 selected = &artifact.Delta.Changed[i]
30 break
31 }
32 }
33 if selected == nil {
34 return nil, fmt.Errorf("file %q was not found in current handoff delta", target)
35 }
36
37 absRoot, err := filepath.Abs(root)
38 if err != nil {
39 return nil, err
40 }
41 if state == nil {
42 state = watch.ReadState(absRoot)
43 }
44
45 importers, imports := dependencyContextForFile(absRoot, state, target)
46 importers = uniqueSorted(importers)
47 imports = uniqueSorted(imports)
48
49 events := make([]EventSummary, 0, len(artifact.Delta.RecentEvents))
50 for _, event := range artifact.Delta.RecentEvents {
51 if event.Path == target {
52 events = append(events, event)
53 }
54 }
55
56 return &FileDetail{
57 Path: selected.Path,
58 Hash: selected.Hash,
59 Size: selected.Size,
60 Status: selected.Status,
61 Importers: importers,
62 Imports: imports,
63 RecentEvents: events,
64 IsHub: len(importers) >= 3,
65 }, nil
66}
67
68func dependencyContextForFile(root string, state *watch.State, path string) ([]string, []string) {
69 if state != nil && (len(state.Importers) > 0 || len(state.Imports) > 0) {

Callers 3

runHandoffSubcommandFunction · 0.92
handleGetHandoffFunction · 0.92
TestBuildFileDetailFunction · 0.85

Calls 4

ReadStateFunction · 0.92
normalizeArtifactFunction · 0.85
dependencyContextForFileFunction · 0.85
uniqueSortedFunction · 0.85

Tested by 1

TestBuildFileDetailFunction · 0.68