Fossil

Check-in [413ebeb1]
Login

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

Overview
Comment:TH1 fossiltag command for accessing tag values.

Has two subcommands: get and list, which do what they sound like.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | th1_fossiltag_cmd
Files: files | file ages | folders
SHA1:413ebeb12e24c09038f1aa188646d9dc51e00ba9
User & Date: bcsmith 2010-10-21 23:26:08
Context
2010-10-21
23:26
TH1 fossiltag command for accessing tag values.

Has two subcommands: get and list, which do what they sound like. Leaf check-in: 413ebeb1 user: bcsmith tags: th1_fossiltag_cmd

2010-10-09
17:18
Fix a potential segfault on "fossil pull". Ticket [71439c64b8d6af66f5e34]. check-in: 26c262cd user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/th_main.c.

231
232
233
234
235
236
237







































































































































































































238
239
240
241
242
243
244
...
348
349
350
351
352
353
354

355
356
357
358
359
360
361
...
517
518
519
520
521
522
523




524
525
526
527




528

529


530

  }
  if( g.thTrace ){
    Th_Trace("[hascap %.*h] => %d<br />\n", argl[1], argv[1], rc);
  }
  Th_SetResultInt(interp, rc);
  return TH_OK;
}








































































































































































































/*
** TH1 command:  combobox NAME TEXT-LIST NUMLINES
**
** Generate an HTML combobox.  NAME is both the name of the
** CGI parameter and the name of a variable that contains the
** currently selected value.  TEXT-LIST is a list of possible
................................................................................
    {"linecount",     linecntCmd,           0},
    {"hascap",        hascapCmd,            0},
    {"htmlize",       htmlizeCmd,           0},
    {"date",          dateCmd,              0},
    {"html",          putsCmd,              0},
    {"puts",          putsCmd,       (void*)1},
    {"wiki",          wikiCmd,              0},

  };
  if( g.interp==0 ){
    int i;
    g.interp = Th_CreateInterp(&vtab);
    th_register_language(g.interp);       /* Basic scripting commands. */
    for(i=0; i<sizeof(aCommand)/sizeof(aCommand[0]); i++){
      Th_CreateCommand(g.interp, aCommand[i].zName, aCommand[i].xProc,
................................................................................
}

/*
** COMMAND: test-th-render
*/
void test_th_render(void){
  Blob in;




  if( g.argc<3 ){
    usage("FILE");
  }
  blob_zero(&in);




  blob_read_from_file(&in, g.argv[2]);

  Th_Render(blob_str(&in));


}








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>







 







>
>
>
>




>
>
>
>
|
>

>
>
|
>
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
...
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
...
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
  }
  if( g.thTrace ){
    Th_Trace("[hascap %.*h] => %d<br />\n", argl[1], argv[1], rc);
  }
  Th_SetResultInt(interp, rc);
  return TH_OK;
}

/*
**
** TH1 command: fossiltag list ?ARTIFACT-ID?
**
**   Returns a list of tags on ARTIFACT-ID. Or, all tags,
**   if ARTIFACT-ID is not specified. Only uncancelled tags
**   are included in the result.
**
**   Example:
**     <b>List of tags on thing:</b>
**     <th1>
**     puts [fossiltag list 2b4630f34]
**     </th1>
*/
static int fossiltagListCmd(
  Th_Interp *interp,
  void *p,
  int argc,
  const char **argv,
  int *argl
){
  Stmt st;
  char *zTagList = 0;
  int  nTagList = 0;
  if( argc==3 ){
    db_prepare(&st,
               "SELECT tag.tagname FROM tag, tagxref "
               "  WHERE tagxref.rid=%d "
               "    AND tagxref.tagid=tag.tagid"
               "    AND tagxref.tagtype>0 ",
               name_to_rid((char*)argv[2])
               );
  }
  else {
    db_prepare(&st,
               "SELECT DISTINCT tag.tagname FROM tag, tagxref "
               "  WHERE "
               "    tagxref.tagid=tag.tagid"
               "    AND tagxref.tagtype>0 "
               );
  }
  while( db_step(&st) == SQLITE_ROW ){
    char *tagname = (char*)db_column_text(&st, 0);
    Th_ListAppend(interp, &zTagList, &nTagList, tagname, -1);

  }

  Th_SetResult(interp, zTagList, nTagList);
  Th_Free(interp, zTagList);
  db_finalize(&st);
  return TH_OK;
}

