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).

stephan 2025-02-28 05:44 mistake
Commit a6a679f11e3fd89620c2667fc51ea41e8e6ceba467e205c712611527005992c9
1 file changed +4 -7
+4 -7
--- src/patch.c
+++ src/patch.c
@@ -705,11 +705,12 @@
705705
** Resolves a patch-command remote system name, accounting for patch
706706
** aliases.
707707
**
708708
** If a VVAR table entry matching name='patch-alias:$zKey' is found,
709709
** 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().
711712
*/
712713
static char * patch_resolve_remote(const char *zKey){
713714
char * zAlias = db_text(0, "SELECT value FROM vvar "
714715
"WHERE name = 'patch-alias:' || %Q",
715716
zKey);
@@ -1062,23 +1063,20 @@
10621063
/* alias add localName remote */
10631064
verify_all_options();
10641065
if( 6!=g.argc ){
10651066
usage("alias add localName remote");
10661067
}
1067
- db_unprotect(PROTECT_CONFIG);
10681068
db_multi_exec("REPLACE INTO vvar (name, value) "
10691069
"VALUES ('patch-alias:%q', %Q)",
10701070
g.argv[4], g.argv[5]);
1071
- db_protect_pop();
10721071
}else if( 0==strcmp("rm", zArg) ){
10731072
/* alias rm */
10741073
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 ){
10771075
usage("alias rm [-all] [aliasGlob [...aliasGlobN]]");
10781076
}
1079
- db_unprotect(PROTECT_CONFIG);
1077
+ verify_all_options();
10801078
if( 0!=fAll ){
10811079
db_multi_exec("DELETE FROM vvar WHERE name GLOB 'patch-alias:*'");
10821080
}else{
10831081
Stmt q;
10841082
int i;
@@ -1089,11 +1087,10 @@
10891087
db_step(&q);
10901088
db_reset(&q);
10911089
}
10921090
db_finalize(&q);
10931091
}
1094
- db_protect_pop();
10951092
}else{
10961093
usage_patch_alias:
10971094
usage("alias ls|list|add|rm ...");
10981095
}
10991096
}else
11001097
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button