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
|
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
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
-
+
-
-
-
-
-
-
-
|
/* Commit */
db_end_transaction(0);
/* Do an autosync push, if requested */
autosync(AUTOSYNC_PUSH);
}
/*
** Prepare a query that will list all branches.
*/
static void prepareBranchQuery(Stmt *pQuery, int showAll, int showClosed){
if( showClosed ){
db_prepare(pQuery,
"SELECT value FROM tagxref"
" WHERE tagid=%d AND value NOT NULL "
"EXCEPT "
"SELECT value FROM tagxref"
" WHERE tagid=%d"
" AND rid IN leaf"
" AND NOT %z"
" ORDER BY value COLLATE nocase /*sort*/",
TAG_BRANCH, TAG_BRANCH, leaf_is_closed_sql("tagxref.rid")
);
}else if( showAll ){
db_prepare(pQuery,
"SELECT DISTINCT value FROM tagxref"
" WHERE tagid=%d AND value NOT NULL"
" AND rid IN leaf"
" ORDER BY value COLLATE nocase /*sort*/",
TAG_BRANCH
);
}else{
db_prepare(pQuery,
"SELECT DISTINCT value FROM tagxref"
" WHERE tagid=%d AND value NOT NULL"
" AND rid IN leaf"
" AND NOT %z"
" ORDER BY value COLLATE nocase /*sort*/",
TAG_BRANCH, leaf_is_closed_sql("tagxref.rid")
);
}
}
/*
** COMMAND: branch
**
** Usage: %fossil branch SUBCOMMAND ... ?-R|--repository FILE?
**
** Run various subcommands to manage branches of the open repository or
** of the repository identified by the -R or --repository option.
**
** %fossil branch new BRANCH-NAME BASIS ?--bgcolor COLOR? ?--private?
**
** Create a new branch BRANCH-NAME off of check-in BASIS.
** You can optionally give the branch a default color. The
** --private option makes the branch private.
**
** %fossil branch list
** %fossil branch ls
**
** List all branches
** List all branches. Use --all or --closed to list all branches
** or closed branches. The default is to show only open branches.
**
*/
void branch_cmd(void){
int n;
const char *zCmd = "list";
db_find_and_open_repository(0, 0);
if( g.argc<2 ){
usage("new|list|ls ...");
}
if( g.argc>=3 ) zCmd = g.argv[2];
n = strlen(zCmd);
if( strncmp(zCmd,"new",n)==0 ){
branch_new();
}else if( (strncmp(zCmd,"list",n)==0)||(strncmp(zCmd, "ls", n)==0) ){
Stmt q;
int vid;
char *zCurrent = 0;
int showAll = find_option("all",0,0)!=0;
int showClosed = find_option("closed",0,0)!=0;
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);
}
db_prepare(&q,
prepareBranchQuery(&q, showAll, showClosed);
"SELECT DISTINCT value FROM tagxref"
" WHERE tagid=%d AND value NOT NULL"
" AND rid IN leaf"
" AND NOT %z"
" ORDER BY value /*sort*/",
TAG_BRANCH, leaf_is_closed_sql("tagxref.rid")
);
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{
|
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
|
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
|
+
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
**
** Show a timeline of all branches
*/
void brlist_page(void){
Stmt q;
int cnt;
int showClosed = P("closed")!=0;
int showAll = P("all")!=0;
login_check_credentials();
if( !g.okRead ){ login_needed(); return; }
style_header(showClosed ? "Closed Branches" : "Open Branches");
style_header(showClosed ? "Closed Branches" :
showAll ? "All Branches" : "Open Branches");
style_submenu_element("Timeline", "Timeline", "brtimeline");
if( showClosed ){
style_submenu_element("All", "All", "brlist?all");
style_submenu_element("Open","Open","brlist");
}else if( showAll ){
style_submenu_element("Closed", "Closed", "brlist?closed");
style_submenu_element("Open","Open","brlist");
}else{
style_submenu_element("All", "All", "brlist?all");
style_submenu_element("Closed","Closed","brlist?closed");
}
login_anonymous_available();
style_sidebox_begin("Nomenclature:", "33%");
@ <ol>
@ <li> An <div class="sideboxDescribed"><a href="brlist">
@ open branch</a></div> is a branch that has one or
@ more <a href="leaves">open leaves.</a>
@ The presence of open leaves presumably means
@ that the branch is still being extended with new check-ins.</li>
@ <li> A <div class="sideboxDescribed"><a href="brlist?closed">
@ closed branch</a></div> is a branch with only
@ <div class="sideboxDescribed"><a 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();
prepareBranchQuery(&q, showAll, showClosed);
cnt = 0;
if( showClosed ){
db_prepare(&q,
"SELECT value FROM tagxref"
" WHERE tagid=%d AND value NOT NULL "
"EXCEPT "
"SELECT value FROM tagxref"
" WHERE tagid=%d"
" AND rid IN leaf"
" AND NOT %z"
" ORDER BY value /*sort*/",
TAG_BRANCH, TAG_BRANCH, leaf_is_closed_sql("tagxref.rid")
);
}else{
db_prepare(&q,
"SELECT DISTINCT value FROM tagxref"
" WHERE tagid=%d AND value NOT NULL"
" AND rid IN leaf"
" AND NOT %z"
" ORDER BY value /*sort*/",
TAG_BRANCH, leaf_is_closed_sql("tagxref.rid")
);
}
while( db_step(&q)==SQLITE_ROW ){
const char *zBr = db_column_text(&q, 0);
if( cnt==0 ){
if( showClosed ){
@ <h2>Closed Branches:</h2>
}else{
@ <h2>Open Branches:</h2>
|