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

Re: [PATCH v4 6/9] rebase -i: add fixup [-C | -c] command

From
Charvi Mendiratta <charvi077@gmail.com>
Date
Feb 2, 2021, 15:29 UTC
Message-ID
<CAPSFM5fZHZDnmRD2GzwPVKwBjogKD=GJbC7e=6aQSbu_iXBdNw@mail.gmail.com>
In-Reply-To
<CAPig+cQeBE7m8wf1e_soVrpvL3==u50MPyb90NwWLnFiUz1Byw@mail.gmail.com>
Hi Eric,
On Tue, 2 Feb 2021 at 06:17, Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 16 quoted lines
>
> On Fri, Jan 29, 2021 at 1:24 PM Charvi Mendiratta <charvi077@gmail.com> wrote:
> > Add options to `fixup` command to fixup both the commit contents and
> > message. `fixup -C` command is used to replace the original commit
> > message and `fixup -c`, additionally allows to edit the commit message.
>
> In the cover letter for this series, you had this additional information:
>
>     This convention is similar to the existing `merge` command in the
>     interactive rebase, that also supports `-c` and `-C` options with
>     similar meanings.
>
> which helps to explain the choice of -c and -C. It might be nice to
> include that explanation in this commit message, as well (but not
> itself worth a re-roll).
>
Agree, I will include this in the commit message.
Show 17 quoted lines
> > Signed-off-by: Charvi Mendiratta <charvi077@gmail.com>
> > ---
> > diff --git a/rebase-interactive.c b/rebase-interactive.c
> > @@ -44,7 +44,9 @@ void append_todo_help(int command_count,
> >  "s, squash <commit> = use commit, but meld into previous commit\n"
> > -"f, fixup <commit> = like \"squash\", but discard this commit's log message\n"
> > +"f, fixup [-C | -c] <commit> = like \"squash\", but discard this\n"
> > +"                   commit's log message. Use -C to replace with this\n"
> > +"                   commit message or -c to edit the commit message\n"
>
> This change jarringly introduces the first and only use of a period
> and capitalized word in the to-do help text. Perhaps instead say:
>
>     ... like \"squash\", but discard this
>     commit's log message; use -C to replace with this
>     commit message or -c to edit the commit message
>
Okay, I will change it.
Show 6 quoted lines
> When `-c` says "edit the commit message" it's not clear what will be
> edited. The original's commit message? The replacement's message? A
> combination of the two? If you can come up with a succinct way to word
> it such that it states more precisely what exactly will be edited, it
> would be nice, but not necessarily worth a re-roll.
>

Here the editor shows the commented out commit message of original commit and the replacement commit message (of fixup -c commit) is not commented out.

So maybe s/edit the commit message/edit this commit message  is better.
Show 45 quoted lines
> > diff --git a/sequencer.c b/sequencer.c
> > @@ -1718,6 +1718,12 @@ static int is_pick_or_similar(enum todo_command command)
> > +enum todo_item_flags {
> > +       TODO_EDIT_MERGE_MSG    = (1 << 0),
> > +       TODO_REPLACE_FIXUP_MSG = (1 << 1),
> > +       TODO_EDIT_FIXUP_MSG    = (1 << 2),
> > +};
>
> I'm confused. These enumeration items are defined as bit flags,
> implying that they may be combined, however...
>
> > @@ -1734,32 +1740,176 @@ static size_t subject_length(const char *body)
> > +static int check_fixup_flag(enum todo_command command,
> > +                           enum todo_item_flags flag)
>
> ...here and elsewhere, you declare the argument as a strict
> `todo_item_flags` enum item rather than `unsigned` which is the
> typical declaration when combining bit flag values. So, the picture
> thus far is confusing. Are the `todo_item_flags` values distinct
> unique values which will never be combined, or are they meant to be
> combined?
>
> > +{
> > +       return command == TODO_FIXUP && ((flag & TODO_REPLACE_FIXUP_MSG) ||
> > +                                        (flag & TODO_EDIT_FIXUP_MSG));
> > +}
>
> This code adds to the confusion. In the function argument list, `flag`
> has been declared as a single enum item, yet this code is treating
> `flag` as if it is a combination of bits. So, it's not clear what the
> intention is here. Is `flag` always going to be a specific enum item
> in this context or is it going to be a combination of bits? If it is
> only ever going to be a distinct enum item, then one would expect this
> code to be written like this:
>
>     return command == TODO_FIXUP &&
>         (flag == TODO_REPLACE_FIXUP_MSG ||
>         flag == TODO_EDIT_FIXUP_MSG);
>
> Otherwise, if `flag` will actually be a bag of bits, then the argument
> should be declared as such:
>
>     static int check_fixup_flag(enum todo_command command,
>         unsigned flag)
>

I admit it resulted in a bit of confusion. Here, its true that flag is always going to be specific enum item( as command can be merge -c, fixup -c, or fixup -C ) and I combined the bag of bits to denote the specific enum item. So, maybe we can go with the first method?

Show 6 quoted lines
> By the way, the function name check_fixup_flag() doesn't necessarily
> do a good job conveying the purpose of this function. Based upon the
> implementation, I gather that it is checking whether the command is a
> "fixup" command, so perhaps the name could reflect that. Perhaps
> is_fixup() or something?
>

Agree, here it's checking if the command is fixup and the flag value ( which implies either user has given command fixup -c or fixup -C ) So, I wonder if we can write is_fixup_flag() ?

Show 21 quoted lines
> > +static int append_squash_message(struct strbuf *buf, const char *body,
> > +                        enum todo_command command, struct replay_opts *opts,
> > +                        enum todo_item_flags flag)
> > +{
> > +       /*
> > +        * amend is non-interactive and not normally used with fixup!
> > +        * or squash! commits, so only comment out those subjects when
> > +        * squashing commit messages.
> > +        */
> > +       if (starts_with(body, "amend!") ||
> > +           ((command == TODO_SQUASH || seen_squash(opts)) &&
> > +            (starts_with(body, "squash!") || starts_with(body, "fixup!"))))
> >                 commented_len = subject_length(body);
>
> I understand from the cover letter that "amend!" is being added by
> this series, however, no patch up to this point, nor this patch
> itself, adds "amend!" functionality, so it's surprising to see it
> being tested here. As a reader, I would expect code/comments related
> to "amend!" to be added in the patch which actually introduces
> "amend!" rather than doing it here.
>

This patch series does not include the implementation of amend! commit. I think to avoid the confusion I will remove this part from this patch series and add it in the next patch series for amend! commit.

Show 14 quoted lines
> > +       /* fixup -C after squash behaves like squash */
> > +       if (check_fixup_flag(command, flag) && !seen_squash(opts)) {
> > +               if (opts->signoff)
> > +                       append_signoff(buf, 0, 0);
> > +
> > +               if ((command == TODO_FIXUP) &&
> > +                   (flag & TODO_REPLACE_FIXUP_MSG) &&
> > +                   (file_exists(rebase_path_fixup_msg()) ||
> > +                    !file_exists(rebase_path_squash_msg()))) {
>
> Is the expression `command == TODO_FIXUP` redundant here considering
> that the only way we got this far is if check_fixup_flag() returned
> true, in which case we know that command is TODO_FIXUP? Or am I
> missing something?
Yes, it implies the same.
Show 26 quoted lines
>
> > @@ -2281,6 +2436,18 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
> > +       if (item->command == TODO_FIXUP) {
> > +               if (skip_prefix(bol, "-C", &bol) &&
> > +                  (*bol == ' ' || *bol == '\t')) {
> > +                       bol += strspn(bol, " \t");
> > +                       item->flags |= TODO_REPLACE_FIXUP_MSG;
> > +               } else if (skip_prefix(bol, "-c", &bol) &&
> > +                                 (*bol == ' ' || *bol == '\t')) {
> > +                       bol += strspn(bol, " \t");
> > +                       item->flags |= TODO_EDIT_FIXUP_MSG;
> > +               }
> > +       }
>
> I was wondering if the above could be rephrased like this to avoid the
> repetition:
>
>     if (bol[0] == '-' && tolower(bol[1]) == 'c' &&
>         (bol[2] == ' ' || bol[2] == '\t') {
>         item->flags |= bol[1] == 'C' ?
>             TODO_REPLACE_FIXUP_MSG :
>             TODO_EDIT_FIXUP_MSG;
>         bol += 2 + strspn(bol + 2, " \t");
>     }
>
> but perhaps it's too magical and ugly.

I agree, this [tolower(bol[1]) == 'c'] is actually doing all the magic, but I am not sure if we should change it or not ? As in the source code just after this code we are checking in a similar way for the 'merge' command. So, maybe implementing in a similar way is easier to read ?

Thanks and Regards, Charvi

Previous: Eric SunshineNext: Eric Sunshine
Message 49 of 110 in “[Outreachy] rebase -i: add options to fixup command”
  1. 0/9 [Outreachy] rebase -i: add options to fixup commandCharvi Mendiratta, Jan 8, 2021
  2. 1/9 rebase -i: only write fixup-message when it's neededCharvi Mendiratta, Jan 8, 2021
  3. Taylor BlauJan 13, 2021
  4. Charvi MendirattaJan 14, 2021
  5. Phillip WoodJan 14, 2021
  6. Charvi MendirattaJan 15, 2021
  7. Junio C HamanoJan 15, 2021
  8. Charvi MendirattaJan 16, 2021
  9. 2/9 sequencer: factor out code to append squash messageCharvi Mendiratta, Jan 8, 2021
  10. 3/9 rebase -i: comment out squash!/fixup! subjects from squash messageCharvi Mendiratta, Jan 8, 2021
  11. Taylor BlauJan 13, 2021
  12. Charvi MendirattaJan 14, 2021
  13. Phillip WoodJan 14, 2021
  14. Charvi MendirattaJan 15, 2021
  15. Christian CouderJan 15, 2021
  16. Charvi MendirattaJan 15, 2021
  17. Charvi MendirattaJan 17, 2021
  18. Phillip WoodJan 18, 2021
  19. Charvi MendirattaJan 19, 2021
  20. 4/9 sequencer: pass todo_item to do_pick_commit()Charvi Mendiratta, Jan 8, 2021
  21. 5/9 sequencer: use const variable for commit message commentsCharvi Mendiratta, Jan 8, 2021
  22. Taylor BlauJan 13, 2021
  23. Junio C HamanoJan 13, 2021
  24. Christian CouderJan 14, 2021
  25. Charvi MendirattaJan 14, 2021
  26. 6/9 rebase -i: add fixup [-C | -c] commandCharvi Mendiratta, Jan 8, 2021
  27. Christian CouderJan 14, 2021
  28. Charvi MendirattaJan 14, 2021
  29. 8/9 rebase -i: teach --autosquash to work with amend!Charvi Mendiratta, Jan 8, 2021
  30. 7/9 t3437: test script for fixup [-C|-c] options in interactive rebaseCharvi Mendiratta, Jan 8, 2021
  31. 9/9 doc/git-rebase: add documentation for fixup [-C|-c] optionsCharvi Mendiratta, Jan 8, 2021
  32. 0/9 [Outreachy] rebase -i: add options to fixup commandCharvi Mendiratta, Jan 19, 2021
  33. 0/9 [Outreachy] rebase -i: add options to fixup commandCharvi Mendiratta, Jan 24, 2021
  34. 1/9 rebase -i: only write fixup-message when it's neededCharvi Mendiratta, Jan 24, 2021
  35. 2/9 sequencer: factor out code to append squash messageCharvi Mendiratta, Jan 24, 2021
  36. 3/9 rebase -i: comment out squash!/fixup! subjects from squash messageCharvi Mendiratta, Jan 24, 2021
  37. 4/9 sequencer: pass todo_item to do_pick_commit()Charvi Mendiratta, Jan 24, 2021
  38. 5/9 sequencer: use const variable for commit message commentsCharvi Mendiratta, Jan 24, 2021
  39. 6/9 rebase -i: add fixup [-C | -c] commandCharvi Mendiratta, Jan 24, 2021
  40. 7/9 t3437: test script for fixup [-C|-c] options in interactive rebaseCharvi Mendiratta, Jan 24, 2021
  41. 8/9 rebase -i: teach --autosquash to work with amend!Charvi Mendiratta, Jan 24, 2021
  42. 9/9 doc/git-rebase: add documentation for fixup [-C|-c] optionsCharvi Mendiratta, Jan 24, 2021
  43. 0/9 [Outreachy] rebase -i: add options to fixup commandCharvi Mendiratta, Jan 29, 2021
  44. 1/9 rebase -i: only write fixup-message when it's neededCharvi Mendiratta, Jan 29, 2021
  45. 2/9 sequencer: factor out code to append squash messageCharvi Mendiratta, Jan 29, 2021
  46. 3/9 rebase -i: comment out squash!/fixup! subjects from squash messageCharvi Mendiratta, Jan 29, 2021
  47. 6/9 rebase -i: add fixup [-C | -c] commandCharvi Mendiratta, Jan 29, 2021
  48. Eric SunshineFeb 2, 2021
  49. Charvi MendirattaFeb 2, 2021
  50. Eric SunshineFeb 3, 2021
  51. Charvi MendirattaFeb 4, 2021
  52. Eric SunshineFeb 4, 2021
  53. 9/9 doc/git-rebase: add documentation for fixup [-C|-c] optionsCharvi Mendiratta, Jan 29, 2021
  54. Eric SunshineFeb 2, 2021
  55. Charvi MendirattaFeb 2, 2021
  56. Marc BranchaudFeb 2, 2021
  57. 7/9 t3437: test script for fixup [-C|-c] options in interactive rebaseCharvi Mendiratta, Jan 29, 2021
  58. Eric SunshineFeb 2, 2021
  59. Christian CouderFeb 2, 2021
  60. Charvi MendirattaFeb 2, 2021
  61. Eric SunshineFeb 3, 2021
  62. Charvi MendirattaFeb 4, 2021
  63. Phillip WoodFeb 4, 2021
  64. Eric SunshineFeb 4, 2021
  65. Charvi MendirattaFeb 4, 2021
  66. 4/9 sequencer: pass todo_item to do_pick_commit()Charvi Mendiratta, Jan 29, 2021
  67. 8/9 rebase -i: teach --autosquash to work with amend!Charvi Mendiratta, Jan 29, 2021
  68. Eric SunshineFeb 2, 2021
  69. Charvi MendirattaFeb 2, 2021
  70. 5/9 sequencer: use const variable for commit message commentsCharvi Mendiratta, Jan 29, 2021
  71. 0/8 [Outreachy] rebase -i: add options to fixup commandCharvi Mendiratta, Feb 4, 2021
  72. 1/8 rebase -i: only write fixup-message when it's neededCharvi Mendiratta, Feb 4, 2021
  73. 3/8 rebase -i: comment out squash!/fixup! subjects from squash messageCharvi Mendiratta, Feb 4, 2021
  74. 7/8 t3437: test script for fixup [-C|-c] options in interactive rebaseCharvi Mendiratta, Feb 4, 2021
  75. 6/8 rebase -i: add fixup [-C | -c] commandCharvi Mendiratta, Feb 4, 2021
  76. 2/8 sequencer: factor out code to append squash messageCharvi Mendiratta, Feb 4, 2021
  77. 5/8 sequencer: use const variable for commit message commentsCharvi Mendiratta, Feb 4, 2021
  78. 8/8 doc/git-rebase: add documentation for fixup [-C|-c] optionsCharvi Mendiratta, Feb 4, 2021
  79. 4/8 sequencer: pass todo_item to do_pick_commit()Charvi Mendiratta, Feb 4, 2021
  80. Eric SunshineFeb 5, 2021
  81. Charvi MendirattaFeb 5, 2021
  82. Christian CouderFeb 5, 2021
  83. Eric SunshineFeb 5, 2021
  84. Charvi MendirattaFeb 6, 2021
  85. Junio C HamanoFeb 5, 2021
  86. Charvi MendirattaFeb 6, 2021
  87. 1/9 rebase -i: only write fixup-message when it's neededCharvi Mendiratta, Jan 19, 2021
  88. 2/9 sequencer: factor out code to append squash messageCharvi Mendiratta, Jan 19, 2021
  89. 5/9 sequencer: use const variable for commit message commentsCharvi Mendiratta, Jan 19, 2021
  90. 3/9 rebase -i: comment out squash!/fixup! subjects from squash messageCharvi Mendiratta, Jan 19, 2021
  91. Junio C HamanoJan 21, 2021
  92. Charvi MendirattaJan 21, 2021
  93. Christian CouderJan 21, 2021
  94. Phillip WoodJan 21, 2021
  95. Junio C HamanoJan 21, 2021
  96. Charvi MendirattaJan 22, 2021
  97. Charvi MendirattaJan 22, 2021
  98. 4/9 sequencer: pass todo_item to do_pick_commit()Charvi Mendiratta, Jan 19, 2021
  99. 7/9 t3437: test script for fixup [-C|-c] options in interactive rebaseCharvi Mendiratta, Jan 19, 2021
  100. 8/9 rebase -i: teach --autosquash to work with amend!Charvi Mendiratta, Jan 19, 2021
  101. 9/9 doc/git-rebase: add documentation for fixup [-C|-c] optionsCharvi Mendiratta, Jan 19, 2021
  102. Marc BranchaudJan 19, 2021
  103. Charvi MendirattaJan 19, 2021
  104. Marc BranchaudJan 19, 2021
  105. Charvi MendirattaJan 20, 2021
  106. Phillip WoodJan 20, 2021
  107. Charvi MendirattaJan 20, 2021
  108. Phillip WoodJan 20, 2021
  109. Charvi MendirattaJan 20, 2021
  110. 6/9 rebase -i: add fixup [-C | -c] commandCharvi Mendiratta, Jan 19, 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.