Fossil SCM
added optional FILE arg to wiki export
Commit
7adbf773c2377e5289d22bf997314d23a71a6f56
Parent
e03d1be55b3056e…
1 file changed
+28
-16
+28
-16
| --- src/wiki.c | ||
| +++ src/wiki.c | ||
| @@ -665,14 +665,14 @@ | ||
| 665 | 665 | ** |
| 666 | 666 | ** Usage: %fossil wiki (export|commit|list) WikiName |
| 667 | 667 | ** |
| 668 | 668 | ** Run various subcommands to fetch wiki entries. |
| 669 | 669 | ** |
| 670 | -** %fossil wiki export PAGENAME | |
| 670 | +** %fossil wiki export PAGENAME ?FILE? | |
| 671 | 671 | ** |
| 672 | 672 | ** Sends the latest version of the PAGENAME wiki |
| 673 | -** entry to stdout. | |
| 673 | +** entry to the given file or standard output. | |
| 674 | 674 | ** |
| 675 | 675 | ** %fossil wiki commit PAGENAME ?FILE? |
| 676 | 676 | ** |
| 677 | 677 | ** Commit changes to a wiki page from FILE or from standard. |
| 678 | 678 | ** |
| @@ -686,29 +686,23 @@ | ||
| 686 | 686 | ** Lists all wiki entries, one per line, ordered |
| 687 | 687 | ** case-insentively by name. |
| 688 | 688 | ** |
| 689 | 689 | ** TODOs: |
| 690 | 690 | ** |
| 691 | -** %fossil wiki export ?UUID? ?-f outfile[=stdout]? WikiName | |
| 691 | +** %fossil wiki export ?-u UUID? WikiName ?FILE? | |
| 692 | 692 | ** |
| 693 | -** Outputs the selected version of WikiName to the selected file. | |
| 693 | +** Outputs the selected version of WikiName. | |
| 694 | 694 | ** |
| 695 | 695 | ** %fossil wiki delete ?-m MESSAGE? WikiName |
| 696 | 696 | ** |
| 697 | 697 | ** The same as deleting a file entry, but i don't know if fossil |
| 698 | 698 | ** supports a commit message for Wiki entries. |
| 699 | 699 | ** |
| 700 | 700 | ** %fossil wiki ?-u? ?-d? ?-s=[|]? list |
| 701 | 701 | ** |
| 702 | -** Lists the UUID and/or Date of last change for each entry, delimited | |
| 703 | -** by the -s char. | |
| 704 | -** | |
| 705 | -** %fossil wiki commit ?-f infile[=stdin]? WikiName | |
| 706 | -** | |
| 707 | -** Commit changes to a wiki page from a file or standard input. | |
| 708 | -** It creats a new entry if needed (or is that philosophically | |
| 709 | -** wrong?). | |
| 702 | +** Lists the UUID and/or Date of last change along with each entry | |
| 703 | +** name, delimited by the -s char. | |
| 710 | 704 | ** |
| 711 | 705 | ** %fossil wiki diff ?UUID? ?-f infile[=stdin]? EntryName |
| 712 | 706 | ** |
| 713 | 707 | ** Diffs the local copy of a page with a given version (defaulting |
| 714 | 708 | ** to the head version). |
| @@ -723,17 +717,18 @@ | ||
| 723 | 717 | if( n==0 ){ |
| 724 | 718 | goto wiki_cmd_usage; |
| 725 | 719 | } |
| 726 | 720 | |
| 727 | 721 | if( strncmp(g.argv[2],"export",n)==0 ){ |
| 728 | - char const *zPageName; /* Name of the wiki page to export */ | |
| 722 | + char const *zPageName; /* Name of the wiki page to export */ | |
| 723 | + char const *zFile; /* Name of the output file (0=stdout) */ | |
| 729 | 724 | int rid; /* Artifact ID of the wiki page */ |
| 730 | 725 | int i; /* Loop counter */ |
| 731 | 726 | char *zBody = 0; /* Wiki page content */ |
| 732 | 727 | Manifest m; /* Parsed wiki page content */ |
| 733 | - if( g.argc!=4 ){ | |
| 734 | - usage("export PAGENAME"); | |
| 728 | + if( (g.argc!=4) && (g.argc!=5) ){ | |
| 729 | + usage("export PAGENAME ?FILE?"); | |
| 735 | 730 | } |
| 736 | 731 | zPageName = g.argv[3]; |
| 737 | 732 | rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x" |
| 738 | 733 | " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'" |
| 739 | 734 | " ORDER BY x.mtime DESC LIMIT 1", |
| @@ -749,11 +744,28 @@ | ||
| 749 | 744 | } |
| 750 | 745 | if( zBody==0 ){ |
| 751 | 746 | fossil_fatal("wiki page [%s] not found",zPageName); |
| 752 | 747 | } |
| 753 | 748 | for(i=strlen(zBody); i>0 && isspace(zBody[i-1]); i--){} |
| 754 | - printf("%.*s\n", i, zBody); | |
| 749 | + zFile = (g.argc==4) ? 0 : g.argv[4]; | |
| 750 | + if( zFile ){ | |
| 751 | + FILE * zF; | |
| 752 | + short doClose = 0; | |
| 753 | + if( (1 == strlen(zFile)) && ('-'==zFile[0]) ){ | |
| 754 | + zF = stdout; | |
| 755 | + }else{ | |
| 756 | + zF = fopen( zFile, "w" ); | |
| 757 | + doClose = zF ? 1 : 0; | |
| 758 | + } | |
| 759 | + if( ! zF ){ | |
| 760 | + fossil_fatal("wiki export could not open output file for writing."); | |
| 761 | + } | |
| 762 | + fprintf(zF,"%.*s\n", i, zBody); | |
| 763 | + if( doClose ) fclose(zF); | |
| 764 | + }else{ | |
| 765 | + printf("%.*s\n", i, zBody); | |
| 766 | + } | |
| 755 | 767 | return; |
| 756 | 768 | }else |
| 757 | 769 | if( strncmp(g.argv[2],"commit",n)==0 |
| 758 | 770 | || strncmp(g.argv[2],"create",n)==0 ){ |
| 759 | 771 | char *zPageName; |
| 760 | 772 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -665,14 +665,14 @@ | |
| 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 | ** |
| @@ -686,29 +686,23 @@ | |
| 686 | ** Lists all wiki entries, one per line, ordered |
| 687 | ** case-insentively by name. |
| 688 | ** |
| 689 | ** TODOs: |
| 690 | ** |
| 691 | ** %fossil wiki export ?UUID? ?-f outfile[=stdout]? WikiName |
| 692 | ** |
| 693 | ** Outputs the selected version of WikiName to the selected file. |
| 694 | ** |
| 695 | ** %fossil wiki delete ?-m MESSAGE? WikiName |
| 696 | ** |
| 697 | ** The same as deleting a file entry, but i don't know if fossil |
| 698 | ** supports a commit message for Wiki entries. |
| 699 | ** |
| 700 | ** %fossil wiki ?-u? ?-d? ?-s=[|]? list |
| 701 | ** |
| 702 | ** Lists the UUID and/or Date of last change for each entry, delimited |
| 703 | ** by the -s char. |
| 704 | ** |
| 705 | ** %fossil wiki commit ?-f infile[=stdin]? WikiName |
| 706 | ** |
| 707 | ** Commit changes to a wiki page from a file or standard input. |
| 708 | ** It creats a new entry if needed (or is that philosophically |
| 709 | ** wrong?). |
| 710 | ** |
| 711 | ** %fossil wiki diff ?UUID? ?-f infile[=stdin]? EntryName |
| 712 | ** |
| 713 | ** Diffs the local copy of a page with a given version (defaulting |
| 714 | ** to the head version). |
| @@ -723,17 +717,18 @@ | |
| 723 | if( n==0 ){ |
| 724 | goto wiki_cmd_usage; |
| 725 | } |
| 726 | |
| 727 | if( strncmp(g.argv[2],"export",n)==0 ){ |
| 728 | char const *zPageName; /* Name of the wiki page to export */ |
| 729 | int rid; /* Artifact ID of the wiki page */ |
| 730 | int i; /* Loop counter */ |
| 731 | char *zBody = 0; /* Wiki page content */ |
| 732 | Manifest m; /* Parsed wiki page content */ |
| 733 | if( g.argc!=4 ){ |
| 734 | usage("export PAGENAME"); |
| 735 | } |
| 736 | zPageName = g.argv[3]; |
| 737 | rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x" |
| 738 | " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'" |
| 739 | " ORDER BY x.mtime DESC LIMIT 1", |
| @@ -749,11 +744,28 @@ | |
| 749 | } |
| 750 | if( zBody==0 ){ |
| 751 | fossil_fatal("wiki page [%s] not found",zPageName); |
| 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 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -665,14 +665,14 @@ | |
| 665 | ** |
| 666 | ** Usage: %fossil wiki (export|commit|list) WikiName |
| 667 | ** |
| 668 | ** Run various subcommands to fetch wiki entries. |
| 669 | ** |
| 670 | ** %fossil wiki export PAGENAME ?FILE? |
| 671 | ** |
| 672 | ** Sends the latest version of the PAGENAME wiki |
| 673 | ** entry to the given file or standard output. |
| 674 | ** |
| 675 | ** %fossil wiki commit PAGENAME ?FILE? |
| 676 | ** |
| 677 | ** Commit changes to a wiki page from FILE or from standard. |
| 678 | ** |
| @@ -686,29 +686,23 @@ | |
| 686 | ** Lists all wiki entries, one per line, ordered |
| 687 | ** case-insentively by name. |
| 688 | ** |
| 689 | ** TODOs: |
| 690 | ** |
| 691 | ** %fossil wiki export ?-u UUID? WikiName ?FILE? |
| 692 | ** |
| 693 | ** Outputs the selected version of WikiName. |
| 694 | ** |
| 695 | ** %fossil wiki delete ?-m MESSAGE? WikiName |
| 696 | ** |
| 697 | ** The same as deleting a file entry, but i don't know if fossil |
| 698 | ** supports a commit message for Wiki entries. |
| 699 | ** |
| 700 | ** %fossil wiki ?-u? ?-d? ?-s=[|]? list |
| 701 | ** |
| 702 | ** Lists the UUID and/or Date of last change along with each entry |
| 703 | ** name, delimited by the -s char. |
| 704 | ** |
| 705 | ** %fossil wiki diff ?UUID? ?-f infile[=stdin]? EntryName |
| 706 | ** |
| 707 | ** Diffs the local copy of a page with a given version (defaulting |
| 708 | ** to the head version). |
| @@ -723,17 +717,18 @@ | |
| 717 | if( n==0 ){ |
| 718 | goto wiki_cmd_usage; |
| 719 | } |
| 720 | |
| 721 | if( strncmp(g.argv[2],"export",n)==0 ){ |
| 722 | char const *zPageName; /* Name of the wiki page to export */ |
| 723 | char const *zFile; /* Name of the output file (0=stdout) */ |
| 724 | int rid; /* Artifact ID of the wiki page */ |
| 725 | int i; /* Loop counter */ |
| 726 | char *zBody = 0; /* Wiki page content */ |
| 727 | Manifest m; /* Parsed wiki page content */ |
| 728 | if( (g.argc!=4) && (g.argc!=5) ){ |
| 729 | usage("export PAGENAME ?FILE?"); |
| 730 | } |
| 731 | zPageName = g.argv[3]; |
| 732 | rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x" |
| 733 | " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'" |
| 734 | " ORDER BY x.mtime DESC LIMIT 1", |
| @@ -749,11 +744,28 @@ | |
| 744 | } |
| 745 | if( zBody==0 ){ |
| 746 | fossil_fatal("wiki page [%s] not found",zPageName); |
| 747 | } |
| 748 | for(i=strlen(zBody); i>0 && isspace(zBody[i-1]); i--){} |
| 749 | zFile = (g.argc==4) ? 0 : g.argv[4]; |
| 750 | if( zFile ){ |
| 751 | FILE * zF; |
| 752 | short doClose = 0; |
| 753 | if( (1 == strlen(zFile)) && ('-'==zFile[0]) ){ |
| 754 | zF = stdout; |
| 755 | }else{ |
| 756 | zF = fopen( zFile, "w" ); |
| 757 | doClose = zF ? 1 : 0; |
| 758 | } |
| 759 | if( ! zF ){ |
| 760 | fossil_fatal("wiki export could not open output file for writing."); |
| 761 | } |
| 762 | fprintf(zF,"%.*s\n", i, zBody); |
| 763 | if( doClose ) fclose(zF); |
| 764 | }else{ |
| 765 | printf("%.*s\n", i, zBody); |
| 766 | } |
| 767 | return; |
| 768 | }else |
| 769 | if( strncmp(g.argv[2],"commit",n)==0 |
| 770 | || strncmp(g.argv[2],"create",n)==0 ){ |
| 771 | char *zPageName; |
| 772 |