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

Re: [PATCH v2 5/6] worktree: teach `list` to annotate prunable worktree

From
Rafael Silva <rafaeloliveira.cs@gmail.com>
Date
Jan 19, 2021, 10:26 UTC
Message-ID
<gohp6kpn216x51.fsf@gmail.com>
In-Reply-To
<CAPig+cRUrN62CDT+e+q02-S_sCD1Qvi5XtgU3D1dr9fXt--YJA@mail.gmail.com>
Eric Sunshine writes:
> On Sun, Jan 17, 2021 at 6:43 PM Rafael Silva
> <rafaeloliveira.cs@gmail.com> wrote:
Show 10 quoted lines
>> diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt
>> @@ -234,6 +235,9 @@ This can also be set up as the default behaviour by using the
>>  --expire <time>::
>>         With `prune`, only expire unused working trees older than `<time>`.
>> ++
>> +With `list`, annotate missing working trees as prunable if they are
>> +older than `<mtime>`.
>
> s/mtime/time/
>
Oops. thanks for catching that. Will fix it in the next revision.
Show 15 quoted lines
>> diff --git a/builtin/worktree.c b/builtin/worktree.c
>> @@ -592,6 +592,10 @@ static void show_worktree_porcelain(struct worktree *wt)
>> +       reason = worktree_prune_reason(wt, expire);
>> +       if (reason && *reason)
>> +               printf("prunable %s\n", reason);
>
> I lean toward not including `*reason` in the condition here. While one
> may argue that `*reason` is future-proofing the condition, we know
> today that worktree_prune_reason() will only ever return NULL or a
> non-empty string. So, having `*reason` in the condition is misleading
> and confuses readers into thinking that worktree_prune_reason() could
> return an empty string or that perhaps it did in the past. And
> studying the history of this file or even this commit won't help them
> understand why the author included `*reason` in the condition.
>

Fair enough. The `*reason` condition was indeed added to be safe and future-proofing and, as you pointed it out, we know that currently the worktree_prune_reason() returns a non-empty string when its true and when the code reaches the `*reason` condition in "if (reason && *reason)" this will always evaluates to true.

Agreed that removing this part of the condition will make the code clearer and easier to followed. So I will drop this in the next revision.

Show 27 quoted lines
>> @@ -617,9 +622,14 @@ static void show_worktree(struct worktree *wt, int path_maxlen, int abbrev_len)
>> -       if (!is_main_worktree(wt) && worktree_lock_reason(wt))
>> +       reason = worktree_lock_reason(wt);
>> +       if (reason)
>>                 strbuf_addstr(&sb, " locked");
>
> Although I understand what happened here because I read the entire
> series, for anyone reading this patch in the future or even someone
> reading this patch in isolation, the disappearance of
> is_main_worktree() from the condition is mysterious. They won't know
> if its removal was an accident or intentional, or if the change
> introduces a bug. Therefore, it would be better to drop
> is_main_worktree() from this conditional in patch [3/6], which is the
> patch which makes it safe to call worktree_lock_reason() even for the
> main worktree. Thus, in [3/6], this would change from:
>
>     if (!is_main_worktree(wt) && worktree_lock_reason(wt))
>
> to:
>
>     if (worktree_lock_reason(wt))
>
> and then in this patch [5/6], it becomes:
>
>     reason = worktree_lock_reason(wt);
>     if (reason)
>

That's a good point, and even worse this is not mentioned in my commit message at all. It make sense to move this change into [3/6] where the API is changed and all the reason is explained in the commit message.

