Fossil

Changes On Branch deltify-tkt-blobs
Login

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

Changes In Branch deltify-tkt-blobs Excluding Merge-Ins

This is equivalent to a diff from 52648d03 to 53b66cf6

2022-10-28
17:08
Improve correctness, usability and efficiency for the case when values in a TICKET's column tend to be long and volatile.

Owner of a repository may specify one or several TICKET's columns so that delta-compression is tried for the corresponding ticket change artifacts and the corresponding changes on the /tkthistory page are rendered via unified diffs.

See details in the associated wiki. ... (check-in: 872a3b23 user: george tags: trunk)

16:28
Add comments for auxiliary local variables inside ticket_output_change_artifact(). ... (Closed-Leaf check-in: 53b66cf6 user: george tags: deltify-tkt-blobs)
06:51
Typo fix in changes.wiki. ... (check-in: 141793c4 user: stephan tags: deltify-tkt-blobs)
06:37
Merge trunk into deltify-tkt-blobs branch. ... (check-in: 86916df5 user: stephan tags: deltify-tkt-blobs)
2022-10-27
17:56
The check for whether to continue during sync due to outstanding "uvgimme" requests was being skipped in clone -u mode due to misordered tests at the end of the client side of the sync protocol. ... (check-in: 52648d03 user: wyoung tags: trunk)
17:15
Since "fossil uv sync -v" turns on UV trace mode, made "fossil clone -u -v" enable that mode as well, since otherwise there's no way to get into UV trace mode during clone. (e.g. There is no global "--uvtrace" option.) ... (check-in: cdd58b1f user: wyoung tags: trunk)

Changes to src/backlink.c.

130
131
132
133
134
135
136
137

138
139
140
141
142
143
144
130
131
132
133
134
135
136

137
138
139
140
141
142
143
144







-
+







    "  WHEN 2 THEN (SELECT substr(tagname,6) FROM tag"
    "                WHERE tagid=srcid AND tagname GLOB 'wiki-*')"
    "  ELSE null END FROM backlink"
  );
  style_table_sorter();
  @ <table border="1" cellpadding="2" cellspacing="0" \
  @  class='sortable' data-column-types='ttt' data-init-sort='0'>
  @ <thead><tr><th> Source <th> Target <th> mtime </tr></thead>
  @ <thead><tr><th> Target <th> Source <th> mtime </tr></thead>
  @ <tbody>
  while( db_step(&q)==SQLITE_ROW ){
    const char *zTarget = db_column_text(&q, 0);
    int srctype = db_column_int(&q, 1);
    int srcid = db_column_int(&q, 2);
    const char *zMtime = db_column_text(&q, 3);
    @ <tr><td><a href="%R/info/%h(zTarget)">%h(zTarget)</a>

Changes to src/blob.c.

51
52
53
54
55
56
57





58
59
60
61
62
63
64
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69







+
+
+
+
+







#define blob_size(X)  ((X)->nUsed)

/*
** The buffer holding the blob data
*/
#define blob_buffer(X)  ((X)->aData)

/*
** Number of elements that fits into the current blob's size
*/
#define blob_count(X,elType)  (blob_size(X)/sizeof(elType))

/*
** Append blob contents to another
*/
#define blob_appendb(dest, src) \
  blob_append((dest), blob_buffer(src), blob_size(src))

/*
925
926
927
928
929
930
931



















932
933
934
935
936
937
938
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







  int i;
  for(i=0; i<n; i++) blob_zero(&aBlob[i]);
}
void blobarray_reset(Blob *aBlob, int n){
  int i;
  for(i=0; i<n; i++) blob_reset(&aBlob[i]);
}
/*
** Allocate array of n blobs and initialize each element with `empty_blob`
*/
Blob* blobarray_new(int n){
  int i;
  Blob *aBlob = fossil_malloc(sizeof(Blob)*n);
  for(i=0; i<n; i++) aBlob[i] = empty_blob;
  return aBlob;
}
/*
** Free array of n blobs some of which may be empty (have NULL buffer)
*/
void blobarray_delete(Blob *aBlob, int n){
  int i;
  for(i=0; i<n; i++){
    if( blob_buffer(aBlob+i) ) blob_reset(aBlob+i);
  }
  fossil_free(aBlob);
}

/*
** Parse a blob into space-separated tokens.  Store each token in
** an element of the blobarray aToken[].  aToken[] is nToken elements in
** size.  Return the number of tokens seen.
*/
int blob_tokenize(Blob *pIn, Blob *aToken, int nToken){

Changes to src/default.css.

705
706
707
708
709
710
711



712







713
714
715
716
717
718
719
705
706
707
708
709
710
711
712
713
714

715
716
717
718
719
720
721
722
723
724
725
726
727
728







+
+
+
-
+
+
+
+
+
+
+







  font-weight: bold;
}
td.difftxt ins > ins.edit {
  background-color: #c0c0ff;
  text-decoration: none;
  font-weight: bold;
}
body.tkt div.content li > table.udiff {
  margin-left: 1.5em;
  margin-top: 0.5em;

}
body.tkt div.content ol.tkt-changes > li:target > p > span {
  border-bottom: 3px solid gold;
}
body.tkt div.content ol.tkt-changes > li:target > ol {
  border-left: 1px solid gold;
}

span.modpending {
  color: #b03800;
  font-style: italic;
}
pre.th1result {
  white-space: pre-wrap;

Changes to src/info.c.

2781
2782
2783
2784
2785
2786
2787
2788

2789
2790
2791
2792
2793
2794
2795
2781
2782
2783
2784
2785
2786
2787

2788
2789
2790
2791
2792
2793
2794
2795







-
+







  zTktTitle = db_table_has_column("repository", "ticket", "title" )
      ? db_text("(No title)", 
                "SELECT title FROM ticket WHERE tkt_uuid=%Q", zTktName)
      : 0;
  style_set_current_feature("tinfo");
  style_header("Ticket Change Details");
  style_submenu_element("Raw", "%R/artifact/%s", zUuid);
  style_submenu_element("History", "%R/tkthistory/%s", zTktName);
  style_submenu_element("History", "%R/tkthistory/%s#%S", zTktName,zUuid);
  style_submenu_element("Page", "%R/tktview/%t", zTktName);
  style_submenu_element("Timeline", "%R/tkttimeline/%t", zTktName);
  if( P("plaintext") ){
    style_submenu_element("Formatted", "%R/info/%s", zUuid);
  }else{
    style_submenu_element("Plaintext", "%R/info/%s?plaintext", zUuid);
  }
2826
2827
2828
2829
2830
2831
2832
2833

2834
2835
2836
2837
2838
2839
2840
2826
2827
2828
2829
2830
2831
2832

2833
2834
2835
2836
2837
2838
2839
2840







-
+







    @ <input type="submit" value="Submit">
    @ </form>
    @ </blockquote>
  }

  @ <div class="section">Changes</div>
  @ <p>
  ticket_output_change_artifact(pTktChng, 0, 1);
  ticket_output_change_artifact(pTktChng, 0, 1, 0);
  manifest_destroy(pTktChng);
  style_finish_page();
}


