Fossil SCM
Improvements to the "fossil user default" command: Setting the default user to an empty string clears the entry from the repository and checkout databases. Adding the -v or --verbose option explains how the default user was determined.
Commit
064d20ee382ec7778a0f796c80f5e77ec6eaaacbad557255c9a28920aa3df41a
Parent
d93344ec3887514…
1 file changed
+79
-41
+79
-41
| --- src/user.c | ||
| +++ src/user.c | ||
| @@ -326,14 +326,21 @@ | ||
| 326 | 326 | ** |
| 327 | 327 | ** > fossil user contact USERNAME ?CONTACT-INFO? |
| 328 | 328 | ** |
| 329 | 329 | ** Query or set contact information for user USERNAME |
| 330 | 330 | ** |
| 331 | -** > fossil user default ?USERNAME? | |
| 331 | +** > fossil user default ?OPTIONS? ?USERNAME? | |
| 332 | 332 | ** |
| 333 | 333 | ** Query or set the default user. The default user is the |
| 334 | -** user for command-line interaction. | |
| 334 | +** user for command-line interaction. If USERNAME is an | |
| 335 | +** empty string, then the default user is unset from the | |
| 336 | +** repository and will subsequently be determined by the -U | |
| 337 | +** command-line option or by environment variables | |
| 338 | +** FOSSIL_USER, USER, LOGNAME, or USERNAME, in that order. | |
| 339 | +** OPTIONS: | |
| 340 | +** | |
| 341 | +** -v|--verbose Show how the default user is computed | |
| 335 | 342 | ** |
| 336 | 343 | ** > fossil user list | ls |
| 337 | 344 | ** |
| 338 | 345 | ** List all users known to the repository |
| 339 | 346 | ** |
| @@ -385,21 +392,50 @@ | ||
| 385 | 392 | &login, zPw, &caps, &contact |
| 386 | 393 | ); |
| 387 | 394 | db_protect_pop(); |
| 388 | 395 | free(zPw); |
| 389 | 396 | }else if( n>=2 && strncmp(g.argv[2],"default",n)==0 ){ |
| 390 | - if( g.argc==3 ){ | |
| 391 | - user_select(); | |
| 392 | - fossil_print("%s\n", g.zLogin); | |
| 393 | - }else{ | |
| 394 | - if( !db_exists("SELECT 1 FROM user WHERE login=%Q", g.argv[3]) ){ | |
| 395 | - fossil_fatal("no such user: %s", g.argv[3]); | |
| 396 | - } | |
| 397 | - if( g.localOpen ){ | |
| 398 | - db_lset("default-user", g.argv[3]); | |
| 399 | - }else{ | |
| 400 | - db_set("default-user", g.argv[3], 0); | |
| 397 | + int eVerbose = find_option("verbose","v",0)!=0; | |
| 398 | + verify_all_options(); | |
| 399 | + if( g.argc>3 ){ | |
| 400 | + const char *zUser = g.argv[3]; | |
| 401 | + if( fossil_strcmp(zUser,"")==0 || fossil_stricmp(zUser,"nobody")==0 ){ | |
| 402 | + db_begin_transaction(); | |
| 403 | + if( g.localOpen ){ | |
| 404 | + db_multi_exec("DELETE FROM vvar WHERE name='default-user'"); | |
| 405 | + } | |
| 406 | + db_unset("default-user",0); | |
| 407 | + db_commit_transaction(); | |
| 408 | + }else{ | |
| 409 | + if( !db_exists("SELECT 1 FROM user WHERE login=%Q", g.argv[3]) ){ | |
| 410 | + fossil_fatal("no such user: %s", g.argv[3]); | |
| 411 | + } | |
| 412 | + if( g.localOpen ){ | |
| 413 | + db_lset("default-user", g.argv[3]); | |
| 414 | + }else{ | |
| 415 | + db_set("default-user", g.argv[3], 0); | |
| 416 | + } | |
| 417 | + } | |
| 418 | + } | |
| 419 | + if( g.argc==3 || eVerbose ){ | |
| 420 | + int eHow = user_select(); | |
| 421 | + const char *zHow = "???"; | |
| 422 | + switch( eHow ){ | |
| 423 | + case 1: zHow = "-U option"; break; | |
| 424 | + case 2: zHow = "previously set"; break; | |
| 425 | + case 3: zHow = "local check-out"; break; | |
| 426 | + case 4: zHow = "repository"; break; | |
| 427 | + case 5: zHow = "FOSSIL_USER"; break; | |
| 428 | + case 6: zHow = "USER"; break; | |
| 429 | + case 7: zHow = "LOGNAME"; break; | |
| 430 | + case 8: zHow = "USERNAME"; break; | |
| 431 | + case 9: zHow = "URL"; break; | |
| 432 | + } | |
| 433 | + if( eVerbose ){ | |
| 434 | + fossil_print("%s (determined by %s)\n", g.zLogin, zHow); | |
| 435 | + }else{ | |
| 436 | + fossil_print("%s\n", g.zLogin); | |
| 401 | 437 | } |
| 402 | 438 | } |
| 403 | 439 | }else if(( n>=2 && strncmp(g.argv[2],"list",n)==0 ) || |
| 404 | 440 | ( n>=2 && strncmp(g.argv[2],"ls",n)==0 )){ |
| 405 | 441 | Stmt q; |
| @@ -496,52 +532,54 @@ | ||
| 496 | 532 | /* |
| 497 | 533 | ** Figure out what user is at the controls. |
| 498 | 534 | ** |
| 499 | 535 | ** (1) Use the --user and -U command-line options. |
| 500 | 536 | ** |
| 501 | -** (2) If the local database is open, check in VVAR. | |
| 502 | -** | |
| 503 | -** (3) Check the default user in the repository | |
| 504 | -** | |
| 505 | -** (4) Try the FOSSIL_USER environment variable. | |
| 506 | -** | |
| 507 | -** (5) Try the USER environment variable. | |
| 508 | -** | |
| 509 | -** (6) Try the LOGNAME environment variable. | |
| 510 | -** | |
| 511 | -** (7) Try the USERNAME environment variable. | |
| 512 | -** | |
| 513 | -** (8) Check if the user can be extracted from the remote URL. | |
| 537 | +** (2) The name used for login (if there was a login). | |
| 538 | +** | |
| 539 | +** (3) If the local database is open, check in VVAR. | |
| 540 | +** | |
| 541 | +** (4) Check the default-user in the repository | |
| 542 | +** | |
| 543 | +** (5) Try the FOSSIL_USER environment variable. | |
| 544 | +** | |
| 545 | +** (6) Try the USER environment variable. | |
| 546 | +** | |
| 547 | +** (7) Try the LOGNAME environment variable. | |
| 548 | +** | |
| 549 | +** (8) Try the USERNAME environment variable. | |
| 550 | +** | |
| 551 | +** (9) Check if the user can be extracted from the remote URL. | |
| 514 | 552 | ** |
| 515 | 553 | ** The user name is stored in g.zLogin. The uid is in g.userUid. |
| 516 | 554 | */ |
| 517 | -void user_select(void){ | |
| 555 | +int user_select(void){ | |
| 518 | 556 | UrlData url; |
| 519 | - if( g.userUid ) return; | |
| 557 | + if( g.userUid ) return 1; | |
| 520 | 558 | if( g.zLogin ){ |
| 521 | 559 | if( attempt_user(g.zLogin)==0 ){ |
| 522 | 560 | fossil_fatal("no such user: %s", g.zLogin); |
| 523 | 561 | }else{ |
| 524 | - return; | |
| 562 | + return 2; | |
| 525 | 563 | } |
| 526 | 564 | } |
| 527 | 565 | |
| 528 | - if( g.localOpen && attempt_user(db_lget("default-user",0)) ) return; | |
| 529 | - | |
| 530 | - if( attempt_user(db_get("default-user", 0)) ) return; | |
| 531 | - | |
| 532 | - if( attempt_user(fossil_getenv("FOSSIL_USER")) ) return; | |
| 533 | - | |
| 534 | - if( attempt_user(fossil_getenv("USER")) ) return; | |
| 535 | - | |
| 536 | - if( attempt_user(fossil_getenv("LOGNAME")) ) return; | |
| 537 | - | |
| 538 | - if( attempt_user(fossil_getenv("USERNAME")) ) return; | |
| 566 | + if( g.localOpen && attempt_user(db_lget("default-user",0)) ) return 3; | |
| 567 | + | |
| 568 | + if( attempt_user(db_get("default-user", 0)) ) return 4; | |
| 569 | + | |
| 570 | + if( attempt_user(fossil_getenv("FOSSIL_USER")) ) return 5; | |
| 571 | + | |
| 572 | + if( attempt_user(fossil_getenv("USER")) ) return 6; | |
| 573 | + | |
| 574 | + if( attempt_user(fossil_getenv("LOGNAME")) ) return 7; | |
| 575 | + | |
| 576 | + if( attempt_user(fossil_getenv("USERNAME")) ) return 8; | |
| 539 | 577 | |
| 540 | 578 | memset(&url, 0, sizeof(url)); |
| 541 | 579 | url_parse_local(0, URL_USE_CONFIG, &url); |
| 542 | - if( url.user && attempt_user(url.user) ) return; | |
| 580 | + if( url.user && attempt_user(url.user) ) return 9; | |
| 543 | 581 | |
| 544 | 582 | fossil_print( |
| 545 | 583 | "Cannot figure out who you are! Consider using the --user\n" |
| 546 | 584 | "command line option, setting your USER environment variable,\n" |
| 547 | 585 | "or setting a default user with \"fossil user default USER\".\n" |
| 548 | 586 |
| --- src/user.c | |
| +++ src/user.c | |
| @@ -326,14 +326,21 @@ | |
| 326 | ** |
| 327 | ** > fossil user contact USERNAME ?CONTACT-INFO? |
| 328 | ** |
| 329 | ** Query or set contact information for user USERNAME |
| 330 | ** |
| 331 | ** > fossil user default ?USERNAME? |
| 332 | ** |
| 333 | ** Query or set the default user. The default user is the |
| 334 | ** user for command-line interaction. |
| 335 | ** |
| 336 | ** > fossil user list | ls |
| 337 | ** |
| 338 | ** List all users known to the repository |
| 339 | ** |
| @@ -385,21 +392,50 @@ | |
| 385 | &login, zPw, &caps, &contact |
| 386 | ); |
| 387 | db_protect_pop(); |
| 388 | free(zPw); |
| 389 | }else if( n>=2 && strncmp(g.argv[2],"default",n)==0 ){ |
| 390 | if( g.argc==3 ){ |
| 391 | user_select(); |
| 392 | fossil_print("%s\n", g.zLogin); |
| 393 | }else{ |
| 394 | if( !db_exists("SELECT 1 FROM user WHERE login=%Q", g.argv[3]) ){ |
| 395 | fossil_fatal("no such user: %s", g.argv[3]); |
| 396 | } |
| 397 | if( g.localOpen ){ |
| 398 | db_lset("default-user", g.argv[3]); |
| 399 | }else{ |
| 400 | db_set("default-user", g.argv[3], 0); |
| 401 | } |
| 402 | } |
| 403 | }else if(( n>=2 && strncmp(g.argv[2],"list",n)==0 ) || |
| 404 | ( n>=2 && strncmp(g.argv[2],"ls",n)==0 )){ |
| 405 | Stmt q; |
| @@ -496,52 +532,54 @@ | |
| 496 | /* |
| 497 | ** Figure out what user is at the controls. |
| 498 | ** |
| 499 | ** (1) Use the --user and -U command-line options. |
| 500 | ** |
| 501 | ** (2) If the local database is open, check in VVAR. |
| 502 | ** |
| 503 | ** (3) Check the default user in the repository |
| 504 | ** |
| 505 | ** (4) Try the FOSSIL_USER environment variable. |
| 506 | ** |
| 507 | ** (5) Try the USER environment variable. |
| 508 | ** |
| 509 | ** (6) Try the LOGNAME environment variable. |
| 510 | ** |
| 511 | ** (7) Try the USERNAME environment variable. |
| 512 | ** |
| 513 | ** (8) Check if the user can be extracted from the remote URL. |
| 514 | ** |
| 515 | ** The user name is stored in g.zLogin. The uid is in g.userUid. |
| 516 | */ |
| 517 | void user_select(void){ |
| 518 | UrlData url; |
| 519 | if( g.userUid ) return; |
| 520 | if( g.zLogin ){ |
| 521 | if( attempt_user(g.zLogin)==0 ){ |
| 522 | fossil_fatal("no such user: %s", g.zLogin); |
| 523 | }else{ |
| 524 | return; |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | if( g.localOpen && attempt_user(db_lget("default-user",0)) ) return; |
| 529 | |
| 530 | if( attempt_user(db_get("default-user", 0)) ) return; |
| 531 | |
| 532 | if( attempt_user(fossil_getenv("FOSSIL_USER")) ) return; |
| 533 | |
| 534 | if( attempt_user(fossil_getenv("USER")) ) return; |
| 535 | |
| 536 | if( attempt_user(fossil_getenv("LOGNAME")) ) return; |
| 537 | |
| 538 | if( attempt_user(fossil_getenv("USERNAME")) ) return; |
| 539 | |
| 540 | memset(&url, 0, sizeof(url)); |
| 541 | url_parse_local(0, URL_USE_CONFIG, &url); |
| 542 | if( url.user && attempt_user(url.user) ) return; |
| 543 | |
| 544 | fossil_print( |
| 545 | "Cannot figure out who you are! Consider using the --user\n" |
| 546 | "command line option, setting your USER environment variable,\n" |
| 547 | "or setting a default user with \"fossil user default USER\".\n" |
| 548 |
| --- src/user.c | |
| +++ src/user.c | |
| @@ -326,14 +326,21 @@ | |
| 326 | ** |
| 327 | ** > fossil user contact USERNAME ?CONTACT-INFO? |
| 328 | ** |
| 329 | ** Query or set contact information for user USERNAME |
| 330 | ** |
| 331 | ** > fossil user default ?OPTIONS? ?USERNAME? |
| 332 | ** |
| 333 | ** Query or set the default user. The default user is the |
| 334 | ** user for command-line interaction. If USERNAME is an |
| 335 | ** empty string, then the default user is unset from the |
| 336 | ** repository and will subsequently be determined by the -U |
| 337 | ** command-line option or by environment variables |
| 338 | ** FOSSIL_USER, USER, LOGNAME, or USERNAME, in that order. |
| 339 | ** OPTIONS: |
| 340 | ** |
| 341 | ** -v|--verbose Show how the default user is computed |
| 342 | ** |
| 343 | ** > fossil user list | ls |
| 344 | ** |
| 345 | ** List all users known to the repository |
| 346 | ** |
| @@ -385,21 +392,50 @@ | |
| 392 | &login, zPw, &caps, &contact |
| 393 | ); |
| 394 | db_protect_pop(); |
| 395 | free(zPw); |
| 396 | }else if( n>=2 && strncmp(g.argv[2],"default",n)==0 ){ |
| 397 | int eVerbose = find_option("verbose","v",0)!=0; |
| 398 | verify_all_options(); |
| 399 | if( g.argc>3 ){ |
| 400 | const char *zUser = g.argv[3]; |
| 401 | if( fossil_strcmp(zUser,"")==0 || fossil_stricmp(zUser,"nobody")==0 ){ |
| 402 | db_begin_transaction(); |
| 403 | if( g.localOpen ){ |
| 404 | db_multi_exec("DELETE FROM vvar WHERE name='default-user'"); |
| 405 | } |
| 406 | db_unset("default-user",0); |
| 407 | db_commit_transaction(); |
| 408 | }else{ |
| 409 | if( !db_exists("SELECT 1 FROM user WHERE login=%Q", g.argv[3]) ){ |
| 410 | fossil_fatal("no such user: %s", g.argv[3]); |
| 411 | } |
| 412 | if( g.localOpen ){ |
| 413 | db_lset("default-user", g.argv[3]); |
| 414 | }else{ |
| 415 | db_set("default-user", g.argv[3], 0); |
| 416 | } |
| 417 | } |
| 418 | } |
| 419 | if( g.argc==3 || eVerbose ){ |
| 420 | int eHow = user_select(); |
| 421 | const char *zHow = "???"; |
| 422 | switch( eHow ){ |
| 423 | case 1: zHow = "-U option"; break; |
| 424 | case 2: zHow = "previously set"; break; |
| 425 | case 3: zHow = "local check-out"; break; |
| 426 | case 4: zHow = "repository"; break; |
| 427 | case 5: zHow = "FOSSIL_USER"; break; |
| 428 | case 6: zHow = "USER"; break; |
| 429 | case 7: zHow = "LOGNAME"; break; |
| 430 | case 8: zHow = "USERNAME"; break; |
| 431 | case 9: zHow = "URL"; break; |
| 432 | } |
| 433 | if( eVerbose ){ |
| 434 | fossil_print("%s (determined by %s)\n", g.zLogin, zHow); |
| 435 | }else{ |
| 436 | fossil_print("%s\n", g.zLogin); |
| 437 | } |
| 438 | } |
| 439 | }else if(( n>=2 && strncmp(g.argv[2],"list",n)==0 ) || |
| 440 | ( n>=2 && strncmp(g.argv[2],"ls",n)==0 )){ |
| 441 | Stmt q; |
| @@ -496,52 +532,54 @@ | |
| 532 | /* |
| 533 | ** Figure out what user is at the controls. |
| 534 | ** |
| 535 | ** (1) Use the --user and -U command-line options. |
| 536 | ** |
| 537 | ** (2) The name used for login (if there was a login). |
| 538 | ** |
| 539 | ** (3) If the local database is open, check in VVAR. |
| 540 | ** |
| 541 | ** (4) Check the default-user in the repository |
| 542 | ** |
| 543 | ** (5) Try the FOSSIL_USER environment variable. |
| 544 | ** |
| 545 | ** (6) Try the USER environment variable. |
| 546 | ** |
| 547 | ** (7) Try the LOGNAME environment variable. |
| 548 | ** |
| 549 | ** (8) Try the USERNAME environment variable. |
| 550 | ** |
| 551 | ** (9) Check if the user can be extracted from the remote URL. |
| 552 | ** |
| 553 | ** The user name is stored in g.zLogin. The uid is in g.userUid. |
| 554 | */ |
| 555 | int user_select(void){ |
| 556 | UrlData url; |
| 557 | if( g.userUid ) return 1; |
| 558 | if( g.zLogin ){ |
| 559 | if( attempt_user(g.zLogin)==0 ){ |
| 560 | fossil_fatal("no such user: %s", g.zLogin); |
| 561 | }else{ |
| 562 | return 2; |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | if( g.localOpen && attempt_user(db_lget("default-user",0)) ) return 3; |
| 567 | |
| 568 | if( attempt_user(db_get("default-user", 0)) ) return 4; |
| 569 | |
| 570 | if( attempt_user(fossil_getenv("FOSSIL_USER")) ) return 5; |
| 571 | |
| 572 | if( attempt_user(fossil_getenv("USER")) ) return 6; |
| 573 | |
| 574 | if( attempt_user(fossil_getenv("LOGNAME")) ) return 7; |
| 575 | |
| 576 | if( attempt_user(fossil_getenv("USERNAME")) ) return 8; |
| 577 | |
| 578 | memset(&url, 0, sizeof(url)); |
| 579 | url_parse_local(0, URL_USE_CONFIG, &url); |
| 580 | if( url.user && attempt_user(url.user) ) return 9; |
| 581 | |
| 582 | fossil_print( |
| 583 | "Cannot figure out who you are! Consider using the --user\n" |
| 584 | "command line option, setting your USER environment variable,\n" |
| 585 | "or setting a default user with \"fossil user default USER\".\n" |
| 586 |