Fossil SCM

Add the ability to specify directories and files on the "fossil ls" command.

drh 2013-06-20 15:39 UTC trunk
Commit 04803ae4ab7442daf15a85f0da945bf2f246d535
1 file changed +34 -6
+34 -6
--- src/checkin.c
+++ src/checkin.c
@@ -217,14 +217,15 @@
217217
}
218218
219219
/*
220220
** COMMAND: ls
221221
**
222
-** Usage: %fossil ls ?OPTIONS? ?VERSION?
222
+** Usage: %fossil ls ?OPTIONS? ?VERSION? ?FILENAMES?
223223
**
224224
** Show the names of all files in the current checkout. The -v provides
225
-** extra information about each file.
225
+** extra information about each file. If FILENAMES are included, the only
226
+** the files listed (or their children if they are directories) are shown.
226227
**
227228
** Options:
228229
** --age Show when each file was committed
229230
** -v|--verbose Provide extra information about each file.
230231
**
@@ -234,10 +235,13 @@
234235
int vid;
235236
Stmt q;
236237
int verboseFlag;
237238
int showAge;
238239
char *zOrderBy = "pathname";
240
+ Blob where;
241
+ int i;
242
+ int nRoot;
239243
240244
verboseFlag = find_option("verbose","v", 0)!=0;
241245
if( !verboseFlag ){
242246
verboseFlag = find_option("l","l", 0)!=0; /* deprecated */
243247
}
@@ -250,25 +254,49 @@
250254
}else{
251255
zOrderBy = "mtime DESC";
252256
}
253257
}
254258
verify_all_options();
259
+ blob_zero(&where);
260
+ nRoot = (int)strlen(g.zLocalRoot);
261
+ for(i=2; i<g.argc; i++){
262
+ Blob fname;
263
+ file_canonical_name(g.argv[i], &fname, 0);
264
+ if( blob_size(&where)>0 ){
265
+ blob_append(&where, " OR ", -1);
266
+ }else{
267
+ blob_append(&where, " WHERE ", -1);
268
+ }
269
+ if( file_wd_isdir(blob_str(&fname))==1 ){
270
+ const char *zFormat;
271
+ if( filenames_are_case_sensitive() ){
272
+ zFormat = "(pathname GLOB '%q/*')";
273
+ }else{
274
+ zFormat = "(pathname LIKE '%q/%%')";
275
+ }
276
+ blob_appendf(&where, zFormat, blob_str(&fname)+nRoot);
277
+ }else{
278
+ blob_appendf(&where, "(pathname=%Q %s)",
279
+ blob_str(&fname)+nRoot, filename_collation());
280
+ }
281
+ }
255282
vfile_check_signature(vid, 0);
256283
if( showAge ){
257284
db_prepare(&q,
258285
"SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0),"
259286
" datetime(checkin_mtime(%d,rid),'unixepoch','localtime')"
260
- " FROM vfile"
261
- " ORDER BY %s", vid, zOrderBy
287
+ " FROM vfile %s"
288
+ " ORDER BY %s", vid, blob_str(&where), zOrderBy
262289
);
263290
}else{
264291
db_prepare(&q,
265292
"SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0)"
266
- " FROM vfile"
267
- " ORDER BY %s", zOrderBy
293
+ " FROM vfile %s"
294
+ " ORDER BY %s", blob_str(&where), zOrderBy
268295
);
269296
}
297
+ blob_reset(&where);
270298
while( db_step(&q)==SQLITE_ROW ){
271299
const char *zPathname = db_column_text(&q,0);
272300
int isDeleted = db_column_int(&q, 1);
273301
int isNew = db_column_int(&q,2)==0;
274302
int chnged = db_column_int(&q,3);
275303
--- src/checkin.c
+++ src/checkin.c
@@ -217,14 +217,15 @@
217 }
218
219 /*
220 ** COMMAND: ls
221 **
222 ** Usage: %fossil ls ?OPTIONS? ?VERSION?
223 **
224 ** Show the names of all files in the current checkout. The -v provides
225 ** extra information about each file.
 
226 **
227 ** Options:
228 ** --age Show when each file was committed
229 ** -v|--verbose Provide extra information about each file.
230 **
@@ -234,10 +235,13 @@
234 int vid;
235 Stmt q;
236 int verboseFlag;
237 int showAge;
238 char *zOrderBy = "pathname";
 
 
 
239
240 verboseFlag = find_option("verbose","v", 0)!=0;
241 if( !verboseFlag ){
242 verboseFlag = find_option("l","l", 0)!=0; /* deprecated */
243 }
@@ -250,25 +254,49 @@
250 }else{
251 zOrderBy = "mtime DESC";
252 }
253 }
254 verify_all_options();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
255 vfile_check_signature(vid, 0);
256 if( showAge ){
257 db_prepare(&q,
258 "SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0),"
259 " datetime(checkin_mtime(%d,rid),'unixepoch','localtime')"
260 " FROM vfile"
261 " ORDER BY %s", vid, zOrderBy
262 );
263 }else{
264 db_prepare(&q,
265 "SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0)"
266 " FROM vfile"
267 " ORDER BY %s", zOrderBy
268 );
269 }
 
