Fossil SCM
cleaned up error handling a bit, minor code style changes, s/import/commit/
Commit
feee32d3af2760a8c90e6811ac358905e17f38ab
Parent
87a1a31d1d1d9c7…
1 file changed
+31
-19
+31
-19
| --- src/wiki.c | ||
| +++ src/wiki.c | ||
| @@ -606,11 +606,11 @@ | ||
| 606 | 606 | } |
| 607 | 607 | |
| 608 | 608 | /* |
| 609 | 609 | ** COMMAND: wiki |
| 610 | 610 | ** |
| 611 | -** Usage: %fossil wiki (export|import|list) WikiName | |
| 611 | +** Usage: %fossil wiki (export|commit|list) WikiName | |
| 612 | 612 | ** |
| 613 | 613 | ** Run various subcommands to fetch wiki entries. |
| 614 | 614 | ** |
| 615 | 615 | ** %fossil wiki export WikiName |
| 616 | 616 | ** |
| @@ -623,11 +623,11 @@ | ||
| 623 | 623 | ** |
| 624 | 624 | ** |
| 625 | 625 | ** TODOs: |
| 626 | 626 | ** |
| 627 | 627 | ** %fossil export WikiName ?UUID? ?-f outfile? |
| 628 | -** %fossil import WikiName ?-f infile? | |
| 628 | +** %fossil commit WikiName ?-f infile? | |
| 629 | 629 | */ |
| 630 | 630 | void wiki_cmd(void){ |
| 631 | 631 | int n; |
| 632 | 632 | db_find_and_open_repository(1); |
| 633 | 633 | if( g.argc<3 ){ |
| @@ -646,21 +646,18 @@ | ||
| 646 | 646 | char * sql; |
| 647 | 647 | if( g.argc!=4 ){ |
| 648 | 648 | usage("export EntryName"); |
| 649 | 649 | } |
| 650 | 650 | wname = g.argv[3]; |
| 651 | - //printf("exporting wiki entry %s\n",wname); | |
| 652 | 651 | rid = -1; |
| 653 | - | |
| 654 | - sql = mprintf("select x.rid from tag t, tagxref x " | |
| 655 | - "where x.tagid=t.tagid and t.tagname='wiki-%q' " | |
| 656 | - " order by x.mtime desc limit 1", | |
| 652 | + sql = mprintf("SELECT x.rid FROM tag t, tagxref x" | |
| 653 | + " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'" | |
| 654 | + " ORDER BY x.mtime DESC LIMIT 1", | |
| 657 | 655 | wname ); |
| 658 | 656 | db_prepare(&q, "%z", sql ); |
| 659 | - while( db_step(&q) == SQLITE_ROW ){ | |
| 657 | + if( db_step(&q) == SQLITE_ROW ){ | |
| 660 | 658 | rid = db_column_int(&q,0); |
| 661 | - break; | |
| 662 | 659 | } |
| 663 | 660 | db_finalize(&q); |
| 664 | 661 | if( -1 == rid ){ |
| 665 | 662 | fprintf(stderr,"export error: wiki entry [%s] not found.\n",wname); |
| 666 | 663 | exit(1); |
| @@ -690,10 +687,16 @@ | ||
| 690 | 687 | if( *it == '\n') { ++it; break; } |
| 691 | 688 | ++it; |
| 692 | 689 | } |
| 693 | 690 | continue; |
| 694 | 691 | } |
| 692 | + if( ! *it ) | |
| 693 | + { | |
| 694 | + fprintf(stderr, | |
| 695 | + "export reached end of input before finding a 'W' card.\n"); | |
| 696 | + exit(1); | |
| 697 | + } | |
| 695 | 698 | ++it; |
| 696 | 699 | while( (*it) && (*it != '\n') ){ |
| 697 | 700 | if( isspace(*it) ) { ++it; continue; } |
| 698 | 701 | blob_append(&numbuf,it,1); |
| 699 | 702 | ++it; |
| @@ -700,32 +703,41 @@ | ||
| 700 | 703 | } |
| 701 | 704 | if( '\n' == *it ) ++it; |
| 702 | 705 | if( 0 == blob_size(&numbuf) ){ |
| 703 | 706 | fprintf(stderr, |
| 704 | 707 | "export error: didn't find \"W NUMBER\" line in input!\n"); |
| 705 | - blob_zero(&buf); | |
| 706 | - blob_zero(&numbuf); | |
| 708 | + blob_reset(&buf); | |
| 709 | + blob_reset(&numbuf); | |
| 707 | 710 | exit(1); |
| 708 | 711 | } |
| 709 | 712 | len = atoi(blob_buffer(&numbuf)); |
| 710 | - //fprintf(stderr,"Writing %d (%s) bytes...\n",len,blob_buffer(&numbuf)); | |
| 711 | - blob_zero(&numbuf); | |
| 713 | + //fprintf(stderr,"Writing %s (%d) bytes...\n",blob_buffer(&numbuf),len); | |
| 714 | + blob_reset(&numbuf); | |
| 715 | + if( ( (it - blob_buffer(&buf)) + len) > blob_size(&buf) ){ | |
| 716 | + fprintf(stderr, | |
| 717 | + "export error: manifest data doesn't match actual data size!" | |
| 718 | + " Manifest says [%s (%d)] bytes.\n", | |
| 719 | + blob_buffer(&numbuf), len ); | |
| 720 | + blob_reset(&buf); | |
| 721 | + blob_reset(&numbuf); | |
| 722 | + exit(1); | |
| 723 | + } | |
| 712 | 724 | fwrite(it,sizeof(char),len,stdout); |
| 713 | - blob_zero(&buf); | |
| 725 | + blob_reset(&buf); | |
| 714 | 726 | return; |
| 715 | 727 | } |
| 716 | 728 | } |
| 717 | - blob_zero(&buf); | |
| 729 | + blob_reset(&buf); | |
| 718 | 730 | return; |
| 719 | 731 | }else |
| 720 | - if( strncmp(g.argv[2],"import",n)==0 ){ | |
| 732 | + if( strncmp(g.argv[2],"commit",n)==0 ){ | |
| 721 | 733 | char *wname; |
| 722 | 734 | if( g.argc!=4 ){ |
| 723 | - usage("import EntryName"); | |
| 735 | + usage("commit EntryName"); | |
| 724 | 736 | } |
| 725 | 737 | wname = g.argv[3]; |
| 726 | - fprintf(stderr,"import not yet implemented.\n"); | |
| 738 | + fprintf(stderr,"commit not yet implemented.\n"); | |
| 727 | 739 | exit(1); |
| 728 | 740 | }else |
| 729 | 741 | if( strncmp(g.argv[2],"delete",n)==0 ){ |
| 730 | 742 | if( g.argc!=5 ){ |
| 731 | 743 | usage("delete WikiName"); |
| @@ -749,8 +761,8 @@ | ||
| 749 | 761 | goto wiki_cmd_usage; |
| 750 | 762 | } |
| 751 | 763 | return; |
| 752 | 764 | |
| 753 | 765 | wiki_cmd_usage: |
| 754 | - usage("delete|export|import|list [EntryName]"); | |
| 766 | + usage("delete|export|commit|list [EntryName]"); | |
| 755 | 767 | } |
| 756 | 768 | |
| 757 | 769 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -606,11 +606,11 @@ | |
| 606 | } |
| 607 | |
| 608 | /* |
| 609 | ** COMMAND: wiki |
| 610 | ** |
| 611 | ** Usage: %fossil wiki (export|import|list) WikiName |
| 612 | ** |
| 613 | ** Run various subcommands to fetch wiki entries. |
| 614 | ** |
| 615 | ** %fossil wiki export WikiName |
| 616 | ** |
| @@ -623,11 +623,11 @@ | |
| 623 | ** |
| 624 | ** |
| 625 | ** TODOs: |
| 626 | ** |
| 627 | ** %fossil export WikiName ?UUID? ?-f outfile? |
| 628 | ** %fossil import WikiName ?-f infile? |
| 629 | */ |
| 630 | void wiki_cmd(void){ |
| 631 | int n; |
| 632 | db_find_and_open_repository(1); |
| 633 | if( g.argc<3 ){ |
| @@ -646,21 +646,18 @@ | |
| 646 | char * sql; |
| 647 | if( g.argc!=4 ){ |
| 648 | usage("export EntryName"); |
| 649 | } |
| 650 | wname = g.argv[3]; |
| 651 | //printf("exporting wiki entry %s\n",wname); |
| 652 | rid = -1; |
| 653 | |
| 654 | sql = mprintf("select x.rid from tag t, tagxref x " |
| 655 | "where x.tagid=t.tagid and t.tagname='wiki-%q' " |
| 656 | " order by x.mtime desc limit 1", |
| 657 | wname ); |
| 658 | db_prepare(&q, "%z", sql ); |
| 659 | while( db_step(&q) == SQLITE_ROW ){ |
| 660 | rid = db_column_int(&q,0); |
| 661 | break; |
| 662 | } |
| 663 | db_finalize(&q); |
| 664 | if( -1 == rid ){ |
| 665 | fprintf(stderr,"export error: wiki entry [%s] not found.\n",wname); |
| 666 | exit(1); |
| @@ -690,10 +687,16 @@ | |
| 690 | if( *it == '\n') { ++it; break; } |
| 691 | ++it; |
| 692 | } |
| 693 | continue; |
| 694 | } |
| 695 | ++it; |
| 696 | while( (*it) && (*it != '\n') ){ |
| 697 | if( isspace(*it) ) { ++it; continue; } |
| 698 | blob_append(&numbuf,it,1); |
| 699 | ++it; |
| @@ -700,32 +703,41 @@ | |
| 700 | } |
| 701 | if( '\n' == *it ) ++it; |
| 702 | if( 0 == blob_size(&numbuf) ){ |
| 703 | fprintf(stderr, |
| 704 | "export error: didn't find \"W NUMBER\" line in input!\n"); |
| 705 | blob_zero(&buf); |
| 706 | blob_zero(&numbuf); |
| 707 | exit(1); |
| 708 | } |
| 709 | len = atoi(blob_buffer(&numbuf)); |
| 710 | //fprintf(stderr,"Writing %d (%s) bytes...\n",len,blob_buffer(&numbuf)); |
| 711 | blob_zero(&numbuf); |
| 712 | fwrite(it,sizeof(char),len,stdout); |
| 713 | blob_zero(&buf); |
| 714 | return; |
| 715 | } |
| 716 | } |
| 717 | blob_zero(&buf); |
| 718 | return; |
| 719 | }else |
| 720 | if( strncmp(g.argv[2],"import",n)==0 ){ |
| 721 | char *wname; |
| 722 | if( g.argc!=4 ){ |
| 723 | usage("import EntryName"); |
| 724 | } |
| 725 | wname = g.argv[3]; |
| 726 | fprintf(stderr,"import not yet implemented.\n"); |
| 727 | exit(1); |
| 728 | }else |
| 729 | if( strncmp(g.argv[2],"delete",n)==0 ){ |
| 730 | if( g.argc!=5 ){ |
| 731 | usage("delete WikiName"); |
| @@ -749,8 +761,8 @@ | |
| 749 | goto wiki_cmd_usage; |
| 750 | } |
| 751 | return; |
| 752 | |
| 753 | wiki_cmd_usage: |
| 754 | usage("delete|export|import|list [EntryName]"); |
| 755 | } |
| 756 | |
| 757 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -606,11 +606,11 @@ | |
| 606 | } |
| 607 | |
| 608 | /* |
| 609 | ** COMMAND: wiki |
| 610 | ** |
| 611 | ** Usage: %fossil wiki (export|commit|list) WikiName |
| 612 | ** |
| 613 | ** Run various subcommands to fetch wiki entries. |
| 614 | ** |
| 615 | ** %fossil wiki export WikiName |
| 616 | ** |
| @@ -623,11 +623,11 @@ | |
| 623 | ** |
| 624 | ** |
| 625 | ** TODOs: |
| 626 | ** |
| 627 | ** %fossil export WikiName ?UUID? ?-f outfile? |
| 628 | ** %fossil commit WikiName ?-f infile? |
| 629 | */ |
| 630 | void wiki_cmd(void){ |
| 631 | int n; |
| 632 | db_find_and_open_repository(1); |
| 633 | if( g.argc<3 ){ |
| @@ -646,21 +646,18 @@ | |
| 646 | char * sql; |
| 647 | if( g.argc!=4 ){ |
| 648 | usage("export EntryName"); |
| 649 | } |
| 650 | wname = g.argv[3]; |
| 651 | rid = -1; |
| 652 | sql = mprintf("SELECT x.rid FROM tag t, tagxref x" |
| 653 | " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'" |
| 654 | " ORDER BY x.mtime DESC LIMIT 1", |
| 655 | wname ); |
| 656 | db_prepare(&q, "%z", sql ); |
| 657 | if( db_step(&q) == SQLITE_ROW ){ |
| 658 | rid = db_column_int(&q,0); |
| 659 | } |
| 660 | db_finalize(&q); |
| 661 | if( -1 == rid ){ |
| 662 | fprintf(stderr,"export error: wiki entry [%s] not found.\n",wname); |
| 663 | exit(1); |
| @@ -690,10 +687,16 @@ | |
| 687 | if( *it == '\n') { ++it; break; } |
| 688 | ++it; |
| 689 | } |
| 690 | continue; |
| 691 | } |
| 692 | if( ! *it ) |
| 693 | { |
| 694 | fprintf(stderr, |
| 695 | "export reached end of input before finding a 'W' card.\n"); |
| 696 | exit(1); |
| 697 | } |
| 698 | ++it; |
| 699 | while( (*it) && (*it != '\n') ){ |
| 700 | if( isspace(*it) ) { ++it; continue; } |
| 701 | blob_append(&numbuf,it,1); |
| 702 | ++it; |
| @@ -700,32 +703,41 @@ | |
| 703 | } |
| 704 | if( '\n' == *it ) ++it; |
| 705 | if( 0 == blob_size(&numbuf) ){ |
| 706 | fprintf(stderr, |
| 707 | "export error: didn't find \"W NUMBER\" line in input!\n"); |
| 708 | blob_reset(&buf); |
| 709 | blob_reset(&numbuf); |
| 710 | exit(1); |
| 711 | } |
| 712 | len = atoi(blob_buffer(&numbuf)); |
| 713 | //fprintf(stderr,"Writing %s (%d) bytes...\n",blob_buffer(&numbuf),len); |
| 714 | blob_reset(&numbuf); |
| 715 | if( ( (it - blob_buffer(&buf)) + len) > blob_size(&buf) ){ |
| 716 | fprintf(stderr, |
| 717 | "export error: manifest data doesn't match actual data size!" |
| 718 | " Manifest says [%s (%d)] bytes.\n", |
| 719 | blob_buffer(&numbuf), len ); |
| 720 | blob_reset(&buf); |
| 721 | blob_reset(&numbuf); |
| 722 | exit(1); |
| 723 | } |
| 724 | fwrite(it,sizeof(char),len,stdout); |
| 725 | blob_reset(&buf); |
| 726 | return; |
| 727 | } |
| 728 | } |
| 729 | blob_reset(&buf); |
| 730 | return; |
| 731 | }else |
| 732 | if( strncmp(g.argv[2],"commit",n)==0 ){ |
| 733 | char *wname; |
| 734 | if( g.argc!=4 ){ |
| 735 | usage("commit EntryName"); |
| 736 | } |
| 737 | wname = g.argv[3]; |
| 738 | fprintf(stderr,"commit not yet implemented.\n"); |
| 739 | exit(1); |
| 740 | }else |
| 741 | if( strncmp(g.argv[2],"delete",n)==0 ){ |
| 742 | if( g.argc!=5 ){ |
| 743 | usage("delete WikiName"); |
| @@ -749,8 +761,8 @@ | |
| 761 | goto wiki_cmd_usage; |
| 762 | } |
| 763 | return; |
| 764 | |
| 765 | wiki_cmd_usage: |
| 766 | usage("delete|export|commit|list [EntryName]"); |
| 767 | } |
| 768 | |
| 769 |