@@ -163,13 +163,77 @@ export function resolveFileDiffPreviousPath(fileDiff: FileDiffMetadata): string
163163 return raw ;
164164}
165165
166+ export function buildFileDiffIdentityKey ( fileDiff : FileDiffMetadata ) : string {
167+ return `${ resolveFileDiffPreviousPath ( fileDiff ) } \u0000${ resolveFileDiffPath ( fileDiff ) } ` ;
168+ }
169+
166170export function buildFileDiffRenderKey ( fileDiff : FileDiffMetadata ) : string {
167171 const cacheKey = fileDiff . cacheKey ;
168172 if ( ! cacheKey ) return `${ fileDiff . prevName ?? "none" } :${ fileDiff . name } ` ;
169173
170174 return cacheKey . endsWith ( ":hydrated" ) ? cacheKey . slice ( 0 , - ":hydrated" . length ) : cacheKey ;
171175}
172176
177+ function hashFileDiffPart ( hash : number , value : string | number | boolean | undefined ) : number {
178+ const serialized = value === undefined ? "undefined" : String ( value ) ;
179+ const withLength = fnv1a32 ( `${ typeof value } :${ serialized . length } :` , hash ) ;
180+ return fnv1a32 ( serialized , withLength ) ;
181+ }
182+
183+ /**
184+ * Content-only version for CodeView reconciliation. Pierre's cache key includes
185+ * the whole patch, so using it here would repaint every file when one changes.
186+ */
187+ export function buildFileDiffContentVersion ( fileDiff : FileDiffMetadata ) : number {
188+ let hash = FNV_OFFSET_BASIS_32 ;
189+ const append = ( value : string | number | boolean | undefined ) => {
190+ hash = hashFileDiffPart ( hash , value ) ;
191+ } ;
192+
193+ append ( fileDiff . name ) ;
194+ append ( fileDiff . prevName ) ;
195+ append ( fileDiff . lang ) ;
196+ append ( fileDiff . newObjectId ) ;
197+ append ( fileDiff . prevObjectId ) ;
198+ append ( fileDiff . mode ) ;
199+ append ( fileDiff . prevMode ) ;
200+ append ( fileDiff . type ) ;
201+ append ( fileDiff . isPartial ) ;
202+ append ( fileDiff . splitLineCount ) ;
203+ append ( fileDiff . unifiedLineCount ) ;
204+
205+ for ( const line of fileDiff . additionLines ) append ( line ) ;
206+ for ( const line of fileDiff . deletionLines ) append ( line ) ;
207+ for ( const hunk of fileDiff . hunks ) {
208+ append ( hunk . collapsedBefore ) ;
209+ append ( hunk . additionStart ) ;
210+ append ( hunk . additionCount ) ;
211+ append ( hunk . additionLines ) ;
212+ append ( hunk . additionLineIndex ) ;
213+ append ( hunk . deletionStart ) ;
214+ append ( hunk . deletionCount ) ;
215+ append ( hunk . deletionLines ) ;
216+ append ( hunk . deletionLineIndex ) ;
217+ append ( hunk . hunkContext ) ;
218+ append ( hunk . hunkSpecs ) ;
219+ append ( hunk . splitLineStart ) ;
220+ append ( hunk . splitLineCount ) ;
221+ append ( hunk . unifiedLineStart ) ;
222+ append ( hunk . unifiedLineCount ) ;
223+ append ( hunk . noEOFCRAdditions ) ;
224+ append ( hunk . noEOFCRDeletions ) ;
225+ for ( const content of hunk . hunkContent ) {
226+ append ( content . type ) ;
227+ append ( content . additionLineIndex ) ;
228+ append ( content . deletionLineIndex ) ;
229+ append ( content . type === "change" ? content . additions : content . lines ) ;
230+ append ( content . type === "change" ? content . deletions : undefined ) ;
231+ }
232+ }
233+
234+ return hash ;
235+ }
236+
173237export function getDiffCollapseIconClassName ( fileDiff : FileDiffMetadata ) : string {
174238 switch ( fileDiff . type ) {
175239 case "new" :
0 commit comments