Debian Codegraph @

cli/src/config/templates.toml

raw
1 [templates]
2 bookmark_list = 'format_commit_ref(self, "bookmark") ++ "\n"'
3
4 commit_summary = 'format_commit_summary_with_refs(self, format_commit_ref_names(bookmarks))'
5 arrange = 'builtin_log_compact'
6
7 file_annotate = '''
8 join(" ",
9 commit.change_id().shortest(8),
10 pad_end(8, truncate_end(8, commit.author().email().local())),
11 commit_timestamp(commit).local().format("%Y-%m-%d %H:%M:%S"),
12 pad_start(4, line_number),
13 ) ++ ": " ++ content
14 '''
15
16 config_list = 'builtin_config_list'
17
18 draft_commit_description = 'builtin_draft_commit_description'
19
20 duplicate_description = 'description'
21 new_description = ''
22
23 commit_trailers = ''
24
25 evolog = 'builtin_evolog_compact'
26
27 file_list = 'format_path(path) ++ "\n"'
28 file_show = ''
29
30 git_push_bookmark = '"push-" ++ change_id.short()'
31
32 log = 'builtin_log_compact'
33 show = 'builtin_log_detailed'
34 op_log = 'builtin_op_log_compact'
35 op_show = 'builtin_op_log_compact'
36
37 revert_description = '''
38 concat(
39 'Revert "' ++ description.first_line() ++ '"' ++ "\n",
40 "\n",
41 "This reverts commit " ++ commit_id ++ ".\n",
42 )
43 '''
44
45 tag_list = 'format_commit_ref(self, "tag") ++ "\n"'
46
47 workspace_list = 'builtin_workspace_list'
48
49 op_summary = '''
50 separate(" ",
51 self.id().short(),
52 if(root,
53 label("root", "root()"),
54 surround("(", ")", format_timestamp(self.time().end())),
55 ),
56 self.description().first_line(),
57 )
58 '''
59
60 log_node = '''
61 if(
62 config("ui.graph.style").as_string().starts_with("ascii"),
63 builtin_log_node_ascii,
64 builtin_log_node
65 )
66 '''
67
68 op_log_node = '''
69 if(
70 config("ui.graph.style").as_string().starts_with("ascii"),
71 builtin_op_log_node_ascii,
72 builtin_op_log_node
73 )
74 '''
75
76 [template-aliases]
77 'format_config_item(x)' = '''
78 if(x.overridden(),
79 indent("# ", x.name() ++ " = " ++ x.value()),
80 x.name() ++ " = " ++ x.value(),
81 )
82 '''
83
84 builtin_config_list = '''
85 label(if(overridden, "overridden"),
86 format_config_item(self) ++ "\n"
87 )
88 '''
89
90 builtin_config_list_detailed = '''
91 label(if(overridden, "overridden"),
92 format_config_item(self) ++ " # " ++ separate(" ", source, path) ++ "\n"
93 )
94 '''
95
96 builtin_draft_commit_description = '''
97 concat(
98 coalesce(description, default_commit_description, "\n"),
99 "\n",
100 "JJ: Change ID: " ++ format_short_change_id(change_id),
101 "\n",
102 surround(
103 "JJ: This commit contains the following changes:\n", "",
104 indent("JJ: ", diff.summary()),
105 ),
106 )
107 '''
108
109 builtin_draft_commit_description_with_diff = '''
110 concat(
111 builtin_draft_commit_description,
112 "\nJJ: ignore-rest\n",
113 diff.git(),
114 )
115 '''
116
117 builtin_evolog_compact = '''
118 concat(
119 builtin_log_compact(commit),
120 if(operation,
121 separate(" ",
122 label("separator", "--"),
123 "operation",
124 operation.id().short(),
125 operation.description().first_line(),
126 ) ++ "\n",
127 ),
128 )
129 '''
130
131 builtin_log_oneline = 'builtin_log_oneline(self)'
132 'builtin_log_oneline(commit)' = '''
133 if(commit.root(),
134 format_root_commit(commit),
135 label(
136 separate(" ",
137 if(commit.current_working_copy(), "working_copy"),
138 if(commit.immutable(), "immutable", "mutable"),
139 if(commit.conflict(), "conflicted"),
140 ),
141 separate(" ",
142 format_short_change_id_with_change_offset(commit),
143 format_short_signature_oneline(commit.author()),
144 format_timestamp(commit_timestamp(commit)),
145 commit.bookmarks(),
146 commit.tags(),
147 commit.working_copies(),
148 format_short_commit_id(commit.commit_id()),
149 format_commit_labels(commit),
150 if(config("ui.show-cryptographic-signatures").as_boolean(),
151 format_short_cryptographic_signature(commit.signature())
152 ),
153 if(commit.empty(), empty_commit_marker),
154 if(commit.description(),
155 commit.description().first_line(),
156 label(if(commit.empty(), "empty"), description_placeholder),
157 ),
158 ) ++ "\n",
159 )
160 )
161 '''
162
163 builtin_log_compact = 'builtin_log_compact(self)'
164 'builtin_log_compact(commit)' = '''
165 if(commit.root(),
166 format_root_commit(commit),
167 label(
168 separate(" ",
169 if(commit.current_working_copy(), "working_copy"),
170 if(commit.immutable(), "immutable", "mutable"),
171 if(commit.conflict(), "conflicted"),
172 ),
173 concat(
174 format_short_commit_header(commit) ++ "\n",
175 separate(" ",
176 if(commit.empty(), empty_commit_marker),
177 if(commit.description(),
178 commit.description().first_line(),
179 label(if(commit.empty(), "empty"), description_placeholder),
180 ),
181 ) ++ "\n",
182 ),
183 )
184 )
185 '''
186
187 builtin_log_redacted = 'builtin_log_redacted(self)'
188 'builtin_log_redacted(commit)' = '''
189 if(commit.root(),
190 format_root_commit(commit),
191 label(
192 separate(" ",
193 if(commit.current_working_copy(), "working_copy"),
194 if(commit.immutable(), "immutable", "mutable"),
195 if(commit.conflict(), "conflicted"),
196 ),
197 concat(
198 format_short_commit_header_redacted(commit) ++ "\n",
199 separate(" ",
200 if(commit.empty(), empty_commit_marker),
201 label("description", "(redacted)"),
202 ) ++ "\n",
203 ),
204 )
205 )
206 '''
207
208 builtin_log_compact_full_description = '''
209 builtin_log_compact_full_description(self)
210 '''
211 'builtin_log_compact_full_description(commit)' = '''
212 if(commit.root(),
213 format_root_commit(commit),
214 label(
215 separate(" ",
216 if(commit.current_working_copy(), "working_copy"),
217 if(commit.immutable(), "immutable", "mutable"),
218 if(commit.conflict(), "conflicted"),
219 ),
220 concat(
221 format_short_commit_header(commit) ++ "\n",
222 separate(" ",
223 if(commit.empty(), empty_commit_marker),
224 if(commit.description(),
225 commit.description().trim_end(),
226 label(if(commit.empty(), "empty"), description_placeholder),
227 ),
228 ) ++ "\n",
229 ),
230 )
231 ) ++ "\n"
232 '''
233
234 builtin_log_comfortable = 'builtin_log_compact ++ "\n"'
235 builtin_log_detailed = 'builtin_log_detailed(self)'
236 'builtin_log_detailed(commit)' = '''
237 concat(
238 "Commit ID: " ++ commit.commit_id() ++ "\n",
239 "Change ID: " ++ commit.change_id() ++ "\n",
240 surround("Bookmarks: ", "\n", separate(" ",
241 commit.local_bookmarks(),
242 commit.remote_bookmarks(),
243 )),
244 surround("Tags : ", "\n", commit.tags()),
245 "Author : " ++ format_detailed_signature(commit.author()) ++ "\n",
246 "Committer: " ++ format_detailed_signature(commit.committer()) ++ "\n",
247 if(config("ui.show-cryptographic-signatures").as_boolean(),
248 concat(
249 "Signature: ",
250 format_detailed_cryptographic_signature(commit.signature()),
251 "\n",
252 )
253 ),
254 "\n",
255 indent(" ",
256 if(commit.description(),
257 commit.description().trim_end(),
258 label(if(commit.empty(), "empty"), description_placeholder)
259 ) ++ "\n"
260 ),
261 "\n",
262 )
263 '''
264
265 builtin_op_log_compact = 'builtin_op_log_compact(self)'
266 'builtin_op_log_compact(op)' = '''
267 label(if(op.current_operation(), "current_operation"),
268 coalesce(
269 if(op.snapshot(), format_snapshot_operation(op)),
270 if(op.root(), format_root_operation(op)),
271 format_operation(op),
272 )
273 )
274 '''
275
276 builtin_op_log_comfortable = 'builtin_op_log_compact ++ "\n"'
277 builtin_op_log_oneline = 'builtin_op_log_oneline(self)'
278 'builtin_op_log_oneline(op)' = '''
279 label(if(current_operation, "current_operation"),
280 coalesce(
281 if(op.snapshot(), format_snapshot_operation_oneline(op)),
282 if(op.root(), format_root_operation(op)),
283 format_operation_oneline(op),
284 )
285 )
286 '''
287 builtin_op_log_redacted = 'builtin_op_log_redacted(self)'
288 'builtin_op_log_redacted(op)' = '''
289 label(if(op.current_operation(), "current_operation"),
290 coalesce(
291 if(op.snapshot(), format_snapshot_operation_redacted(op)),
292 if(op.root(), format_root_operation(op)),
293 format_operation_redacted(op),
294 )
295 )
296 '''
297
298 builtin_workspace_list = '''
299 concat(
300 name,
301 ": ",
302 separate(
303 " ",
304 if(root, root.relative()),
305 format_commit_summary_with_refs(target, format_commit_ref_names(target.bookmarks())),
306 ),
307 "\n",
308 )
309 '''
310
311 default_commit_description = '""'
312 empty_commit_marker = 'label("empty", "(empty)")'
313 description_placeholder = '''
314 label("description placeholder", "(no description set)")
315 '''
316 email_placeholder = 'label("email placeholder", "(no email set)")'
317 name_placeholder = 'label("name placeholder", "(no name set)")'
318 commit_summary_separator = 'label("separator", " | ")'
319
320 # Hook points for users to customize the default templates:
321 'commit_timestamp(commit)' = 'commit.committer().timestamp()'
322 'format_short_id(id)' = 'id.shortest(8)'
323 'format_short_change_id(id)' = 'format_short_id(id)'
324 'format_short_commit_id(id)' = 'format_short_id(id)'
325 'format_short_operation_id(id)' = 'id.short()'
326 'format_path(path)' = 'path.display()'
327 'format_short_signature(signature)' = '''
328 coalesce(signature.email(), email_placeholder)
329 '''
330 'format_short_signature_oneline(signature)' = '''
331 coalesce(signature.email().local(), email_placeholder)
332 '''
333
334 'format_detailed_signature(signature)' = '''
335 join(" ",
336 coalesce(signature.name(), name_placeholder),
337 "<" ++ coalesce(signature.email(), email_placeholder) ++ ">",
338 "(" ++ format_timestamp(signature.timestamp()) ++ ")",
339 )
340 '''
341 # For operations, when it makes a difference whether to use the start time or
342 # the end time, the latter is more meaningful. For mutating operations, this is
343 # the moment when the repo was actually modified due to this operation. TODO:
344 # This macro might need a better name, e.g. `format_operation_time_range`.
345 'format_time_range(time_range)' = '''
346 time_range.end().ago() ++ label("time", ", lasted ") ++ time_range.duration()
347 '''
348 'format_timestamp(timestamp)' = 'timestamp.local().format("%Y-%m-%d %H:%M:%S")'
349
350 'format_commit_summary_with_refs(commit, refs)' = '''
351 label(if(commit.current_working_copy(), "working_copy"),
352 separate(" ",
353 format_short_change_id_with_change_offset(commit),
354 format_short_commit_id(commit.commit_id()),
355 separate(commit_summary_separator,
356 refs,
357 separate(" ",
358 format_commit_labels(commit),
359 if(commit.empty(), empty_commit_marker),
360 if(commit.description(),
361 commit.description().first_line(),
362 label(if(commit.empty(), "empty"), description_placeholder),
363 ),
364 ),
365 ),
366 ),
367 )
368 '''
369
370 'format_root_commit(root)' = '''
371 label("immutable",
372 separate(" ",
373 format_short_change_id(root.change_id()),
374 label("root", "root()"),
375 format_short_commit_id(root.commit_id()),
376 root.bookmarks(),
377 ) ++ "\n"
378 )
379 '''
380
381 'format_commit_ref_names(refs)' = 'refs'
382
383 'format_commit_ref(ref, type)' = '''
384 if(ref.remote(),
385 if(ref.tracked(),
386 concat(
387 " ",
388 separate(" ",
389 label(type, "@" ++ ref.remote()),
390 if(ref.present(), format_tracked_remote_ref_distances(ref)),
391 ),
392 if(ref.present(), format_ref_targets(ref), " (not created yet)"),
393 ),
394 concat(
395 label(type, ref.name() ++ "@" ++ ref.remote()),
396 format_ref_targets(ref),
397 ),
398 ),
399 concat(
400 label(type, ref.name()),
401 if(ref.present(), format_ref_targets(ref), " (deleted)"),
402 ),
403 )
404 '''
405
406 'format_ref_targets(ref)' = '''
407 if(ref.conflict(),
408 separate("\n",
409 " " ++ label("conflict", "(conflicted)") ++ ":",
410 ref.removed_targets().map(|c|
411 " - " ++ format_commit_summary_with_refs(c, "")
412 ).join("\n"),
413 ref.added_targets().map(|c|
414 " + " ++ format_commit_summary_with_refs(c, "")
415 ).join("\n"),
416 ),
417 ": " ++ format_commit_summary_with_refs(ref.normal_target(), ""),
418 )
419 '''
420
421 'format_tracked_remote_ref_distances(ref)' = '''
422 if(ref.tracking_present(), surround("(", ")", separate(", ",
423 if(!ref.tracking_ahead_count().zero(),
424 if(ref.tracking_ahead_count().exact(),
425 "ahead by " ++ ref.tracking_ahead_count().exact() ++ " commits",
426 "ahead by at least " ++ ref.tracking_ahead_count().lower() ++ " commits"
427 )
428 ),
429 if(!ref.tracking_behind_count().zero(),
430 if(ref.tracking_behind_count().exact(),
431 "behind by " ++ ref.tracking_behind_count().exact() ++ " commits",
432 "behind by at least " ++ ref.tracking_behind_count().lower() ++ " commits"
433 )
434 ),
435 )))
436 '''
437
438 'format_operation(op)' = '''
439 concat(
440 separate(" ",
441 format_short_operation_id(op.id()),
442 op.user(),
443 op.workspace_name(),
444 format_time_range(op.time()),
445 ), "\n",
446 op.description().first_line(), "\n",
447 surround("", "\n", op.attributes()),
448 )
449 '''
450 'format_operation_redacted(op)' = '''
451 concat(
452 separate(" ",
453 format_short_operation_id(op.id()),
454 format_user_redacted(op.user()),
455 format_workspace_redacted(op.workspace_name()),
456 format_time_range(op.time()),
457 ), "\n",
458 op.description().first_line(), "\n",
459 if(op.attributes(), "(redacted)\n"),
460 )
461 '''
462 'format_workspace_redacted(workspace)' = '''
463 label("workspace", concat("workspace-", hash(workspace).substr(0, 4), "@"))
464 '''
465 'format_snapshot_operation(op)' = 'format_operation(op)'
466 'format_snapshot_operation_redacted(op)' = 'format_operation_redacted(op)'
467 'format_root_operation(root)' = '''
468 join(" ", root.id().short(), label("root", "root()")) ++ "\n"
469 '''
470
471 'format_operation_oneline(op)' = '''
472 separate(" ",
473 format_short_operation_id(op.id()), op.user(), op.workspace_name(), format_time_range(op.time()),
474 op.description().first_line(),
475 op.attributes(),
476 ) ++ "\n"
477 '''
478 'format_snapshot_operation_oneline(op)' = 'format_operation_oneline(op)'
479
480 'format_short_change_id_with_change_offset(commit)' = '''
481 coalesce(
482 if(commit.hidden(),
483 label("hidden",
484 format_short_change_id(commit.change_id()) ++ format_change_offset(commit),
485 ),
486 ),
487 if(commit.divergent(),
488 label("divergent",
489 format_short_change_id(commit.change_id()) ++ format_change_offset(commit),
490 ),
491 ),
492 format_short_change_id(commit.change_id()),
493 )
494 '''
495
496 'format_change_offset(commit)' = 'surround(label("change_offset", "/"), "", commit.change_offset())'
497
498 # We have "hidden" override "divergent", since a hidden revision does not cause
499 # divergence and is not affected by divergence.
500 'format_commit_labels(commit)' = '''
501 separate(" ",
502 coalesce(
503 if(commit.hidden(), label("hidden", "(hidden)")),
504 if(commit.divergent(), label("divergent", "(divergent)")),
505 ),
506 if(commit.conflict(), label("conflict", "(conflict)")),
507 )
508 '''
509
510 'format_short_commit_header(commit)' = '''
511 separate(" ",
512 format_short_change_id_with_change_offset(commit),
513 format_short_signature(commit.author()),
514 format_timestamp(commit_timestamp(commit)),
515 commit.bookmarks(),
516 commit.tags(),
517 commit.working_copies(),
518 format_short_commit_id(commit.commit_id()),
519 format_commit_labels(commit),
520 if(config("ui.show-cryptographic-signatures").as_boolean(),
521 format_short_cryptographic_signature(commit.signature())
522 ),
523 )
524 '''
525
526 # TODO: Possibly add some kind of repo-unique salt to the hash methods, if it
527 # makes users feel more secure (right now, `main` will always be `branch-c8c7a`
528 # for every repo)
529 'format_short_commit_header_redacted(commit)' = '''
530 separate(" ",
531 format_short_change_id_with_change_offset(commit),
532 label("author", format_user_redacted(commit.author())),
533 format_timestamp(commit_timestamp(commit)),
534 commit.bookmarks().map(|bookmark| concat(
535 "bookmark-", hash(bookmark.name()).substr(0, 4),
536 if(bookmark.remote(),
537 "@remote-" ++ hash(bookmark.remote()).substr(0, 4),
538 if(!bookmark.synced(), "*")
539 )
540 )),
541 commit.tags().map(|tag| concat("tag-", hash(tag.name()).substr(0, 4))),
542 commit.working_copies().map(|workspace| format_workspace_redacted(workspace)),
543 format_short_commit_id(commit.commit_id()),
544 format_commit_labels(commit),
545 if(config("ui.show-cryptographic-signatures").as_boolean(),
546 format_short_cryptographic_signature(commit.signature())
547 ),
548 )
549 '''
550
551 'format_detailed_cryptographic_signature(signature)' = '''
552 if(signature,
553 separate(" ",
554 label("signature status " ++ signature.status(), signature.status()),
555 "signature by",
556 coalesce(signature.display(), "(unknown)"),
557 signature.key(),
558 ),
559 "(no signature)",
560 )
561 '''
562 'format_short_cryptographic_signature(signature)' = '''
563 if(signature,
564 label("signature status", surround(
565 "[", "]",
566 label(signature.status(), coalesce(
567 if(signature.status() == "good", "✓︎"),
568 if(signature.status() == "unknown", "?"),
569 "x",
570 ))
571 ))
572 )
573 '''
574
575 'format_user_redacted(user)' = '''
576 label("user", concat("user-", hash(user).substr(0, 4)))
577 '''
578
579 builtin_log_node = '''
580 coalesce(
581 if(!self, label("elided", "~")),
582 label(
583 separate(" ",
584 if(current_working_copy, "working_copy"),
585 if(immutable, "immutable", "mutable"),
586 if(conflict, "conflicted"),
587 ),
588 coalesce(
589 if(current_working_copy, "@"),
590 if(immutable, "◆"),
591 if(conflict, "×"),
592 "○",
593 )
594 )
595 )
596 '''
597
598 builtin_log_node_ascii = '''
599 coalesce(
600 if(!self, label("elided", "~")),
601 label(
602 separate(" ",
603 if(current_working_copy, "working_copy"),
604 if(immutable, "immutable", "mutable"),
605 if(conflict, "conflicted"),
606 ),
607 coalesce(
608 if(current_working_copy, "@"),
609 if(immutable, "+"),
610 if(conflict, "x"),
611 "o",
612 )
613 )
614 )
615 '''
616
617 builtin_op_log_node = '''
618 coalesce(
619 if(current_operation, label("current_operation", "@")),
620 "○",
621 )
622 '''
623
624 builtin_op_log_node_ascii = '''
625 coalesce(
626 if(current_operation, label("current_operation", "@")),
627 "o",
628 )
629 '''
630
631 # The first line is a fixed magic date string used by
632 # programs like file(1) to identify that this is output from
633 # 'git format-patch'.
634 # See https://git-scm.com/docs/git-format-patch#_description
635 git_format_patch_email_headers = '''
636 concat(
637 "From " ++ commit_id ++ " Mon Sep 17 00:00:00 2001\n",
638 "From: " ++ author ++ "\n",
639 "Date: " ++ author.timestamp().format("%a, %-e %b %Y %T %z") ++ "\n",
640 "Subject: [PATCH] " ++ description.first_line() ++ "\n",
641 "\n",
642 description.remove_prefix(description.first_line()).trim_start(),
643 "---\n",
644 indent(" ", diff.stat()),
645 "\n",
646 )
647 '''
648
649 "format_signed_off_by_trailer(commit)" = '''
650 "Signed-off-by: " ++ commit.committer() ++ "\n"
651 '''
652
653 # Gerrit change ID is 40 chars, jj change ID is 32, so we need some padding.
654 # `6a6a6964` is the hexadecimal of `jjid` in ASCII, just to not pad with zeros.
655 "format_gerrit_change_id_trailer(commit)" = '''
656 "Change-Id: I" ++ commit.change_id().normal_hex() ++ "6a6a6964\n"
657 '''