Fossil

Diff
Login

Diff

Differences From Artifact [56669f6f87]:

To Artifact [6980217297]:


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
  }
  zValue = g.argc==5 ? g.argv[4] : 0;
  db_begin_transaction();
  tag_insert(zTag, tagtype, zValue, -1, 0.0, rid);
  db_end_transaction(0); 
}

/*
** Prepare an artifact that describes a fork from a certain baseline.
** Furthermore a propagating symbolic tag will be inserted and
** all other propagating symbolic tags will be cancelled.
**
** 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",
                 origin.aFile[i].zName,
                 origin.aFile[i].zUuid,
                 origin.aFile[i].zPerm);
  }
  if( origin.nParent>0 ){
    blob_appendf(pCtrl, "P %s\n", origin.azParent[0]);
  }
  blob_appendf(pCtrl, "R %s\n", origin.zRepoCksum);
  blob_appendf(pCtrl, "T *%F *", zTagname);

  /* Cancel any sym- tags that propagate */
  db_prepare(&q,
      "SELECT tagname FROM tagxref, tag"
      " WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid"
      "   AND tagtype>0 AND tagname LIKE 'sym-%%'"
      " ORDER BY tagname",
      rid);
  while( db_step(&q)==SQLITE_ROW ){
    const char *zTag = db_column_text(&q, 0);
    blob_appendf(pCtrl, "\nT -%s *", zTag);
  }
  db_finalize(&q);

  /* Cleanup */
  manifest_clear(&origin);
}

