Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Add --emptydirs option to the 'clean' command to remove empty directories. Corrections to style and comments. Remove superfluous local variable zDir in vfile_scan. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | cleanEmptyDirs |
| Files: | files | file ages | folders |
| SHA1: |
8f1e1ee8fbbe7625cfc2836de034200d |
| User & Date: | mistachkin 2013-09-30 11:45:35.474 |
Context
|
2013-09-30
| ||
| 12:16 | Add the --dirsonly and --allckouts options to the 'clean' command. check-in: 51403ee52e user: mistachkin tags: cleanEmptyDirs | |
| 11:45 | Add --emptydirs option to the 'clean' command to remove empty directories. Corrections to style and comments. Remove superfluous local variable zDir in vfile_scan. check-in: 8f1e1ee8fb user: mistachkin tags: cleanEmptyDirs | |
| 11:39 | Silence harmless compiler warning. check-in: 16113accff user: mistachkin tags: trunk | |
Changes
Changes to src/checkin.c.
| ︙ | ︙ | |||
361 362 363 364 365 366 367 |
}
free(zFullName);
}
db_finalize(&q);
}
/*
| | | > | | | | | | | | | | | | | 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
}
free(zFullName);
}
db_finalize(&q);
}
/*
** Create a TEMP table named SFILE and add all unmanaged files named on
** the command-line to that table. If directories are named, then add
** all unmanaged files contained underneath those directories. If there
** are no files or directories named on the command-line, then add all
** unmanaged files anywhere in the checkout.
*/
static void locate_unmanaged_files(
int argc, /* Number of command-line arguments to examine */
char **argv, /* values of command-line arguments */
unsigned scanFlags, /* Zero or more SCAN_xxx flags */
Glob *pIgnore1, /* Do not add files that match this GLOB */
Glob *pIgnore2 /* Omit files matching this GLOB too */
){
Blob name; /* Name of a candidate file or directory */
char *zName; /* Name of a candidate file or directory */
int isDir; /* 1 for a directory, 0 if doesn't exist, 2 for anything else */
int i; /* Loop counter */
int nRoot; /* length of g.zLocalRoot */
db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY %s)",
filename_collation());
nRoot = (int)strlen(g.zLocalRoot);
if( argc==0 ){
blob_init(&name, g.zLocalRoot, nRoot - 1);
vfile_scan(&name, blob_size(&name), scanFlags, pIgnore1, pIgnore2);
|
| ︙ | ︙ | |||
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 |
** Files and subdirectories whose names begin with "." are
** normally kept. They are handled if the "--dotfiles" option
** is used.
**
** Options:
** --case-sensitive <BOOL> override case-sensitive setting
** --dotfiles Include files beginning with a dot (".").
** -f|--force Remove files without prompting.
** --clean <CSG> Never prompt for files matching this
** comma separated list of glob patterns.
** --ignore <CSG> Ignore files matching patterns from the
** comma separated list of glob patterns.
** --keep <CSG> Keep files matching this comma separated
** list of glob patterns.
** -n|--dry-run If given, display instead of run actions.
** --temp Remove only Fossil-generated temporary files.
** -v|--verbose Show all files as they are removed.
**
** See also: addremove, extra, status
*/
void clean_cmd(void){
| > > > > > > > | | > | 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 |
** Files and subdirectories whose names begin with "." are
** normally kept. They are handled if the "--dotfiles" option
** is used.
**
** Options:
** --case-sensitive <BOOL> override case-sensitive setting
** --dotfiles Include files beginning with a dot (".").
** --emptydirs Remove any empty directories that are not
** explicitly exempted via the empty-dirs setting
** or another applicable setting or command line
** argument. Matching files, if any, are removed
** prior to checking for any empty directories;
** therefore, directories that contain only files
** that were removed will be removed as well.
** -f|--force Remove files without prompting.
** --clean <CSG> Never prompt for files matching this
** comma separated list of glob patterns.
** --ignore <CSG> Ignore files matching patterns from the
** comma separated list of glob patterns.
** --keep <CSG> Keep files matching this comma separated
** list of glob patterns.
** -n|--dry-run If given, display instead of run actions.
** --temp Remove only Fossil-generated temporary files.
** -v|--verbose Show all files as they are removed.
**
** See also: addremove, extra, status
*/
void clean_cmd(void){
int allFileFlag, allDirFlag, dryRunFlag, emptyDirsFlag, verboseFlag;
unsigned scanFlags = 0;
const char *zIgnoreFlag, *zKeepFlag, *zCleanFlag;
Blob repo;
Stmt q;
Glob *pIgnore, *pKeep, *pClean;
int nRoot;
dryRunFlag = find_option("dry-run","n",0)!=0;
if( !dryRunFlag ){
dryRunFlag = find_option("test",0,0)!=0; /* deprecated */
}
allFileFlag = allDirFlag = find_option("force","f",0)!=0;
emptyDirsFlag = find_option("emptydirs","d",0)!=0;
if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL;
if( find_option("temp",0,0)!=0 ) scanFlags |= SCAN_TEMP;
zIgnoreFlag = find_option("ignore",0,1);
verboseFlag = find_option("verbose","v",0)!=0;
zKeepFlag = find_option("keep",0,1);
zCleanFlag = find_option("clean",0,1);
capture_case_sensitive_option();
|
| ︙ | ︙ | |||
555 556 557 558 559 560 561 |
zCleanFlag = db_get("clean-glob", 0);
}
verify_all_options();
pIgnore = glob_create(zIgnoreFlag);
pKeep = glob_create(zKeepFlag);
pClean = glob_create(zCleanFlag);
locate_unmanaged_files(g.argc-2, g.argv+2, scanFlags, pIgnore, pKeep);
| < < | | > | | | > > > > | > > > > > > > > > > > > > > > > > > > | > > > > > > > > | > | > > > > > > > > > > > > | 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 |
zCleanFlag = db_get("clean-glob", 0);
}
verify_all_options();
pIgnore = glob_create(zIgnoreFlag);
pKeep = glob_create(zKeepFlag);
pClean = glob_create(zCleanFlag);
locate_unmanaged_files(g.argc-2, g.argv+2, scanFlags, pIgnore, pKeep);
db_prepare(&q,
"SELECT %Q || x FROM sfile"
" WHERE x NOT IN (%s)"
" ORDER BY 1",
g.zLocalRoot, fossil_all_reserved_names(0)
);
if( file_tree_name(g.zRepositoryName, &repo, 0) ){
db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
}
db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)");
nRoot = (int)strlen(g.zLocalRoot);
while( db_step(&q)==SQLITE_ROW ){
const char *zName = db_column_text(&q, 0);
if( !allFileFlag && !dryRunFlag && !glob_match(pClean, zName+nRoot) ){
Blob ans;
char cReply;
char *prompt = mprintf("Remove unmanaged file \"%s\" (a=all/y/N)? ",
zName+nRoot);
blob_zero(&ans);
prompt_user(prompt, &ans);
cReply = blob_str(&ans)[0];
if( cReply=='a' || cReply=='A' ){
allFileFlag = 1;
}else if( cReply!='y' && cReply!='Y' ){
blob_reset(&ans);
continue;
}
blob_reset(&ans);
}
if ( dryRunFlag || file_delete(zName)==0 ){
if( verboseFlag || dryRunFlag ){
fossil_print("Removed unmanaged file: %s\n", zName+nRoot);
}
}else if( verboseFlag ){
fossil_print("Could not remove file: %s\n", zName+nRoot);
}
}
if( emptyDirsFlag ){
Glob *pEmptyDirs = glob_create(db_get("empty-dirs", 0));
Blob root;
blob_init(&root, g.zLocalRoot, nRoot - 1);
vfile_dir_scan(&root, blob_size(&root), scanFlags, pIgnore, pKeep,
pEmptyDirs);
blob_reset(&root);
db_finalize(&q);
db_prepare(&q,
"SELECT %Q || x FROM dscan_temp"
" WHERE x NOT IN (%s) AND y = 0"
" ORDER BY 1 DESC",
g.zLocalRoot, fossil_all_reserved_names(0)
);
while( db_step(&q)==SQLITE_ROW ){
const char *zName = db_column_text(&q, 0);
if( !allDirFlag && !dryRunFlag && !glob_match(pClean, zName+nRoot) ){
Blob ans;
char cReply;
char *prompt = mprintf("Remove empty directory \"%s\" (a=all/y/N)? ",
zName+nRoot);
blob_zero(&ans);
prompt_user(prompt, &ans);
cReply = blob_str(&ans)[0];
if( cReply=='a' || cReply=='A' ){
allDirFlag = 1;
}else if( cReply!='y' && cReply!='Y' ){
blob_reset(&ans);
continue;
}
blob_reset(&ans);
}
if ( dryRunFlag || file_rmdir(zName)==0 ){
if( verboseFlag || dryRunFlag ){
fossil_print("Removed unmanaged directory: %s\n", zName+nRoot);
}
}else if( verboseFlag ){
fossil_print("Could not remove directory: %s\n", zName+nRoot);
}
}
glob_free(pEmptyDirs);
}
glob_free(pClean);
glob_free(pKeep);
glob_free(pIgnore);
db_finalize(&q);
}
/*
** Prompt the user for a check-in or stash comment (given in pPrompt),
** gather the response, then return the response in pComment.
**
|
| ︙ | ︙ |
Changes to src/file.c.
| ︙ | ︙ | |||
459 460 461 462 463 464 465 466 |
iMTime = file_wd_mtime(zFile);
zDate = db_text(0, "SELECT datetime(%lld, 'unixepoch')", iMTime);
fossil_print("Set mtime of \"%s\" to %s (%lld)\n", zFile, zDate, iMTime);
}
/*
** Delete a file.
*/
| > > | > | | > | 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 |
iMTime = file_wd_mtime(zFile);
zDate = db_text(0, "SELECT datetime(%lld, 'unixepoch')", iMTime);
fossil_print("Set mtime of \"%s\" to %s (%lld)\n", zFile, zDate, iMTime);
}
/*
** Delete a file.
**
** Returns zero upon success.
*/
int file_delete(const char *zFilename){
int rc;
#ifdef _WIN32
wchar_t *z = fossil_utf8_to_filename(zFilename);
rc = _wunlink(z);
#else
char *z = fossil_utf8_to_filename(zFilename);
rc = unlink(zFilename);
#endif
fossil_filename_free(z);
return rc;
}
/*
** Create the directory named in the argument, if it does not already
** exist. If forceFlag is 1, delete any prior non-directory object
** with the same name.
**
|
| ︙ | ︙ | |||
491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
if( rc!=1 ){
#if defined(_WIN32)
wchar_t *zMbcs = fossil_utf8_to_filename(zName);
rc = _wmkdir(zMbcs);
#else
char *zMbcs = fossil_utf8_to_filename(zName);
rc = mkdir(zName, 0755);
#endif
fossil_filename_free(zMbcs);
return rc;
}
return 0;
}
| > > > > > > > > > > > > > > > > > > > > > > > | 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 |
if( rc!=1 ){
#if defined(_WIN32)
wchar_t *zMbcs = fossil_utf8_to_filename(zName);
rc = _wmkdir(zMbcs);
#else
char *zMbcs = fossil_utf8_to_filename(zName);
rc = mkdir(zName, 0755);
#endif
fossil_filename_free(zMbcs);
return rc;
}
return 0;
}
/*
** Removes the directory named in the argument, if it exists. The directory
** must be empty and cannot be the current directory or the root directory.
**
** Returns zero upon success.
*/
int file_rmdir(const char *zName){
int rc = file_wd_isdir(zName);
if( rc==2 ) return 1; /* cannot remove normal file */
if( rc==1 ){
#if defined(_WIN32)
wchar_t *zMbcs = fossil_utf8_to_filename(zName);
rc = _wrmdir(zMbcs);
#else
char *zMbcs = fossil_utf8_to_filename(zName);
rc = rmdir(zName);
#endif
fossil_filename_free(zMbcs);
return rc;
}
return 0;
}
|
| ︙ | ︙ |
Changes to src/vfile.c.
| ︙ | ︙ | |||
426 427 428 429 430 431 432 | ** Load into table SFILE the name of every ordinary file in ** the directory pPath. Omit the first nPrefix characters of ** of pPath when inserting into the SFILE table. ** ** Subdirectories are scanned recursively. ** Omit files named in VFILE. ** | | > | | | < | 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
** Load into table SFILE the name of every ordinary file in
** the directory pPath. Omit the first nPrefix characters of
** of pPath when inserting into the SFILE table.
**
** Subdirectories are scanned recursively.
** Omit files named in VFILE.
**
** Files whose names begin with "." are omitted unless the SCAN_ALL
** flag is set.
**
** Any files or directories that match the glob patterns pIgnore*
** are excluded from the scan. Name matching occurs after the
** first nPrefix characters are elided from the filename.
*/
void vfile_scan(
Blob *pPath, /* Directory to be scanned */
int nPrefix, /* Number of bytes in directory name */
unsigned scanFlags, /* Zero or more SCAN_xxx flags */
Glob *pIgnore1, /* Do not add files that match this GLOB */
Glob *pIgnore2 /* Omit files matching this GLOB too */
){
DIR *d;
int origSize;
struct dirent *pEntry;
int skipAll = 0;
static Stmt ins;
static int depth = 0;
void *zNative;
origSize = blob_size(pPath);
|
| ︙ | ︙ | |||
466 467 468 469 470 471 472 |
"INSERT OR IGNORE INTO sfile(x) SELECT :file"
" WHERE NOT EXISTS(SELECT 1 FROM vfile WHERE"
" pathname=:file %s)", filename_collation()
);
}
depth++;
| < | | 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 |
"INSERT OR IGNORE INTO sfile(x) SELECT :file"
" WHERE NOT EXISTS(SELECT 1 FROM vfile WHERE"
" pathname=:file %s)", filename_collation()
);
}
depth++;
zNative = fossil_utf8_to_filename(blob_str(pPath));
d = opendir(zNative);
if( d ){
while( (pEntry=readdir(d))!=0 ){
char *zPath;
char *zUtf8;
if( pEntry->d_name[0]=='.' ){
if( (scanFlags & SCAN_ALL)==0 ) continue;
|
| ︙ | ︙ | |||
507 508 509 510 511 512 513 514 515 516 517 518 519 520 |
fossil_filename_free(zNative);
depth--;
if( depth==0 ){
db_finalize(&ins);
}
}
/*
** Compute an aggregate MD5 checksum over the disk image of every
** file in vid. The file names are part of the checksum. The resulting
** checksum is the same as is expected on the R-card of a manifest.
**
** This function operates differently if the Global.aCommitFile
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 |
fossil_filename_free(zNative);
depth--;
if( depth==0 ){
db_finalize(&ins);
}
}
/*
** Scans the specified base directory for any directories within it, while
** keeping a count of how many files they each contains, either directly or
** indirectly.
**
** Subdirectories are scanned recursively.
** Omit files named in VFILE.
**
** Directories whose names begin with "." are omitted unless the SCAN_ALL
** flag is set.
**
** Any directories that match the glob patterns pIgnore* are excluded from
** the scan. Name matching occurs after the first nPrefix characters are
** elided from the filename.
**
** Returns the total number of files found.
*/
int vfile_dir_scan(
Blob *pPath, /* Base directory to be scanned */
int nPrefix, /* Number of bytes in base directory name */
unsigned scanFlags, /* Zero or more SCAN_xxx flags */
Glob *pIgnore1, /* Do not add directories that match this GLOB */
Glob *pIgnore2, /* Omit directories matching this GLOB too */
Glob *pIgnore3 /* Omit directories matching this GLOB too */
){
int result = 0;
DIR *d;
int origSize;
struct dirent *pEntry;
int skipAll = 0;
static Stmt ins;
static Stmt upd;
static int depth = 0;
void *zNative;
origSize = blob_size(pPath);
if( pIgnore1 || pIgnore2 || pIgnore3 ){
blob_appendf(pPath, "/");
if( glob_match(pIgnore1, &blob_str(pPath)[nPrefix+1]) ) skipAll = 1;
if( glob_match(pIgnore2, &blob_str(pPath)[nPrefix+1]) ) skipAll = 1;
if( glob_match(pIgnore3, &blob_str(pPath)[nPrefix+1]) ) skipAll = 1;
blob_resize(pPath, origSize);
}
if( skipAll ) return result;
if( depth==0 ){
db_multi_exec("DROP TABLE IF EXISTS dscan_temp;"
"CREATE TEMP TABLE dscan_temp("
" x TEXT PRIMARY KEY %s, y INTEGER)",
filename_collation());
db_prepare(&ins,
"INSERT OR IGNORE INTO dscan_temp(x, y) SELECT :file, :count"
" WHERE NOT EXISTS(SELECT 1 FROM vfile WHERE"
" pathname GLOB :pattern %s)", filename_collation()
);
db_prepare(&upd,
"UPDATE OR IGNORE dscan_temp SET y = coalesce(y, 0) + 1"
" WHERE x=:file %s",
filename_collation()
);
}
depth++;
zNative = fossil_utf8_to_filename(blob_str(pPath));
d = opendir(zNative);
if( d ){
while( (pEntry=readdir(d))!=0 ){
char *zOrigPath;
char *zPath;
char *zUtf8;
if( pEntry->d_name[0]=='.' ){
if( (scanFlags & SCAN_ALL)==0 ) continue;
if( pEntry->d_name[1]==0 ) continue;
if( pEntry->d_name[1]=='.' && pEntry->d_name[2]==0 ) continue;
}
zOrigPath = mprintf("%s", blob_str(pPath));
zUtf8 = fossil_filename_to_utf8(pEntry->d_name);
blob_appendf(pPath, "/%s", zUtf8);
zPath = blob_str(pPath);
if( glob_match(pIgnore1, &zPath[nPrefix+1]) ||
glob_match(pIgnore2, &zPath[nPrefix+1]) ||
glob_match(pIgnore3, &zPath[nPrefix+1]) ){
/* do nothing */
}else if( file_wd_isdir(zPath)==1 ){
if( !vfile_top_of_checkout(zPath) ){
Blob dirPattern;
int count = vfile_dir_scan(pPath, nPrefix, scanFlags, pIgnore1,
pIgnore2, pIgnore3);
blob_init(&dirPattern, &zPath[nPrefix+1], -1);
blob_appendf(&dirPattern, "*");
db_bind_text(&ins, ":file", &zPath[nPrefix+1]);
db_bind_int(&ins, ":count", count);
db_bind_text(&ins, ":pattern", blob_str(&dirPattern));
db_step(&ins);
db_reset(&ins);
blob_reset(&dirPattern);
result += count; /* found X normal files? */
}
}else if( file_wd_isfile_or_link(zPath) ){
db_bind_text(&upd, ":file", zOrigPath);
db_step(&upd);
db_reset(&upd);
result++; /* found 1 normal file */
}
fossil_filename_free(zUtf8);
blob_resize(pPath, origSize);
fossil_free(zOrigPath);
}
closedir(d);
}
fossil_filename_free(zNative);
depth--;
if( depth==0 ){
db_finalize(&upd);
db_finalize(&ins);
}
return result;
}
/*
** Compute an aggregate MD5 checksum over the disk image of every
** file in vid. The file names are part of the checksum. The resulting
** checksum is the same as is expected on the R-card of a manifest.
**
** This function operates differently if the Global.aCommitFile
|
| ︙ | ︙ |