Show 25 quoted lines
>> +       reason = worktree_prune_reason(wt, expire);
>> +       if (reason)
>> +               strbuf_addstr(&sb, " prunable");
>
> Looking at this also makes me wonder if patches [5/6] and [6/6] should
> be swapped since it's not clear to the reader why you're adding the
> `reason` variable in this patch when the same could be accomplished
> more simply:
>
>     if (worktree_lock_reason(wt))
>         strbuf_addstr(&sb, " locked");
>     if (worktree_prune_reason(wt, expire))
>         strbuf_addstr(&sb, " prunable");
>
> If you swap the patches and add --verbose mode first which requires
> this new `reason` variable, then the mystery goes away, and the use of
> `reason` is obvious when `prunable` annotation is added in the
> subsequent patch.
>
> Having said that, I'm not trying to make extra work for you by
> expecting patch perfection. Sometimes it's fine to craft a patch in
> such a way that it makes subsequent patches simpler, even if it looks
> slightly odd in the current patch, and I haven't read [6/6] yet, so
> whatever opinion I express here is based only upon what I've read up
> to this point.
That's a good point. I'm inclined to leave the [5/6] with the following:
    if (worktree_prune_reason(wt, expire))
        strbuf_addstr(&sb, " prunable");

And move up the changes that includes the `reason` into the [5/6] patches that introduces the --verbose option. This line seems easier to follow when the reader is looking on this patch alone and only care about a reason when the --verbose comes into play in the next patch [6/6].

Although your suggestion about changing the patch also sounds reasonable and I'll take into consideration when I re-roll this series.

Btw, I don't mind spending extra work on and I'm all forward with the changes so we it would be easier to understand not only now where all the patches are being reviewed together but in the future when someone is looking at the history of the project, specially for debugging/bisecting reasons.

