From 72d105941675ce0727d973147f3d2a8cd54a5e0b Mon Sep 17 00:00:00 2001 From: Alex Palaistras Date: Tue, 6 Aug 2019 11:49:40 +0100 Subject: [PATCH] Simplify merge handling, add more tests This further simplifies handling of merges, which was made correct in commit 675e79c. We now correctly set both source and destination commit references, where an empty source reference means the base of the branch being merged into. --- Makefile | 2 +- grawkit | 34 +++++-------- tests/01-initial.svg | 6 +-- tests/05-multi-branch.svg | 2 +- tests/06-feature-branch.svg | 5 +- tests/07-multi-merge.svg | 95 +++++++++++++++++++++++++++++++++++++ 6 files changed, 112 insertions(+), 32 deletions(-) create mode 100644 tests/07-multi-merge.svg diff --git a/Makefile b/Makefile index 4a2ceb6..a517404 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ CMD = $(CURDIR)/grawkit # Default executables to use. SHELL = /bin/bash -DIFF = $(shell which colordiff || which diff) +DIFF = $(shell which colordiff 2> /dev/null || which diff) # Test files to execute. TESTS ?= $(shell find tests/*) diff --git a/grawkit b/grawkit index d5d40bd..51ae258 100755 --- a/grawkit +++ b/grawkit @@ -25,9 +25,9 @@ function add_branch(name) { # Branches created before the first commit is established extend to the # beginning of time. if (state["HEAD"] != "") { - branches[len["branches"],"merges"] = state["branch"] "|" state["HEAD"] + branches[len["branches"],"merges"] = state["branch"] "||" state["HEAD"] } else { - branches[len["branches"],"merges"] = len["branches"] "|0" + branches[len["branches"],"merges"] = len["branches"] "||0" } len["branches"] += 1 @@ -131,7 +131,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) { # Do not render merge paths for branch with no commits. - if (branches[idx,"merges"] == "") { + if (branches[idx,"refs"] == "") { return } @@ -148,24 +148,15 @@ function render_merge(idx, _, buf, tmp, refs, fields, m, i, hspc) { for (i in fields) { split(fields[i], m, "|") - if(length(m) == 2) { - # this is actually added by "git branch" command - # Add starting point to source branch ending point. - tmp = "M" m[1] * style["branch/spacing"] "," m[2] * style["commit/spacing"] + # Add starting point to target branch ending point. + tmp = "M" m[1] * style["branch/spacing"] "," m[3] * style["commit/spacing"] - # Add Bezier curve leading to target branch starting point. - tmp = tmp " C" hspc "," m[2] * style["commit/spacing"] - tmp = tmp " " hspc "," m[2] * style["commit/spacing"] - tmp = tmp " " hspc "," refs[1] * style["commit/spacing"] - } else { - # Add starting point to target branch ending point. - tmp = "M" m[1] * style["branch/spacing"] "," m[3] * style["commit/spacing"] + # Add Bezier curve leading to specific commit from source branch. + tmp = tmp " C" hspc "," m[3] * style["commit/spacing"] + tmp = tmp " " hspc "," m[3] * style["commit/spacing"] - # Add Bezier curve leading to specific commit from source branch. - tmp = tmp " C" hspc "," m[3] * style["commit/spacing"] - tmp = tmp " " hspc "," m[3] * style["commit/spacing"] - tmp = tmp " " hspc "," m[2] * style["commit/spacing"] - } + # Set default starting point for merge to beginning of branch, if none is set. + tmp = tmp " " hspc "," ((m[2] == "") ? refs[1] : m[2]) * style["commit/spacing"] # Draw the path. buf = buf "\n\t\t" sprintf(svg["path"], tmp) @@ -240,7 +231,7 @@ BEGIN { # Branch definitions. branches[0,"name"] = "master" branches[0,"refs"] = "" - branches[0,"merges"] = "0|0" + branches[0,"merges"] = "0||0" branches[0,"tags"] = "" len["branches"] = 1 @@ -352,9 +343,10 @@ $0 ~ rule["merge"] { add_commit("merge", "Merge commit") # Add merge reference from last commit in source branch to target branch. - # branch|from-commit|to-commit + # Format: to-branch|from-commit|to-commit split(branches[i,"refs"], refs, ",") merge = state["branch"] "|" refs[length(refs)] "|" state["HEAD"] + if (branches[i,"merges"] == "") { branches[i,"merges"] = merge } else { diff --git a/tests/01-initial.svg b/tests/01-initial.svg index 176a0fc..c18a018 100644 --- a/tests/01-initial.svg +++ b/tests/01-initial.svg @@ -29,9 +29,5 @@ } .branch-master {stroke: #002b36; fill: #002b36} ]]> - - - - - + diff --git a/tests/05-multi-branch.svg b/tests/05-multi-branch.svg index 735b1ac..9b5271a 100644 --- a/tests/05-multi-branch.svg +++ b/tests/05-multi-branch.svg @@ -62,7 +62,7 @@ git commit - + diff --git a/tests/06-feature-branch.svg b/tests/06-feature-branch.svg index f6a1787..45fcd12 100644 --- a/tests/06-feature-branch.svg +++ b/tests/06-feature-branch.svg @@ -66,14 +66,11 @@ git merge feature/ZZ-704_take-it-to-the-limit - + - - - diff --git a/tests/07-multi-merge.svg b/tests/07-multi-merge.svg new file mode 100644 index 0000000..6e98fb6 --- /dev/null +++ b/tests/07-multi-merge.svg @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + second + + + + + + + + + first + + + + + + + + + master + + +