Fossil

Check-in [cde6e7a3]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added 'wiki commit'. Minor stylistic cleanups.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:cde6e7a303b0b19621b35b91628b573b6ed75085
User & Date: stephan 2008-05-15 15:23:08
Context
2008-05-15
16:58
Add the "/doc" method on the server. check-in: 7351b634 user: drh tags: trunk
15:23
Added 'wiki commit'. Minor stylistic cleanups. check-in: cde6e7a3 user: stephan tags: trunk
13:37
Update SQLite to version 3.5.9. check-in: a85cc7ce user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/wiki.c.

595
596
597
598
599
600
601
602
603































































604
605
606
607
608
609
610
611
612
613






614
615
616
617
618
619
620
...
634
635
636
637
638
639
640





641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684

685
686
687
688
689






690



691
692
693
694
695
696
697
  @ <p>The &lt;verbatim&gt; tag disables all wiki and HTML markup
  @ up through the next &lt;/verbatim&gt;.  The &lt;nowiki&gt; tag
  @ disables all wiki formatting rules through the matching
  @ &lt;/nowiki&gt; element.
  @ </ol>
  style_footer();
}

/*































































** COMMAND: wiki
**
** Usage: %fossil wiki (export|delete|commit|list) WikiName
**
** Run various subcommands to fetch wiki entries.
**
**     %fossil wiki export WikiName
**
**        Sends the latest version of the WikiName wiki
**        entry to stdout.






**
**     %fossil wiki list
**
**        Lists all wiki entries, one per line, ordered
**        case-insentively by name.
**
** TODOs:
................................................................................
**        by the -s char.
**
**     %fossil wiki commit ?-f infile[=stdin]? WikiName
**
**        Commit changes to a wiki page from a file or standard input.
**        It creats a new entry if needed (or is that philosophically
**        wrong?).





*/
void wiki_cmd(void){
  int n;
  db_find_and_open_repository(1);
  if( g.argc<3 ){
    goto wiki_cmd_usage;
  }
  n = strlen(g.argv[2]);
  if( n==0 ){
    goto wiki_cmd_usage;
  }

  if( strncmp(g.argv[2],"export",n)==0 ){
    char *wname;            /* Name of the wiki page to export */
    int rid;                /* Artifact ID of the wiki page */
    int i;                  /* Loop counter */
    char *zBody = 0;        /* Wiki page content */
    Manifest m;             /* Parsed wiki page content */

    if( g.argc!=4 ){
      usage("export PAGENAME");
    }
    wname = g.argv[3];
    rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
      " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
      " ORDER BY x.mtime DESC LIMIT 1",
      wname 
    );
    if( rid ){
      Blob content;
      content_get(rid, &content);
      manifest_parse(&m, &content);
      if( m.type==CFTYPE_WIKI ){
        zBody = m.zWiki;
      }
    }
    if( zBody==0 ){
      fossil_fatal("wiki page [%s] not found",wname);
    }
    for(i=strlen(zBody); i>0 && isspace(zBody[i-1]); i--){}
    printf("%.*s\n", i, zBody);
    return;
  }else
  if( strncmp(g.argv[2],"commit",n)==0 ){

    char *wname;
    if( g.argc!=4 ){
      usage("commit PAGENAME");
    }
    wname = g.argv[3];






    fossil_fatal("wiki commit not yet implemented.");



  }else
  if( strncmp(g.argv[2],"delete",n)==0 ){
    if( g.argc!=5 ){
      usage("delete PAGENAME");
    }
    fossil_fatal("delete not yet implemented.");
  }else









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


|







>
>
>
>
>
>







 







>
>
>
>
>













|




<



|



|










|






>
|



|
>
>
>
>
>
>
|
>
>
>







595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
...
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732

733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
  @ <p>The &lt;verbatim&gt; tag disables all wiki and HTML markup
  @ up through the next &lt;/verbatim&gt;.  The &lt;nowiki&gt; tag
  @ disables all wiki formatting rules through the matching
  @ &lt;/nowiki&gt; element.
  @ </ol>
  style_footer();
}

