| | @@ -152,19 +152,19 @@ |
| 152 | 152 | ** the tktfield table and to insert template text into the |
| 153 | 153 | ** config table |
| 154 | 154 | */ |
| 155 | 155 | blob_appendf(&tbldef, |
| 156 | 156 | "DROP TABLE IF EXISTS ticket;\n" |
| 157 | | - "CREATE TABLE ticket(\n" |
| 157 | + "CREATE TABLE repository.ticket(\n" |
| 158 | 158 | " tktid INTEGER PRIMARY KEY,\n" |
| 159 | 159 | " tktuuid TEXT UNIQUE,\n" |
| 160 | 160 | " starttime DATETIME,\n" |
| 161 | 161 | " lastmod DATETIME" |
| 162 | 162 | ); |
| 163 | 163 | blob_appendf(&sql, |
| 164 | 164 | "DROP TABLE IF EXISTS tktfield;\n" |
| 165 | | - "CREATE TABLE tktfield(\n" |
| 165 | + "CREATE TABLE repository.tktfield(\n" |
| 166 | 166 | " fidx INTEGER PRIMARY KEY,\n" |
| 167 | 167 | " name TEXT UNIQUE,\n" |
| 168 | 168 | " type TEXT,\n" |
| 169 | 169 | " width INTEGER,\n" |
| 170 | 170 | " arg\n" |
| | @@ -308,11 +308,10 @@ |
| 308 | 308 | ** <text> |
| 309 | 309 | */ |
| 310 | 310 | if( blob_eq(&token, "description") |
| 311 | 311 | && blob_token(&line, &arg) |
| 312 | 312 | ){ |
| 313 | | - int idx; |
| 314 | 313 | Blob content; |
| 315 | 314 | int start; |
| 316 | 315 | int end; |
| 317 | 316 | |
| 318 | 317 | start = end = blob_tell(pConfig); |
| | @@ -367,18 +366,36 @@ |
| 367 | 366 | } |
| 368 | 367 | |
| 369 | 368 | /* |
| 370 | 369 | ** COMMAND: test-tktconfig-parse |
| 371 | 370 | */ |
| 372 | | -void test_tktconfig_cmd(void){ |
| 371 | +void test_tktconfig_parse_cmd(void){ |
| 373 | 372 | Blob config, err; |
| 374 | 373 | if( g.argc!=3 ){ |
| 375 | 374 | usage("FILENAME"); |
| 376 | 375 | } |
| 377 | 376 | blob_read_from_file(&config, g.argv[2]); |
| 378 | 377 | blob_zero(&err); |
| 379 | 378 | ticket_config_parse(&config, 1, &err); |
| 379 | + if( blob_size(&err) ){ |
| 380 | + blob_write_to_file(&err, "-"); |
| 381 | + } |
| 382 | +} |
| 383 | +/* |
| 384 | +** COMMAND: test-tktconfig-import |
| 385 | +*/ |
| 386 | +void test_tktconfig_import_cmd(void){ |
| 387 | + Blob config, err; |
| 388 | + db_must_be_within_tree(); |
| 389 | + if( g.argc!=3 ){ |
| 390 | + usage("FILENAME"); |
| 391 | + } |
| 392 | + blob_read_from_file(&config, g.argv[2]); |
| 393 | + blob_zero(&err); |
| 394 | + db_begin_transaction(); |
| 395 | + ticket_config_parse(&config, 0, &err); |
| 396 | + db_end_transaction(0); |
| 380 | 397 | if( blob_size(&err) ){ |
| 381 | 398 | blob_write_to_file(&err, "-"); |
| 382 | 399 | } |
| 383 | 400 | } |
| 384 | 401 | |
| | @@ -561,5 +578,91 @@ |
| 561 | 578 | if( blob_size(&errmsg) ){ |
| 562 | 579 | fossil_fatal("%b", &errmsg); |
| 563 | 580 | } |
| 564 | 581 | db_end_transaction(0); |
| 565 | 582 | } |
| 583 | + |
| 584 | +/* |
| 585 | +** Return the length of a string without its trailing whitespace. |
| 586 | +*/ |
| 587 | +static int non_whitespace_length(const char *z){ |
| 588 | + int n = strlen(z); |
| 589 | + while( n>0 && isspace(z[n-1]) ){ n--; } |
| 590 | + return n; |
| 591 | +} |
| 592 | + |
| 593 | +/* |
| 594 | +** Fill the given Blob with text that describes the current |
| 595 | +** ticket configuration. This is the inverse of ticket_config_parse() |
| 596 | +*/ |
| 597 | +void ticket_config_render(Blob *pOut){ |
| 598 | + char *zDelim; |
| 599 | + char *zContent; |
| 600 | + Stmt q; |
| 601 | + int n; |
| 602 | + |
| 603 | + blob_appendf(pOut, "ticket-configuration\n"); |
| 604 | + zDelim = db_text(0, "SELECT '--end-of-text--' || hex(random(20))"); |
| 605 | + blob_appendf(pOut, "###################################################\n"); |
| 606 | + db_prepare(&q, "SELECT name, type, width, arg FROM tktfield"); |
| 607 | + while( db_step(&q)==SQLITE_ROW ){ |
| 608 | + const char *zName = db_column_text(&q, 0); |
| 609 | + const char *zType = db_column_text(&q, 1); |
| 610 | + int width = db_column_int(&q, 2); |
| 611 | + const char *zArg = db_column_text(&q, 3); |
| 612 | + blob_appendf(pOut, "field %s %s %d %s\n", zName, zType, width, zArg); |
| 613 | + } |
| 614 | + db_finalize(&q); |
| 615 | + blob_appendf(pOut, "###################################################\n"); |
| 616 | + blob_appendf(pOut, "template new %s\n", zDelim); |
| 617 | + zContent = db_get("tkt-new-template", 0); |
| 618 | + if( zContent ){ |
| 619 | + n = non_whitespace_length(zContent); |
| 620 | + blob_appendf(pOut, "%.*s\n", n, zContent); |
| 621 | + free(zContent); |
| 622 | + } |
| 623 | + blob_appendf(pOut, "%s\n", zDelim); |
| 624 | + blob_appendf(pOut, "###################################################\n"); |
| 625 | + blob_appendf(pOut, "template edit %s\n", zDelim); |
| 626 | + zContent = db_get("tkt-edit-template", 0); |
| 627 | + if( zContent ){ |
| 628 | + n = non_whitespace_length(zContent); |
| 629 | + blob_appendf(pOut, "%.*s\n", n, zContent); |
| 630 | + free(zContent); |
| 631 | + } |
| 632 | + blob_appendf(pOut, "%s\n", zDelim); |
| 633 | + blob_appendf(pOut, "###################################################\n"); |
| 634 | + blob_appendf(pOut, "template view %s\n", zDelim); |
| 635 | + zContent = db_get("tkt-view-template", 0); |
| 636 | + if( zContent ){ |
| 637 | + n = non_whitespace_length(zContent); |
| 638 | + blob_appendf(pOut, "%.*s\n", n, zContent); |
| 639 | + free(zContent); |
| 640 | + } |
| 641 | + blob_appendf(pOut, "%s\n", zDelim); |
| 642 | + blob_appendf(pOut, "###################################################\n"); |
| 643 | + blob_appendf(pOut, "description %s\n", zDelim); |
| 644 | + zContent = db_get("tkt-desc", 0); |
| 645 | + if( zContent ){ |
| 646 | + n = non_whitespace_length(zContent); |
| 647 | + blob_appendf(pOut, "%.*s\n", n, zContent); |
| 648 | + free(zContent); |
| 649 | + } |
| 650 | + blob_appendf(pOut, "%s\n", zDelim); |
| 651 | +} |
| 652 | + |
| 653 | +/* |
| 654 | +** COMMAND: test-tktconfig-export |
| 655 | +** Write the current ticket configuration out to a file. |
| 656 | +*/ |
| 657 | +void tktconfig_render_cmd(void){ |
| 658 | + Blob config; |
| 659 | + |
| 660 | + db_must_be_within_tree(); |
| 661 | + if( g.argc!=3 ){ |
| 662 | + usage("FILENAME"); |
| 663 | + } |
| 664 | + blob_zero(&config); |
| 665 | + ticket_config_render(&config); |
| 666 | + blob_write_to_file(&config, g.argv[2]); |
| 667 | + blob_reset(&config); |
| 668 | +} |
| 566 | 669 | |