Fossil

Changes On Branch cleanDashN
Login

Changes On Branch cleanDashN

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch pending-review Through [7f0507c0] Excluding Merge-Ins

This is equivalent to a diff from 4e573871 to 7f0507c0

2013-05-28
10:32
Refactoring of the clean -x option, phase 1. ... (check-in: 0dc31f4b user: mistachkin tags: cleanX)
2013-05-27
09:56
rebase ... (Closed-Leaf check-in: 7f0507c0 user: jan.nijtmans tags: cleanDashN)
09:53
Implementation simplification: -n implies -f and -v, this way less separate flag-checks have to be done. No change in functionality. ... (Closed-Leaf check-in: 4e573871 user: jan.nijtmans tags: cleanDashN)
08:53
Better implementation of "fossil clean -x". Previous implementation didn't prompt any more before before removing unknown files when the -x option was used. ... (Closed-Leaf check-in: 6758c2b0 user: jan.nijtmans tags: cleanX)
03:10
Minor documentation updates. ... (check-in: 7794d72c user: drh tags: trunk)

Changes to src/checkin.c.

234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
  int vid;
  Stmt q;
  int verboseFlag;
  int showAge;
  char *zOrderBy = "pathname";

  verboseFlag = find_option("verbose","v", 0)!=0;
  if(!verboseFlag){
    verboseFlag = find_option("l","l", 0)!=0; /* deprecated */
  }
  showAge = find_option("age",0,0)!=0;
  db_must_be_within_tree();
  vid = db_lget_int("checkout", 0);
  if( find_option("t","t",0)!=0 ){
    if( showAge ){







|







234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
  int vid;
  Stmt q;
  int verboseFlag;
  int showAge;
  char *zOrderBy = "pathname";

  verboseFlag = find_option("verbose","v", 0)!=0;
  if( !verboseFlag ){
    verboseFlag = find_option("l","l", 0)!=0; /* deprecated */
  }
  showAge = find_option("age",0,0)!=0;
  db_must_be_within_tree();
  vid = db_lget_int("checkout", 0);
  if( find_option("t","t",0)!=0 ){
    if( showAge ){
379
380
381
382
383
384
385
386


387
388
389
390
391
392
393

/*
** COMMAND: clean
** Usage: %fossil clean ?OPTIONS?
**
** Delete all "extra" files in the source tree.  "Extra" files are
** files that are not officially part of the checkout. This operation
** cannot be undone.


**
** You will be prompted before removing each eligible file unless the
** --force flag is in use or it matches the --clean option.  The
** GLOBPATTERN specified by the "ignore-glob" setting is used if the
** --ignore option is omitted, the same with "clean-glob" and --clean
** as well as "keep-glob" and --keep.  If you are sure you wish to
** remove all "extra" files except the ones specified with --ignore







|
>
>







379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395

/*
** COMMAND: clean
** Usage: %fossil clean ?OPTIONS?
**
** Delete all "extra" files in the source tree.  "Extra" files are
** files that are not officially part of the checkout. This operation
** cannot be undone. Normally, only files unknown to fossil are
** removed, but if the -x option is specified, ignored files are
** removed as well.
**
** You will be prompted before removing each eligible file unless the
** --force flag is in use or it matches the --clean option.  The
** GLOBPATTERN specified by the "ignore-glob" setting is used if the
** --ignore option is omitted, the same with "clean-glob" and --clean
** as well as "keep-glob" and --keep.  If you are sure you wish to
** remove all "extra" files except the ones specified with --ignore
408
409
410
411
412
413
414



415
416
417
418
419
420
421
422
423
424
425
426
427

428
429
430
431
432
433
434
**    --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 allFlag, dryRunFlag, verboseFlag;
  unsigned scanFlags = 0;
  const char *zIgnoreFlag, *zKeepFlag, *zCleanFlag;
  Blob path, repo;
  Stmt q;
  int n;
  Glob *pIgnore, *pKeep, *pClean;

  dryRunFlag = find_option("dry-run","n",0)!=0;

  if( !dryRunFlag ){
    dryRunFlag = find_option("test",0,0)!=0; /* deprecated */
  }
  allFlag = find_option("force","f",0)!=0 || dryRunFlag;
  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);







>
>
>




|








>







410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
**    --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
**    -x               Remove everything unkown to fossil,
**                     including files matching --ignore.
**                     Compatibile with "git clean -x".
**
** See also: addremove, extra, status
*/
void clean_cmd(void){
  int allFlag, dryRunFlag, verboseFlag, xFlag;
  unsigned scanFlags = 0;
  const char *zIgnoreFlag, *zKeepFlag, *zCleanFlag;
  Blob path, repo;
  Stmt q;
  int n;
  Glob *pIgnore, *pKeep, *pClean;

  dryRunFlag = find_option("dry-run","n",0)!=0;
  xFlag = find_option("x","x",0)!=0;
  if( !dryRunFlag ){
    dryRunFlag = find_option("test",0,0)!=0; /* deprecated */
  }
  allFlag = find_option("force","f",0)!=0 || dryRunFlag;
  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);
450
451
452
453
454
455
456
457
458
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
487
488
489
490
491
492

493
494
495
496
497
498
499
  db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY %s)",
                filename_collation());
  n = strlen(g.zLocalRoot);
  blob_init(&path, g.zLocalRoot, n-1);
  pIgnore = glob_create(zIgnoreFlag);
  pKeep = glob_create(zKeepFlag);
  pClean = glob_create(zCleanFlag);
  vfile_scan2(&path, blob_size(&path), scanFlags, pIgnore, pKeep);
  glob_free(pKeep);
  glob_free(pIgnore);
  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)");
  while( db_step(&q)==SQLITE_ROW ){
    const char *zName = db_column_text(&q, 0);
    if( !allFlag && !glob_match(pClean, zName+n) ){

      Blob ans;
      char cReply;
      char *prompt = mprintf("remove unmanaged file \"%s\" (a=all/y/N)? ",
                             zName+n);
      blob_zero(&ans);
      prompt_user(prompt, &ans);
      cReply = blob_str(&ans)[0];
      if( cReply=='a' || cReply=='A' ){
        allFlag = 1;
      }else if( cReply!='y' && cReply!='Y' ){
        continue;
      }
    }
    if( verboseFlag ){
      fossil_print("removed unmanaged file: %s\n", zName+n);
    }
    if( !dryRunFlag ){
      file_delete(zName);
    }
  }

  glob_free(pClean);
  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.







