Fossil SCM
New option "--brief" (or "-b") to the "fossil status" command returns a single-word that describes the status of the fossil repository in the current working directory. Useful for scripts that set the PS1 shell variable.
Commit
514149fc5b78e61c75cde72bef95d78f18983d6170ef0c65b0e2a31fff55c02c
Parent
6041e258bacae51…
1 file changed
+39
+39
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -430,10 +430,11 @@ | ||
| 430 | 430 | ** |
| 431 | 431 | ** The "fossil changes --extra" command is equivalent to "fossil extras". |
| 432 | 432 | ** |
| 433 | 433 | ** General options: |
| 434 | 434 | ** --abs-paths Display absolute pathnames |
| 435 | +** -b|--brief Show a single keyword for the status | |
| 435 | 436 | ** --rel-paths Display pathnames relative to the current working |
| 436 | 437 | ** directory |
| 437 | 438 | ** --hash Verify file status using hashing rather than |
| 438 | 439 | ** relying on file mtimes |
| 439 | 440 | ** --case-sensitive BOOL Override case-sensitive setting |
| @@ -493,10 +494,48 @@ | ||
| 493 | 494 | unsigned scanFlags = 0; |
| 494 | 495 | unsigned flags = 0; |
| 495 | 496 | int vid, i; |
| 496 | 497 | |
| 497 | 498 | fossil_pledge("stdio rpath wpath cpath fattr id flock tty chown"); |
| 499 | + | |
| 500 | + if( find_option("brief","b",0) ){ | |
| 501 | + /* The --brief or -b option is special. It cannot be used with any | |
| 502 | + ** other options. It outputs a single keyword which indicates the | |
| 503 | + ** fossil status, for use by shell scripts. The output might be | |
| 504 | + ** one of: | |
| 505 | + ** | |
| 506 | + ** clean The current working directory is within a | |
| 507 | + ** unmodified fossil check-out. | |
| 508 | + ** | |
| 509 | + ** dirty The pwd is within a fossil check-out that has | |
| 510 | + ** uncommitted changes | |
| 511 | + ** | |
| 512 | + ** none The pwd is not within a fossil check-out. | |
| 513 | + */ | |
| 514 | + int chnged; | |
| 515 | + if( g.argc>2 ){ | |
| 516 | + fossil_fatal("No other arguments or options may occur with --brief"); | |
| 517 | + } | |
| 518 | + if( db_open_local(0)==0 ){ | |
| 519 | + fossil_print("none\n"); | |
| 520 | + return; | |
| 521 | + } | |
| 522 | + vid = db_lget_int("checkout", 0); | |
| 523 | + vfile_check_signature(vid, 0); | |
| 524 | + chnged = db_int(0, | |
| 525 | + "SELECT 1 FROM vfile" | |
| 526 | + " WHERE vid=%d" | |
| 527 | + " AND (chnged>0 OR deleted OR rid==0)", | |
| 528 | + vid | |
| 529 | + ); | |
| 530 | + if( chnged ){ | |
| 531 | + fossil_print("dirty\n"); | |
| 532 | + }else{ | |
| 533 | + fossil_print("clean\n"); | |
| 534 | + } | |
| 535 | + return; | |
| 536 | + } | |
| 498 | 537 | |
| 499 | 538 | /* Load affirmative flag options. */ |
| 500 | 539 | for( i=0; i<count(flagDefs); ++i ){ |
| 501 | 540 | if( (command==CHANGES || !(flagDefs[i].mask & C_CLASSIFY)) |
| 502 | 541 | && find_option(flagDefs[i].option, 0, 0) ){ |
| 503 | 542 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -430,10 +430,11 @@ | |
| 430 | ** |
| 431 | ** The "fossil changes --extra" command is equivalent to "fossil extras". |
| 432 | ** |
| 433 | ** General options: |
| 434 | ** --abs-paths Display absolute pathnames |
| 435 | ** --rel-paths Display pathnames relative to the current working |
| 436 | ** directory |
| 437 | ** --hash Verify file status using hashing rather than |
| 438 | ** relying on file mtimes |
| 439 | ** --case-sensitive BOOL Override case-sensitive setting |
| @@ -493,10 +494,48 @@ | |
| 493 | unsigned scanFlags = 0; |
| 494 | unsigned flags = 0; |
| 495 | int vid, i; |
| 496 | |
| 497 | fossil_pledge("stdio rpath wpath cpath fattr id flock tty chown"); |
| 498 | |
| 499 | /* Load affirmative flag options. */ |
| 500 | for( i=0; i<count(flagDefs); ++i ){ |
| 501 | if( (command==CHANGES || !(flagDefs[i].mask & C_CLASSIFY)) |
| 502 | && find_option(flagDefs[i].option, 0, 0) ){ |
| 503 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -430,10 +430,11 @@ | |
| 430 | ** |
| 431 | ** The "fossil changes --extra" command is equivalent to "fossil extras". |
| 432 | ** |
| 433 | ** General options: |
| 434 | ** --abs-paths Display absolute pathnames |
| 435 | ** -b|--brief Show a single keyword for the status |
| 436 | ** --rel-paths Display pathnames relative to the current working |
| 437 | ** directory |
| 438 | ** --hash Verify file status using hashing rather than |
| 439 | ** relying on file mtimes |
| 440 | ** --case-sensitive BOOL Override case-sensitive setting |
| @@ -493,10 +494,48 @@ | |
| 494 | unsigned scanFlags = 0; |
| 495 | unsigned flags = 0; |
| 496 | int vid, i; |
| 497 | |
| 498 | fossil_pledge("stdio rpath wpath cpath fattr id flock tty chown"); |
| 499 | |
| 500 | if( find_option("brief","b",0) ){ |
| 501 | /* The --brief or -b option is special. It cannot be used with any |
| 502 | ** other options. It outputs a single keyword which indicates the |
| 503 | ** fossil status, for use by shell scripts. The output might be |
| 504 | ** one of: |
| 505 | ** |
| 506 | ** clean The current working directory is within a |
| 507 | ** unmodified fossil check-out. |
| 508 | ** |
| 509 | ** dirty The pwd is within a fossil check-out that has |
| 510 | ** uncommitted changes |
| 511 | ** |
| 512 | ** none The pwd is not within a fossil check-out. |
| 513 | */ |
| 514 | int chnged; |
| 515 | if( g.argc>2 ){ |
| 516 | fossil_fatal("No other arguments or options may occur with --brief"); |
| 517 | } |
| 518 | if( db_open_local(0)==0 ){ |
| 519 | fossil_print("none\n"); |
| 520 | return; |
| 521 | } |
| 522 | vid = db_lget_int("checkout", 0); |
| 523 | vfile_check_signature(vid, 0); |
| 524 | chnged = db_int(0, |
| 525 | "SELECT 1 FROM vfile" |
| 526 | " WHERE vid=%d" |
| 527 | " AND (chnged>0 OR deleted OR rid==0)", |
| 528 | vid |
| 529 | ); |
| 530 | if( chnged ){ |
| 531 | fossil_print("dirty\n"); |
| 532 | }else{ |
| 533 | fossil_print("clean\n"); |
| 534 | } |
| 535 | return; |
| 536 | } |
| 537 | |
| 538 | /* Load affirmative flag options. */ |
| 539 | for( i=0; i<count(flagDefs); ++i ){ |
| 540 | if( (command==CHANGES || !(flagDefs[i].mask & C_CLASSIFY)) |
| 541 | && find_option(flagDefs[i].option, 0, 0) ){ |
| 542 |