From 892a5cec4dee58838fb18f87fcb00f9d8f4d35a8 Mon Sep 17 00:00:00 2001 From: Alex Palaistras Date: Tue, 6 Aug 2019 12:51:57 +0100 Subject: [PATCH] Render paths to end of time for branches with no final merges This is orthogonal to behaviour for rendering paths from the beginning of time for branches created before the first commit, and helps frame the history in a better way. --- grawkit | 14 ++++++++++++-- tests/01-initial.svg | 2 +- tests/02-master.svg | 3 ++- tests/03-branch.svg | 4 +++- tests/04-merge.svg | 3 ++- tests/05-multi-branch.svg | 4 +++- tests/06-feature-branch.svg | 4 +++- tests/07-multi-merge.svg | 4 +++- 8 files changed, 29 insertions(+), 9 deletions(-) diff --git a/grawkit b/grawkit index 51ae258..07900a7 100755 --- a/grawkit +++ b/grawkit @@ -129,7 +129,7 @@ function render_label(idx, class, name, _, buf, tw, w, h, hspc, vspc) { } # > Function `render_merge` renders merge paths for a branch pointed to by `idx`. -function render_merge(idx, _, buf, tmp, refs, fields, m, i, hspc) { +function render_merge(idx, _, buf, tmp, refs, fields, m, i, hspc, last) { # Do not render merge paths for branch with no commits. if (branches[idx,"refs"] == "") { return @@ -160,6 +160,16 @@ function render_merge(idx, _, buf, tmp, refs, fields, m, i, hspc) { # Draw the path. buf = buf "\n\t\t" sprintf(svg["path"], tmp) + + # Store the commit reference for the source commit of the last merge. + last = m[2] + } + + # Extend branch to the end of time, if the last commit reference wasn't a merge source commit. + if (refs[length(refs)] != last) { + tmp = "M" hspc "," refs[length(refs)] * style["commit/spacing"] + tmp = tmp " L" hspc "," (state["HEAD"] + 1) * style["commit/spacing"] + buf = buf "\n\t\t" sprintf(svg["path"], tmp) } return buf "\n\t" svg["/g"] @@ -414,7 +424,7 @@ END { w += style["branch/spacing"] * len["branches"] w -= (branches[0,"refs"] == "") ? style["branch/spacing"] : 0 - h = (style["commit/spacing"] * (len["commits"] - 1)) + (style["commit/stroke-width"] * 4) + h = (style["commit/spacing"] * (len["commits"])) + (style["commit/stroke-width"] * 4) # Print SVG header. printf svg["svg"], x, y, w, h diff --git a/tests/01-initial.svg b/tests/01-initial.svg index c18a018..f8462dd 100644 --- a/tests/01-initial.svg +++ b/tests/01-initial.svg @@ -4,7 +4,7 @@ --> - +