6
6
#include "reachable.h"
7
7
#include "parse-options.h"
8
8
#include "progress.h"
9
- #include "dir.h"
10
9
11
10
static const char * const prune_usage [] = {
12
11
N_ ("git prune [-n] [-v] [--expire <time>] [--] [<head>...]" ),
@@ -76,95 +75,6 @@ static int prune_subdir(int nr, const char *path, void *data)
76
75
return 0 ;
77
76
}
78
77
79
- static int prune_worktree (const char * id , struct strbuf * reason )
80
- {
81
- struct stat st ;
82
- char * path ;
83
- int fd , len ;
84
-
85
- if (!is_directory (git_path ("worktrees/%s" , id ))) {
86
- strbuf_addf (reason , _ ("Removing worktrees/%s: not a valid directory" ), id );
87
- return 1 ;
88
- }
89
- if (file_exists (git_path ("worktrees/%s/locked" , id )))
90
- return 0 ;
91
- if (stat (git_path ("worktrees/%s/gitdir" , id ), & st )) {
92
- strbuf_addf (reason , _ ("Removing worktrees/%s: gitdir file does not exist" ), id );
93
- return 1 ;
94
- }
95
- fd = open (git_path ("worktrees/%s/gitdir" , id ), O_RDONLY );
96
- if (fd < 0 ) {
97
- strbuf_addf (reason , _ ("Removing worktrees/%s: unable to read gitdir file (%s)" ),
98
- id , strerror (errno ));
99
- return 1 ;
100
- }
101
- len = st .st_size ;
102
- path = xmalloc (len + 1 );
103
- read_in_full (fd , path , len );
104
- close (fd );
105
- while (len && (path [len - 1 ] == '\n' || path [len - 1 ] == '\r' ))
106
- len -- ;
107
- if (!len ) {
108
- strbuf_addf (reason , _ ("Removing worktrees/%s: invalid gitdir file" ), id );
109
- free (path );
110
- return 1 ;
111
- }
112
- path [len ] = '\0' ;
113
- if (!file_exists (path )) {
114
- struct stat st_link ;
115
- free (path );
116
- /*
117
- * the repo is moved manually and has not been
118
- * accessed since?
119
- */
120
- if (!stat (git_path ("worktrees/%s/link" , id ), & st_link ) &&
121
- st_link .st_nlink > 1 )
122
- return 0 ;
123
- if (st .st_mtime <= expire ) {
124
- strbuf_addf (reason , _ ("Removing worktrees/%s: gitdir file points to non-existent location" ), id );
125
- return 1 ;
126
- } else {
127
- return 0 ;
128
- }
129
- }
130
- free (path );
131
- return 0 ;
132
- }
133
-
134
- static void prune_worktrees (void )
135
- {
136
- struct strbuf reason = STRBUF_INIT ;
137
- struct strbuf path = STRBUF_INIT ;
138
- DIR * dir = opendir (git_path ("worktrees" ));
139
- struct dirent * d ;
140
- int ret ;
141
- if (!dir )
142
- return ;
143
- while ((d = readdir (dir )) != NULL ) {
144
- if (!strcmp (d -> d_name , "." ) || !strcmp (d -> d_name , ".." ))
145
- continue ;
146
- strbuf_reset (& reason );
147
- if (!prune_worktree (d -> d_name , & reason ))
148
- continue ;
149
- if (show_only || verbose )
150
- printf ("%s\n" , reason .buf );
151
- if (show_only )
152
- continue ;
153
- strbuf_reset (& path );
154
- strbuf_addstr (& path , git_path ("worktrees/%s" , d -> d_name ));
155
- ret = remove_dir_recursively (& path , 0 );
156
- if (ret < 0 && errno == ENOTDIR )
157
- ret = unlink (path .buf );
158
- if (ret )
159
- error (_ ("failed to remove: %s" ), strerror (errno ));
160
- }
161
- closedir (dir );
162
- if (!show_only )
163
- rmdir (git_path ("worktrees" ));
164
- strbuf_release (& reason );
165
- strbuf_release (& path );
166
- }
167
-
168
78
/*
169
79
* Write errors (particularly out of space) can result in
170
80
* failed temporary packs (and more rarely indexes and other
@@ -191,12 +101,10 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
191
101
{
192
102
struct rev_info revs ;
193
103
struct progress * progress = NULL ;
194
- int do_prune_worktrees = 0 ;
195
104
const struct option options [] = {
196
105
OPT__DRY_RUN (& show_only , N_ ("do not remove, show only" )),
197
106
OPT__VERBOSE (& verbose , N_ ("report pruned objects" )),
198
107
OPT_BOOL (0 , "progress" , & show_progress , N_ ("show progress" )),
199
- OPT_BOOL (0 , "worktrees" , & do_prune_worktrees , N_ ("prune .git/worktrees" )),
200
108
OPT_EXPIRY_DATE (0 , "expire" , & expire ,
201
109
N_ ("expire objects older than <time>" )),
202
110
OPT_END ()
@@ -211,13 +119,6 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
211
119
212
120
argc = parse_options (argc , argv , prefix , options , prune_usage , 0 );
213
121
214
- if (do_prune_worktrees ) {
215
- if (argc )
216
- die (_ ("--worktrees does not take extra arguments" ));
217
- prune_worktrees ();
218
- return 0 ;
219
- }
220
-
221
122
while (argc -- ) {
222
123
unsigned char sha1 [20 ];
223
124
const char * name = * argv ++ ;
0 commit comments