Merge branch 'nd/worktree-prune'
The way "git worktree prune" worked internally has been simplified, by assuming how "git worktree move" moves an existing worktree to a different place. * nd/worktree-prune: worktree prune: improve prune logic when worktree is moved worktree: delete dead code gc.txt: more details about what gc doesmaint
commit
ca923f7265
|
@ -15,8 +15,9 @@ DESCRIPTION
|
||||||
-----------
|
-----------
|
||||||
Runs a number of housekeeping tasks within the current repository,
|
Runs a number of housekeeping tasks within the current repository,
|
||||||
such as compressing file revisions (to reduce disk space and increase
|
such as compressing file revisions (to reduce disk space and increase
|
||||||
performance) and removing unreachable objects which may have been
|
performance), removing unreachable objects which may have been
|
||||||
created from prior invocations of 'git add'.
|
created from prior invocations of 'git add', packing refs, pruning
|
||||||
|
reflog, rerere metadata or stale working trees.
|
||||||
|
|
||||||
Users are encouraged to run this task on a regular basis within
|
Users are encouraged to run this task on a regular basis within
|
||||||
each repository to maintain good disk space utilization and good
|
each repository to maintain good disk space utilization and good
|
||||||
|
@ -45,20 +46,25 @@ OPTIONS
|
||||||
With this option, 'git gc' checks whether any housekeeping is
|
With this option, 'git gc' checks whether any housekeeping is
|
||||||
required; if not, it exits without performing any work.
|
required; if not, it exits without performing any work.
|
||||||
Some git commands run `git gc --auto` after performing
|
Some git commands run `git gc --auto` after performing
|
||||||
operations that could create many loose objects.
|
operations that could create many loose objects. Housekeeping
|
||||||
|
is required if there are too many loose objects or too many
|
||||||
|
packs in the repository.
|
||||||
+
|
+
|
||||||
Housekeeping is required if there are too many loose objects or
|
If the number of loose objects exceeds the value of the `gc.auto`
|
||||||
too many packs in the repository. If the number of loose objects
|
configuration variable, then all loose objects are combined into a
|
||||||
exceeds the value of the `gc.auto` configuration variable, then
|
single pack using `git repack -d -l`. Setting the value of `gc.auto`
|
||||||
all loose objects are combined into a single pack using
|
to 0 disables automatic packing of loose objects.
|
||||||
`git repack -d -l`. Setting the value of `gc.auto` to 0
|
|
||||||
disables automatic packing of loose objects.
|
|
||||||
+
|
+
|
||||||
If the number of packs exceeds the value of `gc.autoPackLimit`,
|
If the number of packs exceeds the value of `gc.autoPackLimit`,
|
||||||
then existing packs (except those marked with a `.keep` file)
|
then existing packs (except those marked with a `.keep` file)
|
||||||
are consolidated into a single pack by using the `-A` option of
|
are consolidated into a single pack by using the `-A` option of
|
||||||
'git repack'. Setting `gc.autoPackLimit` to 0 disables
|
'git repack'. Setting `gc.autoPackLimit` to 0 disables
|
||||||
automatic consolidation of packs.
|
automatic consolidation of packs.
|
||||||
|
+
|
||||||
|
If houskeeping is required due to many loose objects or packs, all
|
||||||
|
other housekeeping tasks (e.g. rerere, working trees, reflog...) will
|
||||||
|
be performed as well.
|
||||||
|
|
||||||
|
|
||||||
--prune=<date>::
|
--prune=<date>::
|
||||||
Prune loose objects older than date (default is 2 weeks ago,
|
Prune loose objects older than date (default is 2 weeks ago,
|
||||||
|
@ -133,6 +139,10 @@ The optional configuration variable `gc.pruneExpire` controls how old
|
||||||
the unreferenced loose objects have to be before they are pruned. The
|
the unreferenced loose objects have to be before they are pruned. The
|
||||||
default is "2 weeks ago".
|
default is "2 weeks ago".
|
||||||
|
|
||||||
|
Optional configuration variable `gc.worktreePruneExpire` controls how
|
||||||
|
old a stale working tree should be before `git worktree prune` deletes
|
||||||
|
it. Default is "3 months ago".
|
||||||
|
|
||||||
|
|
||||||
Notes
|
Notes
|
||||||
-----
|
-----
|
||||||
|
|
|
@ -275,11 +275,6 @@ worktrees/<id>/locked::
|
||||||
or manually by `git worktree prune`. The file may contain a string
|
or manually by `git worktree prune`. The file may contain a string
|
||||||
explaining why the repository is locked.
|
explaining why the repository is locked.
|
||||||
|
|
||||||
worktrees/<id>/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
|
SEE ALSO
|
||||||
--------
|
--------
|
||||||
linkgit:git-init[1],
|
linkgit:git-init[1],
|
||||||
|
|
|
@ -101,16 +101,9 @@ static int prune_worktree(const char *id, struct strbuf *reason)
|
||||||
}
|
}
|
||||||
path[len] = '\0';
|
path[len] = '\0';
|
||||||
if (!file_exists(path)) {
|
if (!file_exists(path)) {
|
||||||
struct stat st_link;
|
|
||||||
free(path);
|
free(path);
|
||||||
/*
|
if (stat(git_path("worktrees/%s/index", id), &st) ||
|
||||||
* the repo is moved manually and has not been
|
st.st_mtime <= expire) {
|
||||||
* accessed since?
|
|
||||||
*/
|
|
||||||
if (!stat(git_path("worktrees/%s/link", id), &st_link) &&
|
|
||||||
st_link.st_nlink > 1)
|
|
||||||
return 0;
|
|
||||||
if (st.st_mtime <= expire) {
|
|
||||||
strbuf_addf(reason, _("Removing worktrees/%s: gitdir file points to non-existent location"), id);
|
strbuf_addf(reason, _("Removing worktrees/%s: gitdir file points to non-existent location"), id);
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -78,10 +78,9 @@ test_expect_success 'not prune locked checkout' '
|
||||||
|
|
||||||
test_expect_success 'not prune recent checkouts' '
|
test_expect_success 'not prune recent checkouts' '
|
||||||
test_when_finished rm -r .git/worktrees &&
|
test_when_finished rm -r .git/worktrees &&
|
||||||
mkdir zz &&
|
git worktree add jlm HEAD &&
|
||||||
mkdir -p .git/worktrees/jlm &&
|
test -d .git/worktrees/jlm &&
|
||||||
echo "$(pwd)"/zz >.git/worktrees/jlm/gitdir &&
|
rm -rf jlm &&
|
||||||
rmdir zz &&
|
|
||||||
git worktree prune --verbose --expire=2.days.ago &&
|
git worktree prune --verbose --expire=2.days.ago &&
|
||||||
test -d .git/worktrees/jlm
|
test -d .git/worktrees/jlm
|
||||||
'
|
'
|
||||||
|
|
Loading…
Reference in New Issue