Download raw body.
got patch: add flag to ignore whitespace?
Christian Weisgerber <naddy@mips.inka.de> wrote: > Omar Polo: > > > The last patch from Mark reminded me that I thought some time ago to add > > a "-w" flag for got patch to ignore white spaces. It's conceptually > > similar to patch(1) -l/--ignore-whitespace or git-apply(1) > > --ignore-whitespace. > > > > The diff does exactly what one would expect. > > Well, I'm dense. What does "ignore whitespace" mean exactly? you're not dense. I should have included more context, sorry. > Note that diff(1) has two ways to do this, -b and -w. TIL about -b! > If I understand linecmp() correctly, it's like diff -w? > > Meanwhile patch -l seems to be more like diff -b? the documentation of patch -l says that: : Any sequence of whitespace in the pattern line will match any sequence : in the input file. Normal characters must still match exactly This is implemented at the end of usr.bin/patch/patch.c in similar(), which I assume it's fundamentally equal to my linecmp. So, I think we're following the same behavior of patch -l here,. (which is conceptually the same as diff -w.) However, this got me thinking: maybe ignoring _every_ whitespace is too lax? What about ignoring only the leading and trailing ones? Regress passes and the mangled patch sent by Mark still applies. (the diff cheats a bit, but we're only interested in if the lines are "equal" or not, we don't use it for ordering.) diff /home/op/w/got commit - 4d5ee9564a9e46a1f634f619833c62f636cfbdc1 path + /home/op/w/got blob - f12c747f214e8e4ae165a7c3b1b15212bfdfa531 file + lib/patch.c --- lib/patch.c +++ lib/patch.c @@ -414,16 +414,20 @@ linecmp(const char *a, const char *b, int *mangled) return c; *mangled = 1; - for (;;) { - while (isspace(*a)) - a++; - while (isspace(*b)) - b++; - if (*a == '\0' || *b == '\0' || *a != *b) - break; + + while (isspace(*a)) + a++; + while (isspace(*b)) + b++; + + while (*a != '\0' && *a == *b) a++, b++; - } + while (isspace(*a)) + a++; + while (isspace(*b)) + b++; + return *a - *b; }
got patch: add flag to ignore whitespace?