Fossil SCM
add TECHNOTEID to fossil wiki export. Rename --show-artifact-ids to --show-technote-ids on fossil wiki list (and ignore option for wiki pages as the page name uniquely identifies wiki page name). Rename done as tech note ids are not artifact ids (e.g. they cannot be used on fossil artifact)
dave.vines
2016-04-12 19:14
Commit
f486d0f0694b0549788e0bf58d7c33dd7ef271d5
Parent
cbda43e71bda52f…
2 files changed
+61
-23
+69
-29
+61
-23
| --- src/wiki.c | ||
| +++ src/wiki.c | ||
| @@ -1133,23 +1133,66 @@ | ||
| 1133 | 1133 | db_begin_transaction(); |
| 1134 | 1134 | wiki_put(&wiki, 0, wiki_need_moderation(localUser)); |
| 1135 | 1135 | db_end_transaction(0); |
| 1136 | 1136 | return 1; |
| 1137 | 1137 | } |
| 1138 | + | |
| 1139 | +/* | |
| 1140 | +** Determine the rid for a tech note given either its id or its | |
| 1141 | +** timestamp. Returns 0 if there is no such item and-1 if the details | |
| 1142 | +** are ambiguous and could refer to multiple items | |
| 1143 | +*/ | |
| 1144 | +int wiki_technote_to_rid(const char *zETime) { | |
| 1145 | + int rid=0; /* Artifact ID of the tech note */ | |
| 1146 | + int nETime = strlen(zETime); | |
| 1147 | + Stmt q; | |
| 1148 | + if( nETime>=4 && nETime<=UUID_SIZE && validate16(zETime, nETime) ){ | |
| 1149 | + char zUuid[UUID_SIZE+1]; | |
| 1150 | + memcpy(zUuid, zETime, nETime+1); | |
| 1151 | + canonical16(zUuid, nETime); | |
| 1152 | + db_prepare(&q, | |
| 1153 | + "SELECT e.objid" | |
| 1154 | + " FROM event e, tag t" | |
| 1155 | + " WHERE e.type='e' AND e.tagid IS NOT NULL AND t.tagid=e.tagid" | |
| 1156 | + " AND t.tagname GLOB 'event-%q*'", | |
| 1157 | + zUuid | |
| 1158 | + ); | |
| 1159 | + if( db_step(&q)==SQLITE_ROW ){ | |
| 1160 | + rid = db_column_int(&q, 0); | |
| 1161 | + if( db_step(&q)==SQLITE_ROW ) rid = -1; | |
| 1162 | + } | |
| 1163 | + db_finalize(&q); | |
| 1164 | + } | |
| 1165 | + if (!rid) { | |
| 1166 | + if (strlen(zETime)>4) { | |
| 1167 | + rid = db_int(0, "SELECT objid" | |
| 1168 | + " FROM event" | |
| 1169 | + " WHERE datetime(mtime)=datetime('%q')" | |
| 1170 | + " AND type='e'" | |
| 1171 | + " ORDER BY mtime DESC LIMIT 1", | |
| 1172 | + zETime); | |
| 1173 | + } | |
| 1174 | + } | |
| 1175 | + return rid; | |
| 1176 | +} | |
| 1138 | 1177 | |
| 1139 | 1178 | /* |
| 1140 | 1179 | ** COMMAND: wiki* |
| 1141 | 1180 | ** |
| 1142 | 1181 | ** Usage: %fossil wiki (export|create|commit|list) WikiName |
| 1143 | 1182 | ** |
| 1144 | 1183 | ** Run various subcommands to work with wiki entries or tech notes. |
| 1145 | 1184 | ** |
| 1146 | -** %fossil wiki export ?PAGENAME? ?FILE? [-t|--technote DATETIME ] | |
| 1185 | +** %fossil wiki export PAGENAME ?FILE? | |
| 1186 | +** %fossil wiki export ?FILE? -t|--technote DATETIME|TECHNOTE-ID | |
| 1147 | 1187 | ** |
| 1148 | -** Sends the latest version of either the PAGENAME wiki entry | |
| 1149 | -** or the DATETIME tech note to the given file or standard | |
| 1150 | -** output. One of PAGENAME or DATETIME must be specified. | |
| 1188 | +** Sends the latest version of either a wiki page or of a tech note | |
| 1189 | +** to the given file or standard output. | |
| 1190 | +** If PAGENAME is provided, the wiki page will be output. For | |
| 1191 | +** a tech note either DATETIME or TECHNOTE-ID must be specified. If | |
| 1192 | +** DATETIME is used, the most recently modified tech note with that | |
| 1193 | +** DATETIME will be sent. | |
| 1151 | 1194 | ** |
| 1152 | 1195 | ** %fossil wiki (create|commit) PAGENAME ?FILE? ?OPTIONS? |
| 1153 | 1196 | ** |
| 1154 | 1197 | ** Create a new or commit changes to an existing wiki page or |
| 1155 | 1198 | ** technote from FILE or from standard input. PAGENAME is the |
| @@ -1177,14 +1220,15 @@ | ||
| 1177 | 1220 | ** Options: |
| 1178 | 1221 | ** --technote Technotes will be listed instead of |
| 1179 | 1222 | ** pages. The technotes will be in order |
| 1180 | 1223 | ** of timestamp with the most recent |
| 1181 | 1224 | ** first. |
| 1182 | -** --show-artifact-ids The artifact id of the wiki page or | |
| 1183 | -** tech note will be listed along side the | |
| 1184 | -** page name or timestamp. The artifact id | |
| 1185 | -** will be the first word on each line. | |
| 1225 | +** --show-technote-ids The id of the tech note will be listed | |
| 1226 | +** along side the timestamp. The tech note | |
| 1227 | +** id will be the first word on each line. | |
| 1228 | +** This option only applies if the | |
| 1229 | +** --technote option is also specified. | |
| 1186 | 1230 | ** |
| 1187 | 1231 | */ |
| 1188 | 1232 | void wiki_cmd(void){ |
| 1189 | 1233 | int n; |
| 1190 | 1234 | db_find_and_open_repository(0, 0); |
| @@ -1224,17 +1268,16 @@ | ||
| 1224 | 1268 | fossil_fatal("wiki page [%s] not found",zPageName); |
| 1225 | 1269 | } |
| 1226 | 1270 | zFile = (g.argc==4) ? "-" : g.argv[4]; |
| 1227 | 1271 | }else{ |
| 1228 | 1272 | if( (g.argc!=3) && (g.argc!=4) ){ |
| 1229 | - usage("export ?FILE? --technote DATETIME"); | |
| 1273 | + usage("export ?FILE? --technote DATETIME|TECHNOTE-ID"); | |
| 1230 | 1274 | } |
| 1231 | - rid = db_int(0, "SELECT objid FROM event" | |
| 1232 | - " WHERE datetime(mtime)=datetime('%q') AND type='e'" | |
| 1233 | - " ORDER BY mtime DESC LIMIT 1", | |
| 1234 | - zETime | |
| 1235 | - ); | |
| 1275 | + rid = wiki_technote_to_rid(zETime); | |
| 1276 | + if (rid == -1) { | |
| 1277 | + fossil_fatal("ambiguous tech note id: %s", zETime); | |
| 1278 | + } | |
| 1236 | 1279 | if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){ |
| 1237 | 1280 | zBody = pWiki->zWiki; |
| 1238 | 1281 | } |
| 1239 | 1282 | if( zBody==0 ){ |
| 1240 | 1283 | fossil_fatal("technote [%s] not found",zETime); |
| @@ -1326,26 +1369,21 @@ | ||
| 1326 | 1369 | } |
| 1327 | 1370 | fossil_fatal("delete not yet implemented."); |
| 1328 | 1371 | }else if(( strncmp(g.argv[2],"list",n)==0 ) |
| 1329 | 1372 | || ( strncmp(g.argv[2],"ls",n)==0 )){ |
| 1330 | 1373 | Stmt q; |
| 1331 | - int showIds = find_option("show-artifact-ids","s",0)!=0; | |
| 1374 | + int showIds = 0; | |
| 1332 | 1375 | |
| 1333 | 1376 | if ( !find_option("technote","t",0) ){ |
| 1334 | 1377 | db_prepare(&q, |
| 1335 | - "SELECT substr(t.tagname, 6), b.uuid" | |
| 1336 | - " FROM tag t, tagxref x, blob b" | |
| 1337 | - " WHERE tagname GLOB 'wiki-*'" | |
| 1338 | - " AND t.tagid=x.tagid AND b.rid=x.rid" | |
| 1339 | - " AND x.mtime=(SELECT MAX(xx.mtime)" | |
| 1340 | - " FROM tagxref xx" | |
| 1341 | - " WHERE xx.tagid=x.tagid)" | |
| 1378 | + "SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'" | |
| 1342 | 1379 | " ORDER BY lower(tagname) /*sort*/" |
| 1343 | 1380 | ); |
| 1344 | 1381 | }else{ |
| 1382 | + showIds = find_option("show-technote-ids","s",0)!=0; | |
| 1345 | 1383 | db_prepare(&q, |
| 1346 | - "SELECT datetime(e.mtime), substr(t.tagname,7) " | |
| 1384 | + "SELECT datetime(e.mtime), substr(t.tagname,7)" | |
| 1347 | 1385 | " FROM event e, tag t" |
| 1348 | 1386 | " WHERE e.type='e'" |
| 1349 | 1387 | " AND e.tagid IS NOT NULL" |
| 1350 | 1388 | " AND t.tagid=e.tagid" |
| 1351 | 1389 | " ORDER BY e.mtime DESC /*sort*/" |
| 1352 | 1390 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -1133,23 +1133,66 @@ | |
| 1133 | db_begin_transaction(); |
| 1134 | wiki_put(&wiki, 0, wiki_need_moderation(localUser)); |
| 1135 | db_end_transaction(0); |
| 1136 | return 1; |
| 1137 | } |
| 1138 | |
| 1139 | /* |
| 1140 | ** COMMAND: wiki* |
| 1141 | ** |
| 1142 | ** Usage: %fossil wiki (export|create|commit|list) WikiName |
| 1143 | ** |
| 1144 | ** Run various subcommands to work with wiki entries or tech notes. |
| 1145 | ** |
| 1146 | ** %fossil wiki export ?PAGENAME? ?FILE? [-t|--technote DATETIME ] |
| 1147 | ** |
| 1148 | ** Sends the latest version of either the PAGENAME wiki entry |
| 1149 | ** or the DATETIME tech note to the given file or standard |
| 1150 | ** output. One of PAGENAME or DATETIME must be specified. |
| 1151 | ** |
| 1152 | ** %fossil wiki (create|commit) PAGENAME ?FILE? ?OPTIONS? |
| 1153 | ** |
| 1154 | ** Create a new or commit changes to an existing wiki page or |
| 1155 | ** technote from FILE or from standard input. PAGENAME is the |
| @@ -1177,14 +1220,15 @@ | |
| 1177 | ** Options: |
| 1178 | ** --technote Technotes will be listed instead of |
| 1179 | ** pages. The technotes will be in order |
| 1180 | ** of timestamp with the most recent |
| 1181 | ** first. |
| 1182 | ** --show-artifact-ids The artifact id of the wiki page or |
| 1183 | ** tech note will be listed along side the |
| 1184 | ** page name or timestamp. The artifact id |
| 1185 | ** will be the first word on each line. |
| 1186 | ** |
| 1187 | */ |
| 1188 | void wiki_cmd(void){ |
| 1189 | int n; |
| 1190 | db_find_and_open_repository(0, 0); |
| @@ -1224,17 +1268,16 @@ | |
| 1224 | fossil_fatal("wiki page [%s] not found",zPageName); |
| 1225 | } |
| 1226 | zFile = (g.argc==4) ? "-" : g.argv[4]; |
| 1227 | }else{ |
| 1228 | if( (g.argc!=3) && (g.argc!=4) ){ |
| 1229 | usage("export ?FILE? --technote DATETIME"); |
| 1230 | } |
| 1231 | rid = db_int(0, "SELECT objid FROM event" |
| 1232 | " WHERE datetime(mtime)=datetime('%q') AND type='e'" |
| 1233 | " ORDER BY mtime DESC LIMIT 1", |
| 1234 | zETime |
| 1235 | ); |
| 1236 | if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){ |
| 1237 | zBody = pWiki->zWiki; |
| 1238 | } |
| 1239 | if( zBody==0 ){ |
| 1240 | fossil_fatal("technote [%s] not found",zETime); |
| @@ -1326,26 +1369,21 @@ | |
| 1326 | } |
| 1327 | fossil_fatal("delete not yet implemented."); |
| 1328 | }else if(( strncmp(g.argv[2],"list",n)==0 ) |
| 1329 | || ( strncmp(g.argv[2],"ls",n)==0 )){ |
| 1330 | Stmt q; |
| 1331 | int showIds = find_option("show-artifact-ids","s",0)!=0; |
| 1332 | |
| 1333 | if ( !find_option("technote","t",0) ){ |
| 1334 | db_prepare(&q, |
| 1335 | "SELECT substr(t.tagname, 6), b.uuid" |
| 1336 | " FROM tag t, tagxref x, blob b" |
| 1337 | " WHERE tagname GLOB 'wiki-*'" |
| 1338 | " AND t.tagid=x.tagid AND b.rid=x.rid" |
| 1339 | " AND x.mtime=(SELECT MAX(xx.mtime)" |
| 1340 | " FROM tagxref xx" |
| 1341 | " WHERE xx.tagid=x.tagid)" |
| 1342 | " ORDER BY lower(tagname) /*sort*/" |
| 1343 | ); |
| 1344 | }else{ |
| 1345 | db_prepare(&q, |
| 1346 | "SELECT datetime(e.mtime), substr(t.tagname,7) " |
| 1347 | " FROM event e, tag t" |
| 1348 | " WHERE e.type='e'" |
| 1349 | " AND e.tagid IS NOT NULL" |
| 1350 | " AND t.tagid=e.tagid" |
| 1351 | " ORDER BY e.mtime DESC /*sort*/" |
| 1352 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -1133,23 +1133,66 @@ | |
| 1133 | db_begin_transaction(); |
| 1134 | wiki_put(&wiki, 0, wiki_need_moderation(localUser)); |
| 1135 | db_end_transaction(0); |
| 1136 | return 1; |
| 1137 | } |
| 1138 | |
| 1139 | /* |
| 1140 | ** Determine the rid for a tech note given either its id or its |
| 1141 | ** timestamp. Returns 0 if there is no such item and-1 if the details |
| 1142 | ** are ambiguous and could refer to multiple items |
| 1143 | */ |
| 1144 | int wiki_technote_to_rid(const char *zETime) { |
| 1145 | int rid=0; /* Artifact ID of the tech note */ |
| 1146 | int nETime = strlen(zETime); |
| 1147 | Stmt q; |
| 1148 | if( nETime>=4 && nETime<=UUID_SIZE && validate16(zETime, nETime) ){ |
| 1149 | char zUuid[UUID_SIZE+1]; |
| 1150 | memcpy(zUuid, zETime, nETime+1); |
| 1151 | canonical16(zUuid, nETime); |
| 1152 | db_prepare(&q, |
| 1153 | "SELECT e.objid" |
| 1154 | " FROM event e, tag t" |
| 1155 | " WHERE e.type='e' AND e.tagid IS NOT NULL AND t.tagid=e.tagid" |
| 1156 | " AND t.tagname GLOB 'event-%q*'", |
| 1157 | zUuid |
| 1158 | ); |
| 1159 | if( db_step(&q)==SQLITE_ROW ){ |
| 1160 | rid = db_column_int(&q, 0); |
| 1161 | if( db_step(&q)==SQLITE_ROW ) rid = -1; |
| 1162 | } |
| 1163 | db_finalize(&q); |
| 1164 | } |
| 1165 | if (!rid) { |
| 1166 | if (strlen(zETime)>4) { |
| 1167 | rid = db_int(0, "SELECT objid" |
| 1168 | " FROM event" |
| 1169 | " WHERE datetime(mtime)=datetime('%q')" |
| 1170 | " AND type='e'" |
| 1171 | " ORDER BY mtime DESC LIMIT 1", |
| 1172 | zETime); |
| 1173 | } |
| 1174 | } |
| 1175 | return rid; |
| 1176 | } |
| 1177 | |
| 1178 | /* |
| 1179 | ** COMMAND: wiki* |
| 1180 | ** |
| 1181 | ** Usage: %fossil wiki (export|create|commit|list) WikiName |
| 1182 | ** |
| 1183 | ** Run various subcommands to work with wiki entries or tech notes. |
| 1184 | ** |
| 1185 | ** %fossil wiki export PAGENAME ?FILE? |
| 1186 | ** %fossil wiki export ?FILE? -t|--technote DATETIME|TECHNOTE-ID |
| 1187 | ** |
| 1188 | ** Sends the latest version of either a wiki page or of a tech note |
| 1189 | ** to the given file or standard output. |
| 1190 | ** If PAGENAME is provided, the wiki page will be output. For |
| 1191 | ** a tech note either DATETIME or TECHNOTE-ID must be specified. If |
| 1192 | ** DATETIME is used, the most recently modified tech note with that |
| 1193 | ** DATETIME will be sent. |
| 1194 | ** |
| 1195 | ** %fossil wiki (create|commit) PAGENAME ?FILE? ?OPTIONS? |
| 1196 | ** |
| 1197 | ** Create a new or commit changes to an existing wiki page or |
| 1198 | ** technote from FILE or from standard input. PAGENAME is the |
| @@ -1177,14 +1220,15 @@ | |
| 1220 | ** Options: |
| 1221 | ** --technote Technotes will be listed instead of |
| 1222 | ** pages. The technotes will be in order |
| 1223 | ** of timestamp with the most recent |
| 1224 | ** first. |
| 1225 | ** --show-technote-ids The id of the tech note will be listed |
| 1226 | ** along side the timestamp. The tech note |
| 1227 | ** id will be the first word on each line. |
| 1228 | ** This option only applies if the |
| 1229 | ** --technote option is also specified. |
| 1230 | ** |
| 1231 | */ |
| 1232 | void wiki_cmd(void){ |
| 1233 | int n; |
| 1234 | db_find_and_open_repository(0, 0); |
| @@ -1224,17 +1268,16 @@ | |
| 1268 | fossil_fatal("wiki page [%s] not found",zPageName); |
| 1269 | } |
| 1270 | zFile = (g.argc==4) ? "-" : g.argv[4]; |
| 1271 | }else{ |
| 1272 | if( (g.argc!=3) && (g.argc!=4) ){ |
| 1273 | usage("export ?FILE? --technote DATETIME|TECHNOTE-ID"); |
| 1274 | } |
| 1275 | rid = wiki_technote_to_rid(zETime); |
| 1276 | if (rid == -1) { |
| 1277 | fossil_fatal("ambiguous tech note id: %s", zETime); |
| 1278 | } |
| 1279 | if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){ |
| 1280 | zBody = pWiki->zWiki; |
| 1281 | } |
| 1282 | if( zBody==0 ){ |
| 1283 | fossil_fatal("technote [%s] not found",zETime); |
| @@ -1326,26 +1369,21 @@ | |
| 1369 | } |
| 1370 | fossil_fatal("delete not yet implemented."); |
| 1371 | }else if(( strncmp(g.argv[2],"list",n)==0 ) |
| 1372 | || ( strncmp(g.argv[2],"ls",n)==0 )){ |
| 1373 | Stmt q; |
| 1374 | int showIds = 0; |
| 1375 | |
| 1376 | if ( !find_option("technote","t",0) ){ |
| 1377 | db_prepare(&q, |
| 1378 | "SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'" |
| 1379 | " ORDER BY lower(tagname) /*sort*/" |
| 1380 | ); |
| 1381 | }else{ |
| 1382 | showIds = find_option("show-technote-ids","s",0)!=0; |
| 1383 | db_prepare(&q, |
| 1384 | "SELECT datetime(e.mtime), substr(t.tagname,7)" |
| 1385 | " FROM event e, tag t" |
| 1386 | " WHERE e.type='e'" |
| 1387 | " AND e.tagid IS NOT NULL" |
| 1388 | " AND t.tagid=e.tagid" |
| 1389 | " ORDER BY e.mtime DESC /*sort*/" |
| 1390 |
+69
-29
| --- test/wiki.test | ||
| +++ test/wiki.test | ||
| @@ -221,36 +221,76 @@ | ||
| 221 | 221 | fossil wiki list --technote |
| 222 | 222 | set technotelist [split $RESULT "\n"] |
| 223 | 223 | test wiki-37 {[llength $technotelist] == 7} |
| 224 | 224 | |
| 225 | 225 | ############################################################################### |
| 226 | -# Check that using the show-artifact-ids shows the same tech notes in the same | |
| 227 | -# order (with the artifact id as the first word of the line | |
| 228 | -fossil wiki list --technote --show-artifact-ids | |
| 229 | -set technoteartifactlist [split $RESULT "\n"] | |
| 230 | -test wiki-38 {[llength $technoteartifactlist] == 7} | |
| 231 | -for {set i 0} {$i < [llength $technotelist]} {incr i} { | |
| 232 | - set match "*" | |
| 233 | - append match [lindex $technotelist $i] | |
| 234 | - test "wiki-39-$i" {[string match $match [lindex $technoteartifactlist $i]]} | |
| 235 | -} | |
| 236 | - | |
| 237 | -############################################################################### | |
| 238 | -# Similarly check that wiki pages can have their artifact ids displayed | |
| 239 | -# Note: the tests above have only created a single wiki page, hence the list | |
| 240 | -# should be of length 1 at this point (created by test 1) | |
| 241 | -fossil wiki list | |
| 242 | -set wikilist [split $RESULT "\n"] | |
| 243 | -test wiki-40 {[llength $wikilist] == 1} | |
| 244 | -fossil wiki list --show-artifact-ids | |
| 245 | -set wikiartifactlist [split $RESULT "\n"] | |
| 246 | -test wiki-41 {[llength $wikilist] == [llength $wikiartifactlist]} | |
| 247 | -for {set i 0} {$i < [llength $wikilist]} {incr i} { | |
| 248 | - set match "*" | |
| 249 | - append match [lindex $wikilist $i] | |
| 250 | - test "wiki-42-$i" {[string match $match [lindex $wikiartifactlist $i]]} | |
| 251 | -} | |
| 252 | - | |
| 253 | -############################################################################### | |
| 254 | - | |
| 226 | +# Check that using the show-technote-ids shows the same tech notes in the same | |
| 227 | +# order (with the technote id as the first word of the line | |
| 228 | +fossil wiki list --technote --show-technote-ids | |
| 229 | +set technoteidlist [split $RESULT "\n"] | |
| 230 | +test wiki-38 {[llength $technotelist] == 7} | |
| 231 | +for {set i 0} {$i < [llength $technotelist]} {incr i} { | |
| 232 | + set match "???????????????????????????????????????? " | |
| 233 | + append match [lindex $technotelist $i] | |
| 234 | + test "wiki-39-$i" {[string match $match [lindex $technoteidlist $i]]} | |
| 235 | +} | |
| 236 | + | |
| 237 | +############################################################################### | |
| 238 | +# Create new tech note with a old timestamp so that it is oldest and then check that | |
| 239 | +# the contents of the oldest tech note (by tech note id, both full and short) match up | |
| 240 | +write_file f12 "A really old tech note" | |
| 241 | +fossil wiki create {Old tech note} f12 --technote {2001-07-07 09:08:07} | |
| 242 | +fossil wiki list --technote --show-technote-ids | |
| 243 | +set technotelist [split $RESULT "\n"] | |
| 244 | +set oldesttechnoteid [lindex [split [lindex $technotelist [llength $technotelist]-1]] 0] | |
| 245 | +fossil wiki export a12 --technote $oldesttechnoteid | |
| 246 | +test wiki-40 {[similar_file f12 a12]} | |
| 247 | + | |
| 248 | +############################################################################### | |
| 249 | +# Also check that we can specify a prefix of the tech note id (note: with | |
| 250 | +# 8 items in the tech note at this point there is a chance of a collision. | |
| 251 | +# However with the chance of the collision being 1 in approx 10^22 if I use a 20 | |
| 252 | +# character prefix I'll ignore that possibility for this test. | |
| 253 | +fossil wiki export a12.1 --technote [string range $oldesttechnoteid 0 20] | |
| 254 | +test wiki-41 {[similar_file f12 a12.1]} | |
| 255 | + | |
| 256 | +############################################################################### | |
| 257 | +# Now we need to force a collision in the first four characters of the tech | |
| 258 | +# note id if we don't already have one so we can check we get an error if the | |
| 259 | +# tech note id is ambiguous | |
| 260 | +set idcounts [dict create] | |
| 261 | +set maxcount 0 | |
| 262 | +fossil wiki list --technote --show-technote-ids | |
| 263 | +set technotelist [split $RESULT "\n"] | |
| 264 | +for {set i 0} {$i < [llength $technotelist]} {incr i} { | |
| 265 | + set fullid [lindex $technotelist $i] | |
| 266 | + set id [string range $fullid 0 3] | |
| 267 | + dict incr idcounts $id | |
| 268 | + if {[dict get $idcounts $id] > $maxcount} { | |
| 269 | + set maxid $id | |
| 270 | + incr maxcount | |
| 271 | + } | |
| 272 | +} | |
| 273 | +# get i so that, as a julian date, it is in the 1800s, i.e., older than | |
| 274 | +# any other tech note, but after 1 AD | |
| 275 | +set i 2400000 | |
| 276 | +while {$maxcount < 2} { | |
| 277 | + # keep getting older | |
| 278 | + incr i -1 | |
| 279 | + write_file collision "A tech note with timestamp of jday=$i" | |
| 280 | + fossil wiki create "timestamp of $i" collision --technote "$i" | |
| 281 | + fossil wiki list --technote --show-technote-ids | |
| 282 | + set technotelist [split $RESULT "\n"] | |
| 283 | + set oldesttechnoteid [lindex [split [lindex $technotelist [llength $technotelist]-1]] 0] | |
| 284 | + set id [string range $oldesttechnoteid 0 3] | |
| 285 | + dict incr idcounts $id | |
| 286 | + if {[dict get $idcounts $id] > $maxcount} { | |
| 287 | + set maxid $id | |
| 288 | + incr maxcount | |
| 289 | + } | |
| 290 | +} | |
| 291 | +fossil wiki export a13 --technote $maxid -expectError | |
| 292 | +test wiki-42 {$CODE != 0} | |
| 293 | + | |
| 294 | +############################################################################### | |
| 255 | 295 | test_cleanup |
| 256 | 296 | |
| 257 | 297 |
| --- test/wiki.test | |
| +++ test/wiki.test | |
| @@ -221,36 +221,76 @@ | |
| 221 | fossil wiki list --technote |
| 222 | set technotelist [split $RESULT "\n"] |
| 223 | test wiki-37 {[llength $technotelist] == 7} |
| 224 | |
| 225 | ############################################################################### |
| 226 | # Check that using the show-artifact-ids shows the same tech notes in the same |
| 227 | # order (with the artifact id as the first word of the line |
| 228 | fossil wiki list --technote --show-artifact-ids |
| 229 | set technoteartifactlist [split $RESULT "\n"] |
| 230 | test wiki-38 {[llength $technoteartifactlist] == 7} |
| 231 | for {set i 0} {$i < [llength $technotelist]} {incr i} { |
| 232 | set match "*" |
| 233 | append match [lindex $technotelist $i] |
| 234 | test "wiki-39-$i" {[string match $match [lindex $technoteartifactlist $i]]} |
| 235 | } |
| 236 | |
| 237 | ############################################################################### |
| 238 | # Similarly check that wiki pages can have their artifact ids displayed |
| 239 | # Note: the tests above have only created a single wiki page, hence the list |
| 240 | # should be of length 1 at this point (created by test 1) |
| 241 | fossil wiki list |
| 242 | set wikilist [split $RESULT "\n"] |
| 243 | test wiki-40 {[llength $wikilist] == 1} |
| 244 | fossil wiki list --show-artifact-ids |
| 245 | set wikiartifactlist [split $RESULT "\n"] |
| 246 | test wiki-41 {[llength $wikilist] == [llength $wikiartifactlist]} |
| 247 | for {set i 0} {$i < [llength $wikilist]} {incr i} { |
| 248 | set match "*" |
| 249 | append match [lindex $wikilist $i] |
| 250 | test "wiki-42-$i" {[string match $match [lindex $wikiartifactlist $i]]} |
| 251 | } |
| 252 | |
| 253 | ############################################################################### |
| 254 | |
| 255 | test_cleanup |
| 256 | |
| 257 |
| --- test/wiki.test | |
| +++ test/wiki.test | |
| @@ -221,36 +221,76 @@ | |
| 221 | fossil wiki list --technote |
| 222 | set technotelist [split $RESULT "\n"] |
| 223 | test wiki-37 {[llength $technotelist] == 7} |
| 224 | |
| 225 | ############################################################################### |
| 226 | # Check that using the show-technote-ids shows the same tech notes in the same |
| 227 | # order (with the technote id as the first word of the line |
| 228 | fossil wiki list --technote --show-technote-ids |
| 229 | set technoteidlist [split $RESULT "\n"] |
| 230 | test wiki-38 {[llength $technotelist] == 7} |
| 231 | for {set i 0} {$i < [llength $technotelist]} {incr i} { |
| 232 | set match "???????????????????????????????????????? " |
| 233 | append match [lindex $technotelist $i] |
| 234 | test "wiki-39-$i" {[string match $match [lindex $technoteidlist $i]]} |
| 235 | } |
| 236 | |
| 237 | ############################################################################### |
| 238 | # Create new tech note with a old timestamp so that it is oldest and then check that |
| 239 | # the contents of the oldest tech note (by tech note id, both full and short) match up |
| 240 | write_file f12 "A really old tech note" |
| 241 | fossil wiki create {Old tech note} f12 --technote {2001-07-07 09:08:07} |
| 242 | fossil wiki list --technote --show-technote-ids |
| 243 | set technotelist [split $RESULT "\n"] |
| 244 | set oldesttechnoteid [lindex [split [lindex $technotelist [llength $technotelist]-1]] 0] |
| 245 | fossil wiki export a12 --technote $oldesttechnoteid |
| 246 | test wiki-40 {[similar_file f12 a12]} |
| 247 | |
| 248 | ############################################################################### |
| 249 | # Also check that we can specify a prefix of the tech note id (note: with |
| 250 | # 8 items in the tech note at this point there is a chance of a collision. |
| 251 | # However with the chance of the collision being 1 in approx 10^22 if I use a 20 |
| 252 | # character prefix I'll ignore that possibility for this test. |
| 253 | fossil wiki export a12.1 --technote [string range $oldesttechnoteid 0 20] |
| 254 | test wiki-41 {[similar_file f12 a12.1]} |
| 255 | |
| 256 | ############################################################################### |
| 257 | # Now we need to force a collision in the first four characters of the tech |
| 258 | # note id if we don't already have one so we can check we get an error if the |
| 259 | # tech note id is ambiguous |
| 260 | set idcounts [dict create] |
| 261 | set maxcount 0 |
| 262 | fossil wiki list --technote --show-technote-ids |
| 263 | set technotelist [split $RESULT "\n"] |
| 264 | for {set i 0} {$i < [llength $technotelist]} {incr i} { |
| 265 | set fullid [lindex $technotelist $i] |
| 266 | set id [string range $fullid 0 3] |
| 267 | dict incr idcounts $id |
| 268 | if {[dict get $idcounts $id] > $maxcount} { |
| 269 | set maxid $id |
| 270 | incr maxcount |
| 271 | } |
| 272 | } |
| 273 | # get i so that, as a julian date, it is in the 1800s, i.e., older than |
| 274 | # any other tech note, but after 1 AD |
| 275 | set i 2400000 |
| 276 | while {$maxcount < 2} { |
| 277 | # keep getting older |
| 278 | incr i -1 |
| 279 | write_file collision "A tech note with timestamp of jday=$i" |
| 280 | fossil wiki create "timestamp of $i" collision --technote "$i" |
| 281 | fossil wiki list --technote --show-technote-ids |
| 282 | set technotelist [split $RESULT "\n"] |
| 283 | set oldesttechnoteid [lindex [split [lindex $technotelist [llength $technotelist]-1]] 0] |
| 284 | set id [string range $oldesttechnoteid 0 3] |
| 285 | dict incr idcounts $id |
| 286 | if {[dict get $idcounts $id] > $maxcount} { |
| 287 | set maxid $id |
| 288 | incr maxcount |
| 289 | } |
| 290 | } |
| 291 | fossil wiki export a13 --technote $maxid -expectError |
| 292 | test wiki-42 {$CODE != 0} |
| 293 | |
| 294 | ############################################################################### |
| 295 | test_cleanup |
| 296 | |
| 297 |