Fossil SCM
Clean up handling of global variable to avoid accidental setting of database. Only alter database options if URL is SSH.
Commit
0c1942432551ca54a811f823305da9f047786e88
Parent
3c479fb95bc006a…
4 files changed
+14
-12
+4
-4
-4
+12
-2
+14
-12
| --- src/clone.c | ||
| +++ src/clone.c | ||
| @@ -158,12 +158,12 @@ | ||
| 158 | 158 | db_multi_exec( |
| 159 | 159 | "REPLACE INTO config(name,value,mtime)" |
| 160 | 160 | " VALUES('server-code', lower(hex(randomblob(20))), now());" |
| 161 | 161 | ); |
| 162 | 162 | url_enable_proxy(0); |
| 163 | - url_get_password_if_needed(); | |
| 164 | 163 | clone_ssh_db_set_options(); |
| 164 | + url_get_password_if_needed(); | |
| 165 | 165 | g.xlinkClusterOnly = 1; |
| 166 | 166 | nErr = client_sync(SYNC_CLONE | bPrivate,CONFIGSET_ALL,0); |
| 167 | 167 | g.xlinkClusterOnly = 0; |
| 168 | 168 | verify_cancel(); |
| 169 | 169 | db_end_transaction(0); |
| @@ -213,18 +213,20 @@ | ||
| 213 | 213 | /* |
| 214 | 214 | ** Set SSH options discovered in global variables (set from command line |
| 215 | 215 | ** options). |
| 216 | 216 | */ |
| 217 | 217 | void clone_ssh_db_set_options(void){ |
| 218 | - if( g.zSshFossilCmd && g.zSshFossilCmd[0] ){ | |
| 219 | - db_set("ssh-fossil", g.zSshFossilCmd, 0); | |
| 220 | - } | |
| 221 | - if( g.zSshCmd && g.zSshCmd[0] ){ | |
| 222 | - db_set("ssh-command", g.zSshCmd, 0); | |
| 223 | - } | |
| 224 | - if( g.zFossilUser && g.zFossilUser[0] ){ | |
| 225 | - db_set("ssh-fossil-user", g.zFossilUser, 0); | |
| 226 | - } | |
| 227 | - if( g.zSshUseHttp && g.zSshUseHttp[0] ){ | |
| 228 | - db_set_int("ssh-use-http", is_truth(g.zSshUseHttp), 0); | |
| 218 | + if( g.urlIsSsh ){ | |
| 219 | + if( g.zSshFossilCmd && g.zSshFossilCmd[0] ){ | |
| 220 | + db_set("ssh-fossil", g.zSshFossilCmd, 0); | |
| 221 | + } | |
| 222 | + if( g.zSshCmd && g.zSshCmd[0] ){ | |
| 223 | + db_set("ssh-command", g.zSshCmd, 0); | |
| 224 | + } | |
| 225 | + if( g.zFossilUser && g.zFossilUser[0] ){ | |
| 226 | + db_set("ssh-fossil-user", g.zFossilUser, 0); | |
| 227 | + } | |
| 228 | + if( g.zSshUseHttp && g.zSshUseHttp[0] ){ | |
| 229 | + db_set_int("ssh-use-http", is_truth(g.zSshUseHttp), 0); | |
| 230 | + } | |
| 229 | 231 | } |
| 230 | 232 | } |
| 231 | 233 |
| --- src/clone.c | |
| +++ src/clone.c | |
| @@ -158,12 +158,12 @@ | |
| 158 | db_multi_exec( |
| 159 | "REPLACE INTO config(name,value,mtime)" |
| 160 | " VALUES('server-code', lower(hex(randomblob(20))), now());" |
| 161 | ); |
| 162 | url_enable_proxy(0); |
| 163 | url_get_password_if_needed(); |
| 164 | clone_ssh_db_set_options(); |
| 165 | g.xlinkClusterOnly = 1; |
| 166 | nErr = client_sync(SYNC_CLONE | bPrivate,CONFIGSET_ALL,0); |
| 167 | g.xlinkClusterOnly = 0; |
| 168 | verify_cancel(); |
| 169 | db_end_transaction(0); |
| @@ -213,18 +213,20 @@ | |
| 213 | /* |
| 214 | ** Set SSH options discovered in global variables (set from command line |
| 215 | ** options). |
| 216 | */ |
| 217 | void clone_ssh_db_set_options(void){ |
| 218 | if( g.zSshFossilCmd && g.zSshFossilCmd[0] ){ |
| 219 | db_set("ssh-fossil", g.zSshFossilCmd, 0); |
| 220 | } |
| 221 | if( g.zSshCmd && g.zSshCmd[0] ){ |
| 222 | db_set("ssh-command", g.zSshCmd, 0); |
| 223 | } |
| 224 | if( g.zFossilUser && g.zFossilUser[0] ){ |
| 225 | db_set("ssh-fossil-user", g.zFossilUser, 0); |
| 226 | } |
| 227 | if( g.zSshUseHttp && g.zSshUseHttp[0] ){ |
| 228 | db_set_int("ssh-use-http", is_truth(g.zSshUseHttp), 0); |
| 229 | } |
| 230 | } |
| 231 |
| --- src/clone.c | |
| +++ src/clone.c | |
| @@ -158,12 +158,12 @@ | |
| 158 | db_multi_exec( |
| 159 | "REPLACE INTO config(name,value,mtime)" |
| 160 | " VALUES('server-code', lower(hex(randomblob(20))), now());" |
| 161 | ); |
| 162 | url_enable_proxy(0); |
| 163 | clone_ssh_db_set_options(); |
| 164 | url_get_password_if_needed(); |
| 165 | g.xlinkClusterOnly = 1; |
| 166 | nErr = client_sync(SYNC_CLONE | bPrivate,CONFIGSET_ALL,0); |
| 167 | g.xlinkClusterOnly = 0; |
| 168 | verify_cancel(); |
| 169 | db_end_transaction(0); |
| @@ -213,18 +213,20 @@ | |
| 213 | /* |
| 214 | ** Set SSH options discovered in global variables (set from command line |
| 215 | ** options). |
| 216 | */ |
| 217 | void clone_ssh_db_set_options(void){ |
| 218 | if( g.urlIsSsh ){ |
| 219 | if( g.zSshFossilCmd && g.zSshFossilCmd[0] ){ |
| 220 | db_set("ssh-fossil", g.zSshFossilCmd, 0); |
| 221 | } |
| 222 | if( g.zSshCmd && g.zSshCmd[0] ){ |
| 223 | db_set("ssh-command", g.zSshCmd, 0); |
| 224 | } |
| 225 | if( g.zFossilUser && g.zFossilUser[0] ){ |
| 226 | db_set("ssh-fossil-user", g.zFossilUser, 0); |
| 227 | } |
| 228 | if( g.zSshUseHttp && g.zSshUseHttp[0] ){ |
| 229 | db_set_int("ssh-use-http", is_truth(g.zSshUseHttp), 0); |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 |
+4
-4
| --- src/sync.c | ||
| +++ src/sync.c | ||
| @@ -70,11 +70,11 @@ | ||
| 70 | 70 | configSync = CONFIGSET_SHUN; |
| 71 | 71 | } |
| 72 | 72 | #endif |
| 73 | 73 | if( find_option("verbose","v",0)!=0 ) flags |= SYNC_VERBOSE; |
| 74 | 74 | is_fossil_user() && url_ssh_use_http() ? |
| 75 | - fossil_print("Autosync: (%s) %s\n", g.zFossilUser, g.urlCanonical) : | |
| 75 | + fossil_print("Autosync: (%s) %s\n", get_fossil_user(), g.urlCanonical) : | |
| 76 | 76 | fossil_print("Autosync: %s\n", g.urlCanonical); |
| 77 | 77 | url_enable_proxy("via proxy: "); |
| 78 | 78 | rc = client_sync(flags, configSync, 0); |
| 79 | 79 | if( rc ) fossil_warning("Autosync failed"); |
| 80 | 80 | return rc; |
| @@ -127,19 +127,19 @@ | ||
| 127 | 127 | } |
| 128 | 128 | user_select(); |
| 129 | 129 | if( g.argc==2 ){ |
| 130 | 130 | if( ((*pSyncFlags) & (SYNC_PUSH|SYNC_PULL))==(SYNC_PUSH|SYNC_PULL) ){ |
| 131 | 131 | is_fossil_user() && url_ssh_use_http() ? |
| 132 | - fossil_print("Sync with (%s) %s\n", g.zFossilUser, g.urlCanonical) : | |
| 132 | + fossil_print("Sync with (%s) %s\n",get_fossil_user(),g.urlCanonical): | |
| 133 | 133 | fossil_print("Sync with %s\n", g.urlCanonical); |
| 134 | 134 | }else if( (*pSyncFlags) & SYNC_PUSH ){ |
| 135 | 135 | is_fossil_user() && url_ssh_use_http() ? |
| 136 | - fossil_print("Push to (%s) %s\n", g.zFossilUser, g.urlCanonical) : | |
| 136 | + fossil_print("Push to (%s) %s\n", get_fossil_user(), g.urlCanonical): | |
| 137 | 137 | fossil_print("Push to %s\n", g.urlCanonical); |
| 138 | 138 | }else if( (*pSyncFlags) & SYNC_PULL ){ |
| 139 | 139 | is_fossil_user() && url_ssh_use_http() ? |
| 140 | - fossil_print("Pull from (%s) %s\n", g.zFossilUser, g.urlCanonical) : | |
| 140 | + fossil_print("Pull from (%s) %s\n",get_fossil_user(),g.urlCanonical): | |
| 141 | 141 | fossil_print("Pull from %s\n", g.urlCanonical); |
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | url_enable_proxy("via proxy: "); |
| 145 | 145 | *pConfigFlags |= configSync; |
| 146 | 146 |
| --- src/sync.c | |
| +++ src/sync.c | |
| @@ -70,11 +70,11 @@ | |
| 70 | configSync = CONFIGSET_SHUN; |
| 71 | } |
| 72 | #endif |
| 73 | if( find_option("verbose","v",0)!=0 ) flags |= SYNC_VERBOSE; |
| 74 | is_fossil_user() && url_ssh_use_http() ? |
| 75 | fossil_print("Autosync: (%s) %s\n", g.zFossilUser, g.urlCanonical) : |
| 76 | fossil_print("Autosync: %s\n", g.urlCanonical); |
| 77 | url_enable_proxy("via proxy: "); |
| 78 | rc = client_sync(flags, configSync, 0); |
| 79 | if( rc ) fossil_warning("Autosync failed"); |
| 80 | return rc; |
| @@ -127,19 +127,19 @@ | |
| 127 | } |
| 128 | user_select(); |
| 129 | if( g.argc==2 ){ |
| 130 | if( ((*pSyncFlags) & (SYNC_PUSH|SYNC_PULL))==(SYNC_PUSH|SYNC_PULL) ){ |
| 131 | is_fossil_user() && url_ssh_use_http() ? |
| 132 | fossil_print("Sync with (%s) %s\n", g.zFossilUser, g.urlCanonical) : |
| 133 | fossil_print("Sync with %s\n", g.urlCanonical); |
| 134 | }else if( (*pSyncFlags) & SYNC_PUSH ){ |
| 135 | is_fossil_user() && url_ssh_use_http() ? |
| 136 | fossil_print("Push to (%s) %s\n", g.zFossilUser, g.urlCanonical) : |
| 137 | fossil_print("Push to %s\n", g.urlCanonical); |
| 138 | }else if( (*pSyncFlags) & SYNC_PULL ){ |
| 139 | is_fossil_user() && url_ssh_use_http() ? |
| 140 | fossil_print("Pull from (%s) %s\n", g.zFossilUser, g.urlCanonical) : |
| 141 | fossil_print("Pull from %s\n", g.urlCanonical); |
| 142 | } |
| 143 | } |
| 144 | url_enable_proxy("via proxy: "); |
| 145 | *pConfigFlags |= configSync; |
| 146 |
| --- src/sync.c | |
| +++ src/sync.c | |
| @@ -70,11 +70,11 @@ | |
| 70 | configSync = CONFIGSET_SHUN; |
| 71 | } |
| 72 | #endif |
| 73 | if( find_option("verbose","v",0)!=0 ) flags |= SYNC_VERBOSE; |
| 74 | is_fossil_user() && url_ssh_use_http() ? |
| 75 | fossil_print("Autosync: (%s) %s\n", get_fossil_user(), g.urlCanonical) : |
| 76 | fossil_print("Autosync: %s\n", g.urlCanonical); |
| 77 | url_enable_proxy("via proxy: "); |
| 78 | rc = client_sync(flags, configSync, 0); |
| 79 | if( rc ) fossil_warning("Autosync failed"); |
| 80 | return rc; |
| @@ -127,19 +127,19 @@ | |
| 127 | } |
| 128 | user_select(); |
| 129 | if( g.argc==2 ){ |
| 130 | if( ((*pSyncFlags) & (SYNC_PUSH|SYNC_PULL))==(SYNC_PUSH|SYNC_PULL) ){ |
| 131 | is_fossil_user() && url_ssh_use_http() ? |
| 132 | fossil_print("Sync with (%s) %s\n",get_fossil_user(),g.urlCanonical): |
| 133 | fossil_print("Sync with %s\n", g.urlCanonical); |
| 134 | }else if( (*pSyncFlags) & SYNC_PUSH ){ |
| 135 | is_fossil_user() && url_ssh_use_http() ? |
| 136 | fossil_print("Push to (%s) %s\n", get_fossil_user(), g.urlCanonical): |
| 137 | fossil_print("Push to %s\n", g.urlCanonical); |
| 138 | }else if( (*pSyncFlags) & SYNC_PULL ){ |
| 139 | is_fossil_user() && url_ssh_use_http() ? |
| 140 | fossil_print("Pull from (%s) %s\n",get_fossil_user(),g.urlCanonical): |
| 141 | fossil_print("Pull from %s\n", g.urlCanonical); |
| 142 | } |
| 143 | } |
| 144 | url_enable_proxy("via proxy: "); |
| 145 | *pConfigFlags |= configSync; |
| 146 |
-4
| --- src/url.c | ||
| +++ src/url.c | ||
| @@ -77,11 +77,10 @@ | ||
| 77 | 77 | |
| 78 | 78 | if( zUrl==0 ){ |
| 79 | 79 | zUrl = db_get("last-sync-url", 0); |
| 80 | 80 | if( zUrl==0 ) return; |
| 81 | 81 | g.urlPasswd = unobscure(db_get("last-sync-pw", 0)); |
| 82 | - g.zFossilUser = db_get("ssh-fossil-user", 0); | |
| 83 | 82 | bSetUrl = 0; |
| 84 | 83 | } |
| 85 | 84 | |
| 86 | 85 | if( strncmp(zUrl, "http://", 7)==0 |
| 87 | 86 | || strncmp(zUrl, "https://", 8)==0 |
| @@ -188,13 +187,10 @@ | ||
| 188 | 187 | } |
| 189 | 188 | }else{ |
| 190 | 189 | fossil_fatal("unknown repository: %s", zUrl); |
| 191 | 190 | } |
| 192 | 191 | g.urlFlags = urlFlags; |
| 193 | - if( g.urlIsSsh && g.zFossilUser==0 ){ | |
| 194 | - g.zFossilUser = db_get("ssh-fossil-user", 0); | |
| 195 | - } | |
| 196 | 192 | if( g.urlIsFile ){ |
| 197 | 193 | Blob cfile; |
| 198 | 194 | dehttpize(zFile); |
| 199 | 195 | file_canonical_name(zFile, &cfile, 0); |
| 200 | 196 | free(zFile); |
| 201 | 197 |
| --- src/url.c | |
| +++ src/url.c | |
| @@ -77,11 +77,10 @@ | |
| 77 | |
| 78 | if( zUrl==0 ){ |
| 79 | zUrl = db_get("last-sync-url", 0); |
| 80 | if( zUrl==0 ) return; |
| 81 | g.urlPasswd = unobscure(db_get("last-sync-pw", 0)); |
| 82 | g.zFossilUser = db_get("ssh-fossil-user", 0); |
| 83 | bSetUrl = 0; |
| 84 | } |
| 85 | |
| 86 | if( strncmp(zUrl, "http://", 7)==0 |
| 87 | || strncmp(zUrl, "https://", 8)==0 |
| @@ -188,13 +187,10 @@ | |
| 188 | } |
| 189 | }else{ |
| 190 | fossil_fatal("unknown repository: %s", zUrl); |
| 191 | } |
| 192 | g.urlFlags = urlFlags; |
| 193 | if( g.urlIsSsh && g.zFossilUser==0 ){ |
| 194 | g.zFossilUser = db_get("ssh-fossil-user", 0); |
| 195 | } |
| 196 | if( g.urlIsFile ){ |
| 197 | Blob cfile; |
| 198 | dehttpize(zFile); |
| 199 | file_canonical_name(zFile, &cfile, 0); |
| 200 | free(zFile); |
| 201 |
| --- src/url.c | |
| +++ src/url.c | |
| @@ -77,11 +77,10 @@ | |
| 77 | |
| 78 | if( zUrl==0 ){ |
| 79 | zUrl = db_get("last-sync-url", 0); |
| 80 | if( zUrl==0 ) return; |
| 81 | g.urlPasswd = unobscure(db_get("last-sync-pw", 0)); |
| 82 | bSetUrl = 0; |
| 83 | } |
| 84 | |
| 85 | if( strncmp(zUrl, "http://", 7)==0 |
| 86 | || strncmp(zUrl, "https://", 8)==0 |
| @@ -188,13 +187,10 @@ | |
| 187 | } |
| 188 | }else{ |
| 189 | fossil_fatal("unknown repository: %s", zUrl); |
| 190 | } |
| 191 | g.urlFlags = urlFlags; |
| 192 | if( g.urlIsFile ){ |
| 193 | Blob cfile; |
| 194 | dehttpize(zFile); |
| 195 | file_canonical_name(zFile, &cfile, 0); |
| 196 | free(zFile); |
| 197 |
+12
-2
| --- src/user.c | ||
| +++ src/user.c | ||
| @@ -160,18 +160,28 @@ | ||
| 160 | 160 | |
| 161 | 161 | /* |
| 162 | 162 | ** Return Fossil user if allocated and URL is SSH or URL user |
| 163 | 163 | */ |
| 164 | 164 | const char *url_or_fossil_user(void){ |
| 165 | - return is_fossil_user() ? g.zFossilUser : g.urlUser; | |
| 165 | + return is_fossil_user() ? get_fossil_user() : g.urlUser; | |
| 166 | +} | |
| 167 | + | |
| 168 | +/* | |
| 169 | +** Return the Fossil user from global variable (set from command line | |
| 170 | +** or ssh-fossil-user database setting. | |
| 171 | +*/ | |
| 172 | +const char *get_fossil_user(void){ | |
| 173 | + return ( g.zFossilUser && g.zFossilUser[0] ) ? g.zFossilUser : | |
| 174 | + db_get("ssh-fossil-user", 0); | |
| 166 | 175 | } |
| 167 | 176 | |
| 168 | 177 | /* |
| 169 | 178 | ** Return true if URL is SSH and Fossil user is allocated |
| 170 | 179 | */ |
| 171 | 180 | int is_fossil_user(void) { |
| 172 | - return g.urlIsSsh && g.zFossilUser && g.zFossilUser[0]; | |
| 181 | + return g.urlIsSsh && ( g.zFossilUser && g.zFossilUser[0] || | |
| 182 | + db_get("ssh-fossil-user", 0)!=0 ); | |
| 173 | 183 | } |
| 174 | 184 | |
| 175 | 185 | /* |
| 176 | 186 | ** Prompt the user to enter a single line of text. |
| 177 | 187 | */ |
| 178 | 188 |
| --- src/user.c | |
| +++ src/user.c | |
| @@ -160,18 +160,28 @@ | |
| 160 | |
| 161 | /* |
| 162 | ** Return Fossil user if allocated and URL is SSH or URL user |
| 163 | */ |
| 164 | const char *url_or_fossil_user(void){ |
| 165 | return is_fossil_user() ? g.zFossilUser : g.urlUser; |
| 166 | } |
| 167 | |
| 168 | /* |
| 169 | ** Return true if URL is SSH and Fossil user is allocated |
| 170 | */ |
| 171 | int is_fossil_user(void) { |
| 172 | return g.urlIsSsh && g.zFossilUser && g.zFossilUser[0]; |
| 173 | } |
| 174 | |
| 175 | /* |
| 176 | ** Prompt the user to enter a single line of text. |
| 177 | */ |
| 178 |
| --- src/user.c | |
| +++ src/user.c | |
| @@ -160,18 +160,28 @@ | |
| 160 | |
| 161 | /* |
| 162 | ** Return Fossil user if allocated and URL is SSH or URL user |
| 163 | */ |
| 164 | const char *url_or_fossil_user(void){ |
| 165 | return is_fossil_user() ? get_fossil_user() : g.urlUser; |
| 166 | } |
| 167 | |
| 168 | /* |
| 169 | ** Return the Fossil user from global variable (set from command line |
| 170 | ** or ssh-fossil-user database setting. |
| 171 | */ |
| 172 | const char *get_fossil_user(void){ |
| 173 | return ( g.zFossilUser && g.zFossilUser[0] ) ? g.zFossilUser : |
| 174 | db_get("ssh-fossil-user", 0); |
| 175 | } |
| 176 | |
| 177 | /* |
| 178 | ** Return true if URL is SSH and Fossil user is allocated |
| 179 | */ |
| 180 | int is_fossil_user(void) { |
| 181 | return g.urlIsSsh && ( g.zFossilUser && g.zFossilUser[0] || |
| 182 | db_get("ssh-fossil-user", 0)!=0 ); |
| 183 | } |
| 184 | |
| 185 | /* |
| 186 | ** Prompt the user to enter a single line of text. |
| 187 | */ |
| 188 |