Fossil SCM

Add the --dotfiles option to the "extra" and "clean" commands. Ticket [4de876322f066].

drh 2009-09-19 15:32 trunk
Commit a2749215b71b297780c2b787a938eae82edf32b7
2 files changed +15 -5 +7 -3
+15 -5
--- src/checkin.c
+++ src/checkin.c
@@ -164,25 +164,29 @@
164164
db_finalize(&q);
165165
}
166166
167167
/*
168168
** COMMAND: extras
169
-** Usage: %fossil extras
169
+** Usage: %fossil extras ?--dotfiles?
170170
**
171171
** Print a list of all files in the source tree that are not part of
172172
** the current checkout. See also the "clean" command.
173
+**
174
+** Files and subdirectories whose names begin with "." are normally
175
+** ignored but can be included by adding the --dotfiles option.
173176
*/
174177
void extra_cmd(void){
175178
Blob path;
176179
Blob repo;
177180
Stmt q;
178181
int n;
182
+ int allFlag = find_option("dotfiles",0,0)!=0;
179183
db_must_be_within_tree();
180184
db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
181185
n = strlen(g.zLocalRoot);
182186
blob_init(&path, g.zLocalRoot, n-1);
183
- vfile_scan(0, &path, blob_size(&path));
187
+ vfile_scan(0, &path, blob_size(&path), allFlag);
184188
db_prepare(&q,
185189
"SELECT x FROM sfile"
186190
" WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
187191
" ORDER BY 1");
188192
if( file_tree_name(g.zRepositoryName, &repo, 0) ){
@@ -194,31 +198,37 @@
194198
db_finalize(&q);
195199
}
196200
197201
/*
198202
** COMMAND: clean
199
-** Usage: %fossil clean ?-all?
203
+** Usage: %fossil clean ?--force? ?--dotfiles?
200204
**
201205
** Delete all "extra" files in the source tree. "Extra" files are
202206
** files that are not officially part of the checkout. See also
203207
** the "extra" command. This operation cannot be undone.
204208
**
205209
** You will be prompted before removing each file. If you are
206210
** sure you wish to remove all "extra" files you can specify the
207
-** optional -all flag.
211
+** optional --force flag and no prmpts will be issued.
212
+**
213
+** Files and subdirectories whose names begin with "." are
214
+** normally ignored. They are included if the "--dotfiles" option
215
+** is used.
208216
*/
209217
void clean_cmd(void){
210218
int allFlag;
219
+ int dotfilesFlag;
211220
Blob path, repo;
212221
Stmt q;
213222
int n;
214223
allFlag = find_option("all","a",0)!=0;
224
+ dotfilesFlag = find_option("dotfiles",0,0)!=0;
215225
db_must_be_within_tree();
216226
db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
217227
n = strlen(g.zLocalRoot);
218228
blob_init(&path, g.zLocalRoot, n-1);
219
- vfile_scan(0, &path, blob_size(&path));
229
+ vfile_scan(0, &path, blob_size(&path), dotfilesFlag);
220230
db_prepare(&q,
221231
"SELECT %Q || x FROM sfile"
222232
" WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
223233
" ORDER BY 1", g.zLocalRoot);
224234
if( file_tree_name(g.zRepositoryName, &repo, 0) ){
225235
--- src/checkin.c
+++ src/checkin.c
@@ -164,25 +164,29 @@
164 db_finalize(&q);
165 }
166
167 /*
168 ** COMMAND: extras
169 ** Usage: %fossil extras
170 **
171 ** Print a list of all files in the source tree that are not part of
172 ** the current checkout. See also the "clean" command.
 
 
 
173 */
174 void extra_cmd(void){
175 Blob path;
176 Blob repo;
177 Stmt q;
178 int n;
 
179 db_must_be_within_tree();
180 db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
181 n = strlen(g.zLocalRoot);
182 blob_init(&path, g.zLocalRoot, n-1);
183 vfile_scan(0, &path, blob_size(&path));
184 db_prepare(&q,
185 "SELECT x FROM sfile"
186 " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
187 " ORDER BY 1");
188 if( file_tree_name(g.zRepositoryName, &repo, 0) ){
@@ -194,31 +198,37 @@
194 db_finalize(&q);
195 }
196
197 /*
198 ** COMMAND: clean
199 ** Usage: %fossil clean ?-all?
200 **
201 ** Delete all "extra" files in the source tree. "Extra" files are
202 ** files that are not officially part of the checkout. See also
203 ** the "extra" command. This operation cannot be undone.
204 **
205 ** You will be prompted before removing each file. If you are
206 ** sure you wish to remove all "extra" files you can specify the
207 ** optional -all flag.
 
 
 
 
208 */
209 void clean_cmd(void){
210 int allFlag;
 
211 Blob path, repo;
212 Stmt q;
213 int n;
214 allFlag = find_option("all","a",0)!=0;
 
215 db_must_be_within_tree();
216 db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
217 n = strlen(g.zLocalRoot);
218 blob_init(&path, g.zLocalRoot, n-1);
219 vfile_scan(0, &path, blob_size(&path));
220 db_prepare(&q,
221 "SELECT %Q || x FROM sfile"
222 " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
223 " ORDER BY 1", g.zLocalRoot);
224 if( file_tree_name(g.zRepositoryName, &repo, 0) ){
225
--- src/checkin.c
+++ src/checkin.c
@@ -164,25 +164,29 @@
164 db_finalize(&q);
165 }
166
167 /*
168 ** COMMAND: extras
169 ** Usage: %fossil extras ?--dotfiles?
170 **
171 ** Print a list of all files in the source tree that are not part of
172 ** the current checkout. See also the "clean" command.
173 **
174 ** Files and subdirectories whose names begin with "." are normally
175 ** ignored but can be included by adding the --dotfiles option.
176 */
177 void extra_cmd(void){
178 Blob path;
179 Blob repo;
180 Stmt q;
181 int n;
182 int allFlag = find_option("dotfiles",0,0)!=0;
183 db_must_be_within_tree();
184 db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
185 n = strlen(g.zLocalRoot);
186 blob_init(&path, g.zLocalRoot, n-1);
187 vfile_scan(0, &path, blob_size(&path), allFlag);
188 db_prepare(&q,
189 "SELECT x FROM sfile"
190 " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
191 " ORDER BY 1");
192 if( file_tree_name(g.zRepositoryName, &repo, 0) ){
@@ -194,31 +198,37 @@
198 db_finalize(&q);
199 }
200
201 /*
202 ** COMMAND: clean
203 ** Usage: %fossil clean ?--force? ?--dotfiles?
204 **
205 ** Delete all "extra" files in the source tree. "Extra" files are
206 ** files that are not officially part of the checkout. See also
207 ** the "extra" command. This operation cannot be undone.
208 **
209 ** You will be prompted before removing each file. If you are
210 ** sure you wish to remove all "extra" files you can specify the
211 ** optional --force flag and no prmpts will be issued.
212 **
213 ** Files and subdirectories whose names begin with "." are
214 ** normally ignored. They are included if the "--dotfiles" option
215 ** is used.
216 */
217 void clean_cmd(void){
218 int allFlag;
219 int dotfilesFlag;
220 Blob path, repo;
221 Stmt q;
222 int n;
223 allFlag = find_option("all","a",0)!=0;
224 dotfilesFlag = find_option("dotfiles",0,0)!=0;
225 db_must_be_within_tree();
226 db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
227 n = strlen(g.zLocalRoot);
228 blob_init(&path, g.zLocalRoot, n-1);
229 vfile_scan(0, &path, blob_size(&path), dotfilesFlag);
230 db_prepare(&q,
231 "SELECT %Q || x FROM sfile"
232 " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
233 " ORDER BY 1", g.zLocalRoot);
234 if( file_tree_name(g.zRepositoryName, &repo, 0) ){
235
+7 -3
--- src/vfile.c
+++ src/vfile.c
@@ -259,11 +259,11 @@
259259
** of pPath when inserting into the SFILE table.
260260
**
261261
** Subdirectories are scanned recursively.
262262
** Omit files named in VFILE.vid
263263
*/
264
-void vfile_scan(int vid, Blob *pPath, int nPrefix){
264
+void vfile_scan(int vid, Blob *pPath, int nPrefix, int allFlag){
265265
DIR *d;
266266
int origSize;
267267
const char *zDir;
268268
struct dirent *pEntry;
269269
static const char *zSql = "SELECT 1 FROM vfile "
@@ -273,15 +273,19 @@
273273
zDir = blob_str(pPath);
274274
d = opendir(zDir);
275275
if( d ){
276276
while( (pEntry=readdir(d))!=0 ){
277277
char *zPath;
278
- if( pEntry->d_name[0]=='.' ) continue;
278
+ if( pEntry->d_name[0]=='.' ){
279
+ if( !allFlag ) continue;
280
+ if( pEntry->d_name[1]==0 ) continue;
281
+ if( pEntry->d_name[1]=='.' && pEntry->d_name[2]==0 ) continue;
282
+ }
279283
blob_appendf(pPath, "/%s", pEntry->d_name);
280284
zPath = blob_str(pPath);
281285
if( file_isdir(zPath)==1 ){
282
- vfile_scan(vid, pPath, nPrefix);
286
+ vfile_scan(vid, pPath, nPrefix, allFlag);
283287
}else if( file_isfile(zPath) && !db_exists(zSql, &zPath[nPrefix+1]) ){
284288
db_multi_exec("INSERT INTO sfile VALUES(%Q)", &zPath[nPrefix+1]);
285289
}
286290
blob_resize(pPath, origSize);
287291
}
288292
--- src/vfile.c
+++ src/vfile.c
@@ -259,11 +259,11 @@
259 ** of pPath when inserting into the SFILE table.
260 **
261 ** Subdirectories are scanned recursively.
262 ** Omit files named in VFILE.vid
263 */
264 void vfile_scan(int vid, Blob *pPath, int nPrefix){
265 DIR *d;
266 int origSize;
267 const char *zDir;
268 struct dirent *pEntry;
269 static const char *zSql = "SELECT 1 FROM vfile "
@@ -273,15 +273,19 @@
273 zDir = blob_str(pPath);
274 d = opendir(zDir);
275 if( d ){
276 while( (pEntry=readdir(d))!=0 ){
277 char *zPath;
278 if( pEntry->d_name[0]=='.' ) continue;
 
 
 
 
279 blob_appendf(pPath, "/%s", pEntry->d_name);
280 zPath = blob_str(pPath);
281 if( file_isdir(zPath)==1 ){
282 vfile_scan(vid, pPath, nPrefix);
283 }else if( file_isfile(zPath) && !db_exists(zSql, &zPath[nPrefix+1]) ){
284 db_multi_exec("INSERT INTO sfile VALUES(%Q)", &zPath[nPrefix+1]);
285 }
286 blob_resize(pPath, origSize);
287 }
288
--- src/vfile.c
+++ src/vfile.c
@@ -259,11 +259,11 @@
259 ** of pPath when inserting into the SFILE table.
260 **
261 ** Subdirectories are scanned recursively.
262 ** Omit files named in VFILE.vid
263 */
264 void vfile_scan(int vid, Blob *pPath, int nPrefix, int allFlag){
265 DIR *d;
266 int origSize;
267 const char *zDir;
268 struct dirent *pEntry;
269 static const char *zSql = "SELECT 1 FROM vfile "
@@ -273,15 +273,19 @@
273 zDir = blob_str(pPath);
274 d = opendir(zDir);
275 if( d ){
276 while( (pEntry=readdir(d))!=0 ){
277 char *zPath;
278 if( pEntry->d_name[0]=='.' ){
279 if( !allFlag ) continue;
280 if( pEntry->d_name[1]==0 ) continue;
281 if( pEntry->d_name[1]=='.' && pEntry->d_name[2]==0 ) continue;
282 }
283 blob_appendf(pPath, "/%s", pEntry->d_name);
284 zPath = blob_str(pPath);
285 if( file_isdir(zPath)==1 ){
286 vfile_scan(vid, pPath, nPrefix, allFlag);
287 }else if( file_isfile(zPath) && !db_exists(zSql, &zPath[nPrefix+1]) ){
288 db_multi_exec("INSERT INTO sfile VALUES(%Q)", &zPath[nPrefix+1]);
289 }
290 blob_resize(pPath, origSize);
291 }
292

Keyboard Shortcuts

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