diff --git a/Makefile b/Makefile
index 777dbbe..4a2ceb6 100644
--- a/Makefile
+++ b/Makefile
@@ -16,7 +16,7 @@ SHELL = /bin/bash
DIFF = $(shell which colordiff || which diff)
# Test files to execute.
-TESTS ?= $(shell find tests/*/*)
+TESTS ?= $(shell find tests/*)
# Color & style definitions.
BOLD = \033[1m
diff --git a/grawkit b/grawkit
index d64b876..499e7bc 100755
--- a/grawkit
+++ b/grawkit
@@ -46,7 +46,7 @@ function addcommit(type, message) {
# > Function `branch` renders pre-defined branch under a specific name to its
# > SVG representation.
-function branch(idx, _, buf, tmp, refs, merge, m, i, bspc, cspc) {
+function branch(idx, _, buf, tmp, refs, i, bspc, cspc) {
# Do not render branch with no commits.
if (branches[idx,"refs"] == "") {
return
@@ -57,44 +57,62 @@ function branch(idx, _, buf, tmp, refs, merge, m, i, bspc, cspc) {
bspc = idx * style["branch/spacing"]
# Print branch root element.
- buf = sprintf(svg["g"], branches[idx,"name"])
-
- # Add merge paths for branch, if any.
- split(branches[idx,"merges"], merge, ",")
- for (i in merge) {
- split(merge[i], m, "|")
-
- # Add starting point to previous branch ending point.
- tmp = "M" m[1] * style["branch/spacing"] "," m[2] * style["commit/spacing"]
-
- # Add Bezier curve leading to current branch starting point.
- tmp = tmp " C" m[1] * style["branch/spacing"] "," m[2] * style["commit/spacing"]
- tmp = tmp " " bspc "," m[2] * style["commit/spacing"]
- tmp = tmp " " bspc "," refs[1] * style["commit/spacing"]
-
- # Draw the path.
- buf = buf "\n" sprintf(svg["path"], tmp)
- }
+ buf = sprintf(svg["g"], "branch-" branches[idx,"name"])
# Add path for branch.
tmp = "M" bspc "," refs[1] * style["commit/spacing"]
tmp = tmp " L" bspc "," refs[length(refs)] * style["commit/spacing"]
# Print path.
- buf = buf "\n" sprintf(svg["path"], tmp)
+ buf = buf "\n\t" sprintf(svg["path"], tmp)
# Add commits on path.
for (i in refs) {
cspc = refs[i] * style["commit/spacing"]
tmp = sprintf(svg["circle"], bspc, cspc, style["commit/radius"])
- buf = buf "\n" tmp
+ buf = buf "\n\t" tmp
}
buf = buf "\n" svg["/g"]
return buf
}
+# > Function `merge` renders merge paths for a branch pointed to by `idx`.
+function merge(idx, _, buf, tmp, refs, fields, m, i, bspc) {
+ # Do not render merge paths for branch with no commits.
+ if (branches[idx,"merges"] == "") {
+ return
+ }
+
+ # Get commit refs.
+ split(branches[idx,"refs"], refs, ",")
+ bspc = idx * style["branch/spacing"]
+
+ # Print branch root element.
+ buf = "\n\t" sprintf(svg["g"], "branch-" branches[idx,"name"])
+
+ # Add merge paths for branch, if any.
+ split(branches[idx,"merges"], fields, ",")
+ for (i in fields) {
+ split(fields[i], m, "|")
+
+ # Add starting point to previous branch ending point.
+ tmp = "M" m[1] * style["branch/spacing"] "," m[2] * style["commit/spacing"]
+
+ # Add Bezier curve leading to current branch starting point.
+ tmp = tmp " C" bspc "," m[2] * style["commit/spacing"]
+ tmp = tmp " " bspc "," m[2] * style["commit/spacing"]
+ tmp = tmp " " bspc "," refs[1] * style["commit/spacing"]
+
+ # Draw the path.
+ buf = buf "\n\t\t" sprintf(svg["path"], tmp)
+ }
+
+ buf = buf "\n\t" svg["/g"]
+ return buf
+}
+
# Global Declarations
# -------------------
#
@@ -125,19 +143,20 @@ BEGIN {
# Style definitions.
style["branch/spacing"] = "50"
style["branch/fill"] = "none"
- style["branch/stroke"] = "#333"
style["branch/stroke-width"] = "10"
style["commit/spacing"] = "50"
style["commit/fill"] = "#fff"
- style["commit/stroke"] = style["branch/stroke"]
style["commit/stroke-width"] = style["branch/stroke-width"] / 2
style["commit/radius"] = style["commit/stroke-width"] * 1.5
+ # Color scheme, based on `base16-solarized-dark`
+ style["pallete"] = "#002b36,#268bd2,#859900,#cb4b16,#2aa198,#dc322f,#d33682,#6c71c4,#b58900"
+
# Static SVG templates.
svg["svg"] = ""
- svg["g"] = ""
+ svg["g"] = ""
svg["/g"] = ""
svg["path"] = ""
svg["circle"] = ""
@@ -269,6 +288,9 @@ $0 ~ rule["merge"] {
# internal state, as defined in the command-line provided.
END {
+ buf = ""
+ split(style["pallete"], pallete, ",")
+
xy = style["branch/stroke-width"] * -1
w = (style["branch/spacing"] * (len["branches"] - 1)) + (style["branch/stroke-width"] * 2)
h = (style["commit/spacing"] * (len["commits"] - 1)) + (style["commit/stroke-width"] * 4)
@@ -281,16 +303,30 @@ END {
print ""
+ # Print merge paths for branches.
+ for (i = len["branches"] - 1; i >= 0; i--) {
+ buf = buf merge(i)
+ }
+
+ if (buf != "") {
+ printf svg["g"], "merge"
+ print buf "\n" svg["/g"]
+ }
+
# Print each branch and corresponding commits in turn.
for (i = len["branches"] - 1; i >= 0; i--) {
print branch(i)
diff --git a/tests/simple/01-initial.svg b/tests/01-initial.svg
similarity index 65%
rename from tests/simple/01-initial.svg
rename to tests/01-initial.svg
index b4b666f..a979664 100644
--- a/tests/simple/01-initial.svg
+++ b/tests/01-initial.svg
@@ -8,17 +8,16 @@
-
-
-
+
+
+
diff --git a/tests/simple/02-master.svg b/tests/02-master.svg
similarity index 57%
rename from tests/simple/02-master.svg
rename to tests/02-master.svg
index ed6279a..88e9241 100644
--- a/tests/simple/02-master.svg
+++ b/tests/02-master.svg
@@ -11,19 +11,18 @@ git commit
-
-
-
-
-
+
+
+
+
+
diff --git a/tests/03-branch.svg b/tests/03-branch.svg
new file mode 100644
index 0000000..b853090
--- /dev/null
+++ b/tests/03-branch.svg
@@ -0,0 +1,51 @@
+
+
+
diff --git a/tests/04-merge.svg b/tests/04-merge.svg
new file mode 100644
index 0000000..9043499
--- /dev/null
+++ b/tests/04-merge.svg
@@ -0,0 +1,52 @@
+
+
+
diff --git a/tests/05-multi-branch.svg b/tests/05-multi-branch.svg
new file mode 100644
index 0000000..b59c281
--- /dev/null
+++ b/tests/05-multi-branch.svg
@@ -0,0 +1,64 @@
+
+
+
diff --git a/tests/simple/03-branch.svg b/tests/simple/03-branch.svg
deleted file mode 100644
index cf78901..0000000
--- a/tests/simple/03-branch.svg
+++ /dev/null
@@ -1,47 +0,0 @@
-
-
-
diff --git a/tests/simple/04-merge.svg b/tests/simple/04-merge.svg
deleted file mode 100644
index 0749c4d..0000000
--- a/tests/simple/04-merge.svg
+++ /dev/null
@@ -1,48 +0,0 @@
-
-
-