Fossil

Check-in [d1c99380]
Login

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

Overview
Comment:Change behavior of Fossil's tag handling.
  1. All subcommands of command tag prepends a prefix sym- infront of every tag name passed to them. Tags beginning with sym- are special in Fossil as they might serve as replacement of a UUID they are attached to.

    Further, tag list will only list all tags beginning with sym- but with that prefix removed during display as default.

    All subcommands can get passed an option --raw, that prevent the prepending of the prefix sym- in front of the tag name. tag list will report all tags without removing any prefix if called with option --raw.
  1. If a command takes a tag name that may be confused with a UUID, the command did interpret that parameter as a UUID instead as a tag name. Such tags might now be prefixed with a tag: to enforce the command to take them as tag name instead of a UUID. For example:
            fossil tag add abcde $uuid
            :
            fossil update tag:abcde
          
    without the prefix tag: fossil would try to update to a UUID beginning with abcde. If no such UUID was found, fossil will complain and exit.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:d1c993802524c5a47d2e6219f9f1380f6ccff857
User & Date: cle 2008-07-27 18:35:06
Original Comment: Change behavior of Fossil's tag handling.

1. All subcommands of command tag prepends a prefix "sym-" infront of every tag name passed to them. Tags beginning with "sym-" are special in Fossil as they might serve as replacement of a UUID they are attached to.

Further, "tag list" will only list all tags beginning with "sym-" but with that prefix removed during display as default.
All subcommands can get passed an option "--raw", that prevent the prepending of the prefix "sym-" in front of the tag name. "tag list" will report all tags without removeing any prefix if called with option "--raw".

2. If a command takes a tag name that may be confused with a UUID, the command did interpret that parameter as a UUID instead as a tag name. Such tags might now be prefixed with a "tag:" to enforce the command to take them as tag name instead of a UUID. For example:

fossil tag add abcde $uuid : fossil update tag:abcde
without the prefix "tag:" fossil would try to update to a UUID beginning with abcde. If no such UUID was found, fossil will complain and exit.
Context
2008-07-27
21:02
Reverse the check on inline formatting for indented paragraphs in wikiformat.c check-in: 3bc6d0b0 user: eric tags: trunk
18:35
Change behavior of Fossil's tag handling.
  1. All subcommands of command tag prepends a prefix sym- infront of every tag name passed to them. Tags beginning with sym- are special in Fossil as they might serve as replacement of a UUID they are attached to.

    Further, tag list will only list all tags beginning with sym- but with that prefix removed during display as default.

    All subcommands can get passed an option --raw, that prevent the prepending of the prefix sym- in front of the tag name. tag list will report all tags without removing any prefix if called with option --raw.
  1. If a command takes a tag name that may be confused with a UUID, the command did interpret that parameter as a UUID instead as a tag name. Such tags might now be prefixed with a tag: to enforce the command to take them as tag name instead of a UUID. For example:
            fossil tag add abcde $uuid
            :
            fossil update tag:abcde
          
    without the prefix tag: fossil would try to update to a UUID beginning with abcde. If no such UUID was found, fossil will complain and exit.
check-in: d1c99380 user: cle tags: trunk
2008-07-26
17:08
Make all users inherit the capabilities of "nobody" as well as (optionally) of "anonymous". check-in: eb24a021 user: eric tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/name.c.

44
45
46
47
48
49
50







