Fossil

Check-in [16f864af]
Login

Check-in [16f864af]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:[c541b6e734] Move attachment from wiki subcommand to top level command
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | technoteattachcli
Files: files | file ages | folders
SHA1: 16f864af8fc9fe531dfc299c25c32d23546c30de
User & Date: dave.vines 2016-01-05 08:34:24
Context
2016-01-05
08:40
[c541b6e734] Move attachment command from wiki.c to attach.c ... (check-in: 64a5ef28 user: dave.vines tags: technoteattachcli)
08:34
[c541b6e734] Move attachment from wiki subcommand to top level command ... (check-in: 16f864af user: dave.vines tags: technoteattachcli)
2016-01-02
10:49
[c541b6e734] Correct merge ... (check-in: 85aa2a6f user: dave.vines tags: technoteattachcli)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/info.c.
1328
1329
1330
1331
1332
1333
1334

1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347

1348
1349
1350



1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
    );
    while( db_step(&q)==SQLITE_ROW ){
      const char *zDate = db_column_text(&q, 0);
      const char *zUser = db_column_text(&q, 1);
      const char *zCom = db_column_text(&q, 2);
      const char *zType = db_column_text(&q, 3);
      const char *zUuid = db_column_text(&q, 4);

      if( cnt>0 ){
        @ Also
      }
      if( zType[0]=='w' ){
        @ Wiki edit
        objType |= OBJTYPE_WIKI;
      }else if( zType[0]=='t' ){
        @ Ticket change
        objType |= OBJTYPE_TICKET;
      }else if( zType[0]=='c' ){
        @ Manifest of check-in
        objType |= OBJTYPE_CHECKIN;
      }else if( zType[0]=='e' ){

        @ Instance of technote
        objType |= OBJTYPE_EVENT;
        hyperlink_to_event_tagid(db_column_int(&q, 5));



      }else{
        @ Tag referencing
      }
      if( zType[0]!='e' ){
        hyperlink_to_uuid(zUuid);
      }
      @ - %!W(zCom) by
      hyperlink_to_user(zUser,zDate," on");
      hyperlink_to_date(zDate, ".");
      if( pDownloadName && blob_size(pDownloadName)==0 ){
        blob_appendf(pDownloadName, "%S.txt", zUuid);







>













>
|
|
|
>
>
>



|







1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
    );
    while( db_step(&q)==SQLITE_ROW ){
      const char *zDate = db_column_text(&q, 0);
      const char *zUser = db_column_text(&q, 1);
      const char *zCom = db_column_text(&q, 2);
      const char *zType = db_column_text(&q, 3);
      const char *zUuid = db_column_text(&q, 4);
      int eventTagId = db_column_int(&q, 5);
      if( cnt>0 ){
        @ Also
      }
      if( zType[0]=='w' ){
        @ Wiki edit
        objType |= OBJTYPE_WIKI;
      }else if( zType[0]=='t' ){
        @ Ticket change
        objType |= OBJTYPE_TICKET;
      }else if( zType[0]=='c' ){
        @ Manifest of check-in
        objType |= OBJTYPE_CHECKIN;
      }else if( zType[0]=='e' ){
        if( eventTagId != 0) {
          @ Instance of technote
          objType |= OBJTYPE_EVENT;
          hyperlink_to_event_tagid(db_column_int(&q, 5));
        }else{
          @ Attachment to technote 
        }
      }else{
        @ Tag referencing
      }
      if( zType[0]!='e' || eventTagId == 0){
        hyperlink_to_uuid(zUuid);
      }
      @ - %!W(zCom) by
      hyperlink_to_user(zUser,zDate," on");
      hyperlink_to_date(zDate, ".");
      if( pDownloadName && blob_size(pDownloadName)==0 ){
        blob_appendf(pDownloadName, "%S.txt", zUuid);
Changes to src/wiki.c.
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
**
**       Lists all wiki entries, one per line, ordered
**       case-insensitively by name. The --technote flag
**       specifies that technotes will be listed instead of
**       the wiki entries, which will be listed in order
**       timestamp.
**
**    %fossil wiki attachment add ?PAGENAME? FILENAME [-t|--technote DATETIME ]
**
**       Add an attachment to an existing wiki page or tech note. One of
**       PAGENAME or DATETIME must be specified.
*/
void wiki_cmd(void){
  int n;
  db_find_and_open_repository(0, 0);
  if( g.argc<3 ){
    goto wiki_cmd_usage;
  }







<
<
<
<







1170
1171
1172
1173
1174
1175
1176




1177
1178
1179
1180
1181
1182
1183
**
**       Lists all wiki entries, one per line, ordered
**       case-insensitively by name. The --technote flag
**       specifies that technotes will be listed instead of
**       the wiki entries, which will be listed in order
**       timestamp.
**




*/
void wiki_cmd(void){
  int n;
  db_find_and_open_repository(0, 0);
  if( g.argc<3 ){
    goto wiki_cmd_usage;
  }
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
        " ORDER BY mtime DESC LIMIT 1",
        zETime
      );
      if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){
        zBody = pWiki->zWiki;
      }
      if( zBody==0 ){
        fossil_fatal("technote not found");
      }
      zFile = (g.argc==3) ? "-" : g.argv[3];
    }
    for(i=strlen(zBody); i>0 && fossil_isspace(zBody[i-1]); i--){}
    zBody[i] = 0;
    blob_init(&body, zBody, -1);
    blob_append(&body, "\n", 1);







|







1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
        " ORDER BY mtime DESC LIMIT 1",
        zETime
      );
      if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){
        zBody = pWiki->zWiki;
      }
      if( zBody==0 ){
        fossil_fatal("technote [%s] not found",zETime);
      }
      zFile = (g.argc==3) ? "-" : g.argv[3];
    }
    for(i=strlen(zBody); i>0 && fossil_isspace(zBody[i-1]); i--){}
    zBody[i] = 0;
    blob_init(&body, zBody, -1);
    blob_append(&body, "\n", 1);
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418





























































































      );
    }
    while( db_step(&q)==SQLITE_ROW ){
      const char *zName = db_column_text(&q, 0);
      fossil_print( "%s\n",zName);
    }
    db_finalize(&q);
  }else if( strncmp(g.argv[2],"attachment",n)==0 ){
    int n3 = strlen(g.argv[3]);
    if( n3==0 ){
      usage("attachment add ?PAGENAME? FILENAME [-t|--technote DATETIME]");
    }
    if( strncmp(g.argv[3],"add",n3)==0 ){
      const char *zPageName;        /* Name of the wiki page to attach to */
      const char *zFile;            /* Name of the file to be attached */
      const char *zETime;           /* The name of the technote to attach to */
      Manifest *pWiki = 0;          /* Parsed wiki page content */
      char *zBody = 0;              /* Wiki page content */
      int rid;
      const char *zTarget;          /* Target of the attachment */
      Blob content;                 /* The content of the attachment */
      zETime = find_option("technote","t",1);
      if( !zETime ){
        if( g.argc!=6 ){
          usage("attachment add PAGENAME FILENAME");
        }
        zPageName = g.argv[4];
        rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
          " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
          " ORDER BY x.mtime DESC LIMIT 1",
          zPageName
        );        
        if( (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0 ){
          zBody = pWiki->zWiki;
        }
        if( zBody==0 ){
          fossil_fatal("wiki page [%s] not found",zPageName);
        }
        zTarget = zPageName;
        zFile = g.argv[5];
      }else{
        if( g.argc!=5 ){
          usage("attachment add FILENAME --technote DATETIME");
        }
        rid = db_int(0, "SELECT objid FROM event"
          " WHERE datetime(mtime)=datetime('%q') AND type='e'"
          " ORDER BY mtime DESC LIMIT 1",
          zETime
        );
        if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){
          zBody = pWiki->zWiki;
        }
        if( zBody==0 ){
          fossil_fatal("technote [%s] not found",zPageName);
        }
        zTarget = db_text(0,
          "SELECT substr(tagname,7) FROM tag WHERE tagid=(SELECT tagid FROM event WHERE objid='%d')",
          rid
        );
        zFile = g.argv[4];
      }
      blob_read_from_file(&content, zFile);
      user_select();
      attach_commit(
        zFile,                   /* The filename of the attachment */
        zTarget,                 /* The artifact uuid to attach to */
        blob_buffer(&content),   /* The content of the attachment */
        blob_size(&content),     /* The length of the attachment */
        0,                       /* No need to moderate the attachment */
        ""                       /* Empty attachment comment */
      );
      if( !zETime ){
        fossil_print("Attached %s to wiki page %s.\n", zFile, zPageName);
      }else{
        fossil_print("Attached %s to tech note %s.\n", zFile, zETime);
      }
    }else{
      usage("attachment add ?PAGENAME? FILENAME [-t|--technote DATETIME]");
    }
  }else{
    goto wiki_cmd_usage;
  }
  return;

