]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/Conf/gitattributes: fix "--function-context" for C source code
authorLaszlo Ersek <lersek@redhat.com>
Thu, 16 Jan 2020 18:24:34 +0000 (19:24 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 31 Jan 2020 16:13:06 +0000 (16:13 +0000)
The "--function-context" ("-W") option of git-diff displays the entire
body of a modified function, not just small modified hunks within the
function. It is useful for reviewers when the code changes to the function
are small, but they could affect, or depend on, control flow that is far
away in the same function.

Of course, the size of the displayed context can be controlled with the
"-U" option anyway, but such fixed-size contexts are usually either too
small, or too large, in the above scenario.

It turns out that "--function-context" does not work correctly for C
source files in edk2. In particular, labels for the goto instruction
(which the edk2 coding style places in the leftmost column) appear to
terminate "--function-context".

The "git" utility contains built-in hunk header patterns for the C and C++
languages. However, they do not take effect in edk2 because we don't
explicitly assign the "cpp" git-diff driver to our C files. The
gitattributes(5) manual explains that this is required:

>            There are a few built-in patterns to make this easier, and
>            tex is one of them, so you do not have to write the above in
>            your configuration file (you still need to enable this with
>            the attribute mechanism, via .gitattributes). The following
>            built in patterns are available:
>
>            [...]
>
>            *   cpp suitable for source code in the C and C++
>                languages.

The key statement is the one in parentheses.

Grab the suffix lists from the [C-Code-File] and [Acpi-Table-Code-File]
sections of "BaseTools/Conf/build_rule.template", add "*.h" and "*.H", and
mark those as belonging to the "cpp" git-diff driver.

This change has a dramatic effect on the following command, for example:

$ git show -W 2ef0c27cb84c

Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20200120094245.9010-1-lersek@redhat.com>
Reviewed-by: Leif Lindholm <leif@nuviainc.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Conf/gitattributes

index 58b93e9d4c27eed85d67c9e0ac174449b9ca7131..319e89064133831c19918aa6baa311d46da32473 100644 (file)
 *.fdf     diff=ini\r
 *.fdf.inc diff=ini\r
 *.inf     diff=ini\r
+*.c       diff=cpp\r
+*.C       diff=cpp\r
+*.cc      diff=cpp\r
+*.CC      diff=cpp\r
+*.cpp     diff=cpp\r
+*.Cpp     diff=cpp\r
+*.CPP     diff=cpp\r
+*.aslc    diff=cpp\r
+*.act     diff=cpp\r
+*.h       diff=cpp\r
+*.H       diff=cpp\r