Welcome to the 81st edition of Git Rev News, a digest of all things Git. For our goals, the archives, the way we work, and how to contribute or to subscribe, see the Git Rev News page on git.github.io.
This edition covers what happened during the month of October 2021.
[PATCH 0/3] Fun with cpp word regex
Johannes Sixt sent a small patch series about improving C++ (also called ‘cpp’) support in the userdiff mechanism. This mechanism is used by Git to generate diffs that are customized to specific programming languages (like C, shell, Perl, MATLAB, etc.) or markup languages (like HTML, Markdown, TeX, etc.).
Especially one of the patches splits the regex that was matching all the numbers into 3 different regexes:
The result is that expressions like 1+2
, 1.5-e+2+f
and .l
are
not considered numbers any more and are properly parsed for diff
purposes in C++ files.
Another patch in the series allows single-quote characters as digit
separators according to the C++17 standard, like in 3.141'592'654
or 0xdead'beaf
.
The third and last patch prevents the <=>
generalized comparison
operator (also called ‘spaceship’ operator) introduced in C++20 from
being split into <=
and >
.
Ævar Arnfjörð Bjarmason replied to Johannes suggesting to add a
few tests in the t/t4034/cpp/
directory, where test files for the
cpp userdiff mechanism reside.
Johannes agreed with Ævar and sent a second version of his patch series. This series included 2 new patches that improved existing tests and added new tests for problematic behavior that the other patches were fixing.
Ævar commented on this series saying that it was much improved, but it could perhaps be even better if:
the C++ support was split up from the C support,
some tests were added first, before the behavior was changed, and
some tests could be added for code comments, as he wondered if
tokens that often occur in natural language, like "
and &
,
were still correctly handled when they appeared in code comments.
Johannes agreed with the second point, but wasn’t interested in working on the others.
Ævar and Johannes discussed a bit further if it was worth doing something for code comments, but Johannes concluded that it wasn’t.
Johannes then sent a
third version
of his patch series. In this new version test cases for single-quote
characters as digit separators and the <=>
generalized comparison
operator were moved to a new commit before the commits supporting
these features.
Later on, Johannes noticed
that the single-quote character as digit separator is problematic
and requires a more sophisticated implementation. For example, as
implemented the character literal '.'
would be split into '.
and '
. The support for digit separators was eventually reverted.
This patch series was then merged into the master branch, so that Git 2.34 that was recently released has better support for C++ in diffs.
Various
Light reading
Git tools and sites
commitlint
is a tool written in JavaScript and running on Node.js
(that is, an npm tool) that helps your team with adhering to a commit convention.This edition of Git Rev News was curated by Christian Couder <christian.couder@gmail.com>, Jakub Narębski <jnareb@gmail.com>, Markus Jansen <mja@jansen-preisler.de> and Kaartic Sivaraam <kaartic.sivaraam@gmail.com> with help from Johannes Schindelin and Johannes Sixt.