git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* diff -w when removing nested braces (thus unindenting)
@ 2023-04-04 20:26 Alejandro Colomar
  0 siblings, 0 replies; only message in thread
From: Alejandro Colomar @ 2023-04-04 20:26 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Alejandro Colomar


[-- Attachment #1.1: Type: text/plain, Size: 1889 bytes --]

Hi,

When removing nested braces, it would be nice if the diff algorithm
could try to remove the brace in a way that it fits semantically.
Considering the following diff:

> diff --git a/src/nxt_http_parse.c b/src/nxt_http_parse.c
> index 9f3233c8..0e8de7c5 100644
> --- a/src/nxt_http_parse.c
> +++ b/src/nxt_http_parse.c
> @@ -351,29 +351,30 @@ nxt_http_parse_request_line(nxt_http_request_parse_t *rp, u_char **pos,
>  
>          } while (*p == ' ');
>  
> -        if (memcmp(p, "HTTP/", nxt_min(end - p, 5)) == 0) {
> +        if (memcmp(p, "HTTP/", nxt_min(end - p, 5)) != 0) {
> +            return NXT_HTTP_PARSE_INVALID;
> +        }
>  
>          switch (end - p) {
>          case 8:
>              if (p[7] < '0' || p[7] > '9') {
> -                    break;
> +                return NXT_HTTP_PARSE_INVALID;
>              }
>              /* Fall through. */
>          case 7:
>              if (p[6] != '.') {
> -                    break;
> +                return NXT_HTTP_PARSE_INVALID;
>              }
>              /* Fall through. */
>          case 6:
>              if (p[5] < '0' || p[5] > '9') {
> -                    break;
> +                return NXT_HTTP_PARSE_INVALID;
>              }
>              /* Fall through. */
>          default:
>              return NXT_AGAIN;
>          }
>      }
> -    }

This brace removal looks like it would be an unmatching brace.
It would be nicer if the diff showed this:


          }
 -    }
      }

Although I'm conscious that this might be a wild wish impossible
to implement; so I'd just like you to know this little itch of
mine in case you consider it doable.

Cheers,

Alex

>  
>      /* " HTTP/1.1\r\n" or " HTTP/1.1\n" */
>  



-- 
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-04-04 20:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-04 20:26 diff -w when removing nested braces (thus unindenting) Alejandro Colomar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).