Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Add the TH1 'dir' command, with docs and tests. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA1: |
f4ceace8f574c0350948c7d630af8923 |
| User & Date: | mistachkin 2015-08-27 04:38:02.033 |
Context
|
2015-08-27
| ||
| 04:39 | Update TH1 'dir' command syntax in docs. ... (check-in: 73960e0de5 user: mistachkin tags: trunk) | |
| 04:38 | Add the TH1 'dir' command, with docs and tests. ... (check-in: f4ceace8f5 user: mistachkin tags: trunk) | |
|
2015-08-26
| ||
| 19:49 | Regenerate and sync-up MinGW makefiles. ... (check-in: e947fce957 user: mistachkin tags: trunk) | |
|
2015-08-21
| ||
| 04:33 | Merge updates from trunk. ... (Closed-Leaf check-in: bf380d4b5b user: mistachkin tags: ckol-th1-dir-cmd) | |
Changes
Changes to src/doc.c.
| ︙ | ︙ | |||
520 521 522 523 524 525 526 | ** ** The "ckout" CHECKIN is intended for development - to provide a mechanism ** for looking at what a file will look like using the /doc webpage after ** it gets checked in. ** ** The file extension is used to decide how to render the file. ** | | | > > | | > > > | 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 |
**
** The "ckout" CHECKIN is intended for development - to provide a mechanism
** for looking at what a file will look like using the /doc webpage after
** it gets checked in.
**
** The file extension is used to decide how to render the file.
**
** If FILE ends in "/" then the names "FILE/index.html", "FILE/index.wiki",
** and "FILE/index.md" are tried in that order. If the binary was compiled
** with TH1 embedded documentation support and the "th1-docs" setting is
** enabled, the name "FILE/index.th1" is also tried. If none of those are
** found, then FILE is completely replaced by "404.md" and tried. If that
** is not found, then a default 404 screen is generated.
*/
void doc_page(void){
const char *zName; /* Argument to the /doc page */
const char *zOrigName = "?"; /* Original document name */
const char *zMime; /* Document MIME type */
char *zCheckin = "tip"; /* The check-in holding the document */
int vid = 0; /* Artifact of check-in */
int rid = 0; /* Artifact of file */
int i; /* Loop counter */
Blob filebody; /* Content of the documentation file */
Blob title; /* Document title */
int nMiss = (-1); /* Failed attempts to find the document */
static const char *const azSuffix[] = {
"index.html", "index.wiki", "index.md"
#ifdef FOSSIL_ENABLE_TH1_DOCS
, "index.th1"
#endif
};
login_check_credentials();
if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
blob_init(&title, 0, 0);
db_begin_transaction();
while( rid==0 && (++nMiss)<=ArraySize(azSuffix) ){
|
| ︙ | ︙ |
Changes to src/th_main.c.
| ︙ | ︙ | |||
140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
void Th_PrintTraceLog(){
if( g.thTrace ){
fossil_print("\n------------------ BEGIN TRACE LOG ------------------\n");
fossil_print("%s", blob_str(&g.thLog));
fossil_print("\n------------------- END TRACE LOG -------------------\n");
}
}
/*
** TH1 command: httpize STRING
**
** Escape all characters of STRING which have special meaning in URI
** components. Return a new string result.
*/
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
void Th_PrintTraceLog(){
if( g.thTrace ){
fossil_print("\n------------------ BEGIN TRACE LOG ------------------\n");
fossil_print("%s", blob_str(&g.thLog));
fossil_print("\n------------------- END TRACE LOG -------------------\n");
}
}
/*
** - adopted from ls_cmd_rev in checkin.c
** - adopted commands/error handling for usage within th1
** - interface adopted to allow result creation as TH1 List
**
** Takes a checkin identifier in zRev and an optiona glob pattern in zGLOB
** as parameter returns a TH list in pzList,pnList with filenames matching
** glob pattern with the checking
*/
static void dir_cmd_rev(
Th_Interp *interp,
char **pzList,
int *pnList,
const char *zRev, /* Revision string given */
const char *zGlob, /* Glob pattern given */
int bDetails
){
Stmt q;
char *zOrderBy = "pathname COLLATE nocase";
int rid;
rid = th1_name_to_typed_rid(interp, zRev, "ci");
compute_fileage(rid, zGlob);
db_prepare(&q,
"SELECT datetime(fileage.mtime, 'localtime'), fileage.pathname,\n"
" blob.size\n"
" FROM fileage, blob\n"
" WHERE blob.rid=fileage.fid \n"
" ORDER BY %s;", zOrderBy /*safe-for-%s*/
);
while( db_step(&q)==SQLITE_ROW ){
const char *zFile = db_column_text(&q, 1);
if( bDetails ){
const char *zTime = db_column_text(&q, 0);
int size = db_column_int(&q, 2);
char zSize[50];
char *zSubList = 0;
int nSubList = 0;
sqlite3_snprintf(sizeof(zSize), zSize, "%d", size);
Th_ListAppend(interp, &zSubList, &nSubList, zFile, -1);
Th_ListAppend(interp, &zSubList, &nSubList, zSize, -1);
Th_ListAppend(interp, &zSubList, &nSubList, zTime, -1);
Th_ListAppend(interp, pzList, pnList, zSubList, -1);
Th_Free(interp, zSubList);
}else{
Th_ListAppend(interp, pzList, pnList, zFile, -1);
}
}
db_finalize(&q);
}
/*
** TH1 command: dir CHECKIN ?GLOB? ?DETAILS?
**
** Returns a list containing all files in CHECKIN. If GLOB is given only
** the files matching the pattern GLOB within CHECKIN will be returned.
** If DETAILS is non-zero, the result will be a list-of-lists, with each
** element containing at least three elements: the file name, the file
** size (in bytes), and the file last modification time (relative to the
** time zone configured for the repository).
*/
static int dirCmd(
Th_Interp *interp,
void *ctx,
int argc,
const char **argv,
int *argl
){
const char *zGlob = 0;
int bDetails = 0;
if( argc<2 || argc>4 ){
return Th_WrongNumArgs(interp, "dir CHECKIN ?GLOB? ?DETAILS?");
}
if( argc>=3 ){
zGlob = argv[2];
}
if( argc>=4 && Th_ToInt(interp, argv[3], argl[3], &bDetails) ){
return TH_ERROR;
}
if( Th_IsRepositoryOpen() ){
char *zList = 0;
int nList = 0;
dir_cmd_rev(interp, &zList, &nList, argv[1], zGlob, bDetails);
Th_SetResult(interp, zList, nList);
Th_Free(interp, zList);
return TH_OK;
}else{
Th_SetResult(interp, "repository unavailable", -1);
return TH_ERROR;
}
}
/*
** TH1 command: httpize STRING
**
** Escape all characters of STRING which have special meaning in URI
** components. Return a new string result.
*/
|
| ︙ | ︙ | |||
1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 |
{"anoncap", hascapCmd, (void*)&anonFlag},
{"anycap", anycapCmd, 0},
{"artifact", artifactCmd, 0},
{"checkout", checkoutCmd, 0},
{"combobox", comboboxCmd, 0},
{"date", dateCmd, 0},
{"decorate", wikiCmd, (void*)&aFlags[2]},
{"enable_output", enableOutputCmd, 0},
{"getParameter", getParameterCmd, 0},
{"glob_match", globMatchCmd, 0},
{"globalState", globalStateCmd, 0},
{"httpize", httpizeCmd, 0},
{"hascap", hascapCmd, (void*)&zeroInt},
{"hasfeature", hasfeatureCmd, 0},
| > | 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 |
{"anoncap", hascapCmd, (void*)&anonFlag},
{"anycap", anycapCmd, 0},
{"artifact", artifactCmd, 0},
{"checkout", checkoutCmd, 0},
{"combobox", comboboxCmd, 0},
{"date", dateCmd, 0},
{"decorate", wikiCmd, (void*)&aFlags[2]},
{"dir", dirCmd, 0},
{"enable_output", enableOutputCmd, 0},
{"getParameter", getParameterCmd, 0},
{"glob_match", globMatchCmd, 0},
{"globalState", globalStateCmd, 0},
{"httpize", httpizeCmd, 0},
{"hascap", hascapCmd, (void*)&zeroInt},
{"hasfeature", hasfeatureCmd, 0},
|
| ︙ | ︙ |
Added test/th1-repo.test.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
#
# Copyright (c) 2011 D. Richard Hipp
# Copyright (c) 2015 Ch. Drexler
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the Simplified BSD License (also
# known as the "2-Clause License" or "FreeBSD License".)
#
# This program is distributed in the hope that it will be useful,
# but without any warranty; without even the implied warranty of
# merchantability or fitness for a particular purpose.
#
# Author contact information:
# drh@hwaci.com
# http://www.hwaci.com/drh/
#
# Chris Drexler <ckolumbus@ac-drexler.de>
#
############################################################################
#
# TH1 tests that may modify the repository
#
catch {exec $::fossilexe info} res
if {![regexp {use --repository} $res]} {
puts stderr "Cannot run this test within an open checkout"
return
}
########################################
# Setup: Add Files and Commit #
########################################
set rootDir [file normalize [pwd]]
repo_init
write_file f1.md "f1"
write_file f2.md "f2"
write_file f3.txt "f3"
write_file f4.md "f4"
file mkdir [file join $rootDir subdirA]
# NOTE: There are no files in subdirA.
file mkdir [file join $rootDir subdirB]
write_file [file join $rootDir subdirB f5.md] "f5"
write_file [file join $rootDir subdirB f6.md] "f6"
write_file [file join $rootDir subdirB f7.txt] "f7"
write_file [file join $rootDir subdirB f8.md] "f8"
write_file [file join $rootDir subdirB f9.wiki] "f9"
file mkdir [file join $rootDir subdirC]
write_file [file join $rootDir subdirC f10.md] "f10"
write_file [file join $rootDir subdirC f11t.xt] "f11"
set files_md [list subdirB/f5.md subdirB/f6.md subdirB/f8.md subdirC/f10.md]
fossil add $rootDir
fossil commit -m "c1"
set dir [file dirname [info script]]
###############################################################################
fossil test-th-eval --open-config "dir trunk subdir*/*.md"
test th1-dir-1 {[llength $RESULT] eq [llength $files_md]}
set n 1
foreach i $RESULT j $files_md {
test th1-dir-2.$n {$i eq $j}
set n [expr {$n + 1}]
}
###############################################################################
set dateTime {\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}}
fossil test-th-eval --open-config "dir trunk subdir*/*.md 1"
test th1-dir-3.1 {[lindex [lindex $RESULT 0] 0] eq "subdirB/f5.md"}
test th1-dir-3.2 {[lindex [lindex $RESULT 0] 1] == 2}
test th1-dir-3.3 {[regexp -- $dateTime [lindex [lindex $RESULT 0] 2]]}
test th1-dir-3.4 {[lindex [lindex $RESULT 1] 0] eq "subdirB/f6.md"}
test th1-dir-3.5 {[lindex [lindex $RESULT 1] 1] == 2}
test th1-dir-3.6 {[regexp -- $dateTime [lindex [lindex $RESULT 1] 2]]}
test th1-dir-3.7 {[lindex [lindex $RESULT 2] 0] eq "subdirB/f8.md"}
test th1-dir-3.8 {[lindex [lindex $RESULT 2] 1] == 2}
test th1-dir-3.9 {[regexp -- $dateTime [lindex [lindex $RESULT 2] 2]]}
test th1-dir-3.10 {[lindex [lindex $RESULT 3] 0] eq "subdirC/f10.md"}
test th1-dir-3.11 {[lindex [lindex $RESULT 3] 1] == 3}
test th1-dir-3.12 {[regexp -- $dateTime [lindex [lindex $RESULT 3] 2]]}
|
Changes to test/th1.test.
| ︙ | ︙ | |||
859 860 861 862 863 864 865 |
#
# NOTE: This test may fail if the command names do not always come
# out in a deterministic order from TH1.
#
fossil test-th-eval "info commands"
test th1-info-commands-1 {$RESULT eq {linecount htmlize date stime\
| | | 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 |
#
# NOTE: This test may fail if the command names do not always come
# out in a deterministic order from TH1.
#
fossil test-th-eval "info commands"
test th1-info-commands-1 {$RESULT eq {linecount htmlize date stime\
enable_output uplevel dir http expr glob_match utime styleFooter catch if\
tclReady searchable reinitialize combobox lindex query html anoncap randhex\
llength for set break regexp markdown styleHeader puts return checkout\
decorate artifact trace wiki proc hascap globalState continue getParameter\
hasfeature setting lsearch breakpoint upvar render repository string unset\
setParameter list error info rename anycap httpize}}
###############################################################################
|
| ︙ | ︙ |
Changes to www/th1.md.
| ︙ | ︙ | |||
127 128 129 130 131 132 133 134 135 136 137 138 139 140 | * anoncap * anycap * artifact * checkout * combobox * date * decorate * enable_output * getParameter * glob_match * globalState * hascap * hasfeature * html | > | 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | * anoncap * anycap * artifact * checkout * combobox * date * decorate * dir * enable_output * getParameter * glob_match * globalState * hascap * hasfeature * html |
| ︙ | ︙ | |||
232 233 234 235 236 237 238 239 240 241 242 243 244 245 | ------------------------------------------- * decorate STRING Renders STRING as wiki content; however, only links are handled. No other markup is processed. <a name="enable_output"></a>TH1 enable_output Command ----------------------------------------------------- * enable_output BOOLEAN Enable or disable sending output when the combobox, puts, or wiki commands are used. | > > > > > > > > > > > > | 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | ------------------------------------------- * decorate STRING Renders STRING as wiki content; however, only links are handled. No other markup is processed. <a name="dir"></a>TH1 dir Command ------------------------------------------- * dir CHECKIN ?GLOB? Returns a list containing all files in CHECKIN. If GLOB is given only the files matching the pattern GLOB within CHECKIN will be returned. If DETAILS is non-zero, the result will be a list-of-lists, with each element containing at least three elements: the file name, the file size (in bytes), and the file last modification time (relative to the time zone configured for the repository). <a name="enable_output"></a>TH1 enable_output Command ----------------------------------------------------- * enable_output BOOLEAN Enable or disable sending output when the combobox, puts, or wiki commands are used. |
| ︙ | ︙ |