|
1
|
# Colorized Diffs |
|
2
|
|
|
3
|
The oldest and most widely compatible method to get colorized diffs in |
|
4
|
Fossil is to use its web UI: |
|
5
|
|
|
6
|
fossil ui --page '/vdiff?from=2024-04-01&to=trunk' |
|
7
|
|
|
8
|
That syntax is admittedly awkward, and it doesn’t work where “from” is |
|
9
|
the current checkout. Fortunately, there are many other methods to get |
|
10
|
colorized `diff` output from Fossil. |
|
11
|
|
|
12
|
|
|
13
|
<a id="ui"></a> |
|
14
|
## `fossil diff -b` |
|
15
|
|
|
16
|
This produces a graphical diff in HTML format and sends it to the |
|
17
|
user’s default web browser for viewing. |
|
18
|
|
|
19
|
|
|
20
|
|
|
21
|
<a id="ui"></a> |
|
22
|
## `fossil diff -tk` |
|
23
|
|
|
24
|
You may be surprised to learn that the prior feature doesn’t use any of |
|
25
|
the skinning or chrome from Fossil UI. This is because it is meant as a |
|
26
|
functional replacement for an older method of getting colorized diffs, |
|
27
|
“`fossil diff -tk`”. The feature was added after Apple stopped shipping |
|
28
|
Tcl/Tk in macOS, and the third-party replacements often failed to work |
|
29
|
correctly. It’s useful on other platforms as well. |
|
30
|
|
|
31
|
|
|
32
|
<a id="git"></a> |
|
33
|
## Delegate to Git |
|
34
|
|
|
35
|
It may be considered sacrilege by some, but the most direct method for |
|
36
|
those who want Git-like diff behavior may be to delegate diff behavior |
|
37
|
to Git: |
|
38
|
|
|
39
|
fossil set --global diff-command 'git diff --no-index' |
|
40
|
|
|
41
|
The flag permits it to diff files that aren’t inside a Git repository. |
|
42
|
|
|
43
|
|
|
44
|
<a id="diffutils"></a> |
|
45
|
## GNU Diffutils |
|
46
|
|
|
47
|
If your system is from 2016 or later, it may include [GNU Diffutils][gd] |
|
48
|
3.4 or newer, which lets you say: |
|
49
|
|
|
50
|
fossil set --global diff-command 'diff -dwu --color=always' |
|
51
|
|
|
52
|
You might think you could give `--color=auto`, but that fails with |
|
53
|
commands like “`fossil diff | less`” since the pipe turns the output |
|
54
|
non-interactive from the perspective of the underlying `diff` instance. |
|
55
|
|
|
56
|
This use of unconditional colorization means you will then have to |
|
57
|
remember to add the `-i` option to `fossil diff` commands when producing |
|
58
|
`patch(1)` files or piping diff output to another command that doesn’t |
|
59
|
understand ANSI escape sequences, such as [`diffstat`][ds]. |
|
60
|
|
|
61
|
[ds]: https://invisible-island.net/diffstat/ |
|
62
|
[gd]: https://www.gnu.org/software/diffutils/ |
|
63
|
|
|
64
|
|
|
65
|
<a id="bat"></a> |
|
66
|
## Bat, the Cat with Wings |
|
67
|
|
|
68
|
We can work around the `--color=auto` problem by switching from GNU less |
|
69
|
as our pager to [`bat`][bat], as it can detect GNU diff output and |
|
70
|
colorize it for you: |
|
71
|
|
|
72
|
fossil set --global diff-command 'diff -dwu --color=auto' |
|
73
|
fossil diff | bat |
|
74
|
|
|
75
|
In this author’s experience, that works a lot more reliably than GNU |
|
76
|
less’s ANSI color escape code handling, even when you set `LESS=-R` in |
|
77
|
your environment. |
|
78
|
|
|
79
|
The reason we don’t leave the `diff-command` unset in this case is that |
|
80
|
Fossil produces additional lines at the start which confuse the diff |
|
81
|
format detection in `bat`. Forcing output through an external diff |
|
82
|
command solves that. It also means that if you forget to pipe the output |
|
83
|
through `bat`, you still get colorized output from GNU diff. |
|
84
|
|
|
85
|
[bat]: https://github.com/sharkdp/bat |
|
86
|
|
|
87
|
|
|
88
|
<a id="colordiff"></a> |
|
89
|
## Colordiff |
|
90
|
|
|
91
|
A method that works on systems predating GNU diffutils 3.4 or the |
|
92
|
widespread availability of `bat` is to install [`colordiff`][cdurl], as |
|
93
|
it is included in [many package systems][cdpkg], including ones for |
|
94
|
outdated OSes. That then lets you say: |
|
95
|
|
|
96
|
fossil set --global diff-command 'colordiff -dwu' |
|
97
|
|
|
98
|
The main reason we list this alternative last is that it has the same |
|
99
|
limitation of unconditional color as [above](#diffutils). |
|
100
|
|
|
101
|
[cdurl]: https://www.colordiff.org/ |
|
102
|
[cdpkg]: https://repology.org/project/colordiff/versions |
|
103
|
|
|
104
|
<div style="height:50em" id="this-space-intentionally-left-blank"></div> |
|
105
|
|