File Annotation
Not logged in
dbda8d6ce9 2007-07-21       drh: /*
dbda8d6ce9 2007-07-21       drh: ** Copyright (c) 2007 D. Richard Hipp
dbda8d6ce9 2007-07-21       drh: **
dbda8d6ce9 2007-07-21       drh: ** This program is free software; you can redistribute it and/or
dbda8d6ce9 2007-07-21       drh: ** modify it under the terms of the GNU General Public
dbda8d6ce9 2007-07-21       drh: ** License version 2 as published by the Free Software Foundation.
dbda8d6ce9 2007-07-21       drh: **
dbda8d6ce9 2007-07-21       drh: ** This program is distributed in the hope that it will be useful,
dbda8d6ce9 2007-07-21       drh: ** but WITHOUT ANY WARRANTY; without even the implied warranty of
dbda8d6ce9 2007-07-21       drh: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
dbda8d6ce9 2007-07-21       drh: ** General Public License for more details.
dbda8d6ce9 2007-07-21       drh: **
dbda8d6ce9 2007-07-21       drh: ** You should have received a copy of the GNU General Public
dbda8d6ce9 2007-07-21       drh: ** License along with this library; if not, write to the
dbda8d6ce9 2007-07-21       drh: ** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
dbda8d6ce9 2007-07-21       drh: ** Boston, MA  02111-1307, USA.
dbda8d6ce9 2007-07-21       drh: **
dbda8d6ce9 2007-07-21       drh: ** Author contact information:
dbda8d6ce9 2007-07-21       drh: **   drh@hwaci.com
dbda8d6ce9 2007-07-21       drh: **   http://www.hwaci.com/drh/
dbda8d6ce9 2007-07-21       drh: **
dbda8d6ce9 2007-07-21       drh: *******************************************************************************
dbda8d6ce9 2007-07-21       drh: **
dbda8d6ce9 2007-07-21       drh: ** This file contains code used to push, pull, and sync a repository
dbda8d6ce9 2007-07-21       drh: */
dbda8d6ce9 2007-07-21       drh: #include "config.h"
dbda8d6ce9 2007-07-21       drh: #include "sync.h"
dbda8d6ce9 2007-07-21       drh: #include <assert.h>
dbda8d6ce9 2007-07-21       drh: 
49b59bc559 2008-02-09       drh: #if INTERFACE
49b59bc559 2008-02-09       drh: /*
49b59bc559 2008-02-09       drh: ** Flags used to determine which direction(s) an autosync goes in.
49b59bc559 2008-02-09       drh: */
49b59bc559 2008-02-09       drh: #define AUTOSYNC_PUSH  1
49b59bc559 2008-02-09       drh: #define AUTOSYNC_PULL  2
49b59bc559 2008-02-09       drh: 
49b59bc559 2008-02-09       drh: #endif /* INTERFACE */
49b59bc559 2008-02-09       drh: 
dbda8d6ce9 2007-07-21       drh: /*
fff234b77c 2007-09-25       drh: ** If the respository is configured for autosyncing, then do an
fff234b77c 2007-09-25       drh: ** autosync.  This will be a pull if the argument is true or a push
908009fdc4 2008-05-07       drh: ** if the argument is false.
dbda8d6ce9 2007-07-21       drh: */
908009fdc4 2008-05-07       drh: void autosync(int flags){
fff234b77c 2007-09-25       drh:   const char *zUrl;
9ba6e4287b 2008-05-10       drh:   if( g.fNoSync ){
9ba6e4287b 2008-05-10       drh:     return;
9ba6e4287b 2008-05-10       drh:   }
f9f7cf5684 2007-11-24       drh:   if( db_get_boolean("autosync", 0)==0 ){
908009fdc4 2008-05-07       drh:     return;
fff234b77c 2007-09-25       drh:   }
fff234b77c 2007-09-25       drh:   zUrl = db_get("last-sync-url", 0);
097479f99a 2007-09-26       drh:   if( zUrl==0 ){
908009fdc4 2008-05-07       drh:     return;  /* No default server */
dbda8d6ce9 2007-07-21       drh:   }
fff234b77c 2007-09-25       drh:   url_parse(zUrl);
797d680ef5 2009-01-13       drh:   if( g.urlPort!=g.urlDfltPort ){
797d680ef5 2009-01-13       drh:     printf("Autosync:  %s://%s:%d%s\n",
797d680ef5 2009-01-13       drh:             g.urlProtocol, g.urlName, g.urlPort, g.urlPath);
dbda8d6ce9 2007-07-21       drh:   }else{
797d680ef5 2009-01-13       drh:     printf("Autosync:  %s://%s%s\n", g.urlProtocol, g.urlName, g.urlPath);
b773dda29b 2007-09-25       jnc:   }
676fdd088a 2008-05-01       drh:   url_enable_proxy("via proxy: ");
6b0b57a924 2008-10-25       drh:   client_sync((flags & AUTOSYNC_PUSH)!=0, 1, 0, 0, 0);
b773dda29b 2007-09-25       jnc: }
b773dda29b 2007-09-25       jnc: 
8dbee6731d 2007-07-31       drh: /*
8dbee6731d 2007-07-31       drh: ** This routine processes the command-line argument for push, pull,
8dbee6731d 2007-07-31       drh: ** and sync.  If a command-line argument is given, that is the URL
8dbee6731d 2007-07-31       drh: ** of a server to sync against.  If no argument is given, use the
8dbee6731d 2007-07-31       drh: ** most recently synced URL.  Remember the current URL for next time.
8dbee6731d 2007-07-31       drh: */
28e56282c9 2008-05-23       drh: void process_sync_args(void){
8dbee6731d 2007-07-31       drh:   const char *zUrl = 0;
9346f2290c 2008-10-17       drh:   int urlOptional = find_option("autourl",0,0)!=0;
f652599003 2008-05-06       drh:   url_proxy_options();
4e683ef07b 2008-05-05       drh:   db_find_and_open_repository(1);
8dbee6731d 2007-07-31       drh:   if( g.argc==2 ){
8dbee6731d 2007-07-31       drh:     zUrl = db_get("last-sync-url", 0);
8dbee6731d 2007-07-31       drh:   }else if( g.argc==3 ){
8dbee6731d 2007-07-31       drh:     zUrl = g.argv[2];
8dbee6731d 2007-07-31       drh:   }
8dbee6731d 2007-07-31       drh:   if( zUrl==0 ){
9346f2290c 2008-10-17       drh:     if( urlOptional ) exit(0);
8dbee6731d 2007-07-31       drh:     usage("URL");
8dbee6731d 2007-07-31       drh:   }
8dbee6731d 2007-07-31       drh:   url_parse(zUrl);
47d8fc4944 2009-08-01       drh:   db_set("last-sync-url", g.urlIsFile ? g.urlCanonical : zUrl, 0);
8dbee6731d 2007-07-31       drh:   user_select();
ce825ac954 2007-07-31       drh:   if( g.argc==2 ){
797d680ef5 2009-01-13       drh:     if( g.urlPort!=g.urlDfltPort ){
797d680ef5 2009-01-13       drh:       printf("Server:    %s://%s:%d%s\n",
797d680ef5 2009-01-13       drh:               g.urlProtocol, g.urlName, g.urlPort, g.urlPath);
ce825ac954 2007-07-31       drh:     }else{
797d680ef5 2009-01-13       drh:       printf("Server:    %s://%s%s\n", g.urlProtocol, g.urlName, g.urlPath);
ce825ac954 2007-07-31       drh:     }
dbda8d6ce9 2007-07-21       drh:   }
676fdd088a 2008-05-01       drh:   url_enable_proxy("via proxy: ");
8dbee6731d 2007-07-31       drh: }
8dbee6731d 2007-07-31       drh: 
8dbee6731d 2007-07-31       drh: /*
8dbee6731d 2007-07-31       drh: ** COMMAND: pull
8dbee6731d 2007-07-31       drh: **
6607844a01 2007-08-18       drh: ** Usage: %fossil pull ?URL? ?-R|--respository REPOSITORY?
6607844a01 2007-08-18       drh: **
6a40733531 2009-09-04       drh: ** Pull changes from a remote repository into the local repository.
6a40733531 2009-09-04       drh: **
6a40733531 2009-09-04       drh: ** If the URL is not specified, then the URL from the most recent
6a40733531 2009-09-04       drh: ** clone, push, pull, remote-url, or sync command is used.
6a40733531 2009-09-04       drh: **
6a40733531 2009-09-04       drh: ** See also: clone, push, sync, remote-url
8dbee6731d 2007-07-31       drh: */
8dbee6731d 2007-07-31       drh: void pull_cmd(void){
8dbee6731d 2007-07-31       drh:   process_sync_args();
6b0b57a924 2008-10-25       drh:   client_sync(0,1,0,0,0);
dbda8d6ce9 2007-07-21       drh: }
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh: /*
dbda8d6ce9 2007-07-21       drh: ** COMMAND: push
dbda8d6ce9 2007-07-21       drh: **
6607844a01 2007-08-18       drh: ** Usage: %fossil push ?URL? ?-R|--repository REPOSITORY?
6607844a01 2007-08-18       drh: **
6607844a01 2007-08-18       drh: ** Push changes in the local repository over into a remote repository.
6a40733531 2009-09-04       drh: **
6a40733531 2009-09-04       drh: ** If the URL is not specified, then the URL from the most recent
6a40733531 2009-09-04       drh: ** clone, push, pull, remote-url, or sync command is used.
6a40733531 2009-09-04       drh: **
6a40733531 2009-09-04       drh: ** See also: clone, pull, sync, remote-url
dbda8d6ce9 2007-07-21       drh: */
dbda8d6ce9 2007-07-21       drh: void push_cmd(void){
8dbee6731d 2007-07-31       drh:   process_sync_args();
6b0b57a924 2008-10-25       drh:   client_sync(1,0,0,0,0);
dbda8d6ce9 2007-07-21       drh: }
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh: /*
dbda8d6ce9 2007-07-21       drh: ** COMMAND: sync
dbda8d6ce9 2007-07-21       drh: **
6607844a01 2007-08-18       drh: ** Usage: %fossil sync ?URL? ?-R|--repository REPOSITORY?
6607844a01 2007-08-18       drh: **
6607844a01 2007-08-18       drh: ** Synchronize the local repository with a remote repository.  This is
6607844a01 2007-08-18       drh: ** the equivalent of running both "push" and "pull" at the same time.
6a40733531 2009-09-04       drh: **
6a40733531 2009-09-04       drh: ** If a user-id and password are required, specify them as follows:
6a40733531 2009-09-04       drh: **
6a40733531 2009-09-04       drh: **     http://userid:password@www.domain.com:1234/path
6a40733531 2009-09-04       drh: **
6a40733531 2009-09-04       drh: ** If the URL is not specified, then the URL from the most recent successful
6a40733531 2009-09-04       drh: ** clone, push, pull, remote-url, or sync command is used.
6a40733531 2009-09-04       drh: **
6a40733531 2009-09-04       drh: ** See also:  clone, push, pull, remote-url
dbda8d6ce9 2007-07-21       drh: */
dbda8d6ce9 2007-07-21       drh: void sync_cmd(void){
8dbee6731d 2007-07-31       drh:   process_sync_args();
6b0b57a924 2008-10-25       drh:   client_sync(1,1,0,0,0);
a2cbedcb1f 2009-08-01       drh: }
a2cbedcb1f 2009-08-01       drh: 
a2cbedcb1f 2009-08-01       drh: /*
a2cbedcb1f 2009-08-01       drh: ** COMMAND: remote-url
a2cbedcb1f 2009-08-01       drh: **
9cbef7a104 2009-08-13       drh: ** Usage: %fossil remote-url ?URL|off? --show-pw
a2cbedcb1f 2009-08-01       drh: **
6a40733531 2009-09-04       drh: ** Query and/or change the default server URL used by the "pull", "push",
6a40733531 2009-09-04       drh: ** and "sync" commands.
a2cbedcb1f 2009-08-01       drh: **
6a40733531 2009-09-04       drh: ** The userid and password are of the URL are not printed unless
6a40733531 2009-09-04       drh: ** the --show-pw option is used on the command-line.
a2cbedcb1f 2009-08-01       drh: **
a2cbedcb1f 2009-08-01       drh: ** The remote-url is set automatically by a "clone" command or by any
a2cbedcb1f 2009-08-01       drh: ** "sync", "push", or "pull" command that specifies an explicit URL.
a2cbedcb1f 2009-08-01       drh: ** The default remote-url is used by auto-syncing and by "sync", "push",
a2cbedcb1f 2009-08-01       drh: ** "pull" that omit the server URL.
6a40733531 2009-09-04       drh: **
6a40733531 2009-09-04       drh: ** See also: clone, push, pull, sync
a2cbedcb1f 2009-08-01       drh: */
a2cbedcb1f 2009-08-01       drh: void remote_url_cmd(void){
9cbef7a104 2009-08-13       drh:   char *zUrl;
9cbef7a104 2009-08-13       drh:   int showPw = find_option("show-pw",0,0)!=0;
614519b46c 2009-08-22       drh:   db_find_and_open_repository(1);
a2cbedcb1f 2009-08-01       drh:   if( g.argc!=2 && g.argc!=3 ){
a2cbedcb1f 2009-08-01       drh:     usage("remote-url ?URL|off?");
a2cbedcb1f 2009-08-01       drh:   }
a2cbedcb1f 2009-08-01       drh:   if( g.argc==3 ){
a2cbedcb1f 2009-08-01       drh:     if( strcmp(g.argv[2],"off")==0 ){
a2cbedcb1f 2009-08-01       drh:       db_unset("last-sync-url", 0);
a2cbedcb1f 2009-08-01       drh:     }else{
a2cbedcb1f 2009-08-01       drh:       url_parse(g.argv[2]);
11ecd5c0b5 2009-10-31       drh:       db_set("last-sync-url", g.urlIsFile ? g.urlCanonical : g.argv[2], 0);
a2cbedcb1f 2009-08-01       drh:     }
dbda8d6ce9 2007-07-21       drh:   }
9cbef7a104 2009-08-13       drh:   zUrl = db_get("last-sync-url", 0);
9cbef7a104 2009-08-13       drh:   if( zUrl==0 ){
9cbef7a104 2009-08-13       drh:     printf("off\n");
9cbef7a104 2009-08-13       drh:     return;
9cbef7a104 2009-08-13       drh:   }else if( showPw ){
9cbef7a104 2009-08-13       drh:     g.urlCanonical = zUrl;
dbda8d6ce9 2007-07-21       drh:   }else{
9cbef7a104 2009-08-13       drh:     url_parse(zUrl);
dbda8d6ce9 2007-07-21       drh:   }
9cbef7a104 2009-08-13       drh:   printf("%s\n", g.urlCanonical);
dbda8d6ce9 2007-07-21       drh: }