From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by mx.groups.io with SMTP id smtpd.web09.3948.1579211702810569147 for ; Thu, 16 Jan 2020 13:55:03 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=zAzRgho0; spf=pass (domain: linaro.org, ip: 209.85.221.65, mailfrom: leif.lindholm@linaro.org) Received: by mail-wr1-f65.google.com with SMTP id y11so20702584wrt.6 for ; Thu, 16 Jan 2020 13:55:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=wvvY/z7yKuOznE0mrt5lz6RLVXb+NQA3VjjFR+Z/X4A=; b=zAzRgho0p/cdJUBQIzTYVeNOQi5oBY4vK/6bof3VRPXmgHzXpF0/ZC44hdf3acSczX gpj00T1LAuXPlM+RGGr3d2fzjo0sFOZ0JMlqIybg1+vhcPW6Iyt3D3ZzCbaNJd49ViYX 324B+cbbiOPY+mD9LXJh99LGtN0NOCzA/P5o9L0CdvKcZa+hTVl/ukhp19bR+Vu6qzQJ oF+6+Nhixt+uWhhb9omPfgW9ZjaacX1R1gFevy5FfMzGHzX9I5Hb51P7uyKaBD1qz1rK Jy71HggaGvQbiKB4LhJ0vg+yDjl33acQt0nw0Q3+DkyvkmMnDyHTDI+m+kq0KBYmhCVz 1bMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=wvvY/z7yKuOznE0mrt5lz6RLVXb+NQA3VjjFR+Z/X4A=; b=LIHpUmgRsqU5BM1CfAJykhxfIROsEEAJR/uZ9PO1MyAOiw4n4hpvIgxdFzT6yiVvhU +GFse2N4/gcRnf7mR+FMVqaDrWZbrRNTBHAk+cxw51dpiLD+xb6KWZcsc4yk2PvRzrbO 8/KKWAp+PAxem3NQidJ+JaOh94LlzcVm2lAJ7cY7vwLN7NLRjitIzshbJZ7U5TuOTtZ7 FeZbVb/UoCP4NkJtdGQA94f2X4/XAJPPcTSHZT5xsXHIFszEoAQfO3VDwkdRNijipo8X +h4DhFFYTDWnXGkS+/HqK0MQq0vNAHq+ePmTGF+YAiOWb7NrpPOp4HO6tfCoQYDK7gME dZIw== X-Gm-Message-State: APjAAAUMA3T0Nq2YAA5dlAhxCcmeNBRWAfe8/SfyEdIdVfYEnnhSnf2L 3f05ZZr4558himF1IQf9R4kerg== X-Google-Smtp-Source: APXvYqyZhSimD5OuqWmRHIoSPflF3YoE8J/SgESLgggv61Q3heaGKrtGYJ+MpcZp3DmJHigLl1bhow== X-Received: by 2002:a5d:4c8c:: with SMTP id z12mr5418214wrs.222.1579211701239; Thu, 16 Jan 2020 13:55:01 -0800 (PST) Return-Path: Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id b137sm630177wme.26.2020.01.16.13.55.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2020 13:55:00 -0800 (PST) Date: Thu, 16 Jan 2020 21:54:59 +0000 From: Leif Lindholm To: Laszlo Ersek Cc: devel@edk2.groups.io, Bob Feng , Liming Gao Subject: Re: [PATCH] BaseTools/Conf/gitattributes: fix "--function-context" for *.h and *.c Message-ID: <20200116215459.GG20629@bivouac.eciton.net> References: <20200116184929.18020-1-lersek@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200116184929.18020-1-lersek@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Jan 16, 2020 at 19:49:29 +0100, Laszlo Ersek wrote: > 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 This looks really good, I didn't realise we weren't actually using properly C-aware diff by default. And thank you for the perfect level of background. However, if doing this change, would we want to apply it to all source code types supported by BaseTools (i.e. referenced in build_rule.template)? That would mean: .c .cc .C .CC .cpp .Cpp .CPP .h .H and possibly .act .aslc .vfr .Vfr .VFR / Leif > > Cc: Bob Feng > Cc: Leif Lindholm > Cc: Liming Gao > Signed-off-by: Laszlo Ersek > --- > 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 >