+`;F.on("change",function(){try{let t=F.getValue(),n=JSON.stringify({type:"GitDiff",files:function(e){let t=[];for(;!e.isEof();){let n=function(e){if(!u(e.getCurLine()))return;let t=function(e){let[t,n]=e.getCurLine().split(" ").reverse();return(e.nextLine(),t&&n)?{from:m(e,n,"src"),to:m(e,t,"dst")}:null}(e),n=!1,i=!1,r=!1,c="",y="";for(;!e.isEof();){let l=function(e){if(u(e.getCurLine()))return null;let t=e.getCurLine(),n=o.find(e=>t.startsWith(e));return(n&&e.nextLine(),n===f.RenameFrom||n===f.RenameTo)?{type:n,path:t.slice(`${n} `.length)}:n?{type:n}:null}(e);if(!l)break;l.type===f.Deleted&&(n=!0,c=t?.from||""),l.type===f.NewFile&&(i=!0,y=t?.to||""),l.type===f.RenameFrom&&(r=!0,c=l.path),l.type===f.RenameTo&&(r=!0,y=l.path)}let g=function(e){let t=p(e,"--- "),n=t?m(e,t,"src"):t,i=p(e,"+++ "),r=i?m(e,i,"dst"):i;return r&&n?{added:r,deleted:n}:null}(e),F=function(e){let t=[];for(;!e.isEof();){let n=function(e){let t=function(e){let t=e.getCurLine(),n=/^@@\s\-(\d+),?(\d+)?\s\+(\d+),?(\d+)?\s@@\s?(.+)?/.exec(t);if(!n){let n=/^@@@\s\-(\d+),?(\d+)?\s\-(\d+),?(\d+)?\s\+(\d+),?(\d+)?\s@@@\s?(.+)?/.exec(t);if(!n){let n=/^Binary\sfiles\s(.*)\sand\s(.*)\sdiffer$/.exec(t);if(n){let[t,i,r]=n;return e.nextLine(),{type:"BinaryFiles",fileA:m(e,i,"src"),fileB:m(e,r,"dst")}}return null}let[i,r,l,s,a,f,o,u]=n;return e.nextLine(),{context:u,type:"Combined",fromFileRangeA:d(r,l),fromFileRangeB:d(s,a),toFileRange:d(f,o)}}let[i,r,l,s,a,f]=n;return e.nextLine(),{context:f,type:"Normal",toFileRange:d(s,a),fromFileRange:d(r,l)}}(e);if(t){if("Normal"===t.type){let n=h(e,t.fromFileRange,t.toFileRange);return{...t,type:"Chunk",changes:n}}else if("Combined"===t.type&&t.fromFileRangeA&&t.fromFileRangeB){let n=h(e,t.fromFileRangeA.start<t.fromFileRangeB.start?t.fromFileRangeA:t.fromFileRangeB,t.toFileRange);return{...t,type:"CombinedChunk",changes:n}}else if("BinaryFiles"===t.type&&t.fileA&&t.fileB)return{type:"BinaryFilesChunk",pathBefore:t.fileA,pathAfter:t.fileB}}}(e);if(!n)break;t.push(n)}return t}(e);if(n&&F.length&&"BinaryFilesChunk"===F[0].type)return{type:a,chunks:F,path:F[0].pathBefore};if(n)return{type:a,chunks:F,path:g?.deleted||c};if(i&&F.length&&"BinaryFilesChunk"===F[0].type)return{type:s,chunks:F,path:F[0].pathAfter};if(i)return{type:s,chunks:F,path:g?.added||y};if(r)return{type:"RenamedFile",pathAfter:y,pathBefore:c,chunks:F};if(g)return{type:l,chunks:F,path:g.added};else if(F.length&&"BinaryFilesChunk"===F[0].type&&F[0].pathAfter)return{type:l,chunks:F,path:F[0].pathAfter}}(e);if(!n)break;t.push(n)}return t}(new e(t,void 0))},null,2);x.setValue(n)}catch(e){x.setValue(`Error: ${e.message}`)}}),F.setValue(C);</script>
0 commit comments