Fossil SCM

Get cloning working for local files without the use of network I/O. Ticket [b3482d580e].

drh 2008-10-05 12:34 trunk
Commit 9236f0c086010e7c7704fccdc5845e7c86f80406
2 files changed +23 -29 +18
+23 -29
--- src/clone.c
+++ src/clone.c
@@ -45,47 +45,41 @@
4545
db_open_config();
4646
if( file_size(g.argv[3])>0 ){
4747
fossil_panic("file already exists: %s", g.argv[3]);
4848
}
4949
url_parse(g.argv[2]);
50
- db_create_repository(g.argv[3]);
51
- db_open_repository(g.argv[3]);
52
- db_begin_transaction();
53
- db_initial_setup(0, 0);
54
- user_select();
55
- db_set("content-schema", CONTENT_SCHEMA, 0);
56
- db_set("aux-schema", AUX_SCHEMA, 0);
57
- if( !g.urlIsFile ){
58
- db_set("last-sync-url", g.argv[2], 0);
59
- }
60
- db_multi_exec(
61
- "INSERT INTO config(name,value)"
62
- " VALUES('server-code', lower(hex(randomblob(20))));"
63
- );
6450
if( g.urlIsFile ){
65
- Stmt q;
66
- db_multi_exec("ATTACH DATABASE %Q AS orig", g.urlName);
67
- db_prepare(&q,
68
- "SELECT name FROM orig.sqlite_master"
69
- " WHERE type='table'"
51
+ file_copy(g.urlName, g.argv[3]);
52
+ db_close();
53
+ db_open_repository(g.argv[3]);
54
+ db_multi_exec(
55
+ "REPLACE INTO config(name,value)"
56
+ " VALUES('server-code', lower(hex(randomblob(20))));"
7057
);
71
- while( db_step(&q)==SQLITE_ROW ){
72
- const char *zTab = db_column_text(&q, 0);
73
- db_multi_exec("INSERT OR IGNORE INTO %Q SELECT * FROM orig.%Q",
74
- zTab, zTab);
75
- }
76
- db_finalize(&q);
58
+ printf("Repository cloned into %s\n", g.argv[3]);
7759
}else{
60
+ db_create_repository(g.argv[3]);
61
+ db_open_repository(g.argv[3]);
62
+ db_begin_transaction();
63
+ db_initial_setup(0, 0);
64
+ user_select();
65
+ db_set("content-schema", CONTENT_SCHEMA, 0);
66
+ db_set("aux-schema", AUX_SCHEMA, 0);
67
+ db_set("last-sync-url", g.argv[2], 0);
68
+ db_multi_exec(
69
+ "REPLACE INTO config(name,value)"
70
+ " VALUES('server-code', lower(hex(randomblob(20))));"
71
+ );
7872
url_enable_proxy(0);
7973
g.xlinkClusterOnly = 1;
8074
client_sync(0,0,1,CONFIGSET_ALL);
8175
g.xlinkClusterOnly = 0;
76
+ verify_cancel();
77
+ db_end_transaction(0);
78
+ db_close();
79
+ db_open_repository(g.argv[3]);
8280
}
83
- verify_cancel();
84
- db_end_transaction(0);
85
- db_close();
86
- db_open_repository(g.argv[3]);
8781
db_begin_transaction();
8882
printf("Rebuilding repository meta-data...\n");
8983
rebuild_db(0, 1);
9084
db_end_transaction(0);
9185
}
9286
--- src/clone.c
+++ src/clone.c
@@ -45,47 +45,41 @@
45 db_open_config();
46 if( file_size(g.argv[3])>0 ){
47 fossil_panic("file already exists: %s", g.argv[3]);
48 }
49 url_parse(g.argv[2]);
50 db_create_repository(g.argv[3]);
51 db_open_repository(g.argv[3]);
52 db_begin_transaction();
53 db_initial_setup(0, 0);
54 user_select();
55 db_set("content-schema", CONTENT_SCHEMA, 0);
56 db_set("aux-schema", AUX_SCHEMA, 0);
57 if( !g.urlIsFile ){
58 db_set("last-sync-url", g.argv[2], 0);
59 }
60 db_multi_exec(
61 "INSERT INTO config(name,value)"
62 " VALUES('server-code', lower(hex(randomblob(20))));"
63 );
64 if( g.urlIsFile ){
65 Stmt q;
66 db_multi_exec("ATTACH DATABASE %Q AS orig", g.urlName);
67 db_prepare(&q,
68 "SELECT name FROM orig.sqlite_master"
69 " WHERE type='table'"
 
70 );
71 while( db_step(&q)==SQLITE_ROW ){
72 const char *zTab = db_column_text(&q, 0);
73 db_multi_exec("INSERT OR IGNORE INTO %Q SELECT * FROM orig.%Q",
74 zTab, zTab);
75 }
76 db_finalize(&q);
77 }else{
 
 
 
 
 
 
 
 
 
 
 
 
78 url_enable_proxy(0);
79 g.xlinkClusterOnly = 1;
80 client_sync(0,0,1,CONFIGSET_ALL);
81 g.xlinkClusterOnly = 0;
 
 
 
 
82 }
83 verify_cancel();
84 db_end_transaction(0);
85 db_close();
86 db_open_repository(g.argv[3]);
87 db_begin_transaction();
88 printf("Rebuilding repository meta-data...\n");
89 rebuild_db(0, 1);
90 db_end_transaction(0);
91 }
92
--- src/clone.c
+++ src/clone.c
@@ -45,47 +45,41 @@
45 db_open_config();
46 if( file_size(g.argv[3])>0 ){
47 fossil_panic("file already exists: %s", g.argv[3]);
48 }
49 url_parse(g.argv[2]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50 if( g.urlIsFile ){
51 file_copy(g.urlName, g.argv[3]);
52 db_close();
53 db_open_repository(g.argv[3]);
54 db_multi_exec(
55 "REPLACE INTO config(name,value)"
56 " VALUES('server-code', lower(hex(randomblob(20))));"
57 );
58 printf("Repository cloned into %s\n", g.argv[3]);
 
 
 
 
 
59 }else{
60 db_create_repository(g.argv[3]);
61 db_open_repository(g.argv[3]);
62 db_begin_transaction();
63 db_initial_setup(0, 0);
64 user_select();
65 db_set("content-schema", CONTENT_SCHEMA, 0);
66 db_set("aux-schema", AUX_SCHEMA, 0);
67 db_set("last-sync-url", g.argv[2], 0);
68 db_multi_exec(
69 "REPLACE INTO config(name,value)"
70 " VALUES('server-code', lower(hex(randomblob(20))));"
71 );
72 url_enable_proxy(0);
73 g.xlinkClusterOnly = 1;
74 client_sync(0,0,1,CONFIGSET_ALL);
75 g.xlinkClusterOnly = 0;
76 verify_cancel();
77 db_end_transaction(0);
78 db_close();
79 db_open_repository(g.argv[3]);
80 }
 
 
 
 
81 db_begin_transaction();
82 printf("Rebuilding repository meta-data...\n");
83 rebuild_db(0, 1);
84 db_end_transaction(0);
85 }
86
+18
--- src/file.c
+++ src/file.c
@@ -51,10 +51,28 @@
5151
if( stat(zFilename, &buf)!=0 ){
5252
return -1;
5353
}
5454
return buf.st_mtime;
5555
}
56
+
57
+/*
58
+** Copy the content of a file from one place to another.
59
+*/
60
+void file_copy(const char *zFrom, const char *zTo){
61
+ FILE *in, *out;
62
+ int got;
63
+ char zBuf[8192];
64
+ in = fopen(zFrom, "rb");
65
+ if( in==0 ) fossil_fatal("cannot open \"%s\" for reading", zFrom);
66
+ out = fopen(zTo, "wb");
67
+ if( out==0 ) fossil_fatal("cannot open \"%s\" for writing", zTo);
68
+ while( (got=fread(zBuf, 1, sizeof(zBuf), in))>0 ){
69
+ fwrite(zBuf, 1, got, out);
70
+ }
71
+ fclose(in);
72
+ fclose(out);
73
+}
5674
5775
/*
5876
** Return TRUE if the named file is an ordinary file. Return false
5977
** for directories, devices, fifos, symlinks, etc.
6078
*/
6179
--- src/file.c
+++ src/file.c
@@ -51,10 +51,28 @@
51 if( stat(zFilename, &buf)!=0 ){
52 return -1;
53 }
54 return buf.st_mtime;
55 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
57 /*
58 ** Return TRUE if the named file is an ordinary file. Return false
59 ** for directories, devices, fifos, symlinks, etc.
60 */
61
--- src/file.c
+++ src/file.c
@@ -51,10 +51,28 @@
51 if( stat(zFilename, &buf)!=0 ){
52 return -1;
53 }
54 return buf.st_mtime;
55 }
56
57 /*
58 ** Copy the content of a file from one place to another.
59 */
60 void file_copy(const char *zFrom, const char *zTo){
61 FILE *in, *out;
62 int got;
63 char zBuf[8192];
64 in = fopen(zFrom, "rb");
65 if( in==0 ) fossil_fatal("cannot open \"%s\" for reading", zFrom);
66 out = fopen(zTo, "wb");
67 if( out==0 ) fossil_fatal("cannot open \"%s\" for writing", zTo);
68 while( (got=fread(zBuf, 1, sizeof(zBuf), in))>0 ){
69 fwrite(zBuf, 1, got, out);
70 }
71 fclose(in);
72 fclose(out);
73 }
74
75 /*
76 ** Return TRUE if the named file is an ordinary file. Return false
77 ** for directories, devices, fifos, symlinks, etc.
78 */
79

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button