Fossil SCM

Added new "wiki create" command. Cleaned up the "wiki commit" code and added an option filename argument to both "wiki commit" and "wiki create".

drh 2008-05-16 01:43 trunk
Commit e03d1be55b3056e381dc76be4397cfc9ae82b9f8
1 file changed +62 -59
+62 -59
--- src/wiki.c
+++ src/wiki.c
@@ -600,68 +600,55 @@
600600
@ </ol>
601601
style_footer();
602602
}
603603
604604
/*
605
-** wiki_cmd_commit() is the implementation of "wiki commit ...".
606
-**
607
-** As arguments it expects:
608
-**
609
-** zPageName = the wiki entry's name.
610
-**
611
-** in = input file. The file is read until EOF but is not closed
612
-** by this function (it might be stdin!).
613
-**
614
-** Returns 0 on error, non-zero on success.
615
-**
616
-** TODOs:
617
-** - take EITHER zPageName OR rid. We don't need both.
618
-** - make use of the return value. Add more error checking.
619
-** - give the uuid back to the caller so it can be shown
620
-** in the status output. ("committed version XXXXX of page ...")
621
-** - return some status telling the user if there were no diffs
622
-** (i.e. no commit). How can we find this out?
623
-*/
624
-int wiki_cmd_commit( char const * zPageName, FILE * in )
625
-{
626
- Blob wiki; /* Wiki page content */
627
- Blob content; /* read-in content */
628
- Blob cksum; /* wiki checksum */
629
- int rid; /* rid of existing entry. */
630
- int nrid; /* not really sure */
631
- char * zDate; /* timestamp */
632
- char * zUuid; /* uuid for rid */
633
-
634
- rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
635
- " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
636
- " ORDER BY x.mtime DESC LIMIT 1",
637
- zPageName
638
- );
639
- if( ! rid ){
640
- fossil_fatal("wiki commit NewEntry not yet implemented.");
641
- }
642
-
643
-
644
- blob_read_from_channel( &content, in, -1 );
645
- // ^^^ Reminder: we should allow empty (zero-byte) entries, so don't exit
646
- // if read returns 0.
605
+** Add a new wiki page to the respository. The page name is
606
+** given by the zPageName parameter. isNew must be true to create
607
+** a new page. If no previous page with the name zPageName exists
608
+** and isNew is false, then this routine throws an error.
609
+**
610
+** The content of the new page is given by the blob pContent.
611
+*/
612
+int wiki_cmd_commit(char const * zPageName, int isNew, Blob *pContent){
613
+ Blob wiki; /* Wiki page content */
614
+ Blob cksum; /* wiki checksum */
615
+ int rid; /* artifact ID of parent page */
616
+ int nrid; /* artifact ID of new wiki page */
617
+ char *zDate; /* timestamp */
618
+ char *zUuid; /* uuid for rid */
619
+
620
+ rid = db_int(0,
621
+ "SELECT x.rid FROM tag t, tagxref x"
622
+ " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
623
+ " ORDER BY x.mtime DESC LIMIT 1",
624
+ zPageName
625
+ );
626
+ if( rid==0 && !isNew ){
627
+ fossil_fatal("no such wiki page: %s", zPageName);
628
+ }
629
+ if( rid!=0 && isNew ){
630
+ fossil_fatal("wiki page %s already exists", zPageName);
631
+ }
632
+
647633
blob_zero(&wiki);
648634
zDate = db_text(0, "SELECT datetime('now')");
649635
zDate[10] = 'T';
650636
blob_appendf(&wiki, "D %s\n", zDate);
651637
free(zDate);
652638
blob_appendf(&wiki, "L %F\n", zPageName );
653
- zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
654
- blob_appendf(&wiki, "P %s\n", zUuid);
655
- free(zUuid);
639
+ if( rid ){
640
+ zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
641
+ blob_appendf(&wiki, "P %s\n", zUuid);
642
+ free(zUuid);
643
+ }
656644
user_select();
657645
if( g.zLogin ){
658646
blob_appendf(&wiki, "U %F\n", g.zLogin);
659647
}
660
- blob_appendf( &wiki, "W %d\n%s\n", blob_size(&content),
661
- blob_buffer(&content) );
662
- blob_reset(&content);
648
+ blob_appendf( &wiki, "W %d\n%s\n", blob_size(pContent),
649
+ blob_str(pContent) );
663650
md5sum_blob(&wiki, &cksum);
664651
blob_appendf(&wiki, "Z %b\n", &cksum);
665652
blob_reset(&cksum);
666653
db_begin_transaction();
667654
nrid = content_put( &wiki, 0, 0 );
@@ -678,20 +665,23 @@
678665
**
679666
** Usage: %fossil wiki (export|commit|list) WikiName
680667
**
681668
** Run various subcommands to fetch wiki entries.
682669
**
683
-** %fossil wiki export WikiName
670
+** %fossil wiki export PAGENAME
684671
**
685
-** Sends the latest version of the WikiName wiki
672
+** Sends the latest version of the PAGENAME wiki
686673
** entry to stdout.
687674
**
688
-** %fossil wiki commit WikiName
675
+** %fossil wiki commit PAGENAME ?FILE?
676
+**
677
+** Commit changes to a wiki page from FILE or from standard.
678
+**
679
+** %fossil wiki create PAGENAME ?FILE?
689680
**
690
-** Commit changes to a wiki page from standard input.
691
-** It cannot currently create a new entry (this is on the
692
-** to-fix list).
681
+** Create a new wiki page with initial content taken from
682
+** FILE or from standard input.
693683
**
694684
** %fossil wiki list
695685
**
696686
** Lists all wiki entries, one per line, ordered
697687
** case-insentively by name.
@@ -762,18 +752,31 @@
762752
}
763753
for(i=strlen(zBody); i>0 && isspace(zBody[i-1]); i--){}
764754
printf("%.*s\n", i, zBody);
765755
return;
766756
}else
767
- if( strncmp(g.argv[2],"commit",n)==0 ){
757
+ if( strncmp(g.argv[2],"commit",n)==0
758
+ || strncmp(g.argv[2],"create",n)==0 ){
768759
char *zPageName;
769
- if( g.argc!=4 ){
770
- usage("commit PAGENAME");
760
+ Blob content;
761
+ if( g.argc!=4 && g.argc!=5 ){
762
+ usage("commit PAGENAME ?FILE?");
771763
}
772764
zPageName = g.argv[3];
773
- wiki_cmd_commit( zPageName, stdin );
774
- printf("Committed wiki page %s.\n", zPageName);
765
+ if( g.argc==4 ){
766
+ blob_read_from_channel(&content, stdin, -1);
767
+ }else{
768
+ blob_read_from_file(&content, g.argv[4]);
769
+ }
770
+ if( g.argv[2][1]=='r' ){
771
+ wiki_cmd_commit(zPageName, 1, &content);
772
+ printf("Created new wiki page %s.\n", zPageName);
773
+ }else{
774
+ wiki_cmd_commit(zPageName, 0, &content);
775
+ printf("Updated wiki page %s.\n", zPageName);
776
+ }
777
+ blob_reset(&content);
775778
}else
776779
if( strncmp(g.argv[2],"delete",n)==0 ){
777780
if( g.argc!=5 ){
778781
usage("delete PAGENAME");
779782
}
780783
--- src/wiki.c
+++ src/wiki.c
@@ -600,68 +600,55 @@
600 @ </ol>
601 style_footer();
602 }
603
604 /*
605 ** wiki_cmd_commit() is the implementation of "wiki commit ...".
606 **
607 ** As arguments it expects:
608 **
609 ** zPageName = the wiki entry's name.
610 **
611 ** in = input file. The file is read until EOF but is not closed
612 ** by this function (it might be stdin!).
613 **
614 ** Returns 0 on error, non-zero on success.
615 **
616 ** TODOs:
617 ** - take EITHER zPageName OR rid. We don't need both.
618 ** - make use of the return value. Add more error checking.
619 ** - give the uuid back to the caller so it can be shown
620 ** in the status output. ("committed version XXXXX of page ...")
621 ** - return some status telling the user if there were no diffs
622 ** (i.e. no commit). How can we find this out?
623 */
624 int wiki_cmd_commit( char const * zPageName, FILE * in )
625 {
626 Blob wiki; /* Wiki page content */
627 Blob content; /* read-in content */
628 Blob cksum; /* wiki checksum */
629 int rid; /* rid of existing entry. */
630 int nrid; /* not really sure */
631 char * zDate; /* timestamp */
632 char * zUuid; /* uuid for rid */
633
634 rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
635 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
636 " ORDER BY x.mtime DESC LIMIT 1",
637 zPageName
638 );
639 if( ! rid ){
640 fossil_fatal("wiki commit NewEntry not yet implemented.");
641 }
642
643
644 blob_read_from_channel( &content, in, -1 );
645 // ^^^ Reminder: we should allow empty (zero-byte) entries, so don't exit
646 // if read returns 0.
647 blob_zero(&wiki);
648 zDate = db_text(0, "SELECT datetime('now')");
649 zDate[10] = 'T';
650 blob_appendf(&wiki, "D %s\n", zDate);
651 free(zDate);
652 blob_appendf(&wiki, "L %F\n", zPageName );
653 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
654 blob_appendf(&wiki, "P %s\n", zUuid);
655 free(zUuid);
 
 
656 user_select();
657 if( g.zLogin ){
658 blob_appendf(&wiki, "U %F\n", g.zLogin);
659 }
660 blob_appendf( &wiki, "W %d\n%s\n", blob_size(&content),
661 blob_buffer(&content) );
662 blob_reset(&content);
663 md5sum_blob(&wiki, &cksum);
664 blob_appendf(&wiki, "Z %b\n", &cksum);
665 blob_reset(&cksum);
666 db_begin_transaction();
667 nrid = content_put( &wiki, 0, 0 );
@@ -678,20 +665,23 @@
678 **
679 ** Usage: %fossil wiki (export|commit|list) WikiName
680 **
681 ** Run various subcommands to fetch wiki entries.
682 **
683 ** %fossil wiki export WikiName
684 **
685 ** Sends the latest version of the WikiName wiki
686 ** entry to stdout.
687 **
688 ** %fossil wiki commit WikiName
 
 
 
 
689 **
690 ** Commit changes to a wiki page from standard input.
691 ** It cannot currently create a new entry (this is on the
692 ** to-fix list).
693 **
694 ** %fossil wiki list
695 **
696 ** Lists all wiki entries, one per line, ordered
697 ** case-insentively by name.
@@ -762,18 +752,31 @@
762 }
763 for(i=strlen(zBody); i>0 && isspace(zBody[i-1]); i--){}
764 printf("%.*s\n", i, zBody);
765 return;
766 }else
767 if( strncmp(g.argv[2],"commit",n)==0 ){
 
768 char *zPageName;
769 if( g.argc!=4 ){
770 usage("commit PAGENAME");
 
771 }
772 zPageName = g.argv[3];
773 wiki_cmd_commit( zPageName, stdin );
774 printf("Committed wiki page %s.\n", zPageName);
 
 
 
 
 
 
 
 
 
 
 
775 }else
776 if( strncmp(g.argv[2],"delete",n)==0 ){
777 if( g.argc!=5 ){
778 usage("delete PAGENAME");
779 }
780
--- src/wiki.c
+++ src/wiki.c
@@ -600,68 +600,55 @@
600 @ </ol>
601 style_footer();
602 }
603
604 /*
605 ** Add a new wiki page to the respository. The page name is
606 ** given by the zPageName parameter. isNew must be true to create
607 ** a new page. If no previous page with the name zPageName exists
608 ** and isNew is false, then this routine throws an error.
609 **
610 ** The content of the new page is given by the blob pContent.
611 */
612 int wiki_cmd_commit(char const * zPageName, int isNew, Blob *pContent){
613 Blob wiki; /* Wiki page content */
614 Blob cksum; /* wiki checksum */
615 int rid; /* artifact ID of parent page */
616 int nrid; /* artifact ID of new wiki page */
617 char *zDate; /* timestamp */
618 char *zUuid; /* uuid for rid */
619
620 rid = db_int(0,
621 "SELECT x.rid FROM tag t, tagxref x"
622 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
623 " ORDER BY x.mtime DESC LIMIT 1",
624 zPageName
625 );
626 if( rid==0 && !isNew ){
627 fossil_fatal("no such wiki page: %s", zPageName);
628 }
629 if( rid!=0 && isNew ){
630 fossil_fatal("wiki page %s already exists", zPageName);
631 }
632
 
 
 
 
 
 
 
 
 
 
 
 
 
 
633 blob_zero(&wiki);
634 zDate = db_text(0, "SELECT datetime('now')");
635 zDate[10] = 'T';
636 blob_appendf(&wiki, "D %s\n", zDate);
637 free(zDate);
638 blob_appendf(&wiki, "L %F\n", zPageName );
639 if( rid ){
640 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
641 blob_appendf(&wiki, "P %s\n", zUuid);
642 free(zUuid);
643 }
644 user_select();
645 if( g.zLogin ){
646 blob_appendf(&wiki, "U %F\n", g.zLogin);
647 }
648 blob_appendf( &wiki, "W %d\n%s\n", blob_size(pContent),
649 blob_str(pContent) );
 
650 md5sum_blob(&wiki, &cksum);
651 blob_appendf(&wiki, "Z %b\n", &cksum);
652 blob_reset(&cksum);
653 db_begin_transaction();
654 nrid = content_put( &wiki, 0, 0 );
@@ -678,20 +665,23 @@
665 **
666 ** Usage: %fossil wiki (export|commit|list) WikiName
667 **
668 ** Run various subcommands to fetch wiki entries.
669 **
670 ** %fossil wiki export PAGENAME
671 **
672 ** Sends the latest version of the PAGENAME wiki
673 ** entry to stdout.
674 **
675 ** %fossil wiki commit PAGENAME ?FILE?
676 **
677 ** Commit changes to a wiki page from FILE or from standard.
678 **
679 ** %fossil wiki create PAGENAME ?FILE?
680 **
681 ** Create a new wiki page with initial content taken from
682 ** FILE or from standard input.
 
683 **
684 ** %fossil wiki list
685 **
686 ** Lists all wiki entries, one per line, ordered
687 ** case-insentively by name.
@@ -762,18 +752,31 @@
752 }
753 for(i=strlen(zBody); i>0 && isspace(zBody[i-1]); i--){}
754 printf("%.*s\n", i, zBody);
755 return;
756 }else
757 if( strncmp(g.argv[2],"commit",n)==0
758 || strncmp(g.argv[2],"create",n)==0 ){
759 char *zPageName;
760 Blob content;
761 if( g.argc!=4 && g.argc!=5 ){
762 usage("commit PAGENAME ?FILE?");
763 }
764 zPageName = g.argv[3];
765 if( g.argc==4 ){
766 blob_read_from_channel(&content, stdin, -1);
767 }else{
768 blob_read_from_file(&content, g.argv[4]);
769 }
770 if( g.argv[2][1]=='r' ){
771 wiki_cmd_commit(zPageName, 1, &content);
772 printf("Created new wiki page %s.\n", zPageName);
773 }else{
774 wiki_cmd_commit(zPageName, 0, &content);
775 printf("Updated wiki page %s.\n", zPageName);
776 }
777 blob_reset(&content);
778 }else
779 if( strncmp(g.argv[2],"delete",n)==0 ){
780 if( g.argc!=5 ){
781 usage("delete PAGENAME");
782 }
783

Keyboard Shortcuts

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