| | @@ -679,28 +679,28 @@ |
| 679 | 679 | ** manifest is created. The makeServerCodes flag determines whether or |
| 680 | 680 | ** not server and project codes are invented for this repository. |
| 681 | 681 | */ |
| 682 | 682 | void db_initial_setup (int makeInitialVersion, int makeServerCodes){ |
| 683 | 683 | char *zDate; |
| 684 | | - char *zUser; |
| 684 | + const char *zUser; |
| 685 | 685 | Blob hash; |
| 686 | 686 | Blob manifest; |
| 687 | 687 | |
| 688 | | - db_set("content-schema", CONTENT_SCHEMA); |
| 689 | | - db_set("aux-schema", AUX_SCHEMA); |
| 688 | + db_set("content-schema", CONTENT_SCHEMA, 0); |
| 689 | + db_set("aux-schema", AUX_SCHEMA, 0); |
| 690 | 690 | if( makeServerCodes ){ |
| 691 | 691 | db_multi_exec( |
| 692 | 692 | "INSERT INTO config(name,value)" |
| 693 | 693 | " VALUES('server-code', lower(hex(randomblob(20))));" |
| 694 | 694 | "INSERT INTO config(name,value)" |
| 695 | 695 | " VALUES('project-code', lower(hex(randomblob(20))));" |
| 696 | 696 | ); |
| 697 | 697 | } |
| 698 | | - db_set_int("autosync", 1); |
| 699 | | - db_set_int("safemerge", 0); |
| 700 | | - db_set_int("localauth", 0); |
| 701 | | - zUser = db_global_get("default-user", 0); |
| 698 | + if( !db_is_global("autosync") ) db_set_int("autosync", 1, 0); |
| 699 | + if( !db_is_global("safemerge") ) db_set_int("safemerge", 0, 0); |
| 700 | + if( !db_is_global("localauth") ) db_set_int("localauth", 0, 0); |
| 701 | + zUser = db_get("default-user", 0); |
| 702 | 702 | if( zUser==0 ){ |
| 703 | 703 | zUser = getenv("USER"); |
| 704 | 704 | } |
| 705 | 705 | if( zUser==0 ){ |
| 706 | 706 | zUser = "root"; |
| | @@ -832,30 +832,62 @@ |
| 832 | 832 | |
| 833 | 833 | /* |
| 834 | 834 | ** Get and set values from the CONFIG, GLOBAL_CONFIG and VVAR table in the |
| 835 | 835 | ** repository and local databases. |
| 836 | 836 | */ |
| 837 | | -char *db_get(const char *zName, const char *zDefault){ |
| 838 | | - return db_text((char*)zDefault, |
| 839 | | - "SELECT value FROM config WHERE name=%Q", zName); |
| 837 | +const char *db_get(const char *zName, const char *zDefault){ |
| 838 | + const char *z = 0; |
| 839 | + if( g.repositoryOpen ){ |
| 840 | + z = db_text(0, "SELECT value FROM config WHERE name=%Q", zName); |
| 841 | + } |
| 842 | + if( z==0 ){ |
| 843 | + z = db_text(0, "SELECT value FROM global_config WHERE name=%Q", zName); |
| 844 | + } |
| 845 | + if( z==0 ){ |
| 846 | + z = zDefault; |
| 847 | + } |
| 848 | + return z; |
| 849 | +} |
| 850 | +void db_set(const char *zName, const char *zValue, int globalFlag){ |
| 851 | + db_begin_transaction(); |
| 852 | + db_multi_exec("REPLACE INTO %sconfig(name,value) VALUES(%Q,%Q)", |
| 853 | + globalFlag ? "global_" : "", zName, zValue); |
| 854 | + if( globalFlag && g.repositoryOpen ){ |
| 855 | + db_multi_exec("DELETE FROM config WHERE name=%Q", zName); |
| 856 | + } |
| 857 | + db_end_transaction(0); |
| 840 | 858 | } |
| 841 | | -void db_set(const char *zName, const char *zValue){ |
| 842 | | - db_multi_exec("REPLACE INTO config(name,value) VALUES(%Q,%Q)", zName, zValue); |
| 859 | +int db_is_global(const char *zName){ |
| 860 | + return db_exists("SELECT 1 FROM global_config WHERE name=%Q", zName); |
| 843 | 861 | } |
| 844 | 862 | int db_get_int(const char *zName, int dflt){ |
| 845 | | - return db_int(dflt, "SELECT value FROM config WHERE name=%Q", zName); |
| 846 | | -} |
| 847 | | -void db_set_int(const char *zName, int value){ |
| 848 | | - db_multi_exec("REPLACE INTO config(name,value) VALUES(%Q,%d)", zName, value); |
| 849 | | -} |
| 850 | | -char *db_global_get(const char *zName, const char *zDefault){ |
| 851 | | - return db_text((char*)zDefault, |
| 852 | | - "SELECT value FROM global_config WHERE name=%Q", zName); |
| 853 | | -} |
| 854 | | -void db_global_set(const char *zName, const char *zValue){ |
| 855 | | - db_multi_exec("REPLACE INTO global_config(name,value)" |
| 856 | | - "VALUES(%Q,%Q)", zName, zValue); |
| 863 | + int v; |
| 864 | + int rc; |
| 865 | + if( g.repositoryOpen ){ |
| 866 | + Stmt q; |
| 867 | + db_prepare(&q, "SELECT value FROM config WHERE name=%Q", zName); |
| 868 | + rc = db_step(&q); |
| 869 | + if( rc==SQLITE_ROW ){ |
| 870 | + v = db_column_int(&q, 0); |
| 871 | + } |
| 872 | + db_finalize(&q); |
| 873 | + }else{ |
| 874 | + rc = SQLITE_DONE; |
| 875 | + } |
| 876 | + if( rc==SQLITE_DONE ){ |
| 877 | + v = db_int(dflt, "SELECT value FROM global_config WHERE name=%Q", zName); |
| 878 | + } |
| 879 | + return v; |
| 880 | +} |
| 881 | +void db_set_int(const char *zName, int value, int globalFlag){ |
| 882 | + db_begin_transaction(); |
| 883 | + db_multi_exec("REPLACE INTO %sconfig(name,value) VALUES(%Q,%d)", |
| 884 | + globalFlag ? "global_" : "", zName, value); |
| 885 | + if( globalFlag && g.repositoryOpen ){ |
| 886 | + db_multi_exec("DELETE FROM config WHERE name=%Q", zName); |
| 887 | + } |
| 888 | + db_end_transaction(0); |
| 857 | 889 | } |
| 858 | 890 | char *db_lget(const char *zName, const char *zDefault){ |
| 859 | 891 | return db_text((char*)zDefault, |
| 860 | 892 | "SELECT value FROM vvar WHERE name=%Q", zName); |
| 861 | 893 | } |
| | @@ -904,104 +936,74 @@ |
| 904 | 936 | update_cmd(); |
| 905 | 937 | } |
| 906 | 938 | } |
| 907 | 939 | |
| 908 | 940 | /* |
| 909 | | -** COMMAND: config |
| 910 | | -** |
| 911 | | -** Usage: %fossil config NAME=VALUE ... |
| 912 | | -** |
| 913 | | -** List or change the global configuration settings. With no arguments, |
| 914 | | -** all settings are listed. Arguments of simply NAME cause that setting |
| 915 | | -** to be displayed. Arguments of the form NAME=VALUE change the value of |
| 916 | | -** a setting. Arguments of the form NAME= delete a setting. |
| 917 | | -** |
| 918 | | -** Recognized settings include: |
| 919 | | -** |
| 920 | | -** editor Text editor command used for check-in comments. |
| 921 | | -** |
| 922 | | -** clear-sign Command used to clear-sign manifests at check-in. |
| 923 | | -** The default is "gpg --clearsign -o ". |
| 924 | | -** |
| 925 | | -** omit-sign When enabled, fossil will not attempt to sign any |
| 926 | | -** commit with gpg. All commits will be unsigned. |
| 927 | | -*/ |
| 928 | | -void cmd_config(void){ |
| 929 | | - db_open_config(); |
| 930 | | - if( g.argc>2 ){ |
| 931 | | - int i; |
| 932 | | - db_begin_transaction(); |
| 933 | | - for(i=2; i<g.argc; i++){ |
| 934 | | - char *zName, *zValue; |
| 935 | | - int j, removed=0; |
| 936 | | - |
| 937 | | - zName = mprintf("%s", g.argv[i]); |
| 938 | | - for(j=0; zName[j] && zName[j]!='='; j++){} |
| 939 | | - if( zName[j] ){ |
| 940 | | - zName[j] = 0; |
| 941 | | - zValue = &zName[j+1]; |
| 942 | | - if( zValue[0] ){ |
| 943 | | - db_global_set(zName, zValue); |
| 944 | | - }else{ |
| 945 | | - db_multi_exec("DELETE FROM global_config WHERE name=%Q", zName); |
| 946 | | - removed=1; |
| 947 | | - } |
| 948 | | - } |
| 949 | | - zValue = db_global_get(zName, 0); |
| 950 | | - if( zValue ){ |
| 951 | | - printf("%s=%s\n", zName, zValue); |
| 952 | | - }else{ |
| 953 | | - if( removed==1 ){ |
| 954 | | - printf("%s has been removed from configuration\n", zName); |
| 955 | | - }else{ |
| 956 | | - printf("%s is undefined\n", zName); |
| 957 | | - } |
| 958 | | - } |
| 959 | | - } |
| 960 | | - db_end_transaction(0); |
| 961 | | - }else{ |
| 962 | | - Stmt q; |
| 963 | | - db_prepare(&q, "SELECT name, value FROM global_config ORDER BY name"); |
| 964 | | - while( db_step(&q)==SQLITE_ROW ){ |
| 965 | | - printf("%s=%s\n", db_column_text(&q, 0), db_column_text(&q, 1)); |
| 966 | | - } |
| 967 | | - db_finalize(&q); |
| 968 | | - } |
| 969 | | -} |
| 970 | | - |
| 971 | | -/* |
| 972 | | -** COMMAND: setting |
| 973 | | -** %fossil setting ?PROPERTY? ?VALUE? |
| 941 | +** Print the value of a setting named zName |
| 942 | +*/ |
| 943 | +static void print_setting(const char *zName){ |
| 944 | + Stmt q; |
| 945 | + db_prepare(&q, |
| 946 | + "SELECT '(local)', value FROM config WHERE name=%Q" |
| 947 | + " UNION ALL " |
| 948 | + "SELECT '(global)', value FROM global_config WHERE name=%Q", |
| 949 | + zName, zName |
| 950 | + ); |
| 951 | + if( db_step(&q)==SQLITE_ROW ){ |
| 952 | + printf("%-20s %-8s %s\n", zName, db_column_text(&q, 0), |
| 953 | + db_column_text(&q, 1)); |
| 954 | + }else{ |
| 955 | + printf("%-20s\n", zName); |
| 956 | + } |
| 957 | + db_finalize(&q); |
| 958 | +} |
| 959 | + |
| 960 | + |
| 961 | +/* |
| 962 | +** COMMAND: settings |
| 963 | +** %fossil setting ?PROPERTY? ?VALUE? ?-global? |
| 974 | 964 | ** |
| 975 | 965 | ** With no arguments, list all properties and their values. With just |
| 976 | 966 | ** a property name, show the value of that property. With a value |
| 977 | 967 | ** argument, change the property for the current repository. |
| 978 | 968 | ** |
| 979 | 969 | ** autosync If enabled, automatically pull prior to |
| 980 | 970 | ** commit or update and automatically push |
| 981 | 971 | ** after commit or tag or branch creation. |
| 982 | 972 | ** |
| 973 | +** clear-sign Command used to clear-sign manifests at check-in. |
| 974 | +** The default is "gpg --clearsign -o ". |
| 975 | +** |
| 976 | +** editor Text editor command used for check-in comments. |
| 977 | +** |
| 983 | 978 | ** localauth If enabled, require that HTTP connections from |
| 984 | 979 | ** 127.0.0.1 be authenticated by password. If |
| 985 | 980 | ** false, all HTTP requests from localhost have |
| 986 | 981 | ** unrestricted access to the repository. |
| 982 | +** |
| 983 | +** omit-sign When enabled, fossil will not attempt to sign any |
| 984 | +** commit with gpg. All commits will be unsigned. |
| 987 | 985 | ** |
| 988 | 986 | ** safemerge If enabled, when commit will cause a fork, the |
| 989 | 987 | ** commit will not abort with warning. Also update |
| 990 | 988 | ** will not be allowed if local changes exist. |
| 991 | 989 | */ |
| 992 | 990 | void setting_cmd(void){ |
| 993 | 991 | static const char *azName[] = { |
| 994 | 992 | "autosync", |
| 993 | + "clearsign", |
| 994 | + "editor", |
| 995 | 995 | "localauth", |
| 996 | + "omitsig", |
| 996 | 997 | "safemerge", |
| 997 | 998 | }; |
| 998 | 999 | int i; |
| 1000 | + int globalFlag = find_option("global","g",0)!=0; |
| 999 | 1001 | db_find_and_open_repository(); |
| 1000 | 1002 | if( g.argc==2 ){ |
| 1001 | 1003 | for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){ |
| 1002 | | - printf("%-20s %d\n", azName[i], db_get_int(azName[i], 0)); |
| 1004 | + print_setting(azName[i]); |
| 1003 | 1005 | } |
| 1004 | 1006 | }else if( g.argc==3 || g.argc==4 ){ |
| 1005 | 1007 | const char *zName = g.argv[2]; |
| 1006 | 1008 | int n = strlen(zName); |
| 1007 | 1009 | for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){ |
| | @@ -1009,13 +1011,13 @@ |
| 1009 | 1011 | } |
| 1010 | 1012 | if( i>=sizeof(azName)/sizeof(azName[0]) ){ |
| 1011 | 1013 | fossil_fatal("no such setting: %s", zName); |
| 1012 | 1014 | } |
| 1013 | 1015 | if( g.argc==4 ){ |
| 1014 | | - db_set(azName[i], g.argv[3]); |
| 1016 | + db_set(azName[i], g.argv[3], globalFlag); |
| 1015 | 1017 | }else{ |
| 1016 | | - printf("%-20s %d\n", azName[i], db_get_int(azName[i], 0)); |
| 1018 | + print_setting(azName[i]); |
| 1017 | 1019 | } |
| 1018 | 1020 | }else{ |
| 1019 | 1021 | usage("?PROPERTY? ?VALUE?"); |
| 1020 | 1022 | } |
| 1021 | 1023 | } |
| 1022 | 1024 | |