Fossil SCM

The push, pull, and sync commands remember the last server and reuse it if the URL argument is omitted. Sync via network only now.

drh 2007-07-31 01:34 trunk
Commit 8dbee6731d9b779a2e47b873467584f55370255b
3 files changed +3 +1 -1 +31 -70
--- src/clone.c
+++ src/clone.c
@@ -47,10 +47,13 @@
4747
db_create_repository(g.argv[3]);
4848
db_open_repository(g.argv[3]);
4949
user_select();
5050
db_set("content-schema", CONTENT_SCHEMA);
5151
db_set("aux-schema", AUX_SCHEMA);
52
+ if( !g.urlIsFile ){
53
+ db_set("last-sync-url", g.argv[2]);
54
+ }
5255
db_multi_exec(
5356
"INSERT INTO config(name,value) VALUES('server-code', hex(randomblob(20)));"
5457
);
5558
if( g.urlIsFile ){
5659
Stmt q;
5760
--- src/clone.c
+++ src/clone.c
@@ -47,10 +47,13 @@
47 db_create_repository(g.argv[3]);
48 db_open_repository(g.argv[3]);
49 user_select();
50 db_set("content-schema", CONTENT_SCHEMA);
51 db_set("aux-schema", AUX_SCHEMA);
 
 
 
52 db_multi_exec(
53 "INSERT INTO config(name,value) VALUES('server-code', hex(randomblob(20)));"
54 );
55 if( g.urlIsFile ){
56 Stmt q;
57
--- src/clone.c
+++ src/clone.c
@@ -47,10 +47,13 @@
47 db_create_repository(g.argv[3]);
48 db_open_repository(g.argv[3]);
49 user_select();
50 db_set("content-schema", CONTENT_SCHEMA);
51 db_set("aux-schema", AUX_SCHEMA);
52 if( !g.urlIsFile ){
53 db_set("last-sync-url", g.argv[2]);
54 }
55 db_multi_exec(
56 "INSERT INTO config(name,value) VALUES('server-code', hex(randomblob(20)));"
57 );
58 if( g.urlIsFile ){
59 Stmt q;
60
+1 -1
--- src/db.c
+++ src/db.c
@@ -586,11 +586,11 @@
586586
** fall back to the -R or --repository option.
587587
**
588588
** Error out if the repository cannot be opened.
589589
*/
590590
void db_find_and_open_repository(void){
591
- char *zRep = find_option("repository", "R", 1);
591
+ const char *zRep = find_option("repository", "R", 1);
592592
if( zRep==0 ){
593593
if( db_open_local()==0 ){
594594
goto rep_not_found;
595595
}
596596
zRep = db_lget("repository", 0);
597597
--- src/db.c
+++ src/db.c
@@ -586,11 +586,11 @@
586 ** fall back to the -R or --repository option.
587 **
588 ** Error out if the repository cannot be opened.
589 */
590 void db_find_and_open_repository(void){
591 char *zRep = find_option("repository", "R", 1);
592 if( zRep==0 ){
593 if( db_open_local()==0 ){
594 goto rep_not_found;
595 }
596 zRep = db_lget("repository", 0);
597
--- src/db.c
+++ src/db.c
@@ -586,11 +586,11 @@
586 ** fall back to the -R or --repository option.
587 **
588 ** Error out if the repository cannot be opened.
589 */
590 void db_find_and_open_repository(void){
591 const char *zRep = find_option("repository", "R", 1);
592 if( zRep==0 ){
593 if( db_open_local()==0 ){
594 goto rep_not_found;
595 }
596 zRep = db_lget("repository", 0);
597
+31 -70
--- src/sync.c
+++ src/sync.c
@@ -24,100 +24,61 @@
2424
** This file contains code used to push, pull, and sync a repository
2525
*/
2626
#include "config.h"
2727
#include "sync.h"
2828
#include <assert.h>
29
+
30
+/*
31
+** This routine processes the command-line argument for push, pull,
32
+** and sync. If a command-line argument is given, that is the URL
33
+** of a server to sync against. If no argument is given, use the
34
+** most recently synced URL. Remember the current URL for next time.
35
+*/
36
+static void process_sync_args(void){
37
+ const char *zUrl = 0;
38
+ db_find_and_open_repository();
39
+ if( g.argc==2 ){
40
+ zUrl = db_get("last-sync-url", 0);
41
+ }else if( g.argc==3 ){
42
+ zUrl = g.argv[2];
43
+ }
44
+ if( zUrl==0 ){
45
+ usage("URL");
46
+ }
47
+ url_parse(zUrl);
48
+ if( g.urlIsFile ){
49
+ fossil_fatal("network sync only");
50
+ }
51
+ db_set("last-sync-url", zUrl);
52
+ user_select();
53
+}
2954
3055
/*
3156
** COMMAND: pull
3257
**
3358
** Pull changes in a remote repository into the local repository
3459
*/
3560
void pull_cmd(void){
36
- if( g.argc!=3 ){
37
- usage("FILE-OR-URL");
38
- }
39
- url_parse(g.argv[2]);
40
- db_must_be_within_tree();
41
- user_select();
42
- if( g.urlIsFile ){
43
- Stmt q;
44
- char *zRemote = g.urlName;
45
- if( !file_isfile(zRemote) ){
46
- zRemote = mprintf("%s/_FOSSIL_");
47
- }
48
- if( !file_isfile(zRemote) ){
49
- fossil_panic("no such repository: %s", zRemote);
50
- }
51
- db_multi_exec("ATTACH DATABASE %Q AS other", zRemote);
52
- db_begin_transaction();
53
- db_prepare(&q,
54
- "SELECT rid FROM other.blob WHERE NOT EXISTS"
55
- " (SELECT 1 FROM blob WHERE uuid=other.blob.uuid)"
56
- );
57
- while( db_step(&q)==SQLITE_ROW ){
58
- int nrid;
59
- int rid = db_column_int(&q, 0);
60
- Blob rec;
61
- content_get_from_db(rid, &rec, "other");
62
- nrid = content_put(&rec, 0);
63
- manifest_crosslink(nrid, &rec);
64
- }
65
- db_finalize(&q);
66
- db_end_transaction(0);
67
- }else{
68
- client_sync(0,1,0);
69
- }
61
+ process_sync_args();
62
+ client_sync(0,1,0);
7063
}
7164
7265
/*
7366
** COMMAND: push
7467
**
7568
** Push changes in the local repository over into a remote repository
7669
*/
7770
void push_cmd(void){
78
- if( g.argc!=3 ){
79
- usage("FILE-OR-URL");
80
- }
81
- url_parse(g.argv[2]);
82
- db_must_be_within_tree();
83
- if( g.urlIsFile ){
84
- Blob remote;
85
- char *zRemote;
86
- file_canonical_name(g.urlName, &remote);
87
- zRemote = blob_str(&remote);
88
- if( file_isdir(zRemote)!=1 ){
89
- int i = strlen(zRemote);
90
- while( i>0 && zRemote[i]!='/' ){ i--; }
91
- zRemote[i] = 0;
92
- }
93
- if( chdir(zRemote) ){
94
- fossil_panic("unable to change the working directory to %s", zRemote);
95
- }
96
- db_close();
97
- g.argv[2] = g.zLocalRoot;
98
- pull_cmd();
99
- }else{
100
- client_sync(1,0,0);
101
- }
71
+ process_sync_args();
72
+ client_sync(1,0,0);
10273
}
10374
10475
10576
/*
10677
** COMMAND: sync
10778
**
10879
** Synchronize the local repository with a remote repository
10980
*/
11081
void sync_cmd(void){
111
- if( g.argc!=3 ){
112
- usage("FILE-OR-URL");
113
- }
114
- url_parse(g.argv[2]);
115
- if( g.urlIsFile ){
116
- pull_cmd();
117
- db_close();
118
- push_cmd();
119
- }else{
120
- db_must_be_within_tree();
121
- client_sync(1,1,0);
122
- }
82
+ process_sync_args();
83
+ client_sync(1,1,0);
12384
}
12485
--- src/sync.c
+++ src/sync.c
@@ -24,100 +24,61 @@
24 ** This file contains code used to push, pull, and sync a repository
25 */
26 #include "config.h"
27 #include "sync.h"
28 #include <assert.h>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
30 /*
31 ** COMMAND: pull
32 **
33 ** Pull changes in a remote repository into the local repository
34 */
35 void pull_cmd(void){
36 if( g.argc!=3 ){
37 usage("FILE-OR-URL");
38 }
39 url_parse(g.argv[2]);
40 db_must_be_within_tree();
41 user_select();
42 if( g.urlIsFile ){
43 Stmt q;
44 char *zRemote = g.urlName;
45 if( !file_isfile(zRemote) ){
46 zRemote = mprintf("%s/_FOSSIL_");
47 }
48 if( !file_isfile(zRemote) ){
49 fossil_panic("no such repository: %s", zRemote);
50 }
51 db_multi_exec("ATTACH DATABASE %Q AS other", zRemote);
52 db_begin_transaction();
53 db_prepare(&q,
54 "SELECT rid FROM other.blob WHERE NOT EXISTS"
55 " (SELECT 1 FROM blob WHERE uuid=other.blob.uuid)"
56 );
57 while( db_step(&q)==SQLITE_ROW ){
58 int nrid;
59 int rid = db_column_int(&q, 0);
60 Blob rec;
61 content_get_from_db(rid, &rec, "other");
62 nrid = content_put(&rec, 0);
63 manifest_crosslink(nrid, &rec);
64 }
65 db_finalize(&q);
66 db_end_transaction(0);
67 }else{
68 client_sync(0,1,0);
69 }
70 }
71
72 /*
73 ** COMMAND: push
74 **
75 ** Push changes in the local repository over into a remote repository
76 */
77 void push_cmd(void){
78 if( g.argc!=3 ){
79 usage("FILE-OR-URL");
80 }
81 url_parse(g.argv[2]);
82 db_must_be_within_tree();
83 if( g.urlIsFile ){
84 Blob remote;
85 char *zRemote;
86 file_canonical_name(g.urlName, &remote);
87 zRemote = blob_str(&remote);
88 if( file_isdir(zRemote)!=1 ){
89 int i = strlen(zRemote);
90 while( i>0 && zRemote[i]!='/' ){ i--; }
91 zRemote[i] = 0;
92 }
93 if( chdir(zRemote) ){
94 fossil_panic("unable to change the working directory to %s", zRemote);
95 }
96 db_close();
97 g.argv[2] = g.zLocalRoot;
98 pull_cmd();
99 }else{
100 client_sync(1,0,0);
101 }
102 }
103
104
105 /*
106 ** COMMAND: sync
107 **
108 ** Synchronize the local repository with a remote repository
109 */
110 void sync_cmd(void){
111 if( g.argc!=3 ){
112 usage("FILE-OR-URL");
113 }
114 url_parse(g.argv[2]);
115 if( g.urlIsFile ){
116 pull_cmd();
117 db_close();
118 push_cmd();
119 }else{
120 db_must_be_within_tree();
121 client_sync(1,1,0);
122 }
123 }
124
--- src/sync.c
+++ src/sync.c
@@ -24,100 +24,61 @@
24 ** This file contains code used to push, pull, and sync a repository
25 */
26 #include "config.h"
27 #include "sync.h"
28 #include <assert.h>
29
30 /*
31 ** This routine processes the command-line argument for push, pull,
32 ** and sync. If a command-line argument is given, that is the URL
33 ** of a server to sync against. If no argument is given, use the
34 ** most recently synced URL. Remember the current URL for next time.
35 */
36 static void process_sync_args(void){
37 const char *zUrl = 0;
38 db_find_and_open_repository();
39 if( g.argc==2 ){
40 zUrl = db_get("last-sync-url", 0);
41 }else if( g.argc==3 ){
42 zUrl = g.argv[2];
43 }
44 if( zUrl==0 ){
45 usage("URL");
46 }
47 url_parse(zUrl);
48 if( g.urlIsFile ){
49 fossil_fatal("network sync only");
50 }
51 db_set("last-sync-url", zUrl);
52 user_select();
53 }
54
55 /*
56 ** COMMAND: pull
57 **
58 ** Pull changes in a remote repository into the local repository
59 */
60 void pull_cmd(void){
61 process_sync_args();
62 client_sync(0,1,0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63 }
64
65 /*
66 ** COMMAND: push
67 **
68 ** Push changes in the local repository over into a remote repository
69 */
70 void push_cmd(void){
71 process_sync_args();
72 client_sync(1,0,0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73 }
74
75
76 /*
77 ** COMMAND: sync
78 **
79 ** Synchronize the local repository with a remote repository
80 */
81 void sync_cmd(void){
82 process_sync_args();
83 client_sync(1,1,0);
 
 
 
 
 
 
 
 
 
 
84 }
85

Keyboard Shortcuts

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