Fossil SCM

add TECHNOTEID to fossil wiki commit and allow creation of multiple tech notes with the same timestamp (as already permitted by the GUI).

dave.vines 2016-04-18 08:17
Commit aeaef8fbb1d8c1a289e9c68cd0d45646ed08091c
+4 -24
--- src/event.c
+++ src/event.c
@@ -538,46 +538,26 @@
538538
style_footer();
539539
}
540540
541541
/*
542542
** Add a new tech note to the repository. The timestamp is
543
-** given by the zETime parameter. isNew must be true to create
543
+** given by the zETime parameter. rid must be zero to create
544544
** a new page. If no previous page with the name zPageName exists
545545
** and isNew is false, then this routine throws an error.
546546
*/
547547
void event_cmd_commit(
548548
char *zETime, /* timestamp */
549
- int isNew, /* true to create a new page */
549
+ int rid, /* Artifact id of the tech note */
550550
Blob *pContent, /* content of the new page */
551551
const char *zMimeType, /* mimetype of the content */
552552
const char *zComment, /* comment to go on the timeline */
553553
const char *zTags, /* tags */
554554
const char *zClr /* background color */
555555
){
556
- int rid; /* Artifact id of the tech note */
557556
const char *zId; /* id of the tech note */
558
- rid = db_int(0, "SELECT objid FROM event"
559
- " WHERE datetime(mtime)=datetime('%q') AND type = 'e'"
560
- " AND tagid IS NOT NULL"
561
- " ORDER BY mtime DESC"
562
- " LIMIT 1",
563
- zETime
564
- );
565
- if( rid==0 && !isNew ){
566
-#ifdef FOSSIL_ENABLE_JSON
567
- g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
568
-#endif
569
- fossil_fatal("no such tech note: %s", zETime);
570
- }
571
- if( rid!=0 && isNew ){
572
-#ifdef FOSSIL_ENABLE_JSON
573
- g.json.resultCode = FSL_JSON_E_RESOURCE_ALREADY_EXISTS;
574
-#endif
575
- fossil_fatal("tech note %s already exists", zETime);
576
- }
577
-
578
- if ( isNew ){
557
+
558
+ if ( rid==0 ){
579559
zId = db_text(0, "SELECT lower(hex(randomblob(20)))");
580560
}else{
581561
zId = db_text(0,
582562
"SELECT substr(tagname,7) FROM tag"
583563
" WHERE tagid=(SELECT tagid FROM event WHERE objid='%d')",
584564
--- src/event.c
+++ src/event.c
@@ -538,46 +538,26 @@
538 style_footer();
539 }
540
541 /*
542 ** Add a new tech note to the repository. The timestamp is
543 ** given by the zETime parameter. isNew must be true to create
544 ** a new page. If no previous page with the name zPageName exists
545 ** and isNew is false, then this routine throws an error.
546 */
547 void event_cmd_commit(
548 char *zETime, /* timestamp */
549 int isNew, /* true to create a new page */
550 Blob *pContent, /* content of the new page */
551 const char *zMimeType, /* mimetype of the content */
552 const char *zComment, /* comment to go on the timeline */
553 const char *zTags, /* tags */
554 const char *zClr /* background color */
555 ){
556 int rid; /* Artifact id of the tech note */
557 const char *zId; /* id of the tech note */
558 rid = db_int(0, "SELECT objid FROM event"
559 " WHERE datetime(mtime)=datetime('%q') AND type = 'e'"
560 " AND tagid IS NOT NULL"
561 " ORDER BY mtime DESC"
562 " LIMIT 1",
563 zETime
564 );
565 if( rid==0 && !isNew ){
566 #ifdef FOSSIL_ENABLE_JSON
567 g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
568 #endif
569 fossil_fatal("no such tech note: %s", zETime);
570 }
571 if( rid!=0 && isNew ){
572 #ifdef FOSSIL_ENABLE_JSON
573 g.json.resultCode = FSL_JSON_E_RESOURCE_ALREADY_EXISTS;
574 #endif
575 fossil_fatal("tech note %s already exists", zETime);
576 }
577
578 if ( isNew ){
579 zId = db_text(0, "SELECT lower(hex(randomblob(20)))");
580 }else{
581 zId = db_text(0,
582 "SELECT substr(tagname,7) FROM tag"
583 " WHERE tagid=(SELECT tagid FROM event WHERE objid='%d')",
584
--- src/event.c
+++ src/event.c
@@ -538,46 +538,26 @@
538 style_footer();
539 }
540
541 /*
542 ** Add a new tech note to the repository. The timestamp is
543 ** given by the zETime parameter. rid must be zero to create
544 ** a new page. If no previous page with the name zPageName exists
545 ** and isNew is false, then this routine throws an error.
546 */
547 void event_cmd_commit(
548 char *zETime, /* timestamp */
549 int rid, /* Artifact id of the tech note */
550 Blob *pContent, /* content of the new page */
551 const char *zMimeType, /* mimetype of the content */
552 const char *zComment, /* comment to go on the timeline */
553 const char *zTags, /* tags */
554 const char *zClr /* background color */
555 ){
 
556 const char *zId; /* id of the tech note */
557
558 if ( rid==0 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
559 zId = db_text(0, "SELECT lower(hex(randomblob(20)))");
560 }else{
561 zId = db_text(0,
562 "SELECT substr(tagname,7) FROM tag"
563 " WHERE tagid=(SELECT tagid FROM event WHERE objid='%d')",
564
+1 -1
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -375,11 +375,11 @@
375375
blob_append(&content, cson_string_cstr(jstr),contentLen);
376376
}
377377
378378
zMimeType = json_find_option_cstr("mimetype","mimetype","M");
379379
380
- wiki_cmd_commit(zPageName, 0==rid, &content, zMimeType, 0);
380
+ wiki_cmd_commit(zPageName, rid, &content, zMimeType, 0);
381381
blob_reset(&content);
382382
/*
383383
Our return value here has a race condition: if this operation
384384
is called concurrently for the same wiki page via two requests,
385385
payV could reflect the results of the other save operation.
386386
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -375,11 +375,11 @@
375 blob_append(&content, cson_string_cstr(jstr),contentLen);
376 }
377
378 zMimeType = json_find_option_cstr("mimetype","mimetype","M");
379
380 wiki_cmd_commit(zPageName, 0==rid, &content, zMimeType, 0);
381 blob_reset(&content);
382 /*
383 Our return value here has a race condition: if this operation
384 is called concurrently for the same wiki page via two requests,
385 payV could reflect the results of the other save operation.
386
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -375,11 +375,11 @@
375 blob_append(&content, cson_string_cstr(jstr),contentLen);
376 }
377
378 zMimeType = json_find_option_cstr("mimetype","mimetype","M");
379
380 wiki_cmd_commit(zPageName, rid, &content, zMimeType, 0);
381 blob_reset(&content);
382 /*
383 Our return value here has a race condition: if this operation
384 is called concurrently for the same wiki page via two requests,
385 payV could reflect the results of the other save operation.
386
+43 -48
--- src/wiki.c
+++ src/wiki.c
@@ -1068,47 +1068,26 @@
10681068
style_footer();
10691069
}
10701070
10711071
/*
10721072
** Add a new wiki page to the repository. The page name is
1073
-** given by the zPageName parameter. isNew must be true to create
1074
-** a new page. If no previous page with the name zPageName exists
1075
-** and isNew is false, then this routine throws an error.
1073
+** given by the zPageName parameter. rid must be zero to create
1074
+** a new page otherwise the page identified by rid is updated.
10761075
**
10771076
** The content of the new page is given by the blob pContent.
10781077
**
10791078
** zMimeType specifies the N-card for the wiki page. If it is 0,
10801079
** empty, or "text/x-fossil-wiki" (the default format) then it is
10811080
** ignored.
10821081
*/
1083
-int wiki_cmd_commit(const char *zPageName, int isNew, Blob *pContent,
1082
+int wiki_cmd_commit(const char *zPageName, int rid, Blob *pContent,
10841083
const char *zMimeType, int localUser){
10851084
Blob wiki; /* Wiki page content */
10861085
Blob cksum; /* wiki checksum */
1087
- int rid; /* artifact ID of parent page */
10881086
char *zDate; /* timestamp */
10891087
char *zUuid; /* uuid for rid */
10901088
1091
- rid = db_int(0,
1092
- "SELECT x.rid FROM tag t, tagxref x"
1093
- " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
1094
- " ORDER BY x.mtime DESC LIMIT 1",
1095
- zPageName
1096
- );
1097
- if( rid==0 && !isNew ){
1098
-#ifdef FOSSIL_ENABLE_JSON
1099
- g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
1100
-#endif
1101
- fossil_fatal("no such wiki page: %s", zPageName);
1102
- }
1103
- if( rid!=0 && isNew ){
1104
-#ifdef FOSSIL_ENABLE_JSON
1105
- g.json.resultCode = FSL_JSON_E_RESOURCE_ALREADY_EXISTS;
1106
-#endif
1107
- fossil_fatal("wiki page %s already exists", zPageName);
1108
- }
1109
-
11101089
blob_zero(&wiki);
11111090
zDate = date_in_standard_format("now");
11121091
blob_appendf(&wiki, "D %s\n", zDate);
11131092
free(zDate);
11141093
blob_appendf(&wiki, "L %F\n", zPageName );
@@ -1136,12 +1115,12 @@
11361115
return 1;
11371116
}
11381117
11391118
/*
11401119
** 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
1120
+** timestamp. Returns 0 if there is no such item and -1 if the details
1121
+** are ambiguous and could refer to multiple items.
11431122
*/
11441123
int wiki_technote_to_rid(const char *zETime) {
11451124
int rid=0; /* Artifact ID of the tech note */
11461125
int nETime = strlen(zETime);
11471126
Stmt q;
@@ -1204,11 +1183,15 @@
12041183
** Defaults to the type used by
12051184
** the previous version of the
12061185
** page, or text/x-fossil-wiki.
12071186
** -t|--technote DATETIME Specifies the timestamp of
12081187
** the technote to be created or
1209
-** updated.
1188
+** updated. When updating a tech note
1189
+** the most recently modified with the
1190
+** specified timestamp will be updated.
1191
+** -t|--technote TECHNOTE-ID Specifies the technote to be
1192
+** updated by its technote id.
12101193
** --technote-tags TAGS The set of tags for a technote.
12111194
** --technote-bgcolor COLOR The color used for the technote
12121195
** on the timeline.
12131196
**
12141197
** %fossil wiki list ?OPTIONS?
@@ -1324,44 +1307,56 @@
13241307
if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0
13251308
&& (pWiki->zMimetype && *pWiki->zMimetype)){
13261309
zMimeType = pWiki->zMimetype;
13271310
}
13281311
}else{
1329
- rid = db_int(0, "SELECT objid FROM event"
1330
- " WHERE datetime(mtime)=datetime('%q') AND type='e'"
1331
- " AND tagid IS NOT NULL"
1332
- " ORDER BY mtime DESC LIMIT 1",
1333
- zPageName
1334
- );
1312
+ rid = wiki_technote_to_rid(zETime);
13351313
if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0
13361314
&& (pWiki->zMimetype && *pWiki->zMimetype)){
13371315
zMimeType = pWiki->zMimetype;
13381316
}
13391317
}
13401318
}
1319
+ if( g.argv[2][1]=='r' && rid>0 ){
1320
+ if ( !zETime ){
1321
+ fossil_fatal("wiki page %s already exists", zPageName);
1322
+ }else{
1323
+ /* Creating a tech note with same timestamp is permitted
1324
+ and should create a new tech note */
1325
+ rid = 0;
1326
+ }
1327
+ }else if( g.argv[2][1]=='o' && rid == 0 ){
1328
+ if ( !zETime ){
1329
+ fossil_fatal("no such wiki page: %s", zPageName);
1330
+ }else{
1331
+ fossil_fatal("no such tech note: %s", zETime);
1332
+ }
1333
+ }
1334
+
13411335
if( !zETime ){
1336
+ wiki_cmd_commit(zPageName, rid, &content, zMimeType, 1);
13421337
if( g.argv[2][1]=='r' ){
1343
- wiki_cmd_commit(zPageName, 1, &content, zMimeType, 1);
13441338
fossil_print("Created new wiki page %s.\n", zPageName);
13451339
}else{
1346
- wiki_cmd_commit(zPageName, 0, &content, zMimeType, 1);
13471340
fossil_print("Updated wiki page %s.\n", zPageName);
13481341
}
13491342
}else{
1350
- char *zMETime; /* Normalized, mutable version of zETime */
1351
- zMETime = db_text(0, "SELECT coalesce(datetime(%Q),datetime('now'))",
1352
- zETime);
1353
- if( g.argv[2][1]=='r' ){
1354
- event_cmd_commit(zMETime, 1, &content, zMimeType, zPageName,
1355
- zTags, zClr);
1356
- fossil_print("Created new tech note %s.\n", zMETime);
1357
- }else{
1358
- event_cmd_commit(zMETime, 0, &content, zMimeType, zPageName,
1359
- zTags, zClr);
1360
- fossil_print("Updated tech note %s.\n", zMETime);
1361
- }
1362
- free(zMETime);
1343
+ if( rid != -1 ){
1344
+ char *zMETime; /* Normalized, mutable version of zETime */
1345
+ zMETime = db_text(0, "SELECT coalesce(datetime(%Q),datetime('now'))",
1346
+ zETime);
1347
+ event_cmd_commit(zMETime, rid, &content, zMimeType, zPageName,
1348
+ zTags, zClr);
1349
+ if( g.argv[2][1]=='r' ){
1350
+ fossil_print("Created new tech note %s.\n", zMETime);
1351
+ }else{
1352
+ fossil_print("Updated tech note %s.\n", zMETime);
1353
+ }
1354
+ free(zMETime);
1355
+ }else{
1356
+ fossil_fatal("ambiguous tech note id: %s", zETime);
1357
+ }
13631358
}
13641359
manifest_destroy(pWiki);
13651360
blob_reset(&content);
13661361
}else if( strncmp(g.argv[2],"delete",n)==0 ){
13671362
if( g.argc!=5 ){
13681363
--- src/wiki.c
+++ src/wiki.c
@@ -1068,47 +1068,26 @@
1068 style_footer();
1069 }
1070
1071 /*
1072 ** Add a new wiki page to the repository. The page name is
1073 ** given by the zPageName parameter. isNew must be true to create
1074 ** a new page. If no previous page with the name zPageName exists
1075 ** and isNew is false, then this routine throws an error.
1076 **
1077 ** The content of the new page is given by the blob pContent.
1078 **
1079 ** zMimeType specifies the N-card for the wiki page. If it is 0,
1080 ** empty, or "text/x-fossil-wiki" (the default format) then it is
1081 ** ignored.
1082 */
1083 int wiki_cmd_commit(const char *zPageName, int isNew, Blob *pContent,
1084 const char *zMimeType, int localUser){
1085 Blob wiki; /* Wiki page content */
1086 Blob cksum; /* wiki checksum */
1087 int rid; /* artifact ID of parent page */
1088 char *zDate; /* timestamp */
1089 char *zUuid; /* uuid for rid */
1090
1091 rid = db_int(0,
1092 "SELECT x.rid FROM tag t, tagxref x"
1093 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
1094 " ORDER BY x.mtime DESC LIMIT 1",
1095 zPageName
1096 );
1097 if( rid==0 && !isNew ){
1098 #ifdef FOSSIL_ENABLE_JSON
1099 g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
1100 #endif
1101 fossil_fatal("no such wiki page: %s", zPageName);
1102 }
1103 if( rid!=0 && isNew ){
1104 #ifdef FOSSIL_ENABLE_JSON
1105 g.json.resultCode = FSL_JSON_E_RESOURCE_ALREADY_EXISTS;
1106 #endif
1107 fossil_fatal("wiki page %s already exists", zPageName);
1108 }
1109
1110 blob_zero(&wiki);
1111 zDate = date_in_standard_format("now");
1112 blob_appendf(&wiki, "D %s\n", zDate);
1113 free(zDate);
1114 blob_appendf(&wiki, "L %F\n", zPageName );
@@ -1136,12 +1115,12 @@
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;
@@ -1204,11 +1183,15 @@
1204 ** Defaults to the type used by
1205 ** the previous version of the
1206 ** page, or text/x-fossil-wiki.
1207 ** -t|--technote DATETIME Specifies the timestamp of
1208 ** the technote to be created or
1209 ** updated.
 
 
 
 
1210 ** --technote-tags TAGS The set of tags for a technote.
1211 ** --technote-bgcolor COLOR The color used for the technote
1212 ** on the timeline.
1213 **
1214 ** %fossil wiki list ?OPTIONS?
@@ -1324,44 +1307,56 @@
1324 if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0
1325 && (pWiki->zMimetype && *pWiki->zMimetype)){
1326 zMimeType = pWiki->zMimetype;
1327 }
1328 }else{
1329 rid = db_int(0, "SELECT objid FROM event"
1330 " WHERE datetime(mtime)=datetime('%q') AND type='e'"
1331 " AND tagid IS NOT NULL"
1332 " ORDER BY mtime DESC LIMIT 1",
1333 zPageName
1334 );
1335 if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0
1336 && (pWiki->zMimetype && *pWiki->zMimetype)){
1337 zMimeType = pWiki->zMimetype;
1338 }
1339 }
1340 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1341 if( !zETime ){
 
1342 if( g.argv[2][1]=='r' ){
1343 wiki_cmd_commit(zPageName, 1, &content, zMimeType, 1);
1344 fossil_print("Created new wiki page %s.\n", zPageName);
1345 }else{
1346 wiki_cmd_commit(zPageName, 0, &content, zMimeType, 1);
1347 fossil_print("Updated wiki page %s.\n", zPageName);
1348 }
1349 }else{
1350 char *zMETime; /* Normalized, mutable version of zETime */
1351 zMETime = db_text(0, "SELECT coalesce(datetime(%Q),datetime('now'))",
1352 zETime);
1353 if( g.argv[2][1]=='r' ){
1354 event_cmd_commit(zMETime, 1, &content, zMimeType, zPageName,
1355 zTags, zClr);
1356 fossil_print("Created new tech note %s.\n", zMETime);
1357 }else{
1358 event_cmd_commit(zMETime, 0, &content, zMimeType, zPageName,
1359 zTags, zClr);
1360 fossil_print("Updated tech note %s.\n", zMETime);
1361 }
1362 free(zMETime);
 
 
1363 }
1364 manifest_destroy(pWiki);
1365 blob_reset(&content);
1366 }else if( strncmp(g.argv[2],"delete",n)==0 ){
1367 if( g.argc!=5 ){
1368
--- src/wiki.c
+++ src/wiki.c
@@ -1068,47 +1068,26 @@
1068 style_footer();
1069 }
1070
1071 /*
1072 ** Add a new wiki page to the repository. The page name is
1073 ** given by the zPageName parameter. rid must be zero to create
1074 ** a new page otherwise the page identified by rid is updated.
 
1075 **
1076 ** The content of the new page is given by the blob pContent.
1077 **
1078 ** zMimeType specifies the N-card for the wiki page. If it is 0,
1079 ** empty, or "text/x-fossil-wiki" (the default format) then it is
1080 ** ignored.
1081 */
1082 int wiki_cmd_commit(const char *zPageName, int rid, Blob *pContent,
1083 const char *zMimeType, int localUser){
1084 Blob wiki; /* Wiki page content */
1085 Blob cksum; /* wiki checksum */
 
1086 char *zDate; /* timestamp */
1087 char *zUuid; /* uuid for rid */
1088
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1089 blob_zero(&wiki);
1090 zDate = date_in_standard_format("now");
1091 blob_appendf(&wiki, "D %s\n", zDate);
1092 free(zDate);
1093 blob_appendf(&wiki, "L %F\n", zPageName );
@@ -1136,12 +1115,12 @@
1115 return 1;
1116 }
1117
1118 /*
1119 ** Determine the rid for a tech note given either its id or its
1120 ** timestamp. Returns 0 if there is no such item and -1 if the details
1121 ** are ambiguous and could refer to multiple items.
1122 */
1123 int wiki_technote_to_rid(const char *zETime) {
1124 int rid=0; /* Artifact ID of the tech note */
1125 int nETime = strlen(zETime);
1126 Stmt q;
@@ -1204,11 +1183,15 @@
1183 ** Defaults to the type used by
1184 ** the previous version of the
1185 ** page, or text/x-fossil-wiki.
1186 ** -t|--technote DATETIME Specifies the timestamp of
1187 ** the technote to be created or
1188 ** updated. When updating a tech note
1189 ** the most recently modified with the
1190 ** specified timestamp will be updated.
1191 ** -t|--technote TECHNOTE-ID Specifies the technote to be
1192 ** updated by its technote id.
1193 ** --technote-tags TAGS The set of tags for a technote.
1194 ** --technote-bgcolor COLOR The color used for the technote
1195 ** on the timeline.
1196 **
1197 ** %fossil wiki list ?OPTIONS?
@@ -1324,44 +1307,56 @@
1307 if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0
1308 && (pWiki->zMimetype && *pWiki->zMimetype)){
1309 zMimeType = pWiki->zMimetype;
1310 }
1311 }else{
1312 rid = wiki_technote_to_rid(zETime);
 
 
 
 
 
1313 if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0
1314 && (pWiki->zMimetype && *pWiki->zMimetype)){
1315 zMimeType = pWiki->zMimetype;
1316 }
1317 }
1318 }
1319 if( g.argv[2][1]=='r' && rid>0 ){
1320 if ( !zETime ){
1321 fossil_fatal("wiki page %s already exists", zPageName);
1322 }else{
1323 /* Creating a tech note with same timestamp is permitted
1324 and should create a new tech note */
1325 rid = 0;
1326 }
1327 }else if( g.argv[2][1]=='o' && rid == 0 ){
1328 if ( !zETime ){
1329 fossil_fatal("no such wiki page: %s", zPageName);
1330 }else{
1331 fossil_fatal("no such tech note: %s", zETime);
1332 }
1333 }
1334
1335 if( !zETime ){
1336 wiki_cmd_commit(zPageName, rid, &content, zMimeType, 1);
1337 if( g.argv[2][1]=='r' ){
 
1338 fossil_print("Created new wiki page %s.\n", zPageName);
1339 }else{
 
1340 fossil_print("Updated wiki page %s.\n", zPageName);
1341 }
1342 }else{
1343 if( rid != -1 ){
1344 char *zMETime; /* Normalized, mutable version of zETime */
1345 zMETime = db_text(0, "SELECT coalesce(datetime(%Q),datetime('now'))",
1346 zETime);
1347 event_cmd_commit(zMETime, rid, &content, zMimeType, zPageName,
1348 zTags, zClr);
1349 if( g.argv[2][1]=='r' ){
1350 fossil_print("Created new tech note %s.\n", zMETime);
1351 }else{
1352 fossil_print("Updated tech note %s.\n", zMETime);
1353 }
1354 free(zMETime);
1355 }else{
1356 fossil_fatal("ambiguous tech note id: %s", zETime);
1357 }
1358 }
1359 manifest_destroy(pWiki);
1360 blob_reset(&content);
1361 }else if( strncmp(g.argv[2],"delete",n)==0 ){
1362 if( g.argc!=5 ){
1363
+55 -22
--- test/wiki.test
+++ test/wiki.test
@@ -78,28 +78,41 @@
7878
write_file f3 "A technote"
7979
fossil wiki create technote f3 --technote {2016-01-01 12:34}
8080
test wiki-9 {$CODE == 0}
8181
fossil wiki list --technote
8282
test wiki-10 {[normalize_result] eq {2016-01-01 12:34:00}}
83
+fossil wiki list --technote --show-technote-ids
84
+set technotelist [split $RESULT "\n"]
85
+set veryfirsttechnoteid [lindex [split [lindex $technotelist 0]] 0]
8386
8487
###############################################################################
8588
# exporting that technote should give back similar text
8689
fossil wiki export a3 --technote {2016-01-01 12:34:00}
8790
test wiki-11 {[similar_file f3 a3]}
8891
8992
###############################################################################
90
-# Trying to add a technote with the same timestamp should fail
91
-fossil wiki create 2ndnote f3 -technote {2016-01-01 12:34} -expectError
92
-test wiki-13 {$CODE != 0}
93
+# Trying to add a technote with the same timestamp should succeed and create a
94
+# second tech note
95
+fossil wiki create 2ndnote f3 -technote {2016-01-01 12:34}
96
+test wiki-13 {$CODE == 0}
97
+fossil wiki list --technote
98
+set technotelist [split $RESULT "\n"]
99
+test wiki-13.1 {[llength $technotelist] == 2}
93100
94101
###############################################################################
95102
# commiting a change to an existing technote should replace the page on export
103
+# (this should update the tech note from wiki-13 as that the most recently
104
+# updated one, that should also be the one exported by the export command)
96105
write_file f4 "technote 2nd variant"
97106
fossil wiki commit technote f4 --technote {2016-01-01 12:34}
98107
test wiki-14 {$CODE == 0}
99108
fossil wiki export a4 --technote {2016-01-01 12:34}
100109
test wiki-15 {[similar_file f4 a4]}
110
+# Also check that the tech note with the same timestamp, but modified less
111
+# recently still has its original text
112
+fossil wiki export a4.1 --technote $veryfirsttechnoteid
113
+test wiki-15.1 {[similar_file f3 a4.1]}
101114
102115
###############################################################################
103116
# But we shouldn't be able to update non-existant pages
104117
fossil wiki commit doesntexist f1 -expectError
105118
test wiki-16 {$CODE != 0}
@@ -129,11 +142,11 @@
129142
test wiki-21 {$CODE != 0}
130143
fossil attachment add tcltest fa
131144
test wiki-22 {$CODE == 0}
132145
133146
###############################################################################
134
-# Test adding an attachment to borg a non-existant (should fail) and existing tech note
147
+# Test adding an attachment to both a non-existant (should fail) and existing tech note
135148
fossil attachment add fa --technote {2016-07-22 12:00} -expectError
136149
test wiki-23 {$CODE != 0}
137150
fossil attachment add fa --technote {2016-01-03 12:34}
138151
test wiki-24 {$CODE == 0}
139152
@@ -162,15 +175,14 @@
162175
write_file f8 "Contents of a 'unique' tech note"
163176
fossil wiki create {Unique technote} f8 --technote {2016-01-05 01:02:03}
164177
fossil timeline
165178
test wiki-30 {[string match *Unique*technote* $RESULT]}
166179
167
-
168180
###############################################################################
169
-# Check for a collision between an attachment and a note, this is a
170
-# bug that results from some code apparently treating the attachment
171
-# entry as if it were a technote when it isn't really.
181
+# Check for a collision between an attachment and a note, this was a
182
+# bug that resulted from some code treating the attachment entry as if it
183
+# were a technote when it isn't really.
172184
#
173185
# First, wait for the top of the next second so the attachment
174186
# happens at a known time, then add an attachment to an existing note
175187
# and a new note immediately after.
176188
@@ -214,22 +226,22 @@
214226
fossil wiki list -t
215227
test wiki-36-2 {$CODE == 0}
216228
217229
###############################################################################
218230
# Check that we have the expected number of tech notes on the list (and not
219
-# extra ones from other events (such as the attachments) - 7 tech notes
220
-# expected created by tests 9, 17, 19, 29, 31, 32 and 34
231
+# extra ones from other events (such as the attachments) - 8 tech notes
232
+# expected created by tests 9, 13, 17, 19, 29, 31, 32 and 34
221233
fossil wiki list --technote
222234
set technotelist [split $RESULT "\n"]
223
-test wiki-37 {[llength $technotelist] == 7}
235
+test wiki-37 {[llength $technotelist] == 8}
224236
225237
###############################################################################
226238
# 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
239
+# order (with the technote id as the first word of the line)
228240
fossil wiki list --technote --show-technote-ids
229241
set technoteidlist [split $RESULT "\n"]
230
-test wiki-38 {[llength $technotelist] == 7}
242
+test wiki-38 {[llength $technotelist] == 8}
231243
for {set i 0} {$i < [llength $technotelist]} {incr i} {
232244
set match "???????????????????????????????????????? "
233245
append match [lindex $technotelist $i]
234246
test "wiki-39-$i" {[string match $match [lindex $technoteidlist $i]]}
235247
}
@@ -239,20 +251,20 @@
239251
# the contents of the oldest tech note (by tech note id, both full and short) match up
240252
write_file f12 "A really old tech note"
241253
fossil wiki create {Old tech note} f12 --technote {2001-07-07 09:08:07}
242254
fossil wiki list --technote --show-technote-ids
243255
set technotelist [split $RESULT "\n"]
244
-set oldesttechnoteid [lindex [split [lindex $technotelist [llength $technotelist]-1]] 0]
245
-fossil wiki export a12 --technote $oldesttechnoteid
256
+set anoldtechnoteid [lindex [split [lindex $technotelist [llength $technotelist]-1]] 0]
257
+fossil wiki export a12 --technote $anoldtechnoteid
246258
test wiki-40 {[similar_file f12 a12]}
247259
248260
###############################################################################
249261
# 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]
262
+# 9 items in the tech note at this point there is a chance of a collision.
263
+# However with a 20 character prefix the chance of the collision is
264
+# approximately 1 in 10^22 so this test ignores that possibility.)
265
+fossil wiki export a12.1 --technote [string range $anoldtechnoteid 0 20]
254266
test wiki-41 {[similar_file f12 a12.1]}
255267
256268
###############################################################################
257269
# Now we need to force a collision in the first four characters of the tech
258270
# note id if we don't already have one so we can check we get an error if the
@@ -274,12 +286,12 @@
274286
# any other tech note, but after 1 AD
275287
set i 2400000
276288
while {$maxcount < 2} {
277289
# keep getting older
278290
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"
291
+ write_file f13 "A tech note with timestamp of jday=$i"
292
+ fossil wiki create "timestamp of $i" f13 --technote "$i"
281293
fossil wiki list --technote --show-technote-ids
282294
set technotelist [split $RESULT "\n"]
283295
set oldesttechnoteid [lindex [split [lindex $technotelist [llength $technotelist]-1]] 0]
284296
set id [string range $oldesttechnoteid 0 3]
285297
dict incr idcounts $id
@@ -286,11 +298,32 @@
286298
if {[dict get $idcounts $id] > $maxcount} {
287299
set maxid $id
288300
incr maxcount
289301
}
290302
}
291
-fossil wiki export a13 --technote $maxid -expectError
303
+# Save the duplicate id for this and later tests
304
+set duplicateid $maxid
305
+fossil wiki export a13 --technote $duplicateid -expectError
292306
test wiki-42 {$CODE != 0}
307
+
308
+###############################################################################
309
+# Check we can update technote by its id
310
+write_file f14 "Updated text for the really old tech note"
311
+fossil wiki commit {Old tech note} f14 --technote $anoldtechnoteid
312
+fossil wiki export a14 --technote $anoldtechnoteid
313
+test wiki-43 {[similar_file f14 a14]}
314
+
315
+###############################################################################
316
+# Also check that we can specify a prefix of the tech note id
317
+write_file f15 "Updated text for the really old tech note specified by its id"
318
+fossil wiki commit {Old tech note} f15 --technote [string range $anoldtechnoteid 0 20]
319
+fossil wiki export a15 --technote $anoldtechnoteid
320
+test wiki-44 {[similar_file f15 a15]}
321
+
322
+###############################################################################
323
+# And we get an error for the ambiguous tech note id
324
+fossil wiki commit {Old tech note} f15 --technote $duplicateid -expectError
325
+test wiki-45 {$CODE != 0}
293326
294327
###############################################################################
295328
test_cleanup
296329
297330
--- test/wiki.test
+++ test/wiki.test
@@ -78,28 +78,41 @@
78 write_file f3 "A technote"
79 fossil wiki create technote f3 --technote {2016-01-01 12:34}
80 test wiki-9 {$CODE == 0}
81 fossil wiki list --technote
82 test wiki-10 {[normalize_result] eq {2016-01-01 12:34:00}}
 
 
 
83
84 ###############################################################################
85 # exporting that technote should give back similar text
86 fossil wiki export a3 --technote {2016-01-01 12:34:00}
87 test wiki-11 {[similar_file f3 a3]}
88
89 ###############################################################################
90 # Trying to add a technote with the same timestamp should fail
91 fossil wiki create 2ndnote f3 -technote {2016-01-01 12:34} -expectError
92 test wiki-13 {$CODE != 0}
 
 
 
 
93
94 ###############################################################################
95 # commiting a change to an existing technote should replace the page on export
 
 
96 write_file f4 "technote 2nd variant"
97 fossil wiki commit technote f4 --technote {2016-01-01 12:34}
98 test wiki-14 {$CODE == 0}
99 fossil wiki export a4 --technote {2016-01-01 12:34}
100 test wiki-15 {[similar_file f4 a4]}
 
 
 
 
101
102 ###############################################################################
103 # But we shouldn't be able to update non-existant pages
104 fossil wiki commit doesntexist f1 -expectError
105 test wiki-16 {$CODE != 0}
@@ -129,11 +142,11 @@
129 test wiki-21 {$CODE != 0}
130 fossil attachment add tcltest fa
131 test wiki-22 {$CODE == 0}
132
133 ###############################################################################
134 # Test adding an attachment to borg a non-existant (should fail) and existing tech note
135 fossil attachment add fa --technote {2016-07-22 12:00} -expectError
136 test wiki-23 {$CODE != 0}
137 fossil attachment add fa --technote {2016-01-03 12:34}
138 test wiki-24 {$CODE == 0}
139
@@ -162,15 +175,14 @@
162 write_file f8 "Contents of a 'unique' tech note"
163 fossil wiki create {Unique technote} f8 --technote {2016-01-05 01:02:03}
164 fossil timeline
165 test wiki-30 {[string match *Unique*technote* $RESULT]}
166
167
168 ###############################################################################
169 # Check for a collision between an attachment and a note, this is a
170 # bug that results from some code apparently treating the attachment
171 # entry as if it were a technote when it isn't really.
172 #
173 # First, wait for the top of the next second so the attachment
174 # happens at a known time, then add an attachment to an existing note
175 # and a new note immediately after.
176
@@ -214,22 +226,22 @@
214 fossil wiki list -t
215 test wiki-36-2 {$CODE == 0}
216
217 ###############################################################################
218 # Check that we have the expected number of tech notes on the list (and not
219 # extra ones from other events (such as the attachments) - 7 tech notes
220 # expected created by tests 9, 17, 19, 29, 31, 32 and 34
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 }
@@ -239,20 +251,20 @@
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
@@ -274,12 +286,12 @@
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,11 +298,32 @@
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
--- test/wiki.test
+++ test/wiki.test
@@ -78,28 +78,41 @@
78 write_file f3 "A technote"
79 fossil wiki create technote f3 --technote {2016-01-01 12:34}
80 test wiki-9 {$CODE == 0}
81 fossil wiki list --technote
82 test wiki-10 {[normalize_result] eq {2016-01-01 12:34:00}}
83 fossil wiki list --technote --show-technote-ids
84 set technotelist [split $RESULT "\n"]
85 set veryfirsttechnoteid [lindex [split [lindex $technotelist 0]] 0]
86
87 ###############################################################################
88 # exporting that technote should give back similar text
89 fossil wiki export a3 --technote {2016-01-01 12:34:00}
90 test wiki-11 {[similar_file f3 a3]}
91
92 ###############################################################################
93 # Trying to add a technote with the same timestamp should succeed and create a
94 # second tech note
95 fossil wiki create 2ndnote f3 -technote {2016-01-01 12:34}
96 test wiki-13 {$CODE == 0}
97 fossil wiki list --technote
98 set technotelist [split $RESULT "\n"]
99 test wiki-13.1 {[llength $technotelist] == 2}
100
101 ###############################################################################
102 # commiting a change to an existing technote should replace the page on export
103 # (this should update the tech note from wiki-13 as that the most recently
104 # updated one, that should also be the one exported by the export command)
105 write_file f4 "technote 2nd variant"
106 fossil wiki commit technote f4 --technote {2016-01-01 12:34}
107 test wiki-14 {$CODE == 0}
108 fossil wiki export a4 --technote {2016-01-01 12:34}
109 test wiki-15 {[similar_file f4 a4]}
110 # Also check that the tech note with the same timestamp, but modified less
111 # recently still has its original text
112 fossil wiki export a4.1 --technote $veryfirsttechnoteid
113 test wiki-15.1 {[similar_file f3 a4.1]}
114
115 ###############################################################################
116 # But we shouldn't be able to update non-existant pages
117 fossil wiki commit doesntexist f1 -expectError
118 test wiki-16 {$CODE != 0}
@@ -129,11 +142,11 @@
142 test wiki-21 {$CODE != 0}
143 fossil attachment add tcltest fa
144 test wiki-22 {$CODE == 0}
145
146 ###############################################################################
147 # Test adding an attachment to both a non-existant (should fail) and existing tech note
148 fossil attachment add fa --technote {2016-07-22 12:00} -expectError
149 test wiki-23 {$CODE != 0}
150 fossil attachment add fa --technote {2016-01-03 12:34}
151 test wiki-24 {$CODE == 0}
152
@@ -162,15 +175,14 @@
175 write_file f8 "Contents of a 'unique' tech note"
176 fossil wiki create {Unique technote} f8 --technote {2016-01-05 01:02:03}
177 fossil timeline
178 test wiki-30 {[string match *Unique*technote* $RESULT]}
179
 
180 ###############################################################################
181 # Check for a collision between an attachment and a note, this was a
182 # bug that resulted from some code treating the attachment entry as if it
183 # were a technote when it isn't really.
184 #
185 # First, wait for the top of the next second so the attachment
186 # happens at a known time, then add an attachment to an existing note
187 # and a new note immediately after.
188
@@ -214,22 +226,22 @@
226 fossil wiki list -t
227 test wiki-36-2 {$CODE == 0}
228
229 ###############################################################################
230 # Check that we have the expected number of tech notes on the list (and not
231 # extra ones from other events (such as the attachments) - 8 tech notes
232 # expected created by tests 9, 13, 17, 19, 29, 31, 32 and 34
233 fossil wiki list --technote
234 set technotelist [split $RESULT "\n"]
235 test wiki-37 {[llength $technotelist] == 8}
236
237 ###############################################################################
238 # Check that using the show-technote-ids shows the same tech notes in the same
239 # order (with the technote id as the first word of the line)
240 fossil wiki list --technote --show-technote-ids
241 set technoteidlist [split $RESULT "\n"]
242 test wiki-38 {[llength $technotelist] == 8}
243 for {set i 0} {$i < [llength $technotelist]} {incr i} {
244 set match "???????????????????????????????????????? "
245 append match [lindex $technotelist $i]
246 test "wiki-39-$i" {[string match $match [lindex $technoteidlist $i]]}
247 }
@@ -239,20 +251,20 @@
251 # the contents of the oldest tech note (by tech note id, both full and short) match up
252 write_file f12 "A really old tech note"
253 fossil wiki create {Old tech note} f12 --technote {2001-07-07 09:08:07}
254 fossil wiki list --technote --show-technote-ids
255 set technotelist [split $RESULT "\n"]
256 set anoldtechnoteid [lindex [split [lindex $technotelist [llength $technotelist]-1]] 0]
257 fossil wiki export a12 --technote $anoldtechnoteid
258 test wiki-40 {[similar_file f12 a12]}
259
260 ###############################################################################
261 # Also check that we can specify a prefix of the tech note id (note: with
262 # 9 items in the tech note at this point there is a chance of a collision.
263 # However with a 20 character prefix the chance of the collision is
264 # approximately 1 in 10^22 so this test ignores that possibility.)
265 fossil wiki export a12.1 --technote [string range $anoldtechnoteid 0 20]
266 test wiki-41 {[similar_file f12 a12.1]}
267
268 ###############################################################################
269 # Now we need to force a collision in the first four characters of the tech
270 # note id if we don't already have one so we can check we get an error if the
@@ -274,12 +286,12 @@
286 # any other tech note, but after 1 AD
287 set i 2400000
288 while {$maxcount < 2} {
289 # keep getting older
290 incr i -1
291 write_file f13 "A tech note with timestamp of jday=$i"
292 fossil wiki create "timestamp of $i" f13 --technote "$i"
293 fossil wiki list --technote --show-technote-ids
294 set technotelist [split $RESULT "\n"]
295 set oldesttechnoteid [lindex [split [lindex $technotelist [llength $technotelist]-1]] 0]
296 set id [string range $oldesttechnoteid 0 3]
297 dict incr idcounts $id
@@ -286,11 +298,32 @@
298 if {[dict get $idcounts $id] > $maxcount} {
299 set maxid $id
300 incr maxcount
301 }
302 }
303 # Save the duplicate id for this and later tests
304 set duplicateid $maxid
305 fossil wiki export a13 --technote $duplicateid -expectError
306 test wiki-42 {$CODE != 0}
307
308 ###############################################################################
309 # Check we can update technote by its id
310 write_file f14 "Updated text for the really old tech note"
311 fossil wiki commit {Old tech note} f14 --technote $anoldtechnoteid
312 fossil wiki export a14 --technote $anoldtechnoteid
313 test wiki-43 {[similar_file f14 a14]}
314
315 ###############################################################################
316 # Also check that we can specify a prefix of the tech note id
317 write_file f15 "Updated text for the really old tech note specified by its id"
318 fossil wiki commit {Old tech note} f15 --technote [string range $anoldtechnoteid 0 20]
319 fossil wiki export a15 --technote $anoldtechnoteid
320 test wiki-44 {[similar_file f15 a15]}
321
322 ###############################################################################
323 # And we get an error for the ambiguous tech note id
324 fossil wiki commit {Old tech note} f15 --technote $duplicateid -expectError
325 test wiki-45 {$CODE != 0}
326
327 ###############################################################################
328 test_cleanup
329
330

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button