From e486999f2a02b0b7fef77d52e5e3100ca7fa596a Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 20 May 2021 15:54:30 +0200 Subject: Too large patch diffs become hidden --- api/git.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'api/git.js') diff --git a/api/git.js b/api/git.js index 3161df0..4eb7fff 100644 --- a/api/git.js +++ b/api/git.js @@ -157,12 +157,27 @@ function getCommit(base_dir, repo_name, commit_oid) { return patch.hunks().then((hunks) => { - console.log(patch.newFile().path()); + console.log("\n" + patch.newFile().path()); const patch_start = patch_header_data[0][patch_index] + patch_header_data[1][patch_index]; const patch_end = (patch_header_data[0][patch_index + 1] !== undefined) ? patch_header_data[0][patch_index + 1] : all_patches.length - 1; const patch_content = all_patches.slice(patch_start, patch_end); + console.log(patch_content.length); + if(patch_content.length > 5000) { + console.log("Collapsed!"); + + arr.push({ + from: patch.oldFile().path(), + to: patch.newFile().path(), + additions: patch.lineStats()["total_additions"], + deletions: patch.lineStats()["total_deletions"], + too_large: true, + hunks: null + }); + return arr; + } + // Go through all of the patch's hunks // Patches are split into parts of where in the file the change is made. Those parts are called hunks. return hunks.reduce((acc, hunk, hunk_index) => @@ -197,7 +212,14 @@ function getCommit(base_dir, repo_name, commit_oid) old_lines: prev_hunk.oldLines(), }, parseHunkAddDel(patch_content.slice(hunks_data[0], patch_end)))); - arr.push({ from: patch.oldFile().path(), to: patch.newFile().path(), hunks: hunks_data[1] }); + arr.push({ + from: patch.oldFile().path(), + to: patch.newFile().path(), + additions: patch.lineStats()["total_additions"], + deletions: patch.lineStats()["total_deletions"], + too_large: false, + hunks: hunks_data[1] + }); return arr; }); -- cgit v1.2.3-18-g5258