Fossil SCM

Add the --all option to "fossil sync" and similar, causing the sync to occur against all remote repositories shown in "fossil remote list".

drh 2021-10-24 19:47 trunk
Commit 6b4a04d4494faae2ad66bb54d85616b058000f43500a1122b25da508a04e8992
2 files changed +76 -12 +1
+76 -12
--- src/sync.c
+++ src/sync.c
@@ -18,10 +18,72 @@
1818
** This file contains code used to push, pull, and sync a repository
1919
*/
2020
#include "config.h"
2121
#include "sync.h"
2222
#include <assert.h>
23
+
24
+/*
25
+** Explain what type of sync operation is about to occur
26
+*/
27
+static void sync_explain(unsigned syncFlags){
28
+ if( g.url.isAlias ){
29
+ if( (syncFlags & (SYNC_PUSH|SYNC_PULL))==(SYNC_PUSH|SYNC_PULL) ){
30
+ fossil_print("Sync with %s\n", g.url.canonical);
31
+ }else if( syncFlags & SYNC_PUSH ){
32
+ fossil_print("Push to %s\n", g.url.canonical);
33
+ }else if( syncFlags & SYNC_PULL ){
34
+ fossil_print("Pull from %s\n", g.url.canonical);
35
+ }
36
+ }
37
+}
38
+
39
+
40
+/*
41
+** Call client_sync() one or more times in order to complete a
42
+** sync operation. Usually, client_sync() is called only once, though
43
+** is can be called multiple times if the SYNC_ALLURL flags is set.
44
+*/
45
+static int client_sync_all_urls(
46
+ unsigned syncFlags, /* Mask of SYNC_* flags */
47
+ unsigned configRcvMask, /* Receive these configuration items */
48
+ unsigned configSendMask, /* Send these configuration items */
49
+ const char *zAltPCode /* Alternative project code (usually NULL) */
50
+){
51
+ int nErr;
52
+ int nOther;
53
+ char **azOther;
54
+ int i;
55
+ Stmt q;
56
+
57
+ sync_explain(syncFlags);
58
+ nErr = client_sync(syncFlags, configRcvMask, configSendMask, zAltPCode);
59
+ if( (syncFlags & SYNC_ALLURL)==0 ) return nErr;
60
+ nOther = 0;
61
+ azOther = 0;
62
+ db_prepare(&q,
63
+ "SELECT substr(name,10) FROM config"
64
+ " WHERE name glob 'sync-url:*'"
65
+ " AND value<>(SELECT value FROM config WHERE name='last-sync-url')"
66
+ );
67
+ while( db_step(&q)==SQLITE_ROW ){
68
+ const char *zUrl = db_column_text(&q, 0);
69
+ azOther = fossil_realloc(azOther, sizeof(*azOther)*(nOther+1));
70
+ azOther[nOther++] = fossil_strdup(zUrl);
71
+ }
72
+ db_finalize(&q);
73
+ for(i=0; i<nOther; i++){
74
+ url_unparse(&g.url);
75
+ url_parse(azOther[i], URL_PROMPT_PW);
76
+ sync_explain(syncFlags);
77
+ nErr += client_sync(syncFlags, configRcvMask, configSendMask, zAltPCode);
78
+ fossil_free(azOther[i]);
79
+ azOther[i] = 0;
80
+ }
81
+ fossil_free(azOther);
82
+ return nErr;
83
+}
84
+
2385
2486
/*
2587
** If the repository is configured for autosyncing, then do an
2688
** autosync. Bits of the "flags" parameter determine details of behavior:
2789
**
@@ -149,18 +211,25 @@
149211
*pSyncFlags |= SYNC_VERBOSE;
150212
}
151213
if( find_option("no-http-compression",0,0)!=0 ){
152214
*pSyncFlags |= SYNC_NOHTTPCOMPRESS;
153215
}
216
+ if( find_option("all",0,0)!=0 ){
217
+ *pSyncFlags |= SYNC_ALLURL;
218
+ }
154219
url_proxy_options();
155220
clone_ssh_find_options();
156221
if( !uvOnly ) db_find_and_open_repository(0, 0);
157222
db_open_config(0, 1);
158223
if( g.argc==2 ){
159224
if( db_get_boolean("auto-shun",0) ) configSync = CONFIGSET_SHUN;
160225
}else if( g.argc==3 ){
161226
zUrl = g.argv[2];
227
+ if( (*pSyncFlags) & SYNC_ALLURL ){
228
+ fossil_fatal("cannot use both the --all option and specific URL \"%s\"",
229
+ zUrl);
230
+ }
162231
}
163232
if( ((*pSyncFlags) & (SYNC_PUSH|SYNC_PULL))==(SYNC_PUSH|SYNC_PULL)
164233
&& db_get_boolean("uv-sync",0)
165234
){
166235
*pSyncFlags |= SYNC_UNVERSIONED;
@@ -175,22 +244,14 @@
175244
if( g.url.protocol==0 ){
176245
if( urlOptional ) fossil_exit(0);
177246
usage("URL");
178247
}
179248
user_select();
180
- if( g.url.isAlias ){
181
- if( ((*pSyncFlags) & (SYNC_PUSH|SYNC_PULL))==(SYNC_PUSH|SYNC_PULL) ){
182
- fossil_print("Sync with %s\n", g.url.canonical);
183
- }else if( (*pSyncFlags) & SYNC_PUSH ){
184
- fossil_print("Push to %s\n", g.url.canonical);
185
- }else if( (*pSyncFlags) & SYNC_PULL ){
186
- fossil_print("Pull from %s\n", g.url.canonical);
187
- }
188
- }
189249
url_enable_proxy("via proxy: ");
190250
*pConfigFlags |= configSync;
191251
}
252
+
192253
193254
/*
194255
** COMMAND: pull
195256
**
196257
** Usage: %fossil pull ?URL? ?options?
@@ -205,10 +266,11 @@
205266
** pull, remote, or sync command is used. See "fossil help clone" for
206267
** details on the URL formats.
207268
**
208269
** Options:
209270
**
271
+** --all Pull from all remotes, not just the default
210272
** -B|--httpauth USER:PASS Credentials for the simple HTTP auth protocol,
211273
** if required by the remote website
212274
** --from-parent-project Pull content from the parent project
213275
** --ipv4 Use only IPv4, not IPv6
214276
** --no-http-compression Do not compress HTTP traffic
@@ -237,11 +299,11 @@
237299
process_sync_args(&configFlags, &syncFlags, 0, urlOmitFlags);
238300
239301
/* We should be done with options.. */
240302
verify_all_options();
241303
242
- client_sync(syncFlags, configFlags, 0, zAltPCode);
304
+ client_sync_all_urls(syncFlags, configFlags, 0, zAltPCode);
243305
}
244306
245307
/*
246308
** COMMAND: push
247309
**
@@ -257,10 +319,11 @@
257319
** pull, remote, or sync command is used. See "fossil help clone" for
258320
** details on the URL formats.
259321
**
260322
** Options:
261323
**
324
+** --all Push to all remotes, not just the default
262325
** -B|--httpauth USER:PASS Credentials for the simple HTTP auth protocol,
263326
** if required by the remote website
264327
** --ipv4 Use only IPv4, not IPv6
265328
** --no-http-compression Do not compress HTTP traffic
266329
** --once Do not remember URL for subsequent syncs
@@ -284,11 +347,11 @@
284347
verify_all_options();
285348
286349
if( db_get_boolean("dont-push",0) ){
287350
fossil_fatal("pushing is prohibited: the 'dont-push' option is set");
288351
}
289
- client_sync(syncFlags, 0, 0, 0);
352
+ client_sync_all_urls(syncFlags, 0, 0, 0);
290353
}
291354
292355
293356
/*
294357
** COMMAND: sync
@@ -303,10 +366,11 @@
303366
** pull, remote, or sync command is used. See "fossil help clone" for
304367
** details on the URL formats.
305368
**
306369
** Options:
307370
**
371
+** --all Sync with all remotes, not just the default
308372
** -B|--httpauth USER:PASS Credentials for the simple HTTP auth protocol,
309373
** if required by the remote website
310374
** --ipv4 Use only IPv4, not IPv6
311375
** --no-http-compression Do not compress HTTP traffic
312376
** --once Do not remember URL for subsequent syncs
@@ -332,14 +396,14 @@
332396
333397
/* We should be done with options.. */
334398
verify_all_options();
335399
336400
if( db_get_boolean("dont-push",0) ) syncFlags &= ~SYNC_PUSH;
337
- client_sync(syncFlags, configFlags, 0, 0);
338401
if( (syncFlags & SYNC_PUSH)==0 ){
339402
fossil_warning("pull only: the 'dont-push' option is set");
340403
}
404
+ client_sync_all_urls(syncFlags, configFlags, 0, 0);
341405
}
342406
343407
/*
344408
** Handle the "fossil unversioned sync" and "fossil unversioned revert"
345409
** commands.
346410
--- src/sync.c
+++ src/sync.c
@@ -18,10 +18,72 @@
18 ** This file contains code used to push, pull, and sync a repository
19 */
20 #include "config.h"
21 #include "sync.h"
22 #include <assert.h>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
24 /*
25 ** If the repository is configured for autosyncing, then do an
26 ** autosync. Bits of the "flags" parameter determine details of behavior:
27 **
@@ -149,18 +211,25 @@
149 *pSyncFlags |= SYNC_VERBOSE;
150 }
151 if( find_option("no-http-compression",0,0)!=0 ){
152 *pSyncFlags |= SYNC_NOHTTPCOMPRESS;
153 }
 
 
 
154 url_proxy_options();
155 clone_ssh_find_options();
156 if( !uvOnly ) db_find_and_open_repository(0, 0);
157 db_open_config(0, 1);
158 if( g.argc==2 ){
159 if( db_get_boolean("auto-shun",0) ) configSync = CONFIGSET_SHUN;
160 }else if( g.argc==3 ){
161 zUrl = g.argv[2];
 
 
 
 
162 }
163 if( ((*pSyncFlags) & (SYNC_PUSH|SYNC_PULL))==(SYNC_PUSH|SYNC_PULL)
164 && db_get_boolean("uv-sync",0)
165 ){
166 *pSyncFlags |= SYNC_UNVERSIONED;
@@ -175,22 +244,14 @@
175 if( g.url.protocol==0 ){
176 if( urlOptional ) fossil_exit(0);
177 usage("URL");
178 }
179 user_select();
180 if( g.url.isAlias ){
181 if( ((*pSyncFlags) & (SYNC_PUSH|SYNC_PULL))==(SYNC_PUSH|SYNC_PULL) ){
182 fossil_print("Sync with %s\n", g.url.canonical);
183 }else if( (*pSyncFlags) & SYNC_PUSH ){
184 fossil_print("Push to %s\n", g.url.canonical);
185 }else if( (*pSyncFlags) & SYNC_PULL ){
186 fossil_print("Pull from %s\n", g.url.canonical);
187 }
188 }
189 url_enable_proxy("via proxy: ");
190 *pConfigFlags |= configSync;
191 }
 
192
193 /*
194 ** COMMAND: pull
195 **
196 ** Usage: %fossil pull ?URL? ?options?
@@ -205,10 +266,11 @@
205 ** pull, remote, or sync command is used. See "fossil help clone" for
206 ** details on the URL formats.
207 **
208 ** Options:
209 **
 
210 ** -B|--httpauth USER:PASS Credentials for the simple HTTP auth protocol,
211 ** if required by the remote website
212 ** --from-parent-project Pull content from the parent project
213 ** --ipv4 Use only IPv4, not IPv6
214 ** --no-http-compression Do not compress HTTP traffic
@@ -237,11 +299,11 @@
237 process_sync_args(&configFlags, &syncFlags, 0, urlOmitFlags);
238
239 /* We should be done with options.. */
240 verify_all_options();
241
242 client_sync(syncFlags, configFlags, 0, zAltPCode);
243 }
244
245 /*
246 ** COMMAND: push
247 **
@@ -257,10 +319,11 @@
257 ** pull, remote, or sync command is used. See "fossil help clone" for
258 ** details on the URL formats.
259 **
260 ** Options:
261 **
 
262 ** -B|--httpauth USER:PASS Credentials for the simple HTTP auth protocol,
263 ** if required by the remote website
264 ** --ipv4 Use only IPv4, not IPv6
265 ** --no-http-compression Do not compress HTTP traffic
266 ** --once Do not remember URL for subsequent syncs
@@ -284,11 +347,11 @@
284 verify_all_options();
285
286 if( db_get_boolean("dont-push",0) ){
287 fossil_fatal("pushing is prohibited: the 'dont-push' option is set");
288 }
289 client_sync(syncFlags, 0, 0, 0);
290 }
291
292
293 /*
294 ** COMMAND: sync
@@ -303,10 +366,11 @@
303 ** pull, remote, or sync command is used. See "fossil help clone" for
304 ** details on the URL formats.
305 **
306 ** Options:
307 **
 
308 ** -B|--httpauth USER:PASS Credentials for the simple HTTP auth protocol,
309 ** if required by the remote website
310 ** --ipv4 Use only IPv4, not IPv6
311 ** --no-http-compression Do not compress HTTP traffic
312 ** --once Do not remember URL for subsequent syncs
@@ -332,14 +396,14 @@
332
333 /* We should be done with options.. */
334 verify_all_options();
335
336 if( db_get_boolean("dont-push",0) ) syncFlags &= ~SYNC_PUSH;
337 client_sync(syncFlags, configFlags, 0, 0);
338 if( (syncFlags & SYNC_PUSH)==0 ){
339 fossil_warning("pull only: the 'dont-push' option is set");
340 }
 
