Fossil SCM

Add the "fossil branch current" command. Also rearrange the code and the help text for the "fossil branch" command so that the various subcommands are in alphabetical order.

drh 2018-09-18 15:50 trunk
Commit 3b0a1f4e1e4e9a4eaa41ae132e2ef66ebae9489a1676f7a22aacc727608574ed
1 file changed +48 -28
+48 -28
--- src/branch.c
+++ src/branch.c
@@ -268,10 +268,24 @@
268268
** Usage: %fossil branch SUBCOMMAND ... ?OPTIONS?
269269
**
270270
** Run various subcommands to manage branches of the open repository or
271271
** of the repository identified by the -R or --repository option.
272272
**
273
+** fossil branch current
274
+**
275
+** Print the name of the branch for the current check-out
276
+**
277
+** fossil branch info BRANCH-NAME
278
+**
279
+** Print information about a branch
280
+**
281
+** fossil branch list|ls ?-a|--all|-c|--closed?
282
+**
283
+** List all branches. Use -a or --all to list all branches and
284
+** -c or --closed to list all closed branches. The default is to
285
+** show only open branches.
286
+**
273287
** fossil branch new BRANCH-NAME BASIS ?OPTIONS?
274288
**
275289
** Create a new branch BRANCH-NAME off of check-in BASIS.
276290
** Supported options for this subcommand include:
277291
** --private branch is private (i.e., remains local)
@@ -284,31 +298,50 @@
284298
** year-month-day form, it may be truncated, the "T" may be
285299
** replaced by a space, and it may also name a timezone offset
286300
** from UTC as "-HH:MM" (westward) or "+HH:MM" (eastward).
287301
** Either no timezone suffix or "Z" means UTC.
288302
**
289
-** fossil branch list|ls ?-a|--all|-c|--closed?
290
-**
291
-** List all branches. Use -a or --all to list all branches and
292
-** -c or --closed to list all closed branches. The default is to
293
-** show only open branches.
294
-**
295
-** fossil branch info BRANCH-NAME
296
-**
297
-** Print information about a branch
298
-**
299303
** Options:
300304
** -R|--repository FILE Run commands on repository FILE
305
+**
306
+** Summary:
307
+** fossil branch current
308
+** fossil branch info BRANCHNAME
309
+** fossil branch [list|ls]
310
+** fossil branch new
301311
*/
302312
void branch_cmd(void){
303313
int n;
304314
const char *zCmd = "list";
305315
db_find_and_open_repository(0, 0);
306316
if( g.argc>=3 ) zCmd = g.argv[2];
307317
n = strlen(zCmd);
308
- if( strncmp(zCmd,"new",n)==0 ){
309
- branch_new();
318
+ if( strncmp(zCmd,"current",n)==0 ){
319
+ if( !g.localOpen ){
320
+ fossil_fatal("not within an open checkout");
321
+ }else{
322
+ int vid = db_lget_int("checkout", 0);
323
+ char *zCurrent = db_text(0, "SELECT value FROM tagxref"
324
+ " WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH);
325
+ fossil_print("%s\n", zCurrent);
326
+ fossil_free(zCurrent);
327
+ }
328
+ }else if( strncmp(zCmd,"info",n)==0 ){
329
+ int i;
330
+ for(i=3; i<g.argc; i++){
331
+ const char *zBrName = g.argv[i];
332
+ int rid = branch_is_open(zBrName);
333
+ if( rid==0 ){
334
+ fossil_print("%s: not an open branch\n", zBrName);
335
+ }else{
336
+ const char *zUuid = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",rid);
337
+ const char *zDate = db_text(0,
338
+ "SELECT datetime(mtime,toLocal()) FROM event"
339
+ " WHERE objid=%d", rid);
340
+ fossil_print("%s: open as of %s on %.16s\n", zBrName, zDate, zUuid);
341
+ }
342
+ }
310343
}else if( (strncmp(zCmd,"list",n)==0)||(strncmp(zCmd, "ls", n)==0) ){
311344
Stmt q;
312345
int vid;
313346
char *zCurrent = 0;
314347
int brFlags = BRL_OPEN_ONLY;
@@ -325,28 +358,15 @@
325358
const char *zBr = db_column_text(&q, 0);
326359
int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0;
327360
fossil_print("%s%s\n", (isCur ? "* " : " "), zBr);
328361
}
329362
db_finalize(&q);
330
- }else if( strncmp(zCmd,"info",n)==0 ){
331
- int i;
332
- for(i=3; i<g.argc; i++){
333
- const char *zBrName = g.argv[i];
334
- int rid = branch_is_open(zBrName);
335
- if( rid==0 ){
336
- fossil_print("%s: not an open branch\n", zBrName);
337
- }else{
338
- const char *zUuid = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",rid);
339
- const char *zDate = db_text(0,
340
- "SELECT datetime(mtime,toLocal()) FROM event"
341
- " WHERE objid=%d", rid);
342
- fossil_print("%s: open as of %s on %.16s\n", zBrName, zDate, zUuid);
343
- }
344
- }
363
+ }else if( strncmp(zCmd,"new",n)==0 ){
364
+ branch_new();
345365
}else{
346366
fossil_fatal("branch subcommand should be one of: "
347
- "info list ls new");
367
+ "current info list ls new");
348368
}
349369
}
350370
351371
static const char brlistQuery[] =
352372
@ SELECT
353373
--- src/branch.c
+++ src/branch.c
@@ -268,10 +268,24 @@
268 ** Usage: %fossil branch SUBCOMMAND ... ?OPTIONS?
269 **
270 ** Run various subcommands to manage branches of the open repository or
271 ** of the repository identified by the -R or --repository option.
272 **
 
 
 
 
 
 
 
 
 
 
 
 
 
 
273 ** fossil branch new BRANCH-NAME BASIS ?OPTIONS?
274 **
275 ** Create a new branch BRANCH-NAME off of check-in BASIS.
276 ** Supported options for this subcommand include:
277 ** --private branch is private (i.e., remains local)
@@ -284,31 +298,50 @@
284 ** year-month-day form, it may be truncated, the "T" may be
285 ** replaced by a space, and it may also name a timezone offset
286 ** from UTC as "-HH:MM" (westward) or "+HH:MM" (eastward).
287 ** Either no timezone suffix or "Z" means UTC.
288 **
289 ** fossil branch list|ls ?-a|--all|-c|--closed?
290 **
291 ** List all branches. Use -a or --all to list all branches and
292 ** -c or --closed to list all closed branches. The default is to
293 ** show only open branches.
294 **
295 ** fossil branch info BRANCH-NAME
296 **
297 ** Print information about a branch
298 **
299 ** Options:
300 ** -R|--repository FILE Run commands on repository FILE
 
 
 
 
 
 
301 */
302 void branch_cmd(void){
303 int n;
304 const char *zCmd = "list";
305 db_find_and_open_repository(0, 0);
306 if( g.argc>=3 ) zCmd = g.argv[2];
307 n = strlen(zCmd);
308 if( strncmp(zCmd,"new",n)==0 ){
309 branch_new();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
310 }else if( (strncmp(zCmd,"list",n)==0)||(strncmp(zCmd, "ls", n)==0) ){
311 Stmt q;
312 int vid;
313 char *zCurrent = 0;
314 int brFlags = BRL_OPEN_ONLY;
@@ -325,28 +358,15 @@
325 const char *zBr = db_column_text(&q, 0);
326 int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0;
327 fossil_print("%s%s\n", (isCur ? "* " : " "), zBr);
328 }
329 db_finalize(&q);
330 }else if( strncmp(zCmd,"info",n)==0 ){
331 int i;
332 for(i=3; i<g.argc; i++){
333 const char *zBrName = g.argv[i];
334 int rid = branch_is_open(zBrName);
335 if( rid==0 ){
336 fossil_print("%s: not an open branch\n", zBrName);
337 }else{
338 const char *zUuid = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",rid);
339 const char *zDate = db_text(0,
340 "SELECT datetime(mtime,toLocal()) FROM event"
341 " WHERE objid=%d", rid);
342 fossil_print("%s: open as of %s on %.16s\n", zBrName, zDate, zUuid);
343 }
344 }
345 }else{
346 fossil_fatal("branch subcommand should be one of: "
347 "info list ls new");
348 }
349 }
350
351 static const char brlistQuery[] =
352 @ SELECT
353
--- src/branch.c
+++ src/branch.c
@@ -268,10 +268,24 @@
268 ** Usage: %fossil branch SUBCOMMAND ... ?OPTIONS?
269 **
270 ** Run various subcommands to manage branches of the open repository or
271 ** of the repository identified by the -R or --repository option.
272 **
273 ** fossil branch current
274 **
275 ** Print the name of the branch for the current check-out
276 **
277 ** fossil branch info BRANCH-NAME
278 **
279 ** Print information about a branch
280 **
281 ** fossil branch list|ls ?-a|--all|-c|--closed?
282 **
283 ** List all branches. Use -a or --all to list all branches and
284 ** -c or --closed to list all closed branches. The default is to
285 ** show only open branches.
286 **
287 ** fossil branch new BRANCH-NAME BASIS ?OPTIONS?
288 **
289 ** Create a new branch BRANCH-NAME off of check-in BASIS.
290 ** Supported options for this subcommand include:
291 ** --private branch is private (i.e., remains local)
@@ -284,31 +298,50 @@
298 ** year-month-day form, it may be truncated, the "T" may be
299 ** replaced by a space, and it may also name a timezone offset
300 ** from UTC as "-HH:MM" (westward) or "+HH:MM" (eastward).
301 ** Either no timezone suffix or "Z" means UTC.
302 **
 
 
 
 
 
 
 
 
 
 
303 ** Options:
304 ** -R|--repository FILE Run commands on repository FILE
305 **
306 ** Summary:
307 ** fossil branch current
308 ** fossil branch info BRANCHNAME
309 ** fossil branch [list|ls]
310 ** fossil branch new
311 */
312 void branch_cmd(void){
313 int n;
314 const char *zCmd = "list";
315 db_find_and_open_repository(0, 0);
316 if( g.argc>=3 ) zCmd = g.argv[2];
317 n = strlen(zCmd);
318 if( strncmp(zCmd,"current",n)==0 ){
319 if( !g.localOpen ){
320 fossil_fatal("not within an open checkout");
321 }else{
322 int vid = db_lget_int("checkout", 0);
323 char *zCurrent = db_text(0, "SELECT value FROM tagxref"
324 " WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH);
325 fossil_print("%s\n", zCurrent);
326 fossil_free(zCurrent);
327 }
328 }else if( strncmp(zCmd,"info",n)==0 ){
329 int i;
330 for(i=3; i<g.argc; i++){
331 const char *zBrName = g.argv[i];
332 int rid = branch_is_open(zBrName);
333 if( rid==0 ){
334 fossil_print("%s: not an open branch\n", zBrName);
335 }else{
336 const char *zUuid = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",rid);
337 const char *zDate = db_text(0,
338 "SELECT datetime(mtime,toLocal()) FROM event"
339 " WHERE objid=%d", rid);
340 fossil_print("%s: open as of %s on %.16s\n", zBrName, zDate, zUuid);
341 }
342 }
343 }else if( (strncmp(zCmd,"list",n)==0)||(strncmp(zCmd, "ls", n)==0) ){
344 Stmt q;
345 int vid;
346 char *zCurrent = 0;
347 int brFlags = BRL_OPEN_ONLY;
@@ -325,28 +358,15 @@
358 const char *zBr = db_column_text(&q, 0);
359 int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0;
360 fossil_print("%s%s\n", (isCur ? "* " : " "), zBr);
361 }
362 db_finalize(&q);
363 }else if( strncmp(zCmd,"new",n)==0 ){
364 branch_new();
 
 
 
 
 
 
 
 
 
 
 
 
 
365 }else{
366 fossil_fatal("branch subcommand should be one of: "
367 "current info list ls new");
368 }
369 }
370
371 static const char brlistQuery[] =
372 @ SELECT
373

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button