From 7893e5939a4bafbd4a3e5a7699c81e7780429eda Mon Sep 17 00:00:00 2001
From: Alexey Terentyev <axifnx@gmail.com>
Date: Sat, 2 Jun 2018 18:54:40 +0300
Subject: [PATCH] Update gitgraph.js to fix "Cannot read property color of
 undefined" (#4095)

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
---
 public/vendor/VERSIONS                     |  2 +-
 public/vendor/plugins/gitgraph/gitgraph.js | 71 ++++++++++++++--------
 2 files changed, 45 insertions(+), 28 deletions(-)

diff --git a/public/vendor/VERSIONS b/public/vendor/VERSIONS
index 0ce93fe107..561d3d3e44 100644
--- a/public/vendor/VERSIONS
+++ b/public/vendor/VERSIONS
@@ -15,7 +15,7 @@ File(s): /vendor/plugins/clipboard/clipboard.min.js
 Version: 1.5.9
 
 File(s): /vendor/plugins/gitgraph/gitgraph.js
-Version: 9b492e8bf1ddf7908a4997b8f83fa38a809a9da3
+Version: 745f604212e2abfe2f0a59169ea530857b46625c
 
 File(s): /vendor/plugins/vue/vue.min.js
 Version: 2.1.10
diff --git a/public/vendor/plugins/gitgraph/gitgraph.js b/public/vendor/plugins/gitgraph/gitgraph.js
index bab36e7701..05ca0844d7 100644
--- a/public/vendor/plugins/gitgraph/gitgraph.js
+++ b/public/vendor/plugins/gitgraph/gitgraph.js
@@ -126,7 +126,20 @@ var gitGraph = function (canvas, rawGraphList, config) {
 			!(row[i - 2] && row[i] === "_" && row[i - 2] === "|")) {}
 		
 		return i;
-	}
+	};
+	
+	var findLineBreak = function (row) {
+		if (!row) {
+			return -1
+		}
+		
+		var i = row.length;
+		
+		while (i-- &&
+		!(row[i - 1] && row[i - 2] && row[i] === " " && row[i - 1] === "|" && row[i - 2] === "_")) {}
+		
+		return i;
+	};
 	
 	var genNewFlow = function () {
 		var newId;
@@ -138,21 +151,21 @@ var gitGraph = function (canvas, rawGraphList, config) {
 		return {id:newId, color:"#" + newId};
 	};
 	
-	//draw method
-	var drawLineRight = function (x, y, color) {
+	//Draw methods
+	var drawLine = function (moveX, moveY, lineX, lineY, color) {
 		ctx.strokeStyle = color;
 		ctx.beginPath();
-		ctx.moveTo(x, y + config.unitSize / 2);
-		ctx.lineTo(x + config.unitSize, y + config.unitSize / 2);
+		ctx.moveTo(moveX, moveY);
+		ctx.lineTo(lineX, lineY);
 		ctx.stroke();
 	};
 	
+	var drawLineRight = function (x, y, color) {
+		drawLine(x, y + config.unitSize / 2, x + config.unitSize, y + config.unitSize / 2, color);
+	};
+	
 	var drawLineUp = function (x, y, color) {
-		ctx.strokeStyle = color;
-		ctx.beginPath();
-		ctx.moveTo(x, y + config.unitSize / 2);
-		ctx.lineTo(x, y - config.unitSize / 2);
-		ctx.stroke();
+		drawLine(x, y + config.unitSize / 2, x, y - config.unitSize / 2, color);
 	};
 	
 	var drawNode = function (x, y, color) {
@@ -166,37 +179,28 @@ var gitGraph = function (canvas, rawGraphList, config) {
 	};
 	
 	var drawLineIn = function (x, y, color) {
-		ctx.strokeStyle = color;
-		
-		ctx.beginPath();
-		ctx.moveTo(x + config.unitSize, y + config.unitSize / 2);
-		ctx.lineTo(x, y - config.unitSize / 2);
-		ctx.stroke();
+		drawLine(x + config.unitSize, y + config.unitSize / 2, x, y - config.unitSize / 2, color);
 	};
 	
 	var drawLineOut = function (x, y, color) {
-		ctx.strokeStyle = color;
-		ctx.beginPath();
-		ctx.moveTo(x, y + config.unitSize / 2);
-		ctx.lineTo(x + config.unitSize, y - config.unitSize / 2);
-		ctx.stroke();
+		drawLine(x, y + config.unitSize / 2, x + config.unitSize, y - config.unitSize / 2, color);
 	};
 	
 	var draw = function (graphList) {
-		var colomn, colomnIndex, prevColomn, condenseIndex;
+		var colomn, colomnIndex, prevColomn, condenseIndex, breakIndex = -1;
 		var x, y;
 		var color;
-		var nodePos, outPos;
+		var nodePos;
 		var tempFlow;
 		var prevRowLength = 0;
 		var flowSwapPos = -1;
 		var lastLinePos;
-		var i, k, l;
+		var i, l;
 		var condenseCurrentLength, condensePrevLength = 0, condenseNextLength = 0;
 		
 		var inlineIntersect = false;
 		
-		//initiate for first row
+		//initiate color array for first row
 		for (i = 0, l = graphList[0].length; i < l; i++) {
 			if (graphList[0][i] !== "_" && graphList[0][i] !== " ") {
 				flows.push(genNewFlow());
@@ -275,6 +279,7 @@ var gitGraph = function (canvas, rawGraphList, config) {
 			colomnIndex = 0; //reset index
 			condenseIndex = 0;
 			condensePrevLength = 0;
+			breakIndex = -1; //reset break index
 			while (colomnIndex < currentRow.length) {
 				colomn = currentRow[colomnIndex];
 				
@@ -282,6 +287,18 @@ var gitGraph = function (canvas, rawGraphList, config) {
 					++condensePrevLength;
 				}
 				
+				//check and fix line break in next row
+				if (colomn === "/" && currentRow[colomnIndex - 1] && currentRow[colomnIndex - 1] === "|") {
+					if ((breakIndex = findLineBreak(nextRow)) !== -1) {
+						nextRow.splice(breakIndex, 1);
+					}
+				}
+				//if line break found replace all '/' with '|' after breakIndex in previous row
+				if (breakIndex !== - 1 && colomn === "/" && colomnIndex > breakIndex) {
+					currentRow[colomnIndex] = "|";
+					colomn = "|";
+				}
+				
 				if (colomn === " " && 
 					currentRow[colomnIndex + 1] &&
 					currentRow[colomnIndex + 1] === "_" &&
@@ -294,7 +311,7 @@ var gitGraph = function (canvas, rawGraphList, config) {
 					colomn = "/";
 				}
 				
-				//create new flow only when no intersetc happened
+				//create new flow only when no intersect happened
 				if (flowSwapPos === -1 &&
 					colomn === "/" &&
 					currentRow[colomnIndex - 1] && 
@@ -415,4 +432,4 @@ var gitGraph = function (canvas, rawGraphList, config) {
 	init();
 	draw(graphList);
 };
-// @end-license
+// @end-license
\ No newline at end of file