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

Re: [PATCH v1 2/8] format-patch: confirmation whenever patches exist

From
Firmin Martin <firminmartin24@gmail.com>
Date
May 10, 2021, 03:30 UTC
Message-ID
<878s4ngta2.fsf@Inspiron.i-did-not-set--mail-host-address--so-tickle-me>
In-Reply-To
<xmqqk0obwhi2.fsf@gitster.g>
Hi Junio,
Junio C Hamano <gitster@pobox.com> writes:
Show 15 quoted lines
> Firmin Martin <firminmartin24@gmail.com> writes:
>
>> Currently, git-format-patch, along with the option --cover-letter,
>> unconditionaly overwrites a cover letter with the same name (if
>> present). Although this is a desired behaviour for patches which are
>> auto-generated from Git commits log, it might not be the case for a
>> cover letter whose the content is meticulously written manually.
>
> True.  But if we require confirmation before overwriting patches,
> that would be overall worsening the end-user experience, I am
> afraid.  In a 5-patch series with a cover-letter that was formatted,
> proofread, corrected with "rebase -i" and then re-formatted, unless
> you rephrased the titles of the patches, you'd get prompted once for
> the cover letter (which *IS* valuable) and five-times for patches
> (which is annoying).

This is true for this patch, but the semantics changed after the patch #3. I really should have squashed them together to not create confusion. Sorry about that.

After patch #3:
- The prompt happens only one time so that the user could decide whether they
want overwrite the existing file and subsequent ones. In your example,
the session would go like this:
    git format-patch --cover-letter -o patch upstream/master
    The file 'patch/0000-cover-letter.patch' already exists.
    Would you overwrite this file and subsequent ones [Y/n]? n
    fatal: failed to create cover-letter file
(replying Y would overwrite the cover letter and the patches as usual)
 
- The default behaviour affects only cover letters, meaning that, in
  your example, if the user employs instead 
    git format-patch -o patch upstream/master

(without --cover-letter) the second time, the patches are overwritten without any disturbance.

After all, the point of this patch series is to prevent overwriting an existing cover letter by using a cover letter template (--cover-letter).

Show 5 quoted lines
>
> It also is unfortunate that this change does not address another
> annoyance after retitling a patch---the stale output from the
> previous run is not overwritten with the updated one but is left in
> the same directory as the output files from the latest run.
Show 30 quoted lines
> So, while I very much do welcome the motivation, I am not onboard
> with this particular design.
>
>> diff --git a/builtin/log.c b/builtin/log.c
>> index 6102893fcc..bada3db9eb 100644
>> --- a/builtin/log.c
>> +++ b/builtin/log.c
>> @@ -35,6 +35,7 @@
>>  #include "repository.h"
>>  #include "commit-reach.h"
>>  #include "range-diff.h"
>> +#include "prompt.h"
>>  
>>  #define MAIL_DEFAULT_WRAP 72
>>  #define COVER_FROM_AUTO_MAX_SUBJECT_LEN 100
>> @@ -959,6 +960,10 @@ static int open_next_file(struct commit *commit, const char *subject,
>>  			 struct rev_info *rev, int quiet)
>>  {
>>  	struct strbuf filename = STRBUF_INIT;
>> +	struct strbuf file_exists_prompt = STRBUF_INIT;
>> +	const char *yesno;
>> +	static int not_prompted = 1;
>
> When the API passes a structure that keeps track of state (like
> "struct rev_info *rev", used to hold rev->diffopt.file which is
> clearly a state), add a member to it, instead of inventing a
> function local static that will hurt reuse of the API you are
> touching.  This static variable will make it impossible from a
> single process to format two patch series, but if it is made a part
> of rev_info, you do not have to introduce such a limitation.

OK, I will keep in mind of that. But after the discussion on git_prompt, I think this variable will be dropped.

Many thanks for your comments,
Firmin
Previous: Junio C HamanoNext: Junio C Hamano
Message 14 of 34 in “format-patch: introduce --confirm-overwrite”
  1. 0/8 format-patch: introduce --confirm-overwriteFirmin Martin, May 6, 2021
  2. 1/8 compat/terminal: let prompt accept input from pipeFirmin Martin, May 6, 2021
  3. Junio C HamanoMay 6, 2021
  4. Jeff KingMay 7, 2021
  5. Junio C HamanoMay 7, 2021
  6. Firmin MartinMay 10, 2021
  7. Jeff KingMay 10, 2021
  8. Junio C HamanoMay 11, 2021
  9. Jeff KingMay 11, 2021
  10. Junio C HamanoMay 11, 2021
  11. Jeff KingMay 11, 2021
  12. 2/8 format-patch: confirmation whenever patches existFirmin Martin, May 6, 2021
  13. Junio C HamanoMay 6, 2021
  14. Firmin MartinMay 10, 2021
  15. Junio C HamanoMay 10, 2021
  16. Firmin MartinMay 11, 2021
  17. 3/8 format-patch: add config option confirmOverwriteFirmin Martin, May 6, 2021
  18. 4/8 format-patch: add the option --confirm-overwriteFirmin Martin, May 6, 2021
  19. 5/8 t4014: test patches overwrite confirmationFirmin Martin, May 6, 2021
  20. 6/8 t4014: fix tests overwriting cover letter in silentFirmin Martin, May 6, 2021
  21. 7/8 doc/format-patch: describe --confirm-overwriteFirmin Martin, May 6, 2021
  22. Bagas SanjayaMay 7, 2021
  23. Firmin MartinMay 10, 2021
  24. 8/8 config/format: describe format.confirmOverwriteFirmin Martin, May 6, 2021
  25. Junio C HamanoMay 6, 2021
  26. Firmin MartinMay 11, 2021
  27. Felipe ContrerasMay 7, 2021
  28. Denton LiuMay 7, 2021
  29. Firmin MartinMay 11, 2021
  30. Felipe ContrerasMay 11, 2021
  31. Felipe ContrerasMay 11, 2021
  32. Sergey OrganovMay 7, 2021
  33. Firmin MartinMay 11, 2021
  34. Ævar Arnfjörð BjarmasonMay 10, 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.