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: dbda8d6ce9 2007-07-21 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. dbda8d6ce9 2007-07-21 drh: */ 8dbee6731d 2007-07-31 drh: static void process_sync_args(void){ 8dbee6731d 2007-07-31 drh: const char *zUrl = 0; 8dbee6731d 2007-07-31 drh: db_find_and_open_repository(); 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 ){ 8dbee6731d 2007-07-31 drh: usage("URL"); dbda8d6ce9 2007-07-21 drh: } 8dbee6731d 2007-07-31 drh: url_parse(zUrl); dbda8d6ce9 2007-07-21 drh: if( g.urlIsFile ){ 8dbee6731d 2007-07-31 drh: fossil_fatal("network sync only"); 8dbee6731d 2007-07-31 drh: } 8dbee6731d 2007-07-31 drh: db_set("last-sync-url", zUrl); 8dbee6731d 2007-07-31 drh: user_select(); ce825ac954 2007-07-31 drh: if( g.argc==2 ){ ce825ac954 2007-07-31 drh: if( g.urlPort!=80 ){ ce825ac954 2007-07-31 drh: printf("Server: http://%s:%d%s\n", g.urlName, g.urlPort, g.urlPath); ce825ac954 2007-07-31 drh: }else{ ce825ac954 2007-07-31 drh: printf("Server: http://%s%s\n", g.urlName, g.urlPath); dbda8d6ce9 2007-07-21 drh: } dbda8d6ce9 2007-07-21 drh: } 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: ** 6607844a01 2007-08-18 drh: ** Pull changes in a remote repository into the local repository. 6607844a01 2007-08-18 drh: ** The repository is identified by the -R or --repository option. 6607844a01 2007-08-18 drh: ** If there is no such option then the open repository is used. 6607844a01 2007-08-18 drh: ** The URL of the remote server is specified on the command line 6607844a01 2007-08-18 drh: ** If no URL is specified then the URL used by the most recent 6607844a01 2007-08-18 drh: ** "pull", "push", or "sync" command is used. 6607844a01 2007-08-18 drh: ** 6607844a01 2007-08-18 drh: ** The URL is of the following form: 6607844a01 2007-08-18 drh: ** 6607844a01 2007-08-18 drh: ** http://USER@HOST:PORT/PATH 6607844a01 2007-08-18 drh: ** 6607844a01 2007-08-18 drh: ** The "USER@" and ":PORT" substrings are optional. 6607844a01 2007-08-18 drh: ** The "USER" substring specifies the login user. You will be 6607844a01 2007-08-18 drh: ** prompted for the password on the command-line. The PORT 6607844a01 2007-08-18 drh: ** specifies the TCP port of the server. The default port is 6607844a01 2007-08-18 drh: ** 80. 8dbee6731d 2007-07-31 drh: */ 8dbee6731d 2007-07-31 drh: void pull_cmd(void){ 8dbee6731d 2007-07-31 drh: process_sync_args(); 8dbee6731d 2007-07-31 drh: client_sync(0,1,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. 6607844a01 2007-08-18 drh: ** See the "pull" command for additional information. dbda8d6ce9 2007-07-21 drh: */ dbda8d6ce9 2007-07-21 drh: void push_cmd(void){ 8dbee6731d 2007-07-31 drh: process_sync_args(); 8dbee6731d 2007-07-31 drh: client_sync(1,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. 6607844a01 2007-08-18 drh: ** See the "pull" command for additional information. dbda8d6ce9 2007-07-21 drh: */ dbda8d6ce9 2007-07-21 drh: void sync_cmd(void){ 8dbee6731d 2007-07-31 drh: process_sync_args(); 8dbee6731d 2007-07-31 drh: client_sync(1,1,0); dbda8d6ce9 2007-07-21 drh: }