dsh-volcano-git-plugin 0.0.0-stage → 1.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/git-graph.mjs ADDED
@@ -0,0 +1,77 @@
1
+ // git-graph.mjs — dsh-git-manager 分支线布局算法
2
+ //
3
+ // 纯函数 computeGraph(commits):输入 git log --all --date-order 顺序的提交列表,
4
+ // 输出 { nodes, links, laneCount },Client 据此渲染 SVG 分支线图形。
5
+ //
6
+ // 节点:nodes[i] = { col, color } —— commits[i] 在第 col 列、颜色索引。
7
+ // 连线:links[] = { fromRow, fromCol, toRow, toCol, color, kind }
8
+ // kind ∈ "parent" | "merge" | "collapse"
9
+ // toRow=null 表示父提交不在当前窗口(Client 画到 SVG 底部)
10
+ //
11
+ // 不变量:--date-order 保证父提交晚于子提交出现,toRow > fromRow 恒成立。
12
+
13
+ export function computeGraph(commits) {
14
+ const lanes = []; // lanes[i] = { sha, color } | null
15
+ const rowOf = new Map();
16
+ commits.forEach((c, i) => rowOf.set(c.sha, i));
17
+ const nodes = [];
18
+ const links = [];
19
+ let colorSeq = 0;
20
+ let peak = 0;
21
+
22
+ const alloc = (sha, color) => {
23
+ let i = lanes.findIndex((l) => l === null);
24
+ if (i < 0) { i = lanes.length; lanes.push(null); }
25
+ lanes[i] = { sha, color: color ?? (colorSeq++ % 12) };
26
+ if (lanes.length > peak) peak = lanes.length;
27
+ return i;
28
+ };
29
+
30
+ commits.forEach((c, row) => {
31
+ let col = lanes.findIndex((l) => l && l.sha === c.sha);
32
+ if (col < 0) col = alloc(c.sha);
33
+ const color = lanes[col].color;
34
+
35
+ // 其他也在等这个 sha 的列并入本列(合并的另一侧)
36
+ for (let i = 0; i < lanes.length; i++) {
37
+ if (i !== col && lanes[i] && lanes[i].sha === c.sha) {
38
+ links.push({
39
+ fromRow: row, fromCol: col, toRow: row, toCol: i,
40
+ color: lanes[i].color, kind: "collapse",
41
+ });
42
+ lanes[i] = null;
43
+ }
44
+ }
45
+
46
+ nodes.push({ col, color });
47
+
48
+ const ps = Array.isArray(c.parents) ? c.parents : [];
49
+ if (ps.length === 0) {
50
+ lanes[col] = null;
51
+ } else {
52
+ const first = ps[0];
53
+ lanes[col] = { sha: first, color };
54
+ links.push({
55
+ fromRow: row, fromCol: col,
56
+ toRow: rowOf.has(first) ? rowOf.get(first) : null,
57
+ toCol: col, color, kind: "parent",
58
+ });
59
+ for (const p of ps.slice(1)) {
60
+ let pc = lanes.findIndex((l) => l && l.sha === p);
61
+ if (pc < 0) pc = alloc(p);
62
+ links.push({
63
+ fromRow: row, fromCol: col,
64
+ toRow: rowOf.has(p) ? rowOf.get(p) : null,
65
+ toCol: pc, color: lanes[pc].color, kind: "merge",
66
+ });
67
+ }
68
+ }
69
+ // 注意:不在循环里裁剪尾部空列——会破坏 alloc 的左偏重用 + 让 laneCount 错算。
70
+ // SVG 渲染宽度需要的是 peak(峰值同时活动列数),下面统一报告。
71
+ });
72
+
73
+ // 收尾裁剪只在"全部 commit 处理完"之后进行,仅影响 laneCount 报告(不保留释放的列即可)。
74
+ while (lanes.length && lanes[lanes.length - 1] === null) lanes.pop();
75
+
76
+ return { nodes, links, laneCount: peak };
77
+ }
package/icon.svg ADDED
@@ -0,0 +1,19 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="48" height="48">
2
+ <defs>
3
+ <linearGradient id="g-gm" x1="0" y1="0" x2="1" y2="1">
4
+ <stop offset="0" stop-color="#4D6BFE"/>
5
+ <stop offset="1" stop-color="#00B8A9"/>
6
+ </linearGradient>
7
+ </defs>
8
+ <rect x="2" y="2" width="44" height="44" rx="11" fill="url(#g-gm)"/>
9
+ <g fill="none" stroke="#fff" stroke-width="3" stroke-linecap="round">
10
+ <path d="M18 16.2 V29"/>
11
+ <path d="M18 18 C18 25 24 20 28.2 17"/>
12
+ </g>
13
+ <g fill="none" stroke="#fff" stroke-width="3">
14
+ <circle cx="18" cy="13.2" r="2.8"/>
15
+ <circle cx="18" cy="32" r="2.8"/>
16
+ <circle cx="31" cy="17" r="2.8"/>
17
+ </g>
18
+ <path d="M10 39.5 q3.5 -2.6 7 0 t7 0 t7 0 t7 0" fill="none" stroke="#fff" stroke-opacity=".5" stroke-width="1.6" stroke-linecap="round"/>
19
+ </svg>