Fossil SCM

Fixed (wiki commit) to check for an existing page when the --mimetype flag is used (previously it only checked when that flag was not provided).

stephan 2019-10-02 20:18 trunk
Commit c0de97a1555c6397adaa2f03e48a89d916e37030a1c4b1ca5dfadff6f009ee75
1 file changed +20 -18
+20 -18
--- src/wiki.c
+++ src/wiki.c
@@ -1495,10 +1495,11 @@
14951495
|| strncmp(g.argv[2],"create",n)==0 ){
14961496
const char *zPageName; /* page name */
14971497
Blob content; /* Input content */
14981498
int rid = 0;
14991499
Manifest *pWiki = 0; /* Parsed wiki page content */
1500
+ const int isCreate = 'r'==g.argv[2][1] /* else "commit" */;
15001501
const char *zMimeType = find_option("mimetype", "M", 1);
15011502
const char *zETime = find_option("technote", "t", 1);
15021503
const char *zTags = find_option("technote-tags", NULL, 1);
15031504
const char *zClr = find_option("technote-bgcolor", NULL, 1);
15041505
if( g.argc!=4 && g.argc!=5 ){
@@ -1509,42 +1510,43 @@
15091510
zPageName = g.argv[3];
15101511
if( g.argc==4 ){
15111512
blob_read_from_channel(&content, stdin, -1);
15121513
}else{
15131514
blob_read_from_file(&content, g.argv[4], ExtFILE);
1515
+ }
1516
+ if ( !zETime ){
1517
+ rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
1518
+ " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
1519
+ " ORDER BY x.mtime DESC LIMIT 1",
1520
+ zPageName
1521
+ );
1522
+ if( rid>0 ){
1523
+ pWiki = manifest_get(rid, CFTYPE_WIKI, 0);
1524
+ }
1525
+ }else{
1526
+ rid = wiki_technote_to_rid(zETime);
1527
+ if( rid>0 ){
1528
+ pWiki = manifest_get(rid, CFTYPE_EVENT, 0);
1529
+ }
15141530
}
15151531
if( !zMimeType || !*zMimeType ){
15161532
/* Try to deduce the mime type based on the prior version. */
1517
- if ( !zETime ){
1518
- rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
1519
- " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
1520
- " ORDER BY x.mtime DESC LIMIT 1",
1521
- zPageName
1522
- );
1523
- if( rid>0 && (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0
1524
- && (pWiki->zMimetype && *pWiki->zMimetype) ){
1525
- zMimeType = pWiki->zMimetype;
1526
- }
1527
- }else{
1528
- rid = wiki_technote_to_rid(zETime);
1529
- if( rid>0 && (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0
1530
- && (pWiki->zMimetype && *pWiki->zMimetype) ){
1531
- zMimeType = pWiki->zMimetype;
1532
- }
1533
+ if( pWiki!=0 && (pWiki->zMimetype && *pWiki->zMimetype) ){
1534
+ zMimeType = pWiki->zMimetype;
15331535
}
15341536
}else{
15351537
zMimeType = wiki_filter_mimetypes(zMimeType);
15361538
}
1537
- if( g.argv[2][1]=='r' && rid>0 ){
1539
+ if( isCreate && rid>0 ){
15381540
if ( !zETime ){
15391541
fossil_fatal("wiki page %s already exists", zPageName);
15401542
}else{
15411543
/* Creating a tech note with same timestamp is permitted
15421544
and should create a new tech note */
15431545
rid = 0;
15441546
}
1545
- }else if( g.argv[2][1]=='o' && rid == 0 ){
1547
+ }else if( !isCreate && rid == 0 ){
15461548
if ( !zETime ){
15471549
fossil_fatal("no such wiki page: %s", zPageName);
15481550
}else{
15491551
fossil_fatal("no such tech note: %s", zETime);
15501552
}
15511553
--- src/wiki.c
+++ src/wiki.c
@@ -1495,10 +1495,11 @@
1495 || strncmp(g.argv[2],"create",n)==0 ){
1496 const char *zPageName; /* page name */
1497 Blob content; /* Input content */
1498 int rid = 0;
1499 Manifest *pWiki = 0; /* Parsed wiki page content */
 
1500 const char *zMimeType = find_option("mimetype", "M", 1);
1501 const char *zETime = find_option("technote", "t", 1);
1502 const char *zTags = find_option("technote-tags", NULL, 1);
1503 const char *zClr = find_option("technote-bgcolor", NULL, 1);
1504 if( g.argc!=4 && g.argc!=5 ){
@@ -1509,42 +1510,43 @@
1509 zPageName = g.argv[3];
1510 if( g.argc==4 ){
1511 blob_read_from_channel(&content, stdin, -1);
1512 }else{
1513 blob_read_from_file(&content, g.argv[4], ExtFILE);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1514 }
1515 if( !zMimeType || !*zMimeType ){
1516 /* Try to deduce the mime type based on the prior version. */
1517 if ( !zETime ){
1518 rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
1519 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
1520 " ORDER BY x.mtime DESC LIMIT 1",
1521 zPageName
1522 );
1523 if( rid>0 && (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0
1524 && (pWiki->zMimetype && *pWiki->zMimetype) ){
1525 zMimeType = pWiki->zMimetype;
1526 }
1527 }else{
1528 rid = wiki_technote_to_rid(zETime);
1529 if( rid>0 && (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0
1530 && (pWiki->zMimetype && *pWiki->zMimetype) ){
1531 zMimeType = pWiki->zMimetype;
1532 }
1533 }
1534 }else{
1535 zMimeType = wiki_filter_mimetypes(zMimeType);
1536 }
1537 if( g.argv[2][1]=='r' && rid>0 ){
1538 if ( !zETime ){
1539 fossil_fatal("wiki page %s already exists", zPageName);
1540 }else{
1541 /* Creating a tech note with same timestamp is permitted
1542 and should create a new tech note */
1543 rid = 0;
1544 }
1545 }else if( g.argv[2][1]=='o' && rid == 0 ){
1546 if ( !zETime ){
1547 fossil_fatal("no such wiki page: %s", zPageName);
1548 }else{
1549 fossil_fatal("no such tech note: %s", zETime);
1550 }
1551
--- src/wiki.c
+++ src/wiki.c
@@ -1495,10 +1495,11 @@
1495 || strncmp(g.argv[2],"create",n)==0 ){
1496 const char *zPageName; /* page name */
1497 Blob content; /* Input content */
1498 int rid = 0;
1499 Manifest *pWiki = 0; /* Parsed wiki page content */
1500 const int isCreate = 'r'==g.argv[2][1] /* else "commit" */;
1501 const char *zMimeType = find_option("mimetype", "M", 1);
1502 const char *zETime = find_option("technote", "t", 1);
1503 const char *zTags = find_option("technote-tags", NULL, 1);
1504 const char *zClr = find_option("technote-bgcolor", NULL, 1);
1505 if( g.argc!=4 && g.argc!=5 ){
@@ -1509,42 +1510,43 @@
1510 zPageName = g.argv[3];
1511 if( g.argc==4 ){
1512 blob_read_from_channel(&content, stdin, -1);
1513 }else{
1514 blob_read_from_file(&content, g.argv[4], ExtFILE);
1515 }
1516 if ( !zETime ){
1517 rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
1518 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
1519 " ORDER BY x.mtime DESC LIMIT 1",
1520 zPageName
1521 );
1522 if( rid>0 ){
1523 pWiki = manifest_get(rid, CFTYPE_WIKI, 0);
1524 }
1525 }else{
1526 rid = wiki_technote_to_rid(zETime);
1527 if( rid>0 ){
1528 pWiki = manifest_get(rid, CFTYPE_EVENT, 0);
1529 }
1530 }
1531 if( !zMimeType || !*zMimeType ){
1532 /* Try to deduce the mime type based on the prior version. */
1533 if( pWiki!=0 && (pWiki->zMimetype && *pWiki->zMimetype) ){
1534 zMimeType = pWiki->zMimetype;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1535 }
1536 }else{
1537 zMimeType = wiki_filter_mimetypes(zMimeType);
1538 }
1539 if( isCreate && rid>0 ){
1540 if ( !zETime ){
1541 fossil_fatal("wiki page %s already exists", zPageName);
1542 }else{
1543 /* Creating a tech note with same timestamp is permitted
1544 and should create a new tech note */
1545 rid = 0;
1546 }
1547 }else if( !isCreate && rid == 0 ){
1548 if ( !zETime ){
1549 fossil_fatal("no such wiki page: %s", zPageName);
1550 }else{
1551 fossil_fatal("no such tech note: %s", zETime);
1552 }
1553

Keyboard Shortcuts

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