/*
**  wiki_cmd_commit() is the implementation of "wiki commit ...".
**
** As arguments it expects:
**
** zPageName = the wiki entry's name.
**
** rid = record ID for the zPageName entry. This func SHOULD deduce
** this from zPageName, but the code which calls this func already has
** the rid, so we pass it along here. If it does not match the entry
** for zPageName then Undefined Behaviour.
**
** in = input file. The file is read until EOF but is not closed
** by this function (it might be stdin!).
**
** Returns 0 on error, non-zero on success.
**
** TODOs:
** - take EITHER zPageName OR rid. We don't need both.
** - make use of the return value. Add more error checking.
** - give the uuid back to the caller so it can be shown
**   in the status output. ("committed version XXXXX of page ...")
*/
int wiki_cmd_commit( char const * zPageName, int rid, FILE * in )
{
  Blob wiki;              /* Wiki page content */
  Blob content;           /* read-in content */
  Blob cksum;             /* wiki checksum */
  int nrid;               /* not really sure */
  char * zDate;           /* timestamp */
  char * zUuid;           /* uuid for rid */
  blob_read_from_channel( &content, in, -1 );
  // ^^^ Reminder: we should allow empty (zero-byte) entries, so don't exit
  // if read returns 0.
  blob_zero(&wiki);
  zDate = db_text(0, "SELECT datetime('now')");
  zDate[10] = 'T';
  blob_appendf(&wiki, "D %s\n", zDate);
  free(zDate);
  blob_appendf(&wiki, "L %F\n", zPageName );
  zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
  blob_appendf(&wiki, "P %s\n", zUuid);
  free(zUuid);
  user_select();
  if( g.zLogin ){
      blob_appendf(&wiki, "U %F\n", g.zLogin);
  }
  blob_appendf( &wiki, "W %d\n%s\n", blob_size(&content),
                blob_buffer(&content) );
  blob_reset(&content);
  md5sum_blob(&wiki, &cksum);
  blob_appendf(&wiki, "Z %b\n", &cksum);
  blob_reset(&cksum);
  db_begin_transaction();
  nrid = content_put( &wiki, 0, 0 );
  db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nrid);
  manifest_crosslink(nrid,&wiki);
  blob_reset(&wiki);
  content_deltify(rid,nrid,0);
  db_end_transaction(0);
  return 1;
}

/*
** COMMAND: wiki
**
** Usage: %fossil wiki (export|commit|list) WikiName
**
** Run various subcommands to fetch wiki entries.
**
**     %fossil wiki export WikiName
**
**        Sends the latest version of the WikiName wiki
**        entry to stdout.
**
**     %fossil wiki commit WikiName
**
**        Commit changes to a wiki page from standard input.
**        It cannot currently create a new entry (this is on the
**        to-fix list).
**
**     %fossil wiki list
**
**        Lists all wiki entries, one per line, ordered
**        case-insentively by name.
**
** TODOs:
................................................................................
**        by the -s char.
**
**     %fossil wiki commit ?-f infile[=stdin]? WikiName
**
**        Commit changes to a wiki page from a file or standard input.
**        It creats a new entry if needed (or is that philosophically
**        wrong?).
**
**     %fossil wiki diff ?UUID? ?-f infile[=stdin]? EntryName
**
**        Diffs the local copy of a page with a given version (defaulting
**        to the head version).
*/
void wiki_cmd(void){
  int n;
  db_find_and_open_repository(1);
  if( g.argc<3 ){
    goto wiki_cmd_usage;
  }
  n = strlen(g.argv[2]);
  if( n==0 ){
    goto wiki_cmd_usage;
  }

  if( strncmp(g.argv[2],"export",n)==0 ){
    char const *zPageName;            /* Name of the wiki page to export */
    int rid;                /* Artifact ID of the wiki page */
    int i;                  /* Loop counter */
    char *zBody = 0;        /* Wiki page content */
    Manifest m;             /* Parsed wiki page content */

    if( g.argc!=4 ){
      usage("export PAGENAME");
    }
    zPageName = g.argv[3];
    rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
      " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
      " ORDER BY x.mtime DESC LIMIT 1",
      zPageName 
    );
    if( rid ){
      Blob content;
      content_get(rid, &content);
      manifest_parse(&m, &content);
      if( m.type==CFTYPE_WIKI ){
        zBody = m.zWiki;
      }
    }
    if( zBody==0 ){
      fossil_fatal("wiki page [%s] not found",zPageName);
    }
    for(i=strlen(zBody); i>0 && isspace(zBody[i-1]); i--){}
    printf("%.*s\n", i, zBody);
    return;
  }else
  if( strncmp(g.argv[2],"commit",n)==0 ){
    int rid;
    char *zPageName;
    if( g.argc!=4 ){
      usage("commit PAGENAME");
    }
    zPageName = g.argv[3];
    rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
                 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
		 " ORDER BY x.mtime DESC LIMIT 1",
		 zPageName
		 );
    if( ! rid ){
        fossil_fatal("wiki commit NewEntry not yet implemented.");
    }
    wiki_cmd_commit( zPageName, rid, stdin );
    printf("Committed wiki page %s.\n", zPageName);
  }else
  if( strncmp(g.argv[2],"delete",n)==0 ){
    if( g.argc!=5 ){
      usage("delete PAGENAME");
    }
    fossil_fatal("delete not yet implemented.");
  }else