51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
int name_to_uuid(Blob *pName, int iErrPriority){
  int rc;
  int sz;
  sz = blob_size(pName);
  if( sz>UUID_SIZE || sz<4 || !validate16(blob_buffer(pName), sz) ){
    Stmt q;
    Blob uuid;








    db_prepare(&q,
      "SELECT (SELECT uuid FROM blob WHERE rid=objid)"
      "  FROM tagxref JOIN event ON rid=objid"
      " WHERE tagid=(SELECT tagid FROM tag WHERE tagname='sym-'||%B)"
      "   AND tagtype>0"
      "   AND value IS NULL"
      " ORDER BY event.mtime DESC",
      pName
    );
    blob_zero(&uuid);
    if( db_step(&q)==SQLITE_ROW ){
      db_column_blob(&q, 0, &uuid);
    }
    db_finalize(&q);
    if( blob_size(&uuid)==0 ){
      fossil_error(iErrPriority, "not a valid object name: %b", pName);
      blob_reset(&uuid);
      return 1;
    }else{
      blob_reset(pName);
      *pName = uuid;
      return 0;
    }







>
>
>
>
>
>
>




|



|







|







44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
int name_to_uuid(Blob *pName, int iErrPriority){
  int rc;
  int sz;
  sz = blob_size(pName);
  if( sz>UUID_SIZE || sz<4 || !validate16(blob_buffer(pName), sz) ){
    Stmt q;
    Blob uuid;
    static const char prefix[] = "tag:";
    static const int preflen = sizeof(prefix)-1;
    const char *zName = blob_str(pName);

    if( strncmp(zName, prefix, preflen)==0 ){
      zName += preflen;
    }

    db_prepare(&q,
      "SELECT (SELECT uuid FROM blob WHERE rid=objid)"
      "  FROM tagxref JOIN event ON rid=objid"
      " WHERE tagid=(SELECT tagid FROM tag WHERE tagname='sym-'||%Q)"
      "   AND tagtype>0"
      "   AND value IS NULL"
      " ORDER BY event.mtime DESC",
      zName
    );
    blob_zero(&uuid);
    if( db_step(&q)==SQLITE_ROW ){
      db_column_blob(&q, 0, &uuid);
    }
    db_finalize(&q);
    if( blob_size(&uuid)==0 ){
      fossil_error(iErrPriority, "not a valid object name: %s", zName);
      blob_reset(&uuid);
      return 1;
    }else{
      blob_reset(pName);
      *pName = uuid;
      return 0;
    }

Changes to src/tag.c.

271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
...
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
...
389
390
391
392
393
394
395
396



397
398
399
400
401
402
403
...
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
  blob_zero(&uuid);
  blob_append(&uuid, zObjName, -1);
  if( name_to_uuid(&uuid, 9) ){
    return;
  }
  rid = name_to_rid(blob_str(&uuid));
  blob_zero(&ctrl);
  
  if( validate16(zTagname, strlen(zTagname)) ){
    fossil_fatal("invalid tag name \"%s\" - might be confused with a UUID",
                 zTagname);
  }
  zDate = db_text(0, "SELECT datetime('now')");
  zDate[10] = 'T';
  blob_appendf(&ctrl, "D %s\n", zDate);
................................................................................

/*
** COMMAND: tag
** Usage: %fossil tag SUBCOMMAND ...
**
** Run various subcommands to control tags and properties
**
**     %fossil tag add TAGNAME UUID ?VALUE?
**
**         Add a new tag or property to UUID.


**
**     %fossil tag branch TAGNAME UUID ?VALUE?
**
**         Add a new tag or property to UUID and make that
**         tag propagate to all direct children.
**
**     %fossil tag delete TAGNAME UUID
**
**         Delete the tag TAGNAME from UUID
**
**     %fossil tag find TAGNAME
**
**         List all baselines that use TAGNAME
**
**     %fossil tag list ?UUID?
**
**         List all tags, or if UUID is supplied, list
**         all tags and their values for UUID.



















*/
void tag_cmd(void){
  int n;





  db_find_and_open_repository(1);
  if( g.argc<3 ){
    goto tag_cmd_usage;
  }
  n = strlen(g.argv[2]);
  if( n==0 ){
    goto tag_cmd_usage;
  }



  if( strncmp(g.argv[2],"add",n)==0 ){
    char *zValue;
    if( g.argc!=5 && g.argc!=6 ){
      usage("add TAGNAME UUID ?VALUE?");
    }

    zValue = g.argc==6 ? g.argv[5] : 0;
    tag_add_artifact(g.argv[3], g.argv[4], zValue, 1);
  }else

  if( strncmp(g.argv[2],"branch",n)==0 ){
    char *zValue;
    if( g.argc!=5 && g.argc!=6 ){
      usage("branch TAGNAME UUID ?VALUE?");
    }

    zValue = g.argc==6 ? g.argv[5] : 0;
    tag_add_artifact(g.argv[3], g.argv[4], zValue, 2);
  }else

  if( strncmp(g.argv[2],"delete",n)==0 ){
    if( g.argc!=5 ){
      usage("delete TAGNAME UUID");
    }

    tag_add_artifact(g.argv[3], g.argv[4], 0, 0);
  }else

  if( strncmp(g.argv[2],"find",n)==0 ){
    Stmt q;
    if( g.argc!=4 ){
      usage("find TAGNAME");
    }

    db_prepare(&q,
      "SELECT blob.uuid FROM tagxref, blob"
      " WHERE tagid=(SELECT tagid FROM tag WHERE tagname=%Q)"
      "   AND blob.rid=tagxref.rid", g.argv[3]
    );
    while( db_step(&q)==SQLITE_ROW ){
      printf("%s\n", db_column_text(&q, 0));
    }
    db_finalize(&q);
  }else

................................................................................
        "  FROM tag"
        " WHERE EXISTS(SELECT 1 FROM tagxref"
        "               WHERE tagid=tag.tagid"
        "                 AND tagtype>0)"
        " ORDER BY tagname"
      );
      while( db_step(&q)==SQLITE_ROW ){
        printf("%s\n", db_column_text(&q, 0));



      }
      db_finalize(&q);
    }else if( g.argc==4 ){
      int rid = name_to_rid(g.argv[3]);
      db_prepare(&q,
        "SELECT tagname, value"
        "  FROM tagxref, tag"
................................................................................
        " ORDER BY tagname",
        rid
      );
      while( db_step(&q)==SQLITE_ROW ){
        const char *zName = db_column_text(&q, 0);
        const char *zValue = db_column_text(&q, 1);
        if( zValue ){

          printf("%s=%s\n", zName, zValue);

        }else{

          printf("%s\n", zName);

        }
      }
      db_finalize(&q);
    }else{
      usage("tag list ?UUID?");
    }
  }else
  {
    goto tag_cmd_usage;
  }



  return;

tag_cmd_usage:
  usage("add|branch|delete|find|list ...");
}







|







 







|

|
>
>

|




|



|



|



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



>
>
>
>
>








>
>






>

|







>

|






>
|







>


|
|







 







|
>
>
>







 







>
|
>

>
|
>










>
>
>





271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
...
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
...
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
...
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
  blob_zero(&uuid);
  blob_append(&uuid, zObjName, -1);
  if( name_to_uuid(&uuid, 9) ){
    return;
  }
  rid = name_to_rid(blob_str(&uuid));
  blob_zero(&ctrl);

  if( validate16(zTagname, strlen(zTagname)) ){
    fossil_fatal("invalid tag name \"%s\" - might be confused with a UUID",
                 zTagname);
  }
  zDate = db_text(0, "SELECT datetime('now')");
  zDate[10] = 'T';
  blob_appendf(&ctrl, "D %s\n", zDate);
................................................................................

/*
** COMMAND: tag
** Usage: %fossil tag SUBCOMMAND ...
**
** Run various subcommands to control tags and properties
**
**     %fossil tag add ?--raw? TAGNAME UUID ?VALUE?
**
**         Add a new tag or property to UUID. The tag will
**         be usable instead of a UUID in commands like
**         update and the like.
**
**     %fossil tag branch ?--raw? TAGNAME UUID ?VALUE?
**
**         Add a new tag or property to UUID and make that
**         tag propagate to all direct children.
**
**     %fossil tag delete ?--raw? TAGNAME UUID
**
**         Delete the tag TAGNAME from UUID
**
**     %fossil tag find ?--raw? TAGNAME
**
**         List all baselines that use TAGNAME
**
**     %fossil tag list ?--raw? ?UUID?
**
**         List all tags, or if UUID is supplied, list
**         all tags and their values for UUID.
**
** The option ?--raw? is to expose the internal interface 
** for tag handling. This option is not necessary for the
** normal use.
**
** If you use a tagname that might be confused with a UUID,
** you have to explicitly disambiguate it by prefixing it
** with "tag:". For instance:
**
**   fossil update cfcfcfee
**
** is not the same as:
**
**   fossil update tag:cfcfcfee
**
** The first will be taken as UUID and fossil will complain
** if no such revision was found, and the second one expect
** "cfcfcfee" to be a tag/branch name!
**
*/
void tag_cmd(void){
  int n;
  int raw = find_option("raw","",0)!=0;
  const char *prefix = raw ? "" : "sym-";
  int preflen = strlen(prefix);
  Blob tagname;

  db_find_and_open_repository(1);
  if( g.argc<3 ){
    goto tag_cmd_usage;
  }
  n = strlen(g.argv[2]);
  if( n==0 ){
    goto tag_cmd_usage;
  }

  blob_set(&tagname, prefix);

  if( strncmp(g.argv[2],"add",n)==0 ){
    char *zValue;
    if( g.argc!=5 && g.argc!=6 ){
      usage("add TAGNAME UUID ?VALUE?");
    }
    blob_append(&tagname, g.argv[3], strlen(g.argv[3]));
    zValue = g.argc==6 ? g.argv[5] : 0;
    tag_add_artifact(blob_str(&tagname), g.argv[4], zValue, 1);
  }else

  if( strncmp(g.argv[2],"branch",n)==0 ){
    char *zValue;
    if( g.argc!=5 && g.argc!=6 ){
      usage("branch TAGNAME UUID ?VALUE?");
    }
    blob_append(&tagname, g.argv[3], strlen(g.argv[3]));
    zValue = g.argc==6 ? g.argv[5] : 0;
    tag_add_artifact(blob_str(&tagname), g.argv[4], zValue, 2);
  }else

  if( strncmp(g.argv[2],"delete",n)==0 ){
    if( g.argc!=5 ){
      usage("delete TAGNAME UUID");
    }
    blob_append(&tagname, g.argv[3], strlen(g.argv[3]));
    tag_add_artifact(blob_str(&tagname), g.argv[4], 0, 0);
  }else

  if( strncmp(g.argv[2],"find",n)==0 ){
    Stmt q;
    if( g.argc!=4 ){
      usage("find TAGNAME");
    }
    blob_append(&tagname, g.argv[3], strlen(g.argv[3]));
    db_prepare(&q,
      "SELECT blob.uuid FROM tagxref, blob"
      " WHERE tagid=(SELECT tagid FROM tag WHERE tagname=%B)"
      "   AND blob.rid=tagxref.rid", &tagname
    );
    while( db_step(&q)==SQLITE_ROW ){
      printf("%s\n", db_column_text(&q, 0));
    }
    db_finalize(&q);
  }else

................................................................................
        "  FROM tag"
        " WHERE EXISTS(SELECT 1 FROM tagxref"
        "               WHERE tagid=tag.tagid"
        "                 AND tagtype>0)"
        " ORDER BY tagname"
      );
      while( db_step(&q)==SQLITE_ROW ){
        const char *name = db_column_text(&q, 0);
        if( raw || strncmp(name, prefix, preflen)==0 ){
          printf("%s\n", name+preflen);
        }
      }
      db_finalize(&q);
    }else if( g.argc==4 ){
      int rid = name_to_rid(g.argv[3]);
      db_prepare(&q,
        "SELECT tagname, value"
        "  FROM tagxref, tag"
................................................................................
        " ORDER BY tagname",
        rid
      );
      while( db_step(&q)==SQLITE_ROW ){
        const char *zName = db_column_text(&q, 0);
        const char *zValue = db_column_text(&q, 1);
        if( zValue ){
          if( raw || strncmp(zName, prefix, preflen)==0 ){
            printf("%s=%s\n", zName+preflen, zValue);
          }
        }else{
          if( raw || strncmp(zName, prefix, preflen)==0 ){
            printf("%s\n", zName+preflen);
          }
        }
      }
      db_finalize(&q);
    }else{
      usage("tag list ?UUID?");
    }
  }else
  {
    goto tag_cmd_usage;
  }

  /* Cleanup */
  blob_reset(&tagname);
  return;

tag_cmd_usage:
  usage("add|branch|delete|find|list ...");
}