Fossil

Check-in [c887b2b6]
Login

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

Overview
Comment:Add a --nofork option to "tag branch" so that --raw is not being used for two different purposes. Modify and tidy up the corresponding help text.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:c887b2b66e643ef09989ecfda62733f9b274066a
User & Date: eric 2008-10-22 19:35:08
Context
2008-10-23
03:21
Fix a spelling in help text of 'tag branch'. check-in: 56177cfe user: cle tags: trunk
2008-10-22
19:35
Add a --nofork option to "tag branch" so that --raw is not being used for two different purposes. Modify and tidy up the corresponding help text. check-in: c887b2b6 user: eric tags: trunk
2008-10-21
06:52
The "diff" command with no arguments now does a diff on all files in the checkout which have been edited. check-in: c863ec1a user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/tag.c.

255
256
257
258
259
260
261
262

263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
...
307
308
309
310
311
312
313
314

315
316
317
318
319
320
321
...
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
...
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
...
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
473
474
475
476
477
**
** The changes are appended at the Blob pCtrl. However the manifest
** is not complete at that stage.
*/
static void tag_prepare_fork(
  Blob *pCtrl, 
  const char *zTagname,
  int rid

){
  Stmt q;
  Manifest origin;
  Blob originContent;
  char *zDate;
  int i;

  blob_appendf(pCtrl, "C Create\\snamed\\sfork\\s%s\n", zTagname+4);
  content_get(rid, &originContent);
  manifest_parse(&origin, &originContent);
  zDate = db_text(0, "SELECT datetime('now')");
  zDate[10] = 'T';
  blob_appendf(pCtrl, "D %s\n", zDate);
  for(i=0; i<origin.nFile; ++i){
    blob_appendf(pCtrl, "F %s %s %s\n",
................................................................................
** or cancels a tag.
*/
static void tag_add_artifact(
  const char *zTagname,       /* The tag to add or cancel */
  const char *zObjName,       /* Name of object attached to */
  const char *zValue,         /* Value for the tag.  Might be NULL */
  int tagtype,                /* 0:cancel 1:singleton 2:propagated */
  int fork                    /* Should a fork created from zObjName? */

){
  int rid;
  int nrid;
  char *zDate;
  Blob uuid;
  Blob ctrl;
  Blob cksum;
................................................................................
  blob_zero(&ctrl);

  if( validate16(zTagname, strlen(zTagname)) ){
    fossil_fatal("invalid tag name \"%s\" - might be confused with a UUID",
                 zTagname);
  }
  if( fork ){
    tag_prepare_fork(&ctrl, zTagname, rid);
  }else{
    zDate = db_text(0, "SELECT datetime('now')");
    zDate[10] = 'T';
    blob_appendf(&ctrl, "D %s\n", zDate);
    blob_appendf(&ctrl, "T %c%F %b", zTagtype[tagtype], zTagname, &uuid);
  }
  if( tagtype && zValue && zValue[0] ){
................................................................................
** 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 such.
**
**     %fossil tag branch ?--raw? TAGNAME UUID ?VALUE?
**
**         A fork of UUID will be created. Then the new tag
**         or property will be added to the fork that
**         propagate to all direct children.
**
**         Additionally all symbolic tags of that fork
**         inherited from UUID will be cancelled.

**
**         However, if the option '--raw' was given, no
**         fork will be created but the tag/property will be
**         added to UUID directly and no tag will be
**         canceled.
**
**         Please see the description of '--raw' below too.
**
**     %fossil tag cancel ?--raw? TAGNAME UUID
**
**         Cancel 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;
................................................................................
  if( strncmp(g.argv[2],"add",n)==0 ){
    char *zValue;
    if( g.argc!=5 && g.argc!=6 ){
      usage("add ?--raw? 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, 0);
  }else

  if( strncmp(g.argv[2],"branch",n)==0 ){
    char *zValue;
    if( g.argc!=5 && g.argc!=6 ){
      usage("branch ?--raw? 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, raw==0);

    if( !raw ){
      const char *zUuid = db_text(0, "SELECT uuid, MAX(rowid) FROM blob");
      printf("New_Fork \"%s\": %s\n", g.argv[3], zUuid);
    }
  }else

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

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







|
>







|







 







|
>







 







|







 







|
|

|

|
|
|
|
|
|
>

|
|
|
<
<
<



|
>










|
|
|
>

|
|
|

|

<
>
>



|
<
<





>







 







|





|



|
>
|










|







255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
...
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
...
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
...
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
...
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
473
474
475
476
477
478
479
480
**
** The changes are appended at the Blob pCtrl. However the manifest
** is not complete at that stage.
*/
static void tag_prepare_fork(
  Blob *pCtrl, 
  const char *zTagname,
  int rid,
  int preflen                 /* Tag prefix length to adjust name if reqd */
){
  Stmt q;
  Manifest origin;
  Blob originContent;
  char *zDate;
  int i;

  blob_appendf(pCtrl, "C Create\\snamed\\sfork\\s%s\n", zTagname+preflen);
  content_get(rid, &originContent);
  manifest_parse(&origin, &originContent);
  zDate = db_text(0, "SELECT datetime('now')");
  zDate[10] = 'T';
  blob_appendf(pCtrl, "D %s\n", zDate);
  for(i=0; i<origin.nFile; ++i){
    blob_appendf(pCtrl, "F %s %s %s\n",
................................................................................
** or cancels a tag.
*/
static void tag_add_artifact(
  const char *zTagname,       /* The tag to add or cancel */
  const char *zObjName,       /* Name of object attached to */
  const char *zValue,         /* Value for the tag.  Might be NULL */
  int tagtype,                /* 0:cancel 1:singleton 2:propagated */
  int fork,                   /* Should a fork created from zObjName? */
  int preflen                 /* Tag prefix length to adjust name if reqd */
){
  int rid;
  int nrid;
  char *zDate;
  Blob uuid;
  Blob ctrl;
  Blob cksum;
................................................................................
  blob_zero(&ctrl);

  if( validate16(zTagname, strlen(zTagname)) ){
    fossil_fatal("invalid tag name \"%s\" - might be confused with a UUID",
                 zTagname);
  }
  if( fork ){
    tag_prepare_fork(&ctrl, zTagname, rid, preflen);
  }else{
    zDate = db_text(0, "SELECT datetime('now')");
    zDate[10] = 'T';
    blob_appendf(&ctrl, "D %s\n", zDate);
    blob_appendf(&ctrl, "T %c%F %b", zTagtype[tagtype], zTagname, &uuid);
  }
  if( tagtype && zValue && zValue[0] ){
................................................................................
** 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 such as
**         update and merge.
**
**     %fossil tag branch ?--raw? ?--nofork? TAGNAME UUID ?VALUE?
**
**         A fork will be created so that the new checkin
**         is a sibling of UUID and identical to it except
**         for a generated comment. Then the new tag will
**         be added to the new checkin and propagated to
**         all direct children.  Additionally all symbolic
**         tags of that checkin inherited from UUID will
**         be cancelled.
**
**         However, if the option --nofork is given, no
**         fork will be created and the tag/property will be
**         added to UUID directly. No tags will be canceled.



**
**     %fossil tag cancel ?--raw? TAGNAME UUID
**
**         Remove the tag TAGNAME from UUID, and also remove
**         the propagation of the tag to any descendants.
**
**     %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 allows the manipulation of all types of
** tags used for various internal purposes in fossil. You
** should not use this option to make changes unless you are
** sure what you are doing.
**
** If you need to use a tagname that might be confused with
** a UUID, you can explicitly disambiguate it by prefixing
** it with "tag:". For instance:
**
**   fossil update decaf
**

** will be taken as a UUID and fossil will probably complain
** that no such revision was found. However
**
**   fossil update tag:cfcfcfee
**
** will assume that "decaf" is a tag/branch name.


**
*/
void tag_cmd(void){
  int n;
  int raw = find_option("raw","",0)!=0;
  int fork = find_option("nofork","",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;
................................................................................
  if( strncmp(g.argv[2],"add",n)==0 ){
    char *zValue;
    if( g.argc!=5 && g.argc!=6 ){
      usage("add ?--raw? 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, 0, 0);
  }else

  if( strncmp(g.argv[2],"branch",n)==0 ){
    char *zValue;
    if( g.argc!=5 && g.argc!=6 ){
      usage("branch ?--raw? ?--nofork? 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, fork!=0,
                                                      preflen);
    if( fork ){
      const char *zUuid = db_text(0, "SELECT uuid, MAX(rowid) FROM blob");
      printf("New_Fork \"%s\": %s\n", g.argv[3], zUuid);
    }
  }else

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

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