Fossil SCM
Refactoring of the clean -x option, phase 1.
Commit
0dc31f4bf79da046325ed3ef0fa82aefccb959c2
Parent
7f0507c04da883b…
1 file changed
+26
-20
+26
-20
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -381,13 +381,16 @@ | ||
| 381 | 381 | ** COMMAND: clean |
| 382 | 382 | ** Usage: %fossil clean ?OPTIONS? |
| 383 | 383 | ** |
| 384 | 384 | ** Delete all "extra" files in the source tree. "Extra" files are |
| 385 | 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. | |
| 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. | |
| 389 | 392 | ** |
| 390 | 393 | ** You will be prompted before removing each eligible file unless the |
| 391 | 394 | ** --force flag is in use or it matches the --clean option. The |
| 392 | 395 | ** GLOBPATTERN specified by the "ignore-glob" setting is used if the |
| 393 | 396 | ** --ignore option is omitted, the same with "clean-glob" and --clean |
| @@ -401,23 +404,24 @@ | ||
| 401 | 404 | ** normally kept. They are handled if the "--dotfiles" option |
| 402 | 405 | ** is used. |
| 403 | 406 | ** |
| 404 | 407 | ** Options: |
| 405 | 408 | ** --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. | |
| 419 | 423 | ** Compatibile with "git clean -x". |
| 420 | 424 | ** |
| 421 | 425 | ** See also: addremove, extra, status |
| 422 | 426 | */ |
| 423 | 427 | void clean_cmd(void){ |
| @@ -426,13 +430,15 @@ | ||
| 426 | 430 | const char *zIgnoreFlag, *zKeepFlag, *zCleanFlag; |
| 427 | 431 | Blob path, repo; |
| 428 | 432 | Stmt q; |
| 429 | 433 | int n; |
| 430 | 434 | Glob *pIgnore, *pKeep, *pClean; |
| 435 | + int extremeFlag, dryRunFlag; | |
| 436 | + int verboseFlag; | |
| 431 | 437 | |
| 432 | 438 | dryRunFlag = find_option("dry-run","n",0)!=0; |
| 433 | - xFlag = find_option("x","x",0)!=0; | |
| 439 | + extremeFlag = find_option("extreme","x",0)!=0; | |
| 434 | 440 | if( !dryRunFlag ){ |
| 435 | 441 | dryRunFlag = find_option("test",0,0)!=0; /* deprecated */ |
| 436 | 442 | } |
| 437 | 443 | allFlag = find_option("force","f",0)!=0 || dryRunFlag; |
| 438 | 444 | if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL; |
| @@ -458,11 +464,12 @@ | ||
| 458 | 464 | n = strlen(g.zLocalRoot); |
| 459 | 465 | blob_init(&path, g.zLocalRoot, n-1); |
| 460 | 466 | pIgnore = glob_create(zIgnoreFlag); |
| 461 | 467 | pKeep = glob_create(zKeepFlag); |
| 462 | 468 | 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); | |
| 464 | 471 | glob_free(pKeep); |
| 465 | 472 | db_prepare(&q, |
| 466 | 473 | "SELECT %Q || x FROM sfile" |
| 467 | 474 | " WHERE x NOT IN (%s)" |
| 468 | 475 | " ORDER BY 1", |
| @@ -472,12 +479,11 @@ | ||
| 472 | 479 | db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo); |
| 473 | 480 | } |
| 474 | 481 | db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)"); |
| 475 | 482 | while( db_step(&q)==SQLITE_ROW ){ |
| 476 | 483 | 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) ){ | |
| 479 | 485 | Blob ans; |
| 480 | 486 | char cReply; |
| 481 | 487 | char *prompt = mprintf("remove unmanaged file \"%s\" (a=all/y/N)? ", |
| 482 | 488 | zName+n); |
| 483 | 489 | blob_zero(&ans); |
| 484 | 490 |
| --- 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 |