270 while( db_step(&q)==SQLITE_ROW ){
271 const char *zPathname = db_column_text(&q,0);
272 int isDeleted = db_column_int(&q, 1);
273 int isNew = db_column_int(&q,2)==0;
274 int chnged = db_column_int(&q,3);
275
--- src/checkin.c
+++ src/checkin.c
@@ -217,14 +217,15 @@
217 }
218
219 /*
220 ** COMMAND: ls
221 **
222 ** Usage: %fossil ls ?OPTIONS? ?VERSION? ?FILENAMES?
223 **
224 ** Show the names of all files in the current checkout. The -v provides
225 ** extra information about each file. If FILENAMES are included, the only
226 ** the files listed (or their children if they are directories) are shown.
227 **
228 ** Options:
229 ** --age Show when each file was committed
230 ** -v|--verbose Provide extra information about each file.
231 **
@@ -234,10 +235,13 @@
235 int vid;
236 Stmt q;
237 int verboseFlag;
238 int showAge;
239 char *zOrderBy = "pathname";
240 Blob where;
241 int i;
242 int nRoot;
243
244 verboseFlag = find_option("verbose","v", 0)!=0;
245 if( !verboseFlag ){
246 verboseFlag = find_option("l","l", 0)!=0; /* deprecated */
247 }
@@ -250,25 +254,49 @@
254 }else{
255 zOrderBy = "mtime DESC";
256 }
257 }
258 verify_all_options();
259 blob_zero(&where);
260 nRoot = (int)strlen(g.zLocalRoot);
261 for(i=2; i<g.argc; i++){
262 Blob fname;
263 file_canonical_name(g.argv[i], &fname, 0);
264 if( blob_size(&where)>0 ){
265 blob_append(&where, " OR ", -1);
266 }else{
267 blob_append(&where, " WHERE ", -1);
268 }
269 if( file_wd_isdir(blob_str(&fname))==1 ){
270 const char *zFormat;
271 if( filenames_are_case_sensitive() ){
272 zFormat = "(pathname GLOB '%q/*')";
273 }else{
274 zFormat = "(pathname LIKE '%q/%%')";
275 }
276 blob_appendf(&where, zFormat, blob_str(&fname)+nRoot);
277 }else{
278 blob_appendf(&where, "(pathname=%Q %s)",
279 blob_str(&fname)+nRoot, filename_collation());
280 }
281 }
282 vfile_check_signature(vid, 0);
283 if( showAge ){
284 db_prepare(&q,
285 "SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0),"
286 " datetime(checkin_mtime(%d,rid),'unixepoch','localtime')"
287 " FROM vfile %s"
288 " ORDER BY %s", vid, blob_str(&where), zOrderBy
289 );
290 }else{
291 db_prepare(&q,
292 "SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0)"
293 " FROM vfile %s"
294 " ORDER BY %s", blob_str(&where), zOrderBy
295 );
296 }
297 blob_reset(&where);
298 while( db_step(&q)==SQLITE_ROW ){
299 const char *zPathname = db_column_text(&q,0);
300 int isDeleted = db_column_int(&q, 1);
301 int isNew = db_column_int(&q,2)==0;
302 int chnged = db_column_int(&q,3);
303

Keyboard Shortcuts

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