|

<












|
>




















>







456
457
458
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
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
  db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY %s)",
                filename_collation());
  n = strlen(g.zLocalRoot);
  blob_init(&path, g.zLocalRoot, n-1);
  pIgnore = glob_create(zIgnoreFlag);
  pKeep = glob_create(zKeepFlag);
  pClean = glob_create(zCleanFlag);
  vfile_scan2(&path, blob_size(&path), scanFlags, xFlag?0:pIgnore, pKeep);
  glob_free(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)");
  while( db_step(&q)==SQLITE_ROW ){
    const char *zName = db_column_text(&q, 0);
    if( !allFlag && !glob_match(pClean, zName+n)
        && (!xFlag || !glob_match(pIgnore, zName+n))){
      Blob ans;
      char cReply;
      char *prompt = mprintf("remove unmanaged file \"%s\" (a=all/y/N)? ",
                             zName+n);
      blob_zero(&ans);
      prompt_user(prompt, &ans);
      cReply = blob_str(&ans)[0];
      if( cReply=='a' || cReply=='A' ){
        allFlag = 1;
      }else if( cReply!='y' && cReply!='Y' ){
        continue;
      }
    }
    if( verboseFlag ){
      fossil_print("removed unmanaged file: %s\n", zName+n);
    }
    if( !dryRunFlag ){
      file_delete(zName);
    }
  }
  glob_free(pIgnore);
  glob_free(pClean);
  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.