Changes On Branch annotate_links
Not logged in

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

Changes In Branch annotate_links Excluding Merge-Ins

This is equivalent to a diff from 67f787dc4e to 96c3133576

2013-02-15
14:37
Fixing annotate. It was hanging. Leaf check-in: 96c3133576 user: viriketo tags: annotate_links
2013-02-13
11:31
Add a draft document describing the ticket tables and how they are generated from ticket change artifacts. check-in: d5be709c20 user: drh tags: trunk
03:14
Improvements to the UTF-16 BOM detection. check-in: 81c4d78137 user: mistachkin tags: utf16Bom
2013-02-12
20:17
Picking recent trunk fixes on tickets. check-in: 7a8ed6d7df user: viriketo tags: annotate_links
19:23
Revised ticket processing to align with coding style guide, and for clarity of presentation. check-in: 67f787dc4e user: drh tags: trunk
19:09
Fixing the rebuild of the ticket databases, so they get properly the comments included by manifests' "+comment".    drh says not to be able to reproduce this issue, but here is a fix that makes all work for me.    Feel free to rewrite this patch to match your taste. check-in: 9cca9398ab user: viriketo tags: trunk

Changes to src/checkin.c.

97
98
99
100
101
102
103



104
105
106
107
108
109
110
111
112
....
1209
1210
1211
1212
1213
1214
1215

