Re: [PATCH] pretty-print: de-tabify indented logs to make things line up properly
- From
Linus Torvalds <torvalds@linux-foundation.org>
- Date
- Mar 16, 2016, 18:21 UTC
- Message-ID
- <CA+55aFxV5PWdSn9Gj=zV464TtJo=QvciZrhc5Pwe+Qfyqt8sXw@mail.gmail.com>
- In-Reply-To
- <xmqq7fh25mkc.fsf@gitster.mtv.corp.google.com>
On Wed, Mar 16, 2016 at 11:01 AM, Junio C Hamano <gitster@pobox.com> wrote:
>
> (1) if turning your "preparation; do { ... } while()" into
> "while () { }" would make the result a bit easier to read;So it's probably partly taste, but I will also disagree with your "easier to read", because of the way the code is logically structured.
In particular, the "no TAB" case is actually *fundamentally* different from the "no TAB at the end" case. The return value is different, and the caller does very different things - the code tries to make it very clear that that "no TAB" situation is very different from "we found a TAB".
So it's not "preparation + do-while".
It's "preparation + handle the no-TAB case differently", and then the "do-while" is very natural because by the time we get to the "ok, we are now going to need to do something about the line" stage, we already know we have a tab.
But the code *could* be made to just always do the whole "strbuf_add()", and not return a return value at all, and the no-tab case wouldn't be explicitly written to be different.
Let me know if you'd prefer that variant, and I'll send a new version.
> (2) if we can somehow eliminate duplication of "tab + 1" (spelled > differently on the previous line as "1+tab"), the end result > may get easier to follow.
Yeah, I considered that. Either by just doing "tab++" before (so the +1" would come from that in both cases), or by introducing a new variable like
ptrdiff_t bytes_used;
...
bytes_used = 1 + tab - line;and then just doing
line += bytes_used;
linelen -= bytes_used;and the code I wrote just didn't do any of those temporary updates, and instead just did the "+1" by hand in both cases.
Again, I can redo the patch, just tell me which model you prefer.
Linus