MCPcopy Index your code
hub / github.com/bigcode-project/jupytercoder / parseHunk

Function parseHunk

src/diff.js:630–703  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

628
629
630 function parseHunk() {
631 var chunkHeaderIndex = i,
632 chunkHeaderLine = diffstr[i++],
633 chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
634 var hunk = {
635 oldStart: +chunkHeader[1],
636 oldLines: typeof chunkHeader[2] === 'undefined' ? 1 : +chunkHeader[2],
637 newStart: +chunkHeader[3],
638 newLines: typeof chunkHeader[4] === 'undefined' ? 1 : +chunkHeader[4],
639 lines: [],
640 linedelimiters: []
641 }; // Unified Diff Format quirk: If the chunk size is 0,
642 // the first number is one lower than one would expect.
643 // https://www.artima.com/weblogs/viewpost.jsp?thread=164293
644
645 if (hunk.oldLines === 0) {
646 hunk.oldStart += 1;
647 }
648
649 if (hunk.newLines === 0) {
650 hunk.newStart += 1;
651 }
652
653 var addCount = 0,
654 removeCount = 0;
655
656 for (; i < diffstr.length; i++) {
657 // Lines starting with '---' could be mistaken for the "remove line" operation
658 // But they could be the header for the next file. Therefore prune such cases out.
659 if (diffstr[i].indexOf('--- ') === 0 && i + 2 < diffstr.length && diffstr[i + 1].indexOf('+++ ') === 0 && diffstr[i + 2].indexOf('@@') === 0) {
660 break;
661 }
662
663 var operation = diffstr[i].length == 0 && i != diffstr.length - 1 ? ' ' : diffstr[i][0];
664
665 if (operation === '+' || operation === '-' || operation === ' ' || operation === '\\') {
666 hunk.lines.push(diffstr[i]);
667 hunk.linedelimiters.push(delimiters[i] || '\n');
668
669 if (operation === '+') {
670 addCount++;
671 } else if (operation === '-') {
672 removeCount++;
673 } else if (operation === ' ') {
674 addCount++;
675 removeCount++;
676 }
677 } else {
678 break;
679 }
680 } // Handle the empty block count case
681
682
683 if (!addCount && hunk.newLines === 1) {
684 hunk.newLines = 0;
685 }
686
687 if (!removeCount && hunk.oldLines === 1) {

Callers 1

parseIndexFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected