Fossil SCM
Add the "unset" command for clearing settings.
Commit
418207989a55779c3226021079c046f8f296919b
Parent
9ba6e4287ba0db0…
1 file changed
+23
-4
M
src/db.c
+23
-4
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -941,10 +941,19 @@ | ||
| 941 | 941 | globalFlag ? "global_" : "", zName, zValue); |
| 942 | 942 | if( globalFlag && g.repositoryOpen ){ |
| 943 | 943 | db_multi_exec("DELETE FROM config WHERE name=%Q", zName); |
| 944 | 944 | } |
| 945 | 945 | db_end_transaction(0); |
| 946 | +} | |
| 947 | +void db_unset(const char *zName, int globalFlag){ | |
| 948 | + db_begin_transaction(); | |
| 949 | + db_multi_exec("DELETE FROM %sconfig WHERE name=%Q", | |
| 950 | + globalFlag ? "global_" : "", zName); | |
| 951 | + if( globalFlag && g.repositoryOpen ){ | |
| 952 | + db_multi_exec("DELETE FROM config WHERE name=%Q", zName); | |
| 953 | + } | |
| 954 | + db_end_transaction(0); | |
| 946 | 955 | } |
| 947 | 956 | int db_is_global(const char *zName){ |
| 948 | 957 | if( g.configOpen ){ |
| 949 | 958 | return db_exists("SELECT 1 FROM global_config WHERE name=%Q", zName); |
| 950 | 959 | }else{ |
| @@ -1063,15 +1072,19 @@ | ||
| 1063 | 1072 | } |
| 1064 | 1073 | |
| 1065 | 1074 | |
| 1066 | 1075 | /* |
| 1067 | 1076 | ** COMMAND: settings |
| 1077 | +** COMMAND: unset | |
| 1068 | 1078 | ** %fossil setting ?PROPERTY? ?VALUE? ?-global? |
| 1079 | +** %fossil unset PROPERTY ?-global? | |
| 1080 | +** | |
| 1081 | +** The "setting" command with no arguments lists all properties and their | |
| 1082 | +** values. With just a property name it shows the value of that property. | |
| 1083 | +** With a value argument it changes the property for the current repository. | |
| 1069 | 1084 | ** |
| 1070 | -** With no arguments, list all properties and their values. With just | |
| 1071 | -** a property name, show the value of that property. With a value | |
| 1072 | -** argument, change the property for the current repository. | |
| 1085 | +** The "unset" command clears a property setting. | |
| 1073 | 1086 | ** |
| 1074 | 1087 | ** autosync If enabled, automatically pull prior to |
| 1075 | 1088 | ** commit or update and automatically push |
| 1076 | 1089 | ** after commit or tag or branch creation. |
| 1077 | 1090 | ** |
| @@ -1110,15 +1123,19 @@ | ||
| 1110 | 1123 | "diff-command", |
| 1111 | 1124 | "gdiff-command", |
| 1112 | 1125 | }; |
| 1113 | 1126 | int i; |
| 1114 | 1127 | int globalFlag = find_option("global","g",0)!=0; |
| 1128 | + int unsetFlag = g.argv[1][0]=='u'; | |
| 1115 | 1129 | db_find_and_open_repository(0); |
| 1116 | 1130 | if( !g.repositoryOpen ){ |
| 1117 | 1131 | db_open_config(); |
| 1118 | 1132 | globalFlag = 1; |
| 1119 | 1133 | } |
| 1134 | + if( unsetFlag && g.argc!=3 ){ | |
| 1135 | + usage("PROPERTY ?-global?"); | |
| 1136 | + } | |
| 1120 | 1137 | if( g.argc==2 ){ |
| 1121 | 1138 | for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){ |
| 1122 | 1139 | print_setting(azName[i]); |
| 1123 | 1140 | } |
| 1124 | 1141 | }else if( g.argc==3 || g.argc==4 ){ |
| @@ -1128,11 +1145,13 @@ | ||
| 1128 | 1145 | if( strncmp(azName[i], zName, n)==0 ) break; |
| 1129 | 1146 | } |
| 1130 | 1147 | if( i>=sizeof(azName)/sizeof(azName[0]) ){ |
| 1131 | 1148 | fossil_fatal("no such setting: %s", zName); |
| 1132 | 1149 | } |
| 1133 | - if( g.argc==4 ){ | |
| 1150 | + if( unsetFlag ){ | |
| 1151 | + db_unset(azName[i], globalFlag); | |
| 1152 | + }else if( g.argc==4 ){ | |
| 1134 | 1153 | db_set(azName[i], g.argv[3], globalFlag); |
| 1135 | 1154 | }else{ |
| 1136 | 1155 | print_setting(azName[i]); |
| 1137 | 1156 | } |
| 1138 | 1157 | }else{ |
| 1139 | 1158 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -941,10 +941,19 @@ | |
| 941 | globalFlag ? "global_" : "", zName, zValue); |
| 942 | if( globalFlag && g.repositoryOpen ){ |
| 943 | db_multi_exec("DELETE FROM config WHERE name=%Q", zName); |
| 944 | } |
| 945 | db_end_transaction(0); |
| 946 | } |
| 947 | int db_is_global(const char *zName){ |
| 948 | if( g.configOpen ){ |
| 949 | return db_exists("SELECT 1 FROM global_config WHERE name=%Q", zName); |
| 950 | }else{ |
| @@ -1063,15 +1072,19 @@ | |
| 1063 | } |
| 1064 | |
| 1065 | |
| 1066 | /* |
| 1067 | ** COMMAND: settings |
| 1068 | ** %fossil setting ?PROPERTY? ?VALUE? ?-global? |
| 1069 | ** |
| 1070 | ** With no arguments, list all properties and their values. With just |
| 1071 | ** a property name, show the value of that property. With a value |
| 1072 | ** argument, change the property for the current repository. |
| 1073 | ** |
| 1074 | ** autosync If enabled, automatically pull prior to |
| 1075 | ** commit or update and automatically push |
| 1076 | ** after commit or tag or branch creation. |
| 1077 | ** |
| @@ -1110,15 +1123,19 @@ | |
| 1110 | "diff-command", |
| 1111 | "gdiff-command", |
| 1112 | }; |
| 1113 | int i; |
| 1114 | int globalFlag = find_option("global","g",0)!=0; |
| 1115 | db_find_and_open_repository(0); |
| 1116 | if( !g.repositoryOpen ){ |
| 1117 | db_open_config(); |
| 1118 | globalFlag = 1; |
| 1119 | } |
| 1120 | if( g.argc==2 ){ |
| 1121 | for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){ |
| 1122 | print_setting(azName[i]); |
| 1123 | } |
| 1124 | }else if( g.argc==3 || g.argc==4 ){ |
| @@ -1128,11 +1145,13 @@ | |
| 1128 | if( strncmp(azName[i], zName, n)==0 ) break; |
| 1129 | } |
| 1130 | if( i>=sizeof(azName)/sizeof(azName[0]) ){ |
| 1131 | fossil_fatal("no such setting: %s", zName); |
| 1132 | } |
| 1133 | if( g.argc==4 ){ |
| 1134 | db_set(azName[i], g.argv[3], globalFlag); |
| 1135 | }else{ |
| 1136 | print_setting(azName[i]); |
| 1137 | } |
| 1138 | }else{ |
| 1139 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -941,10 +941,19 @@ | |
| 941 | globalFlag ? "global_" : "", zName, zValue); |
| 942 | if( globalFlag && g.repositoryOpen ){ |
| 943 | db_multi_exec("DELETE FROM config WHERE name=%Q", zName); |
| 944 | } |
| 945 | db_end_transaction(0); |
| 946 | } |
| 947 | void db_unset(const char *zName, int globalFlag){ |
| 948 | db_begin_transaction(); |
| 949 | db_multi_exec("DELETE FROM %sconfig WHERE name=%Q", |
| 950 | globalFlag ? "global_" : "", zName); |
| 951 | if( globalFlag && g.repositoryOpen ){ |
| 952 | db_multi_exec("DELETE FROM config WHERE name=%Q", zName); |
| 953 | } |
| 954 | db_end_transaction(0); |
| 955 | } |
| 956 | int db_is_global(const char *zName){ |
| 957 | if( g.configOpen ){ |
| 958 | return db_exists("SELECT 1 FROM global_config WHERE name=%Q", zName); |
| 959 | }else{ |
| @@ -1063,15 +1072,19 @@ | |
| 1072 | } |
| 1073 | |
| 1074 | |
| 1075 | /* |
| 1076 | ** COMMAND: settings |
| 1077 | ** COMMAND: unset |
| 1078 | ** %fossil setting ?PROPERTY? ?VALUE? ?-global? |
| 1079 | ** %fossil unset PROPERTY ?-global? |
| 1080 | ** |
| 1081 | ** The "setting" command with no arguments lists all properties and their |
| 1082 | ** values. With just a property name it shows the value of that property. |
| 1083 | ** With a value argument it changes the property for the current repository. |
| 1084 | ** |
| 1085 | ** The "unset" command clears a property setting. |
| 1086 | ** |
| 1087 | ** autosync If enabled, automatically pull prior to |
| 1088 | ** commit or update and automatically push |
| 1089 | ** after commit or tag or branch creation. |
| 1090 | ** |
| @@ -1110,15 +1123,19 @@ | |
| 1123 | "diff-command", |
| 1124 | "gdiff-command", |
| 1125 | }; |
| 1126 | int i; |
| 1127 | int globalFlag = find_option("global","g",0)!=0; |
| 1128 | int unsetFlag = g.argv[1][0]=='u'; |
| 1129 | db_find_and_open_repository(0); |
| 1130 | if( !g.repositoryOpen ){ |
| 1131 | db_open_config(); |
| 1132 | globalFlag = 1; |
| 1133 | } |
| 1134 | if( unsetFlag && g.argc!=3 ){ |
| 1135 | usage("PROPERTY ?-global?"); |
| 1136 | } |
| 1137 | if( g.argc==2 ){ |
| 1138 | for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){ |
| 1139 | print_setting(azName[i]); |
| 1140 | } |
| 1141 | }else if( g.argc==3 || g.argc==4 ){ |
| @@ -1128,11 +1145,13 @@ | |
| 1145 | if( strncmp(azName[i], zName, n)==0 ) break; |
| 1146 | } |
| 1147 | if( i>=sizeof(azName)/sizeof(azName[0]) ){ |
| 1148 | fossil_fatal("no such setting: %s", zName); |
| 1149 | } |
| 1150 | if( unsetFlag ){ |
| 1151 | db_unset(azName[i], globalFlag); |
| 1152 | }else if( g.argc==4 ){ |
| 1153 | db_set(azName[i], g.argv[3], globalFlag); |
| 1154 | }else{ |
| 1155 | print_setting(azName[i]); |
| 1156 | } |
| 1157 | }else{ |
| 1158 |