Index: src/rebuild.c ================================================================== --- src/rebuild.c +++ src/rebuild.c @@ -756,12 +756,11 @@ */ void test_detach_cmd(void){ db_find_and_open_repository(0, 2); db_begin_transaction(); db_multi_exec( - "DELETE FROM config WHERE name GLOB 'last-sync-*';" - "DELETE FROM config WHERE name GLOB 'sync-*:*';" + "DELETE FROM config WHERE name='last-sync-url';" "UPDATE config SET value=lower(hex(randomblob(20)))" " WHERE name='project-code';" "UPDATE config SET value='detached-' || value" " WHERE name='project-name' AND value NOT GLOB 'detached-*';" ); @@ -913,11 +912,10 @@ } if( !privateOnly ){ db_multi_exec( "UPDATE user SET pw='';" "DELETE FROM config WHERE name GLOB 'last-sync-*';" - "DELETE FROM config WHERE name GLOB 'sync-*:*';" "DELETE FROM config WHERE name GLOB 'peer-*';" "DELETE FROM config WHERE name GLOB 'login-group-*';" "DELETE FROM config WHERE name GLOB 'skin:*';" "DELETE FROM config WHERE name GLOB 'subrepo:*';" "DELETE FROM config WHERE name GLOB 'http-auth:*';" Index: src/sync.c ================================================================== --- src/sync.c +++ src/sync.c @@ -172,11 +172,11 @@ if( g.url.protocol==0 ){ if( urlOptional ) fossil_exit(0); usage("URL"); } user_select(); - if( g.url.isAlias ){ + if( g.argc==2 ){ if( ((*pSyncFlags) & (SYNC_PUSH|SYNC_PULL))==(SYNC_PUSH|SYNC_PULL) ){ fossil_print("Sync with %s\n", g.url.canonical); }else if( (*pSyncFlags) & SYNC_PUSH ){ fossil_print("Push to %s\n", g.url.canonical); }else if( (*pSyncFlags) & SYNC_PULL ){ @@ -197,11 +197,11 @@ ** wiki pages, tickets, and tech-notes, as well as forum content. Add ** the --private option to pull private branches. Use the ** "configuration pull" command to pull website configuration details. ** ** If URL is not specified, then the URL from the most recent clone, push, -** pull, remote, or sync command is used. See "fossil help clone" for +** pull, remote-url, or sync command is used. See "fossil help clone" for ** details on the URL formats. ** ** Options: ** ** -B|--httpauth USER:PASS Credentials for the simple HTTP auth protocol, @@ -217,11 +217,11 @@ ** --ssh-command SSH Use SSH as the "ssh" command ** -v|--verbose Additional (debugging) output ** --verily Exchange extra information with the remote ** to ensure no content is overlooked ** -** See also: [[clone]], [[config]], [[push]], [[remote]], [[sync]] +** See also: [[clone]], [[config]], [[push]], [[remote-url]], [[sync]] */ void pull_cmd(void){ unsigned configFlags = 0; unsigned syncFlags = SYNC_PULL; unsigned urlOmitFlags = 0; @@ -248,11 +248,11 @@ ** wiki pages, tickets, and tech-notes, as well as forum content. Use ** --private to also push private branches. Use the "configuration ** push" command to push website configuration details. ** ** If URL is not specified, then the URL from the most recent clone, push, -** pull, remote, or sync command is used. See "fossil help clone" for +** pull, remote-url, or sync command is used. See "fossil help clone" for ** details on the URL formats. ** ** Options: ** ** -B|--httpauth USER:PASS Credentials for the simple HTTP auth protocol, @@ -266,11 +266,11 @@ ** --ssh-command SSH Use SSH as the "ssh" command ** -v|--verbose Additional (debugging) output ** --verily Exchange extra information with the remote ** to ensure no content is overlooked ** -** See also: [[clone]], [[config]], [[pull]], [[remote]], [[sync]] +** See also: [[clone]], [[config]], [[pull]], [[remote-url]], [[sync]] */ void push_cmd(void){ unsigned configFlags = 0; unsigned syncFlags = SYNC_PUSH; process_sync_args(&configFlags, &syncFlags, 0, 0); @@ -293,11 +293,11 @@ ** Synchronize all sharable changes between the local repository and a ** remote repository. Sharable changes include public check-ins and ** edits to wiki pages, tickets, and technical notes. ** ** If URL is not specified, then the URL from the most recent clone, push, -** pull, remote, or sync command is used. See "fossil help clone" for +** pull, remote-url, or sync command is used. See "fossil help clone" for ** details on the URL formats. ** ** Options: ** ** -B|--httpauth USER:PASS Credentials for the simple HTTP auth protocol, @@ -312,11 +312,11 @@ ** -u|--unversioned Also sync unversioned content ** -v|--verbose Additional (debugging) output ** --verily Exchange extra information with the remote ** to ensure no content is overlooked ** -** See also: [[clone]], [[pull]], [[push]], [[remote]] +** See also: [[clone]], [[pull]], [[push]], [[remote-url]] */ void sync_cmd(void){ unsigned configFlags = 0; unsigned syncFlags = SYNC_PUSH|SYNC_PULL; if( find_option("unversioned","u",0)!=0 ){ @@ -348,158 +348,49 @@ /* ** COMMAND: remote ** COMMAND: remote-url* ** -** Usage: %fossil remote ?SUBCOMMAND ...? -** -** Use this command to view or modify the set of remote repositories -** used as the default target for sync, push, and pull and for autosync. -** -** The default remote is set automatically by a "clone" command or by any -** "sync", "push", or "pull" command that specifies an explicit URL -** and omits the --once flag. The default remote is used by -** auto-syncing and by "sync", "push", and "pull" that omit the server URL. -** Additional remotes can be added using the "add" command or deleted -** using the "delete" command. The name of any additional remote can be -** used as an argument to the "sync", "push", and "pull" commands where -** one would normally put a URL argument. -** -** See "fossil help clone" for further information about URL formats. -** -** The official name of this command is "remote-url" but most people -** use the shortened name "remote". -** -** > fossil remote -** -** With no arguments, this command shows the current default remote. -** Or if there is no default, it shows "off". The default remote is -** used by autosync. The default remote is whatever URL was specified -** for the most recent "sync", "push", or "pull" command that omitted -** the --once option. -** -** > fossil remote add NAME URL -** -** Add a new URL to the set of remotes. The new URL is assigned the -** symbolic identifier "NAME". Subsequently, NAME can be used in place -** of the full URL on commands like "push" and "pull". -** -** > fossil remote delete NAME -** -** Delete a URL previously added by the "add" subcommand. -** -** > fossil remote list -** -** Show all remote URLs -** -** > fossil remote off -** -** Disable the default URL. Use this as a shorthand to prevent -** autosync while in airplane mode, for example. -** -** > fossil remote URL -** -** Make URL the new default URL. The prior default URL is replaced. +** Usage: %fossil remote-url ?URL|off? +** +** Query and/or change the default server URL used by the "pull", "push", +** and "sync" commands. +** +** The remote-url is set automatically by a "clone" command or by any +** "sync", "push", or "pull" command that specifies an explicit URL. +** The default remote-url is used by auto-syncing and by "sync", "push", +** "pull" that omit the server URL. +** +** See "fossil help clone" for further information about URL formats +** +** See also: clone, push, pull, sync */ void remote_url_cmd(void){ - char *zUrl, *zArg; - int nArg; + char *zUrl; db_find_and_open_repository(0, 0); /* We should be done with options.. */ verify_all_options(); - if( g.argc==2 ){ - /* "fossil remote" with no arguments: Show the last sync URL. */ - zUrl = db_get("last-sync-url", 0); - if( zUrl==0 ){ - fossil_print("off\n"); - }else{ - url_parse(zUrl, 0); - fossil_print("%s\n", g.url.canonical); - } - return; - } - zArg = g.argv[2]; - nArg = (int)strlen(zArg); - if( strcmp(zArg,"off")==0 ){ - /* fossil remote off - ** Forget the last-sync-URL and its password - */ - if( g.argc!=3 ) usage("off"); -remote_delete_default: - db_multi_exec( - "DELETE FROM config WHERE name GLOB 'last-sync-*';" - ); - return; - } - if( strncmp(zArg, "list", nArg)==0 || strcmp(zArg,"ls")==0 ){ - Stmt q; - if( g.argc!=3 ) usage("list"); - db_prepare(&q, - "SELECT 'default', value FROM config WHERE name='last-sync-url'" - " UNION ALL " - "SELECT substr(name,10), value FROM config" - " WHERE name GLOB 'sync-url:*'" - " ORDER BY 1" - ); - while( db_step(&q)==SQLITE_ROW ){ - fossil_print("%-18s %s\n", db_column_text(&q,0), db_column_text(&q,1)); - } - db_finalize(&q); - return; - } - if( strcmp(zArg, "add")==0 ){ - char *zName; - char *zUrl; - UrlData x; - if( g.argc!=5 ) usage("add NAME URL"); - memset(&x, 0, sizeof(x)); - zName = g.argv[3]; - zUrl = g.argv[4]; - if( strcmp(zName,"default")==0 ) goto remote_add_default; - url_parse_local(zUrl, URL_PROMPT_PW, &x); - db_begin_write(); - db_multi_exec( - "REPLACE INTO config(name, value, mtime)" - " VALUES('sync-url:%q',%Q,now())", - zName, x.canonical - ); - db_multi_exec( - "REPLACE INTO config(name, value, mtime)" - " VALUES('sync-pw:%q',obscure(%Q),now())", - zName, x.passwd - ); - db_commit_transaction(); - return; - } - if( strncmp(zArg, "delete", nArg)==0 ){ - char *zName; - if( g.argc!=4 ) usage("delete NAME"); - zName = g.argv[3]; - if( strcmp(zName,"default")==0 ) goto remote_delete_default; - db_begin_write(); - db_multi_exec("DELETE FROM config WHERE name glob 'sync-url:%q'", zName); - db_multi_exec("DELETE FROM config WHERE name glob 'sync-pw:%q'", zName); - db_commit_transaction(); - return; - } - if( sqlite3_strlike("http://%",zArg,0)==0 - || sqlite3_strlike("https://%",zArg,0)==0 - || sqlite3_strlike("ssh:%",zArg,0)==0 - || sqlite3_strlike("file:%",zArg,0)==0 - || db_exists("SELECT 1 FROM config WHERE name='sync-url:%q'",zArg) - ){ -remote_add_default: + if( g.argc!=2 && g.argc!=3 ){ + usage("?URL|off?"); + } + if( g.argc==3 ){ db_unset("last-sync-url", 0); db_unset("last-sync-pw", 0); + if( is_false(g.argv[2]) ) return; url_parse(g.argv[2], URL_REMEMBER|URL_PROMPT_PW|URL_ASK_REMEMBER_PW); - url_remember(); - return; } - fossil_fatal("unknown command \"%s\" - should be a URL or one of: " - "add delete list off", zArg); + url_remember(); + zUrl = db_get("last-sync-url", 0); + if( zUrl==0 ){ + fossil_print("off\n"); + return; + }else{ + url_parse(zUrl, 0); + fossil_print("%s\n", g.url.canonical); + } } /* ** COMMAND: backup* ** Index: src/url.c ================================================================== --- src/url.c +++ src/url.c @@ -47,11 +47,10 @@ */ struct UrlData { int isFile; /* True if a "file:" url */ int isHttps; /* True if a "https:" url */ int isSsh; /* True if an "ssh:" url */ - int isAlias; /* Input URL was an alias */ char *name; /* Hostname for http: or filename for file: */ char *hostname; /* The HOST: parameter on http headers */ const char *protocol; /* "http" or "https" or "ssh" */ int port; /* TCP port number for http: or https: */ int dfltPort; /* The default port for the given protocol */ @@ -68,13 +67,11 @@ }; #endif /* INTERFACE */ /* -** Parse the given URL. Or if zUrl is NULL, parse the URL in the -** last-sync-url setting using last-sync-pw as the password. Store -** the parser results in the pUrlData object. Populate members of pUrlData +** Parse the given URL. Populate members of the provided UrlData structure ** as follows: ** ** isFile True if FILE: ** isHttps True if HTTPS: ** isSsh True if SSH: @@ -86,43 +83,25 @@ ** user Userid. ** passwd Password. ** hostname HOST:PORT or just HOST if port is the default. ** canonical The URL in canonical form, omitting the password ** -** This routine differs from url_parse() in that this routine stores the -** results in pUrlData and does not change the values of global variables. -** The url_parse() routine puts its result in g.url. */ void url_parse_local( const char *zUrl, unsigned int urlFlags, UrlData *pUrlData ){ int i, j, c; char *zFile = 0; - if( zUrl==0 || strcmp(zUrl,"default")==0 ){ + if( zUrl==0 ){ zUrl = db_get("last-sync-url", 0); if( zUrl==0 ) return; if( pUrlData->passwd==0 ){ pUrlData->passwd = unobscure(db_get("last-sync-pw", 0)); } - pUrlData->isAlias = 1; - }else{ - char *zKey = sqlite3_mprintf("sync-url:%q", zUrl); - char *zAlt = db_get(zKey, 0); - sqlite3_free(zKey); - if( zAlt ){ - pUrlData->passwd = unobscure( - db_text(0, "SELECT value FROM config WHERE name='sync-pw:%q'",zUrl) - ); - zUrl = zAlt; - urlFlags |= URL_REMEMBER_PW; - pUrlData->isAlias = 1; - }else{ - pUrlData->isAlias = 0; - } } if( strncmp(zUrl, "http://", 7)==0 || strncmp(zUrl, "https://", 8)==0 || strncmp(zUrl, "ssh://", 6)==0 @@ -282,12 +261,11 @@ pUrlData->protocol = "file"; pUrlData->path = ""; pUrlData->name = mprintf("%b", &cfile); pUrlData->canonical = mprintf("file://%T", pUrlData->name); blob_reset(&cfile); - }else if( pUrlData->user!=0 && pUrlData->passwd==0 - && (urlFlags & URL_PROMPT_PW)!=0 ){ + }else if( pUrlData->user!=0 && pUrlData->passwd==0 && (urlFlags & URL_PROMPT_PW) ){ url_prompt_for_password_local(pUrlData); }else if( pUrlData->user!=0 && ( urlFlags & URL_ASK_REMEMBER_PW ) ){ if( isatty(fileno(stdin)) && ( urlFlags & URL_REMEMBER_PW )==0 ){ if( save_password_prompt(pUrlData->passwd) ){ pUrlData->flags = urlFlags |= URL_REMEMBER_PW; @@ -298,13 +276,11 @@ } } /* ** Parse the given URL, which describes a sync server. Populate variables -** in the global "g.url" structure as shown below. If zUrl is NULL, then -** parse the URL given in the last-sync-url setting, taking the password -** form last-sync-pw. +** in the global "g" structure as follows: ** ** g.url.isFile True if FILE: ** g.url.isHttps True if HTTPS: ** g.url.isSsh True if SSH: ** g.url.protocol "http" or "https" or "file"