Fossil

Check-in [7c99ebc5]
Login

Check-in [7c99ebc5]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added a new doc distilling all the common methods for getting colorized diffs. Extracted its seed from the gitusers doc in part because it isn't Git-specific, and because there are more options to cover, sufficient to justify a separate doc.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 7c99ebc5921446c9da30486fb315df0f3ed67e1e7e7e1e39683e17159ef84bf7
User & Date: wyoung 2024-04-26 17:28:01
Context
2024-04-26
17:33
Explained why we don't leave diff-command unset for the "bat" alternative. ... (check-in: 9fca91e8 user: wyoung tags: trunk)
17:28
Added a new doc distilling all the common methods for getting colorized diffs. Extracted its seed from the gitusers doc in part because it isn't Git-specific, and because there are more options to cover, sufficient to justify a separate doc. ... (check-in: 7c99ebc5 user: wyoung tags: trunk)
16:19
Indent fix in gitusers.md to make it use a monospace font for nested command examples. ... (check-in: dd8d1a58 user: wyoung tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added www/colordiff.md.































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
# Colorized Diffs

The oldest and most widely compatible method to get colorized diffs in
Fossil is to use its web UI:

    fossil ui --page '/vdiff?from=2024-04-01&to=trunk'

That syntax is admittedly awkward, and it doesn’t work where “from” is
the current checkout.  Fortunately, there are many other methods to get
colorized `diff` output from Fossil.


<a id="ui"></a>
## `fossil diff -b`

This produces a graphical diff in HTML format and sends it to the
user’s default web browser for viewing.



<a id="ui"></a>
## `fossil diff -tk`

You may be surprised to learn that the prior feature doesn’t use any of
the skinning or chrome from Fossil UI. This is because it is meant as a
functional replacement for an older method of getting colorized diffs,
“`fossil diff -tk`”. The feature was added after Apple stopped shipping
Tcl/Tk in macOS, and the third-party replacements often failed to work
correctly. It’s useful on other platforms as well.


<a id="git"></a>
## Delegate to Git

It may be considered sacrilege by some, but the most direct method for
those who want Git-like diff behavior may be to delegate diff behavior
to Git:

    fossil set --global diff-command 'git diff --no-index'

The flag permits it to diff files that aren’t inside a Git repository.


<a id="diffutils"></a>
## GNU Diffutils

If your system is from 2016 or later, it may include [GNU Diffutils][gd]
3.4 or newer, which lets you say:

    fossil set --global diff-command 'diff -dwu --color=always'

You might think you could give `--color=auto`, but that fails with
commands like “`fossil diff | less`” since the pipe turns the output
non-interactive from the perspective of the underlying `diff` instance.

This use of unconditional colorization means you will then have to
remember to add the `-i` option to `fossil diff` commands when producing
`patch(1)` files or piping diff output to another command that doesn’t
understand ANSI escape sequences, such as [`diffstat`][ds].

[ds]: https://invisible-island.net/diffstat/
[gd]: https://www.gnu.org/software/diffutils/


<a id="bat"></a>
## Bat, the Cat with Wings

We can work around the `--color=auto` problem by switching from GNU less
as our pager to [`bat`][bat], as it can detect GNU diff output and
colorize it for you:

    fossil set --global diff-command 'diff -dwu --color=auto'
    fossil diff -i | bat

In this author’s experience, that works a lot more reliably than GNU
less’s ANSI color escape code handling, even when you set `LESS=-R` in
your environment.

[bat]: https://github.com/sharkdp/bat


<a id="colordiff"></a>
## Colordiff

A method that works on systems predating GNU diffutils 3.4 or the
widespread availability of `bat` is to install [`colordiff`][cd], as
it is included in [many package systems][cdpkg], including ones for
outdated OSes. That then lets you say:

    fossil set --global diff-command 'colordiff -dwu'

The main reason we list this alternative last is that it has the same
limitation of unconditional color as [above](#diffutils).

[cd]: https://www.colordiff.org/

Changes to www/gitusers.md.

848
849
850
851
852
853
854
855

856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
There is only one sub-feature of `git rebase` that is philosophically
compatible with Fossil yet which currently has no functional equivalent.
We [covered this and the workaround for its lack](#comsplit) above.

[3]: ./rebaseharm.md


## <a id="cdiff"></a> Colorized Diffs


When you run `git diff` on an ANSI X3.64 capable terminal, it uses color
to distinguish insertions, deletions, and replacements, but as of this
writing, `fossil diff` produces traditional uncolored [unified diff
format][udiff] output, suitable for producing a [patch file][pfile].

Nevertheless, there are multiple ways to get colorized diff output from
Fossil:

*   The most direct method is to delegate diff behavior back to Git:

        fossil set --global diff-command 'git diff --no-index'

    The flag permits it to diff files that aren’t inside a Git repository.

*   Another method is to install [`colordiff`][cdiff] — included in
    [many package systems][cdpkg] — then say:

        fossil set --global diff-command 'colordiff -wu'

    Because this is unconditional, unlike `git diff --color=auto`, you
    will then have to remember to add the `-i` option to `fossil diff`
    commands when you want color disabled, such as when producing
    `patch(1)` files or piping diff output to another command that
    doesn’t understand ANSI escape sequences. There’s an example of this
    [below](#dstat).

*   Use the Fossil web UI to diff existing commits.

*   To diff the current working directory contents against some parent
    instead, Fossil’s diff command can produce
    colorized HTML output and open it in the OS’s default web browser.
    For example, `fossil diff -by` will show side-by-side diffs.

*   Use the older `fossil diff --tk` option to do much the same using
    Tcl/Tk instead of a browser.

Viewed this way, Fossil doesn’t lack colorized diffs, it simply has
*one* method where they *aren’t* colorized.

[cdpkg]: https://repology.org/project/colordiff/versions
[pfile]: https://en.wikipedia.org/wiki/Patch_(Unix)
[udiff]: https://en.wikipedia.org/wiki/Diff#Unified_format








|
>






<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







848
849
850
851
852
853
854
855
856
857
858
859
860
861
862


863




























864
865
866
867
868
869
870
There is only one sub-feature of `git rebase` that is philosophically
compatible with Fossil yet which currently has no functional equivalent.
We [covered this and the workaround for its lack](#comsplit) above.

[3]: ./rebaseharm.md


<a id="cdiff"></a>
## Colorized Diffs

When you run `git diff` on an ANSI X3.64 capable terminal, it uses color
to distinguish insertions, deletions, and replacements, but as of this
writing, `fossil diff` produces traditional uncolored [unified diff
format][udiff] output, suitable for producing a [patch file][pfile].



There are [many methods](./colordiff.md) for solving this.




























Viewed this way, Fossil doesn’t lack colorized diffs, it simply has
*one* method where they *aren’t* colorized.

[cdpkg]: https://repology.org/project/colordiff/versions
[pfile]: https://en.wikipedia.org/wiki/Patch_(Unix)
[udiff]: https://en.wikipedia.org/wiki/Diff#Unified_format

962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
The `--numstat` output is a bit cryptic, so we recommend delegating
this task to [the widely-available `diffstat` tool][dst], which gives
a histogram in its default output mode rather than bare integers:

    fossil diff -i -v --from 2020-04-01 | diffstat

We gave the `-i` flag in both cases to force Fossil to use its internal
diff implementation, bypassing [your local `diff-command` setting][dcset].
The `--numstat` option has no effect when you have an external diff
command set, and some diff command alternatives like
[`colordiff`][cdiff] (covered [above](#cdiff)) produce output that confuses `diffstat`.

If you leave off the `-v` flag in the second example, the `diffstat`
output won’t include info about any newly-added files.

[cdiff]: https://www.colordiff.org/
[dcset]: https://fossil-scm.org/home/help?cmd=diff-command
[dst]:   https://invisible-island.net/diffstat/diffstat.html


<a id="btnames"></a>
## Branch and Tag Names








|
|
|
<




<







933
934
935
936
937
938
939
940
941
942

943
944
945
946

947
948
949
950
951
952
953
The `--numstat` output is a bit cryptic, so we recommend delegating
this task to [the widely-available `diffstat` tool][dst], which gives
a histogram in its default output mode rather than bare integers:

    fossil diff -i -v --from 2020-04-01 | diffstat

We gave the `-i` flag in both cases to force Fossil to use its internal
diff implementation, bypassing [your local `diff-command` setting][dcset]
since the `--numstat` option has no effect when you have an external diff
command set.


If you leave off the `-v` flag in the second example, the `diffstat`
output won’t include info about any newly-added files.


[dcset]: https://fossil-scm.org/home/help?cmd=diff-command
[dst]:   https://invisible-island.net/diffstat/diffstat.html


<a id="btnames"></a>
## Branch and Tag Names

Changes to www/mkindex.tcl.

33
34
35
36
37
38
39

40
41
42
43
44
45
46
  chat.md {Fossil Chat}
  checkin_names.wiki {Check-in And Version Names}
  checkin.wiki {Check-in Checklist}
  childprojects.wiki {Child Projects}
  chroot.md {Server Chroot Jail}
  ckout-workflows.md {Check-Out Workflows}
  co-vs-up.md {Checkout vs Update}

  copyright-release.html {Contributor License Agreement}
  concepts.wiki {Fossil Core Concepts}
  contact.md {Developer Contact Information}
  containers.md {OCI Containers}
  contribute.wiki {Contributing Code or Documentation To The Fossil Project}
  css-tricks.md {Fossil CSS Tips and Tricks}
  customgraph.md {Theming: Customizing the Timeline Graph}







>







33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
  chat.md {Fossil Chat}
  checkin_names.wiki {Check-in And Version Names}
  checkin.wiki {Check-in Checklist}
  childprojects.wiki {Child Projects}
  chroot.md {Server Chroot Jail}
  ckout-workflows.md {Check-Out Workflows}
  co-vs-up.md {Checkout vs Update}
  colordiff.md {Colorized Diffs}
  copyright-release.html {Contributor License Agreement}
  concepts.wiki {Fossil Core Concepts}
  contact.md {Developer Contact Information}
  containers.md {OCI Containers}
  contribute.wiki {Contributing Code or Documentation To The Fossil Project}
  css-tricks.md {Fossil CSS Tips and Tricks}
  customgraph.md {Theming: Customizing the Timeline Graph}

Changes to www/permutedindex.html.

33
34
35
36
37
38
39

40
41
42
43
44
45
46
<li><a href="serverext.wiki">CGI Server Extensions</a></li>
<li><a href="checkin_names.wiki">Check-in And Version Names</a></li>
<li><a href="checkin.wiki">Check-in Checklist</a></li>
<li><a href="ckout-workflows.md">Check-Out Workflows</a></li>
<li><a href="foss-cklist.wiki">Checklist For Successful Open-Source Projects</a></li>
<li><a href="co-vs-up.md">Checkout vs Update</a></li>
<li><a href="childprojects.wiki">Child Projects</a></li>

<li><a href="build.wiki">Compiling and Installing Fossil</a></li>
<li><a href="contribute.wiki">Contributing Code or Documentation To The Fossil Project</a></li>
<li><a href="copyright-release.html">Contributor License Agreement</a></li>
<li><a href="private.wiki">Creating, Syncing, and Deleting Private Branches</a></li>
<li><a href="customskin.md">Custom Skins</a></li>
<li><a href="custom_ticket.wiki">Customizing The Ticket System</a></li>
<li><a href="antibot.wiki">Defense against Spiders and Robots</a></li>







>







33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<li><a href="serverext.wiki">CGI Server Extensions</a></li>
<li><a href="checkin_names.wiki">Check-in And Version Names</a></li>
<li><a href="checkin.wiki">Check-in Checklist</a></li>
<li><a href="ckout-workflows.md">Check-Out Workflows</a></li>
<li><a href="foss-cklist.wiki">Checklist For Successful Open-Source Projects</a></li>
<li><a href="co-vs-up.md">Checkout vs Update</a></li>
<li><a href="childprojects.wiki">Child Projects</a></li>
<li><a href="colordiff.md">Colorized Diffs</a></li>
<li><a href="build.wiki">Compiling and Installing Fossil</a></li>
<li><a href="contribute.wiki">Contributing Code or Documentation To The Fossil Project</a></li>
<li><a href="copyright-release.html">Contributor License Agreement</a></li>
<li><a href="private.wiki">Creating, Syncing, and Deleting Private Branches</a></li>
<li><a href="customskin.md">Custom Skins</a></li>
<li><a href="custom_ticket.wiki">Customizing The Ticket System</a></li>
<li><a href="antibot.wiki">Defense against Spiders and Robots</a></li>