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. 8dbee6731d 2007-07-31 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"); 8dbee6731d 2007-07-31 drh: } 8dbee6731d 2007-07-31 drh: url_parse(zUrl); 8dbee6731d 2007-07-31 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); ce825ac954 2007-07-31 drh: } ce825ac954 2007-07-31 drh: } 8dbee6731d 2007-07-31 drh: } 8dbee6731d 2007-07-31 drh: 8dbee6731d 2007-07-31 drh: /* dbda8d6ce9 2007-07-21 drh: ** COMMAND: pull dbda8d6ce9 2007-07-21 drh: ** dbda8d6ce9 2007-07-21 drh: ** Pull changes in a remote repository into the local repository dbda8d6ce9 2007-07-21 drh: */ dbda8d6ce9 2007-07-21 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: ** dbda8d6ce9 2007-07-21 drh: ** Push changes in the local repository over into a remote repository 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: ** dbda8d6ce9 2007-07-21 drh: ** Synchronize the local repository with a remote repository 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: }