wiki_cmd_usage:
  usage("export|create|commit|list|attachment ...");
}




































































































<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<






|

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1328
1329
1330
1331
1332
1333
1334








































































1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
      );
    }
    while( db_step(&q)==SQLITE_ROW ){
      const char *zName = db_column_text(&q, 0);
      fossil_print( "%s\n",zName);
    }
    db_finalize(&q);








































































  }else{
    goto wiki_cmd_usage;
  }
  return;

wiki_cmd_usage:
  usage("export|create|commit|list ...");
}

/*
** COMMAND: attachment*
**
** Usage: %fossil attachment add ?PAGENAME? FILENAME [-t|--technote DATETIME ]
**
**       Add an attachment to an existing wiki page or tech note. One of
**       PAGENAME or DATETIME must be specified.
**
*/
void attachment_cmd(void){
  int n;
  db_find_and_open_repository(0, 0);
  if( g.argc<3 ){
    goto attachment_cmd_usage;
  }
  n = strlen(g.argv[2]);
  if( n==0 ){
    goto attachment_cmd_usage;
  }

  if( strncmp(g.argv[2],"add",n)==0 ){
    const char *zPageName;        /* Name of the wiki page to attach to */
    const char *zFile;            /* Name of the file to be attached */
    const char *zETime;           /* The name of the technote to attach to */
    Manifest *pWiki = 0;          /* Parsed wiki page content */
    char *zBody = 0;              /* Wiki page content */
    int rid;
    const char *zTarget;          /* Target of the attachment */
    Blob content;                 /* The content of the attachment */
    zETime = find_option("technote","t",1);
    if( !zETime ){
      if( g.argc!=5 ){
        usage("attachment add PAGENAME FILENAME");
      }
      zPageName = g.argv[3];
      rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
        " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
        " ORDER BY x.mtime DESC LIMIT 1",
        zPageName
      );        
      if( (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0 ){
        zBody = pWiki->zWiki;
      }
      if( zBody==0 ){
        fossil_fatal("wiki page [%s] not found",zPageName);
      }
      zTarget = zPageName;
      zFile = g.argv[4];
    }else{
      if( g.argc!=4 ){
        usage("attachment add FILENAME --technote DATETIME");
      }
      rid = db_int(0, "SELECT objid FROM event"
        " WHERE datetime(mtime)=datetime('%q') AND type='e'"
        " ORDER BY mtime DESC LIMIT 1",
        zETime
      );
      if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){
        zBody = pWiki->zWiki;
      }
      if( zBody==0 ){
        fossil_fatal("technote [%s] not found",zETime);
      }
      zTarget = db_text(0,
        "SELECT substr(tagname,7) FROM tag WHERE tagid=(SELECT tagid FROM event WHERE objid='%d')",
        rid
      );
      zFile = g.argv[3];
    }
    blob_read_from_file(&content, zFile);
    user_select();
    attach_commit(
      zFile,                   /* The filename of the attachment */
      zTarget,                 /* The artifact uuid to attach to */
      blob_buffer(&content),   /* The content of the attachment */
      blob_size(&content),     /* The length of the attachment */
      0,                       /* No need to moderate the attachment */
      ""                       /* Empty attachment comment */
    );
    if( !zETime ){
      fossil_print("Attached %s to wiki page %s.\n", zFile, zPageName);
    }else{
      fossil_print("Attached %s to tech note %s.\n", zFile, zETime);
    }
  }else{
    goto attachment_cmd_usage;
  }
  return;

attachment_cmd_usage:
  usage("attachment add ?PAGENAME? FILENAME [-t|--technote DATETIME ]");
}