1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
    }else if( isRenamed ){
      blob_appendf(report, "RENAMED    %s\n", zDisplayName);
    }
    free(zFullName);
  }
  blob_reset(&rewrittenPathname);
  db_finalize(&q);



  db_prepare(&q, "SELECT uuid, id FROM vmerge JOIN blob ON merge=rid"
                 " WHERE id<=0");
  while( db_step(&q)==SQLITE_ROW ){
    const char *zLabel = "MERGED_WITH";
    switch( db_column_int(&q, 1) ){
      case -1:  zLabel = "CHERRYPICK ";  break;
      case -2:  zLabel = "BACKOUT    ";  break;
    }
    blob_append(report, zPrefix, nPrefix);
................................................................................
  */
  if ( select_commit_files() ){
    blob_zero(&ans);
    prompt_user("continue (y/N)? ", &ans);
    cReply = blob_str(&ans)[0];
    if( cReply!='y' && cReply!='Y' ) fossil_exit(1);;
  }

  isAMerge = db_exists("SELECT 1 FROM vmerge WHERE id=0");
  if( g.aCommitFile && isAMerge ){
    fossil_fatal("cannot do a partial commit of a merge");
  }

  /* Doing "fossil mv fileA fileB; fossil add fileA; fossil commit fileA"
  ** will generate a manifest that has two fileA entries, which is illegal.
  ** When you think about it, the sequence above makes no sense.  So detect
  ** it and disallow it.  Ticket [0ff64b0a5fc8].
  */






>
>
>

|







 







>


|







97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
....
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
    }else if( isRenamed ){
      blob_appendf(report, "RENAMED    %s\n", zDisplayName);
    }
    free(zFullName);
  }
  blob_reset(&rewrittenPathname);
  db_finalize(&q);
  /* -3 holds the baseline-based merges - nor cherrypick nor backout.
   * Now we can't report easily the baseline-based merges, because
   * we don't store the baseline point in vmerge */
  db_prepare(&q, "SELECT uuid, id FROM vmerge JOIN blob ON merge=rid"
                 " WHERE id<=0 AND id >= -2");
  while( db_step(&q)==SQLITE_ROW ){
    const char *zLabel = "MERGED_WITH";
    switch( db_column_int(&q, 1) ){
      case -1:  zLabel = "CHERRYPICK ";  break;
      case -2:  zLabel = "BACKOUT    ";  break;
    }
    blob_append(report, zPrefix, nPrefix);
................................................................................
  */
  if ( select_commit_files() ){
    blob_zero(&ans);
    prompt_user("continue (y/N)? ", &ans);
    cReply = blob_str(&ans)[0];
    if( cReply!='y' && cReply!='Y' ) fossil_exit(1);;
  }
  /* id=0 means that it introduces a new parent */
  isAMerge = db_exists("SELECT 1 FROM vmerge WHERE id=0");
  if( g.aCommitFile && isAMerge ){
    fossil_fatal("cannot do a partial commit of a graph merge");
  }

  /* Doing "fossil mv fileA fileB; fossil add fileA; fossil commit fileA"
  ** will generate a manifest that has two fileA entries, which is illegal.
  ** When you think about it, the sequence above makes no sense.  So detect
  ** it and disallow it.  Ticket [0ff64b0a5fc8].
  */

Changes to src/db.c.

2068
2069
2070
2071
2072
2073
2074

2075
2076
2077
2078
2079
2080
2081
  { "editor",        0,               32, 0, ""                    },
  { "empty-dirs",    0,               40, 1, ""                    },
  { "encoding-glob",  0,              40, 1, ""                    },
  { "gdiff-command", 0,               40, 0, "gdiff"               },
  { "gmerge-command",0,               40, 0, ""                    },
  { "http-port",     0,               16, 0, "8080"                },
  { "https-login",   0,                0, 0, "off"                 },

  { "ignore-glob",   0,               40, 1, ""                    },
  { "localauth",     0,                0, 0, "off"                 },
  { "main-branch",   0,               40, 0, "trunk"               },
  { "manifest",      0,                0, 1, "off"                 },
#ifdef FOSSIL_ENABLE_MARKDOWN
  { "markdown",      0,                0, 0, "off"                 },
#endif






>







2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
  { "editor",        0,               32, 0, ""                    },
  { "empty-dirs",    0,               40, 1, ""                    },
  { "encoding-glob",  0,              40, 1, ""                    },
  { "gdiff-command", 0,               40, 0, "gdiff"               },
  { "gmerge-command",0,               40, 0, ""                    },
  { "http-port",     0,               16, 0, "8080"                },
  { "https-login",   0,                0, 0, "off"                 },
  { "href-targets",  0,                0, 0, "on"                  },
  { "ignore-glob",   0,               40, 1, ""                    },
  { "localauth",     0,                0, 0, "off"                 },
  { "main-branch",   0,               40, 0, "trunk"               },
  { "manifest",      0,                0, 1, "off"                 },
#ifdef FOSSIL_ENABLE_MARKDOWN
  { "markdown",      0,                0, 0, "off"                 },
#endif

Changes to src/diff.c.

55
56
57
58
59
60
61

62
63
64
65
66
67
68
...
616
617
618
619
620
621
622


623
624
625
626
627
628
629
...
657
658
659
660
661
662
663

664
665
666
667




668
669
670
671
672

673
674
675
676
677
678
679
680
681

682
683
684
685
686
687
688
689
690
691

692


693


694

695
696

697
698

699

700
701

702

703
704

705

706
707

708

709

710
711
712
713

714
715
716





717
718
719
720
721
722
723
....
1239
1240
1241
1242
1243
1244
1245








1246
1247
1248
1249
1250
1251
1252
....
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
....
2173
2174
2175
2176
2177
2178
2179
2180

2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191





2192
2193
2194
2195
2196
2197
2198
....
2199
2200
2201
2202
2203
2204
2205


2206
2207
2208
2209
2210
2211
2212
....
2213
2214
2215
2216
2217
2218
2219


2220
2221
2222
2223

2224
2225




2226
2227







2228
2229
2230
2231
2232
2233
2234
....
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
....
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
#define looks_like_binary(blob) (looks_like_utf8((blob)) == 0)
#endif /* INTERFACE */

/*
** Maximum length of a line in a text file, in bytes.  (2**13 = 8192 bytes)
*/
#define LENGTH_MASK_SZ  13

#define LENGTH_MASK     ((1<<LENGTH_MASK_SZ)-1)

/*
** Information about each line of a file being diffed.
**
** The lower LENGTH_MASK_SZ bits of the hash (DLine.h) are the length
** of the line.  If any line is longer than LENGTH_MASK characters,
................................................................................
    for(j=0; j<m; j++){
      if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1, html);
      appendDiffLine(pOut, ' ', &B[b+j], html, 0);
    }
  }
}



/*
** Status of a single output line
*/
typedef struct SbsLine SbsLine;
struct SbsLine {
  char *zLine;             /* The output line under construction */
  int n;                   /* Index of next unused slot in the zLine[] */
................................................................................
  int i;   /* Number of input characters consumed */
  int j;   /* Number of output characters generated */
  int k;   /* Cursor position */
  int needEndSpan = 0;
  const char *zIn = pLine->z;
  char *z = &p->zLine[p->n];
  int w = p->width;

  int colorize = p->escHtml;
  if( colorize && p->pRe && re_dline_match(p->pRe, pLine, 1)==0 ){
    colorize = 0;
  }




  for(i=j=k=0; k<w && i<n; i++, k++){
    char c = zIn[i];
    if( colorize ){
      if( i==p->iStart ){
        int x = strlen(p->zStart);

        memcpy(z+j, p->zStart, x);
        j += x;
        needEndSpan = 1;
        if( p->iStart2 ){
          p->iStart = p->iStart2;
          p->zStart = p->zStart2;
          p->iStart2 = 0;
        }
      }else if( i==p->iEnd ){

        memcpy(z+j, "</span>", 7);
        j += 7;
        needEndSpan = 0;
        if( p->iEnd2 ){
          p->iEnd = p->iEnd2;
          p->iEnd2 = 0;
        }
      }
    }
    if( c=='\t' ){

      z[j++] = ' ';


      while( (k&7)!=7 && k<w ){ z[j++] = ' '; k++; }


    }else if( c=='\r' || c=='\f' ){

      z[j++] = ' ';
    }else if( c=='<' && p->escHtml ){

      memcpy(&z[j], "&lt;", 4);
      j += 4;

    }else if( c=='&' && p->escHtml ){

      memcpy(&z[j], "&amp;", 5);
      j += 5;

    }else if( c=='>' && p->escHtml ){

      memcpy(&z[j], "&gt;", 4);
      j += 4;

    }else if( c=='"' && p->escHtml ){

      memcpy(&z[j], "&quot;", 6);
      j += 6;

    }else{

      z[j++] = c;

      if( (c&0xc0)==0x80 ) k--;
    }
  }
  if( needEndSpan ){

    memcpy(&z[j], "</span>", 7);
    j += 7;
  }





  if( (flags & SBS_PAD)!=0 ){
    while( k<w ){ k++;  z[j++] = ' '; }
  }
  if( flags & SBS_NEWLINE ){
    z[j++] = '\n';
  }
  p->n += j;
................................................................................
  int nChunk = 0; /* Number of chunks of diff output seen so far */
  SbsLine s;    /* Output line buffer */
  int nContext; /* Lines of context above and below each change */
  int showDivider = 0;  /* True to show the divider */

  memset(&s, 0, sizeof(s));
  s.width = diff_width(diffFlags);








  s.zLine = fossil_malloc( 15*s.width + 200 );
  if( s.zLine==0 ) return;
  nContext = diff_context_lines(diffFlags);
  s.escHtml = (diffFlags & DIFF_HTML)!=0;
  s.pRe = pRe;
  s.iStart = -1;
  s.iStart2 = 0;
................................................................................

/*
** Extract the width of columns for side-by-side diff.  Supply an
** appropriate default if no width is given.
*/
int diff_width(u64 diffFlags){
  int w = (diffFlags & DIFF_WIDTH_MASK)/(DIFF_CONTEXT_MASK+1);
  if( w==0 ) w = 80;
  return w;
}

/*
** Generate a report of the differences between files pA and pB.
** If pOut is not NULL then a unified diff is appended there.  It
** is assumed that pOut has already been initialized.  If pOut is
................................................................................
/*
** Compute a complete annotation on a file.  The file is identified
** by its filename number (filename.fnid) and the baseline in which
** it was checked in (mlink.mid).
*/
static void annotate_file(
  Annotator *p,        /* The annotator */
  int fnid,            /* The name of the file to be annotated */

  int mid,             /* Use the version of the file in this check-in */
  int webLabel,        /* Use web-style annotations if true */
  int iLimit,          /* Limit the number of levels if greater than zero */
  int annFlags         /* Flags to alter the annotation */
){
  Blob toAnnotate;     /* Text of the final (mid) version of the file */
  Blob step;           /* Text of previous revision */
  int rid;             /* Artifact ID of the file being annotated */
  char *zLabel;        /* Label to apply to a line */
  Stmt q;              /* Query returning all ancestor versions */
  int cnt = 0;         /* Number of versions examined */






  /* Initialize the annotation */
  rid = db_int(0, "SELECT fid FROM mlink WHERE mid=%d AND fnid=%d",mid,fnid);
  if( rid==0 ){
    fossil_panic("file #%d is unchanged in manifest #%d", fnid, mid);
  }
  if( !content_get(rid, &toAnnotate) ){
................................................................................
    fossil_panic("unable to retrieve content of artifact #%d", rid);
  }
  if( iLimit<=0 ) iLimit = 1000000000;
  annotation_start(p, &toAnnotate);
  
  db_prepare(&q,
    "SELECT (SELECT uuid FROM blob WHERE rid=mlink.%s),"


    "       date(event.mtime),"
    "       coalesce(event.euser,event.user),"
    "       mlink.pid"
    "  FROM mlink, event"
    " WHERE mlink.fid=:rid"
    "   AND event.objid=mlink.mid"
    " ORDER BY event.mtime",
................................................................................
    (annFlags & ANN_FILE_VERS)!=0 ? "fid" : "mid"
  );
  
  db_bind_int(&q, ":rid", rid);
  if( iLimit==0 ) iLimit = 1000000000;
  while( rid && iLimit>cnt && db_step(&q)==SQLITE_ROW ){
    const char *zUuid = db_column_text(&q, 0);


    const char *zDate = db_column_text(&q, 1);
    const char *zUser = db_column_text(&q, 2);
    int prevId = db_column_int(&q, 3);
    if( webLabel ){

      zLabel = mprintf(
          "<a href='%R/info/%s' target='infowindow'>%.10s</a> %s %13.13s",




          zUuid, zUuid, zDate, zUser
      );







    }else{
      zLabel = mprintf("%.10s %s %13.13s", zUuid, zDate, zUser);
    }
    p->nVers++;
    p->azVers = fossil_realloc(p->azVers, p->nVers*sizeof(p->azVers[0]) );
    p->azVers[p->nVers-1] = zLabel;
    content_get(rid, &step);
................................................................................
  if( mid==0 || fnid==0 ){ fossil_redirect_home(); }
  iLimit = atoi(PD("limit","-1"));
  if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d AND fnid=%d",mid,fnid) ){
    fossil_redirect_home();
  }
  style_header("File Annotation");
  if( P("filevers") ) annFlags |= ANN_FILE_VERS;
  annotate_file(&ann, fnid, mid, g.perm.Hyperlink, iLimit, annFlags);
  if( P("log") ){
    int i;
    @ <h2>Versions analyzed:</h2>
    @ <ol>
    for(i=0; i<ann.nVers; i++){
      @ <li><tt>%s(ann.azVers[i])</tt></li>
    }
................................................................................
          " WHERE mlink.fid=%d AND mlink.fnid=%d AND mlink.mid=ancestor.rid"
          " ORDER BY ancestor.generation ASC LIMIT 1",
          fid, fnid);
  if( mid==0 ){
    fossil_panic("unable to find manifest");
  }
  if( fileVers ) annFlags |= ANN_FILE_VERS;
  annotate_file(&ann, fnid, mid, 0, iLimit, annFlags);
  if( showLog ){
    for(i=0; i<ann.nVers; i++){
      printf("version %3d: %s\n", i+1, ann.azVers[i]);
    }
    printf("---------------------------------------------------\n");
  }
  for(i=0; i<ann.nOrig; i++){
    fossil_print("%s: %.*s\n",
                 ann.aOrig[i].zSrc, ann.aOrig[i].n, ann.aOrig[i].z);
  }
}






>







 







>
>







 







>




>
>
>
>
|




>
|








>
|









>
|
>
>
|
>
>

>
|

>
|
|
>

>
|
|
>

>
|
|
>

>
|
|
>

>
|
>




>
|
|
|
>
>
>
>
>







 







>
>
>
>
>
>
>
>







 







<







 







|
>











>
>
>
>
>







 







>
>







 







>
>
|
|
|

>
|
|
>
>
>
>
|
<
>
>
>
>
>
>
>







 







|







 







|











55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
...
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
...
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
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
743
744
745
746
747
748
749
750
751
752
753
754
755
....
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
....
1901
1902
1903
1904
1905
1906
1907

1908
1909
1910
1911
1912
1913
1914
....
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
....
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
....
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280

2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
....
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
....
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
#define looks_like_binary(blob) (looks_like_utf8((blob)) == 0)
#endif /* INTERFACE */

/*
** Maximum length of a line in a text file, in bytes.  (2**13 = 8192 bytes)
*/
#define LENGTH_MASK_SZ  13
#define TABLENGTH        4
#define LENGTH_MASK     ((1<<LENGTH_MASK_SZ)-1)

/*
** Information about each line of a file being diffed.
**
** The lower LENGTH_MASK_SZ bits of the hash (DLine.h) are the length
** of the line.  If any line is longer than LENGTH_MASK characters,
................................................................................
    for(j=0; j<m; j++){
      if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1, html);
      appendDiffLine(pOut, ' ', &B[b+j], html, 0);
    }
  }
}

static int maxwidth;

/*
** Status of a single output line
*/
typedef struct SbsLine SbsLine;
struct SbsLine {
  char *zLine;             /* The output line under construction */
  int n;                   /* Index of next unused slot in the zLine[] */
................................................................................
  int i;   /* Number of input characters consumed */
  int j;   /* Number of output characters generated */
  int k;   /* Cursor position */
  int needEndSpan = 0;
  const char *zIn = pLine->z;
  char *z = &p->zLine[p->n];
  int w = p->width;

  int colorize = p->escHtml;
  if( colorize && p->pRe && re_dline_match(p->pRe, pLine, 1)==0 ){
    colorize = 0;
  }

  /* In the case w == 0, we want to calculate the output line
   * width (k), but not write anything to 'z', because it has
   * a buffer of limited size. */
  for(i=j=k=0; (w == 0 || k<w) && i<n; i++, k++){
    char c = zIn[i];
    if( colorize ){
      if( i==p->iStart ){
        int x = strlen(p->zStart);
        if (w != 0)
          memcpy(z+j, p->zStart, x);
        j += x;
        needEndSpan = 1;
        if( p->iStart2 ){
          p->iStart = p->iStart2;
          p->zStart = p->zStart2;
          p->iStart2 = 0;
        }
      }else if( i==p->iEnd ){
        if (w != 0)
          memcpy(z+j, "</span>", 7);
        j += 7;
        needEndSpan = 0;
        if( p->iEnd2 ){
          p->iEnd = p->iEnd2;
          p->iEnd2 = 0;
        }
      }
    }
    if( c=='\t' ){
      if (w != 0)
        z[j++] = ' ';
      while( (k%TABLENGTH)!=0 && (w == 0 || k<w) ){
        if (w != 0)
          z[j++] = ' ';
        k++;
      }
    }else if( c=='\r' || c=='\f' ){
      if (w != 0)
        z[j++] = ' ';
    }else if( c=='<' && p->escHtml ){
      if (w != 0) {
        memcpy(&z[j], "&lt;", 4);
        j += 4;
      }
    }else if( c=='&' && p->escHtml ){
      if (w != 0) {
        memcpy(&z[j], "&amp;", 5);
        j += 5;
      }
    }else if( c=='>' && p->escHtml ){
      if (w != 0) {
        memcpy(&z[j], "&gt;", 4);
        j += 4;
      }
    }else if( c=='"' && p->escHtml ){
      if (w != 0) {
        memcpy(&z[j], "&quot;", 6);
        j += 6;
      }
    }else{
      if (w != 0) {
        z[j++] = c;
      }
      if( (c&0xc0)==0x80 ) k--;
    }
  }
  if( needEndSpan ){
    if (w != 0) {
      memcpy(&z[j], "</span>", 7);
      j += 7;
    }
  }

  if (k > maxwidth)
    maxwidth = k;

  if( (flags & SBS_PAD)!=0 ){
    while( k<w ){ k++;  z[j++] = ' '; }
  }
  if( flags & SBS_NEWLINE ){
    z[j++] = '\n';
  }
  p->n += j;
................................................................................
  int nChunk = 0; /* Number of chunks of diff output seen so far */
  SbsLine s;    /* Output line buffer */
  int nContext; /* Lines of context above and below each change */
  int showDivider = 0;  /* True to show the divider */

  memset(&s, 0, sizeof(s));
  s.width = diff_width(diffFlags);
  if( s.width == 0 ) { /* May Autocalculate */
    Blob dump;
    maxwidth = -1; /* The webserver may call sbsDiff more than once per process */
    blob_zero(&dump);
    sbsDiff(p, &dump, pRe, diffFlags | DIFF_WIDTH_MASK);
    s.width = maxwidth;
    blob_reset(&dump);
  }
  s.zLine = fossil_malloc( 15*s.width + 200 );
  if( s.zLine==0 ) return;
  nContext = diff_context_lines(diffFlags);
  s.escHtml = (diffFlags & DIFF_HTML)!=0;
  s.pRe = pRe;
  s.iStart = -1;
  s.iStart2 = 0;
................................................................................

/*
** Extract the width of columns for side-by-side diff.  Supply an
** appropriate default if no width is given.
*/
int diff_width(u64 diffFlags){
  int w = (diffFlags & DIFF_WIDTH_MASK)/(DIFF_CONTEXT_MASK+1);

  return w;
}

/*
** Generate a report of the differences between files pA and pB.
** If pOut is not NULL then a unified diff is appended there.  It
** is assumed that pOut has already been initialized.  If pOut is
................................................................................
/*
** Compute a complete annotation on a file.  The file is identified
** by its filename number (filename.fnid) and the baseline in which
** it was checked in (mlink.mid).
*/
static void annotate_file(
  Annotator *p,        /* The annotator */
  const char *zFilename,/* The name of the file to be annotated */
  int fnid,            /* The file name id of the file to be annotated */
  int mid,             /* Use the version of the file in this check-in */
  int webLabel,        /* Use web-style annotations if true */
  int iLimit,          /* Limit the number of levels if greater than zero */
  int annFlags         /* Flags to alter the annotation */
){
  Blob toAnnotate;     /* Text of the final (mid) version of the file */
  Blob step;           /* Text of previous revision */
  int rid;             /* Artifact ID of the file being annotated */
  char *zLabel;        /* Label to apply to a line */
  Stmt q;              /* Query returning all ancestor versions */
  int cnt = 0;         /* Number of versions examined */
  const char *zInfoTarget;     /* String for target info window */
  const char *zDiffTarget;     /* String for target diff window */

  zInfoTarget = db_get_boolean("href-targets", 1) ? "target='infowindow'" : "";
  zDiffTarget = db_get_boolean("href-targets", 1) ? "target='diffwindow'" : "";

  /* Initialize the annotation */
  rid = db_int(0, "SELECT fid FROM mlink WHERE mid=%d AND fnid=%d",mid,fnid);
  if( rid==0 ){
    fossil_panic("file #%d is unchanged in manifest #%d", fnid, mid);
  }
  if( !content_get(rid, &toAnnotate) ){
................................................................................
    fossil_panic("unable to retrieve content of artifact #%d", rid);
  }
  if( iLimit<=0 ) iLimit = 1000000000;
  annotation_start(p, &toAnnotate);
  
  db_prepare(&q,
    "SELECT (SELECT uuid FROM blob WHERE rid=mlink.%s),"
    "       (SELECT uuid FROM blob WHERE rid=mlink.fid),"
    "       (SELECT uuid FROM blob WHERE rid=mlink.pid),"
    "       date(event.mtime),"
    "       coalesce(event.euser,event.user),"
    "       mlink.pid"
    "  FROM mlink, event"
    " WHERE mlink.fid=:rid"
    "   AND event.objid=mlink.mid"
    " ORDER BY event.mtime",
................................................................................
    (annFlags & ANN_FILE_VERS)!=0 ? "fid" : "mid"
  );
  
  db_bind_int(&q, ":rid", rid);
  if( iLimit==0 ) iLimit = 1000000000;
  while( rid && iLimit>cnt && db_step(&q)==SQLITE_ROW ){
    const char *zUuid = db_column_text(&q, 0);
    const char *zUuidFile = db_column_text(&q, 1);
    const char *zUuidParentFile = db_column_text(&q, 2);
    const char *zDate = db_column_text(&q, 3);
    const char *zUser = db_column_text(&q, 4);
    int prevId = db_column_int(&q, 5);
    if( webLabel ){
      if (zUuidParentFile) {
        zLabel = mprintf(
            "<a href='%R/info/%s' %s>%.10s</a> "
            "<a href='%R/fdiff?v1=%s&v2=%s' %s>d</a> "
            "%s %13.13s", 
            zUuid, zInfoTarget, zUuid,
            zUuidParentFile, zUuidFile, zDiffTarget,
            zDate, zUser);

      }else{
        zLabel = mprintf(
            "<a href='%R/info/%s' %s>%.10s</a>   "
            "%s %13.13s", 
            zUuid, zInfoTarget, zUuid,
            zDate, zUser);
      }
    }else{
      zLabel = mprintf("%.10s %s %13.13s", zUuid, zDate, zUser);
    }
    p->nVers++;
    p->azVers = fossil_realloc(p->azVers, p->nVers*sizeof(p->azVers[0]) );
    p->azVers[p->nVers-1] = zLabel;
    content_get(rid, &step);
................................................................................
  if( mid==0 || fnid==0 ){ fossil_redirect_home(); }
  iLimit = atoi(PD("limit","-1"));
  if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d AND fnid=%d",mid,fnid) ){
    fossil_redirect_home();
  }
  style_header("File Annotation");
  if( P("filevers") ) annFlags |= ANN_FILE_VERS;
  annotate_file(&ann, P("filename"), fnid, mid, g.perm.Hyperlink, iLimit, annFlags);
  if( P("log") ){
    int i;
    @ <h2>Versions analyzed:</h2>
    @ <ol>
    for(i=0; i<ann.nVers; i++){
      @ <li><tt>%s(ann.azVers[i])</tt></li>
    }
................................................................................
          " WHERE mlink.fid=%d AND mlink.fnid=%d AND mlink.mid=ancestor.rid"
          " ORDER BY ancestor.generation ASC LIMIT 1",
          fid, fnid);
  if( mid==0 ){
    fossil_panic("unable to find manifest");
  }
  if( fileVers ) annFlags |= ANN_FILE_VERS;
  annotate_file(&ann, zFilename, fnid, mid, 0, iLimit, annFlags);
  if( showLog ){
    for(i=0; i<ann.nVers; i++){
      printf("version %3d: %s\n", i+1, ann.azVers[i]);
    }
    printf("---------------------------------------------------\n");
  }
  for(i=0; i<ann.nOrig; i++){
    fossil_print("%s: %.*s\n",
                 ann.aOrig[i].zSrc, ann.aOrig[i].n, ann.aOrig[i].z);
  }
}

Changes to src/diffcmd.c.

48
49
50
51
52
53
54

55
56






57
58
59
60
61
62
63
  char *z = 0;
  if( diffFlags & DIFF_BRIEF ){
    /* no-op */
  }else if( diffFlags & DIFF_SIDEBYSIDE ){
    int w = diff_width(diffFlags);
    int n1 = strlen(zLeft);
    int x;

    if( n1>w*2 ) n1 = w*2;
    x = w*2+17 - (n1+2);






    z = mprintf("%.*c %.*s %.*c\n",
                x/2, '=', n1, zLeft, (x+1)/2, '=');
  }else{
    z = mprintf("--- %s\n+++ %s\n", zLeft, zRight);
  }
  fossil_print("%s", z);
  fossil_free(z);






>
|
|
>
>
>
>
>
>







48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  char *z = 0;
  if( diffFlags & DIFF_BRIEF ){
    /* no-op */
  }else if( diffFlags & DIFF_SIDEBYSIDE ){
    int w = diff_width(diffFlags);
    int n1 = strlen(zLeft);
    int x;
    if (w > 0) {
        if( n1>w*2 ) n1 = w*2;
        x = w*2+17 - (n1+2);
    }else{
        /* Autocalculate width
         * We can't know the width in advance, so we'll make it
         * output three = around the name */
        x = 6;
    }
    z = mprintf("%.*c %.*s %.*c\n",
                x/2, '=', n1, zLeft, (x+1)/2, '=');
  }else{
    z = mprintf("--- %s\n+++ %s\n", zLeft, zRight);
  }
  fossil_print("%s", z);
  fossil_free(z);

Changes to src/doc.c.

186
187
188
189
190
191
192



193
194
195
196
197
198
199
    { "mpeg",       4, "video/mpeg"                        },
    { "mpg",        3, "video/mpeg"                        },
    { "mpga",       4, "audio/mpeg"                        },
    { "ms",         2, "application/x-troff-ms"            },
    { "msh",        3, "model/mesh"                        },
    { "nc",         2, "application/x-netcdf"              },
    { "oda",        3, "application/oda"                   },



    { "ogg",        3, "application/ogg"                   },
    { "ogm",        3, "application/ogg"                   },
    { "pbm",        3, "image/x-portable-bitmap"           },
    { "pdb",        3, "chemical/x-pdb"                    },
    { "pdf",        3, "application/pdf"                   },
    { "pgm",        3, "image/x-portable-graymap"          },
    { "pgn",        3, "application/x-chess-pgn"           },






>
>
>







186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
    { "mpeg",       4, "video/mpeg"                        },
    { "mpg",        3, "video/mpeg"                        },
    { "mpga",       4, "audio/mpeg"                        },
    { "ms",         2, "application/x-troff-ms"            },
    { "msh",        3, "model/mesh"                        },
    { "nc",         2, "application/x-netcdf"              },
    { "oda",        3, "application/oda"                   },
    { "odp",        3, "application/vnd.oasis.opendocument.presentation" },
    { "ods",        3, "application/vnd.oasis.opendocument.spreadsheet" },
    { "odt",        3, "application/vnd.oasis.opendocument.text" },
    { "ogg",        3, "application/ogg"                   },
    { "ogm",        3, "application/ogg"                   },
    { "pbm",        3, "image/x-portable-bitmap"           },
    { "pdb",        3, "chemical/x-pdb"                    },
    { "pdf",        3, "application/pdf"                   },
    { "pgm",        3, "image/x-portable-graymap"          },
    { "pgn",        3, "application/x-chess-pgn"           },

Changes to src/info.c.

405
406
407
408
409
410
411
412

413
414
415
416
417
418
419
420
...
648
649
650
651
652
653
654


655
656
657
658
659
660
661
...
873
874
875
876
877
878
879


880
881
882
883
884
885
886
887
888
889
890
891

892
893
894
895
896
897
898


899
900
901
902
903
904
905
...
972
973
974
975
976
977
978
979
980
981
982
983


984
985
986
987








988
989
990
991
992
993
994
  if( showDiff==0 ){
    diffFlags = 0;  /* Zero means do not show any diff */
  }else{
    int x;
    if( sideBySide ){
      diffFlags = DIFF_SIDEBYSIDE | DIFF_IGNORE_EOLWS;

      /* "dw" query parameter determines width of each column */

      x = atoi(PD("dw","80"))*(DIFF_CONTEXT_MASK+1);
      if( x<0 || x>DIFF_WIDTH_MASK ) x = DIFF_WIDTH_MASK;
      diffFlags += x;
    }else{
      diffFlags = DIFF_INLINE | DIFF_IGNORE_EOLWS;
    }

    /* "dc" query parameter determines lines of context */
................................................................................
      }
      @ </td></tr>
      @ <tr><th>Other&nbsp;Links:</th>
      @   <td>
      @     %z(href("%R/dir?ci=%S",zUuid))files</a>
      @   | %z(href("%R/fileage?name=%S",zUuid))file ages</a>
      @   | %z(href("%R/artifact/%S",zUuid))manifest</a>


      if( g.perm.Write ){
        @   | %z(href("%R/ci_edit?r=%S",zUuid))edit</a>
      }
      @   </td>
      @ </tr>
    }
    @ </table>
................................................................................
** Output a description of a check-in
*/
static void checkin_description(int rid){
  Stmt q;
  db_prepare(&q,
    "SELECT datetime(mtime), coalesce(euser,user),"
    "       coalesce(ecomment,comment), uuid,"


    "      (SELECT group_concat(substr(tagname,5), ', ') FROM tag, tagxref"
    "        WHERE tagname GLOB 'sym-*' AND tag.tagid=tagxref.tagid"
    "          AND tagxref.rid=blob.rid AND tagxref.tagtype>0)"
    "  FROM event, blob"
    " WHERE event.objid=%d AND type='ci'"
    "   AND blob.rid=%d",
    rid, rid
  );
  while( db_step(&q)==SQLITE_ROW ){
    const char *zDate = db_column_text(&q, 0);
    const char *zUser = db_column_text(&q, 1);
    const char *zUuid = db_column_text(&q, 3);

    const char *zTagList = db_column_text(&q, 4);
    Blob comment;
    int wikiFlags = WIKI_INLINE|WIKI_NOBADLINKS;
    if( db_get_boolean("timeline-block-markup", 0)==0 ){
      wikiFlags |= WIKI_NOBLOCK;
    }
    hyperlink_to_uuid(zUuid);


    blob_zero(&comment);
    db_column_blob(&q, 2, &comment);
    wiki_convert(&comment, 0, wikiFlags);
    blob_reset(&comment);
    @ (user:
    hyperlink_to_user(zUser,zDate,",");
    if( zTagList && zTagList[0] && g.perm.Hyperlink ){
................................................................................
  pFrom = vdiff_parse_manifest("from", &ridFrom);
  if( pFrom==0 ) return;
  sideBySide = atoi(PD("sbs","1"));
  showDetail = atoi(PD("detail","0"));
  if( !showDetail && sideBySide ) showDetail = 1;
  zFrom = P("from");
  zTo = P("to");
  if( !sideBySide ){
    style_submenu_element("Side-by-side Diff", "sbsdiff",
                          "%R/vdiff?from=%T&to=%T&detail=%d&sbs=1",
                          zFrom, zTo, showDetail);
  }else{


    style_submenu_element("Unified Diff", "udiff",
                          "%R/vdiff?from=%T&to=%T&detail=%d&sbs=0",
                          zFrom, zTo, showDetail);
  }








  style_submenu_element("Invert", "invert",
                        "%R/vdiff?from=%T&to=%T&detail=%d&sbs=%d",
                        zTo, zFrom, showDetail, sideBySide);
  style_header("Check-in Differences");
  @ <h2>Difference From:</h2><blockquote>
  checkin_description(ridFrom);
  @ </blockquote><h2>To:</h2><blockquote>






|
>
|







 







>
>







 







>
>






|





>







>
>







 







|
|
|
|
<
>
>

|
|

>
>
>
>
>
>
>
>







405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
...
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
...
876
877
878
879
880
881
882
883
884
885
886
887
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
...
980
981
982
983
984
985
986
987
988
989
990

991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
  if( showDiff==0 ){
    diffFlags = 0;  /* Zero means do not show any diff */
  }else{
    int x;
    if( sideBySide ){
      diffFlags = DIFF_SIDEBYSIDE | DIFF_IGNORE_EOLWS;

      /* "dw" query parameter determines width of each column
       * 0 means autocalculate. */
      x = atoi(PD("dw","0"))*(DIFF_CONTEXT_MASK+1);
      if( x<0 || x>DIFF_WIDTH_MASK ) x = DIFF_WIDTH_MASK;
      diffFlags += x;
    }else{
      diffFlags = DIFF_INLINE | DIFF_IGNORE_EOLWS;
    }

    /* "dc" query parameter determines lines of context */
................................................................................
      }
      @ </td></tr>
      @ <tr><th>Other&nbsp;Links:</th>
      @   <td>
      @     %z(href("%R/dir?ci=%S",zUuid))files</a>
      @   | %z(href("%R/fileage?name=%S",zUuid))file ages</a>
      @   | %z(href("%R/artifact/%S",zUuid))manifest</a>
      @   | <a href="%s(g.zTop)/vdiff?from=pbranch:%S(zUuid)&to=%S(zUuid)">
      @           vdiff to parent branch</a>
      if( g.perm.Write ){
        @   | %z(href("%R/ci_edit?r=%S",zUuid))edit</a>
      }
      @   </td>
      @ </tr>
    }
    @ </table>
................................................................................
** Output a description of a check-in
*/
static void checkin_description(int rid){
  Stmt q;
  db_prepare(&q,
    "SELECT datetime(mtime), coalesce(euser,user),"
    "       coalesce(ecomment,comment), uuid,"
    "       coalesce((SELECT value FROM tagxref"
    "        WHERE tagid=%d AND tagtype>0 AND rid=blob.rid),'trunk'),"
    "      (SELECT group_concat(substr(tagname,5), ', ') FROM tag, tagxref"
    "        WHERE tagname GLOB 'sym-*' AND tag.tagid=tagxref.tagid"
    "          AND tagxref.rid=blob.rid AND tagxref.tagtype>0)"
    "  FROM event, blob"
    " WHERE event.objid=%d AND type='ci'"
    "   AND blob.rid=%d",
    TAG_BRANCH, rid, rid
  );
  while( db_step(&q)==SQLITE_ROW ){
    const char *zDate = db_column_text(&q, 0);
    const char *zUser = db_column_text(&q, 1);
    const char *zUuid = db_column_text(&q, 3);
    const char *zBranch = db_column_text(&q, 4);
    const char *zTagList = db_column_text(&q, 4);
    Blob comment;
    int wikiFlags = WIKI_INLINE|WIKI_NOBADLINKS;
    if( db_get_boolean("timeline-block-markup", 0)==0 ){
      wikiFlags |= WIKI_NOBLOCK;
    }
    hyperlink_to_uuid(zUuid);
    @ on branch <a href="%R/timeline?r=%s(zBranch)&nd&c=%T(zDate)">
    @   %s(zBranch)</a> - 
    blob_zero(&comment);
    db_column_blob(&q, 2, &comment);
    wiki_convert(&comment, 0, wikiFlags);
    blob_reset(&comment);
    @ (user:
    hyperlink_to_user(zUser,zDate,",");
    if( zTagList && zTagList[0] && g.perm.Hyperlink ){
................................................................................
  pFrom = vdiff_parse_manifest("from", &ridFrom);
  if( pFrom==0 ) return;
  sideBySide = atoi(PD("sbs","1"));
  showDetail = atoi(PD("detail","0"));
  if( !showDetail && sideBySide ) showDetail = 1;
  zFrom = P("from");
  zTo = P("to");
  if (showDetail){
    style_submenu_element("Abstract", "abstract",
                          "%s/vdiff?from=%T&to=%T&detail=0&sbs=0",
                          g.zTop, zFrom, zTo);

  }
  if( !showDetail || sideBySide ){
    style_submenu_element("Unified Diff", "udiff",
                          "%R/vdiff?from=%T&to=%T&detail=1&sbs=0",
                          zFrom, zTo);
  }
  if (!sideBySide){
    style_submenu_element("Side-by-side Diff", "sbsdiff",
                          "%R/vdiff?from=%T&to=%T&detail=1&sbs=1",
                          zFrom, zTo);
  }
  style_submenu_element("Patch", "patch",
                        "%s/vpatch?from=%T&to=%T",
                        g.zTop, zFrom, zTo);
  style_submenu_element("Invert", "invert",
                        "%R/vdiff?from=%T&to=%T&detail=%d&sbs=%d",
                        zTo, zFrom, showDetail, sideBySide);
  style_header("Check-in Differences");
  @ <h2>Difference From:</h2><blockquote>
  checkin_description(ridFrom);
  @ </blockquote><h2>To:</h2><blockquote>

Changes to src/merge.c.

628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
  }

  /*
  ** Clean up the mid and pid VFILE entries.  Then commit the changes.
  */
  db_multi_exec("DELETE FROM vfile WHERE vid!=%d", vid);
  db_multi_exec("INSERT OR IGNORE INTO vmerge(id,merge) VALUES(%d,%d)",
                pickFlag ? -1 : (backoutFlag ? -2 : 0), mid);
  if( pickFlag ){
    /* For a cherry-pick merge, make the default check-in comment the same
    ** as the check-in comment on the check-in that is being merged in. */
    db_multi_exec(
       "REPLACE INTO vvar(name,value)"
       " SELECT 'ci-comment', coalesce(ecomment,comment) FROM event"
       "  WHERE type='ci' AND objid=%d",
       mid
    );
  }
  undo_finish();
  db_end_transaction(nochangeFlag);
}






|













628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
  }

  /*
  ** Clean up the mid and pid VFILE entries.  Then commit the changes.
  */
  db_multi_exec("DELETE FROM vfile WHERE vid!=%d", vid);
  db_multi_exec("INSERT OR IGNORE INTO vmerge(id,merge) VALUES(%d,%d)",
                pickFlag ? -1 : (backoutFlag ? -2 : (zPivot ? -3 : 0)), mid);
  if( pickFlag ){
    /* For a cherry-pick merge, make the default check-in comment the same
    ** as the check-in comment on the check-in that is being merged in. */
    db_multi_exec(
       "REPLACE INTO vvar(name,value)"
       " SELECT 'ci-comment', coalesce(ecomment,comment) FROM event"
       "  WHERE type='ci' AND objid=%d",
       mid
    );
  }
  undo_finish();
  db_end_transaction(nochangeFlag);
}

Changes to src/name.c.

110
111
112
113
114
115
116








117
118
119
120
121
122
123
...
520
521
522
523
524
525
526




























































































    rid = db_int(0, 
      "SELECT objid FROM event"
      " WHERE mtime<=julianday(%Q,'utc') AND type GLOB '%q'"
      " ORDER BY mtime DESC LIMIT 1",
      &zTag[5], zType);
    return rid;
  }








  if( fossil_isdate(zTag) ){
    rid = db_int(0, 
      "SELECT objid FROM event"
      " WHERE mtime<=julianday(%Q,'utc') AND type GLOB '%q'"
      " ORDER BY mtime DESC LIMIT 1",
      zTag, zType);
    if( rid) return rid;
................................................................................
        db_column_text(&q, 2));
      fossil_print("          ");
      comment_print(db_column_text(&q,4), 10, 78);
    }
    db_finalize(&q);
  }
}


































































































>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
...
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
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
    rid = db_int(0, 
      "SELECT objid FROM event"
      " WHERE mtime<=julianday(%Q,'utc') AND type GLOB '%q'"
      " ORDER BY mtime DESC LIMIT 1",
      &zTag[5], zType);
    return rid;
  }

  if( memcmp(zTag, "pbranch:", 8)==0 ){
    int branchRid = symbolic_name_to_rid(&zTag[8], zType);
    if (branchRid == 0) return 0;
    rid = get_parent_branch_rid(branchRid);
    return rid;
  }

  if( fossil_isdate(zTag) ){
    rid = db_int(0, 
      "SELECT objid FROM event"
      " WHERE mtime<=julianday(%Q,'utc') AND type GLOB '%q'"
      " ORDER BY mtime DESC LIMIT 1",
      zTag, zType);
    if( rid) return rid;
................................................................................
        db_column_text(&q, 2));
      fossil_print("          ");
      comment_print(db_column_text(&q,4), 10, 78);
    }
    db_finalize(&q);
  }
}

int get_parent_branch_rid(int ridRequested){
  Stmt s;
  const char *branchName;    /* Name of the branch requested at rid */
  const char *parentBranchName; /* Name of the parent branch */
  int rid;

  /* Get the name of the current branch */
  branchName = db_text(0,
    "SELECT value FROM tagxref"
    " WHERE tagid=%d"
    "   AND tagxref.tagtype>0"
    "   AND rid=%d",
    TAG_BRANCH, ridRequested);

  if ( !branchName )
    return 0;

  /* Find the name of the branch this was forked from */
  db_prepare(&s,
    "SELECT pid, tagxref.value FROM plink JOIN tagxref"
    " WHERE cid=:rid"
    "   AND isprim=1"
    "   AND tagxref.tagid=%d"
    "   AND tagxref.tagtype>0"
    "   AND tagxref.rid=pid",
    TAG_BRANCH);

  rid = ridRequested;
  while( rid > 0 ) {
    db_bind_int(&s, ":rid", rid);
    if ( db_step(&s) == SQLITE_ROW ) {
      rid = db_column_int(&s, 0);
      parentBranchName = db_column_text(&s, 1);
      if ( !parentBranchName ) {
        rid = 0;
        break;
      }

      if ( fossil_strcmp(parentBranchName, branchName) ) {
        parentBranchName = fossil_strdup(parentBranchName);
        break;
      }
    }else{
      rid = 0;
      break;
    }
    db_reset(&s);
  }
  db_finalize(&s);

  if (rid == 0)
      return 0;

  /* Find the last checkin coming from the parent branch */
  db_prepare(&s,
    "SELECT pid, tagxref.value FROM plink JOIN tagxref"
    " WHERE cid=:rid"
    "   AND tagxref.tagid=%d"
    "   AND tagxref.tagtype>0"
    "   AND tagxref.rid=pid ORDER BY isprim ASC",
    TAG_BRANCH);

  rid = ridRequested;
  while( rid > 0 ) {
    db_bind_int(&s, ":rid", rid);
    int found = 0;
    while ( db_step(&s) == SQLITE_ROW ) {
      const char *branchNamePid; /* Branch name of the pid */

      ++found;
      rid = db_column_int(&s, 0);
      branchNamePid = db_column_text(&s, 1);
      if ( !branchNamePid ) {
        break;
      }
      if ( fossil_strcmp(parentBranchName, branchNamePid)==0 ) {
        /* Found the last merge from the parent branch */
        db_finalize(&s);
        return rid;
      }
    }
    
    if (found == 0) {
      break;
    }
    db_reset(&s);
  }
  db_finalize(&s);

  return 0;
}

Changes to src/timeline.c.

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
157
158
159
160
...
200
201
202
203
204
205
206

207
208
209
210


211
212
213
214
215
216
217
...
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
/*
** Hash a string and use the hash to determine a background color.
*/
char *hash_color(const char *z){
  int i;                       /* Loop counter */
  unsigned int h = 0;          /* Hash on the branch name */
  int r, g, b;                 /* Values for red, green, and blue */
  int h1, h2, h3, h4;          /* Elements of the hash value */
  int mx, mn;                  /* Components of HSV */
  static char zColor[10];      /* The resulting color */


  static int ix[2] = {0,0};    /* Color chooser parameters */



  if( ix[0]==0 ){

    if( db_get_boolean("white-foreground", 0) ){
      ix[0] = 140;
      ix[1] = 40;
    }else{
      ix[0] = 216;
      ix[1] = 16;
    }
  }

  for(i=0; z[i]; i++ ){
    h = (h<<11) ^ (h<<1) ^ (h>>3) ^ z[i];
  }



  h1 = h % 6;  h /= 6;
  h3 = h % 30; h /= 30;
  h4 = h % 40; h /= 40;

  mx = ix[0] - h3;
  mn = mx - h4 - ix[1];
  h2 = (h%(mx - mn)) + mn;

  switch( h1 ){
    case 0:  r = mx; g = h2, b = mn;  break;
    case 1:  r = h2; g = mx, b = mn;  break;
    case 2:  r = mn; g = mx, b = h2;  break;
    case 3:  r = mn; g = h2, b = mx;  break;
    case 4:  r = h2; g = mn, b = mx;  break;
    default: r = mx; g = mn, b = h2;  break;
  }
  sqlite3_snprintf(8, zColor, "#%02x%02x%02x", r,g,b);
  return zColor;
}

/*
** COMMAND:  test-hash-color
................................................................................
  int suppressCnt = 0;
  char zPrevDate[20];
  GraphContext *pGraph = 0;
  int prevWasDivider = 0;     /* True if previous output row was <hr> */
  int fchngQueryInit = 0;     /* True if fchngQuery is initialized */
  Stmt fchngQuery;            /* Query for file changes on check-ins */
  static Stmt qbranch;

  int pendingEndTr = 0;       /* True if a </td></tr> is needed */

  zPrevDate[0] = 0;
  mxWikiLen = db_get_int("timeline-max-comment", 0);


  if( tmFlags & TIMELINE_GRAPH ){
    pGraph = graph_init();
    /* style is not moved to css, because this is
    ** a technical div for the timeline graph
    */
    @ <div id="canvas" style="position:relative;height:0px;width:0px;"
    @  onclick="clickOnGraph(event)"></div>
................................................................................
        const char *zNew = db_column_text(&fchngQuery, 3);
        if( !inUl ){
          @ <ul class="filelist">
          inUl = 1;
        }
        if( isNew ){
          @ <li> %h(zFilename) (new file) &nbsp;
          @ %z(xhref("target='diffwindow'","%R/artifact/%S",zNew))
          @ [view]</a></li>
        }else if( isDel ){
          @ <li> %h(zFilename) (deleted)</li>
        }else if( fossil_strcmp(zOld,zNew)==0 && zOldName!=0 ){
          @ <li> %h(zOldName) &rarr; %h(zFilename)
          @ %z(xhref("target='diffwindow'","%R/artifact/%S",zNew))
          @ [view]</a></li>
        }else{
          if( zOldName!=0 ){
            @ <li> %h(zOldName) &rarr; %h(zFilename)
          }else{
            @ <li> %h(zFilename) &nbsp;
          }
          @ %z(xhref("target='diffwindow'","%R/fdiff?v1=%S&v2=%S",zOld,zNew))
          @ [diff]</a></li>
        }
      }
      db_reset(&fchngQuery);
      if( inUl ){
        @ </ul>
      }






<
<

>
>
|
>
>

<
>
|
<
<
<
<
<
|
<
>
|


>
>
>
|
|
<
>
|
|
<
>
|
|
|
<
<
<
<







 







>




>
>







 







|





|







|







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
...
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
...
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
/*
** Hash a string and use the hash to determine a background color.
*/
char *hash_color(const char *z){
  int i;                       /* Loop counter */
  unsigned int h = 0;          /* Hash on the branch name */
  int r, g, b;                 /* Values for red, green, and blue */


  static char zColor[10];      /* The resulting color */
  static int whitefg = -1;
  int cpc = 4;                 /* colours per component */
  int cfactor = 128/cpc;       /* Factor so n*cpc < 128 */
  int cmin = cfactor - 1;      /* Factor so the max component is 127
                                  and the min is different than the bg */


  if( whitefg = -1 ) 
    whitefg = db_get_boolean("white-foreground", 0);







  /* Calculate the hash based on the branch name */
  for( i=0; z[i]; i++ ){
    h = (h<<11) ^ (h<<1) ^ (h>>3) ^ z[i];
  }

  /* 'cpc' different random values per component, between 'cmin' and 127 */
  r = cmin + (h % cpc) * cfactor;  h /= cpc;
  g = cmin + (h % cpc) * cfactor;  h /= cpc;
  b = cmin + (h % cpc) * cfactor;  h /= cpc;


  /* In case of blackfg, get the inverse effect */
  if( !whitefg )

  {
      r = 255 - r;
      g = 255 - g;
      b = 255 - b;




  }
  sqlite3_snprintf(8, zColor, "#%02x%02x%02x", r,g,b);
  return zColor;
}

