MCPcopy Index your code
hub / github.com/codeaashu/claude-code / useDiffData

Function useDiffData

src/hooks/useDiffData.ts:34–110  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32 * Fetches both stats and hunks when component mounts.
33 */
34export function useDiffData(): DiffData {
35 const [diffResult, setDiffResult] = useState<GitDiffResult | null>(null)
36 const [hunks, setHunks] = useState<Map<string, StructuredPatchHunk[]>>(
37 new Map(),
38 )
39 const [loading, setLoading] = useState(true)
40
41 // Fetch diff data on mount
42 useEffect(() => {
43 let cancelled = false
44
45 async function loadDiffData() {
46 try {
47 // Fetch both stats and hunks
48 const [statsResult, hunksResult] = await Promise.all([
49 fetchGitDiff(),
50 fetchGitDiffHunks(),
51 ])
52
53 if (!cancelled) {
54 setDiffResult(statsResult)
55 setHunks(hunksResult)
56 setLoading(false)
57 }
58 } catch (_error) {
59 if (!cancelled) {
60 setDiffResult(null)
61 setHunks(new Map())
62 setLoading(false)
63 }
64 }
65 }
66
67 void loadDiffData()
68
69 return () => {
70 cancelled = true
71 }
72 }, [])
73
74 return useMemo(() => {
75 if (!diffResult) {
76 return { stats: null, files: [], hunks: new Map(), loading }
77 }
78
79 const { stats, perFileStats } = diffResult
80 const files: DiffFile[] = []
81
82 // Iterate over perFileStats to get all files including large/skipped ones
83 for (const [path, fileStats] of perFileStats) {
84 const fileHunks = hunks.get(path)
85 const isUntracked = fileStats.isUntracked ?? false
86
87 // Detect large file (in perFileStats but not in hunks, and not binary/untracked)
88 const isLargeFile = !fileStats.isBinary && !isUntracked && !fileHunks
89
90 // Detect truncated file (total > limit means we truncated)
91 const totalLines = fileStats.added + fileStats.removed

Callers 1

DiffDialogFunction · 0.85

Calls 3

loadDiffDataFunction · 0.70
getMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected