Skip to content

Commit

Permalink
Handle multiple merges in gitgraph.js
Browse files Browse the repository at this point in the history
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 go-gitea#11981

Signed-off-by: Andrew Thornton <[email protected]>
  • Loading branch information
zeripath committed Jun 20, 2020
1 parent d31a9c5 commit ee503a1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 41 deletions.
64 changes: 31 additions & 33 deletions templates/repo/graph.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,37 @@
<div class="repository commits">
{{template "repo/header" .}}
<div class="ui container">
<div id="git-graph-container" class="ui segment">
<h1>{{.i18n.Tr "repo.commit_graph"}}</h1>
<div id="rel-container">
<canvas id="graph-canvas">
<ul id="graph-raw-list">
{{ range .Graph }}
<li><span class="node-relation">{{ .GraphAcii -}}</span></li>
{{ end }}
</ul>
</canvas>
</div>
<div id="rev-container">
<ul id="rev-list">
{{ range .Graph }}
<li>
{{ if .OnlyRelation }}
<span />
{{ else }}
<code id="{{.ShortRev}}">
<a href="{{AppSubUrl}}/{{$.Username}}/{{$.Reponame}}/commit/{{.Rev}}">{{ .ShortRev}}</a>
</code>
<strong> {{.Branch}}</strong>
<span>{{RenderCommitMessage .Subject $.RepoLink $.Repository.ComposeMetas}}</span> by
<span class="author">
{{.Author}}
</span>
<span class="time">{{.Date}}</span>
{{ end }}
</li>
{{ end }}
</ul>
</div>
</div>
<div id="git-graph-container" class="ui segment">
<h1>{{.i18n.Tr "repo.commit_graph"}}</h1>
<div id="rel-container">
<canvas id="graph-canvas">
<ul id="graph-raw-list">
{{ range .Graph }}
<li><span class="node-relation">{{ .GraphAcii -}}</span></li>
{{ end }}
</ul>
</canvas>
</div>
<div id="rev-container">
<ul id="rev-list">
{{ range .Graph }}
<li>
{{ if .OnlyRelation }}
<span />
{{ else }}
<code id="{{.ShortRev}}">
<a href="{{AppSubUrl}}/{{$.Username}}/{{$.Reponame}}/commit/{{.Rev}}">{{ .ShortRev}}</a>
</code>
<strong> {{.Branch}}</strong>
<span>{{RenderCommitMessage .Subject $.RepoLink $.Repository.ComposeMetas}}</span> by
<span class="author">{{.Author}}</span>
<span class="time">{{.Date}}</span>
{{ end }}
</li>
{{ end }}
</ul>
</div>
</div>
</div>
</div>
{{template "base/paginate" .}}
Expand Down
17 changes: 9 additions & 8 deletions web_src/js/vendor/gitgraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function gitGraph(canvas, rawGraphList, config) {

for (i = 0; i < l; i++) {
midStr = rawGraphList[i].replace(/\s+/g, ' ').replace(/^\s+|\s+$/g, '');

midStr = midStr.replace(/(--)|(-\.)/g,'-')
maxWidth = Math.max(midStr.replace(/(_|\s)/g, '').length, maxWidth);

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

// do some clean up
if (flows.length > condenseCurrentLength) {
flows.splice(condenseCurrentLength, flows.length - condenseCurrentLength);
}

colomnIndex = 0;

// a little inline analysis and draw process
Expand All @@ -362,10 +357,10 @@ export default function gitGraph(canvas, rawGraphList, config) {
continue;
}

// inline interset
// inline intersect
if ((colomn === '_' || colomn === '/')
&& currentRow[colomnIndex - 1] === '|'
&& currentRow[colomnIndex - 2] === '_') {
&& currentRow[colomnIndex - 2] === '_' ) {
inlineIntersect = true;

tempFlow = flows.splice(colomnIndex - 2, 1)[0];
Expand All @@ -380,6 +375,7 @@ export default function gitGraph(canvas, rawGraphList, config) {
color = flows[colomnIndex].color;

switch (colomn) {
case '-':
case '_':
drawLineRight(x, y, color);

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

y -= config.unitSize;
}

// do some clean up
if (flows.length > condenseCurrentLength) {
flows.splice(condenseCurrentLength, flows.length - condenseCurrentLength);
}
};

init();
Expand Down

0 comments on commit ee503a1

Please sign in to comment.