From d887eca03cd0009624a86f48ff77e94f26450e0a Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Wed, 17 Sep 2014 12:02:13 +0100 Subject: [PATCH] Chaneg path scope & check excludedArray first treePaths, diffPaths and deletedPaths now all namespaced to top level so we can access from elsewhere Check we have excludedArray first before looking at it's index. This is to avoid issues when switching in and out of GitHub Diff mode. --- lib/get-branch.php | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/get-branch.php b/lib/get-branch.php index db80d22..e03d405 100644 --- a/lib/get-branch.php +++ b/lib/get-branch.php @@ -219,9 +219,9 @@ if ($_SESSION['githubDiff']) { var repo = github.getRepo(top.repo.split("/")[0], top.repo.split("/")[1]); repo.getTree('master?recursive=true', function(err, tree) { if(!err) { - treePaths = []; - diffPaths = []; - deletedPaths = []; + top.treePaths = []; + top.diffPaths = []; + top.deletedPaths = []; // ========================================================== // NEW FILES are not compared for diffs in this loop, so kept // ========================================================== @@ -241,16 +241,16 @@ if ($_SESSION['githubDiff']) { // CHANGED FILES are kept // ====================== if ("undefined" != typeof dirSHAArray[dirListArray.indexOf(tree[i].path)]) { - diffPaths.push(tree[i].path); + top.diffPaths.push(tree[i].path); // ====================== // DELETED FILES are kept // ====================== } else { - deletedPaths.push(tree[i].path); + top.deletedPaths.push(tree[i].path); } } } else { - treePaths.push(tree[i].path); + top.treePaths.push(tree[i].path); } } // Now we are only showing new, changed and deleted files from our GitHub tree list @@ -258,17 +258,17 @@ if ($_SESSION['githubDiff']) { // However, we should now consider dirs that the user hasn't opened yet as we can // maybe remove closed dirs that contain no changes - for (var i=0; i 0) { + if ("undefined" != typeof top.deletedPaths && top.deletedPaths.length > 0) { k = 0; top.addDeletedFiles = setInterval(function() { - fSplit = deletedPaths[k].lastIndexOf("/"); - thePath = deletedPaths[k].substr(0,fSplit); - theFile = deletedPaths[k].substr(fSplit+1); + fSplit = top.deletedPaths[k].lastIndexOf("/"); + thePath = top.deletedPaths[k].substr(0,fSplit); + theFile = top.deletedPaths[k].substr(fSplit+1); // If it's not excluded - if (excludedArray.indexOf((thePath == "" ? "" : "/" + thePath)+"/"+theFile) == -1) { + if ("undefined" != typeof excludedArray && excludedArray.indexOf((thePath == "" ? "" : "/" + thePath)+"/"+theFile) == -1) { // If we're adding a deleted dir/file in a sub-dir if ("" == "/"+thePath) { @@ -362,7 +362,7 @@ if ($_SESSION['githubDiff']) { } k++; - if ("undefined" == typeof deletedPaths[k]) { + if ("undefined" == typeof top.deletedPaths[k]) { clearInterval(top.addDeletedFiles); }