Fossil SCM

Additional protection for fossil executables being removed by "fossil clean", even when using --ignore "". Add a warning when kept files are refused to be removed, don't keep this situation silent any more. Backport various improvements from cleanX branch: Use of capitals in messages, missing blob_reset() calls.

jan.nijtmans 2013-05-30 07:28 trunk
Commit 67c9cd12ad2ab631909d7d4e468ab1903f08021c
--- a/.fossil-settings/keep-glob
+++ b/.fossil-settings/keep-glob
@@ -0,0 +1,2 @@
1
+fossil
2
+fossil.exe
--- a/.fossil-settings/keep-glob
+++ b/.fossil-settings/keep-glob
@@ -0,0 +1,2 @@
 
 
--- a/.fossil-settings/keep-glob
+++ b/.fossil-settings/keep-glob
@@ -0,0 +1,2 @@
1 fossil
2 fossil.exe
+28 -24
--- src/checkin.c
+++ src/checkin.c
@@ -236,11 +236,11 @@
236236
int verboseFlag;
237237
int showAge;
238238
char *zOrderBy = "pathname";
239239
240240
verboseFlag = find_option("verbose","v", 0)!=0;
241
- if(!verboseFlag){
241
+ if( !verboseFlag ){
242242
verboseFlag = find_option("l","l", 0)!=0; /* deprecated */
243243
}
244244
showAge = find_option("age",0,0)!=0;
245245
db_must_be_within_tree();
246246
vid = db_lget_int("checkout", 0);
@@ -399,44 +399,42 @@
399399
** normally kept. They are handled if the "--dotfiles" option
400400
** is used.
401401
**
402402
** Options:
403403
** --case-sensitive <BOOL> override case-sensitive setting
404
-** --dotfiles include files beginning with a dot (".")
405
-** -f|--force Remove files without prompting
406
-** --clean <CSG> never prompt for files matching this
407
-** comma separated list of glob patterns.
408
-** --ignore <CSG> ignore files matching patterns from the
409
-** comma separated list of glob patterns.
410
-** --keep <CSG> keep files matching this comma separated
411
-** list of glob patterns.
412
-** -n|--dry-run If given, display instead of run actions
413
-** --temp Remove only Fossil-generated temporary files
414
-** -v|--verbose Show all files as they are removed
404
+** --dotfiles Include files beginning with a dot (".").
405
+** -f|--force Remove files without prompting.
406
+** --clean <CSG> Never prompt for files matching this
407
+** comma separated list of glob patterns.
408
+** --ignore <CSG> Ignore files matching patterns from the
409
+** comma separated list of glob patterns.
410
+** --keep <CSG> Keep files matching this comma separated
411
+** list of glob patterns.
412
+** -n|--dry-run If given, display instead of run actions.
413
+** --temp Remove only Fossil-generated temporary files.
414
+** -v|--verbose Show all files as they are removed.
415415
**
416416
** See also: addremove, extra, status
417417
*/
418418
void clean_cmd(void){
419
- int allFlag;
419
+ int allFlag, dryRunFlag, verboseFlag;
420420
unsigned scanFlags = 0;
421421
const char *zIgnoreFlag, *zKeepFlag, *zCleanFlag;
422422
Blob path, repo;
423423
Stmt q;
424424
int n;
425425
Glob *pIgnore, *pKeep, *pClean;
426
- int dryRunFlag = 0;
427
- int verboseFlag;
428426
427
+ dryRunFlag = find_option("dry-run","n",0)!=0;
428
+ if( !dryRunFlag ){
429
+ dryRunFlag = find_option("test",0,0)!=0; /* deprecated */
430
+ }
429431
allFlag = find_option("force","f",0)!=0;
430432
if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL;
431433
if( find_option("temp",0,0)!=0 ) scanFlags |= SCAN_TEMP;
432434
zIgnoreFlag = find_option("ignore",0,1);
433435
verboseFlag = find_option("verbose","v",0)!=0;
434
- dryRunFlag = find_option("dry-run","n",0)!=0;
435
- if( !dryRunFlag ){
436
- dryRunFlag = find_option("test",0,0)!=0; /* deprecated */
437
- }
438436
zKeepFlag = find_option("keep",0,1);
439437
zCleanFlag = find_option("clean",0,1);
440438
capture_case_sensitive_option();
441439
db_must_be_within_tree();
442440
if( zIgnoreFlag==0 ){
@@ -454,12 +452,11 @@
454452
n = strlen(g.zLocalRoot);
455453
blob_init(&path, g.zLocalRoot, n-1);
456454
pIgnore = glob_create(zIgnoreFlag);
457455
pKeep = glob_create(zKeepFlag);
458456
pClean = glob_create(zCleanFlag);
459
- vfile_scan2(&path, blob_size(&path), scanFlags, pIgnore, pKeep);
460
- glob_free(pKeep);
457
+ vfile_scan(&path, blob_size(&path), scanFlags, pIgnore);
461458
glob_free(pIgnore);
462459
db_prepare(&q,
463460
"SELECT %Q || x FROM sfile"
464461
" WHERE x NOT IN (%s)"
465462
" ORDER BY 1",
@@ -469,32 +466,39 @@
469466
db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
470467
}
471468
db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)");
472469
while( db_step(&q)==SQLITE_ROW ){
473470
const char *zName = db_column_text(&q, 0);
471
+ if( glob_match(pKeep, zName+n) ){
472
+ fossil_print("WARNING: KEPT file \"%s\" not removed\n");
473
+ continue;
474
+ }
474475
if( !allFlag && !dryRunFlag && !glob_match(pClean, zName+n) ){
475476
Blob ans;
476477
char cReply;
477
- char *prompt = mprintf("remove unmanaged file \"%s\" (a=all/y/N)? ",
478
+ char *prompt = mprintf("Remove unmanaged file \"%s\" (a=all/y/N)? ",
478479
zName+n);
479480
blob_zero(&ans);
480481
prompt_user(prompt, &ans);
481482
cReply = blob_str(&ans)[0];
482483
if( cReply=='a' || cReply=='A' ){
483484
allFlag = 1;
484485
}else if( cReply!='y' && cReply!='Y' ){
486
+ blob_reset(&ans);
485487
continue;
486488
}
489
+ blob_reset(&ans);
487490
}
488
- if( dryRunFlag || verboseFlag ){
489
- fossil_print("removed unmanaged file: %s\n", zName+n);
491
+ if( verboseFlag || dryRunFlag ){
492
+ fossil_print("Removed unmanaged file: %s\n", zName+n);
490493
}
491494
if( !dryRunFlag ){
492495
file_delete(zName);
493496
}
494497
}
495498
glob_free(pClean);
499
+ glob_free(pKeep);
496500
db_finalize(&q);
497501
}
498502
499503
/*
500504
** Prompt the user for a check-in or stash comment (given in pPrompt),
501505
--- src/checkin.c
+++ src/checkin.c
@@ -236,11 +236,11 @@
236 int verboseFlag;
237 int showAge;
238 char *zOrderBy = "pathname";
239
240 verboseFlag = find_option("verbose","v", 0)!=0;
241 if(!verboseFlag){
242 verboseFlag = find_option("l","l", 0)!=0; /* deprecated */
243 }
244 showAge = find_option("age",0,0)!=0;
245 db_must_be_within_tree();
246 vid = db_lget_int("checkout", 0);
@@ -399,44 +399,42 @@
399 ** normally kept. They are handled if the "--dotfiles" option
400 ** is used.
401 **
402 ** Options:
403 ** --case-sensitive <BOOL> override case-sensitive setting
404 ** --dotfiles include files beginning with a dot (".")
405 ** -f|--force Remove files without prompting
406 ** --clean <CSG> never prompt for files matching this
407 ** comma separated list of glob patterns.
408 ** --ignore <CSG> ignore files matching patterns from the
409 ** comma separated list of glob patterns.
410 ** --keep <CSG> keep files matching this comma separated
411 ** list of glob patterns.
412 ** -n|--dry-run If given, display instead of run actions
413 ** --temp Remove only Fossil-generated temporary files
414 ** -v|--verbose Show all files as they are removed
415 **
416 ** See also: addremove, extra, status
417 */
418 void clean_cmd(void){
419 int allFlag;
420 unsigned scanFlags = 0;
421 const char *zIgnoreFlag, *zKeepFlag, *zCleanFlag;
422 Blob path, repo;
423 Stmt q;
424 int n;
425 Glob *pIgnore, *pKeep, *pClean;
426 int dryRunFlag = 0;
427 int verboseFlag;
428
 
 
 
 
429 allFlag = find_option("force","f",0)!=0;
430 if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL;
431 if( find_option("temp",0,0)!=0 ) scanFlags |= SCAN_TEMP;
432 zIgnoreFlag = find_option("ignore",0,1);
433 verboseFlag = find_option("verbose","v",0)!=0;
434 dryRunFlag = find_option("dry-run","n",0)!=0;
435 if( !dryRunFlag ){
436 dryRunFlag = find_option("test",0,0)!=0; /* deprecated */
437 }
438 zKeepFlag = find_option("keep",0,1);
439 zCleanFlag = find_option("clean",0,1);
440 capture_case_sensitive_option();
441 db_must_be_within_tree();
442 if( zIgnoreFlag==0 ){
@@ -454,12 +452,11 @@
454 n = strlen(g.zLocalRoot);
455 blob_init(&path, g.zLocalRoot, n-1);
456 pIgnore = glob_create(zIgnoreFlag);
457 pKeep = glob_create(zKeepFlag);
458 pClean = glob_create(zCleanFlag);
459 vfile_scan2(&path, blob_size(&path), scanFlags, pIgnore, pKeep);
460 glob_free(pKeep);
461 glob_free(pIgnore);
462 db_prepare(&q,
463 "SELECT %Q || x FROM sfile"
464 " WHERE x NOT IN (%s)"
465 " ORDER BY 1",
@@ -469,32 +466,39 @@
469 db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
470 }
471 db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)");
472 while( db_step(&q)==SQLITE_ROW ){
473 const char *zName = db_column_text(&q, 0);
 
 
 
 
474 if( !allFlag && !dryRunFlag && !glob_match(pClean, zName+n) ){
475 Blob ans;
476 char cReply;
477 char *prompt = mprintf("remove unmanaged file \"%s\" (a=all/y/N)? ",
478 zName+n);
479 blob_zero(&ans);
480 prompt_user(prompt, &ans);
481 cReply = blob_str(&ans)[0];
482 if( cReply=='a' || cReply=='A' ){
483 allFlag = 1;
484 }else if( cReply!='y' && cReply!='Y' ){
 
485 continue;
486 }
 
487 }
488 if( dryRunFlag || verboseFlag ){
489 fossil_print("removed unmanaged file: %s\n", zName+n);
490 }
491 if( !dryRunFlag ){
492 file_delete(zName);
493 }
494 }
495 glob_free(pClean);
 
496 db_finalize(&q);
497 }
498
499 /*
500 ** Prompt the user for a check-in or stash comment (given in pPrompt),
501
--- src/checkin.c
+++ src/checkin.c
@@ -236,11 +236,11 @@
236 int verboseFlag;
237 int showAge;
238 char *zOrderBy = "pathname";
239
240 verboseFlag = find_option("verbose","v", 0)!=0;
241 if( !verboseFlag ){
242 verboseFlag = find_option("l","l", 0)!=0; /* deprecated */
243 }
244 showAge = find_option("age",0,0)!=0;
245 db_must_be_within_tree();
246 vid = db_lget_int("checkout", 0);
@@ -399,44 +399,42 @@
399 ** normally kept. They are handled if the "--dotfiles" option
400 ** is used.
401 **
402 ** Options:
403 ** --case-sensitive <BOOL> override case-sensitive setting
404 ** --dotfiles Include files beginning with a dot (".").
405 ** -f|--force Remove files without prompting.
406 ** --clean <CSG> Never prompt for files matching this
407 ** comma separated list of glob patterns.
408 ** --ignore <CSG> Ignore files matching patterns from the
409 ** comma separated list of glob patterns.
410 ** --keep <CSG> Keep files matching this comma separated
411 ** list of glob patterns.
412 ** -n|--dry-run If given, display instead of run actions.
413 ** --temp Remove only Fossil-generated temporary files.
414 ** -v|--verbose Show all files as they are removed.
415 **
416 ** See also: addremove, extra, status
417 */
418 void clean_cmd(void){
419 int allFlag, dryRunFlag, verboseFlag;
420 unsigned scanFlags = 0;
421 const char *zIgnoreFlag, *zKeepFlag, *zCleanFlag;
422 Blob path, repo;
423 Stmt q;
424 int n;
425 Glob *pIgnore, *pKeep, *pClean;
 
 
426
427 dryRunFlag = find_option("dry-run","n",0)!=0;
428 if( !dryRunFlag ){
429 dryRunFlag = find_option("test",0,0)!=0; /* deprecated */
430 }
431 allFlag = find_option("force","f",0)!=0;
432 if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL;
433 if( find_option("temp",0,0)!=0 ) scanFlags |= SCAN_TEMP;
434 zIgnoreFlag = find_option("ignore",0,1);
435 verboseFlag = find_option("verbose","v",0)!=0;
 
 
 
 
436 zKeepFlag = find_option("keep",0,1);
437 zCleanFlag = find_option("clean",0,1);
438 capture_case_sensitive_option();
439 db_must_be_within_tree();
440 if( zIgnoreFlag==0 ){
@@ -454,12 +452,11 @@
452 n = strlen(g.zLocalRoot);
453 blob_init(&path, g.zLocalRoot, n-1);
454 pIgnore = glob_create(zIgnoreFlag);
455 pKeep = glob_create(zKeepFlag);
456 pClean = glob_create(zCleanFlag);
457 vfile_scan(&path, blob_size(&path), scanFlags, pIgnore);
 
458 glob_free(pIgnore);
459 db_prepare(&q,
460 "SELECT %Q || x FROM sfile"
461 " WHERE x NOT IN (%s)"
462 " ORDER BY 1",
@@ -469,32 +466,39 @@
466 db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
467 }
468 db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)");
469 while( db_step(&q)==SQLITE_ROW ){
470 const char *zName = db_column_text(&q, 0);
471 if( glob_match(pKeep, zName+n) ){
472 fossil_print("WARNING: KEPT file \"%s\" not removed\n");
473 continue;
474 }
475 if( !allFlag && !dryRunFlag && !glob_match(pClean, zName+n) ){
476 Blob ans;
477 char cReply;
478 char *prompt = mprintf("Remove unmanaged file \"%s\" (a=all/y/N)? ",
479 zName+n);
480 blob_zero(&ans);
481 prompt_user(prompt, &ans);
482 cReply = blob_str(&ans)[0];
483 if( cReply=='a' || cReply=='A' ){
484 allFlag = 1;
485 }else if( cReply!='y' && cReply!='Y' ){
486 blob_reset(&ans);
487 continue;
488 }
489 blob_reset(&ans);
490 }
491 if( verboseFlag || dryRunFlag ){
492 fossil_print("Removed unmanaged file: %s\n", zName+n);
493 }
494 if( !dryRunFlag ){
495 file_delete(zName);
496 }
497 }
498 glob_free(pClean);
499 glob_free(pKeep);
500 db_finalize(&q);
501 }
502
503 /*
504 ** Prompt the user for a check-in or stash comment (given in pPrompt),
505

Keyboard Shortcuts

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