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

Re: [PATCH v4] format-patch: allow a non-integral version numbers

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Mar 16, 2021, 06:15 UTC
Message-ID
<CAPig+cRkGvKU8b2vauUZ4=EtTj4DU2e9k0HciTVEz-6-P6X5KQ@mail.gmail.com>
In-Reply-To
<CAOLTT8T14P1VfbbXnXpAV-6GfZ8jXUqqCVaY1Uxs3UtfnFvKvw@mail.gmail.com>
On Tue, Mar 16, 2021 at 1:48 AM ZheNing Hu <adlternative@gmail.com> wrote:
Show 22 quoted lines
> Eric Sunshine <sunshine@sunshineco.com> 于2021年3月16日周二 上午7:41写道:
> > > +               strtol_i(reroll_count_string, 10, &reroll_count);
> >
> > This code can be confusing to readers since it appears to ignore the
> > result of strtol_i() [...]
> > [...] I think it would be clearer if you move the strtol_i()
> > call into the diff_title() function since -- following your changes --
> > that function is the only code which cares whether `reroll_count` can
> > be parsed as a number (the rest of the code, after your change, just
> > uses it as a string).
>
> Well, The reason `strtol_i` does not check the return value is that
> `strtol_i` will
> only modify the value of `reroll_count` if the `reroll_count_string`
> we provide is
>  an integer string, so if `reroll_count_string` is not an integer string, then
> `reroll_count` will remain -1, and then `diff_title` will only execute
>
>         if (reroll_count <= 0)
>                 strbuf_addstr(sb, generic);
>
> So don't need check strtol_i return value.

Yes, I understand the reason, but it is not easy for someone new to this code to figure it out without looking at diff_title() and its callers. The place where the return value of strtol_i() is ignored is very far removed from the place where the value of `reroll_count` is consumed in diff_title(), so it's not obvious to the reader how this is all supposed to work. If you move strtol_i() into diff_title(), then the parsing and the consuming of that value happen in the same place, making it easier to understand.

> But what you said to put
> `strtol_i` in
> `diff_title` is indeed a good idea. Of course, we need to modify the declaration
>  and parameters of `diff_title`.

Yes, it is a very minor modification to diff_title(), changing `reroll_count` from int to string.

Moving the parsing into diff_title() also allows you to use the simpler name `reroll_count` for the string variable in cmd_fmt_patch() rather than the longer `reroll_count_string`; just change `reroll_count` from int to string.

Previous: ZheNing HuNext: Junio C Hamano
Message 21 of 49 in “format-patch: allow a non-integral version numbers”
  1. format-patch: allow a non-integral version numbersZheNing Hu via GitGitGadget, Feb 25, 2021
  2. Eric SunshineFeb 25, 2021
  3. ZheNing HuFeb 27, 2021
  4. Junio C HamanoFeb 25, 2021
  5. ZheNing HuFeb 27, 2021
  6. Đoàn Trần Công DanhMar 17, 2021
  7. Junio C HamanoMar 17, 2021
  8. format-patch: allow a non-integral version numbersZheNing Hu via GitGitGadget, Mar 1, 2021
  9. Junio C HamanoMar 3, 2021
  10. Denton LiuMar 3, 2021
  11. Junio C HamanoMar 4, 2021
  12. ZheNing HuMar 4, 2021
  13. Eric SunshineMar 4, 2021
  14. Denton LiuMar 4, 2021
  15. format-patch: allow a non-integral version numbersZheNing Hu via GitGitGadget, Mar 4, 2021
  16. Denton LiuMar 4, 2021
  17. ZheNing HuMar 5, 2021
  18. format-patch: allow a non-integral version numbersZheNing Hu via GitGitGadget, Mar 5, 2021
  19. Eric SunshineMar 15, 2021
  20. ZheNing HuMar 16, 2021
  21. Eric SunshineMar 16, 2021
  22. Junio C HamanoMar 17, 2021
  23. format-patch: allow a non-integral version numbersZheNing Hu via GitGitGadget, Mar 16, 2021
  24. Eric SunshineMar 16, 2021
  25. ZheNing HuMar 17, 2021
  26. format-patch: allow a non-integral version numbersZheNing Hu via GitGitGadget, Mar 18, 2021
  27. Eric SunshineMar 19, 2021
  28. ZheNing HuMar 19, 2021
  29. format-patch: allow a non-integral version numbersZheNing Hu via GitGitGadget, Mar 19, 2021
  30. Junio C HamanoMar 19, 2021
  31. ZheNing HuMar 20, 2021
  32. Junio C HamanoMar 19, 2021
  33. ZheNing HuMar 20, 2021
  34. format-patch: allow a non-integral version numbersZheNing Hu via GitGitGadget, Mar 20, 2021
  35. Junio C HamanoMar 20, 2021
  36. ZheNing HuMar 21, 2021
  37. Eric SunshineMar 21, 2021
  38. Junio C HamanoMar 21, 2021
  39. Eric SunshineMar 21, 2021
  40. Denton LiuMar 24, 2021
  41. ZheNing HuMar 21, 2021
  42. format-patch: allow a non-integral version numbersZheNing Hu via GitGitGadget, Mar 21, 2021
  43. Eric SunshineMar 23, 2021
  44. Junio C HamanoMar 23, 2021
  45. ZheNing HuMar 23, 2021
  46. ZheNing HuMar 23, 2021
  47. format-patch: allow a non-integral version numbersZheNing Hu via GitGitGadget, Mar 23, 2021
  48. Eric SunshineMar 24, 2021
  49. ZheNing HuMar 24, 2021

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.