#2631 Adding safeguard to the while loops

This commit is contained in:
Knut Sveidqvist
2022-01-16 15:08:14 +01:00
parent ce04c82356
commit 7abe279b4a
2 changed files with 9 additions and 3 deletions

View File

@@ -17,7 +17,9 @@ function getId() {
*/ */
function isfastforwardable(currentCommit, otherCommit) { function isfastforwardable(currentCommit, otherCommit) {
log.debug('Entering isfastforwardable:', currentCommit.id, otherCommit.id); log.debug('Entering isfastforwardable:', currentCommit.id, otherCommit.id);
while (currentCommit.seq <= otherCommit.seq && currentCommit !== otherCommit) { let cnt = 0;
while (currentCommit.seq <= otherCommit.seq && currentCommit !== otherCommit && cnt < 1000) {
cnt++;
// only if other branch has more commits // only if other branch has more commits
if (otherCommit.parent == null) break; if (otherCommit.parent == null) break;
if (Array.isArray(otherCommit.parent)) { if (Array.isArray(otherCommit.parent)) {

View File

@@ -227,7 +227,9 @@ function renderCommitHistory(svg, commitid, branches, direction) {
let commit; let commit;
const numCommits = Object.keys(allCommitsDict).length; const numCommits = Object.keys(allCommitsDict).length;
if (typeof commitid === 'string') { if (typeof commitid === 'string') {
let cnt = 0;
do { do {
cnt++;
commit = allCommitsDict[commitid]; commit = allCommitsDict[commitid];
log.debug('in renderCommitHistory', commit.id, commit.seq); log.debug('in renderCommitHistory', commit.id, commit.seq);
if (svg.select('#node-' + commitid).size() > 0) { if (svg.select('#node-' + commitid).size() > 0) {
@@ -293,7 +295,7 @@ function renderCommitHistory(svg, commitid, branches, direction) {
.text(', ' + commit.message); .text(', ' + commit.message);
} }
commitid = commit.parent; commitid = commit.parent;
} while (commitid && allCommitsDict[commitid]); } while (commitid && allCommitsDict[commitid] && cnt < 1000);
} }
if (Array.isArray(commitid)) { if (Array.isArray(commitid)) {
@@ -313,7 +315,9 @@ function renderCommitHistory(svg, commitid, branches, direction) {
*/ */
function renderLines(svg, commit, direction, branchColor) { function renderLines(svg, commit, direction, branchColor) {
branchColor = branchColor || 0; branchColor = branchColor || 0;
while (commit.seq > 0 && !commit.lineDrawn) { let cnt = 0;
while (commit.seq > 0 && !commit.lineDrawn && cnt < 1000) {
cnt++;
if (typeof commit.parent === 'string') { if (typeof commit.parent === 'string') {
svgDrawLineForCommits(svg, commit.id, commit.parent, direction, branchColor); svgDrawLineForCommits(svg, commit.id, commit.parent, direction, branchColor);
commit.lineDrawn = true; commit.lineDrawn = true;