Fossil SCM

[c541b6e734] Move attachment command from wiki.c to attach.c

dave.vines 2016-01-05 08:40
Commit 64a5ef28e5e69c6dbed8e2d4575023e0a0c86a10
2 files changed +93 -93
+93
--- src/attach.c
+++ src/attach.c
@@ -679,5 +679,98 @@
679679
@ </ul>
680680
}
681681
db_finalize(&q);
682682
683683
}
684
+
685
+/*
686
+** COMMAND: attachment*
687
+**
688
+** Usage: %fossil attachment add ?PAGENAME? FILENAME [-t|--technote DATETIME ]
689
+**
690
+** Add an attachment to an existing wiki page or tech note. One of
691
+** PAGENAME or DATETIME must be specified.
692
+**
693
+*/
694
+void attachment_cmd(void){
695
+ int n;
696
+ db_find_and_open_repository(0, 0);
697
+ if( g.argc<3 ){
698
+ goto attachment_cmd_usage;
699
+ }
700
+ n = strlen(g.argv[2]);
701
+ if( n==0 ){
702
+ goto attachment_cmd_usage;
703
+ }
704
+
705
+ if( strncmp(g.argv[2],"add",n)==0 ){
706
+ const char *zPageName; /* Name of the wiki page to attach to */
707
+ const char *zFile; /* Name of the file to be attached */
708
+ const char *zETime; /* The name of the technote to attach to */
709
+ Manifest *pWiki = 0; /* Parsed wiki page content */
710
+ char *zBody = 0; /* Wiki page content */
711
+ int rid;
712
+ const char *zTarget; /* Target of the attachment */
713
+ Blob content; /* The content of the attachment */
714
+ zETime = find_option("technote","t",1);
715
+ if( !zETime ){
716
+ if( g.argc!=5 ){
717
+ usage("attachment add PAGENAME FILENAME");
718
+ }
719
+ zPageName = g.argv[3];
720
+ rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
721
+ " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
722
+ " ORDER BY x.mtime DESC LIMIT 1",
723
+ zPageName
724
+ );
725
+ if( (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0 ){
726
+ zBody = pWiki->zWiki;
727
+ }
728
+ if( zBody==0 ){
729
+ fossil_fatal("wiki page [%s] not found",zPageName);
730
+ }
731
+ zTarget = zPageName;
732
+ zFile = g.argv[4];
733
+ }else{
734
+ if( g.argc!=4 ){
735
+ usage("attachment add FILENAME --technote DATETIME");
736
+ }
737
+ rid = db_int(0, "SELECT objid FROM event"
738
+ " WHERE datetime(mtime)=datetime('%q') AND type='e'"
739
+ " ORDER BY mtime DESC LIMIT 1",
740
+ zETime
741
+ );
742
+ if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){
743
+ zBody = pWiki->zWiki;
744
+ }
745
+ if( zBody==0 ){
746
+ fossil_fatal("technote [%s] not found",zETime);
747
+ }
748
+ zTarget = db_text(0,
749
+ "SELECT substr(tagname,7) FROM tag WHERE tagid=(SELECT tagid FROM event WHERE objid='%d')",
750
+ rid
751
+ );
752
+ zFile = g.argv[3];
753
+ }
754
+ blob_read_from_file(&content, zFile);
755
+ user_select();
756
+ attach_commit(
757
+ zFile, /* The filename of the attachment */
758
+ zTarget, /* The artifact uuid to attach to */
759
+ blob_buffer(&content), /* The content of the attachment */
760
+ blob_size(&content), /* The length of the attachment */
761
+ 0, /* No need to moderate the attachment */
762
+ "" /* Empty attachment comment */
763
+ );
764
+ if( !zETime ){
765
+ fossil_print("Attached %s to wiki page %s.\n", zFile, zPageName);
766
+ }else{
767
+ fossil_print("Attached %s to tech note %s.\n", zFile, zETime);
768
+ }
769
+ }else{
770
+ goto attachment_cmd_usage;
771
+ }
772
+ return;
773
+
774
+attachment_cmd_usage:
775
+ usage("attachment add ?PAGENAME? FILENAME [-t|--technote DATETIME ]");
776
+}
684777
--- src/attach.c
+++ src/attach.c
@@ -679,5 +679,98 @@
679 @ </ul>
680 }
681 db_finalize(&q);
682
683 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
684
--- src/attach.c
+++ src/attach.c
@@ -679,5 +679,98 @@
679 @ </ul>
680 }
681 db_finalize(&q);
682
683 }
684
685 /*
686 ** COMMAND: attachment*
687 **
688 ** Usage: %fossil attachment add ?PAGENAME? FILENAME [-t|--technote DATETIME ]
689 **
690 ** Add an attachment to an existing wiki page or tech note. One of
691 ** PAGENAME or DATETIME must be specified.
692 **
693 */
694 void attachment_cmd(void){
695 int n;
696 db_find_and_open_repository(0, 0);
697 if( g.argc<3 ){
698 goto attachment_cmd_usage;
699 }
700 n = strlen(g.argv[2]);
701 if( n==0 ){
702 goto attachment_cmd_usage;
703 }
704
705 if( strncmp(g.argv[2],"add",n)==0 ){
706 const char *zPageName; /* Name of the wiki page to attach to */
707 const char *zFile; /* Name of the file to be attached */
708 const char *zETime; /* The name of the technote to attach to */
709 Manifest *pWiki = 0; /* Parsed wiki page content */
710 char *zBody = 0; /* Wiki page content */
711 int rid;
712 const char *zTarget; /* Target of the attachment */
713 Blob content; /* The content of the attachment */
714 zETime = find_option("technote","t",1);
715 if( !zETime ){
716 if( g.argc!=5 ){
717 usage("attachment add PAGENAME FILENAME");
718 }
719 zPageName = g.argv[3];
720 rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
721 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
722 " ORDER BY x.mtime DESC LIMIT 1",
723 zPageName
724 );
725 if( (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0 ){
726 zBody = pWiki->zWiki;
727 }
728 if( zBody==0 ){
729 fossil_fatal("wiki page [%s] not found",zPageName);
730 }
731 zTarget = zPageName;
732 zFile = g.argv[4];
733 }else{
734 if( g.argc!=4 ){
735 usage("attachment add FILENAME --technote DATETIME");
736 }
737 rid = db_int(0, "SELECT objid FROM event"
738 " WHERE datetime(mtime)=datetime('%q') AND type='e'"
739 " ORDER BY mtime DESC LIMIT 1",
740 zETime
741 );
742 if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){
743 zBody = pWiki->zWiki;
744 }
745 if( zBody==0 ){
746 fossil_fatal("technote [%s] not found",zETime);
747 }
748 zTarget = db_text(0,
749 "SELECT substr(tagname,7) FROM tag WHERE tagid=(SELECT tagid FROM event WHERE objid='%d')",
750 rid
751 );
752 zFile = g.argv[3];
753 }
754 blob_read_from_file(&content, zFile);
755 user_select();
756 attach_commit(
757 zFile, /* The filename of the attachment */
758 zTarget, /* The artifact uuid to attach to */
759 blob_buffer(&content), /* The content of the attachment */
760 blob_size(&content), /* The length of the attachment */
761 0, /* No need to moderate the attachment */
762 "" /* Empty attachment comment */
763 );
764 if( !zETime ){
765 fossil_print("Attached %s to wiki page %s.\n", zFile, zPageName);
766 }else{
767 fossil_print("Attached %s to tech note %s.\n", zFile, zETime);
768 }
769 }else{
770 goto attachment_cmd_usage;
771 }
772 return;
773
774 attachment_cmd_usage:
775 usage("attachment add ?PAGENAME? FILENAME [-t|--technote DATETIME ]");
776 }
777
-93
--- src/wiki.c
+++ src/wiki.c
@@ -1338,98 +1338,5 @@
13381338
return;
13391339
13401340
wiki_cmd_usage:
13411341
usage("export|create|commit|list ...");
13421342
}
1343
-
1344
-/*
1345
-** COMMAND: attachment*
1346
-**
1347
-** Usage: %fossil attachment add ?PAGENAME? FILENAME [-t|--technote DATETIME ]
1348
-**
1349
-** Add an attachment to an existing wiki page or tech note. One of
1350
-** PAGENAME or DATETIME must be specified.
1351
-**
1352
-*/
1353
-void attachment_cmd(void){
1354
- int n;
1355
- db_find_and_open_repository(0, 0);
1356
- if( g.argc<3 ){
1357
- goto attachment_cmd_usage;
1358
- }
1359
- n = strlen(g.argv[2]);
1360
- if( n==0 ){
1361
- goto attachment_cmd_usage;
1362
- }
1363
-
1364
- if( strncmp(g.argv[2],"add",n)==0 ){
1365
- const char *zPageName; /* Name of the wiki page to attach to */
1366
- const char *zFile; /* Name of the file to be attached */
1367
- const char *zETime; /* The name of the technote to attach to */
1368
- Manifest *pWiki = 0; /* Parsed wiki page content */
1369
- char *zBody = 0; /* Wiki page content */
1370
- int rid;
1371
- const char *zTarget; /* Target of the attachment */
1372
- Blob content; /* The content of the attachment */
1373
- zETime = find_option("technote","t",1);
1374
- if( !zETime ){
1375
- if( g.argc!=5 ){
1376
- usage("attachment add PAGENAME FILENAME");
1377
- }
1378
- zPageName = g.argv[3];
1379
- rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
1380
- " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
1381
- " ORDER BY x.mtime DESC LIMIT 1",
1382
- zPageName
1383
- );
1384
- if( (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0 ){
1385
- zBody = pWiki->zWiki;
1386
- }
1387
- if( zBody==0 ){
1388
- fossil_fatal("wiki page [%s] not found",zPageName);
1389
- }
1390
- zTarget = zPageName;
1391
- zFile = g.argv[4];
1392
- }else{
1393
- if( g.argc!=4 ){
1394
- usage("attachment add FILENAME --technote DATETIME");
1395
- }
1396
- rid = db_int(0, "SELECT objid FROM event"
1397
- " WHERE datetime(mtime)=datetime('%q') AND type='e'"
1398
- " ORDER BY mtime DESC LIMIT 1",
1399
- zETime
1400
- );
1401
- if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){
1402
- zBody = pWiki->zWiki;
1403
- }
1404
- if( zBody==0 ){
1405
- fossil_fatal("technote [%s] not found",zETime);
1406
- }
1407
- zTarget = db_text(0,
1408
- "SELECT substr(tagname,7) FROM tag WHERE tagid=(SELECT tagid FROM event WHERE objid='%d')",
1409
- rid
1410
- );
1411
- zFile = g.argv[3];
1412
- }
1413
- blob_read_from_file(&content, zFile);
1414
- user_select();
1415
- attach_commit(
1416
- zFile, /* The filename of the attachment */
1417
- zTarget, /* The artifact uuid to attach to */
1418
- blob_buffer(&content), /* The content of the attachment */
1419
- blob_size(&content), /* The length of the attachment */
1420
- 0, /* No need to moderate the attachment */
1421
- "" /* Empty attachment comment */
1422
- );
1423
- if( !zETime ){
1424
- fossil_print("Attached %s to wiki page %s.\n", zFile, zPageName);
1425
- }else{
1426
- fossil_print("Attached %s to tech note %s.\n", zFile, zETime);
1427
- }
1428
- }else{
1429
- goto attachment_cmd_usage;
1430
- }
1431
- return;
1432
-
1433
-attachment_cmd_usage:
1434
- usage("attachment add ?PAGENAME? FILENAME [-t|--technote DATETIME ]");
1435
-}
14361343
--- src/wiki.c
+++ src/wiki.c
@@ -1338,98 +1338,5 @@
1338 return;
1339
1340 wiki_cmd_usage:
1341 usage("export|create|commit|list ...");
1342 }
1343
1344 /*
1345 ** COMMAND: attachment*
1346 **
1347 ** Usage: %fossil attachment add ?PAGENAME? FILENAME [-t|--technote DATETIME ]
1348 **
1349 ** Add an attachment to an existing wiki page or tech note. One of
1350 ** PAGENAME or DATETIME must be specified.
1351 **
1352 */
1353 void attachment_cmd(void){
1354 int n;
1355 db_find_and_open_repository(0, 0);
1356 if( g.argc<3 ){
1357 goto attachment_cmd_usage;
1358 }
1359 n = strlen(g.argv[2]);
1360 if( n==0 ){
1361 goto attachment_cmd_usage;
1362 }
1363
1364 if( strncmp(g.argv[2],"add",n)==0 ){
1365 const char *zPageName; /* Name of the wiki page to attach to */
1366 const char *zFile; /* Name of the file to be attached */
1367 const char *zETime; /* The name of the technote to attach to */
1368 Manifest *pWiki = 0; /* Parsed wiki page content */
1369 char *zBody = 0; /* Wiki page content */
1370 int rid;
1371 const char *zTarget; /* Target of the attachment */
1372 Blob content; /* The content of the attachment */
1373 zETime = find_option("technote","t",1);
1374 if( !zETime ){
1375 if( g.argc!=5 ){
1376 usage("attachment add PAGENAME FILENAME");
1377 }
1378 zPageName = g.argv[3];
1379 rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
1380 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
1381 " ORDER BY x.mtime DESC LIMIT 1",
1382 zPageName
1383 );
1384 if( (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0 ){
1385 zBody = pWiki->zWiki;
1386 }
1387 if( zBody==0 ){
1388 fossil_fatal("wiki page [%s] not found",zPageName);
1389 }
1390 zTarget = zPageName;
1391 zFile = g.argv[4];
1392 }else{
1393 if( g.argc!=4 ){
1394 usage("attachment add FILENAME --technote DATETIME");
1395 }
1396 rid = db_int(0, "SELECT objid FROM event"
1397 " WHERE datetime(mtime)=datetime('%q') AND type='e'"
1398 " ORDER BY mtime DESC LIMIT 1",
1399 zETime
1400 );
1401 if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){
1402 zBody = pWiki->zWiki;
1403 }
1404 if( zBody==0 ){
1405 fossil_fatal("technote [%s] not found",zETime);
1406 }
1407 zTarget = db_text(0,
1408 "SELECT substr(tagname,7) FROM tag WHERE tagid=(SELECT tagid FROM event WHERE objid='%d')",
1409 rid
1410 );
1411 zFile = g.argv[3];
1412 }
1413 blob_read_from_file(&content, zFile);
1414 user_select();
1415 attach_commit(
1416 zFile, /* The filename of the attachment */
1417 zTarget, /* The artifact uuid to attach to */
1418 blob_buffer(&content), /* The content of the attachment */
1419 blob_size(&content), /* The length of the attachment */
1420 0, /* No need to moderate the attachment */
1421 "" /* Empty attachment comment */
1422 );
1423 if( !zETime ){
1424 fossil_print("Attached %s to wiki page %s.\n", zFile, zPageName);
1425 }else{
1426 fossil_print("Attached %s to tech note %s.\n", zFile, zETime);
1427 }
1428 }else{
1429 goto attachment_cmd_usage;
1430 }
1431 return;
1432
1433 attachment_cmd_usage:
1434 usage("attachment add ?PAGENAME? FILENAME [-t|--technote DATETIME ]");
1435 }
1436
--- src/wiki.c
+++ src/wiki.c
@@ -1338,98 +1338,5 @@
1338 return;
1339
1340 wiki_cmd_usage:
1341 usage("export|create|commit|list ...");
1342 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1343

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button