From: Eric Sunshine <sunshine@sunshineco.com>
To: David Aguilar <davvid@gmail.com>
Cc: Fernando Ramos <greenfoo@u92.eu>,
Git Mailing List <git@vger.kernel.org>,
Junio C Hamano <gitster@pobox.com>, Seth House <seth@eseth.com>,
Philippe Blain <levraiphilippeblain@gmail.com>,
rogi@skylittlesystem.org
Subject: Re: [PATCH 1/3] vimdiff: new implementation with layout support
Date: Sun, 7 Nov 2021 19:47:17 -0500 [thread overview]
Message-ID: <CAPig+cRiMVzMd5yEZkRvwdAjf-tawGGrSsCBUAVs+pTTw5KunA@mail.gmail.com> (raw)
In-Reply-To: <CAJDDKr5KZK3wpox6FJPOL9koPr=k5+qTzZtPPFEmg4iZsvwoog@mail.gmail.com>
On Sun, Nov 7, 2021 at 5:42 PM David Aguilar <davvid@gmail.com> wrote:
> On Thu, Nov 4, 2021 at 9:10 AM Fernando Ramos <greenfoo@u92.eu> wrote:
> > + AUX=$(echo "$LAYOUT" | grep -oe "[A-Z]\+\*")
>
> From Documentatin/CodingGuidelines:
>
> As to use of grep, stick to a subset of BRE (namely, no {m,n},
> [::], [==], or [..]) for portability.
Also, `grep -o` isn't POSIX.
> > + if test $(echo $LAYOUT | wc -w) == "1"
> > + then
> > + CMD="$CMD | bufdo diffthis"
> > + else
> > + CMD="$CMD | tabdo windo diffthis"
> > + fi
>
> The output of "wc -c" is non-portable. It contains leading whitespace
> on some platforms.
>
> The test expression should be:
>
> test "$value" = 1
>
> with a single "=" rather than "==".
For clarification, the leading whitespace emitted by some `wc`
implementations is only a problem when encapsulated in a string. For
instance, like this:
if test "$(... | wc -w)" = "1"
in which case " 1" won't equal "1". The usage here, however, should
be okay since the output is not quoted.
Quite correct about using "=" (or even "-eq") here rather than "==", though.
> > + if $base_present
> > + then
> > + eval "$merge_tool_path" \
> > + -f $FINAL_CMD "$LOCAL" "$BASE" "$REMOTE" "$MERGED"
> > + else
> > + [...]
> > + eval "$merge_tool_path" \
> > + -f $FINAL_CMD "$LOCAL" "$REMOTE" "$MERGED"
> > + fi
> > +
> > + ret="$?"
> > + if test "$ret" -eq 0
>
> This should be:
>
> if test "$ret" = 0
Or simpler, no need for `ret` at all:
if test $? -eq 0
(or `if test $? = 0` -- either works)
Another (perhaps better) alternative is to assign the result of `eval`
to `ret` at the point of invocation, which lessens the cognitive load
a bit since you don't have to scan backward through the code trying to
figure out what $? refers to.
Also, why is `eval` needed here? Is there something non-obvious going
on? (Genuine question; I didn't trace the code thoroughly to
understand.)
> > + eval cp -- \$"$FINAL_TARGET" "$MERGED"
>
> This eval may not be safe when the value contains whitespace or shell
> metacharacters.
>
> I think it might be better to just spell it out and be explicit.
>
> It's more code but it'll be easier to follow:
> [...]
> if test -n "$source_path"
> then
> cp -- "$source_path" "$MERGED"
> fi
I suspect `--` also needs to be avoided since it is not POSIX.
next prev parent reply other threads:[~2021-11-08 0:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-04 16:09 [PATCH 0/3] vimdiff: new layout option + docs Fernando Ramos
2021-11-04 16:09 ` [PATCH 1/3] vimdiff: new implementation with layout support Fernando Ramos
2021-11-07 22:41 ` David Aguilar
2021-11-08 0:47 ` Eric Sunshine [this message]
2021-11-04 16:09 ` [PATCH 2/3] vimdiff: add tool documentation Fernando Ramos
2021-11-07 21:24 ` David Aguilar
2021-11-08 1:02 ` Eric Sunshine
2021-11-08 19:08 ` Junio C Hamano
2021-11-04 16:09 ` [PATCH 3/3] vimdiff: remove deprecated {,g,n}vimdiff{1,2,3} variants Fernando Ramos
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAPig+cRiMVzMd5yEZkRvwdAjf-tawGGrSsCBUAVs+pTTw5KunA@mail.gmail.com \
--to=sunshine@sunshineco.com \
--cc=davvid@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=greenfoo@u92.eu \
--cc=levraiphilippeblain@gmail.com \
--cc=rogi@skylittlesystem.org \
--cc=seth@eseth.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).