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

Re: [PATCH 00/16] worktree: use "git reset --hard" to populate worktree

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Jul 14, 2015, 09:53 UTC
Message-ID
<55A4DC1C.90908@drmicha.warpmail.net>
In-Reply-To
<xmqqsi8rzyzo.fsf@gitster.dls.corp.google.com>
Junio C Hamano venit, vidit, dixit 13.07.2015 20:36:
Show 58 quoted lines
> Eric Sunshine <sunshine@sunshineco.com> writes:
> 
>> This is a follow-on series to [1], which migrated "git checkout --to"
>> functionality to "git worktree add". That series continued using "git
>> checkout" for the initial population of the new worktree, which required
>> git-checkout to have too intimate knowledge that it was operating in a
>> newly created worktree.
>>
>> This series eliminates git-checkout from the picture by instead
>> employing "git reset --hard"[2] to populate the new worktree initially.
>>
>> It is built atop 1eb07d8 (worktree: add: auto-vivify new branch when
>> <branch> is omitted, 2015-07-06), currently in 'next', which is
>> es/worktree-add except for the final patch (which retires
>> --ignore-other-worktrees) since the intention[3] was to drop that patch.
> 
> A few comments on things I noticed while reading (mostly coming from
> the original before this patch series):
> 
>  - What does this comment apply to?
> 
>         /*
>          * $GIT_COMMON_DIR/HEAD is practically outside
>          * $GIT_DIR so resolve_ref_unsafe() won't work (it
>          * uses git_path). Parse the ref ourselves.
>          */
> 
>    It appears in front of a call to check-linked-checkout, but I
>    think the comment attempts to explain why it manually decides
>    what the path should be in that function, so perhaps move it to
>    the callee from the caller?
> 
>  - check_linked_checkout() when trying to decide what branch is
>    checked out assumes HEAD is always a regular file, but I do not
>    think we have dropped the support of SYMLINK_HEAD yet.  It needs
>    to check st_mode and readlink(2), like resolve_ref_unsafe() does.
> 
>  - After a new skelton worktree is set up, the code runs a few
>    commands to finish populating it, under a different pair of
>    GIT_DIR/GIT_WORK_TREE, but the function does so with setenv(); it
>    may be cleaner to use cp.env[] for it, as the process we care
>    about using the updated environment is not "worktree add" command
>    we are running ourselves, but "update-ref/symbolic-ref" and
>    "reset" commands that run in the new worktree.
> 
> Other than that, looks nicely done.
> 
> I however have to wonder if the stress on "reset --hard" on log
> messages of various commits (and in the endgame) is somewhat
> misplaced.
> 
> The primary thing we wanted to see, which this series nicely brings
> us, is to remove "new-worktree-mode" hack from "checkout" (in other
> words, instead of "reset --hard", "checkout -f" would also have been
> a satisfactory endgame).
> 
> Thanks.
> 

Related to that, I'm interested in "worktree list", and I'm wondering how many more worktree commands we foresee, and therefore how much refactoring should be done: Currently, the parsing of the contents of .../worktrees/ into worktree information is done right in prune-spcefic functions. They will have to be refactored. The following questions come to my mind:

- Is a simple funtion refactoring enough, or should we introduce a
worktree struct (and a list of such)?
- Should each command do its own looping, or do we want
for_each_worktree() with a callback?
- Is a fixed output format for "list"[1] enough, or do we want something
like for-each-ref or log formats (GSOC project...)?
- Finally: Who will be stepping on whose toes doing this?
Michael
[1] Something like:
* fooworktree (master)
  barworktree (HEAD detached from deadbeef)

with "*" denoting the worktree you're in (if any) and (optionally?) adding the "on" info from "git branch" in parentheses after each worktree (checked out branch name, or detached info). Maybe the path, too?

Previous: Junio C HamanoNext: Duy Nguyen
Message 26 of 31 in “worktree: use "git reset --hard" to populate worktree”
  1. 00/16 worktree: use "git reset --hard" to populate worktreeEric Sunshine, Jul 11, 2015
  2. 01/16 checkout: avoid resolving HEAD unnecessarilyEric Sunshine, Jul 11, 2015
  3. 02/16 checkout: name check_linked_checkouts() more meaningfullyEric Sunshine, Jul 11, 2015
  4. 03/16 checkout: improve die_if_checked_out() robustnessEric Sunshine, Jul 11, 2015
  5. 04/16 checkout: die_if_checked_out: simplify strbuf managementEric Sunshine, Jul 11, 2015
  6. 05/16 checkout: generalize die_if_checked_out() branch name argumentEric Sunshine, Jul 11, 2015
  7. 06/16 branch: publish die_if_checked_out()Eric Sunshine, Jul 11, 2015
  8. 07/16 worktree: simplify new branch (-b/-B) option checkingEric Sunshine, Jul 11, 2015
  9. 08/16 worktree: introduce options containerEric Sunshine, Jul 11, 2015
  10. 09/16 worktree: make --detach mutually exclusive with -b/-BEric Sunshine, Jul 11, 2015
  11. 10/16 worktree: make branch creation distinct from worktree populationEric Sunshine, Jul 11, 2015
  12. Duy NguyenJul 12, 2015
  13. Eric SunshineJul 12, 2015
  14. Duy NguyenJul 12, 2015
  15. Eric SunshineJul 12, 2015
  16. Eric SunshineJul 12, 2015
  17. Eric SunshineJul 12, 2015
  18. Duy NguyenJul 12, 2015
  19. 11/16 worktree: add_worktree: construct worktree-population command locallyEric Sunshine, Jul 11, 2015
  20. 12/16 worktree: detect branch symref/detach and error conditions locallyEric Sunshine, Jul 11, 2015
  21. 13/16 worktree: make setup of new HEAD distinct from worktree populationEric Sunshine, Jul 11, 2015
  22. 14/16 worktree: avoid resolving HEAD unnecessarilyEric Sunshine, Jul 11, 2015
  23. 15/16 worktree: populate via "git reset --hard" rather than "git checkout"Eric Sunshine, Jul 11, 2015
  24. 16/16 checkout: drop intimate knowledge of new worktree initial populationEric Sunshine, Jul 11, 2015
  25. Junio C HamanoJul 13, 2015
  26. Michael J GruberJul 14, 2015
  27. Duy NguyenJul 14, 2015
  28. Eric SunshineJul 14, 2015
  29. Eric SunshineJul 15, 2015
  30. Duy NguyenJul 15, 2015
  31. Eric SunshineJul 12, 2015

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.