Thanks for the insightful comments.
-- 
Thanks
Rafael
Previous: Eric SunshineNext: Eric Sunshine
Message 44 of 88 in “teach `worktree list` verbose mode and prunable annotations”
  1. 0/7 teach `worktree list` verbose mode and prunable annotationsRafael Silva, Jan 4, 2021
  2. 3/7 worktree: teach worktree_lock_reason() to gently handle main worktreeRafael Silva, Jan 4, 2021
  3. Eric SunshineJan 6, 2021
  4. Rafael SilvaJan 8, 2021
  5. 6/7 worktree: add tests for `list` verbose and annotationsRafael Silva, Jan 4, 2021
  6. Eric SunshineJan 6, 2021
  7. Eric SunshineJan 7, 2021
  8. Rafael SilvaJan 8, 2021
  9. 4/7 worktree: teach `list` prunable annotation and verboseRafael Silva, Jan 4, 2021
  10. Eric SunshineJan 6, 2021
  11. Rafael SilvaJan 8, 2021
  12. 7/7 worktree: document `list` verbose and prunable annotationsRafael Silva, Jan 4, 2021
  13. Eric SunshineJan 6, 2021
  14. Rafael SilvaJan 8, 2021
  15. 5/7 worktree: `list` escape lock reason in --porcelainRafael Silva, Jan 4, 2021
  16. Phillip WoodJan 5, 2021
  17. worktree: add -z option for list subcommandPhillip Wood, Jan 5, 2021
  18. Eric SunshineJan 7, 2021
  19. Phillip WoodJan 8, 2021
  20. Eric SunshineJan 10, 2021
  21. Eric SunshineJan 6, 2021
  22. Rafael SilvaJan 8, 2021
  23. Eric SunshineJan 6, 2021
  24. 1/7 worktree: move should_prune_worktree() to worktree.cRafael Silva, Jan 4, 2021
  25. Eric SunshineJan 6, 2021
  26. Rafael SilvaJan 8, 2021
  27. Eric SunshineJan 6, 2021
  28. Eric SunshineJan 7, 2021
  29. Rafael SilvaJan 8, 2021
  30. 2/7 worktree: implement worktree_prune_reason() wrapperRafael Silva, Jan 4, 2021
  31. Eric SunshineJan 6, 2021
  32. Rafael SilvaJan 8, 2021
  33. Eric SunshineJan 6, 2021
  34. Rafael SilvaJan 8, 2021
  35. Eric SunshineJan 8, 2021
  36. 0/6 teach `worktree list` verbose mode and prunable annotationsRafael Silva, Jan 17, 2021
  37. 1/6 worktree: libify should_prune_worktree()Rafael Silva, Jan 17, 2021
  38. 4/6 worktree: teach `list --porcelain` to annotate locked worktreeRafael Silva, Jan 17, 2021
  39. Eric SunshineJan 18, 2021
  40. Rafael SilvaJan 19, 2021
  41. Eric SunshineJan 19, 2021
  42. 5/6 worktree: teach `list` to annotate prunable worktreeRafael Silva, Jan 17, 2021
  43. Eric SunshineJan 18, 2021
  44. Rafael SilvaJan 19, 2021
  45. Eric SunshineJan 19, 2021
  46. 6/6 worktree: teach `list` verbose modeRafael Silva, Jan 17, 2021
  47. Eric SunshineJan 18, 2021
  48. Eric SunshineJan 18, 2021
  49. 2/6 worktree: teach worktree to lazy-load "prunable" reasonRafael Silva, Jan 17, 2021
  50. Eric SunshineJan 18, 2021
  51. Rafael SilvaJan 19, 2021
  52. 3/6 worktree: teach worktree_lock_reason() to gently handle main worktreeRafael Silva, Jan 17, 2021
  53. Eric SunshineJan 18, 2021
  54. Rafael SilvaJan 19, 2021
  55. 0/7 teach `worktree list` verbose mode and prunable annotationsRafael Silva, Jan 19, 2021
  56. 1/7 worktree: libify should_prune_worktree()Rafael Silva, Jan 19, 2021
  57. 7/7 worktree: teach `list` verbose modeRafael Silva, Jan 19, 2021
  58. Eric SunshineJan 24, 2021
  59. Rafael SilvaJan 24, 2021
  60. 2/7 worktree: teach worktree to lazy-load "prunable" reasonRafael Silva, Jan 19, 2021
  61. 6/7 worktree: teach `list` to annotate prunable worktreeRafael Silva, Jan 19, 2021
  62. Junio C HamanoJan 21, 2021
  63. Rafael SilvaJan 21, 2021
  64. Junio C HamanoJan 21, 2021
  65. 3/7 worktree: teach worktree_lock_reason() to gently handle main worktreeRafael Silva, Jan 19, 2021
  66. 4/7 t2402: ensure locked worktree is properly cleaned upRafael Silva, Jan 19, 2021
  67. Eric SunshineJan 24, 2021
  68. Rafael SilvaJan 24, 2021
  69. 5/7 worktree: teach `list --porcelain` to annotate locked worktreeRafael Silva, Jan 19, 2021
  70. Phillip WoodJan 20, 2021
  71. Junio C HamanoJan 21, 2021
  72. Rafael SilvaJan 21, 2021
  73. Eric SunshineJan 24, 2021
  74. Eric SunshineJan 24, 2021
  75. Rafael SilvaJan 24, 2021
  76. Eric SunshineJan 24, 2021
  77. Rafael SilvaJan 27, 2021
  78. 0/7 teach `worktree list` verbose mode and prunable annotationsRafael Silva, Jan 27, 2021
  79. 2/7 worktree: teach worktree to lazy-load "prunable" reasonRafael Silva, Jan 27, 2021
  80. 6/7 worktree: teach `list` to annotate prunable worktreeRafael Silva, Jan 27, 2021
  81. 5/7 worktree: teach `list --porcelain` to annotate locked worktreeRafael Silva, Jan 27, 2021
  82. 7/7 worktree: teach `list` verbose modeRafael Silva, Jan 27, 2021
  83. 3/7 worktree: teach worktree_lock_reason() to gently handle main worktreeRafael Silva, Jan 27, 2021
  84. 1/7 worktree: libify should_prune_worktree()Rafael Silva, Jan 27, 2021
  85. 4/7 t2402: ensure locked worktree is properly cleaned upRafael Silva, Jan 27, 2021
  86. Eric SunshineJan 30, 2021
  87. Rafael SilvaJan 30, 2021
  88. Junio C HamanoJan 30, 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.