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

Function computeDiffStatsBetweenMessages

src/components/MessageSelector.tsx:722–766  ·  view source on GitHub ↗

* Computes the diff stats for all the file edits in-between two messages.

(messages: Message[], fromMessageId: UUID, toMessageId: UUID | undefined)

Source from the content-addressed store, hash-verified

720 * Computes the diff stats for all the file edits in-between two messages.
721 */
722function computeDiffStatsBetweenMessages(messages: Message[], fromMessageId: UUID, toMessageId: UUID | undefined): DiffStats | undefined {
723 const startIndex = messages.findIndex(msg => msg.uuid === fromMessageId);
724 if (startIndex === -1) {
725 return undefined;
726 }
727 let endIndex = toMessageId ? messages.findIndex(msg => msg.uuid === toMessageId) : messages.length;
728 if (endIndex === -1) {
729 endIndex = messages.length;
730 }
731 const filesChanged: string[] = [];
732 let insertions = 0;
733 let deletions = 0;
734 for (let i = startIndex + 1; i < endIndex; i++) {
735 const msg = messages[i];
736 if (!msg || !isToolUseResultMessage(msg)) {
737 continue;
738 }
739 const result = msg.toolUseResult as FileEditOutput | FileWriteToolOutput;
740 if (!result || !result.filePath || !result.structuredPatch) {
741 continue;
742 }
743 if (!filesChanged.includes(result.filePath)) {
744 filesChanged.push(result.filePath);
745 }
746 try {
747 if ('type' in result && result.type === 'create') {
748 insertions += result.content.split(/\r?\n/).length;
749 } else {
750 for (const hunk of result.structuredPatch) {
751 const additions = count(hunk.lines, line => line.startsWith('+'));
752 const removals = count(hunk.lines, line => line.startsWith('-'));
753 insertions += additions;
754 deletions += removals;
755 }
756 }
757 } catch {
758 continue;
759 }
760 }
761 return {
762 filesChanged,
763 insertions,
764 deletions
765 };
766}
767export function selectableUserMessagesFilter(message: Message): message is UserMessage {
768 if (message.type !== 'user') {
769 return false;

Callers 1

loadFileHistoryMetadataFunction · 0.85

Calls 3

isToolUseResultMessageFunction · 0.85
countFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected