Fossil SCM
Remove the db_protect() handling made unnecessary by moving patch aliases into the vvar table. Fix argc count validation for (patch alias rm).
Commit
a6a679f11e3fd89620c2667fc51ea41e8e6ceba467e205c712611527005992c9
Parent
a10f55ba3ffded6…
1 file changed
+4
-7
+4
-7
| --- src/patch.c | ||
| +++ src/patch.c | ||
| @@ -705,11 +705,12 @@ | ||
| 705 | 705 | ** Resolves a patch-command remote system name, accounting for patch |
| 706 | 706 | ** aliases. |
| 707 | 707 | ** |
| 708 | 708 | ** If a VVAR table entry matching name='patch-alias:$zKey' is found, |
| 709 | 709 | ** the corresponding value is returned, else a fossil_strdup() of zKey |
| 710 | -** is returned. | |
| 710 | +** is returned. The caller is responsible for passing the resulting | |
| 711 | +** string to fossil_free(). | |
| 711 | 712 | */ |
| 712 | 713 | static char * patch_resolve_remote(const char *zKey){ |
| 713 | 714 | char * zAlias = db_text(0, "SELECT value FROM vvar " |
| 714 | 715 | "WHERE name = 'patch-alias:' || %Q", |
| 715 | 716 | zKey); |
| @@ -1062,23 +1063,20 @@ | ||
| 1062 | 1063 | /* alias add localName remote */ |
| 1063 | 1064 | verify_all_options(); |
| 1064 | 1065 | if( 6!=g.argc ){ |
| 1065 | 1066 | usage("alias add localName remote"); |
| 1066 | 1067 | } |
| 1067 | - db_unprotect(PROTECT_CONFIG); | |
| 1068 | 1068 | db_multi_exec("REPLACE INTO vvar (name, value) " |
| 1069 | 1069 | "VALUES ('patch-alias:%q', %Q)", |
| 1070 | 1070 | g.argv[4], g.argv[5]); |
| 1071 | - db_protect_pop(); | |
| 1072 | 1071 | }else if( 0==strcmp("rm", zArg) ){ |
| 1073 | 1072 | /* alias rm */ |
| 1074 | 1073 | const int fAll = 0!=find_option("all", 0, 0); |
| 1075 | - verify_all_options(); | |
| 1076 | - if( g.argc<5 ){ | |
| 1074 | + if( fAll ? g.argc<4 : g.argc<5 ){ | |
| 1077 | 1075 | usage("alias rm [-all] [aliasGlob [...aliasGlobN]]"); |
| 1078 | 1076 | } |
| 1079 | - db_unprotect(PROTECT_CONFIG); | |
| 1077 | + verify_all_options(); | |
| 1080 | 1078 | if( 0!=fAll ){ |
| 1081 | 1079 | db_multi_exec("DELETE FROM vvar WHERE name GLOB 'patch-alias:*'"); |
| 1082 | 1080 | }else{ |
| 1083 | 1081 | Stmt q; |
| 1084 | 1082 | int i; |
| @@ -1089,11 +1087,10 @@ | ||
| 1089 | 1087 | db_step(&q); |
| 1090 | 1088 | db_reset(&q); |
| 1091 | 1089 | } |
| 1092 | 1090 | db_finalize(&q); |
| 1093 | 1091 | } |
| 1094 | - db_protect_pop(); | |
| 1095 | 1092 | }else{ |
| 1096 | 1093 | usage_patch_alias: |
| 1097 | 1094 | usage("alias ls|list|add|rm ..."); |
| 1098 | 1095 | } |
| 1099 | 1096 | }else |
| 1100 | 1097 |
| --- src/patch.c | |
| +++ src/patch.c | |
| @@ -705,11 +705,12 @@ | |
| 705 | ** Resolves a patch-command remote system name, accounting for patch |
| 706 | ** aliases. |
| 707 | ** |
| 708 | ** If a VVAR table entry matching name='patch-alias:$zKey' is found, |
| 709 | ** the corresponding value is returned, else a fossil_strdup() of zKey |
| 710 | ** is returned. |
| 711 | */ |
| 712 | static char * patch_resolve_remote(const char *zKey){ |
| 713 | char * zAlias = db_text(0, "SELECT value FROM vvar " |
| 714 | "WHERE name = 'patch-alias:' || %Q", |
| 715 | zKey); |
| @@ -1062,23 +1063,20 @@ | |
| 1062 | /* alias add localName remote */ |
| 1063 | verify_all_options(); |
| 1064 | if( 6!=g.argc ){ |
| 1065 | usage("alias add localName remote"); |
| 1066 | } |
| 1067 | db_unprotect(PROTECT_CONFIG); |
| 1068 | db_multi_exec("REPLACE INTO vvar (name, value) " |
| 1069 | "VALUES ('patch-alias:%q', %Q)", |
| 1070 | g.argv[4], g.argv[5]); |
| 1071 | db_protect_pop(); |
| 1072 | }else if( 0==strcmp("rm", zArg) ){ |
| 1073 | /* alias rm */ |
| 1074 | const int fAll = 0!=find_option("all", 0, 0); |
| 1075 | verify_all_options(); |
| 1076 | if( g.argc<5 ){ |
| 1077 | usage("alias rm [-all] [aliasGlob [...aliasGlobN]]"); |
| 1078 | } |
| 1079 | db_unprotect(PROTECT_CONFIG); |
| 1080 | if( 0!=fAll ){ |
| 1081 | db_multi_exec("DELETE FROM vvar WHERE name GLOB 'patch-alias:*'"); |
| 1082 | }else{ |
| 1083 | Stmt q; |
| 1084 | int i; |
| @@ -1089,11 +1087,10 @@ | |
| 1089 | db_step(&q); |
| 1090 | db_reset(&q); |
| 1091 | } |
| 1092 | db_finalize(&q); |
| 1093 | } |
| 1094 | db_protect_pop(); |
| 1095 | }else{ |
| 1096 | usage_patch_alias: |
| 1097 | usage("alias ls|list|add|rm ..."); |
| 1098 | } |
| 1099 | }else |
| 1100 |
| --- src/patch.c | |
| +++ src/patch.c | |
| @@ -705,11 +705,12 @@ | |
| 705 | ** Resolves a patch-command remote system name, accounting for patch |
| 706 | ** aliases. |
| 707 | ** |
| 708 | ** If a VVAR table entry matching name='patch-alias:$zKey' is found, |
| 709 | ** the corresponding value is returned, else a fossil_strdup() of zKey |
| 710 | ** is returned. The caller is responsible for passing the resulting |
| 711 | ** string to fossil_free(). |
| 712 | */ |
| 713 | static char * patch_resolve_remote(const char *zKey){ |
| 714 | char * zAlias = db_text(0, "SELECT value FROM vvar " |
| 715 | "WHERE name = 'patch-alias:' || %Q", |
| 716 | zKey); |
| @@ -1062,23 +1063,20 @@ | |
| 1063 | /* alias add localName remote */ |
| 1064 | verify_all_options(); |
| 1065 | if( 6!=g.argc ){ |
| 1066 | usage("alias add localName remote"); |
| 1067 | } |
| 1068 | db_multi_exec("REPLACE INTO vvar (name, value) " |
| 1069 | "VALUES ('patch-alias:%q', %Q)", |
| 1070 | g.argv[4], g.argv[5]); |
| 1071 | }else if( 0==strcmp("rm", zArg) ){ |
| 1072 | /* alias rm */ |
| 1073 | const int fAll = 0!=find_option("all", 0, 0); |
| 1074 | if( fAll ? g.argc<4 : g.argc<5 ){ |
| 1075 | usage("alias rm [-all] [aliasGlob [...aliasGlobN]]"); |
| 1076 | } |
| 1077 | verify_all_options(); |
| 1078 | if( 0!=fAll ){ |
| 1079 | db_multi_exec("DELETE FROM vvar WHERE name GLOB 'patch-alias:*'"); |
| 1080 | }else{ |
| 1081 | Stmt q; |
| 1082 | int i; |
| @@ -1089,11 +1087,10 @@ | |
| 1087 | db_step(&q); |
| 1088 | db_reset(&q); |
| 1089 | } |
| 1090 | db_finalize(&q); |
| 1091 | } |
| 1092 | }else{ |
| 1093 | usage_patch_alias: |
| 1094 | usage("alias ls|list|add|rm ..."); |
| 1095 | } |
| 1096 | }else |
| 1097 |