git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] userdiff: permit Rust's macro_rules! keyword in hunk headers

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 7, 2020, 06:10 UTC
Message-ID
<xmqqimbm4ldb.fsf@gitster.c.googlers.com>
In-Reply-To
<pull.865.v2.git.git.1602048429067.gitgitgadget@gmail.com>
"Konrad Borowski via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 11 quoted lines
> From: Konrad Borowski <konrad@borowski.pw>
>
> Changes since v1:
> - Changed macro_rules! to be considered to use the same
>   rule as rest of keywords to reduce the size of a change
>   as suggested by Phillip Wood. This means that
>   'pub macro_rules!` (a syntax error) is considered to be
>   a hunk header.
>
> - Written commit message in imperative mood as suggested by
>   Johannes Sixt.

The above is where you write the proposed log message, not where you write the differences between v1 and v2 (which, if exists, would be below the three-dash line after your sign off). After all, people who are reading the final history of the project in "git log" will not even know or care that what they are reading is the second iteration and/or there was a first iteration that was different from the final version.

> Subject: [PATCH v2] userdiff: permit Rust's macro_rules! keyword in hunk headers

Somehow I find the "permit" a bit odd---it is not like we are disallowing Rust programs written in certain way.

     userdiff: recognize 'macro_rules!' as starting a Rust function block
or something?
> Signed-off-by: Konrad Borowski <konrad@borowski.pw>
> ---
> ...
As to the simplified rule that matches 'pub macro_rules!'.

We assume what is written by the end-user, in which these patterns are used to find function headers, is a syntactically correct program. This allows us to write a pattern that may match with a syntactic nonsense (i.e. false positive is perfectly fine). What we care about is to avoid false negatives---if our pattern does not recognize what users would consider a valid and common function header line, that is a problem.

So, from that point of view, you do not have to worry too much about 'pub macro_rules!' matching your pattern.

Show 22 quoted lines
> diff --git a/t/t4018/rust-macro-rules b/t/t4018/rust-macro-rules
> new file mode 100644
> index 0000000000..ec610c5b62
> --- /dev/null
> +++ b/t/t4018/rust-macro-rules
> @@ -0,0 +1,6 @@
> +macro_rules! RIGHT {
> +    () => {
> +        // a comment
> +        let x = ChangeMe;
> +    };
> +}
> diff --git a/userdiff.c b/userdiff.c
> index fde02f225b..c0f63c57b2 100644
> --- a/userdiff.c
> +++ b/userdiff.c
> @@ -165,7 +165,7 @@ PATTERNS("ruby", "^[ \t]*((class|module|def)[ \t].*)$",
>  	 "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\?(\\\\C-)?(\\\\M-)?."
>  	 "|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\.{1,3}|::|[!=]~"),
>  PATTERNS("rust",
> -	 "^[\t ]*((pub(\\([^\\)]+\\))?[\t ]+)?((async|const|unsafe|extern([\t ]+\"[^\"]+\"))[\t ]+)?(struct|enum|union|mod|trait|fn|impl)[< \t]+[^;]*)$",
> +	 "^[\t ]*((pub(\\([^\\)]+\\))?[\t ]+)?((async|const|unsafe|extern([\t ]+\"[^\"]+\"))[\t ]+)?(struct|enum|union|mod|trait|fn|impl|macro_rules[\t ]*!)[< \t]+[^;]*)$",

I notice that you still allow "macro_rules !" as Phillip pointed out. Is that intended?

Thanks.
Previous: Konrad Borowski via GitGitGadgetNext: Konrad Borowski via GitGitGadget
Message 5 of 6 in “userdiff: support Rust macros”
  1. userdiff: support Rust macrosKonrad Borowski via GitGitGadget, Oct 6, 2020
  2. Phillip WoodOct 6, 2020
  3. Johannes SixtOct 6, 2020
  4. userdiff: permit Rust's macro_rules! keyword in hunk headersKonrad Borowski via GitGitGadget, Oct 7, 2020
  5. Junio C HamanoOct 7, 2020
  6. userdiff: recognize 'macro_rules!' as starting a Rust function blockKonrad Borowski via GitGitGadget, Oct 7, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.