1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
59
60
61
62
63
64
65
66
67
68
69
70
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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
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
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
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
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
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
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
| /*
** Copyright (c) 2007 D. Richard Hipp
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the Simplified BSD License (also
** known as the "2-Clause License" or "FreeBSD License".)
** This program is distributed in the hope that it will be useful,
** but without any warranty; without even the implied warranty of
** merchantability or fitness for a particular purpose.
**
** Author contact information:
** drh@hwaci.com
** http://www.hwaci.com/drh/
**
*******************************************************************************
**
** This file contains code used to create new branches within a repository.
*/
#include "config.h"
#include "branch.h"
#include <assert.h>
/*
** fossil branch new NAME BASIS ?OPTIONS?
** argv0 argv1 argv2 argv3 argv4
*/
void branch_new(void){
int rootid; /* RID of the root check-in - what we branch off of */
int brid; /* RID of the branch check-in */
int noSign; /* True if the branch is unsigned */
int i; /* Loop counter */
char *zUuid; /* Artifact ID of origin */
Stmt q; /* Generic query */
const char *zBranch; /* Name of the new branch */
char *zDate; /* Date that branch was created */
char *zComment; /* Check-in comment for the new branch */
const char *zColor; /* Color of the new branch */
Blob branch; /* manifest for the new branch */
Manifest *pParent; /* Parsed parent manifest */
Blob mcksum; /* Self-checksum on the manifest */
const char *zDateOvrd; /* Override date string */
const char *zUserOvrd; /* Override user name */
int isPrivate = 0; /* True if the branch should be private */
noSign = find_option("nosign","",0)!=0;
zColor = find_option("bgcolor","c",1);
isPrivate = find_option("private",0,0)!=0;
zDateOvrd = find_option("date-override",0,1);
zUserOvrd = find_option("user-override",0,1);
verify_all_options();
if( g.argc<5 ){
usage("new BRANCH-NAME BASIS ?OPTIONS?");
}
db_find_and_open_repository(0, 0);
noSign = db_get_boolean("omitsign", 0)|noSign;
if( db_get_boolean("clearsign", 0)==0 ){ noSign = 1; }
/* fossil branch new name */
zBranch = g.argv[3];
if( zBranch==0 || zBranch[0]==0 ){
fossil_fatal("branch name cannot be empty");
}
if( db_exists(
"SELECT 1 FROM tagxref"
" WHERE tagtype>0"
" AND tagid=(SELECT tagid FROM tag WHERE tagname='sym-%q')",
zBranch)!=0 ){
fossil_fatal("branch \"%s\" already exists", zBranch);
}
user_select();
db_begin_transaction();
rootid = name_to_typed_rid(g.argv[4], "ci");
if( rootid==0 ){
fossil_fatal("unable to locate check-in off of which to branch");
}
pParent = manifest_get(rootid, CFTYPE_MANIFEST, 0);
if( pParent==0 ){
fossil_fatal("%s is not a valid check-in", g.argv[4]);
}
/* Create a manifest for the new branch */
blob_zero(&branch);
if( pParent->zBaseline ){
blob_appendf(&branch, "B %s\n", pParent->zBaseline);
}
zComment = mprintf("Create new branch named \"%h\"", zBranch);
blob_appendf(&branch, "C %F\n", zComment);
zDate = date_in_standard_format(zDateOvrd ? zDateOvrd : "now");
blob_appendf(&branch, "D %s\n", zDate);
/* Copy all of the content from the parent into the branch */
for(i=0; i<pParent->nFile; ++i){
blob_appendf(&branch, "F %F", pParent->aFile[i].zName);
if( pParent->aFile[i].zUuid ){
blob_appendf(&branch, " %s", pParent->aFile[i].zUuid);
if( pParent->aFile[i].zPerm && pParent->aFile[i].zPerm[0] ){
blob_appendf(&branch, " %s", pParent->aFile[i].zPerm);
}
}
blob_append(&branch, "\n", 1);
}
zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rootid);
blob_appendf(&branch, "P %s\n", zUuid);
if( pParent->zRepoCksum ){
blob_appendf(&branch, "R %s\n", pParent->zRepoCksum);
}
manifest_destroy(pParent);
/* Add the symbolic branch name and the "branch" tag to identify
** this as a new branch */
if( content_is_private(rootid) ) isPrivate = 1;
if( isPrivate && zColor==0 ) zColor = "#fec084";
if( zColor!=0 ){
blob_appendf(&branch, "T *bgcolor * %F\n", zColor);
}
blob_appendf(&branch, "T *branch * %F\n", zBranch);
blob_appendf(&branch, "T *sym-%F *\n", zBranch);
if( isPrivate ){
blob_appendf(&branch, "T +private *\n");
noSign = 1;
}
/* Cancel all other symbolic tags */
db_prepare(&q,
"SELECT tagname FROM tagxref, tag"
" WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid"
" AND tagtype>0 AND tagname GLOB 'sym-*'"
" ORDER BY tagname",
rootid);
while( db_step(&q)==SQLITE_ROW ){
const char *zTag = db_column_text(&q, 0);
blob_appendf(&branch, "T -%F *\n", zTag);
}
db_finalize(&q);
blob_appendf(&branch, "U %F\n", zUserOvrd ? zUserOvrd : login_name());
md5sum_blob(&branch, &mcksum);
blob_appendf(&branch, "Z %b\n", &mcksum);
if( !noSign && clearsign(&branch, &branch) ){
Blob ans;
char cReply;
prompt_user("unable to sign manifest. continue (y/N)? ", &ans);
cReply = blob_str(&ans)[0];
if( cReply!='y' && cReply!='Y'){
db_end_transaction(1);
fossil_exit(1);
}
}
brid = content_put_ex(&branch, 0, 0, 0, isPrivate);
if( brid==0 ){
fossil_fatal("trouble committing manifest: %s", g.zErrMsg);
}
db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", brid);
if( manifest_crosslink(brid, &branch, MC_PERMIT_HOOKS)==0 ){
fossil_fatal("%s", g.zErrMsg);
}
assert( blob_is_reset(&branch) );
content_deltify(rootid, &brid, 1, 0);
zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", brid);
fossil_print("New branch: %s\n", zUuid);
if( g.argc==3 ){
fossil_print(
"\n"
"Note: the local check-out has not been updated to the new\n"
" branch. To begin working on the new branch, do this:\n"
"\n"
" %s update %s\n",
g.argv[0], zBranch
);
}
/* Commit */
db_end_transaction(0);
/* Do an autosync push, if requested */
if( !isPrivate ) autosync_loop(SYNC_PUSH, db_get_int("autosync-tries",1),0);
}
/*
** Create a TEMP table named "tmp_brlist" with 7 columns:
**
** name Name of the branch
** mtime Time of last checkin on this branch
** isclosed True if the branch is closed
** mergeto Another branch this branch was merged into
** nckin Number of checkins on this branch
** ckin Hash of the last checkin on this branch
** bgclr Background color for this branch
*/
static const char createBrlistQuery[] =
@ CREATE TEMP TABLE IF NOT EXISTS tmp_brlist AS
@ SELECT
@ tagxref.value AS name,
@ max(event.mtime) AS mtime,
@ EXISTS(SELECT 1 FROM tagxref AS tx
@ WHERE tx.rid=tagxref.rid
@ AND tx.tagid=(SELECT tagid FROM tag WHERE tagname='closed')
@ AND tx.tagtype>0) AS isclosed,
@ (SELECT tagxref.value
@ FROM plink CROSS JOIN tagxref
@ WHERE plink.pid=event.objid
@ AND tagxref.rid=plink.cid
@ AND tagxref.tagid=(SELECT tagid FROM tag WHERE tagname='branch')
@ AND tagtype>0) AS mergeto,
@ count(*) AS nckin,
@ (SELECT uuid FROM blob WHERE rid=tagxref.rid) AS ckin,
@ event.bgcolor AS bgclr
@ FROM tagxref, tag, event
@ WHERE tagxref.tagid=tag.tagid
@ AND tagxref.tagtype>0
@ AND tag.tagname='branch'
@ AND event.objid=tagxref.rid
@ GROUP BY 1;
;
/* Call this routine to create the TEMP table */
static void brlist_create_temp_table(void){
db_multi_exec(createBrlistQuery/*works-like:""*/);
}
#if INTERFACE
/*
** Allows bits in the mBplqFlags parameter to branch_prepare_list_query().
*/
#define BRL_CLOSED_ONLY 0x001 /* Show only closed branches */
#define BRL_OPEN_ONLY 0x002 /* Show only open branches */
#define BRL_BOTH 0x003 /* Show both open and closed branches */
#define BRL_OPEN_CLOSED_MASK 0x003
#define BRL_ORDERBY_MTIME 0x004 /* Sort by MTIME. (otherwise sort by name)*/
#define BRL_REVERSE 0x008 /* Reverse the sort order */
#endif /* INTERFACE */
/*
** Prepare a query that will list branches.
**
** If (which<0) then the query pulls only closed branches. If
** (which>0) then the query pulls all (closed and opened)
** branches. Else the query pulls currently-opened branches.
*/
void branch_prepare_list_query(Stmt *pQuery, int brFlags){
Blob sql;
blob_init(&sql, 0, 0);
brlist_create_temp_table();
switch( brFlags & BRL_OPEN_CLOSED_MASK ){
case BRL_CLOSED_ONLY: {
blob_append_sql(&sql,
"SELECT name FROM tmp_brlist WHERE isclosed"
);
break;
}
case BRL_BOTH: {
blob_append_sql(&sql,
"SELECT name FROM tmp_brlist"
);
break;
}
case BRL_OPEN_ONLY: {
blob_append_sql(&sql,
"SELECT name FROM tmp_brlist WHERE NOT isclosed"
);
break;
}
}
if( brFlags & BRL_ORDERBY_MTIME ){
blob_append_sql(&sql, " ORDER BY -mtime");
}else{
blob_append_sql(&sql, " ORDER BY name COLLATE nocase");
}
if( brFlags & BRL_REVERSE ){
blob_append_sql(&sql," DESC");
}
db_prepare_blob(pQuery, &sql);
blob_reset(&sql);
}
/*
** If the branch named in the argument is open, return a RID for one of
** the open leaves of that branch. If the branch does not exists or is
** closed, return 0.
*/
int branch_is_open(const char *zBrName){
return db_int(0,
"SELECT rid FROM tagxref AS ox"
" WHERE tagid=%d"
" AND tagtype=2"
" AND value=%Q"
" AND rid IN leaf"
" AND NOT EXISTS(SELECT 1 FROM tagxref AS ix"
" WHERE tagid=%d"
" AND tagtype=1"
" AND ox.rid=ix.rid)",
TAG_BRANCH, zBrName, TAG_CLOSED
);
}
/*
** COMMAND: branch
**
** Usage: %fossil branch SUBCOMMAND ... ?OPTIONS?
**
** Run various subcommands to manage branches of the open repository or
** of the repository identified by the -R or --repository option.
**
** fossil branch current
**
** Print the name of the branch for the current check-out
**
** fossil branch info BRANCH-NAME
**
** Print information about a branch
**
** fossil branch list|ls ?OPTIONS?
**
** List all branches. Options:
** -a|--all List all branches. Default show only open branches
** -c|--closed List closed branches.
** -r Reverse the sort order
** -t Show recently changed branches first
**
** fossil branch new BRANCH-NAME BASIS ?OPTIONS?
**
** Create a new branch BRANCH-NAME off of check-in BASIS.
** Supported options for this subcommand include:
** --private branch is private (i.e., remains local)
** --bgcolor COLOR use COLOR instead of automatic background
** --nosign do not sign contents on this branch
** --date-override DATE DATE to use instead of 'now'
** --user-override USER USER to use instead of the current default
**
** DATE may be "now" or "YYYY-MM-DDTHH:MM:SS.SSS". If in
** year-month-day form, it may be truncated, the "T" may be
** replaced by a space, and it may also name a timezone offset
** from UTC as "-HH:MM" (westward) or "+HH:MM" (eastward).
** Either no timezone suffix or "Z" means UTC.
**
** Options:
** -R|--repository FILE Run commands on repository FILE
**
** Summary:
** fossil branch current
** fossil branch info BRANCHNAME
** fossil branch [list|ls]
** fossil branch new
*/
void branch_cmd(void){
int n;
const char *zCmd = "list";
db_find_and_open_repository(0, 0);
if( g.argc>=3 ) zCmd = g.argv[2];
n = strlen(zCmd);
if( strncmp(zCmd,"current",n)==0 ){
if( !g.localOpen ){
fossil_fatal("not within an open checkout");
}else{
int vid = db_lget_int("checkout", 0);
char *zCurrent = db_text(0, "SELECT value FROM tagxref"
" WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH);
fossil_print("%s\n", zCurrent);
fossil_free(zCurrent);
}
}else if( strncmp(zCmd,"info",n)==0 ){
int i;
for(i=3; i<g.argc; i++){
const char *zBrName = g.argv[i];
int rid = branch_is_open(zBrName);
if( rid==0 ){
fossil_print("%s: not an open branch\n", zBrName);
}else{
const char *zUuid = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",rid);
const char *zDate = db_text(0,
"SELECT datetime(mtime,toLocal()) FROM event"
" WHERE objid=%d", rid);
fossil_print("%s: open as of %s on %.16s\n", zBrName, zDate, zUuid);
}
}
}else if( (strncmp(zCmd,"list",n)==0)||(strncmp(zCmd, "ls", n)==0) ){
Stmt q;
int vid;
char *zCurrent = 0;
int brFlags = BRL_OPEN_ONLY;
if( find_option("all","a",0)!=0 ) brFlags = BRL_BOTH;
if( find_option("closed","c",0)!=0 ) brFlags = BRL_CLOSED_ONLY;
if( find_option("t",0,0)!=0 ) brFlags |= BRL_ORDERBY_MTIME;
if( find_option("r",0,0)!=0 ) brFlags |= BRL_REVERSE;
if( g.localOpen ){
vid = db_lget_int("checkout", 0);
zCurrent = db_text(0, "SELECT value FROM tagxref"
" WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH);
}
branch_prepare_list_query(&q, brFlags);
while( db_step(&q)==SQLITE_ROW ){
const char *zBr = db_column_text(&q, 0);
int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0;
fossil_print("%s%s\n", (isCur ? "* " : " "), zBr);
}
db_finalize(&q);
}else if( strncmp(zCmd,"new",n)==0 ){
branch_new();
}else{
fossil_fatal("branch subcommand should be one of: "
"current info list ls new");
}
}
/*
** This is the new-style branch-list page that shows the branch names
** together with their ages (time of last check-in) and whether or not
** they are closed or merged to another branch.
**
** Control jumps to this routine from brlist_page() (the /brlist handler)
** if there are no query parameters.
*/
static void new_brlist_page(void){
Stmt q;
double rNow;
int show_colors = PB("colors");
login_check_credentials();
if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
style_header("Branches");
style_adunit_config(ADUNIT_RIGHT_OK);
style_submenu_checkbox("colors", "Use Branch Colors", 0, 0);
login_anonymous_available();
brlist_create_temp_table();
db_prepare(&q, "SELECT * FROM tmp_brlist ORDER BY mtime DESC");
rNow = db_double(0.0, "SELECT julianday('now')");
@ <div class="brlist">
@ <table class='sortable' data-column-types='tkNtt' data-init-sort='2'>
@ <thead><tr>
@ <th>Branch Name</th>
@ <th>Last Change</th>
@ <th>Check-ins</th>
@ <th>Status</th>
@ <th>Resolution</th>
@ </tr></thead><tbody>
while( db_step(&q)==SQLITE_ROW ){
const char *zBranch = db_column_text(&q, 0);
double rMtime = db_column_double(&q, 1);
int isClosed = db_column_int(&q, 2);
const char *zMergeTo = db_column_text(&q, 3);
int nCkin = db_column_int(&q, 4);
const char *zLastCkin = db_column_text(&q, 5);
const char *zBgClr = db_column_text(&q, 6);
char *zAge = human_readable_age(rNow - rMtime);
sqlite3_int64 iMtime = (sqlite3_int64)(rMtime*86400.0);
if( zMergeTo && zMergeTo[0]==0 ) zMergeTo = 0;
if( zBgClr == 0 ){
if( zBranch==0 || strcmp(zBranch,"trunk")==0 ){
zBgClr = 0;
}else{
zBgClr = hash_color(zBranch);
}
}
if( zBgClr && zBgClr[0] && show_colors ){
@ <tr style="background-color:%s(zBgClr)">
}else{
@ <tr>
}
@ <td>%z(href("%R/timeline?r=%T",zBranch))%h(zBranch)</a></td>
@ <td data-sortkey="%016llx(iMtime)">%s(zAge)</td>
@ <td>%d(nCkin)</td>
fossil_free(zAge);
@ <td>%s(isClosed?"closed":"")</td>
if( zMergeTo ){
@ <td>merged into
@ %z(href("%R/timeline?f=%!S",zLastCkin))%h(zMergeTo)</a></td>
}else{
@ <td></td>
}
@ </tr>
}
@ </tbody></table></div>
db_finalize(&q);
style_table_sorter();
style_footer();
}
/*
** WEBPAGE: brlist
** Show a list of branches. With no query parameters, a sortable table
** is used to show all branches. If query parameters are present a
** fixed bullet list is shown.
**
** Query parameters:
**
** all Show all branches
** closed Show only closed branches
** open Show only open branches
** colortest Show all branches with automatic color
**
** When there are no query parameters, a new-style /brlist page shows
** all branches in a sortable table. The new-style /brlist page is
** preferred and is the default.
*/
void brlist_page(void){
Stmt q;
int cnt;
int showClosed = P("closed")!=0;
int showAll = P("all")!=0;
int showOpen = P("open")!=0;
int colorTest = P("colortest")!=0;
int brFlags = BRL_OPEN_ONLY;
if( showClosed==0 && showAll==0 && showOpen==0 && colorTest==0 ){
new_brlist_page();
return;
}
login_check_credentials();
if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
if( colorTest ){
showClosed = 0;
showAll = 1;
}
if( showAll ) brFlags = BRL_BOTH;
if( showClosed ) brFlags = BRL_CLOSED_ONLY;
style_header("%s", showClosed ? "Closed Branches" :
showAll ? "All Branches" : "Open Branches");
style_submenu_element("Timeline", "brtimeline");
if( showClosed ){
style_submenu_element("All", "brlist?all");
style_submenu_element("Open", "brlist?open");
}else if( showAll ){
style_submenu_element("Closed", "brlist?closed");
style_submenu_element("Open", "brlist");
}else{
style_submenu_element("All", "brlist?all");
style_submenu_element("Closed", "brlist?closed");
}
if( !colorTest ){
style_submenu_element("Color-Test", "brlist?colortest");
}else{
style_submenu_element("All", "brlist?all");
}
login_anonymous_available();
#if 0
style_sidebox_begin("Nomenclature:", "33%");
@ <ol>
@ <li> An <div class="sideboxDescribed">%z(href("brlist"))
@ open branch</a></div> is a branch that has one or more
@ <div class="sideboxDescribed">%z(href("leaves"))open leaves.</a></div>
@ The presence of open leaves presumably means
@ that the branch is still being extended with new check-ins.</li>
@ <li> A <div class="sideboxDescribed">%z(href("brlist?closed"))
@ closed branch</a></div> is a branch with only
@ <div class="sideboxDescribed">%z(href("leaves?closed"))
@ closed leaves</a></div>.
@ Closed branches are fixed and do not change (unless they are first
@ reopened).</li>
@ </ol>
style_sidebox_end();
#endif
branch_prepare_list_query(&q, brFlags);
cnt = 0;
while( db_step(&q)==SQLITE_ROW ){
const char *zBr = db_column_text(&q, 0);
if( cnt==0 ){
if( colorTest ){
@ <h2>Default background colors for all branches:</h2>
}else if( showClosed ){
@ <h2>Closed Branches:</h2>
}else if( showAll ){
@ <h2>All Branches:</h2>
}else{
@ <h2>Open Branches:</h2>
}
@ <ul>
cnt++;
}
if( colorTest ){
const char *zColor = hash_color(zBr);
@ <li><span style="background-color: %s(zColor)">
@ %h(zBr) → %s(zColor)</span></li>
}else{
@ <li>%z(href("%R/timeline?r=%T",zBr))%h(zBr)</a></li>
}
}
if( cnt ){
@ </ul>
}
db_finalize(&q);
style_footer();
}
/*
** This routine is called while for each check-in that is rendered by
** the timeline of a "brlist" page. Add some additional hyperlinks
** to the end of the line.
*/
static void brtimeline_extra(int rid){
Stmt q;
if( !g.perm.Hyperlink ) return;
db_prepare(&q,
"SELECT substr(tagname,5) FROM tagxref, tag"
" WHERE tagxref.rid=%d"
" AND tagxref.tagid=tag.tagid"
" AND tagxref.tagtype>0"
" AND tag.tagname GLOB 'sym-*'",
rid
);
while( db_step(&q)==SQLITE_ROW ){
const char *zTagName = db_column_text(&q, 0);
@ %z(href("%R/timeline?r=%T",zTagName))[timeline]</a>
}
db_finalize(&q);
}
/*
** WEBPAGE: brtimeline
**
** Show a timeline of all branches
**
** Query parameters:
**
** ng No graph
** nohidden Hide check-ins with "hidden" tag
** onlyhidden Show only check-ins with "hidden" tag
** brbg Background color by branch name
** ubg Background color by user name
*/
void brtimeline_page(void){
Blob sql = empty_blob;
Stmt q;
int tmFlags; /* Timeline display flags */
int fNoHidden = PB("nohidden")!=0; /* The "nohidden" query parameter */
int fOnlyHidden = PB("onlyhidden")!=0; /* The "onlyhidden" query parameter */
login_check_credentials();
if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
style_header("Branches");
style_submenu_element("List", "brlist");
login_anonymous_available();
timeline_ss_submenu();
cookie_render();
@ <h2>The initial check-in for each branch:</h2>
blob_append(&sql, timeline_query_for_www(), -1);
blob_append_sql(&sql,
"AND blob.rid IN (SELECT rid FROM tagxref"
" WHERE tagtype>0 AND tagid=%d AND srcid!=0)", TAG_BRANCH);
if( fNoHidden || fOnlyHidden ){
const char* zUnaryOp = fNoHidden ? "NOT" : "";
blob_append_sql(&sql,
" AND %s EXISTS(SELECT 1 FROM tagxref"
" WHERE tagid=%d AND tagtype>0 AND rid=blob.rid)\n",
zUnaryOp/*safe-for-%s*/, TAG_HIDDEN);
}
db_prepare(&q, "%s ORDER BY event.mtime DESC", blob_sql_text(&sql));
blob_reset(&sql);
/* Always specify TIMELINE_DISJOINT, or graph_finish() may fail because of too
** many descenders to (off-screen) parents. */
tmFlags = TIMELINE_DISJOINT | TIMELINE_NOSCROLL;
if( PB("ng")==0 ) tmFlags |= TIMELINE_GRAPH;
if( PB("brbg")!=0 ) tmFlags |= TIMELINE_BRCOLOR;
if( PB("ubg")!=0 ) tmFlags |= TIMELINE_UCOLOR;
www_print_timeline(&q, tmFlags, 0, 0, 0, 0, brtimeline_extra);
db_finalize(&q);
style_footer();
}
|