Fossil SCM
Update the "fossil wiki export" command to use standard file output utilities so that line endings will be handled correctly. Ticket [d9040c134bf41]
Commit
11f2f71f4ca93d2121dc2d457dc9287d1b2fe09b
Parent
336e194c4d1e41a…
1 file changed
+7
-18
+7
-18
| --- src/wiki.c | ||
| +++ src/wiki.c | ||
| @@ -891,10 +891,11 @@ | ||
| 891 | 891 | char const *zPageName; /* Name of the wiki page to export */ |
| 892 | 892 | char const *zFile; /* Name of the output file (0=stdout) */ |
| 893 | 893 | int rid; /* Artifact ID of the wiki page */ |
| 894 | 894 | int i; /* Loop counter */ |
| 895 | 895 | char *zBody = 0; /* Wiki page content */ |
| 896 | + Blob body; /* Wiki page content */ | |
| 896 | 897 | Manifest *pWiki = 0; /* Parsed wiki page content */ |
| 897 | 898 | |
| 898 | 899 | if( (g.argc!=4) && (g.argc!=5) ){ |
| 899 | 900 | usage("export PAGENAME ?FILE?"); |
| 900 | 901 | } |
| @@ -909,28 +910,16 @@ | ||
| 909 | 910 | } |
| 910 | 911 | if( zBody==0 ){ |
| 911 | 912 | fossil_fatal("wiki page [%s] not found",zPageName); |
| 912 | 913 | } |
| 913 | 914 | for(i=strlen(zBody); i>0 && fossil_isspace(zBody[i-1]); i--){} |
| 914 | - zFile = (g.argc==4) ? 0 : g.argv[4]; | |
| 915 | - if( zFile ){ | |
| 916 | - FILE * zF; | |
| 917 | - short doClose = 0; | |
| 918 | - if( (1 == strlen(zFile)) && ('-'==zFile[0]) ){ | |
| 919 | - zF = stdout; | |
| 920 | - }else{ | |
| 921 | - zF = fossil_fopen( zFile, "w" ); | |
| 922 | - doClose = zF ? 1 : 0; | |
| 923 | - } | |
| 924 | - if( ! zF ){ | |
| 925 | - fossil_fatal("wiki export could not open output file for writing."); | |
| 926 | - } | |
| 927 | - fprintf(zF,"%.*s\n", i, zBody); | |
| 928 | - if( doClose ) fclose(zF); | |
| 929 | - }else{ | |
| 930 | - fossil_print("%.*s\n", i, zBody); | |
| 931 | - } | |
| 915 | + zBody[i] = 0; | |
| 916 | + zFile = (g.argc==4) ? "-" : g.argv[4]; | |
| 917 | + blob_init(&body, zBody, -1); | |
| 918 | + blob_append(&body, "\n", 1); | |
| 919 | + blob_write_to_file(&body, zFile); | |
| 920 | + blob_reset(&body); | |
| 932 | 921 | manifest_destroy(pWiki); |
| 933 | 922 | return; |
| 934 | 923 | }else |
| 935 | 924 | if( strncmp(g.argv[2],"commit",n)==0 |
| 936 | 925 | || strncmp(g.argv[2],"create",n)==0 ){ |
| 937 | 926 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -891,10 +891,11 @@ | |
| 891 | char const *zPageName; /* Name of the wiki page to export */ |
| 892 | char const *zFile; /* Name of the output file (0=stdout) */ |
| 893 | int rid; /* Artifact ID of the wiki page */ |
| 894 | int i; /* Loop counter */ |
| 895 | char *zBody = 0; /* Wiki page content */ |
| 896 | Manifest *pWiki = 0; /* Parsed wiki page content */ |
| 897 | |
| 898 | if( (g.argc!=4) && (g.argc!=5) ){ |
| 899 | usage("export PAGENAME ?FILE?"); |
| 900 | } |
| @@ -909,28 +910,16 @@ | |
| 909 | } |
| 910 | if( zBody==0 ){ |
| 911 | fossil_fatal("wiki page [%s] not found",zPageName); |
| 912 | } |
| 913 | for(i=strlen(zBody); i>0 && fossil_isspace(zBody[i-1]); i--){} |
| 914 | zFile = (g.argc==4) ? 0 : g.argv[4]; |
| 915 | if( zFile ){ |
| 916 | FILE * zF; |
| 917 | short doClose = 0; |
| 918 | if( (1 == strlen(zFile)) && ('-'==zFile[0]) ){ |
| 919 | zF = stdout; |
| 920 | }else{ |
| 921 | zF = fossil_fopen( zFile, "w" ); |
| 922 | doClose = zF ? 1 : 0; |
| 923 | } |
| 924 | if( ! zF ){ |
| 925 | fossil_fatal("wiki export could not open output file for writing."); |
| 926 | } |
| 927 | fprintf(zF,"%.*s\n", i, zBody); |
| 928 | if( doClose ) fclose(zF); |
| 929 | }else{ |
| 930 | fossil_print("%.*s\n", i, zBody); |
| 931 | } |
| 932 | manifest_destroy(pWiki); |
| 933 | return; |
| 934 | }else |
| 935 | if( strncmp(g.argv[2],"commit",n)==0 |
| 936 | || strncmp(g.argv[2],"create",n)==0 ){ |
| 937 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -891,10 +891,11 @@ | |
| 891 | char const *zPageName; /* Name of the wiki page to export */ |
| 892 | char const *zFile; /* Name of the output file (0=stdout) */ |
| 893 | int rid; /* Artifact ID of the wiki page */ |
| 894 | int i; /* Loop counter */ |
| 895 | char *zBody = 0; /* Wiki page content */ |
| 896 | Blob body; /* Wiki page content */ |
| 897 | Manifest *pWiki = 0; /* Parsed wiki page content */ |
| 898 | |
| 899 | if( (g.argc!=4) && (g.argc!=5) ){ |
| 900 | usage("export PAGENAME ?FILE?"); |
| 901 | } |
| @@ -909,28 +910,16 @@ | |
| 910 | } |
| 911 | if( zBody==0 ){ |
| 912 | fossil_fatal("wiki page [%s] not found",zPageName); |
| 913 | } |
| 914 | for(i=strlen(zBody); i>0 && fossil_isspace(zBody[i-1]); i--){} |
| 915 | zBody[i] = 0; |
| 916 | zFile = (g.argc==4) ? "-" : g.argv[4]; |
| 917 | blob_init(&body, zBody, -1); |
| 918 | blob_append(&body, "\n", 1); |
| 919 | blob_write_to_file(&body, zFile); |
| 920 | blob_reset(&body); |
| 921 | manifest_destroy(pWiki); |
| 922 | return; |
| 923 | }else |
| 924 | if( strncmp(g.argv[2],"commit",n)==0 |
| 925 | || strncmp(g.argv[2],"create",n)==0 ){ |
| 926 |