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