Re: [PATCH v2 23/32] prune: strategies for linked checkouts
On Sun, Sep 21, 2014 at 6:29 AM, Duy Nguyen wrote: > Here we go again. Thanks both for the suggestions. > > -- 8< -- > Subject: [PATCH] prune: strategies for linked checkouts > > (alias R=$GIT_COMMON_DIR/worktrees/) > > - linked checkouts are supposed to keep its location in $R/gitdir up >to date. The use case is auto fixup after a manual checkout move. > > - linked checkouts are supposed to update mtime of $R/gitdir. If >$R/gitdir's mtime is older than a limit, and it points to nowhere, >worktrees/ is to be pruned. > > - If $R/locked exists, worktrees/ is not supposed to be pruned. If >$R/locked exists and $R/gitdir's mtime is older than a really long >limit, warn about old unused repo. > > - "git checkout --to" is supposed to make a hard link named $R/link >pointing to the .git file on supported file systems to help detect >the user manually deleting the checkout. If $R/link exists and its >link count is greated than 1, the repo is kept. > > Helped-by: Marc Branchaud > Helped-by: Eric Sunshine > Signed-off-by: Nguyễn Thái Ngọc Duy > --- > Documentation/git-checkout.txt | 20 +++ > Documentation/git-prune.txt| 3 + > Documentation/gitrepository-layout.txt | 19 ++ > builtin/checkout.c | 19 +- > builtin/prune.c| 95 > ++ > setup.c| 13 > t/t2026-prune-linked-checkouts.sh (new +x) | 84 ++ > 7 files changed, 251 insertions(+), 2 deletions(-) > create mode 100755 t/t2026-prune-linked-checkouts.sh > > diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt > index c101575..0fd3bab 100644 > --- a/Documentation/git-checkout.txt > +++ b/Documentation/git-checkout.txt > @@ -434,6 +434,26 @@ thumb is do not make any assumption about whether a path > belongs to > $GIT_DIR or $GIT_COMMON_DIR when you need to directly access something > inside $GIT_DIR. Use `git rev-parse --git-path` to get the final path. > > +When you are done with a linked working tree you can simply delete it. > +You can clean up any stale $GIT_DIR/worktrees entries via `git prune > +--worktrees` in the main worktree or any linked work tree. Nit: In the rest of the documentation, you have consistently spelled out "working tree", so the (poor) example you copied from my email, which says "worktree", is an anomaly. My bad. Plus, you have a mix of "worktree" and "work tree". You probably want: ... in the main or any linked working tree. > +If you move a linked working directory to another file system, or > +within a file system that does not support hard links, you need to run > +at least one git command inside the linked working directory > +(e.g. `git status`) in order to update its entry in $GIT_DIR/worktrees > +so that it does not get automatically removed. > + > +To prevent `git prune --worktrees` from deleting a $GIT_DIR/worktrees > +entry (which can be useful in some situations, such as when the > +entry's working tree is stored on a portable device), add a file named > +'locked' to the entry's directory. The file contains the reason in > +plain text. For example, if a linked working tree's `.git` file points > +to `/path/main/.git/worktrees/test-next` then a file named > +`/path/main/.git/worktrees/test-next/locked` will prevent the > +`test-next` entry from being pruned. See > +linkgit:gitrepository-layout[5] for details. > + > EXAMPLES > > > diff --git a/Documentation/git-prune.txt b/Documentation/git-prune.txt > index 7a493c8..a0ea381 100644 > --- a/Documentation/git-prune.txt > +++ b/Documentation/git-prune.txt > @@ -48,6 +48,9 @@ OPTIONS > --expire :: > Only expire loose objects older than . > > +--worktrees:: > + Prune stale worktree information in $GIT_DIR/worktrees. > + > ...:: > In addition to objects > reachable from any of our references, keep objects > diff --git a/Documentation/gitrepository-layout.txt > b/Documentation/gitrepository-layout.txt > index 8228450..2b30a92 100644 > --- a/Documentation/gitrepository-layout.txt > +++ b/Documentation/gitrepository-layout.txt > @@ -259,6 +259,25 @@ worktrees:: > $GIT_COMMON_DIR is set and "$GIT_COMMON_DIR/worktrees" will be > used instead. > > +worktrees//gitdir:: > + A text file containing the absolute path back to the .git file > + that points to here. This is used to check if the linked > + repository has been manually removed and there is no need to > + keep this directory any more. mtime of this file should be > + updated every time the linked repository is accessed. > + > +worktrees//locked:: > + If this file exists, the linked repository may be on a > + portable device and not available. It does not mean that the > + linked repository is gone and `worktrees/` could be > + removed. The file's content contain
Re: [PATCH v2 23/32] prune: strategies for linked checkouts
On 14-09-21 06:29 AM, Duy Nguyen wrote: > Here we go again. Thanks both for the suggestions. The documentation looks good to me. FWIW: Signed-off-by: Marc Branchaud M. > -- 8< -- > Subject: [PATCH] prune: strategies for linked checkouts > > (alias R=$GIT_COMMON_DIR/worktrees/) > > - linked checkouts are supposed to keep its location in $R/gitdir up >to date. The use case is auto fixup after a manual checkout move. > > - linked checkouts are supposed to update mtime of $R/gitdir. If >$R/gitdir's mtime is older than a limit, and it points to nowhere, >worktrees/ is to be pruned. > > - If $R/locked exists, worktrees/ is not supposed to be pruned. If >$R/locked exists and $R/gitdir's mtime is older than a really long >limit, warn about old unused repo. > > - "git checkout --to" is supposed to make a hard link named $R/link >pointing to the .git file on supported file systems to help detect >the user manually deleting the checkout. If $R/link exists and its >link count is greated than 1, the repo is kept. > > Helped-by: Marc Branchaud > Helped-by: Eric Sunshine > Signed-off-by: Nguyễn Thái Ngọc Duy > --- > Documentation/git-checkout.txt | 20 +++ > Documentation/git-prune.txt| 3 + > Documentation/gitrepository-layout.txt | 19 ++ > builtin/checkout.c | 19 +- > builtin/prune.c| 95 > ++ > setup.c| 13 > t/t2026-prune-linked-checkouts.sh (new +x) | 84 ++ > 7 files changed, 251 insertions(+), 2 deletions(-) > create mode 100755 t/t2026-prune-linked-checkouts.sh > > diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt > index c101575..0fd3bab 100644 > --- a/Documentation/git-checkout.txt > +++ b/Documentation/git-checkout.txt > @@ -434,6 +434,26 @@ thumb is do not make any assumption about whether a path > belongs to > $GIT_DIR or $GIT_COMMON_DIR when you need to directly access something > inside $GIT_DIR. Use `git rev-parse --git-path` to get the final path. > > +When you are done with a linked working tree you can simply delete it. > +You can clean up any stale $GIT_DIR/worktrees entries via `git prune > +--worktrees` in the main worktree or any linked worktree. > + > +If you move a linked working directory to another file system, or > +within a file system that does not support hard links, you need to run > +at least one git command inside the linked working directory > +(e.g. `git status`) in order to update its entry in $GIT_DIR/worktrees > +so that it does not get automatically removed. > + > +To prevent `git prune --worktrees` from deleting a $GIT_DIR/worktrees > +entry (which can be useful in some situations, such as when the > +entry's working tree is stored on a portable device), add a file named > +'locked' to the entry's directory. The file contains the reason in > +plain text. For example, if a linked working tree's `.git` file points > +to `/path/main/.git/worktrees/test-next` then a file named > +`/path/main/.git/worktrees/test-next/locked` will prevent the > +`test-next` entry from being pruned. See > +linkgit:gitrepository-layout[5] for details. > + > EXAMPLES > > > diff --git a/Documentation/git-prune.txt b/Documentation/git-prune.txt > index 7a493c8..a0ea381 100644 > --- a/Documentation/git-prune.txt > +++ b/Documentation/git-prune.txt > @@ -48,6 +48,9 @@ OPTIONS > --expire :: > Only expire loose objects older than . > > +--worktrees:: > + Prune stale worktree information in $GIT_DIR/worktrees. > + > ...:: > In addition to objects > reachable from any of our references, keep objects > diff --git a/Documentation/gitrepository-layout.txt > b/Documentation/gitrepository-layout.txt > index 8228450..2b30a92 100644 > --- a/Documentation/gitrepository-layout.txt > +++ b/Documentation/gitrepository-layout.txt > @@ -259,6 +259,25 @@ worktrees:: > $GIT_COMMON_DIR is set and "$GIT_COMMON_DIR/worktrees" will be > used instead. > > +worktrees//gitdir:: > + A text file containing the absolute path back to the .git file > + that points to here. This is used to check if the linked > + repository has been manually removed and there is no need to > + keep this directory any more. mtime of this file should be > + updated every time the linked repository is accessed. > + > +worktrees//locked:: > + If this file exists, the linked repository may be on a > + portable device and not available. It does not mean that the > + linked repository is gone and `worktrees/` could be > + removed. The file's content contains a reason string on why > + the repository is locked. > + > +worktrees//link:: > + If this file exists, it is a hard link to the linked .git > + file. It is used to detect if the linked repository is > + manually remo
Re: [PATCH v2 23/32] prune: strategies for linked checkouts
Here we go again. Thanks both for the suggestions. -- 8< -- Subject: [PATCH] prune: strategies for linked checkouts (alias R=$GIT_COMMON_DIR/worktrees/) - linked checkouts are supposed to keep its location in $R/gitdir up to date. The use case is auto fixup after a manual checkout move. - linked checkouts are supposed to update mtime of $R/gitdir. If $R/gitdir's mtime is older than a limit, and it points to nowhere, worktrees/ is to be pruned. - If $R/locked exists, worktrees/ is not supposed to be pruned. If $R/locked exists and $R/gitdir's mtime is older than a really long limit, warn about old unused repo. - "git checkout --to" is supposed to make a hard link named $R/link pointing to the .git file on supported file systems to help detect the user manually deleting the checkout. If $R/link exists and its link count is greated than 1, the repo is kept. Helped-by: Marc Branchaud Helped-by: Eric Sunshine Signed-off-by: Nguyễn Thái Ngọc Duy --- Documentation/git-checkout.txt | 20 +++ Documentation/git-prune.txt| 3 + Documentation/gitrepository-layout.txt | 19 ++ builtin/checkout.c | 19 +- builtin/prune.c| 95 ++ setup.c| 13 t/t2026-prune-linked-checkouts.sh (new +x) | 84 ++ 7 files changed, 251 insertions(+), 2 deletions(-) create mode 100755 t/t2026-prune-linked-checkouts.sh diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt index c101575..0fd3bab 100644 --- a/Documentation/git-checkout.txt +++ b/Documentation/git-checkout.txt @@ -434,6 +434,26 @@ thumb is do not make any assumption about whether a path belongs to $GIT_DIR or $GIT_COMMON_DIR when you need to directly access something inside $GIT_DIR. Use `git rev-parse --git-path` to get the final path. +When you are done with a linked working tree you can simply delete it. +You can clean up any stale $GIT_DIR/worktrees entries via `git prune +--worktrees` in the main worktree or any linked worktree. + +If you move a linked working directory to another file system, or +within a file system that does not support hard links, you need to run +at least one git command inside the linked working directory +(e.g. `git status`) in order to update its entry in $GIT_DIR/worktrees +so that it does not get automatically removed. + +To prevent `git prune --worktrees` from deleting a $GIT_DIR/worktrees +entry (which can be useful in some situations, such as when the +entry's working tree is stored on a portable device), add a file named +'locked' to the entry's directory. The file contains the reason in +plain text. For example, if a linked working tree's `.git` file points +to `/path/main/.git/worktrees/test-next` then a file named +`/path/main/.git/worktrees/test-next/locked` will prevent the +`test-next` entry from being pruned. See +linkgit:gitrepository-layout[5] for details. + EXAMPLES diff --git a/Documentation/git-prune.txt b/Documentation/git-prune.txt index 7a493c8..a0ea381 100644 --- a/Documentation/git-prune.txt +++ b/Documentation/git-prune.txt @@ -48,6 +48,9 @@ OPTIONS --expire :: Only expire loose objects older than . +--worktrees:: + Prune stale worktree information in $GIT_DIR/worktrees. + ...:: In addition to objects reachable from any of our references, keep objects diff --git a/Documentation/gitrepository-layout.txt b/Documentation/gitrepository-layout.txt index 8228450..2b30a92 100644 --- a/Documentation/gitrepository-layout.txt +++ b/Documentation/gitrepository-layout.txt @@ -259,6 +259,25 @@ worktrees:: $GIT_COMMON_DIR is set and "$GIT_COMMON_DIR/worktrees" will be used instead. +worktrees//gitdir:: + A text file containing the absolute path back to the .git file + that points to here. This is used to check if the linked + repository has been manually removed and there is no need to + keep this directory any more. mtime of this file should be + updated every time the linked repository is accessed. + +worktrees//locked:: + If this file exists, the linked repository may be on a + portable device and not available. It does not mean that the + linked repository is gone and `worktrees/` could be + removed. The file's content contains a reason string on why + the repository is locked. + +worktrees//link:: + If this file exists, it is a hard link to the linked .git + file. It is used to detect if the linked repository is + manually removed. + SEE ALSO linkgit:git-init[1], diff --git a/builtin/checkout.c b/builtin/checkout.c index ad10f99..ab46af9 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -826,7 +826,7 @@ static int prepare_linked_checkout(const struct checkout_opts *opts, const char *path = opts->new_worktree,
Re: [PATCH v2 23/32] prune: strategies for linked checkouts
On Sat, Sep 20, 2014 at 10:54 PM, Duy Nguyen wrote: > On Fri, Sep 12, 2014 at 10:06 AM, Eric Sunshine > wrote: >> One minor addition for clarification would be to mention that the 'git >> prune --worktrees' invocation applies to the main worktree: >> >> When you are done with a linked working tree, you can simply delete >> it. You can clean up any stale $GIT_DIR/worktrees entries via >> `git prune --worktrees` in the main worktree. > > > The command should work from any worktree (of course not the worktree > that you just deleted). I try to make all operations work on all > worktrees. How should I write this? I realized that a bit after writing the above. You could qualify it as: When you are done with a linked working tree, you can simply delete it. You can clean up any stale $GIT_DIR/worktrees entries via `git prune --worktrees` in the main worktree or any linked tree. But the "...in the main worktree or any linked tree" is likely redundant, in which case Marc's rewrite is probably sufficient. -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 23/32] prune: strategies for linked checkouts
On Fri, Sep 12, 2014 at 10:06 AM, Eric Sunshine wrote: > One minor addition for clarification would be to mention that the 'git > prune --worktrees' invocation applies to the main worktree: > > When you are done with a linked working tree, you can simply delete > it. You can clean up any stale $GIT_DIR/worktrees entries via > `git prune --worktrees` in the main worktree. The command should work from any worktree (of course not the worktree that you just deleted). I try to make all operations work on all worktrees. How should I write this? >>> +To stop `git prune --worktrees` from deleting a specific working >>> +directory (e.g. because it's on a portable device), you could add the >>> +file 'locked' to $GIT_DIR/worktrees. For example, if `.git` file of >>> +the new working directory points to `/path/main/worktrees/test-next`, >>> +the full path of the 'locked' file would be >>> +`/path/main/worktrees/test-next/locked`. See >>> +linkgit:gitrepository-layout[5] for details. >> >> Sorry, I can't help rewriting this one too: >> >> To prevent `git prune --worktrees` from deleting a >> $GIT_DIR/worktrees entry (which can be useful in some situations, >> such as when the entry's working tree is stored on a portable >> device), add a file named 'locked' to the entry's directory. For >> example, if a linked working tree's `.git` file points to >> `/path/main/.git/worktrees/test-next` then a file named >> `/path/main/.git/worktrees/test-next/locked` will prevent the >> `test-next` entry from being pruned. See >> linkgit:gitrepository-layout[5] for details. > > Each time I read this (or Duy's original), the first question that > pops into my head is "should 'locked' be empty or have content, and if > content, what content?" gitrepository-layout.txt does explain the > content (if the reader bothers to chase the link), but perhaps it is > worth an explanatory sentence here? Will do. -- Duy -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 23/32] prune: strategies for linked checkouts
On 14-09-11 11:06 PM, Eric Sunshine wrote: > On Thu, Sep 11, 2014 at 11:36 AM, Marc Branchaud wrote: >> On 14-09-10 06:41 PM, Nguyễn Thái Ngọc Duy wrote: >>> (alias R=$GIT_COMMON_DIR/worktrees/) >>> >>> - linked checkouts are supposed to keep its location in $R/gitdir up >>>to date. The use case is auto fixup after a manual checkout move. >>> >>> - linked checkouts are supposed to update mtime of $R/gitdir. If >>>$R/gitdir's mtime is older than a limit, and it points to nowhere, >>>worktrees/ is to be pruned. >>> >>> - If $R/locked exists, worktrees/ is not supposed to be pruned. If >>>$R/locked exists and $R/gitdir's mtime is older than a really long >>>limit, warn about old unused repo. >>> >>> - "git checkout --to" is supposed to make a hard link named $R/link >>>pointing to the .git file on supported file systems to help detect >>>the user manually deleting the checkout. If $R/link exists and its >>>link count is greated than 1, the repo is kept. >>> >>> Signed-off-by: Nguyễn Thái Ngọc Duy >>> --- >>> Documentation/git-checkout.txt | 18 ++ >>> Documentation/git-prune.txt| 3 + >>> Documentation/gitrepository-layout.txt | 19 ++ >>> builtin/checkout.c | 19 +- >>> builtin/prune.c| 95 >>> ++ >>> setup.c| 13 >>> t/t2026-prune-linked-checkouts.sh (new +x) | 84 ++ >>> 7 files changed, 249 insertions(+), 2 deletions(-) >>> create mode 100755 t/t2026-prune-linked-checkouts.sh >>> >>> diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt >>> index bd0fc1d..a29748e 100644 >>> --- a/Documentation/git-checkout.txt >>> +++ b/Documentation/git-checkout.txt >>> @@ -431,6 +431,24 @@ thumb is do not make any assumption about whether a >>> path belongs to >>> $GIT_DIR or $GIT_COMMON_DIR when you need to directly access something >>> inside $GIT_DIR. Use `git rev-parse --git-path` to get the final path. >>> >>> +When you are done, simply deleting the linked working directory would >>> +suffice. $GIT_DIR/worktrees can be cleaned up using `git prune >>> +--worktrees`. >> >> This needs a tweak or two so that it follows more naturally from the previous >> paragraph. How about: >> >> When you are done with a linked working tree you can simply delete >> it. You can clean up any stale $GIT_DIR/worktrees entries with >> `git prune --worktrees`. > > Thanks for these rewrites; I was going to provide similar suggestions. > > One minor addition for clarification would be to mention that the 'git > prune --worktrees' invocation applies to the main worktree: > > When you are done with a linked working tree, you can simply delete > it. You can clean up any stale $GIT_DIR/worktrees entries via > `git prune --worktrees` in the main worktree. > >> Then in commit 28, when you add worktrees pruning to gc, you should change >> this paragraph again: >> >> When you are done with a linked working tree you can simply delete >> it. The working tree's entry in the repository's $GIT_DIR/worktrees >> directory will eventually be removed automatically (see >> `gc.pruneworktreesexpire` in linkgit::git-config[1]), or you can run >> `git prune --worktrees` to clean up any stale entries in >> $GIT_DIR/worktrees. > > Ditto about qualifying 'git prune --worktrees' with "in the main work tree". > >>> +After you move a linked working directory to another file system, or >>> +on a file system that does not support hard link, execute any git >>> +command (e.g. `git status`) in the new working directory so that it >>> +could update its location in $GIT_DIR/worktrees and not be >>> +accidentally pruned. >> >> It took me a couple of seconds to parse that. How about: >> >> If you move a linked working directory to another file system, or >> within a file system that does not support hard links, you need to >> run at least one git command inside the moved linked working > > I trip over "moved linked" every time I read it. I think there's > sufficient context in the 'if' clause leading to this that "moved" can > be dropped. Fine by me, as are your other suggestions. M. >> directory (e.g. `git status`) in order to update its entry in >> $GIT_DIR/worktrees so that it does not get automatically removed. >> >>> +To stop `git prune --worktrees` from deleting a specific working >>> +directory (e.g. because it's on a portable device), you could add the >>> +file 'locked' to $GIT_DIR/worktrees. For example, if `.git` file of >>> +the new working directory points to `/path/main/worktrees/test-next`, >>> +the full path of the 'locked' file would be >>> +`/path/main/worktrees/test-next/locked`. See >>> +linkgit:gitrepository-layout[5] for details. >> >> Sorry, I can't
Re: [PATCH v2 23/32] prune: strategies for linked checkouts
On Thu, Sep 11, 2014 at 11:36 AM, Marc Branchaud wrote: > On 14-09-10 06:41 PM, Nguyễn Thái Ngọc Duy wrote: >> (alias R=$GIT_COMMON_DIR/worktrees/) >> >> - linked checkouts are supposed to keep its location in $R/gitdir up >>to date. The use case is auto fixup after a manual checkout move. >> >> - linked checkouts are supposed to update mtime of $R/gitdir. If >>$R/gitdir's mtime is older than a limit, and it points to nowhere, >>worktrees/ is to be pruned. >> >> - If $R/locked exists, worktrees/ is not supposed to be pruned. If >>$R/locked exists and $R/gitdir's mtime is older than a really long >>limit, warn about old unused repo. >> >> - "git checkout --to" is supposed to make a hard link named $R/link >>pointing to the .git file on supported file systems to help detect >>the user manually deleting the checkout. If $R/link exists and its >>link count is greated than 1, the repo is kept. >> >> Signed-off-by: Nguyễn Thái Ngọc Duy >> --- >> Documentation/git-checkout.txt | 18 ++ >> Documentation/git-prune.txt| 3 + >> Documentation/gitrepository-layout.txt | 19 ++ >> builtin/checkout.c | 19 +- >> builtin/prune.c| 95 >> ++ >> setup.c| 13 >> t/t2026-prune-linked-checkouts.sh (new +x) | 84 ++ >> 7 files changed, 249 insertions(+), 2 deletions(-) >> create mode 100755 t/t2026-prune-linked-checkouts.sh >> >> diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt >> index bd0fc1d..a29748e 100644 >> --- a/Documentation/git-checkout.txt >> +++ b/Documentation/git-checkout.txt >> @@ -431,6 +431,24 @@ thumb is do not make any assumption about whether a >> path belongs to >> $GIT_DIR or $GIT_COMMON_DIR when you need to directly access something >> inside $GIT_DIR. Use `git rev-parse --git-path` to get the final path. >> >> +When you are done, simply deleting the linked working directory would >> +suffice. $GIT_DIR/worktrees can be cleaned up using `git prune >> +--worktrees`. > > This needs a tweak or two so that it follows more naturally from the previous > paragraph. How about: > > When you are done with a linked working tree you can simply delete > it. You can clean up any stale $GIT_DIR/worktrees entries with > `git prune --worktrees`. Thanks for these rewrites; I was going to provide similar suggestions. One minor addition for clarification would be to mention that the 'git prune --worktrees' invocation applies to the main worktree: When you are done with a linked working tree, you can simply delete it. You can clean up any stale $GIT_DIR/worktrees entries via `git prune --worktrees` in the main worktree. > Then in commit 28, when you add worktrees pruning to gc, you should change > this paragraph again: > > When you are done with a linked working tree you can simply delete > it. The working tree's entry in the repository's $GIT_DIR/worktrees > directory will eventually be removed automatically (see > `gc.pruneworktreesexpire` in linkgit::git-config[1]), or you can run > `git prune --worktrees` to clean up any stale entries in > $GIT_DIR/worktrees. Ditto about qualifying 'git prune --worktrees' with "in the main work tree". >> +After you move a linked working directory to another file system, or >> +on a file system that does not support hard link, execute any git >> +command (e.g. `git status`) in the new working directory so that it >> +could update its location in $GIT_DIR/worktrees and not be >> +accidentally pruned. > > It took me a couple of seconds to parse that. How about: > > If you move a linked working directory to another file system, or > within a file system that does not support hard links, you need to > run at least one git command inside the moved linked working I trip over "moved linked" every time I read it. I think there's sufficient context in the 'if' clause leading to this that "moved" can be dropped. > directory (e.g. `git status`) in order to update its entry in > $GIT_DIR/worktrees so that it does not get automatically removed. > >> +To stop `git prune --worktrees` from deleting a specific working >> +directory (e.g. because it's on a portable device), you could add the >> +file 'locked' to $GIT_DIR/worktrees. For example, if `.git` file of >> +the new working directory points to `/path/main/worktrees/test-next`, >> +the full path of the 'locked' file would be >> +`/path/main/worktrees/test-next/locked`. See >> +linkgit:gitrepository-layout[5] for details. > > Sorry, I can't help rewriting this one too: > > To prevent `git prune --worktrees` from deleting a > $GIT_DIR/worktrees entry (which can be useful in some situations, > such as when the entry's working tree is stored
Re: [PATCH v2 23/32] prune: strategies for linked checkouts
On 14-09-10 06:41 PM, Nguyễn Thái Ngọc Duy wrote: > (alias R=$GIT_COMMON_DIR/worktrees/) > > - linked checkouts are supposed to keep its location in $R/gitdir up >to date. The use case is auto fixup after a manual checkout move. > > - linked checkouts are supposed to update mtime of $R/gitdir. If >$R/gitdir's mtime is older than a limit, and it points to nowhere, >worktrees/ is to be pruned. > > - If $R/locked exists, worktrees/ is not supposed to be pruned. If >$R/locked exists and $R/gitdir's mtime is older than a really long >limit, warn about old unused repo. > > - "git checkout --to" is supposed to make a hard link named $R/link >pointing to the .git file on supported file systems to help detect >the user manually deleting the checkout. If $R/link exists and its >link count is greated than 1, the repo is kept. > > Signed-off-by: Nguyễn Thái Ngọc Duy > --- > Documentation/git-checkout.txt | 18 ++ > Documentation/git-prune.txt| 3 + > Documentation/gitrepository-layout.txt | 19 ++ > builtin/checkout.c | 19 +- > builtin/prune.c| 95 > ++ > setup.c| 13 > t/t2026-prune-linked-checkouts.sh (new +x) | 84 ++ > 7 files changed, 249 insertions(+), 2 deletions(-) > create mode 100755 t/t2026-prune-linked-checkouts.sh > > diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt > index bd0fc1d..a29748e 100644 > --- a/Documentation/git-checkout.txt > +++ b/Documentation/git-checkout.txt > @@ -431,6 +431,24 @@ thumb is do not make any assumption about whether a path > belongs to > $GIT_DIR or $GIT_COMMON_DIR when you need to directly access something > inside $GIT_DIR. Use `git rev-parse --git-path` to get the final path. > > +When you are done, simply deleting the linked working directory would > +suffice. $GIT_DIR/worktrees can be cleaned up using `git prune > +--worktrees`. This needs a tweak or two so that it follows more naturally from the previous paragraph. How about: When you are done with a linked working tree you can simply delete it. You can clean up any stale $GIT_DIR/worktrees entries with `git prune --worktrees`. Then in commit 28, when you add worktrees pruning to gc, you should change this paragraph again: When you are done with a linked working tree you can simply delete it. The working tree's entry in the repository's $GIT_DIR/worktrees directory will eventually be removed automatically (see `gc.pruneworktreesexpire` in linkgit::git-config[1]), or you can run `git prune --worktrees` to clean up any stale entries in $GIT_DIR/worktrees. > +After you move a linked working directory to another file system, or > +on a file system that does not support hard link, execute any git > +command (e.g. `git status`) in the new working directory so that it > +could update its location in $GIT_DIR/worktrees and not be > +accidentally pruned. It took me a couple of seconds to parse that. How about: If you move a linked working directory to another file system, or within a file system that does not support hard links, you need to run at least one git command inside the moved linked working directory (e.g. `git status`) in order to update its entry in $GIT_DIR/worktrees so that it does not get automatically removed. > +To stop `git prune --worktrees` from deleting a specific working > +directory (e.g. because it's on a portable device), you could add the > +file 'locked' to $GIT_DIR/worktrees. For example, if `.git` file of > +the new working directory points to `/path/main/worktrees/test-next`, > +the full path of the 'locked' file would be > +`/path/main/worktrees/test-next/locked`. See > +linkgit:gitrepository-layout[5] for details. Sorry, I can't help rewriting this one too: To prevent `git prune --worktrees` from deleting a $GIT_DIR/worktrees entry (which can be useful in some situations, such as when the entry's working tree is stored on a portable device), add a file named 'locked' to the entry's directory. For example, if a linked working tree's `.git` file points to `/path/main/.git/worktrees/test-next` then a file named `/path/main/.git/worktrees/test-next/locked` will prevent the `test-next` entry from being pruned. See linkgit:gitrepository-layout[5] for details. I also suggest this paragraph get updated in commit 28, but just change the first clause, before "(which can be ...": To prevent a $GIT_DIR/worktrees entry from being pruned (which ... Thanks for all this work! M. -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at htt
[PATCH v2 23/32] prune: strategies for linked checkouts
(alias R=$GIT_COMMON_DIR/worktrees/) - linked checkouts are supposed to keep its location in $R/gitdir up to date. The use case is auto fixup after a manual checkout move. - linked checkouts are supposed to update mtime of $R/gitdir. If $R/gitdir's mtime is older than a limit, and it points to nowhere, worktrees/ is to be pruned. - If $R/locked exists, worktrees/ is not supposed to be pruned. If $R/locked exists and $R/gitdir's mtime is older than a really long limit, warn about old unused repo. - "git checkout --to" is supposed to make a hard link named $R/link pointing to the .git file on supported file systems to help detect the user manually deleting the checkout. If $R/link exists and its link count is greated than 1, the repo is kept. Signed-off-by: Nguyễn Thái Ngọc Duy --- Documentation/git-checkout.txt | 18 ++ Documentation/git-prune.txt| 3 + Documentation/gitrepository-layout.txt | 19 ++ builtin/checkout.c | 19 +- builtin/prune.c| 95 ++ setup.c| 13 t/t2026-prune-linked-checkouts.sh (new +x) | 84 ++ 7 files changed, 249 insertions(+), 2 deletions(-) create mode 100755 t/t2026-prune-linked-checkouts.sh diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt index bd0fc1d..a29748e 100644 --- a/Documentation/git-checkout.txt +++ b/Documentation/git-checkout.txt @@ -431,6 +431,24 @@ thumb is do not make any assumption about whether a path belongs to $GIT_DIR or $GIT_COMMON_DIR when you need to directly access something inside $GIT_DIR. Use `git rev-parse --git-path` to get the final path. +When you are done, simply deleting the linked working directory would +suffice. $GIT_DIR/worktrees can be cleaned up using `git prune +--worktrees`. + +After you move a linked working directory to another file system, or +on a file system that does not support hard link, execute any git +command (e.g. `git status`) in the new working directory so that it +could update its location in $GIT_DIR/worktrees and not be +accidentally pruned. + +To stop `git prune --worktrees` from deleting a specific working +directory (e.g. because it's on a portable device), you could add the +file 'locked' to $GIT_DIR/worktrees. For example, if `.git` file of +the new working directory points to `/path/main/worktrees/test-next`, +the full path of the 'locked' file would be +`/path/main/worktrees/test-next/locked`. See +linkgit:gitrepository-layout[5] for details. + EXAMPLES diff --git a/Documentation/git-prune.txt b/Documentation/git-prune.txt index 7a493c8..a0ea381 100644 --- a/Documentation/git-prune.txt +++ b/Documentation/git-prune.txt @@ -48,6 +48,9 @@ OPTIONS --expire :: Only expire loose objects older than . +--worktrees:: + Prune dead worktree information in $GIT_DIR/worktrees. + ...:: In addition to objects reachable from any of our references, keep objects diff --git a/Documentation/gitrepository-layout.txt b/Documentation/gitrepository-layout.txt index a82780c..5ceff51 100644 --- a/Documentation/gitrepository-layout.txt +++ b/Documentation/gitrepository-layout.txt @@ -255,6 +255,25 @@ worktrees:: $GIT_COMMON_DIR is set and "$GIT_COMMON_DIR/worktrees" will be used instead. +worktrees//gitdir:: + A text file containing the absolute path back to the .git file + that points to here. This is used to check if the linked + repository has been manually removed and there is no need to + keep this directory any more. mtime of this file should be + updated every time the linked repository is accessed. + +worktrees//locked:: + If this file exists, the linked repository may be on a + portable device and not available. It does not mean that the + linked repository is gone and `worktrees/` could be + removed. The file's content contains a reason string on why + the repository is locked. + +worktrees//link:: + If this file exists, it is a hard link to the linked .git + file. It is used to detect if the linked repository is + manually removed. + SEE ALSO linkgit:git-init[1], diff --git a/builtin/checkout.c b/builtin/checkout.c index 1868f69..b5ddf88 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -822,7 +822,7 @@ static int prepare_linked_checkout(const struct checkout_opts *opts, const char *path = opts->new_worktree, *name; struct stat st; struct child_process cp; - int counter = 0, len; + int counter = 0, len, ret; if (!new->commit) die(_("no branch specified")); @@ -853,11 +853,21 @@ static int prepare_linked_checkout(const struct checkout_opts *opts, if (mkdir(sb_repo.buf, 0777)) die_errno(_("could not create directory of '%s'"), sb