341 }
342
343 /*
344 ** Handle the "fossil unversioned sync" and "fossil unversioned revert"
345 ** commands.
346
--- src/sync.c
+++ src/sync.c
@@ -18,10 +18,72 @@
18 ** This file contains code used to push, pull, and sync a repository
19 */
20 #include "config.h"
21 #include "sync.h"
22 #include <assert.h>
23
24 /*
25 ** Explain what type of sync operation is about to occur
26 */
27 static void sync_explain(unsigned syncFlags){
28 if( g.url.isAlias ){
29 if( (syncFlags & (SYNC_PUSH|SYNC_PULL))==(SYNC_PUSH|SYNC_PULL) ){
30 fossil_print("Sync with %s\n", g.url.canonical);
31 }else if( syncFlags & SYNC_PUSH ){
32 fossil_print("Push to %s\n", g.url.canonical);
33 }else if( syncFlags & SYNC_PULL ){
34 fossil_print("Pull from %s\n", g.url.canonical);
35 }
36 }
37 }
38
39
40 /*
41 ** Call client_sync() one or more times in order to complete a
42 ** sync operation. Usually, client_sync() is called only once, though
43 ** is can be called multiple times if the SYNC_ALLURL flags is set.
44 */
45 static int client_sync_all_urls(
46 unsigned syncFlags, /* Mask of SYNC_* flags */
47 unsigned configRcvMask, /* Receive these configuration items */
48 unsigned configSendMask, /* Send these configuration items */
49 const char *zAltPCode /* Alternative project code (usually NULL) */
50 ){
51 int nErr;
52 int nOther;
53 char **azOther;
54 int i;
55 Stmt q;
56
57 sync_explain(syncFlags);
58 nErr = client_sync(syncFlags, configRcvMask, configSendMask, zAltPCode);
59 if( (syncFlags & SYNC_ALLURL)==0 ) return nErr;
60 nOther = 0;
61 azOther = 0;
62 db_prepare(&q,
63 "SELECT substr(name,10) FROM config"
64 " WHERE name glob 'sync-url:*'"
65 " AND value<>(SELECT value FROM config WHERE name='last-sync-url')"
66 );
67 while( db_step(&q)==SQLITE_ROW ){
68 const char *zUrl = db_column_text(&q, 0);
69 azOther = fossil_realloc(azOther, sizeof(*azOther)*(nOther+1));
70 azOther[nOther++] = fossil_strdup(zUrl);
71 }
72 db_finalize(&q);
73 for(i=0; i<nOther; i++){
74 url_unparse(&g.url);
75 url_parse(azOther[i], URL_PROMPT_PW);
76 sync_explain(syncFlags);
77 nErr += client_sync(syncFlags, configRcvMask, configSendMask, zAltPCode);
78 fossil_free(azOther[i]);
79 azOther[i] = 0;
80 }
81 fossil_free(azOther);
82 return nErr;
83 }
84
85
86 /*
87 ** If the repository is configured for autosyncing, then do an
88 ** autosync. Bits of the "flags" parameter determine details of behavior:
89 **
@@ -149,18 +211,25 @@
211 *pSyncFlags |= SYNC_VERBOSE;
212 }
213 if( find_option("no-http-compression",0,0)!=0 ){
214 *pSyncFlags |= SYNC_NOHTTPCOMPRESS;
215 }
216 if( find_option("all",0,0)!=0 ){
217 *pSyncFlags |= SYNC_ALLURL;
218 }
219 url_proxy_options();
220 clone_ssh_find_options();
221 if( !uvOnly ) db_find_and_open_repository(0, 0);
222 db_open_config(0, 1);
223 if( g.argc==2 ){
224 if( db_get_boolean("auto-shun",0) ) configSync = CONFIGSET_SHUN;
225 }else if( g.argc==3 ){
226 zUrl = g.argv[2];
227 if( (*pSyncFlags) & SYNC_ALLURL ){
228 fossil_fatal("cannot use both the --all option and specific URL \"%s\"",
229 zUrl);
230 }
231 }
232 if( ((*pSyncFlags) & (SYNC_PUSH|SYNC_PULL))==(SYNC_PUSH|SYNC_PULL)
233 && db_get_boolean("uv-sync",0)
234 ){
235 *pSyncFlags |= SYNC_UNVERSIONED;
@@ -175,22 +244,14 @@
244 if( g.url.protocol==0 ){
245 if( urlOptional ) fossil_exit(0);
246 usage("URL");
247 }
248 user_select();
 
 
 
 
 
 
 
 
 
249 url_enable_proxy("via proxy: ");
250 *pConfigFlags |= configSync;
251 }
252
253
254 /*
255 ** COMMAND: pull
256 **
257 ** Usage: %fossil pull ?URL? ?options?
@@ -205,10 +266,11 @@
266 ** pull, remote, or sync command is used. See "fossil help clone" for
267 ** details on the URL formats.
268 **
269 ** Options:
270 **
271 ** --all Pull from all remotes, not just the default
272 ** -B|--httpauth USER:PASS Credentials for the simple HTTP auth protocol,
273 ** if required by the remote website
274 ** --from-parent-project Pull content from the parent project
275 ** --ipv4 Use only IPv4, not IPv6
276 ** --no-http-compression Do not compress HTTP traffic
@@ -237,11 +299,11 @@
299 process_sync_args(&configFlags, &syncFlags, 0, urlOmitFlags);
300
301 /* We should be done with options.. */
302 verify_all_options();
303
304 client_sync_all_urls(syncFlags, configFlags, 0, zAltPCode);
305 }
306
307 /*
308 ** COMMAND: push
309 **
@@ -257,10 +319,11 @@
319 ** pull, remote, or sync command is used. See "fossil help clone" for
320 ** details on the URL formats.
321 **
322 ** Options:
323 **
324 ** --all Push to all remotes, not just the default
325 ** -B|--httpauth USER:PASS Credentials for the simple HTTP auth protocol,
326 ** if required by the remote website
327 ** --ipv4 Use only IPv4, not IPv6
328 ** --no-http-compression Do not compress HTTP traffic
329 ** --once Do not remember URL for subsequent syncs
@@ -284,11 +347,11 @@
347 verify_all_options();
348
349 if( db_get_boolean("dont-push",0) ){
350 fossil_fatal("pushing is prohibited: the 'dont-push' option is set");
351 }
352 client_sync_all_urls(syncFlags, 0, 0, 0);
353 }
354
355
356 /*
357 ** COMMAND: sync
@@ -303,10 +366,11 @@
366 ** pull, remote, or sync command is used. See "fossil help clone" for
367 ** details on the URL formats.
368 **
369 ** Options:
370 **
371 ** --all Sync with all remotes, not just the default
372 ** -B|--httpauth USER:PASS Credentials for the simple HTTP auth protocol,
373 ** if required by the remote website
374 ** --ipv4 Use only IPv4, not IPv6
375 ** --no-http-compression Do not compress HTTP traffic
376 ** --once Do not remember URL for subsequent syncs
@@ -332,14 +396,14 @@
396
397 /* We should be done with options.. */
398 verify_all_options();
399
400 if( db_get_boolean("dont-push",0) ) syncFlags &= ~SYNC_PUSH;
 
