Fossil SCM

Add the -r option to the "ls" command.

drh 2015-03-10 00:17 trunk merge
Commit e567a910de739d0cf9f684ead99bfe9a34470b5f
2 files changed +94 -4 +94 -4
+94 -4
--- src/checkin.c
+++ src/checkin.c
@@ -265,44 +265,134 @@
265265
show_common_info(vid, "checkout:", 1, 1);
266266
}
267267
db_record_repository_filename(0);
268268
print_changes(useSha1sum, showHdr, verboseFlag, cwdRelative);
269269
}
270
+
271
+/*
272
+** Take care of -r version of ls command
273
+*/
274
+static void ls_cmd_rev(
275
+ const char *zRev, /* Revision string given */
276
+ int verboseFlag, /* Verbose flag given */
277
+ int showAge, /* Age flag given */
278
+ int timeOrder /* Order by time flag given */
279
+){
280
+ Stmt q;
281
+ char *zOrderBy = "pathname COLLATE nocase";
282
+ char *zName;
283
+ Blob where;
284
+ int rid;
285
+ int i;
286
+
287
+ /* Handle given file names */
288
+ blob_zero(&where);
289
+ for(i=2; i<g.argc; i++){
290
+ Blob fname;
291
+ file_tree_name(g.argv[i], &fname, 1);
292
+ zName = blob_str(&fname);
293
+ if( fossil_strcmp(zName, ".")==0 ) {
294
+ blob_reset(&where);
295
+ break;
296
+ }
297
+ blob_append_sql(&where,
298
+ " %s (pathname=%Q %s) "
299
+ "OR (pathname>'%q/' %s AND pathname<'%q0' %s)",
300
+ (blob_size(&where)>0) ? "OR" : "AND (", zName,
301
+ filename_collation(), zName, filename_collation(),
302
+ zName, filename_collation()
303
+ );
304
+ }
305
+ if( blob_size(&where)>0 ){
306
+ blob_append_sql(&where, ")");
307
+ }
308
+
309
+ rid = symbolic_name_to_rid(zRev, "ci");
310
+ if( rid==0 ){
311
+ fossil_fatal("not a valid check-in: %s", zRev);
312
+ }
313
+
314
+ if( timeOrder ){
315
+ zOrderBy = "mtime DESC";
316
+ }
317
+
318
+ compute_fileage(rid,0);
319
+ db_prepare(&q,
320
+ "SELECT datetime(fileage.mtime, 'localtime'), fileage.pathname,\n"
321
+ " blob.size\n"
322
+ " FROM fileage, blob\n"
323
+ " WHERE blob.rid=fileage.fid %s\n"
324
+ " ORDER BY %s;", blob_sql_text(&where), zOrderBy /*safe-for-%s*/
325
+ );
326
+ blob_reset(&where);
327
+
328
+ while( db_step(&q)==SQLITE_ROW ){
329
+ const char *zTime = db_column_text(&q,0);
330
+ const char *zFile = db_column_text(&q,1);
331
+ int size = db_column_int(&q,2);
332
+ if( verboseFlag ){
333
+ fossil_print("%s %7d %s\n", zTime, size, zFile);
334
+ }else if( showAge ){
335
+ fossil_print("%s %s\n", zTime, zFile);
336
+ }else{
337
+ fossil_print("%s\n", zFile);
338
+ }
339
+ }
340
+ db_finalize(&q);
341
+}
270342
271343
/*
272344
** COMMAND: ls
273345
**
274
-** Usage: %fossil ls ?OPTIONS? ?VERSION? ?FILENAMES?
346
+** Usage: %fossil ls ?OPTIONS? ?FILENAMES?
275347
**
276348
** Show the names of all files in the current checkout. The -v provides
277349
** extra information about each file. If FILENAMES are included, only
278350
** the files listed (or their children if they are directories) are shown.
279351
**
352
+** If -r is given a specific check-in is listed. In this case -R can be
353
+** given to query another repository.
354
+**
280355
** Options:
281
-** --age Show when each file was committed
282
-** -v|--verbose Provide extra information about each file.
356
+** --age Show when each file was committed
357
+** -v|--verbose Provide extra information about each file.
358
+** -t Sort output in time order.
359
+** -r VERSION The specific check-in to list
360
+** -R|--repository FILE Extract info from repository FILE
283361
**
284362
** See also: changes, extras, status
285363
*/
286364
void ls_cmd(void){
287365
int vid;
288366
Stmt q;
289367
int verboseFlag;
290368
int showAge;
369
+ int timeOrder;
291370
char *zOrderBy = "pathname";
292371
Blob where;
293372
int i;
294373
const char *zName;
374
+ const char *zRev;
295375
296376
verboseFlag = find_option("verbose","v", 0)!=0;
297377
if( !verboseFlag ){
298378
verboseFlag = find_option("l","l", 0)!=0; /* deprecated */
299379
}
300380
showAge = find_option("age",0,0)!=0;
381
+ zRev = find_option("r","r",1);
382
+ timeOrder = find_option("t","t",0)!=0;
383
+
384
+ if( zRev!=0 ){
385
+ db_find_and_open_repository(0, 0);
386
+ verify_all_options();
387
+ ls_cmd_rev(zRev,verboseFlag,showAge,timeOrder);
388
+ return;
389
+ }
390
+
301391
db_must_be_within_tree();
302392
vid = db_lget_int("checkout", 0);
303
- if( find_option("t","t",0)!=0 ){
393
+ if( timeOrder ){
304394
if( showAge ){
305395
zOrderBy = mprintf("checkin_mtime(%d,rid) DESC", vid);
306396
}else{
307397
zOrderBy = "mtime DESC";
308398
}
309399
--- src/checkin.c
+++ src/checkin.c
@@ -265,44 +265,134 @@
265 show_common_info(vid, "checkout:", 1, 1);
266 }
267 db_record_repository_filename(0);
268 print_changes(useSha1sum, showHdr, verboseFlag, cwdRelative);
269 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
270
271 /*
272 ** COMMAND: ls
273 **
274 ** Usage: %fossil ls ?OPTIONS? ?VERSION? ?FILENAMES?
275 **
276 ** Show the names of all files in the current checkout. The -v provides
277 ** extra information about each file. If FILENAMES are included, only
278 ** the files listed (or their children if they are directories) are shown.
279 **
 
 
 
280 ** Options:
281 ** --age Show when each file was committed
282 ** -v|--verbose Provide extra information about each file.
 
 
 
283 **
284 ** See also: changes, extras, status
285 */
286 void ls_cmd(void){
287 int vid;
288 Stmt q;
289 int verboseFlag;
290 int showAge;
 
291 char *zOrderBy = "pathname";
292 Blob where;
293 int i;
294 const char *zName;
 
295
296 verboseFlag = find_option("verbose","v", 0)!=0;
297 if( !verboseFlag ){
298 verboseFlag = find_option("l","l", 0)!=0; /* deprecated */
299 }
300 showAge = find_option("age",0,0)!=0;
 
 
 
 
 
 
 
 
 
 
301 db_must_be_within_tree();
302 vid = db_lget_int("checkout", 0);
303 if( find_option("t","t",0)!=0 ){
304 if( showAge ){
305 zOrderBy = mprintf("checkin_mtime(%d,rid) DESC", vid);
306 }else{
307 zOrderBy = "mtime DESC";
308 }
309
--- src/checkin.c
+++ src/checkin.c
@@ -265,44 +265,134 @@
265 show_common_info(vid, "checkout:", 1, 1);
266 }
267 db_record_repository_filename(0);
268 print_changes(useSha1sum, showHdr, verboseFlag, cwdRelative);
269 }
270
271 /*
272 ** Take care of -r version of ls command
273 */
274 static void ls_cmd_rev(
275 const char *zRev, /* Revision string given */
276 int verboseFlag, /* Verbose flag given */
277 int showAge, /* Age flag given */
278 int timeOrder /* Order by time flag given */
279 ){
280 Stmt q;
281 char *zOrderBy = "pathname COLLATE nocase";
282 char *zName;
283 Blob where;
284 int rid;
285 int i;
286
287 /* Handle given file names */
288 blob_zero(&where);
289 for(i=2; i<g.argc; i++){
290 Blob fname;
291 file_tree_name(g.argv[i], &fname, 1);
292 zName = blob_str(&fname);
293 if( fossil_strcmp(zName, ".")==0 ) {
294 blob_reset(&where);
295 break;
296 }
297 blob_append_sql(&where,
298 " %s (pathname=%Q %s) "
299 "OR (pathname>'%q/' %s AND pathname<'%q0' %s)",
300 (blob_size(&where)>0) ? "OR" : "AND (", zName,
301 filename_collation(), zName, filename_collation(),
302 zName, filename_collation()
303 );
304 }
305 if( blob_size(&where)>0 ){
306 blob_append_sql(&where, ")");
307 }
308
309 rid = symbolic_name_to_rid(zRev, "ci");
310 if( rid==0 ){
311 fossil_fatal("not a valid check-in: %s", zRev);
312 }
313
314 if( timeOrder ){
315 zOrderBy = "mtime DESC";
316 }
317
318 compute_fileage(rid,0);
319 db_prepare(&q,
320 "SELECT datetime(fileage.mtime, 'localtime'), fileage.pathname,\n"
321 " blob.size\n"
322 " FROM fileage, blob\n"
323 " WHERE blob.rid=fileage.fid %s\n"
324 " ORDER BY %s;", blob_sql_text(&where), zOrderBy /*safe-for-%s*/
325 );
326 blob_reset(&where);
327
328 while( db_step(&q)==SQLITE_ROW ){
329 const char *zTime = db_column_text(&q,0);
330 const char *zFile = db_column_text(&q,1);
331 int size = db_column_int(&q,2);
332 if( verboseFlag ){
333 fossil_print("%s %7d %s\n", zTime, size, zFile);
334 }else if( showAge ){
335 fossil_print("%s %s\n", zTime, zFile);
336 }else{
337 fossil_print("%s\n", zFile);
338 }
339 }
340 db_finalize(&q);
341 }
342
343 /*
344 ** COMMAND: ls
345 **
346 ** Usage: %fossil ls ?OPTIONS? ?FILENAMES?
347 **
348 ** Show the names of all files in the current checkout. The -v provides
349 ** extra information about each file. If FILENAMES are included, only
350 ** the files listed (or their children if they are directories) are shown.
351 **
352 ** If -r is given a specific check-in is listed. In this case -R can be
353 ** given to query another repository.
354 **
355 ** Options:
356 ** --age Show when each file was committed
357 ** -v|--verbose Provide extra information about each file.
358 ** -t Sort output in time order.
359 ** -r VERSION The specific check-in to list
360 ** -R|--repository FILE Extract info from repository FILE
361 **
362 ** See also: changes, extras, status
363 */
364 void ls_cmd(void){
365 int vid;
366 Stmt q;
367 int verboseFlag;
368 int showAge;
369 int timeOrder;
370 char *zOrderBy = "pathname";
371 Blob where;
372 int i;
373 const char *zName;
374 const char *zRev;
375
376 verboseFlag = find_option("verbose","v", 0)!=0;
377 if( !verboseFlag ){
378 verboseFlag = find_option("l","l", 0)!=0; /* deprecated */
379 }
380 showAge = find_option("age",0,0)!=0;
381 zRev = find_option("r","r",1);
382 timeOrder = find_option("t","t",0)!=0;
383
384 if( zRev!=0 ){
385 db_find_and_open_repository(0, 0);
386 verify_all_options();
387 ls_cmd_rev(zRev,verboseFlag,showAge,timeOrder);
388 return;
389 }
390
391 db_must_be_within_tree();
392 vid = db_lget_int("checkout", 0);
393 if( timeOrder ){
394 if( showAge ){
395 zOrderBy = mprintf("checkin_mtime(%d,rid) DESC", vid);
396 }else{
397 zOrderBy = "mtime DESC";
398 }
399
+94 -4
--- src/checkin.c
+++ src/checkin.c
@@ -265,44 +265,134 @@
265265
show_common_info(vid, "checkout:", 1, 1);
266266
}
267267
db_record_repository_filename(0);
268268
print_changes(useSha1sum, showHdr, verboseFlag, cwdRelative);
269269
}
270
+
271
+/*
272
+** Take care of -r version of ls command
273
+*/
274
+static void ls_cmd_rev(
275
+ const char *zRev, /* Revision string given */
276
+ int verboseFlag, /* Verbose flag given */
277
+ int showAge, /* Age flag given */
278
+ int timeOrder /* Order by time flag given */
279
+){
280
+ Stmt q;
281
+ char *zOrderBy = "pathname COLLATE nocase";
282
+ char *zName;
283
+ Blob where;
284
+ int rid;
285
+ int i;
286
+
287
+ /* Handle given file names */
288
+ blob_zero(&where);
289
+ for(i=2; i<g.argc; i++){
290
+ Blob fname;
291
+ file_tree_name(g.argv[i], &fname, 1);
292
+ zName = blob_str(&fname);
293
+ if( fossil_strcmp(zName, ".")==0 ) {
294
+ blob_reset(&where);
295
+ break;
296
+ }
297
+ blob_append_sql(&where,
298
+ " %s (pathname=%Q %s) "
299
+ "OR (pathname>'%q/' %s AND pathname<'%q0' %s)",
300
+ (blob_size(&where)>0) ? "OR" : "AND (", zName,
301
+ filename_collation(), zName, filename_collation(),
302
+ zName, filename_collation()
303
+ );
304
+ }
305
+ if( blob_size(&where)>0 ){
306
+ blob_append_sql(&where, ")");
307
+ }
308
+
309
+ rid = symbolic_name_to_rid(zRev, "ci");
310
+ if( rid==0 ){
311
+ fossil_fatal("not a valid check-in: %s", zRev);
312
+ }
313
+
314
+ if( timeOrder ){
315
+ zOrderBy = "mtime DESC";
316
+ }
317
+
318
+ compute_fileage(rid,0);
319
+ db_prepare(&q,
320
+ "SELECT datetime(fileage.mtime, 'localtime'), fileage.pathname,\n"
321
+ " blob.size\n"
322
+ " FROM fileage, blob\n"
323
+ " WHERE blob.rid=fileage.fid %s\n"
324
+ " ORDER BY %s;", blob_sql_text(&where), zOrderBy /*safe-for-%s*/
325
+ );
326
+ blob_reset(&where);
327
+
328
+ while( db_step(&q)==SQLITE_ROW ){
329
+ const char *zTime = db_column_text(&q,0);
330
+ const char *zFile = db_column_text(&q,1);
331
+ int size = db_column_int(&q,2);
332
+ if( verboseFlag ){
333
+ fossil_print("%s %7d %s\n", zTime, size, zFile);
334
+ }else if( showAge ){
335
+ fossil_print("%s %s\n", zTime, zFile);
336
+ }else{
337
+ fossil_print("%s\n", zFile);
338
+ }
339
+ }
340
+ db_finalize(&q);
341
+}
270342
271343
/*
272344
** COMMAND: ls
273345
**
274
-** Usage: %fossil ls ?OPTIONS? ?VERSION? ?FILENAMES?
346
+** Usage: %fossil ls ?OPTIONS? ?FILENAMES?
275347
**
276348
** Show the names of all files in the current checkout. The -v provides
277349
** extra information about each file. If FILENAMES are included, only
278350
** the files listed (or their children if they are directories) are shown.
279351
**
352
+** If -r is given a specific check-in is listed. In this case -R can be
353
+** given to query another repository.
354
+**
280355
** Options:
281
-** --age Show when each file was committed
282
-** -v|--verbose Provide extra information about each file.
356
+** --age Show when each file was committed
357
+** -v|--verbose Provide extra information about each file.
358
+** -t Sort output in time order.
359
+** -r VERSION The specific check-in to list
360
+** -R|--repository FILE Extract info from repository FILE
283361
**
284362
** See also: changes, extras, status
285363
*/
286364
void ls_cmd(void){
287365
int vid;
288366
Stmt q;
289367
int verboseFlag;
290368
int showAge;
369
+ int timeOrder;
291370
char *zOrderBy = "pathname";
292371
Blob where;
293372
int i;
294373
const char *zName;
374
+ const char *zRev;
295375
296376
verboseFlag = find_option("verbose","v", 0)!=0;
297377
if( !verboseFlag ){
298378
verboseFlag = find_option("l","l", 0)!=0; /* deprecated */
299379
}
300380
showAge = find_option("age",0,0)!=0;
381
+ zRev = find_option("r","r",1);
382
+ timeOrder = find_option("t","t",0)!=0;
383
+
384
+ if( zRev!=0 ){
385
+ db_find_and_open_repository(0, 0);
386
+ verify_all_options();
387
+ ls_cmd_rev(zRev,verboseFlag,showAge,timeOrder);
388
+ return;
389
+ }
390
+
301391
db_must_be_within_tree();
302392
vid = db_lget_int("checkout", 0);
303
- if( find_option("t","t",0)!=0 ){
393
+ if( timeOrder ){
304394
if( showAge ){
305395
zOrderBy = mprintf("checkin_mtime(%d,rid) DESC", vid);
306396
}else{
307397
zOrderBy = "mtime DESC";
308398
}
309399
--- src/checkin.c
+++ src/checkin.c
@@ -265,44 +265,134 @@
265 show_common_info(vid, "checkout:", 1, 1);
266 }
267 db_record_repository_filename(0);
268 print_changes(useSha1sum, showHdr, verboseFlag, cwdRelative);
269 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
270
271 /*
272 ** COMMAND: ls
273 **
274 ** Usage: %fossil ls ?OPTIONS? ?VERSION? ?FILENAMES?
275 **
276 ** Show the names of all files in the current checkout. The -v provides
277 ** extra information about each file. If FILENAMES are included, only
278 ** the files listed (or their children if they are directories) are shown.
279 **
 
 
 
280 ** Options:
281 ** --age Show when each file was committed
282 ** -v|--verbose Provide extra information about each file.
 
 
 
283 **
284 ** See also: changes, extras, status
285 */
286 void ls_cmd(void){
287 int vid;
288 Stmt q;
289 int verboseFlag;
290 int showAge;
 
291 char *zOrderBy = "pathname";
292 Blob where;
293 int i;
294 const char *zName;
 
295
296 verboseFlag = find_option("verbose","v", 0)!=0;
297 if( !verboseFlag ){
298 verboseFlag = find_option("l","l", 0)!=0; /* deprecated */
299 }
300 showAge = find_option("age",0,0)!=0;
 
 
 
 
 
 
 
 
 
 
301 db_must_be_within_tree();
302 vid = db_lget_int("checkout", 0);
303 if( find_option("t","t",0)!=0 ){
304 if( showAge ){
305 zOrderBy = mprintf("checkin_mtime(%d,rid) DESC", vid);
306 }else{
307 zOrderBy = "mtime DESC";
308 }
309
--- src/checkin.c
+++ src/checkin.c
@@ -265,44 +265,134 @@
265 show_common_info(vid, "checkout:", 1, 1);
266 }
267 db_record_repository_filename(0);
268 print_changes(useSha1sum, showHdr, verboseFlag, cwdRelative);
269 }
270
271 /*
272 ** Take care of -r version of ls command
273 */
274 static void ls_cmd_rev(
275 const char *zRev, /* Revision string given */
276 int verboseFlag, /* Verbose flag given */
277 int showAge, /* Age flag given */
278 int timeOrder /* Order by time flag given */
279 ){
280 Stmt q;
281 char *zOrderBy = "pathname COLLATE nocase";
282 char *zName;
283 Blob where;
284 int rid;
285 int i;
286
287 /* Handle given file names */
288 blob_zero(&where);
289 for(i=2; i<g.argc; i++){
290 Blob fname;
291 file_tree_name(g.argv[i], &fname, 1);
292 zName = blob_str(&fname);
293 if( fossil_strcmp(zName, ".")==0 ) {
294 blob_reset(&where);
295 break;
296 }
297 blob_append_sql(&where,
298 " %s (pathname=%Q %s) "
299 "OR (pathname>'%q/' %s AND pathname<'%q0' %s)",
300 (blob_size(&where)>0) ? "OR" : "AND (", zName,
301 filename_collation(), zName, filename_collation(),
302 zName, filename_collation()
303 );
304 }
305 if( blob_size(&where)>0 ){
306 blob_append_sql(&where, ")");
307 }
308
309 rid = symbolic_name_to_rid(zRev, "ci");
310 if( rid==0 ){
311 fossil_fatal("not a valid check-in: %s", zRev);
312 }
313
314 if( timeOrder ){
315 zOrderBy = "mtime DESC";
316 }
317
318 compute_fileage(rid,0);
319 db_prepare(&q,
320 "SELECT datetime(fileage.mtime, 'localtime'), fileage.pathname,\n"
321 " blob.size\n"
322 " FROM fileage, blob\n"
323 " WHERE blob.rid=fileage.fid %s\n"
324 " ORDER BY %s;", blob_sql_text(&where), zOrderBy /*safe-for-%s*/
325 );
326 blob_reset(&where);
327
328 while( db_step(&q)==SQLITE_ROW ){
329 const char *zTime = db_column_text(&q,0);
330 const char *zFile = db_column_text(&q,1);
331 int size = db_column_int(&q,2);
332 if( verboseFlag ){
333 fossil_print("%s %7d %s\n", zTime, size, zFile);
334 }else if( showAge ){
335 fossil_print("%s %s\n", zTime, zFile);
336 }else{
337 fossil_print("%s\n", zFile);
338 }
339 }
340 db_finalize(&q);
341 }
342
343 /*
344 ** COMMAND: ls
345 **
346 ** Usage: %fossil ls ?OPTIONS? ?FILENAMES?
347 **
348 ** Show the names of all files in the current checkout. The -v provides
349 ** extra information about each file. If FILENAMES are included, only
350 ** the files listed (or their children if they are directories) are shown.
351 **
352 ** If -r is given a specific check-in is listed. In this case -R can be
353 ** given to query another repository.
354 **
355 ** Options:
356 ** --age Show when each file was committed
357 ** -v|--verbose Provide extra information about each file.
358 ** -t Sort output in time order.
359 ** -r VERSION The specific check-in to list
360 ** -R|--repository FILE Extract info from repository FILE
361 **
362 ** See also: changes, extras, status
363 */
364 void ls_cmd(void){
365 int vid;
366 Stmt q;
367 int verboseFlag;
368 int showAge;
369 int timeOrder;
370 char *zOrderBy = "pathname";
371 Blob where;
372 int i;
373 const char *zName;
374 const char *zRev;
375
376 verboseFlag = find_option("verbose","v", 0)!=0;
377 if( !verboseFlag ){
378 verboseFlag = find_option("l","l", 0)!=0; /* deprecated */
379 }
380 showAge = find_option("age",0,0)!=0;
381 zRev = find_option("r","r",1);
382 timeOrder = find_option("t","t",0)!=0;
383
384 if( zRev!=0 ){
385 db_find_and_open_repository(0, 0);
386 verify_all_options();
387 ls_cmd_rev(zRev,verboseFlag,showAge,timeOrder);
388 return;
389 }
390
391 db_must_be_within_tree();
392 vid = db_lget_int("checkout", 0);
393 if( timeOrder ){
394 if( showAge ){
395 zOrderBy = mprintf("checkin_mtime(%d,rid) DESC", vid);
396 }else{
397 zOrderBy = "mtime DESC";
398 }
399

Keyboard Shortcuts

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