summaryrefslogtreecommitdiff
path: root/trees/jj-log.typst
blob: 814cedb3e61d6ed0e7bde5bec713335c86cbd79d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#import "_lib/kodama.typ": *
#show: kodama

#let raw-text = read("_data/jj-log.json")
#let lines = raw-text.split("\n").filter(l => l.trim() != "")
#let commits = lines.map(l => json(bytes(l)))
#let commits = commits.filter(c => not c.root)

// Title is the shortest unique change id of the working copy (first commit)
#let wc-short = commits.at(0).short_change
#metadata(("title": wc-short))

// --- Helpers ---

#let body = raw(body)
#let tag-pill(name, color: rgb("#4a6fa5")) = {
  box(
    fill: color.lighten(75%),
    stroke: 0.5pt + color,
    radius: 3pt,
    inset: (x: 4pt, y: 2pt),
    text(size: 0.8em, weight: "bold", raw(name)),
  )
}

#let format-date(ts) = {
  let date-part = ts.slice(0, 10)
  let time-part = ts.slice(11, 16)
  date-part + " " + time-part
}

#let all-bookmarks = (
  commits
    .map(c => {
      c.bookmarks.map(b => (
        name: b.name,
        change: c.short_change,
        commit: c.short_commit,
        desc: c.commit.description.trim(),
      ))
    })
    .flatten()
)

#text(size: 0.9em, fill: luma(120))[
  #commits.len() commits #h(0.5em) | #h(0.5em)
  #all-bookmarks.len() bookmarks #h(0.5em) | #h(0.5em)
  newest #sym.arrow oldest
]

== Bookmarks

#if all-bookmarks.len() > 0 [
  #for bm in all-bookmarks [
    - #tag-pill(bm.name) #h(0.3em) at #bm.change — #emph(bm.desc)
  ]
] else [
  _No bookmarks in ancestor chain._
]

== Commit History

#table(
  columns: (auto, auto, 1fr, auto),
  align: (center, center, left, right),
  stroke: 0.4pt + luma(200),
  inset: 6pt,

  table.header(
    text(weight: "bold")[Change],
    text(weight: "bold")[Commit],
    text(weight: "bold")[Description],
    text(weight: "bold")[Date],
  ),

  ..commits
    .map(c => {
      let bookmarks = c.bookmarks.map(b => tag-pill(b.name))
      let desc = c.commit.description.trim()
      if desc == "" { desc = "(no description)" }

      let badges = {
        if c.empty { tag-pill("empty", color: rgb("#999")) }
        if c.conflict { tag-pill("conflict", color: rgb("#c44")) }
      }

      (
        c.short_change,
        c.short_commit,
        [
          #desc
          #if bookmarks.len() > 0 {
            h(0.3em)
            bookmarks.join(h(0.2em))
          }
          #badges
        ],
        text(size: 0.85em, fill: luma(100), format-date(
          c.commit.author.timestamp,
        )),
      )
    })
    .flatten(),
)