/*
** Add a control record to the repository that either creates
** 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;
  static const char zTagtype[] = { '-', '+', '*' };

  assert( tagtype>=0 && tagtype<=2 );
  user_select();
  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 hexadecimal artifact ID",
       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] ){
    blob_appendf(&ctrl, " %F\n", zValue);
  }else{
    blob_appendf(&ctrl, "\n");
  }
  blob_appendf(&ctrl, "U %F\n", g.zLogin);
  md5sum_blob(&ctrl, &cksum);
  blob_appendf(&ctrl, "Z %b\n", &cksum);








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




>



|
<
<



















>







|
<
<
|
|
|
|
<
>
|







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
  }
  zValue = g.argc==5 ? g.argv[4] : 0;
  db_begin_transaction();
  tag_insert(zTag, tagtype, zValue, -1, 0.0, rid);
  db_end_transaction(0); 
}

/*























































** Add a control record to the repository that either creates
** or cancels a tag.
*/
static void tag_add_artifact(
  const char *zPrefix,        /* Prefix to prepend to tag name */
  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 rid;
  int nrid;
  char *zDate;
  Blob uuid;
  Blob ctrl;
  Blob cksum;
  static const char zTagtype[] = { '-', '+', '*' };

  assert( tagtype>=0 && tagtype<=2 );
  user_select();
  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 0
  if( validate16(zTagname, strlen(zTagname)) ){
    fossil_fatal(
       "invalid tag name \"%s\" - might be confused with"
       " a hexadecimal artifact ID",
       zTagname
    );
  }
#endif


  zDate = db_text(0, "SELECT datetime('now')");
  zDate[10] = 'T';
  blob_appendf(&ctrl, "D %s\n", zDate);
  blob_appendf(&ctrl, "T %c%s%F %b",

               zTagtype[tagtype], zPrefix, zTagname, &uuid);
  if( tagtype>0 && zValue && zValue[0] ){
    blob_appendf(&ctrl, " %F\n", zValue);
  }else{
    blob_appendf(&ctrl, "\n");
  }
  blob_appendf(&ctrl, "U %F\n", g.zLogin);
  md5sum_blob(&ctrl, &cksum);
  blob_appendf(&ctrl, "Z %b\n", &cksum);
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

/*
** COMMAND: tag
** Usage: %fossil tag SUBCOMMAND ...
**
** Run various subcommands to control tags and properties
**
**     %fossil tag add ?--raw? TAGNAME BASELINE ?VALUE?
**
**         Add a new tag or property to BASELINE. The tag will
**         be usable instead of a BASELINE in commands such as
**         update and merge.
**
**     %fossil tag branch ?--raw? ?--nofork? TAGNAME BASELINE ?VALUE?
**
**         A fork will be created so that the new checkin
**         is a sibling of BASELINE 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 BASELINE will
**         be cancelled.
**
**         However, if the option --nofork is given, no
**         fork will be created and the tag/property will be
**         added to BASELINE directly. No tags will be canceled.
**
**     %fossil tag cancel ?--raw? TAGNAME BASELINE
**
**         Remove the tag TAGNAME from BASELINE, 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? ?BASELINE?
**
**         List all tags, or if BASELINE is supplied, list
**         all tags and their values for BASELINE.
**
** The option --raw allows the manipulation of all types of tags
** used for various internal purposes in fossil. It also shows
** "cancel" tags for the "find" and "list" subcommands. You should
** not use this option to make changes unless you are sure what
** you are doing.
**







|

|
|
|
<
<
<
<
<
<
<
<
<
|

<
<
<
<
|

|




|

|

|
|







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

/*
** COMMAND: tag
** Usage: %fossil tag SUBCOMMAND ...
**
** Run various subcommands to control tags and properties
**
**     %fossil tag add ?--raw? ?--propagate? TAGNAME CHECK-IN ?VALUE?
**
**         Add a new tag or property to CHECK-IN. The tag will
**         be usable instead of a CHECK-IN in commands such as
**         update and merge.  If the --propagate flag is present,









**         the tag value propages to all descendants of CHECK-IN
**




**     %fossil tag cancel ?--raw? TAGNAME CHECK-IN
**
**         Remove the tag TAGNAME from CHECK-IN, and also remove
**         the propagation of the tag to any descendants.
**
**     %fossil tag find ?--raw? TAGNAME
**
**         List all check-ins that use TAGNAME
**
**     %fossil tag list ?--raw? ?CHECK-IN?
**
**         List all tags, or if CHECK-IN is supplied, list
**         all tags and their values for CHECK-IN.
**
** The option --raw allows the manipulation of all types of tags
** used for various internal purposes in fossil. It also shows
** "cancel" tags for the "find" and "list" subcommands. You should
** not use this option to make changes unless you are sure what
** you are doing.
**
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
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
478
479
480
481
482
483
484
485
486
487
488
489
490

491
492
493
494
495

















496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512


513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532


533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
**   fossil update tag:decaf
**
** 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;
  }
  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 ?--raw? TAGNAME BASELINE ?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 BASELINE ?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 BASELINE");
    }
    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");
    }
    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 tagxref.tagtype > %d"
      "   AND blob.rid=tagxref.rid", &tagname, raw ? -1 : 0

    );
    while( db_step(&q)==SQLITE_ROW ){
      printf("%s\n", db_column_text(&q, 0));
    }
    db_finalize(&q);

















  }else

  if( strncmp(g.argv[2],"list",n)==0 ){
    Stmt q;
    if( g.argc==3 ){
      db_prepare(&q, 
        "SELECT tagname FROM tag"
        " WHERE EXISTS(SELECT 1 FROM tagxref"
        "               WHERE tagid=tag.tagid"
        "                 AND tagtype>%d)"
        " ORDER BY tagname",
        raw ? -1 : 0
      );
      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"
        " WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid"
        "   AND tagtype>%d"
        " ORDER BY tagname",
        rid,
        raw ? -1 : 0
      );
      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 ?BASELINE?");
    }
  }else
  {
    goto tag_cmd_usage;
  }

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

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







|
|
|
<
<










<
<



|

<

|



|
<
|
<
<
<
<
<
<
<
<
<




|

<
|







|
|
|
|
|
|
>
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>









|
|
<


|
|
|
>
>











|




|
|
|
|
>
>

<
|
<




|







<



|

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
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
481

482
483
484
485
486
**   fossil update tag:decaf
**
** will assume that "decaf" is a tag/branch name.
**
*/
void tag_cmd(void){
  int n;
  int fRaw = find_option("raw","",0)!=0;
  int fPropagate = find_option("propagate","",0)!=0;
  const char *zPrefix = fRaw ? "" : "sym-";



  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 ?--raw? ?--propagate? TAGNAME CHECK-IN ?VALUE?");
    }

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

  if( strncmp(g.argv[2],"branch",n)==0 ){
    fossil_fatal("the \"fossil tag branch\" command is discontinued\n"

                 "Use the \"fossil branch new\" command instead.");









  }else

  if( strncmp(g.argv[2],"cancel",n)==0 ){
    if( g.argc!=5 ){
      usage("cancel ?--raw? TAGNAME CHECK-IN");
    }

    tag_add_artifact(zPrefix, 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 ?--raw? TAGNAME");
    }
    if( fRaw ){
      db_prepare(&q,
        "SELECT blob.uuid FROM tagxref, blob"
        " WHERE tagid=(SELECT tagid FROM tag WHERE tagname=%Q)"
        "   AND tagxref.tagtype>0"
        "   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{
      int tagid = db_int(0, "SELECT tagid FROM tag WHERE tagname='sym-%q'",
                         g.argv[3]);
      if( tagid>0 ){
        db_prepare(&q,
          "%s"
          "  AND blob.rid IN ("
                    " SELECT rid FROM tagxref"
                    "  WHERE tagtype>0 AND tagid=%d"
                    ")"
          " ORDER BY event.mtime DESC",
          timeline_query_for_tty(), tagid
        );
        print_timeline(&q, 2000);
        db_finalize(&q);
      }
    }
  }else

  if( strncmp(g.argv[2],"list",n)==0 ){
    Stmt q;
    if( g.argc==3 ){
      db_prepare(&q, 
        "SELECT tagname 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 *zName = db_column_text(&q, 0);
        if( fRaw ){
          printf("%s\n", zName);
        }else if( strncmp(zName, "sym-", 4)==0 ){
          printf("%s\n", &zName[4]);
        }
      }
      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"
        " WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid"
        "   AND tagtype>%d"
        " ORDER BY tagname",
        rid,
        fRaw ? -1 : 0
      );
      while( db_step(&q)==SQLITE_ROW ){
        const char *zName = db_column_text(&q, 0);
        const char *zValue = db_column_text(&q, 1);
        if( fRaw==0 ){
          if( strncmp(zName, "sym-", 4)!=0 ) continue;
          zName += 4;
        }
        if( zValue && zValue[0] ){
          printf("%s=%s\n", zName, zValue);
        }else{

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

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

  /* Cleanup */

  return;

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