401 if( (syncFlags & SYNC_PUSH)==0 ){
402 fossil_warning("pull only: the 'dont-push' option is set");
403 }
404 client_sync_all_urls(syncFlags, configFlags, 0, 0);
405 }
406
407 /*
408 ** Handle the "fossil unversioned sync" and "fossil unversioned revert"
409 ** commands.
410
+1
--- src/xfer.c
+++ src/xfer.c
@@ -1821,10 +1821,11 @@
18211821
#define SYNC_UV_TRACE 0x0400 /* Describe UV activities */
18221822
#define SYNC_UV_DRYRUN 0x0800 /* Do not actually exchange files */
18231823
#define SYNC_IFABLE 0x1000 /* Inability to sync is not fatal */
18241824
#define SYNC_CKIN_LOCK 0x2000 /* Lock the current check-in */
18251825
#define SYNC_NOHTTPCOMPRESS 0x4000 /* Do not compression HTTP messages */
1826
+#define SYNC_ALLURL 0x8000 /* The --all flag - sync to all URLs */
18261827
#endif
18271828
18281829
/*
18291830
** Floating-point absolute value
18301831
*/
18311832
--- src/xfer.c
+++ src/xfer.c
@@ -1821,10 +1821,11 @@
1821 #define SYNC_UV_TRACE 0x0400 /* Describe UV activities */
1822 #define SYNC_UV_DRYRUN 0x0800 /* Do not actually exchange files */
1823 #define SYNC_IFABLE 0x1000 /* Inability to sync is not fatal */
1824 #define SYNC_CKIN_LOCK 0x2000 /* Lock the current check-in */
1825 #define SYNC_NOHTTPCOMPRESS 0x4000 /* Do not compression HTTP messages */
 
1826 #endif
1827
1828 /*
1829 ** Floating-point absolute value
1830 */
1831
--- src/xfer.c
+++ src/xfer.c
@@ -1821,10 +1821,11 @@
1821 #define SYNC_UV_TRACE 0x0400 /* Describe UV activities */
1822 #define SYNC_UV_DRYRUN 0x0800 /* Do not actually exchange files */
1823 #define SYNC_IFABLE 0x1000 /* Inability to sync is not fatal */
1824 #define SYNC_CKIN_LOCK 0x2000 /* Lock the current check-in */
1825 #define SYNC_NOHTTPCOMPRESS 0x4000 /* Do not compression HTTP messages */
1826 #define SYNC_ALLURL 0x8000 /* The --all flag - sync to all URLs */
1827 #endif
1828
1829 /*
1830 ** Floating-point absolute value
1831 */
1832

Keyboard Shortcuts

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