Fossil SCM

Add the -i or --prompt option to the "fossil clean" command.

drh 2015-11-03 01:07 UTC clean-cmd-cleanup
Commit 1c9da04a39c9b06f4efcee7264b309d90ced678e
1 file changed +28 -9
+28 -9
--- src/checkin.c
+++ src/checkin.c
@@ -674,10 +674,11 @@
674674
** argument. Matching files, if any, are removed
675675
** prior to checking for any empty directories;
676676
** therefore, directories that contain only files
677677
** that were removed will be removed as well.
678678
** -f|--force Remove files without prompting.
679
+** -i|--prompt Prompt before removing each file.
679680
** -x|--verily WARNING: Removes everything that is not a managed
680681
** file or the repository itself. This option
681682
** implies the --force, --emptydirs, --dotfiles, and
682683
** --disable-undo options. Furthermore, it completely
683684
** disregards the keep-glob and ignore-glob settings.
@@ -702,10 +703,11 @@
702703
*/
703704
void clean_cmd(void){
704705
int allFileFlag, allDirFlag, dryRunFlag, verboseFlag;
705706
int emptyDirsFlag, dirsOnlyFlag;
706707
int disableUndo, noPrompt;
708
+ int alwaysPrompt = 0;
707709
unsigned scanFlags = 0;
708710
int verilyFlag = 0;
709711
const char *zIgnoreFlag, *zKeepFlag, *zCleanFlag;
710712
Glob *pIgnore, *pKeep, *pClean;
711713
int nRoot;
@@ -722,10 +724,11 @@
722724
if( !dryRunFlag ){
723725
dryRunFlag = find_option("whatif",0,0)!=0;
724726
}
725727
disableUndo = find_option("disable-undo",0,0)!=0;
726728
noPrompt = find_option("no-prompt",0,0)!=0;
729
+ alwaysPrompt = find_option("prompt","i",0)!=0;
727730
allFileFlag = allDirFlag = find_option("force","f",0)!=0;
728731
dirsOnlyFlag = find_option("dirsonly",0,0)!=0;
729732
emptyDirsFlag = find_option("emptydirs","d",0)!=0 || dirsOnlyFlag;
730733
if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL;
731734
if( find_option("temp",0,0)!=0 ) scanFlags |= SCAN_TEMP;
@@ -781,28 +784,44 @@
781784
" or \"keep-glob\")\n", zName+nRoot);
782785
}
783786
continue;
784787
}
785788
if( !dryRunFlag && !glob_match(pClean, zName+nRoot) ){
789
+ char *zPrompt = 0;
790
+ char cReply;
791
+ Blob ans = empty_blob;
786792
int undoRc = UNDO_NONE;
787
- if( !disableUndo ){
793
+ if( alwaysPrompt ){
794
+ zPrompt = mprintf("Remove unmanaged file \"%s\" (a=all/y/N)? ",
795
+ zName+nRoot);
796
+ prompt_user(zPrompt, &ans);
797
+ fossil_free(zPrompt);
798
+ cReply = fossil_toupper(blob_str(&ans)[0]);
799
+ blob_reset(&ans);
800
+ if( cReply=='N' ) continue;
801
+ if( cReply=='A' ){
802
+ allFileFlag = 1;
803
+ alwaysPrompt = 0;
804
+ }else{
805
+ undoRc = UNDO_SAVED_OK;
806
+ }
807
+ }else if( !disableUndo ){
788808
undoRc = undo_maybe_save(zName+nRoot, UNDO_SIZE_LIMIT);
789809
}
790810
if( undoRc!=UNDO_SAVED_OK ){
791
- char cReply;
792811
if( allFileFlag ){
793812
cReply = 'Y';
794813
}else if( !noPrompt ){
795814
Blob ans;
796
- char *prompt = mprintf("\nWARNING: Deletion of this file will "
797
- "not be undoable via the 'undo'\n"
798
- " command because %s.\n\n"
799
- "Remove unmanaged file \"%s\" (a=all/y/N)? ",
800
- undo_save_message(undoRc), zName+nRoot);
801
- prompt_user(prompt, &ans);
815
+ zPrompt = mprintf("\nWARNING: Deletion of this file will "
816
+ "not be undoable via the 'undo'\n"
817
+ " command because %s.\n\n"
818
+ "Remove unmanaged file \"%s\" (a=all/y/N)? ",
819
+ undo_save_message(undoRc), zName+nRoot);
820
+ prompt_user(zPrompt, &ans);
821
+ fossil_free(zPrompt);
802822
cReply = blob_str(&ans)[0];
803
- fossil_free(prompt);
804823
blob_reset(&ans);
805824
}else{
806825
cReply = 'N';
807826
}
808827
if( cReply=='a' || cReply=='A' ){
809828
--- src/checkin.c
+++ src/checkin.c
@@ -674,10 +674,11 @@
674 ** argument. Matching files, if any, are removed
675 ** prior to checking for any empty directories;
676 ** therefore, directories that contain only files
677 ** that were removed will be removed as well.
678 ** -f|--force Remove files without prompting.
 
679 ** -x|--verily WARNING: Removes everything that is not a managed
680 ** file or the repository itself. This option
681 ** implies the --force, --emptydirs, --dotfiles, and
682 ** --disable-undo options. Furthermore, it completely
683 ** disregards the keep-glob and ignore-glob settings.
@@ -702,10 +703,11 @@
702 */
703 void clean_cmd(void){
704 int allFileFlag, allDirFlag, dryRunFlag, verboseFlag;
705 int emptyDirsFlag, dirsOnlyFlag;
706 int disableUndo, noPrompt;
 
707 unsigned scanFlags = 0;
708 int verilyFlag = 0;
709 const char *zIgnoreFlag, *zKeepFlag, *zCleanFlag;
710 Glob *pIgnore, *pKeep, *pClean;
711 int nRoot;
@@ -722,10 +724,11 @@
722 if( !dryRunFlag ){
723 dryRunFlag = find_option("whatif",0,0)!=0;
724 }
725 disableUndo = find_option("disable-undo",0,0)!=0;
726 noPrompt = find_option("no-prompt",0,0)!=0;
 
727 allFileFlag = allDirFlag = find_option("force","f",0)!=0;
728 dirsOnlyFlag = find_option("dirsonly",0,0)!=0;
729 emptyDirsFlag = find_option("emptydirs","d",0)!=0 || dirsOnlyFlag;
730 if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL;
731 if( find_option("temp",0,0)!=0 ) scanFlags |= SCAN_TEMP;
@@ -781,28 +784,44 @@
781 " or \"keep-glob\")\n", zName+nRoot);
782 }
783 continue;
784 }
785 if( !dryRunFlag && !glob_match(pClean, zName+nRoot) ){
 
 
 
786 int undoRc = UNDO_NONE;
787 if( !disableUndo ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
788 undoRc = undo_maybe_save(zName+nRoot, UNDO_SIZE_LIMIT);
789 }
790 if( undoRc!=UNDO_SAVED_OK ){
791 char cReply;
792 if( allFileFlag ){
793 cReply = 'Y';
794 }else if( !noPrompt ){
795 Blob ans;
796 char *prompt = mprintf("\nWARNING: Deletion of this file will "
797 "not be undoable via the 'undo'\n"
798 " command because %s.\n\n"
799 "Remove unmanaged file \"%s\" (a=all/y/N)? ",
800 undo_save_message(undoRc), zName+nRoot);
801 prompt_user(prompt, &ans);
 
802 cReply = blob_str(&ans)[0];
803 fossil_free(prompt);
804 blob_reset(&ans);
805 }else{
806 cReply = 'N';
807 }
808 if( cReply=='a' || cReply=='A' ){
809
--- src/checkin.c
+++ src/checkin.c
@@ -674,10 +674,11 @@
674 ** argument. Matching files, if any, are removed
675 ** prior to checking for any empty directories;
676 ** therefore, directories that contain only files
677 ** that were removed will be removed as well.
678 ** -f|--force Remove files without prompting.
679 ** -i|--prompt Prompt before removing each file.
680 ** -x|--verily WARNING: Removes everything that is not a managed
681 ** file or the repository itself. This option
682 ** implies the --force, --emptydirs, --dotfiles, and
683 ** --disable-undo options. Furthermore, it completely
684 ** disregards the keep-glob and ignore-glob settings.
@@ -702,10 +703,11 @@
703 */
704 void clean_cmd(void){
705 int allFileFlag, allDirFlag, dryRunFlag, verboseFlag;
706 int emptyDirsFlag, dirsOnlyFlag;
707 int disableUndo, noPrompt;
708 int alwaysPrompt = 0;
709 unsigned scanFlags = 0;
710 int verilyFlag = 0;
711 const char *zIgnoreFlag, *zKeepFlag, *zCleanFlag;
712 Glob *pIgnore, *pKeep, *pClean;
713 int nRoot;
@@ -722,10 +724,11 @@
724 if( !dryRunFlag ){
725 dryRunFlag = find_option("whatif",0,0)!=0;
726 }
727 disableUndo = find_option("disable-undo",0,0)!=0;
728 noPrompt = find_option("no-prompt",0,0)!=0;
729 alwaysPrompt = find_option("prompt","i",0)!=0;
730 allFileFlag = allDirFlag = find_option("force","f",0)!=0;
731 dirsOnlyFlag = find_option("dirsonly",0,0)!=0;
732 emptyDirsFlag = find_option("emptydirs","d",0)!=0 || dirsOnlyFlag;
733 if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL;
734 if( find_option("temp",0,0)!=0 ) scanFlags |= SCAN_TEMP;
@@ -781,28 +784,44 @@
784 " or \"keep-glob\")\n", zName+nRoot);
785 }
786 continue;
787 }
788 if( !dryRunFlag && !glob_match(pClean, zName+nRoot) ){
789 char *zPrompt = 0;
790 char cReply;
791 Blob ans = empty_blob;
792 int undoRc = UNDO_NONE;
793 if( alwaysPrompt ){
794 zPrompt = mprintf("Remove unmanaged file \"%s\" (a=all/y/N)? ",
795 zName+nRoot);
796 prompt_user(zPrompt, &ans);
797 fossil_free(zPrompt);
798 cReply = fossil_toupper(blob_str(&ans)[0]);
799 blob_reset(&ans);
800 if( cReply=='N' ) continue;
801 if( cReply=='A' ){
802 allFileFlag = 1;
803 alwaysPrompt = 0;
804 }else{
805 undoRc = UNDO_SAVED_OK;
806 }
807 }else if( !disableUndo ){
808 undoRc = undo_maybe_save(zName+nRoot, UNDO_SIZE_LIMIT);
809 }
810 if( undoRc!=UNDO_SAVED_OK ){
 
811 if( allFileFlag ){
812 cReply = 'Y';
813 }else if( !noPrompt ){
814 Blob ans;
815 zPrompt = mprintf("\nWARNING: Deletion of this file will "
816 "not be undoable via the 'undo'\n"
817 " command because %s.\n\n"
818 "Remove unmanaged file \"%s\" (a=all/y/N)? ",
819 undo_save_message(undoRc), zName+nRoot);
820 prompt_user(zPrompt, &ans);
821 fossil_free(zPrompt);
822 cReply = blob_str(&ans)[0];
 
823 blob_reset(&ans);
824 }else{
825 cReply = 'N';
826 }
827 if( cReply=='a' || cReply=='A' ){
828

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button