/*
** WEBPAGE: info

Changes to src/tkt.c.

28
29
30
31
32
33
34

35
36
37
38
39



40
41
42
43
44
45
46

47
48
49
50
51
52
53
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58







+





+
+
+







+







** use.  The internal-use fields begin with "tkt_".
*/
static int nField = 0;
static struct tktFieldInfo {
  char *zName;             /* Name of the database field */
  char *zValue;            /* Value to store */
  char *zAppend;           /* Value to append */
  char *zBsln;             /* "baseline for $zName" if that field exists*/
  unsigned mUsed;          /* 01: TICKET  02: TICKETCHNG */
} *aField;
#define USEDBY_TICKET      01
#define USEDBY_TICKETCHNG  02
#define USEDBY_BOTH        03
#define JCARD_ASSIGN     ('=')
#define JCARD_APPEND     ('+')
#define JCARD_PRIVATE    ('p')
static u8 haveTicket = 0;        /* True if the TICKET table exists */
static u8 haveTicketCTime = 0;   /* True if TICKET.TKT_CTIME exists */
static u8 haveTicketChng = 0;    /* True if the TICKETCHNG table exists */
static u8 haveTicketChngRid = 0; /* True if TICKETCHNG.TKT_RID exists */
static u8 haveTicketChngUser = 0;/* True if TICKETCHNG.TKT_USER exists */
static u8 useTicketGenMt = 0;    /* use generated TICKET.MIMETYPE */
static u8 useTicketChngGenMt = 0;/* use generated TICKETCHNG.MIMETYPE */
static int nTicketBslns = 0;     /* number of valid "baseline for ..." */


