Skip to content

Commit a07cc0d

Browse files
authored
Handle multiple merges in gitgraph.js (#11996)
* Handle multiple merges in gitgraph.js There is a bug in web_src/js/vendor/gitgraph.js whereby it fails to handle multiple merges in a single commit correctly. This PR adds changes to make this work. Fix #11981 Signed-off-by: Andrew Thornton <[email protected]> * Update web_src/js/vendor/gitgraph.js
1 parent d31a9c5 commit a07cc0d

File tree

2 files changed

+39
-40
lines changed

2 files changed

+39
-40
lines changed

templates/repo/graph.tmpl

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,37 @@
22
<div class="repository commits">
33
{{template "repo/header" .}}
44
<div class="ui container">
5-
<div id="git-graph-container" class="ui segment">
6-
<h1>{{.i18n.Tr "repo.commit_graph"}}</h1>
7-
<div id="rel-container">
8-
<canvas id="graph-canvas">
9-
<ul id="graph-raw-list">
10-
{{ range .Graph }}
11-
<li><span class="node-relation">{{ .GraphAcii -}}</span></li>
12-
{{ end }}
13-
</ul>
14-
</canvas>
15-
</div>
16-
<div id="rev-container">
17-
<ul id="rev-list">
18-
{{ range .Graph }}
19-
<li>
20-
{{ if .OnlyRelation }}
21-
<span />
22-
{{ else }}
23-
<code id="{{.ShortRev}}">
24-
<a href="{{AppSubUrl}}/{{$.Username}}/{{$.Reponame}}/commit/{{.Rev}}">{{ .ShortRev}}</a>
25-
</code>
26-
<strong> {{.Branch}}</strong>
27-
<span>{{RenderCommitMessage .Subject $.RepoLink $.Repository.ComposeMetas}}</span> by
28-
<span class="author">
29-
{{.Author}}
30-
</span>
31-
<span class="time">{{.Date}}</span>
32-
{{ end }}
33-
</li>
34-
{{ end }}
35-
</ul>
36-
</div>
37-
</div>
5+
<div id="git-graph-container" class="ui segment">
6+
<h1>{{.i18n.Tr "repo.commit_graph"}}</h1>
7+
<div id="rel-container">
8+
<canvas id="graph-canvas">
9+
<ul id="graph-raw-list">
10+
{{ range .Graph }}
11+
<li><span class="node-relation">{{ .GraphAcii -}}</span></li>
12+
{{ end }}
13+
</ul>
14+
</canvas>
15+
</div>
16+
<div id="rev-container">
17+
<ul id="rev-list">
18+
{{ range .Graph }}
19+
<li>
20+
{{ if .OnlyRelation }}
21+
<span />
22+
{{ else }}
23+
<code id="{{.ShortRev}}">
24+
<a href="{{AppSubUrl}}/{{$.Username}}/{{$.Reponame}}/commit/{{.Rev}}">{{ .ShortRev}}</a>
25+
</code>
26+
<strong> {{.Branch}}</strong>
27+
<span>{{RenderCommitMessage .Subject $.RepoLink $.Repository.ComposeMetas}}</span> by
28+
<span class="author">{{.Author}}</span>
29+
<span class="time">{{.Date}}</span>
30+
{{ end }}
31+
</li>
32+
{{ end }}
33+
</ul>
34+
</div>
35+
</div>
3836
</div>
3937
</div>
4038
{{template "base/paginate" .}}

web_src/js/vendor/gitgraph.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default function gitGraph(canvas, rawGraphList, config) {
6565

6666
for (i = 0; i < l; i++) {
6767
midStr = rawGraphList[i].replace(/\s+/g, ' ').replace(/^\s+|\s+$/g, '');
68-
68+
midStr = midStr.replace(/(--)|(-\.)/g,'-')
6969
maxWidth = Math.max(midStr.replace(/(_|\s)/g, '').length, maxWidth);
7070

7171
row = midStr.split('');
@@ -343,11 +343,6 @@ export default function gitGraph(canvas, rawGraphList, config) {
343343
return (val !== ' ' && val !== '_');
344344
}).length;
345345

346-
// do some clean up
347-
if (flows.length > condenseCurrentLength) {
348-
flows.splice(condenseCurrentLength, flows.length - condenseCurrentLength);
349-
}
350-
351346
colomnIndex = 0;
352347

353348
// a little inline analysis and draw process
@@ -362,7 +357,7 @@ export default function gitGraph(canvas, rawGraphList, config) {
362357
continue;
363358
}
364359

365-
// inline interset
360+
// inline intersect
366361
if ((colomn === '_' || colomn === '/')
367362
&& currentRow[colomnIndex - 1] === '|'
368363
&& currentRow[colomnIndex - 2] === '_') {
@@ -380,6 +375,7 @@ export default function gitGraph(canvas, rawGraphList, config) {
380375
color = flows[colomnIndex].color;
381376

382377
switch (colomn) {
378+
case '-':
383379
case '_':
384380
drawLineRight(x, y, color);
385381

@@ -416,6 +412,11 @@ export default function gitGraph(canvas, rawGraphList, config) {
416412

417413
y -= config.unitSize;
418414
}
415+
416+
// do some clean up
417+
if (flows.length > condenseCurrentLength) {
418+
flows.splice(condenseCurrentLength, flows.length - condenseCurrentLength);
419+
}
419420
};
420421

421422
init();

0 commit comments

Comments
 (0)