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 clone a repository dbda8d6ce9 2007-07-21 drh: */ dbda8d6ce9 2007-07-21 drh: #include "config.h" dbda8d6ce9 2007-07-21 drh: #include "clone.h" dbda8d6ce9 2007-07-21 drh: #include <assert.h> 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: clone dbda8d6ce9 2007-07-21 drh: ** c9fdb846fb 2007-08-18 drh: ** Usage: %fossil clone URL FILENAME dbda8d6ce9 2007-07-21 drh: ** c9fdb846fb 2007-08-18 drh: ** Make a clone of a repository specified by URL in the local c9fdb846fb 2007-08-18 drh: ** file named FILENAME. dbda8d6ce9 2007-07-21 drh: */ dbda8d6ce9 2007-07-21 drh: void clone_cmd(void){ f652599003 2008-05-06 drh: url_proxy_options(); dbda8d6ce9 2007-07-21 drh: if( g.argc!=4 ){ dbda8d6ce9 2007-07-21 drh: usage("FILE-OR-URL NEW-REPOSITORY"); dbda8d6ce9 2007-07-21 drh: } cbe0ace8f3 2007-09-26 drh: db_open_config(); dbda8d6ce9 2007-07-21 drh: if( file_size(g.argv[3])>0 ){ dbda8d6ce9 2007-07-21 drh: fossil_panic("file already exists: %s", g.argv[3]); dbda8d6ce9 2007-07-21 drh: } dbda8d6ce9 2007-07-21 drh: url_parse(g.argv[2]); dbda8d6ce9 2007-07-21 drh: db_create_repository(g.argv[3]); dbda8d6ce9 2007-07-21 drh: db_open_repository(g.argv[3]); 097479f99a 2007-09-26 drh: db_begin_transaction(); 097479f99a 2007-09-26 drh: db_initial_setup(0, 0); dbda8d6ce9 2007-07-21 drh: user_select(); 134e2aeccc 2007-09-28 drh: db_set("content-schema", CONTENT_SCHEMA, 0); 134e2aeccc 2007-09-28 drh: db_set("aux-schema", AUX_SCHEMA, 0); 8dbee6731d 2007-07-31 drh: if( !g.urlIsFile ){ 134e2aeccc 2007-09-28 drh: db_set("last-sync-url", g.argv[2], 0); 8dbee6731d 2007-07-31 drh: } dbda8d6ce9 2007-07-21 drh: db_multi_exec( 097479f99a 2007-09-26 drh: "INSERT INTO config(name,value)" 097479f99a 2007-09-26 drh: " VALUES('server-code', lower(hex(randomblob(20))));" dbda8d6ce9 2007-07-21 drh: ); 13b7ac16e4 2007-08-09 drh: if( g.urlIsFile ){ dbda8d6ce9 2007-07-21 drh: Stmt q; dbda8d6ce9 2007-07-21 drh: db_multi_exec("ATTACH DATABASE %Q AS orig", g.urlName); dbda8d6ce9 2007-07-21 drh: db_prepare(&q, dbda8d6ce9 2007-07-21 drh: "SELECT name FROM orig.sqlite_master" dbda8d6ce9 2007-07-21 drh: " WHERE type='table'" dbda8d6ce9 2007-07-21 drh: ); dbda8d6ce9 2007-07-21 drh: while( db_step(&q)==SQLITE_ROW ){ dbda8d6ce9 2007-07-21 drh: const char *zTab = db_column_text(&q, 0); dbda8d6ce9 2007-07-21 drh: db_multi_exec("INSERT OR IGNORE INTO %Q SELECT * FROM orig.%Q", dbda8d6ce9 2007-07-21 drh: zTab, zTab); dbda8d6ce9 2007-07-21 drh: } dbda8d6ce9 2007-07-21 drh: db_finalize(&q); dbda8d6ce9 2007-07-21 drh: }else{ 676fdd088a 2008-05-01 drh: url_enable_proxy(0); dbda8d6ce9 2007-07-21 drh: client_sync(0,0,1); dbda8d6ce9 2007-07-21 drh: } 0afb5e8e39 2008-03-08 drh: verify_cancel(); 097479f99a 2007-09-26 drh: db_end_transaction(0); dbda8d6ce9 2007-07-21 drh: }