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 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: **
dbda8d6ce9 2007-07-21       drh: ** Make a clone of a repository in the local directory
dbda8d6ce9 2007-07-21       drh: **
dbda8d6ce9 2007-07-21       drh: **    fossil clone FILE-OR-URL NEWDATABASE
dbda8d6ce9 2007-07-21       drh: */
dbda8d6ce9 2007-07-21       drh: void clone_cmd(void){
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:   }
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]);
dbda8d6ce9 2007-07-21       drh:   user_select();
dbda8d6ce9 2007-07-21       drh:   db_set("content-schema", CONTENT_SCHEMA);
dbda8d6ce9 2007-07-21       drh:   db_set("aux-schema", AUX_SCHEMA);
dbda8d6ce9 2007-07-21       drh:   db_multi_exec(
dbda8d6ce9 2007-07-21       drh:     "INSERT INTO config(name,value) VALUES('server-code', hex(randomblob(20)));"
dbda8d6ce9 2007-07-21       drh:   );
dbda8d6ce9 2007-07-21       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_begin_transaction();
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:     db_end_transaction(0);
dbda8d6ce9 2007-07-21       drh:   }else{
dbda8d6ce9 2007-07-21       drh:     client_sync(0,0,1);
dbda8d6ce9 2007-07-21       drh:   }
dbda8d6ce9 2007-07-21       drh: }