Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Added -n|-count ### option to list the most recent (or all) history entries, ordered descending by time. |
|---|---|
| Timelines: | family | ancestors | descendants | both | usage-command |
| Files: | files | file ages | folders |
| SHA1: |
b613c52bc5a48da076162e8f22ab2cba |
| User & Date: | stephan 2013-09-03 21:51:25.562 |
Context
|
2013-09-03
| ||
| 22:01 | Added a missing error code check - now properly fails if no checkout is available (e.g. when called using -R repofile). check-in: f550bdc7b9 user: stephan tags: usage-command | |
| 21:51 | Added -n|-count ### option to list the most recent (or all) history entries, ordered descending by time. check-in: b613c52bc5 user: stephan tags: usage-command | |
| 20:15 | Fixed the is-this-server-mode check to avoid updating cmd_usage stats in server/ui mode even if there is a local checkout. check-in: e11bec70ef user: stephan tags: usage-command | |
Changes
Changes to src/main.c.
| ︙ | ︙ | |||
505 506 507 508 509 510 511 |
sqlite3_snprintf(sizeof(zCode),zCode,"error code %d",iCode);
}
}
return zCode;
}
static void update_cmd_usage_stats(char const * zCommand){
| | | > | > > > > > > | > > | > > > > | | | > > > > > > > | | > > > > > > | | > | 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 |
sqlite3_snprintf(sizeof(zCode),zCode,"error code %d",iCode);
}
}
return zCode;
}
static void update_cmd_usage_stats(char const * zCommand){
if(!g.localOpen || g.isHTTP) return
/* we need a checkout and do not want to log the 'ui' bits forked
by local ui mode.*/;
db_multi_exec("CREATE TABLE IF NOT EXISTS "
"cmd_usage (name TEXT,mtime FLOAT);"
"INSERT INTO cmd_usage (name,mtime) VALUES (%Q,julianday('now'));",
zCommand);
}
/*
** COMMAND: usage*
**
** Usage: %fossil usage [-clear|-c] [-n|-count ###]
**
** Reports or clears information from the local checkout's cmd_usage
** table (if any). The cmd_usage table is updated each time a fossil
** CLI command succeeds (returns). The db has (name TEXT, mtime FLOAT
** (Julian Day)) fields for collecting statistics about usage. This
** information is stored in the local checkout db and is not
** synchronized.
**
** The -n|-count ### option changes the output to list the last ###
** commands used, ordered by time (most recent first). A value of 0
** means "no limit", and lists all history for the checkout. If the
** ### value is negative, it is ignored (treated as if -n had not been
** specified).
*/
void usage_cmd(){
int rc;
Stmt q;
int i = 0;
int fClear = find_option("clear","c",0)!=0;
char const *zLimit = find_option("n","count",1);
int fLimit = zLimit ? atoi(zLimit) : -1;
char const * sql;
db_open_local(0);
if(fLimit>=0){
sql = "SELECT name, strftime('%%Y-%%m-%%d %%H:%%M:%%S',mtime) "
"FROM cmd_usage ORDER BY mtime DESC";
}else{
sql = "SELECT name, count(*) AS n "
"FROM cmd_usage GROUP BY name "
"ORDER BY n DESC";
}
rc = db_prepare_ignore_error(&q,sql);
if(rc){
/* Assume missing cmd_usage table. */
fossil_print("(An sqlite error message is normal the first time "
"this is run for a given checkout!)\n"
"No command usage history has been collected "
"for this checkout.\n");
return;
}
if(fClear){
db_multi_exec("DELETE FROM cmd_usage;");
fossil_print("Usage history cleared.\n");
db_finalize(&q);
return;
}
if(fLimit>=0){
if(fLimit>0) fossil_print("Most recent %d CLI command(s):\n", fLimit);
else fossil_print("All CLI command history:\n");
fossil_print("Time Command\n");
}else{
fossil_print("CLI command usage history for this checkout:\n");
fossil_print("Count Command\n");
}
while(SQLITE_ROW==db_step(&q)){
++i;
if(fLimit>=0){
fossil_print("%s %s\n", db_column_text(&q, 1),
db_column_text(&q,0));
if(i==fLimit) break;
}else{
fossil_print("%5d %s\n", db_column_int(&q, 1),
db_column_text(&q,0));
}
}
db_finalize(&q);
if(!i){
fossil_print("No command usage history has been collected "
"for this checkout.\n");
}
}
|
| ︙ | ︙ |