/*
**
** TH1 command: fossiltag get TAG-NAME ?ARTIFACT-ID? ?FALLBACK-VALUE?
**
**   Returns the value of TAG-NAME on ARTIFACT-ID, or
**   one of the following:
**   if FALLBACK-VALUE provided and TAG-NAME not present,
**   then FALLBACK-VALUE is returned.
**   if FALLBACK-VALUE not provided, and TAG-NAME not present,
**   then 0 returned.
**   if TAG-NAME present, but has no value, then 1 is returned.
**
**   Example:
**     <b>Check-in acceptance status:</b>
**     <th1>
**     set accept_out ""
**     if {[set out [fossiltag get "QA_acceptance" $check_in_id "<b>DID NOT PASS</b>"]]} {
**       set accept_out "  *  QA: ${out}"
**     }
**     if {[set out [fossiltag get "Unit_passed" $check_in_id "<b>DID NOT PASS UNIT TESTS</b>"]]} {
**       set accept_out "${accept_out}\n  *  Unit tests: ${out}"
**     }
**     if {[set out [fossiltag get "Signed_off_by" $check_in_id "<b>NOT SIGNED OFF</b>"]]} {
**       set accept_out "${accept_out}\n  *  Signed off by: ${out}"
**     }
**     puts [wiki $accept_out]
**     </th1>
*/
static int fossiltagGetCmd(
  Th_Interp *interp,
  void *p,
  int argc,
  const char **argv,
  int *argl
){
  int rid = -1;
  char *zTagValue = 0;
  char *zDefault = 0;
  int nDefault = 0;
  db_open_local();
  db_open_repository(0);
  if( argc<3 ){
    return Th_WrongNumArgs(interp, "fossiltag get TAG-NAME ?ARTIFACT-ID? ?FALLBACK-TEXT?");
  }
  /* if a fallback value was provided, place it in zDefault */
  if( argc==5 ){
    zDefault = (char*)argv[4];
    nDefault = argl[4];
  }
  /* if an artifact-id (name) is given.. */
  if( argc>=4 && strlen((char*)argv[3])){
    rid =
    db_int(0,
           "SELECT blob.rid "
           "  FROM tag, tagxref, blob "
           "WHERE tag.tagname=%Q AND blob.rid=%d"
           "  AND tagxref.tagid=tag.tagid AND tagxref.tagtype>0 "
           "  AND blob.rid=tagxref.rid ",
           argv[2], name_to_rid((char*)argv[3])
           );

    if( g.thTrace ){
      Th_Trace("[tagget] artifact-id: %s %d\n", argv[3], rid);
    }
  }
  else { /* if no artifact-id is given, we select the most recent commit
            containing TAG-NAME */
    rid =
    db_int(0,
       "SELECT blob.rid "
       "  FROM tag, tagxref, event, blob "
       "WHERE tag.tagname=%Q "
       "  AND tagxref.tagid=tag.tagid AND tagxref.tagtype>0 "
       "  AND event.objid=tagxref.rid "
       "  AND blob.rid=event.objid "
       "ORDER BY event.mtime DESC ",
       argv[2]
    );
    if( g.thTrace ){
      Th_Trace("[tagget] artifact-rid: %d\n", rid);
    }
  }

  /* return 0 or the fallback value, since we couldn't
     find an artifact with TAG-NAME on it. */
  if( rid==0 && argc==5 ){
    if( g.thTrace ){
      Th_Trace("[tagget] tag not on any artifact; returning default: %s\n", zDefault);
    }
    Th_SetResult(interp, zDefault, nDefault);
    return TH_OK;
  }
  else if( rid==0 && argc<5 ){
    if( g.thTrace ){
      Th_Trace("[tagget] tag not on any artifact; ret: 0\n");
    }
    Th_SetResultInt(interp, 0);
    return TH_OK;
  }

  zTagValue = db_text(zDefault,
                      "SELECT tagxref.value FROM tag, tagxref "
                      "  WHERE tag.tagname=%Q "
                      "    AND tagxref.tagid=tag.tagid "
                      "    AND tagxref.rid=%d ",
                      argv[2], rid
                      );
  if( zTagValue && strlen(zTagValue)==0 ){
    if( g.thTrace ){
      Th_Trace("[tagget] tag has no value; ret: 1\n");
    }
    Th_SetResultInt(interp, 1);
    free(zTagValue);
  }
  else {
    if( g.thTrace ){
      Th_Trace("[tagget] returning tag value: %s\n", zTagValue);
    }
    Th_SetResult(interp, zTagValue, -1);
    free(zTagValue);
  }
  return TH_OK;
}

/*
** TH1 command: fossiltag list|get ...
**
** Provide TH1 commands for read-only interation with tags on
** any taggable artifact. The tags are always raw.
**
*/
static int fossiltagCmd(
  Th_Interp *interp,
  void *p,
  int argc,
  const char **argv,
  int *argl
){
  Th_SubCommand aSub[] = {
    { "list", fossiltagListCmd },
    { "get",   fossiltagGetCmd },
    { 0, 0 }
  };
  return Th_CallSubCommand(interp, p, argc, argv, argl, aSub);
}

/*
** TH1 command:  combobox NAME TEXT-LIST NUMLINES
**
** Generate an HTML combobox.  NAME is both the name of the
** CGI parameter and the name of a variable that contains the
** currently selected value.  TEXT-LIST is a list of possible
................................................................................
    {"linecount",     linecntCmd,           0},
    {"hascap",        hascapCmd,            0},
    {"htmlize",       htmlizeCmd,           0},
    {"date",          dateCmd,              0},
    {"html",          putsCmd,              0},
    {"puts",          putsCmd,       (void*)1},
    {"wiki",          wikiCmd,              0},
    {"fossiltag",     fossiltagCmd,         0},
  };
  if( g.interp==0 ){
    int i;
    g.interp = Th_CreateInterp(&vtab);
    th_register_language(g.interp);       /* Basic scripting commands. */
    for(i=0; i<sizeof(aCommand)/sizeof(aCommand[0]); i++){
      Th_CreateCommand(g.interp, aCommand[i].zName, aCommand[i].xProc,
................................................................................
}

/*
** COMMAND: test-th-render
*/
void test_th_render(void){
  Blob in;
  g.thTrace = find_option("th-trace", 0, 0)!=0;
  if( g.thTrace ){
    blob_zero(&g.thLog);
  }
  if( g.argc<3 ){
    usage("FILE");
  }
  blob_zero(&in);
  if( g.thTrace ){
    blob_read_from_file(&in, g.argv[3]);
  }
  else{
    blob_read_from_file(&in, g.argv[2]);
  }
  Th_Render(blob_str(&in));
  if( g.thTrace ){
    fossil_print("%s", blob_materialize(&g.thLog));
  }
}