| | @@ -380,28 +380,31 @@ |
| 380 | 380 | ** |
| 381 | 381 | ** Delete all "extra" files in the source tree. "Extra" files are |
| 382 | 382 | ** files that are not officially part of the checkout. This operation |
| 383 | 383 | ** cannot be undone. |
| 384 | 384 | ** |
| 385 | | -** You will be prompted before removing each file, except for files |
| 386 | | -** matching the patterns specified with --ignore and --keep. The GLOBPATTERN |
| 387 | | -** specified by the "ignore-glob" setting is used if the --ignore |
| 388 | | -** option is omitted, the same with "keep-glob" and --keep. If you are |
| 389 | | -** sure you wish to remove all "extra" files except the ones specified |
| 390 | | -** with --keep, you can specify the optional -f|--force flag and no prompts |
| 391 | | -** will be issued. If any file matches both --keep and --ignore, --keep |
| 392 | | -** takes precedence. |
| 385 | +** You will be prompted before removing each eligible file unless the |
| 386 | +** --force flag is in use or it matches the --clean option. The |
| 387 | +** GLOBPATTERN specified by the "ignore-glob" setting is used if the |
| 388 | +** --ignore option is omitted, the same with "clean-glob" and --clean |
| 389 | +** as well as "keep-glob" and --keep. If you are sure you wish to |
| 390 | +** remove all "extra" files except the ones specified with --ignore |
| 391 | +** and --keep, you can specify the optional -f|--force flag and no |
| 392 | +** prompts will be issued. If a file matches both --keep and --clean, |
| 393 | +** --keep takes precedence. |
| 393 | 394 | ** |
| 394 | 395 | ** Files and subdirectories whose names begin with "." are |
| 395 | 396 | ** normally kept. They are handled if the "--dotfiles" option |
| 396 | 397 | ** is used. |
| 397 | 398 | ** |
| 398 | 399 | ** Options: |
| 399 | 400 | ** --case-sensitive <BOOL> override case-sensitive setting |
| 400 | 401 | ** --dotfiles include files beginning with a dot (".") |
| 401 | 402 | ** -f|--force Remove files without prompting |
| 402 | | -** --ignore <CSG> don't prompt for files matching this |
| 403 | +** --clean <CSG> never prompt for files matching this |
| 404 | +** comma separated list of glob patterns. |
| 405 | +** --ignore <CSG> ignore files matching patterns from the |
| 403 | 406 | ** comma separated list of glob patterns. |
| 404 | 407 | ** --keep <CSG> keep files matching this comma separated |
| 405 | 408 | ** list of glob patterns. |
| 406 | 409 | ** -n|--dry-run If given, display instead of run actions |
| 407 | 410 | ** --temp Remove only Fossil-generated temporary files |
| | @@ -409,15 +412,15 @@ |
| 409 | 412 | ** See also: addremove, extra, status |
| 410 | 413 | */ |
| 411 | 414 | void clean_cmd(void){ |
| 412 | 415 | int allFlag; |
| 413 | 416 | unsigned scanFlags = 0; |
| 414 | | - const char *zIgnoreFlag, *zKeepFlag; |
| 417 | + const char *zIgnoreFlag, *zKeepFlag, *zCleanFlag; |
| 415 | 418 | Blob path, repo; |
| 416 | 419 | Stmt q; |
| 417 | 420 | int n; |
| 418 | | - Glob *pIgnore, *pKeep; |
| 421 | + Glob *pIgnore, *pKeep, *pClean; |
| 419 | 422 | int dryRunFlag = 0; |
| 420 | 423 | |
| 421 | 424 | allFlag = find_option("force","f",0)!=0; |
| 422 | 425 | if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL; |
| 423 | 426 | if( find_option("temp",0,0)!=0 ) scanFlags |= SCAN_TEMP; |
| | @@ -425,24 +428,29 @@ |
| 425 | 428 | dryRunFlag = find_option("dry-run","n",0)!=0; |
| 426 | 429 | if( !dryRunFlag ){ |
| 427 | 430 | dryRunFlag = find_option("test",0,0)!=0; /* deprecated */ |
| 428 | 431 | } |
| 429 | 432 | zKeepFlag = find_option("keep",0,1); |
| 433 | + zCleanFlag = find_option("clean",0,1); |
| 430 | 434 | capture_case_sensitive_option(); |
| 431 | 435 | db_must_be_within_tree(); |
| 432 | 436 | if( zIgnoreFlag==0 ){ |
| 433 | 437 | zIgnoreFlag = db_get("ignore-glob", 0); |
| 434 | 438 | } |
| 435 | 439 | if( zKeepFlag==0 ){ |
| 436 | 440 | zKeepFlag = db_get("keep-glob", 0); |
| 437 | 441 | } |
| 442 | + if( zCleanFlag==0 ){ |
| 443 | + zCleanFlag = db_get("clean-glob", 0); |
| 444 | + } |
| 438 | 445 | db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY %s)", |
| 439 | 446 | filename_collation()); |
| 440 | 447 | n = strlen(g.zLocalRoot); |
| 441 | 448 | blob_init(&path, g.zLocalRoot, n-1); |
| 442 | 449 | pIgnore = glob_create(zIgnoreFlag); |
| 443 | 450 | pKeep = glob_create(zKeepFlag); |
| 451 | + pClean = glob_create(zCleanFlag); |
| 444 | 452 | vfile_scan(&path, blob_size(&path), scanFlags, pKeep); |
| 445 | 453 | glob_free(pKeep); |
| 446 | 454 | db_prepare(&q, |
| 447 | 455 | "SELECT %Q || x FROM sfile" |
| 448 | 456 | " WHERE x NOT IN (%s)" |
| | @@ -453,18 +461,16 @@ |
| 453 | 461 | db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo); |
| 454 | 462 | } |
| 455 | 463 | db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)"); |
| 456 | 464 | while( db_step(&q)==SQLITE_ROW ){ |
| 457 | 465 | const char *zName = db_column_text(&q, 0); |
| 458 | | - if( dryRunFlag ){ |
| 459 | | - fossil_print("%s\n", db_column_text(&q,0)); |
| 460 | | - continue; |
| 461 | | - }else if( !allFlag && !glob_match(pIgnore, zName+n) ){ |
| 466 | + if( glob_match(pIgnore, zName+n) ) continue; |
| 467 | + if( !allFlag && !glob_match(pClean, zName+n) ){ |
| 462 | 468 | Blob ans; |
| 463 | 469 | char cReply; |
| 464 | 470 | char *prompt = mprintf("remove unmanaged file \"%s\" (a=all/y/N)? ", |
| 465 | | - zName+n); |
| 471 | + zName+n); |
| 466 | 472 | blob_zero(&ans); |
| 467 | 473 | prompt_user(prompt, &ans); |
| 468 | 474 | cReply = blob_str(&ans)[0]; |
| 469 | 475 | if( cReply=='a' || cReply=='A' ){ |
| 470 | 476 | allFlag = 1; |
| | @@ -471,12 +477,15 @@ |
| 471 | 477 | }else if( cReply!='y' && cReply!='Y' ){ |
| 472 | 478 | continue; |
| 473 | 479 | } |
| 474 | 480 | } |
| 475 | 481 | fossil_print("removed unmanaged file \"%s\"\n", zName+n); |
| 476 | | - file_delete(zName); |
| 482 | + if( !dryRunFlag ){ |
| 483 | + file_delete(zName); |
| 484 | + } |
| 477 | 485 | } |
| 486 | + glob_free(pClean); |
| 478 | 487 | glob_free(pIgnore); |
| 479 | 488 | db_finalize(&q); |
| 480 | 489 | } |
| 481 | 490 | |
| 482 | 491 | /* |
| 483 | 492 | |