Fossil

Changes On Branch c79e8c9301ceb138
Login

Changes On Branch c79e8c9301ceb138

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch usage-command Through [c79e8c9301] Excluding Merge-Ins

This is equivalent to a diff from c66ee0d667 to c79e8c9301

2013-09-08
07:13
Pulled in latest upstream JSON_parser(), which has an MIT license instead of BSD+do-no-evil clause. ... (check-in: e2975b71f1 user: stephan tags: usage-command)
2013-09-06
22:18
On Cygwin, when editing with Notepad, make sure it starts with the UTF-8 BOM. ... (check-in: 3e90ef61f3 user: jan.nijtmans tags: trunk)
18:23
merged trunk ... (check-in: c79e8c9301 user: stephan tags: usage-command)
18:17
slight change to the assertions in the latin1 workaround. Nothing functional. ... (check-in: c66ee0d667 user: stephan tags: trunk)
18:09
pulled in a minor (doc) cleanup for the latin1 workaround. ... (check-in: 339f9f324f user: stephan tags: trunk)
2013-09-05
20:30
merged in trunk ... (check-in: 8124aa4a2a user: stephan tags: usage-command)

Changes to src/main.c.
503
504
505
506
507
508
509

























































































510
511
512
513
514
515
516
    case SQLITE_WARNING:    return "SQLITE_WARNING";
    default: {
      sqlite3_snprintf(sizeof(zCode),zCode,"error code %d",iCode);
    }
  }
  return zCode;
}


























































































/* Error logs from SQLite */
static void fossil_sqlite_log(void *notUsed, int iCode, const char *zErrmsg){
#ifdef __APPLE__
  /* Disable the file alias warning on apple products because Time Machine
  ** creates lots of aliases and the warning alarms people. */
  if( iCode==SQLITE_WARNING ) return;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







503
504
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
597
598
599
600
601
602
603
604
605
    case SQLITE_WARNING:    return "SQLITE_WARNING";
    default: {
      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 an opened 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;
  if(!db_open_local(0)){
    fossil_fatal("'usage' requires a checkout.");
  }
  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");
  }
}

/* Error logs from SQLite */
static void fossil_sqlite_log(void *notUsed, int iCode, const char *zErrmsg){
#ifdef __APPLE__
  /* Disable the file alias warning on apple products because Time Machine
  ** creates lots of aliases and the warning alarms people. */
  if( iCode==SQLITE_WARNING ) return;
633
634
635
636
637
638
639

640
641
642
643
644
645
646
                 "%s: could be any of:%s\n"
                 "%s: use \"help\" for more information\n",
                 g.argv[0], zCmdName, g.argv[0], blob_str(&couldbe), g.argv[0]);
    fossil_exit(1);
  }
  atexit( fossil_atexit );
  aCommand[idx].xFunc();

  fossil_exit(0);
  /*NOT_REACHED*/
  return 0;
}

/*
** Print a usage comment and quit







>







722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
                 "%s: could be any of:%s\n"
                 "%s: use \"help\" for more information\n",
                 g.argv[0], zCmdName, g.argv[0], blob_str(&couldbe), g.argv[0]);
    fossil_exit(1);
  }
  atexit( fossil_atexit );
  aCommand[idx].xFunc();
  update_cmd_usage_stats(aCommand[idx].zName);
  fossil_exit(0);
  /*NOT_REACHED*/
  return 0;
}

/*
** Print a usage comment and quit