Fossil

Changes On Branch usage-command
Login

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

Changes In Branch usage-command Excluding Merge-Ins

This is equivalent to a diff from da96f916cb to 4fb3675a1a

2013-09-27
14:41
The various "diff --tk" commands now take an optional, undocumented option "--script FILENAME" that causes the Tk script to be written into FILENAME rather than to be run. One use for this is to get a copy of the diff script in a form were it can be easily edited and enhanced before being moved back into Fossil. ... (check-in: 326a736493 user: drh tags: tkdiff-enhancements)
2013-09-25
23:56
Add formal unloading support to the Tcl integration subsystem. This is necessary to prevent a deadlock while exiting the process when Tcl is loaded. Add runtime detection of the ability to directly invoke an objProc for a Tcl command. Support USE_TCL_STUBS define in the version information. ... (check-in: 6b58c67ed8 user: mistachkin tags: trunk)
08:29
FOSSIL_ENABLE_TCL_PRIVATE_STUBS only makes sense when USE_TCL_STUBS is defined as well. Use that consistantly in the code. Easier testing whether Tcl integration works fine, just by "fossil version -v". ... (check-in: 0038f4c999 user: jan.nijtmans tags: pending-review)
2013-09-24
16:11
merged in trunk ... (Closed-Leaf check-in: 4fb3675a1a user: stephan tags: usage-command)
2013-09-23
12:09
Loading Tcl 8.4 only works when USE_TCL_EVALOBJV=1. Reason: the function Tcl_GetCommandFromObj is introduced in Tcl 8.5 (TIP #139). Actually, the source code history for Tcl indicates that this is not correct. Both Tcl_GetCommandFromObj and Tcl_GetCommandInfoFromToken are present for Tcl 8.4. The Tcl_GetCommandInfoFromToken function was added in TIP #32 and the Tcl_GetCommandFromObj function exists since the initial check-in in the Tcl repository, circa 1998. ... (Closed-Leaf check-in: 2234fabe76 user: jan.nijtmans tags: support-tcl84-stubs)
10:17
Prevent a crash in fossil during exit, when a mingw-compiled (with dw2) Tcl version is still loaded. This is clearly a dw2 bug (see: [http://comments.gmane.org/gmane.comp.gnu.mingw.user/41724]), but the suggested workaround works and is managable. ... (check-in: da96f916cb user: jan.nijtmans tags: trunk)
2013-09-19
18:36
Per feedback, further improve the Tcl shared library error message. ... (check-in: aad3ef3288 user: mistachkin tags: trunk)
08:10
merged in trunk ... (check-in: d3e4ef94b4 user: stephan tags: usage-command)
2013-09-11
19:53
minor typo fix, no code changes. ... (check-in: bd7daa1f2d user: stephan tags: trunk)

Changes to src/main.c.
514
515
516
517
518
519
520

























































































521
522
523
524
525
526
527
    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;







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







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
606
607
608
609
610
611
612
613
614
615
616
    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;
644
645
646
647
648
649
650

651
652
653
654
655
656
657
                 "%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







>







733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
                 "%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