[edk2-devel] [PATCH] BaseTools/Conf/gitattributes: fix "--function-context" for *.h and *.c

Laszlo Ersek lersek at redhat.com
Thu Jan 16 18:49:29 UTC 2020


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 *.h and
*.c 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 *.h and *.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.

Thus, mark our *.h and *.c files 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 at intel.com>
Cc: Leif Lindholm <leif.lindholm at linaro.org>
Cc: Liming Gao <liming.gao at intel.com>
Signed-off-by: Laszlo Ersek <lersek at redhat.com>
---
 BaseTools/Conf/gitattributes | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/BaseTools/Conf/gitattributes b/BaseTools/Conf/gitattributes
index 58b93e9d4c27..8b8b4b92105b 100644
--- a/BaseTools/Conf/gitattributes
+++ b/BaseTools/Conf/gitattributes
@@ -17,3 +17,5 @@
 *.fdf     diff=ini
 *.fdf.inc diff=ini
 *.inf     diff=ini
+*.h       diff=cpp
+*.c       diff=cpp
-- 
2.19.1.3.g30247aa5d201


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#53312): https://edk2.groups.io/g/devel/message/53312
Mute This Topic: https://groups.io/mt/69751918/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-





More information about the edk2-devel-archive mailing list