git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] revision: parse integer arguments to --max-count, --skip, etc., more carefully

From
Jeff King <peff@peff.net>
Date
Dec 12, 2023, 22:05 UTC
Message-ID
<20231212220505.GA1220605@coredump.intra.peff.net>
In-Reply-To
<xmqqjzpjsbjl.fsf@gitster.g>
On Tue, Dec 12, 2023 at 07:09:02AM -0800, Junio C Hamano wrote:
Show 12 quoted lines
> Jeff King <peff@peff.net> writes:
> 
> > This all looks pretty reasonable to me.
> >
> > I couldn't help but think, though, that surely we have some helpers for
> > this already? But the closest seems to be git_parse_int(), which also
> > allows unit factors. I'm not sure if allowing "-n 1k" would be a feature
> > or a bug. ;)
> 
> The change in question is meant to be a pure fix to replace a careless
> use of atoi().  I do not mind to see a separate patch to add such a
> feature later on top.

Oh, I mostly meant that I would have turned to git_parse_int() as that already-existing helper, but it is not suitable because of the extra unit-handling. I think your patch draws the line in the right place.

Show 11 quoted lines
> > I wonder if there are more spots that could benefit.
> 
> "git grep -e 'atoi('" would give somebody motivated a decent set of
> #microproject ideas, but many hits are not suited for strtol_i(),
> which is designed to parse an integer at the end of a string.  Some
> places use atoi() immediately followed by strspn() to skip over
> digits, which means they are parsing an integer and want to continue
> reading after the integer, which is incompatible with what
> strtol_i() wants to do.  They need either a separate helper or an
> updated strtol_i() that optionally allows you to parse the prefix
> and report where the integer ended, e.g., something like:

Yeah, I agree this might be a good microproject (or leftoverbits) area, and the semantics for the helper you propose make sense to me.

-Peff
Previous: Junio C Hamano
Message 6 of 6 in “[BUG] rev-list doesn't validate arguments to -n option”
  1. Britton KerinDec 7, 2023
  2. Junio C HamanoDec 8, 2023
  3. revision: parse integer arguments to --max-count, --skip, etc., more carefullyJunio C Hamano, Dec 8, 2023
  4. Jeff KingDec 12, 2023
  5. Junio C HamanoDec 12, 2023
  6. Jeff KingDec 12, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.