/*
** COMMAND:  test-hash-color
................................................................................
  int suppressCnt = 0;
  char zPrevDate[20];
  GraphContext *pGraph = 0;
  int prevWasDivider = 0;     /* True if previous output row was <hr> */
  int fchngQueryInit = 0;     /* True if fchngQuery is initialized */
  Stmt fchngQuery;            /* Query for file changes on check-ins */
  static Stmt qbranch;
  const char *zDiffTarget;    /* String for the target diff window */
  int pendingEndTr = 0;       /* True if a </td></tr> is needed */

  zPrevDate[0] = 0;
  mxWikiLen = db_get_int("timeline-max-comment", 0);
  zDiffTarget = db_get_boolean("href-targets", 1) ?
      "target='diffwindow'": "";
  if( tmFlags & TIMELINE_GRAPH ){
    pGraph = graph_init();
    /* style is not moved to css, because this is
    ** a technical div for the timeline graph
    */
    @ <div id="canvas" style="position:relative;height:0px;width:0px;"
    @  onclick="clickOnGraph(event)"></div>
................................................................................
        const char *zNew = db_column_text(&fchngQuery, 3);
        if( !inUl ){
          @ <ul class="filelist">
          inUl = 1;
        }
        if( isNew ){
          @ <li> %h(zFilename) (new file) &nbsp;
          @ %z(xhref(zDiffTarget,"%R/artifact/%S",zNew))
          @ [view]</a></li>
        }else if( isDel ){
          @ <li> %h(zFilename) (deleted)</li>
        }else if( fossil_strcmp(zOld,zNew)==0 && zOldName!=0 ){
          @ <li> %h(zOldName) &rarr; %h(zFilename)
          @ %z(xhref(zDiffTarget,"%R/artifact/%S",zNew))
          @ [view]</a></li>
        }else{
          if( zOldName!=0 ){
            @ <li> %h(zOldName) &rarr; %h(zFilename)
          }else{
            @ <li> %h(zFilename) &nbsp;
          }
          @ %z(xhref(zDiffTarget,"%R/fdiff?v1=%S&v2=%S",zOld,zNew))
          @ [diff]</a></li>
        }
      }
      db_reset(&fchngQuery);
      if( inUl ){
        @ </ul>
      }