Fossil SCM

fossil rm can now remove entire directories.

jeremy_c 2010-02-08 18:47 trunk
Commit 6dbd362de9edaef511859cb49691b0ad62e6b78f
1 file changed +67 -20
+67 -20
--- src/add.c
+++ src/add.c
@@ -7,11 +7,11 @@
77
**
88
** This program is distributed in the hope that it will be useful,
99
** but WITHOUT ANY WARRANTY; without even the implied warranty of
1010
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1111
** General Public License for more details.
12
-**
12
+**
1313
** You should have received a copy of the GNU General Public
1414
** License along with this library; if not, write to the
1515
** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1616
** Boston, MA 02111-1307, USA.
1717
**
@@ -32,18 +32,18 @@
3232
/*
3333
** Set to true if files whose names begin with "." should be
3434
** included when processing a recursive "add" command.
3535
*/
3636
static int includeDotFiles = 0;
37
-
37
+
3838
/*
3939
** Add a single file
4040
*/
4141
static void add_one_file(const char *zName, int vid, Blob *pOmit){
4242
Blob pathname;
4343
const char *zPath;
44
-
44
+
4545
file_tree_name(zName, &pathname, 1);
4646
zPath = blob_str(&pathname);
4747
if( strcmp(zPath, "manifest")==0
4848
|| strcmp(zPath, "_FOSSIL_")==0
4949
|| strcmp(zPath, "manifest.uuid")==0
@@ -126,11 +126,11 @@
126126
/*
127127
** COMMAND: add
128128
**
129129
** Usage: %fossil add FILE...
130130
**
131
-** Make arrangements to add one or more files to the current checkout
131
+** Make arrangements to add one or more files to the current checkout
132132
** at the next commit.
133133
**
134134
** When adding files recursively, filenames that begin with "." are
135135
** excluded by default. To include such files, add the "--dotfiles"
136136
** option to the command-line.
@@ -174,10 +174,57 @@
174174
}
175175
free(zName);
176176
}
177177
db_end_transaction(0);
178178
}
179
+
180
+/*
181
+** Remove all contents of zDir
182
+*/
183
+void del_directory_content(const char *zDir){
184
+ DIR *d;
185
+ int origSize;
186
+ struct dirent *pEntry;
187
+ Blob path;
188
+
189
+ blob_zero(&path);
190
+ blob_append(&path, zDir, -1);
191
+ origSize = blob_size(&path);
192
+ d = opendir(zDir);
193
+ if( d ){
194
+ while( (pEntry=readdir(d))!=0 ){
195
+ char *zPath;
196
+ if( pEntry->d_name[0]=='.'){
197
+ if( !includeDotFiles ) continue;
198
+ if( pEntry->d_name[1]==0 ) continue;
199
+ if( pEntry->d_name[1]=='.' && pEntry->d_name[2]==0 ) continue;
200
+ }
201
+ blob_appendf(&path, "/%s", pEntry->d_name);
202
+ zPath = blob_str(&path);
203
+ if( file_isdir(zPath)==1 ){
204
+ del_directory_content(zPath);
205
+ }else if( file_isfile(zPath) ){
206
+ char *zFilePath;
207
+ Blob pathname;
208
+ file_tree_name(zPath, &pathname, 1);
209
+ zFilePath = blob_str(&pathname);
210
+ if( !db_exists(
211
+ "SELECT 1 FROM vfile WHERE pathname=%Q AND NOT deleted", zFilePath)
212
+ ){
213
+ printf("SKIPPED %s\n", zPath);
214
+ }else{
215
+ db_multi_exec("UPDATE vfile SET deleted=1 WHERE pathname=%Q", zPath);
216
+ printf("DELETED %s\n", zPath);
217
+ }
218
+ blob_reset(&pathname);
219
+ }
220
+ blob_resize(&path, origSize);
221
+ }
222
+ }
223
+ closedir(d);
224
+ blob_reset(&path);
225
+}
179226
180227
/*
181228
** COMMAND: rm
182229
** COMMAND: del
183230
**
@@ -200,36 +247,36 @@
200247
fossil_panic("no checkout to remove from");
201248
}
202249
db_begin_transaction();
203250
for(i=2; i<g.argc; i++){
204251
char *zName;
205
- char *zPath;
206
- Blob pathname;
207252
208253
zName = mprintf("%/", g.argv[i]);
209254
if( file_isdir(zName) ){
210
- fossil_fatal("cannot remove directories -"
211
- " remove individual files instead");
212
- }
213
- file_tree_name(zName, &pathname, 1);
214
- zPath = blob_str(&pathname);
215
- if( !db_exists(
216
- "SELECT 1 FROM vfile WHERE pathname=%Q AND NOT deleted", zPath) ){
217
- fossil_fatal("not in the repository: %s", zName);
218
- }else{
219
- db_multi_exec("UPDATE vfile SET deleted=1 WHERE pathname=%Q", zPath);
220
- printf("DELETED %s\n", zPath);
221
- }
222
- blob_reset(&pathname);
255
+ del_directory_content(zName);
256
+ } else {
257
+ char *zPath;
258
+ Blob pathname;
259
+ file_tree_name(zName, &pathname, 1);
260
+ zPath = blob_str(&pathname);
261
+ if( !db_exists(
262
+ "SELECT 1 FROM vfile WHERE pathname=%Q AND NOT deleted", zPath) ){
263
+ fossil_fatal("not in the repository: %s", zName);
264
+ }else{
265
+ db_multi_exec("UPDATE vfile SET deleted=1 WHERE pathname=%Q", zPath);
266
+ printf("DELETED %s\n", zPath);
267
+ }
268
+ blob_reset(&pathname);
269
+ }
223270
free(zName);
224271
}
225272
db_multi_exec("DELETE FROM vfile WHERE deleted AND rid=0");
226273
db_end_transaction(0);
227274
}
228275
229276
/*
230
-** Rename a single file.
277
+** Rename a single file.
231278
**
232279
** The original name of the file is zOrig. The new filename is zNew.
233280
*/
234281
static void mv_one_file(int vid, const char *zOrig, const char *zNew){
235282
printf("RENAME %s %s\n", zOrig, zNew);
236283
--- src/add.c
+++ src/add.c
@@ -7,11 +7,11 @@
7 **
8 ** This program is distributed in the hope that it will be useful,
9 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 ** General Public License for more details.
12 **
13 ** You should have received a copy of the GNU General Public
14 ** License along with this library; if not, write to the
15 ** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 ** Boston, MA 02111-1307, USA.
17 **
@@ -32,18 +32,18 @@
32 /*
33 ** Set to true if files whose names begin with "." should be
34 ** included when processing a recursive "add" command.
35 */
36 static int includeDotFiles = 0;
37
38 /*
39 ** Add a single file
40 */
41 static void add_one_file(const char *zName, int vid, Blob *pOmit){
42 Blob pathname;
43 const char *zPath;
44
45 file_tree_name(zName, &pathname, 1);
46 zPath = blob_str(&pathname);
47 if( strcmp(zPath, "manifest")==0
48 || strcmp(zPath, "_FOSSIL_")==0
49 || strcmp(zPath, "manifest.uuid")==0
@@ -126,11 +126,11 @@
126 /*
127 ** COMMAND: add
128 **
129 ** Usage: %fossil add FILE...
130 **
131 ** Make arrangements to add one or more files to the current checkout
132 ** at the next commit.
133 **
134 ** When adding files recursively, filenames that begin with "." are
135 ** excluded by default. To include such files, add the "--dotfiles"
136 ** option to the command-line.
@@ -174,10 +174,57 @@
174 }
175 free(zName);
176 }
177 db_end_transaction(0);
178 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
180 /*
181 ** COMMAND: rm
182 ** COMMAND: del
183 **
@@ -200,36 +247,36 @@
200 fossil_panic("no checkout to remove from");
201 }
202 db_begin_transaction();
203 for(i=2; i<g.argc; i++){
204 char *zName;
205 char *zPath;
206 Blob pathname;
207
208 zName = mprintf("%/", g.argv[i]);
209 if( file_isdir(zName) ){
210 fossil_fatal("cannot remove directories -"
211 " remove individual files instead");
212 }
213 file_tree_name(zName, &pathname, 1);
214 zPath = blob_str(&pathname);
215 if( !db_exists(
216 "SELECT 1 FROM vfile WHERE pathname=%Q AND NOT deleted", zPath) ){
217 fossil_fatal("not in the repository: %s", zName);
218 }else{
219 db_multi_exec("UPDATE vfile SET deleted=1 WHERE pathname=%Q", zPath);
220 printf("DELETED %s\n", zPath);
221 }
222 blob_reset(&pathname);
 
 
223 free(zName);
224 }
225 db_multi_exec("DELETE FROM vfile WHERE deleted AND rid=0");
226 db_end_transaction(0);
227 }
228
229 /*
230 ** Rename a single file.
231 **
232 ** The original name of the file is zOrig. The new filename is zNew.
233 */
234 static void mv_one_file(int vid, const char *zOrig, const char *zNew){
235 printf("RENAME %s %s\n", zOrig, zNew);
236
--- src/add.c
+++ src/add.c
@@ -7,11 +7,11 @@
7 **
8 ** This program is distributed in the hope that it will be useful,
9 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 ** General Public License for more details.
12 **
13 ** You should have received a copy of the GNU General Public
14 ** License along with this library; if not, write to the
15 ** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 ** Boston, MA 02111-1307, USA.
17 **
@@ -32,18 +32,18 @@
32 /*
33 ** Set to true if files whose names begin with "." should be
34 ** included when processing a recursive "add" command.
35 */
36 static int includeDotFiles = 0;
37
38 /*
39 ** Add a single file
40 */
41 static void add_one_file(const char *zName, int vid, Blob *pOmit){
42 Blob pathname;
43 const char *zPath;
44
45 file_tree_name(zName, &pathname, 1);
46 zPath = blob_str(&pathname);
47 if( strcmp(zPath, "manifest")==0
48 || strcmp(zPath, "_FOSSIL_")==0
49 || strcmp(zPath, "manifest.uuid")==0
@@ -126,11 +126,11 @@
126 /*
127 ** COMMAND: add
128 **
129 ** Usage: %fossil add FILE...
130 **
131 ** Make arrangements to add one or more files to the current checkout
132 ** at the next commit.
133 **
134 ** When adding files recursively, filenames that begin with "." are
135 ** excluded by default. To include such files, add the "--dotfiles"
136 ** option to the command-line.
@@ -174,10 +174,57 @@
174 }
175 free(zName);
176 }
177 db_end_transaction(0);
178 }
179
180 /*
181 ** Remove all contents of zDir
182 */
183 void del_directory_content(const char *zDir){
184 DIR *d;
185 int origSize;
186 struct dirent *pEntry;
187 Blob path;
188
189 blob_zero(&path);
190 blob_append(&path, zDir, -1);
191 origSize = blob_size(&path);
192 d = opendir(zDir);
193 if( d ){
194 while( (pEntry=readdir(d))!=0 ){
195 char *zPath;
196 if( pEntry->d_name[0]=='.'){
197 if( !includeDotFiles ) continue;
198 if( pEntry->d_name[1]==0 ) continue;
199 if( pEntry->d_name[1]=='.' && pEntry->d_name[2]==0 ) continue;
200 }
201 blob_appendf(&path, "/%s", pEntry->d_name);
202 zPath = blob_str(&path);
203 if( file_isdir(zPath)==1 ){
204 del_directory_content(zPath);
205 }else if( file_isfile(zPath) ){
206 char *zFilePath;
207 Blob pathname;
208 file_tree_name(zPath, &pathname, 1);
209 zFilePath = blob_str(&pathname);
210 if( !db_exists(
211 "SELECT 1 FROM vfile WHERE pathname=%Q AND NOT deleted", zFilePath)
212 ){
213 printf("SKIPPED %s\n", zPath);
214 }else{
215 db_multi_exec("UPDATE vfile SET deleted=1 WHERE pathname=%Q", zPath);
216 printf("DELETED %s\n", zPath);
217 }
218 blob_reset(&pathname);
219 }
220 blob_resize(&path, origSize);
221 }
222 }
223 closedir(d);
224 blob_reset(&path);
225 }
226
227 /*
228 ** COMMAND: rm
229 ** COMMAND: del
230 **
@@ -200,36 +247,36 @@
247 fossil_panic("no checkout to remove from");
248 }
249 db_begin_transaction();
250 for(i=2; i<g.argc; i++){
251 char *zName;
 
 
252
253 zName = mprintf("%/", g.argv[i]);
254 if( file_isdir(zName) ){
255 del_directory_content(zName);
256 } else {
257 char *zPath;
258 Blob pathname;
259 file_tree_name(zName, &pathname, 1);
260 zPath = blob_str(&pathname);
261 if( !db_exists(
262 "SELECT 1 FROM vfile WHERE pathname=%Q AND NOT deleted", zPath) ){
263 fossil_fatal("not in the repository: %s", zName);
264 }else{
265 db_multi_exec("UPDATE vfile SET deleted=1 WHERE pathname=%Q", zPath);
266 printf("DELETED %s\n", zPath);
267 }
268 blob_reset(&pathname);
269 }
270 free(zName);
271 }
272 db_multi_exec("DELETE FROM vfile WHERE deleted AND rid=0");
273 db_end_transaction(0);
274 }
275
276 /*
277 ** Rename a single file.
278 **
279 ** The original name of the file is zOrig. The new filename is zNew.
280 */
281 static void mv_one_file(int vid, const char *zOrig, const char *zNew){
282 printf("RENAME %s %s\n", zOrig, zNew);
283

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button