/*
** Compare two entries in aField[] for sorting purposes
*/
static int nameCmpr(const void *a, const void *b){
  return fossil_strcmp(((const struct tktFieldInfo*)a)->zName,
71
72
73
74
75
76
77
78

79
80
81

82
83
84
85
86
87
88






89
90
91
92
93

94
95
96
97
98

















99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

119
120
121
122
123
124
125
76
77
78
79
80
81
82

83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156







-
+



+







+
+
+
+
+
+





+





+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




















+







** in sorted order in aField[].
**
** The haveTicket and haveTicketChng variables are set to 1 if the TICKET and
** TICKETCHANGE tables exist, respectively.
*/
static void getAllTicketFields(void){
  Stmt q;
  int i, noRegularMimetype;
  int i, noRegularMimetype, nBaselines;
  static int once = 0;
  if( once ) return;
  once = 1;
  nBaselines = 0;
  db_prepare(&q, "PRAGMA table_info(ticket)");
  while( db_step(&q)==SQLITE_ROW ){
    const char *zFieldName = db_column_text(&q, 1);
    haveTicket = 1;
    if( memcmp(zFieldName,"tkt_",4)==0 ){
      if( strcmp(zFieldName, "tkt_ctime")==0 ) haveTicketCTime = 1;
      continue;
    }
    if( memcmp(zFieldName,"baseline for ",13)==0 ){
      if( strcmp(db_column_text(&q,2),"INTEGER")==0 ){
        nBaselines++;
      }
      continue;
    }
    if( strchr(zFieldName,' ')!=0 ) continue;
    if( nField%10==0 ){
      aField = fossil_realloc(aField, sizeof(aField[0])*(nField+10) );
    }
    aField[nField].zBsln = 0;
    aField[nField].zName = mprintf("%s", zFieldName);
    aField[nField].mUsed = USEDBY_TICKET;
    nField++;
  }
  db_finalize(&q);
  if( nBaselines ){
    db_prepare(&q, "SELECT 1 FROM pragma_table_info('ticket') "
                   "WHERE type = 'INTEGER' AND name = :n");
    for(i=0; i<nField && nBaselines!=0; i++){
      char *zBsln = mprintf("baseline for %s",aField[i].zName);
      db_bind_text(&q, ":n", zBsln);
      if( db_step(&q)==SQLITE_ROW ){
        aField[i].zBsln = zBsln;
        nTicketBslns++;
        nBaselines--;
      }else{
        free(zBsln);
      }
      db_reset(&q);
    }
    db_finalize(&q);
  }
  db_prepare(&q, "PRAGMA table_info(ticketchng)");
  while( db_step(&q)==SQLITE_ROW ){
    const char *zFieldName = db_column_text(&q, 1);
    haveTicketChng = 1;
    if( memcmp(zFieldName,"tkt_",4)==0 ){
      if( strcmp(zFieldName+4,"rid")==0 ){
        haveTicketChngRid = 1;  /* tkt_rid */
      }else if( strcmp(zFieldName+4,"user")==0 ){
        haveTicketChngUser = 1; /* tkt_user */
      }
      continue;
    }
    if( strchr(zFieldName,' ')!=0 ) continue;
    if( (i = fieldId(zFieldName))>=0 ){
      aField[i].mUsed |= USEDBY_TICKETCHNG;
      continue;
    }
    if( nField%10==0 ){
      aField = fossil_realloc(aField, sizeof(aField[0])*(nField+10) );
    }
    aField[nField].zBsln = 0;
    aField[nField].zName = mprintf("%s", zFieldName);
    aField[nField].mUsed = USEDBY_TICKETCHNG;
    nField++;
  }
  db_finalize(&q);
  qsort(aField, nField, sizeof(aField[0]), nameCmpr);
  noRegularMimetype = 1;
199
200
201
202
203
204
205










206
207
208
209
210
211
212







213
214
215
216


217
218
219
220
221
222
223
224
225
226
227
228
229
230
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
230
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







+
+
+
+
+
+
+
+
+
+







+
+
+
+
+
+
+



-
+
+




















-
+
-










+


+
+
+







  const char *z;

  for(i=0; (z = cgi_parameter_name(i))!=0; i++){
    Th_Store(z, P(z));
  }
}

/*
** Information about a single J-card
*/
struct jCardInfo {
  char  *zValue;
  int    mimetype;
  int    rid;
  double mtime;
};

/*
** Update an entry of the TICKET and TICKETCHNG tables according to the
** information in the ticket artifact given in p.  Attempt to create
** the appropriate TICKET table entry if tktid is zero.  If tktid is nonzero
** then it will be the ROWID of an existing TICKET entry.
**
** Parameter rid is the recordID for the ticket artifact in the BLOB table.
** Upon assignment of a field this rid is stored into a corresponding
** zBsln integer column (provided that it is defined within TICKET table).
**
** If a field is USEDBY_TICKETCHNG table then back-references within it
** are extracted and inserted into the BACKLINK table; otherwise
** a corresponding blob in the `fields` array is updated so that the
** caller could extract backlinks from the most recent field's values.
**
** Return the new rowid of the TICKET table entry.
*/
static int ticket_insert(const Manifest *p, const int rid, int tktid){
static int ticket_insert(const Manifest *p, const int rid, int tktid,
                         Blob *fields){
  Blob sql1; /* update or replace TICKET ... */
  Blob sql2; /* list of TICKETCHNG's fields that are in the manifest */
  Blob sql3; /* list of values which correspond to the previous list */
  Stmt q;
  int i, j;
  char *aUsed;
  int mimetype_tkt = MT_NONE, mimetype_tktchng = MT_NONE;

  if( tktid==0 ){
    db_multi_exec("INSERT INTO ticket(tkt_uuid, tkt_mtime) "
                  "VALUES(%Q, 0)", p->zTicketUuid);
    tktid = db_last_insert_rowid();
  }
  blob_zero(&sql1);
  blob_zero(&sql2);
  blob_zero(&sql3);
  blob_append_sql(&sql1, "UPDATE OR REPLACE ticket SET tkt_mtime=:mtime");
  if( haveTicketCTime ){
    blob_append_sql(&sql1, ", tkt_ctime=coalesce(tkt_ctime,:mtime)");
  }
  aUsed = fossil_malloc( nField );
  aUsed = fossil_malloc_zero( nField );
  memset(aUsed, 0, nField);
  for(i=0; i<p->nField; i++){
    const char * const zName = p->aField[i].zName;
    const char * const zBaseName = zName[0]=='+' ? zName+1 : zName;
    j = fieldId(zBaseName);
    if( j<0 ) continue;
    aUsed[j] = 1;
    if( aField[j].mUsed & USEDBY_TICKET ){
      if( zName[0]=='+' ){
        blob_append_sql(&sql1,", \"%w\"=coalesce(\"%w\",'') || %Q",
                        zBaseName, zBaseName, p->aField[i].zValue);
        /* when appending keep "baseline for ..." unchanged */
      }else{
        blob_append_sql(&sql1,", \"%w\"=%Q", zBaseName, p->aField[i].zValue);
        if( aField[j].zBsln ){
          blob_append_sql(&sql1,", \"%w\"=%d", aField[j].zBsln, rid);
        }
      }
    }
    if( aField[j].mUsed & USEDBY_TICKETCHNG ){
      blob_append_sql(&sql2, ",\"%w\"", zBaseName);
      blob_append_sql(&sql3, ",%Q", p->aField[i].zValue);
    }
    if( strcmp(zBaseName,"mimetype")==0 ){
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
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







-






-
+
+
+
+

+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
-
+
+
+







    }
    db_finalize(&q);
  }
  blob_reset(&sql2);
  blob_reset(&sql3);
  fossil_free(aUsed);
  if( rid>0 ){                   /* extract backlinks */
    int bReplace = 1, mimetype;
    for(i=0; i<p->nField; i++){
      const char *zName = p->aField[i].zName;
      const char *zBaseName = zName[0]=='+' ? zName+1 : zName;
      j = fieldId(zBaseName);
      if( j<0 ) continue;
      if( aField[j].mUsed & USEDBY_TICKETCHNG ){
        mimetype = mimetype_tktchng;
        backlink_extract(p->aField[i].zValue, mimetype_tktchng,
                         rid, BKLNK_TICKET, p->rDate,
                          /* existing backlinks must have been
                           * already deleted by the caller */ 0 );
      }else{
        /* update field's data with the most recent values */
        Blob *cards = fields + j;
        struct jCardInfo card = {
          fossil_strdup(p->aField[i].zValue),
        mimetype = mimetype_tkt;
      }
      backlink_extract(p->aField[i].zValue, mimetype, rid, BKLNK_TICKET,
                       p->rDate, bReplace);
          mimetype_tkt, rid, p->rDate
        };
        if( blob_size(cards) && zName[0]!='+' ){
          struct jCardInfo *x = (struct jCardInfo *)blob_buffer(cards);
          struct jCardInfo *end = x + blob_count(cards,struct jCardInfo);
          for(; x!=end; x++){
            fossil_free( x->zValue );
          }
          blob_truncate(cards,0);
      bReplace = 0;
        }
        blob_append(cards, (const char*)(&card), sizeof(card));
      }
    }
  }
  return tktid;
}

/*
** Returns non-zero if moderation is required for ticket changes and ticket
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
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







-
+

+











+
+
+





-
+






+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







** Rebuild an entire entry in the TICKET table
*/
void ticket_rebuild_entry(const char *zTktUuid){
  char *zTag = mprintf("tkt-%s", zTktUuid);
  int tagid = tag_findid(zTag, 1);
  Stmt q;
  Manifest *pTicket;
  int tktid;
  int tktid, i;
  int createFlag = 1;
  Blob *fields;  /* array of blobs; each blob holds array of jCardInfo */

  fossil_free(zTag);
  getAllTicketFields();
  if( haveTicket==0 ) return;
  tktid = db_int(0, "SELECT tkt_id FROM ticket WHERE tkt_uuid=%Q", zTktUuid);
  search_doc_touch('t', tktid, 0);
  if( haveTicketChng ){
    db_multi_exec("DELETE FROM ticketchng WHERE tkt_id=%d;", tktid);
  }
  db_multi_exec("DELETE FROM ticket WHERE tkt_id=%d", tktid);
  tktid = 0;
  fields = blobarray_new( nField );
  db_multi_exec("DELETE FROM backlink WHERE srctype=%d AND srcid IN "
                "(SELECT rid FROM tagxref WHERE tagid=%d)",BKLNK_TICKET, tagid);
  db_prepare(&q, "SELECT rid FROM tagxref WHERE tagid=%d ORDER BY mtime",tagid);
  while( db_step(&q)==SQLITE_ROW ){
    int rid = db_column_int(&q, 0);
    pTicket = manifest_get(rid, CFTYPE_TICKET, 0);
    if( pTicket ){
      tktid = ticket_insert(pTicket, rid, tktid);
      tktid = ticket_insert(pTicket, rid, tktid, fields);
      manifest_ticket_event(rid, pTicket, createFlag, tagid);
      manifest_destroy(pTicket);
    }
    createFlag = 0;
  }
  db_finalize(&q);
  /* Extract backlinks from the most recent values of TICKET fields */
  for(i=0; i<nField; i++){
    Blob *cards = fields + i;
    if( blob_size(cards) ){
      struct jCardInfo *x = (struct jCardInfo *)blob_buffer(cards);
      struct jCardInfo *end = x + blob_count(cards,struct jCardInfo);
      for(; x!=end; x++){
        assert( x->zValue );
        backlink_extract(x->zValue,x->mimetype,
                         x->rid,BKLNK_TICKET,x->mtime,0);
        fossil_free( x->zValue );
      }
    }
    blob_truncate(cards,0);
  }
  blobarray_delete(fields,nField);
}


/*
** Create the TH1 interpreter and load the "common" code.
*/
void ticket_init(void){
736
737
738
739
740
741
742


743
744
745
746

747
748
749
750
751
752
753
754
755















756
757
758
759
760
761
762
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865







+
+




+









+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







  }
  aField[idx].zAppend = mprintf("%.*s", argl[2], argv[2]);
  return TH_OK;
}

/*
** Write a ticket into the repository.
** Upon reassignment of fields try to delta-compress an artifact against
** all artifacts that are referenced in the corresponding zBsln fields.
*/
static int ticket_put(
  Blob *pTicket,           /* The text of the ticket change record */
  const char *zTktId,      /* The ticket to which this change is applied */
  const char *aUsed,       /* Indicators for fields' modifications */
  int needMod              /* True if moderation is needed */
){
  int result;
  int rid;
  manifest_crosslink_begin();
  rid = content_put_ex(pTicket, 0, 0, 0, needMod);
  if( rid==0 ){
    fossil_fatal("trouble committing ticket: %s", g.zErrMsg);
  }
  if( nTicketBslns ){
    int i, s, buf[8], nSrc=0, *aSrc=&(buf[0]);
    if( nTicketBslns > count(buf) ){
      aSrc = (int*)fossil_malloc(sizeof(int)*nTicketBslns);
    }
    for(i=0; i<nField; i++){
      if( aField[i].zBsln && aUsed[i]==JCARD_ASSIGN ){
        s = db_int(0,"SELECT \"%w\" FROM ticket WHERE tkt_uuid = '%q'",
                      aField[i].zBsln, zTktId );
        if( s > 0 ) aSrc[nSrc++] = s;
      }
    }
    if( nSrc ) content_deltify(rid, aSrc, nSrc, 0);
    if( aSrc!=&(buf[0]) ) fossil_free( aSrc );
  }
  if( needMod ){
    moderation_table_create();
    db_multi_exec(
      "INSERT INTO modreq(objid, tktid) VALUES(%d,%Q)",
      rid, zTktId
    );
  }else{
785
786
787
788
789
790
791
792

793
794
795

796
797
798
799
800
801
802
803
804
805
806
807
808

809
810
811
812
813

814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829

830
831

832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851

852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870


871


872

873
874
875
876
877
878
879
888
889
890
891
892
893
894

895
896
897

898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957

958
959
960
961
962
963
964
965
966
967
968
969

970
971
972
973
974
975

976
977
978
979
980

981
982
983
984
985
986
987
988







-
+


-
+













+





+
















+


+



















-
+











-






-
+
+

+
+
-
+







static int submitTicketCmd(
  Th_Interp *interp,
  void *pUuid,
  int argc,
  const char **argv,
  int *argl
){
  char *zDate;
  char *zDate, *aUsed;
  const char *zUuid;
  int i;
  int nJ = 0;
  int nJ = 0, rc = TH_OK;
  Blob tktchng, cksum;
  int needMod;

  login_verify_csrf_secret();
  if( !captcha_is_correct(0) ){
    @ <p class="generalError">Error: Incorrect security code.</p>
    return TH_OK;
  }
  zUuid = (const char *)pUuid;
  blob_zero(&tktchng);
  zDate = date_in_standard_format("now");
  blob_appendf(&tktchng, "D %s\n", zDate);
  free(zDate);
  aUsed = fossil_malloc_zero( nField );
  for(i=0; i<nField; i++){
    if( aField[i].zAppend ){
      blob_appendf(&tktchng, "J +%s %z\n", aField[i].zName,
                   fossilize(aField[i].zAppend, -1));
      ++nJ;
      aUsed[i] = JCARD_APPEND;
    }
  }
  for(i=0; i<nField; i++){
    const char *zValue;
    int nValue;
    if( aField[i].zAppend ) continue;
    zValue = Th_Fetch(aField[i].zName, &nValue);
    if( zValue ){
      while( nValue>0 && fossil_isspace(zValue[nValue-1]) ){ nValue--; }
      if( ((aField[i].mUsed & USEDBY_TICKETCHNG)!=0 && nValue>0)
       || memcmp(zValue, aField[i].zValue, nValue)!=0
       || strlen(aField[i].zValue)!=nValue
      ){
        if( memcmp(aField[i].zName, "private_", 8)==0 ){
          zValue = db_conceal(zValue, nValue);
          blob_appendf(&tktchng, "J %s %s\n", aField[i].zName, zValue);
          aUsed[i] = JCARD_PRIVATE;
        }else{
          blob_appendf(&tktchng, "J %s %#F\n", aField[i].zName, nValue, zValue);
          aUsed[i] = JCARD_ASSIGN;
        }
        nJ++;
      }
    }
  }
  if( *(char**)pUuid ){
    zUuid = db_text(0,
       "SELECT tkt_uuid FROM ticket WHERE tkt_uuid GLOB '%q*'", P("name")
    );
  }else{
    zUuid = db_text(0, "SELECT lower(hex(randomblob(20)))");
  }
  *(const char**)pUuid = zUuid;
  blob_appendf(&tktchng, "K %s\n", zUuid);
  blob_appendf(&tktchng, "U %F\n", login_name());
  md5sum_blob(&tktchng, &cksum);
  blob_appendf(&tktchng, "Z %b\n", &cksum);
  if( nJ==0 ){
    blob_reset(&tktchng);
    return TH_OK;
    goto finish;
  }
  needMod = ticket_need_moderation(0);
  if( g.zPath[0]=='d' ){
    const char *zNeedMod = needMod ? "required" : "skipped";
    /* If called from /debug_tktnew or /debug_tktedit... */
    @ <div style="color:blue">
    @ <p>Ticket artifact that would have been submitted:</p>
    @ <blockquote><pre>%h(blob_str(&tktchng))</pre></blockquote>
    @ <blockquote><pre>Moderation would be %h(zNeedMod).</pre></blockquote>
    @ </div>
    @ <hr />
    return TH_OK;
  }else{
    if( g.thTrace ){
      Th_Trace("submit_ticket {\n<blockquote><pre>\n%h\n</pre></blockquote>\n"
               "}<br />\n",
         blob_str(&tktchng));
    }
    ticket_put(&tktchng, zUuid, needMod);
    ticket_put(&tktchng, zUuid, aUsed, needMod);
    rc = ticket_change(zUuid);
  }
  finish:
    fossil_free( aUsed );
  return ticket_change(zUuid);
    return rc;
}


/*
** WEBPAGE: tktnew
** WEBPAGE: debug_tktnew
**
1139
1140
1141
1142
1143
1144
1145



1146
1147
1148
1149
1150
1151
1152

1153
1154
1155
1156
1157
1158
1159
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272







+
+
+







+







** another way) show a list of artifacts associated with a single ticket.
**
** By default, the artifacts are decoded and formatted.  Text fields
** are formatted as text/plain, since in the general case Fossil does
** not have knowledge of the encoding.  If the "raw" query parameter
** is present, then the undecoded and unformatted text of each artifact
** is displayed.
**
** Reassignments of a field of the TICKET table that has a corresponding
** "baseline for ..." companion are rendered as unified diffs.
*/
void tkthistory_page(void){
  Stmt q;
  char *zTitle;
  const char *zUuid;
  int tagid;
  int nChng = 0;
  Blob *aLastVal = 0; /* holds the last rendered value for each field */

  login_check_credentials();
  if( !g.perm.Hyperlink || !g.perm.RdTkt ){
    login_needed(g.anon.Hyperlink && g.anon.RdTkt);
    return;
  }
  zUuid = PD("name","");
1175
1176
1177
1178
1179
1180
1181




1182
1183
1184
1185
1186
1187
1188
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305







+
+
+
+







    style_finish_page();
    return;
  }
  if( P("raw")!=0 ){
    @ <h2>Raw Artifacts Associated With Ticket %h(zUuid)</h2>
  }else{
    @ <h2>Artifacts Associated With Ticket %h(zUuid)</h2>
    getAllTicketFields();
    if( nTicketBslns ){
      aLastVal = blobarray_new(nField);
    }
  }
  db_prepare(&q,
    "SELECT datetime(mtime,toLocal()), objid, uuid, NULL, NULL, NULL"
    "  FROM event, blob"
    " WHERE objid IN (SELECT rid FROM tagxref WHERE tagid=%d)"
    "   AND blob.rid=event.objid"
    " UNION "
1196
1197
1198
1199
1200
1201
1202
1203

1204
1205
1206
1207
1208
1209
1210




1211
1212
1213

1214
1215
1216

1217
1218
1219
1220
1221
1222
1223
1224
1225


1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238

1239
1240
1241
1242

1243
1244
1245
1246
1247
1248

1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265



1266
1267
1268
1269
1270


1271
1272
1273
1274
1275
1276
1277
1278
1279
1280

1281
1282
1283










1284
1285
1286
1287
1288
1289
1290
1291
1292

1293
























1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
























1304
1305
1306
1307
1308
1309
1310
1313
1314
1315
1316
1317
1318
1319

1320
1321
1322
1323
1324



1325
1326
1327
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
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445










1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476







-
+




-
-
-
+
+
+
+

-
-
+


-
+







-
-
+
+












-
+




+






+

















+
+
+




-
+
+






-
-
-
-
+
-
-
-
+
+
+
+
+
+
+
+
+
+









+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







  for(nChng=0; db_step(&q)==SQLITE_ROW; nChng++){
    Manifest *pTicket;
    const char *zDate = db_column_text(&q, 0);
    int rid = db_column_int(&q, 1);
    const char *zChngUuid = db_column_text(&q, 2);
    const char *zFile = db_column_text(&q, 4);
    if( nChng==0 ){
      @ <ol>
      @ <ol class="tkt-changes">
    }
    if( zFile!=0 ){
      const char *zSrc = db_column_text(&q, 3);
      const char *zUser = db_column_text(&q, 5);
      if( zSrc==0 || zSrc[0]==0 ){
        @
        @ <li><p>Delete attachment "%h(zFile)"
      @
      @ <li id="%S(zChngUuid)"><p><span>
      if( zSrc==0 || zSrc[0]==0 ){
        @ Delete attachment "%h(zFile)"
      }else{
        @
        @ <li><p>Add attachment
        @ Add attachment
        @ "%z(href("%R/artifact/%!S",zSrc))%s(zFile)</a>"
      }
      @ [%z(href("%R/artifact/%!S",zChngUuid))%S(zChngUuid)</a>]
      @ [%z(href("%R/artifact/%!S",zChngUuid))%S(zChngUuid)</a>]</span>
      @ (rid %d(rid)) by
      hyperlink_to_user(zUser,zDate," on");
      hyperlink_to_date(zDate, ".</p>");
    }else{
      pTicket = manifest_get(rid, CFTYPE_TICKET, 0);
      if( pTicket ){
        @
        @ <li><p>Ticket change
        @ [%z(href("%R/artifact/%!S",zChngUuid))%S(zChngUuid)</a>]
        @ <li id="%S(zChngUuid)"><p><span>Ticket change
        @ [%z(href("%R/artifact/%!S",zChngUuid))%S(zChngUuid)</a>]</span>
        @ (rid %d(rid)) by
        hyperlink_to_user(pTicket->zUser,zDate," on");
        hyperlink_to_date(zDate, ":");
        @ </p>
        if( P("raw")!=0 ){
          Blob c;
          content_get(rid, &c);
          @ <blockquote><pre>
          @ %h(blob_str(&c))
          @ </pre></blockquote>
          blob_reset(&c);
        }else{
          ticket_output_change_artifact(pTicket, "a", nChng);
          ticket_output_change_artifact(pTicket, "a", nChng, aLastVal);
        }
      }
      manifest_destroy(pTicket);
    }
    @ </li>
  }
  db_finalize(&q);
  if( nChng ){
    @ </ol>
  }
  style_finish_page();
  if( aLastVal ) blobarray_delete(aLastVal, nField);
}

/*
** Return TRUE if the given BLOB contains a newline character.
*/
static int contains_newline(Blob *p){
  const char *z = blob_str(p);
  while( *z ){
    if( *z=='\n' ) return 1;
    z++;
  }
  return 0;
}

/*
** The pTkt object is a ticket change artifact.  Output a detailed
** description of this object.
**
** If `aLastVal` is not NULL then render selected fields as unified diffs
** and update corresponding elements of that array with values from `pTkt`.
*/
void ticket_output_change_artifact(
  Manifest *pTkt,           /* Parsed artifact for the ticket change */
  const char *zListType,    /* Which type of list */
  int n                     /* Which ticket change is this */
  int n,                    /* Which ticket change is this */
  Blob *aLastVal            /* Array of the latest values for the diffs */
){
  int i;
  if( zListType==0 ) zListType = "1";
  getAllTicketFields();
  @ <ol type="%s(zListType)">
  for(i=0; i<pTkt->nField; i++){
    Blob val;
    const char *z, *zX;
    int id;
    z = pTkt->aField[i].zName;
    const char *z  = pTkt->aField[i].zName;
    blob_set(&val, pTkt->aField[i].zValue);
    zX = z[0]=='+' ? z+1 : z;
    id = fieldId(zX);
    const char *zX = z[0]=='+' ? z+1 : z;
    const int id = fieldId(zX);
    const char  *zValue = pTkt->aField[i].zValue;
    const size_t nValue = strlen(zValue);
    const int bLong = nValue>50 || memchr(zValue,'\n',nValue)!=NULL;
                      /* zValue is long enough to justify a <blockquote> */
    const int bCanDiff = aLastVal && id>=0 && aField[id].zBsln;
                      /* preliminary flag for rendering via unified diff */
    int bAppend = 0;  /* zValue is being appended to a TICKET's field */
    int bRegular = 0; /* prev value of a TICKET's field is being superseded*/
    @ <li>\
    if( id<0 ){
      @ Untracked field %h(zX):
    }else if( aField[id].mUsed==USEDBY_TICKETCHNG ){
      @ %h(zX):
    }else if( n==0 ){
      @ %h(zX) initialized to:
    }else if( z[0]=='+' && (aField[id].mUsed&USEDBY_TICKET)!=0 ){
      @ Appended to %h(zX):
      bAppend = 1;
    }else{
      if( !bCanDiff ){
        @ %h(zX) changed to: \
      }
      bRegular = 1;
    }
    if( bCanDiff ){
      Blob *prev = aLastVal+id;
      Blob val = BLOB_INITIALIZER;
      if( nValue ){
        blob_init(&val, zValue, nValue+1);
        val.nUsed--;  /* makes blob_str() faster */
      }
      if( bRegular && nValue && blob_buffer(prev) && blob_size(prev) ){
        Blob d = BLOB_INITIALIZER;
        DiffConfig DCfg;
        construct_diff_flags(1, &DCfg);
        DCfg.diffFlags |= DIFF_HTML | DIFF_LINENO;
        text_diff(prev, &val, &d, &DCfg);
        @ %h(zX) changed as:
        @ %s(blob_str(&d))
        @ </li>
        blob_reset(&d);
      }else{
        if( bRegular ){
      @ %h(zX) changed to:
    }
    if( blob_size(&val)>50 || contains_newline(&val) ){
      @ <blockquote><pre class='verbatim'>
      @ %h(blob_str(&val))
      @ </pre></blockquote></li>
    }else{
      @ "%h(blob_str(&val))"</li>
    }
    blob_reset(&val);
          @ %h(zX) changed to:
        }
        if( bLong ){
          @ <blockquote><pre class='verbatim'>
          @ %h(zValue)
          @ </pre></blockquote></li>
        }else{
          @ "%h(zValue)"</li>
        }
      }
      if( blob_buffer(prev) && blob_size(prev) && !bAppend ){
        blob_truncate(prev,0);
      }
      if( nValue ) blob_appendb(prev, &val);
      blob_reset(&val);
    }else{
      if( bLong ){
        @ <blockquote><pre class='verbatim'>
        @ %h(zValue)
        @ </pre></blockquote></li>
      }else{
        @ "%h(zValue)"</li>
      }
    }
  }
  @ </ol>
}

/*
** COMMAND: ticket*
**
1458
1459
1460
1461
1462
1463
1464

1465
1466
1467
1468
1469
1470
1471
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638







+







        rptshow( zRep, zSep, zFilterUuid, tktEncoding );
      }
    }else{
      /* add a new ticket or update an existing ticket */
      enum { set,add,history,err } eCmd = err;
      int i = 0;
      Blob tktchng, cksum;
      char *aUsed;

      /* get command type (set/add) and get uuid, if needed for set */
      if( strncmp(g.argv[2],"set",n)==0 || strncmp(g.argv[2],"change",n)==0 ||
         strncmp(g.argv[2],"history",n)==0 ){
        if( strncmp(g.argv[2],"history",n)==0 ){
          eCmd = history;
        }else{
1600
1601
1602
1603
1604
1605
1606

1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619

1620
1621
1622

1623
1624
1625
1626
1627
1628

1629
1630
1631
1632
1633
1634
1635
1636
1637
1638


1639
1640
1641
1642
1643

1644
1645
1646
1647
1648
1649
1650
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808

1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823







+













+



+






+









-
+
+





+







          if( append ){
            aField[j].zAppend = zFValue;
          }else{
            aField[j].zValue = zFValue;
          }
        }
      }
      aUsed = fossil_malloc_zero( nField );

      /* now add the needed artifacts to the repository */
      blob_zero(&tktchng);
      /* add the time to the ticket manifest */
      blob_appendf(&tktchng, "D %s\n", zDate);
      /* append defined elements */
      for(i=0; i<nField; i++){
        char *zValue = 0;
        char *zPfx;

        if( aField[i].zAppend && aField[i].zAppend[0] ){
          zPfx = " +";
          zValue = aField[i].zAppend;
          aUsed[i] = JCARD_APPEND;
        }else if( aField[i].zValue && aField[i].zValue[0] ){
          zPfx = " ";
          zValue = aField[i].zValue;
          aUsed[i] = JCARD_ASSIGN;
        }else{
          continue;
        }
        if( memcmp(aField[i].zName, "private_", 8)==0 ){
          zValue = db_conceal(zValue, strlen(zValue));
          blob_appendf(&tktchng, "J%s%s %s\n", zPfx, aField[i].zName, zValue);
          aUsed[i] = JCARD_PRIVATE;
        }else{
          blob_appendf(&tktchng, "J%s%s %#F\n", zPfx,
                       aField[i].zName, strlen(zValue), zValue);
        }
      }
      blob_appendf(&tktchng, "K %s\n", zTktUuid);
      blob_appendf(&tktchng, "U %F\n", zUser);
      md5sum_blob(&tktchng, &cksum);
      blob_appendf(&tktchng, "Z %b\n", &cksum);
      if( ticket_put(&tktchng, zTktUuid, ticket_need_moderation(1))==0 ){
      if( ticket_put(&tktchng, zTktUuid, aUsed,
                      ticket_need_moderation(1) )==0 ){
        fossil_fatal("%s", g.zErrMsg);
      }else{
        fossil_print("ticket %s succeeded for %s\n",
             (eCmd==set?"set":"add"),zTktUuid);
      }
      fossil_free( aUsed );
    }
  }
}


#if INTERFACE
/* Standard submenu items for wiki pages */

Changes to src/wiki.c.

1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1865
1866
1867
1868
1869
1870
1871

1872

1873
1874
1875
1876
1877
1878
1879







-

-







  }
  style_set_current_feature("wiki");
  style_header("Changes To %s", pW1->zWikiTitle);
  blob_zero(&d);
  construct_diff_flags(1, &DCfg);
  DCfg.diffFlags |= DIFF_HTML | DIFF_LINENO;
  text_diff(&w2, &w1, &d, &DCfg);
  @ <pre class="udiff">
  @ %s(blob_str(&d))
  @ <pre>
  manifest_destroy(pW1);
  manifest_destroy(pW2);
  style_finish_page();
}

/*
** A query that returns information about all wiki pages.

Changes to www/changes.wiki.

12
13
14
15
16
17
18



19
20
21
22
23
24
25
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28







+
+
+







  *  Replace the <tt>--dryrun</tt> flag with <tt>--dry-run</tt> in all
     commands which still used the former name, for consistency.
  *  Rebuilt [/file/Dockerfile | the stock Dockerfile] to create a "from scratch"
     Busybox based container image via an Alpine Linux intermediary
  *  Added [/doc/trunk/www/containers.md | a new document] describing how to
     customize, use, and run that container.
  *  Added "by hour of day" report to [/reports?view=byhour|the /reports page].
  *  Improved correctness, usability, and efficiency for the case
     [/timeline?r=deltify-tkt-blobs|when values in a TICKET's column
     tend to be long and volatile].

<h2 id='v2_19'>Changes for version 2.19 (2022-07-21)</h2>
  *  On file listing pages, sort filenames using the "uintnocase" collating
     sequence, so that filenames that contains embedded integers sort in
     numeric order even if they contain a different number of digits.
     (Example:  "fossil_80_..." comes before "fossil_100.png" in the
     [/dir?ci=92fd091703a28c07&name=skins/blitz|/skins/blitz] directory listing.)