Fossil SCM
[c541b6e734] Move attachment from wiki subcommand to top level command
dave.vines
2016-01-05 08:34
Commit
16f864af8fc9fe531dfc299c25c32d23546c30de
Parent
85aa2a6f766420c…
2 files changed
+9
-4
+95
-78
+9
-4
| --- src/info.c | ||
| +++ src/info.c | ||
| @@ -1330,10 +1330,11 @@ | ||
| 1330 | 1330 | const char *zDate = db_column_text(&q, 0); |
| 1331 | 1331 | const char *zUser = db_column_text(&q, 1); |
| 1332 | 1332 | const char *zCom = db_column_text(&q, 2); |
| 1333 | 1333 | const char *zType = db_column_text(&q, 3); |
| 1334 | 1334 | const char *zUuid = db_column_text(&q, 4); |
| 1335 | + int eventTagId = db_column_int(&q, 5); | |
| 1335 | 1336 | if( cnt>0 ){ |
| 1336 | 1337 | @ Also |
| 1337 | 1338 | } |
| 1338 | 1339 | if( zType[0]=='w' ){ |
| 1339 | 1340 | @ Wiki edit |
| @@ -1343,17 +1344,21 @@ | ||
| 1343 | 1344 | objType |= OBJTYPE_TICKET; |
| 1344 | 1345 | }else if( zType[0]=='c' ){ |
| 1345 | 1346 | @ Manifest of check-in |
| 1346 | 1347 | objType |= OBJTYPE_CHECKIN; |
| 1347 | 1348 | }else if( zType[0]=='e' ){ |
| 1348 | - @ Instance of technote | |
| 1349 | - objType |= OBJTYPE_EVENT; | |
| 1350 | - hyperlink_to_event_tagid(db_column_int(&q, 5)); | |
| 1349 | + if( eventTagId != 0) { | |
| 1350 | + @ Instance of technote | |
| 1351 | + objType |= OBJTYPE_EVENT; | |
| 1352 | + hyperlink_to_event_tagid(db_column_int(&q, 5)); | |
| 1353 | + }else{ | |
| 1354 | + @ Attachment to technote | |
| 1355 | + } | |
| 1351 | 1356 | }else{ |
| 1352 | 1357 | @ Tag referencing |
| 1353 | 1358 | } |
| 1354 | - if( zType[0]!='e' ){ | |
| 1359 | + if( zType[0]!='e' || eventTagId == 0){ | |
| 1355 | 1360 | hyperlink_to_uuid(zUuid); |
| 1356 | 1361 | } |
| 1357 | 1362 | @ - %!W(zCom) by |
| 1358 | 1363 | hyperlink_to_user(zUser,zDate," on"); |
| 1359 | 1364 | hyperlink_to_date(zDate, "."); |
| 1360 | 1365 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -1330,10 +1330,11 @@ | |
| 1330 | const char *zDate = db_column_text(&q, 0); |
| 1331 | const char *zUser = db_column_text(&q, 1); |
| 1332 | const char *zCom = db_column_text(&q, 2); |
| 1333 | const char *zType = db_column_text(&q, 3); |
| 1334 | const char *zUuid = db_column_text(&q, 4); |
| 1335 | if( cnt>0 ){ |
| 1336 | @ Also |
| 1337 | } |
| 1338 | if( zType[0]=='w' ){ |
| 1339 | @ Wiki edit |
| @@ -1343,17 +1344,21 @@ | |
| 1343 | objType |= OBJTYPE_TICKET; |
| 1344 | }else if( zType[0]=='c' ){ |
| 1345 | @ Manifest of check-in |
| 1346 | objType |= OBJTYPE_CHECKIN; |
| 1347 | }else if( zType[0]=='e' ){ |
| 1348 | @ Instance of technote |
| 1349 | objType |= OBJTYPE_EVENT; |
| 1350 | hyperlink_to_event_tagid(db_column_int(&q, 5)); |
| 1351 | }else{ |
| 1352 | @ Tag referencing |
| 1353 | } |
| 1354 | if( zType[0]!='e' ){ |
| 1355 | hyperlink_to_uuid(zUuid); |
| 1356 | } |
| 1357 | @ - %!W(zCom) by |
| 1358 | hyperlink_to_user(zUser,zDate," on"); |
| 1359 | hyperlink_to_date(zDate, "."); |
| 1360 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -1330,10 +1330,11 @@ | |
| 1330 | const char *zDate = db_column_text(&q, 0); |
| 1331 | const char *zUser = db_column_text(&q, 1); |
| 1332 | const char *zCom = db_column_text(&q, 2); |
| 1333 | const char *zType = db_column_text(&q, 3); |
| 1334 | const char *zUuid = db_column_text(&q, 4); |
| 1335 | int eventTagId = db_column_int(&q, 5); |
| 1336 | if( cnt>0 ){ |
| 1337 | @ Also |
| 1338 | } |
| 1339 | if( zType[0]=='w' ){ |
| 1340 | @ Wiki edit |
| @@ -1343,17 +1344,21 @@ | |
| 1344 | objType |= OBJTYPE_TICKET; |
| 1345 | }else if( zType[0]=='c' ){ |
| 1346 | @ Manifest of check-in |
| 1347 | objType |= OBJTYPE_CHECKIN; |
| 1348 | }else if( zType[0]=='e' ){ |
| 1349 | if( eventTagId != 0) { |
| 1350 | @ Instance of technote |
| 1351 | objType |= OBJTYPE_EVENT; |
| 1352 | hyperlink_to_event_tagid(db_column_int(&q, 5)); |
| 1353 | }else{ |
| 1354 | @ Attachment to technote |
| 1355 | } |
| 1356 | }else{ |
| 1357 | @ Tag referencing |
| 1358 | } |
| 1359 | if( zType[0]!='e' || eventTagId == 0){ |
| 1360 | hyperlink_to_uuid(zUuid); |
| 1361 | } |
| 1362 | @ - %!W(zCom) by |
| 1363 | hyperlink_to_user(zUser,zDate," on"); |
| 1364 | hyperlink_to_date(zDate, "."); |
| 1365 |
+95
-78
| --- src/wiki.c | ||
| +++ src/wiki.c | ||
| @@ -1172,14 +1172,10 @@ | ||
| 1172 | 1172 | ** case-insensitively by name. The --technote flag |
| 1173 | 1173 | ** specifies that technotes will be listed instead of |
| 1174 | 1174 | ** the wiki entries, which will be listed in order |
| 1175 | 1175 | ** timestamp. |
| 1176 | 1176 | ** |
| 1177 | -** %fossil wiki attachment add ?PAGENAME? FILENAME [-t|--technote DATETIME ] | |
| 1178 | -** | |
| 1179 | -** Add an attachment to an existing wiki page or tech note. One of | |
| 1180 | -** PAGENAME or DATETIME must be specified. | |
| 1181 | 1177 | */ |
| 1182 | 1178 | void wiki_cmd(void){ |
| 1183 | 1179 | int n; |
| 1184 | 1180 | db_find_and_open_repository(0, 0); |
| 1185 | 1181 | if( g.argc<3 ){ |
| @@ -1228,11 +1224,11 @@ | ||
| 1228 | 1224 | ); |
| 1229 | 1225 | if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){ |
| 1230 | 1226 | zBody = pWiki->zWiki; |
| 1231 | 1227 | } |
| 1232 | 1228 | if( zBody==0 ){ |
| 1233 | - fossil_fatal("technote not found"); | |
| 1229 | + fossil_fatal("technote [%s] not found",zETime); | |
| 1234 | 1230 | } |
| 1235 | 1231 | zFile = (g.argc==3) ? "-" : g.argv[3]; |
| 1236 | 1232 | } |
| 1237 | 1233 | for(i=strlen(zBody); i>0 && fossil_isspace(zBody[i-1]); i--){} |
| 1238 | 1234 | zBody[i] = 0; |
| @@ -1334,85 +1330,106 @@ | ||
| 1334 | 1330 | while( db_step(&q)==SQLITE_ROW ){ |
| 1335 | 1331 | const char *zName = db_column_text(&q, 0); |
| 1336 | 1332 | fossil_print( "%s\n",zName); |
| 1337 | 1333 | } |
| 1338 | 1334 | db_finalize(&q); |
| 1339 | - }else if( strncmp(g.argv[2],"attachment",n)==0 ){ | |
| 1340 | - int n3 = strlen(g.argv[3]); | |
| 1341 | - if( n3==0 ){ | |
| 1342 | - usage("attachment add ?PAGENAME? FILENAME [-t|--technote DATETIME]"); | |
| 1343 | - } | |
| 1344 | - if( strncmp(g.argv[3],"add",n3)==0 ){ | |
| 1345 | - const char *zPageName; /* Name of the wiki page to attach to */ | |
| 1346 | - const char *zFile; /* Name of the file to be attached */ | |
| 1347 | - const char *zETime; /* The name of the technote to attach to */ | |
| 1348 | - Manifest *pWiki = 0; /* Parsed wiki page content */ | |
| 1349 | - char *zBody = 0; /* Wiki page content */ | |
| 1350 | - int rid; | |
| 1351 | - const char *zTarget; /* Target of the attachment */ | |
| 1352 | - Blob content; /* The content of the attachment */ | |
| 1353 | - zETime = find_option("technote","t",1); | |
| 1354 | - if( !zETime ){ | |
| 1355 | - if( g.argc!=6 ){ | |
| 1356 | - usage("attachment add PAGENAME FILENAME"); | |
| 1357 | - } | |
| 1358 | - zPageName = g.argv[4]; | |
| 1359 | - rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x" | |
| 1360 | - " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'" | |
| 1361 | - " ORDER BY x.mtime DESC LIMIT 1", | |
| 1362 | - zPageName | |
| 1363 | - ); | |
| 1364 | - if( (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0 ){ | |
| 1365 | - zBody = pWiki->zWiki; | |
| 1366 | - } | |
| 1367 | - if( zBody==0 ){ | |
| 1368 | - fossil_fatal("wiki page [%s] not found",zPageName); | |
| 1369 | - } | |
| 1370 | - zTarget = zPageName; | |
| 1371 | - zFile = g.argv[5]; | |
| 1372 | - }else{ | |
| 1373 | - if( g.argc!=5 ){ | |
| 1374 | - usage("attachment add FILENAME --technote DATETIME"); | |
| 1375 | - } | |
| 1376 | - rid = db_int(0, "SELECT objid FROM event" | |
| 1377 | - " WHERE datetime(mtime)=datetime('%q') AND type='e'" | |
| 1378 | - " ORDER BY mtime DESC LIMIT 1", | |
| 1379 | - zETime | |
| 1380 | - ); | |
| 1381 | - if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){ | |
| 1382 | - zBody = pWiki->zWiki; | |
| 1383 | - } | |
| 1384 | - if( zBody==0 ){ | |
| 1385 | - fossil_fatal("technote [%s] not found",zPageName); | |
| 1386 | - } | |
| 1387 | - zTarget = db_text(0, | |
| 1388 | - "SELECT substr(tagname,7) FROM tag WHERE tagid=(SELECT tagid FROM event WHERE objid='%d')", | |
| 1389 | - rid | |
| 1390 | - ); | |
| 1391 | - zFile = g.argv[4]; | |
| 1392 | - } | |
| 1393 | - blob_read_from_file(&content, zFile); | |
| 1394 | - user_select(); | |
| 1395 | - attach_commit( | |
| 1396 | - zFile, /* The filename of the attachment */ | |
| 1397 | - zTarget, /* The artifact uuid to attach to */ | |
| 1398 | - blob_buffer(&content), /* The content of the attachment */ | |
| 1399 | - blob_size(&content), /* The length of the attachment */ | |
| 1400 | - 0, /* No need to moderate the attachment */ | |
| 1401 | - "" /* Empty attachment comment */ | |
| 1402 | - ); | |
| 1403 | - if( !zETime ){ | |
| 1404 | - fossil_print("Attached %s to wiki page %s.\n", zFile, zPageName); | |
| 1405 | - }else{ | |
| 1406 | - fossil_print("Attached %s to tech note %s.\n", zFile, zETime); | |
| 1407 | - } | |
| 1408 | - }else{ | |
| 1409 | - usage("attachment add ?PAGENAME? FILENAME [-t|--technote DATETIME]"); | |
| 1410 | - } | |
| 1411 | 1335 | }else{ |
| 1412 | 1336 | goto wiki_cmd_usage; |
| 1413 | 1337 | } |
| 1414 | 1338 | return; |
| 1415 | 1339 | |
| 1416 | 1340 | wiki_cmd_usage: |
| 1417 | - usage("export|create|commit|list|attachment ..."); | |
| 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 ]"); | |
| 1418 | 1435 | } |
| 1419 | 1436 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -1172,14 +1172,10 @@ | |
| 1172 | ** case-insensitively by name. The --technote flag |
| 1173 | ** specifies that technotes will be listed instead of |
| 1174 | ** the wiki entries, which will be listed in order |
| 1175 | ** timestamp. |
| 1176 | ** |
| 1177 | ** %fossil wiki attachment add ?PAGENAME? FILENAME [-t|--technote DATETIME ] |
| 1178 | ** |
| 1179 | ** Add an attachment to an existing wiki page or tech note. One of |
| 1180 | ** PAGENAME or DATETIME must be specified. |
| 1181 | */ |
| 1182 | void wiki_cmd(void){ |
| 1183 | int n; |
| 1184 | db_find_and_open_repository(0, 0); |
| 1185 | if( g.argc<3 ){ |
| @@ -1228,11 +1224,11 @@ | |
| 1228 | ); |
| 1229 | if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){ |
| 1230 | zBody = pWiki->zWiki; |
| 1231 | } |
| 1232 | if( zBody==0 ){ |
| 1233 | fossil_fatal("technote not found"); |
| 1234 | } |
| 1235 | zFile = (g.argc==3) ? "-" : g.argv[3]; |
| 1236 | } |
| 1237 | for(i=strlen(zBody); i>0 && fossil_isspace(zBody[i-1]); i--){} |
| 1238 | zBody[i] = 0; |
| @@ -1334,85 +1330,106 @@ | |
| 1334 | while( db_step(&q)==SQLITE_ROW ){ |
| 1335 | const char *zName = db_column_text(&q, 0); |
| 1336 | fossil_print( "%s\n",zName); |
| 1337 | } |
| 1338 | db_finalize(&q); |
| 1339 | }else if( strncmp(g.argv[2],"attachment",n)==0 ){ |
| 1340 | int n3 = strlen(g.argv[3]); |
| 1341 | if( n3==0 ){ |
| 1342 | usage("attachment add ?PAGENAME? FILENAME [-t|--technote DATETIME]"); |
| 1343 | } |
| 1344 | if( strncmp(g.argv[3],"add",n3)==0 ){ |
| 1345 | const char *zPageName; /* Name of the wiki page to attach to */ |
| 1346 | const char *zFile; /* Name of the file to be attached */ |
| 1347 | const char *zETime; /* The name of the technote to attach to */ |
| 1348 | Manifest *pWiki = 0; /* Parsed wiki page content */ |
| 1349 | char *zBody = 0; /* Wiki page content */ |
| 1350 | int rid; |
| 1351 | const char *zTarget; /* Target of the attachment */ |
| 1352 | Blob content; /* The content of the attachment */ |
| 1353 | zETime = find_option("technote","t",1); |
| 1354 | if( !zETime ){ |
| 1355 | if( g.argc!=6 ){ |
| 1356 | usage("attachment add PAGENAME FILENAME"); |
| 1357 | } |
| 1358 | zPageName = g.argv[4]; |
| 1359 | rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x" |
| 1360 | " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'" |
| 1361 | " ORDER BY x.mtime DESC LIMIT 1", |
| 1362 | zPageName |
| 1363 | ); |
| 1364 | if( (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0 ){ |
| 1365 | zBody = pWiki->zWiki; |
| 1366 | } |
| 1367 | if( zBody==0 ){ |
| 1368 | fossil_fatal("wiki page [%s] not found",zPageName); |
| 1369 | } |
| 1370 | zTarget = zPageName; |
| 1371 | zFile = g.argv[5]; |
| 1372 | }else{ |
| 1373 | if( g.argc!=5 ){ |
| 1374 | usage("attachment add FILENAME --technote DATETIME"); |
| 1375 | } |
| 1376 | rid = db_int(0, "SELECT objid FROM event" |
| 1377 | " WHERE datetime(mtime)=datetime('%q') AND type='e'" |
| 1378 | " ORDER BY mtime DESC LIMIT 1", |
| 1379 | zETime |
| 1380 | ); |
| 1381 | if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){ |
| 1382 | zBody = pWiki->zWiki; |
| 1383 | } |
| 1384 | if( zBody==0 ){ |
| 1385 | fossil_fatal("technote [%s] not found",zPageName); |
| 1386 | } |
| 1387 | zTarget = db_text(0, |
| 1388 | "SELECT substr(tagname,7) FROM tag WHERE tagid=(SELECT tagid FROM event WHERE objid='%d')", |
| 1389 | rid |
| 1390 | ); |
| 1391 | zFile = g.argv[4]; |
| 1392 | } |
| 1393 | blob_read_from_file(&content, zFile); |
| 1394 | user_select(); |
| 1395 | attach_commit( |
| 1396 | zFile, /* The filename of the attachment */ |
| 1397 | zTarget, /* The artifact uuid to attach to */ |
| 1398 | blob_buffer(&content), /* The content of the attachment */ |
| 1399 | blob_size(&content), /* The length of the attachment */ |
| 1400 | 0, /* No need to moderate the attachment */ |
| 1401 | "" /* Empty attachment comment */ |
| 1402 | ); |
| 1403 | if( !zETime ){ |
| 1404 | fossil_print("Attached %s to wiki page %s.\n", zFile, zPageName); |
| 1405 | }else{ |
| 1406 | fossil_print("Attached %s to tech note %s.\n", zFile, zETime); |
| 1407 | } |
| 1408 | }else{ |
| 1409 | usage("attachment add ?PAGENAME? FILENAME [-t|--technote DATETIME]"); |
| 1410 | } |
| 1411 | }else{ |
| 1412 | goto wiki_cmd_usage; |
| 1413 | } |
| 1414 | return; |
| 1415 | |
| 1416 | wiki_cmd_usage: |
| 1417 | usage("export|create|commit|list|attachment ..."); |
| 1418 | } |
| 1419 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -1172,14 +1172,10 @@ | |
| 1172 | ** case-insensitively by name. The --technote flag |
| 1173 | ** specifies that technotes will be listed instead of |
| 1174 | ** the wiki entries, which will be listed in order |
| 1175 | ** timestamp. |
| 1176 | ** |
| 1177 | */ |
| 1178 | void wiki_cmd(void){ |
| 1179 | int n; |
| 1180 | db_find_and_open_repository(0, 0); |
| 1181 | if( g.argc<3 ){ |
| @@ -1228,11 +1224,11 @@ | |
| 1224 | ); |
| 1225 | if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){ |
| 1226 | zBody = pWiki->zWiki; |
| 1227 | } |
| 1228 | if( zBody==0 ){ |
| 1229 | fossil_fatal("technote [%s] not found",zETime); |
| 1230 | } |
| 1231 | zFile = (g.argc==3) ? "-" : g.argv[3]; |
| 1232 | } |
| 1233 | for(i=strlen(zBody); i>0 && fossil_isspace(zBody[i-1]); i--){} |
| 1234 | zBody[i] = 0; |
| @@ -1334,85 +1330,106 @@ | |
| 1330 | while( db_step(&q)==SQLITE_ROW ){ |
| 1331 | const char *zName = db_column_text(&q, 0); |
| 1332 | fossil_print( "%s\n",zName); |
| 1333 | } |
| 1334 | db_finalize(&q); |
| 1335 | }else{ |
| 1336 | goto wiki_cmd_usage; |
| 1337 | } |
| 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 |