Fossil SCM

Refactoring of the clean -x option, phase 1.

mistachkin 2013-05-28 10:32 UTC cleanDashN
Commit 0dc31f4bf79da046325ed3ef0fa82aefccb959c2
1 file changed +26 -20
+26 -20
--- src/checkin.c
+++ src/checkin.c
@@ -381,13 +381,16 @@
381381
** COMMAND: clean
382382
** Usage: %fossil clean ?OPTIONS?
383383
**
384384
** Delete all "extra" files in the source tree. "Extra" files are
385385
** files that are not officially part of the checkout. This operation
386
-** cannot be undone. Normally, only files unknown to fossil are
387
-** removed, but if the -x option is specified, ignored files are
388
-** removed as well.
386
+** cannot be undone.
387
+**
388
+** WARNING: Normally, only the files unknown to Fossil are removed;
389
+** however, if the -x option is specified, all files that are not part
390
+** of the current checkout will be removed as well, without regard for
391
+** the "ignore-glob" and "keep-glob" settings.
389392
**
390393
** You will be prompted before removing each eligible file unless the
391394
** --force flag is in use or it matches the --clean option. The
392395
** GLOBPATTERN specified by the "ignore-glob" setting is used if the
393396
** --ignore option is omitted, the same with "clean-glob" and --clean
@@ -401,23 +404,24 @@
401404
** normally kept. They are handled if the "--dotfiles" option
402405
** is used.
403406
**
404407
** Options:
405408
** --case-sensitive <BOOL> override case-sensitive setting
406
-** --dotfiles include files beginning with a dot (".")
407
-** -f|--force Remove files without prompting
408
-** --clean <CSG> never prompt for files matching this
409
-** comma separated list of glob patterns.
410
-** --ignore <CSG> ignore files matching patterns from the
411
-** comma separated list of glob patterns.
412
-** --keep <CSG> keep files matching this comma separated
413
-** list of glob patterns.
414
-** -n|--dry-run If given, display instead of run actions
415
-** --temp Remove only Fossil-generated temporary files
416
-** -v|--verbose Show all files as they are removed
417
-** -x Remove everything unkown to fossil,
418
-** including files matching --ignore.
409
+** --dotfiles Include files beginning with a dot (".").
410
+** -f|--force Remove files without prompting.
411
+** --clean <CSG> Never prompt for files matching this
412
+** comma separated list of glob patterns.
413
+** --ignore <CSG> Ignore files matching patterns from the
414
+** comma separated list of glob patterns.
415
+** --keep <CSG> Keep files matching this comma separated
416
+** list of glob patterns.
417
+** -n|--dry-run If given, display instead of run actions.
418
+** --temp Remove only Fossil-generated temporary files.
419
+** -v|--verbose Show all files as they are removed.
420
+** -x|--extreme Remove all files not part of the current
421
+** checkout, without taking into consideration
422
+** the "ignore-glob" and "keep-glob" settings.
419423
** Compatibile with "git clean -x".
420424
**
421425
** See also: addremove, extra, status
422426
*/
423427
void clean_cmd(void){
@@ -426,13 +430,15 @@
426430
const char *zIgnoreFlag, *zKeepFlag, *zCleanFlag;
427431
Blob path, repo;
428432
Stmt q;
429433
int n;
430434
Glob *pIgnore, *pKeep, *pClean;
435
+ int extremeFlag, dryRunFlag;
436
+ int verboseFlag;
431437
432438
dryRunFlag = find_option("dry-run","n",0)!=0;
433
- xFlag = find_option("x","x",0)!=0;
439
+ extremeFlag = find_option("extreme","x",0)!=0;
434440
if( !dryRunFlag ){
435441
dryRunFlag = find_option("test",0,0)!=0; /* deprecated */
436442
}
437443
allFlag = find_option("force","f",0)!=0 || dryRunFlag;
438444
if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL;
@@ -458,11 +464,12 @@
458464
n = strlen(g.zLocalRoot);
459465
blob_init(&path, g.zLocalRoot, n-1);
460466
pIgnore = glob_create(zIgnoreFlag);
461467
pKeep = glob_create(zKeepFlag);
462468
pClean = glob_create(zCleanFlag);
463
- vfile_scan2(&path, blob_size(&path), scanFlags, xFlag?0:pIgnore, pKeep);
469
+ vfile_scan2(&path, blob_size(&path), scanFlags,
470
+ extremeFlag ? 0 : pIgnore, pKeep);
464471
glob_free(pKeep);
465472
db_prepare(&q,
466473
"SELECT %Q || x FROM sfile"
467474
" WHERE x NOT IN (%s)"
468475
" ORDER BY 1",
@@ -472,12 +479,11 @@
472479
db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
473480
}
474481
db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)");
475482
while( db_step(&q)==SQLITE_ROW ){
476483
const char *zName = db_column_text(&q, 0);
477
- if( !allFlag && !glob_match(pClean, zName+n)
478
- && (!xFlag || !glob_match(pIgnore, zName+n))){
484
+ if( !allFlag && !dryRunFlag && !glob_match(pClean, zName+n) ){
479485
Blob ans;
480486
char cReply;
481487
char *prompt = mprintf("remove unmanaged file \"%s\" (a=all/y/N)? ",
482488
zName+n);
483489
blob_zero(&ans);
484490
--- src/checkin.c
+++ src/checkin.c
@@ -381,13 +381,16 @@
381 ** COMMAND: clean
382 ** Usage: %fossil clean ?OPTIONS?
383 **
384 ** Delete all "extra" files in the source tree. "Extra" files are
385 ** files that are not officially part of the checkout. This operation
386 ** cannot be undone. Normally, only files unknown to fossil are
387 ** removed, but if the -x option is specified, ignored files are
388 ** removed as well.
 
 
 
389 **
390 ** You will be prompted before removing each eligible file unless the
391 ** --force flag is in use or it matches the --clean option. The
392 ** GLOBPATTERN specified by the "ignore-glob" setting is used if the
393 ** --ignore option is omitted, the same with "clean-glob" and --clean
@@ -401,23 +404,24 @@
401 ** normally kept. They are handled if the "--dotfiles" option
402 ** is used.
403 **
404 ** Options:
405 ** --case-sensitive <BOOL> override case-sensitive setting
406 ** --dotfiles include files beginning with a dot (".")
407 ** -f|--force Remove files without prompting
408 ** --clean <CSG> never prompt for files matching this
409 ** comma separated list of glob patterns.
410 ** --ignore <CSG> ignore files matching patterns from the
411 ** comma separated list of glob patterns.
412 ** --keep <CSG> keep files matching this comma separated
413 ** list of glob patterns.
414 ** -n|--dry-run If given, display instead of run actions
415 ** --temp Remove only Fossil-generated temporary files
416 ** -v|--verbose Show all files as they are removed
417 ** -x Remove everything unkown to fossil,
418 ** including files matching --ignore.
 
419 ** Compatibile with "git clean -x".
420 **
421 ** See also: addremove, extra, status
422 */
423 void clean_cmd(void){
@@ -426,13 +430,15 @@
426 const char *zIgnoreFlag, *zKeepFlag, *zCleanFlag;
427 Blob path, repo;
428 Stmt q;
429 int n;
430 Glob *pIgnore, *pKeep, *pClean;
 
 
431
432 dryRunFlag = find_option("dry-run","n",0)!=0;
433 xFlag = find_option("x","x",0)!=0;
434 if( !dryRunFlag ){
435 dryRunFlag = find_option("test",0,0)!=0; /* deprecated */
436 }
437 allFlag = find_option("force","f",0)!=0 || dryRunFlag;
438 if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL;
@@ -458,11 +464,12 @@
458 n = strlen(g.zLocalRoot);
459 blob_init(&path, g.zLocalRoot, n-1);
460 pIgnore = glob_create(zIgnoreFlag);
461 pKeep = glob_create(zKeepFlag);
462 pClean = glob_create(zCleanFlag);
463 vfile_scan2(&path, blob_size(&path), scanFlags, xFlag?0:pIgnore, pKeep);
 
464 glob_free(pKeep);
465 db_prepare(&q,
466 "SELECT %Q || x FROM sfile"
467 " WHERE x NOT IN (%s)"
468 " ORDER BY 1",
@@ -472,12 +479,11 @@
472 db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
473 }
474 db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)");
475 while( db_step(&q)==SQLITE_ROW ){
476 const char *zName = db_column_text(&q, 0);
477 if( !allFlag && !glob_match(pClean, zName+n)
478 && (!xFlag || !glob_match(pIgnore, zName+n))){
479 Blob ans;
480 char cReply;
481 char *prompt = mprintf("remove unmanaged file \"%s\" (a=all/y/N)? ",
482 zName+n);
483 blob_zero(&ans);
484
--- src/checkin.c
+++ src/checkin.c
@@ -381,13 +381,16 @@
381 ** COMMAND: clean
382 ** Usage: %fossil clean ?OPTIONS?
383 **
384 ** Delete all "extra" files in the source tree. "Extra" files are
385 ** files that are not officially part of the checkout. This operation
386 ** cannot be undone.
387 **
388 ** WARNING: Normally, only the files unknown to Fossil are removed;
389 ** however, if the -x option is specified, all files that are not part
390 ** of the current checkout will be removed as well, without regard for
391 ** the "ignore-glob" and "keep-glob" settings.
392 **
393 ** You will be prompted before removing each eligible file unless the
394 ** --force flag is in use or it matches the --clean option. The
395 ** GLOBPATTERN specified by the "ignore-glob" setting is used if the
396 ** --ignore option is omitted, the same with "clean-glob" and --clean
@@ -401,23 +404,24 @@
404 ** normally kept. They are handled if the "--dotfiles" option
405 ** is used.
406 **
407 ** Options:
408 ** --case-sensitive <BOOL> override case-sensitive setting
409 ** --dotfiles Include files beginning with a dot (".").
410 ** -f|--force Remove files without prompting.
411 ** --clean <CSG> Never prompt for files matching this
412 ** comma separated list of glob patterns.
413 ** --ignore <CSG> Ignore files matching patterns from the
414 ** comma separated list of glob patterns.
415 ** --keep <CSG> Keep files matching this comma separated
416 ** list of glob patterns.
417 ** -n|--dry-run If given, display instead of run actions.
418 ** --temp Remove only Fossil-generated temporary files.
419 ** -v|--verbose Show all files as they are removed.
420 ** -x|--extreme Remove all files not part of the current
421 ** checkout, without taking into consideration
422 ** the "ignore-glob" and "keep-glob" settings.
423 ** Compatibile with "git clean -x".
424 **
425 ** See also: addremove, extra, status
426 */
427 void clean_cmd(void){
@@ -426,13 +430,15 @@
430 const char *zIgnoreFlag, *zKeepFlag, *zCleanFlag;
431 Blob path, repo;
432 Stmt q;
433 int n;
434 Glob *pIgnore, *pKeep, *pClean;
435 int extremeFlag, dryRunFlag;
436 int verboseFlag;
437
438 dryRunFlag = find_option("dry-run","n",0)!=0;
439 extremeFlag = find_option("extreme","x",0)!=0;
440 if( !dryRunFlag ){
441 dryRunFlag = find_option("test",0,0)!=0; /* deprecated */
442 }
443 allFlag = find_option("force","f",0)!=0 || dryRunFlag;
444 if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL;
@@ -458,11 +464,12 @@
464 n = strlen(g.zLocalRoot);
465 blob_init(&path, g.zLocalRoot, n-1);
466 pIgnore = glob_create(zIgnoreFlag);
467 pKeep = glob_create(zKeepFlag);
468 pClean = glob_create(zCleanFlag);
469 vfile_scan2(&path, blob_size(&path), scanFlags,
470 extremeFlag ? 0 : pIgnore, pKeep);
471 glob_free(pKeep);
472 db_prepare(&q,
473 "SELECT %Q || x FROM sfile"
474 " WHERE x NOT IN (%s)"
475 " ORDER BY 1",
@@ -472,12 +479,11 @@
479 db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
480 }
481 db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)");
482 while( db_step(&q)==SQLITE_ROW ){
483 const char *zName = db_column_text(&q, 0);
484 if( !allFlag && !dryRunFlag && !glob_match(pClean, zName+n) ){
 
485 Blob ans;
486 char cReply;
487 char *prompt = mprintf("remove unmanaged file \"%s\" (a=all/y/N)? ",
488 zName+n);
489 blob_zero(&ans);
490

Keyboard Shortcuts

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