Thread (23 messages) 23 messages, 6 authors, 2021-09-13

Re: [PATCH v2 5/7] rebase: don't have loop over "struct strvec" depend on signed "nr"

From: Eric Sunshine <hidden>
Date: 2021-09-12 02:57:50

On Sat, Sep 11, 2021 at 8:16 PM Ævar Arnfjörð Bjarmason
[off-list ref] wrote:
As in the preceding commit, prepare for the "nr" member of "struct
strvec" changing from an "int" to a "size_t".

Let's change this code added in f57696802c3 (rebase: really just
passthru the `git am` options, 2018-11-14) so that it won't cause a
bug if the "i" variable here is updated to be a "size_t" instead of an
"int".

The reason it would be buggy is because this for-loop relied on
"counting down" from nr-1 to 0, we'll then decrement the variable one
last time, so a value of -1 indicates that we've visited all
elements. Since we're looking for a needle in the haystack having
looked at all the hay means that the needle isn't there.
s/haystack/&,/
Let's replace this with simpler code that loops overthe "struct
strvec" and checks the current needle is "-q", if it isn't and we're
doing a merge we die, otherwise we do a "REBASE_APPLY".
s/overthe/over the/

Nit: comma-splice[1] at `"-q",`; replace comma with semicolon or period.

[1]: https://lore.kernel.org/git/CAPx1GvfFPWvJsj+uJV7RZrv1rgEpio=pk6rKF2UrjHebVY=LPA@mail.gmail.com/ (local)
We've been able to simplify this code since 8295ed690bf (rebase: make
the backend configurable via config setting, 2020-02-15) when we
stopped using this for anything except this one check, so let's do
that and move the check into the loop itself.

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help