50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
*/
static int client_sync_all_urls(
unsigned syncFlags, /* Mask of SYNC_* flags */
unsigned configRcvMask, /* Receive these configuration items */
unsigned configSendMask, /* Send these configuration items */
const char *zAltPCode /* Alternative project code (usually NULL) */
){
int nErr;
int nOther;
char **azOther;
int i;
Stmt q;
int nErr; /* Number of errors seen */
int nOther; /* Number of extra remote URLs */
char **azOther; /* Text of extra remote URLs */
int i; /* Loop counter */
int iEnd; /* Loop termination point */
int nextIEnd; /* Loop termination point for next pass */
int iPass; /* Which pass through the remotes. 0 or 1 */
int nPass; /* Number of passes to make. 1 or 2 */
Stmt q; /* An SQL statement */
UrlData baseUrl; /* Saved parse of the default remote */
sync_explain(syncFlags);
if( (syncFlags & SYNC_ALLURL)==0 ){
/* Common-case: Only sync with the remote identified by g.url */
nErr = client_sync(syncFlags, configRcvMask, configSendMask, zAltPCode);
if( nErr==0 ) url_remember();
if( (syncFlags & SYNC_ALLURL)==0 ) return nErr;
nErr = client_sync(syncFlags, configRcvMask, configSendMask, zAltPCode, 0);
if( nErr==0 ) url_remember();
return nErr;
}
/* If we reach this point, it means we want to sync with all remotes */
memset(&baseUrl, 0, sizeof(baseUrl));
url_move_parse(&baseUrl, &g.url);
nOther = 0;
azOther = 0;
db_prepare(&q,
"SELECT substr(name,10) FROM config"
" WHERE name glob 'sync-url:*'"
" AND value<>(SELECT value FROM config WHERE name='last-sync-url')"
);
while( db_step(&q)==SQLITE_ROW ){
const char *zUrl = db_column_text(&q, 0);
azOther = fossil_realloc(azOther, sizeof(*azOther)*(nOther+1));
azOther[nOther++] = fossil_strdup(zUrl);
}
db_finalize(&q);
iEnd = nOther+1;
nextIEnd = 0;
nPass = 1 + ((syncFlags & (SYNC_PUSH|SYNC_PULL))==(SYNC_PUSH|SYNC_PULL));
for(iPass=0; iPass<nPass; iPass++){
for(i=0; i<nOther; i++){
int rc;
url_unparse(&g.url);
url_parse(azOther[i], URL_PROMPT_PW|URL_ASK_REMEMBER_PW|URL_USE_CONFIG);
sync_explain(syncFlags);
rc = client_sync(syncFlags, configRcvMask, configSendMask, zAltPCode);
nErr += rc;
if( (g.url.flags & URL_REMEMBER_PW)!=0 && rc==0 ){
char *zKey = mprintf("sync-pw:%s", azOther[i]);
char *zPw = obscure(g.url.passwd);
if( zPw && zPw[0] ){
db_set(zKey/*works-like:""*/, zPw, 0);
}
fossil_free(zPw);
fossil_free(zKey);
}
for(i=0; i<iEnd; i++){
int rc;
int nRcvd;
if( i==0 ){
url_move_parse(&g.url, &baseUrl); /* Load canonical URL */
}else{
/* Load an auxiliary remote URL */
url_parse(azOther[i-1],
URL_PROMPT_PW|URL_ASK_REMEMBER_PW|URL_USE_CONFIG);
}
if( i>0 || iPass>0 ) sync_explain(syncFlags);
rc = client_sync(syncFlags, configRcvMask, configSendMask,
zAltPCode, &nRcvd);
if( nRcvd>0 ){
/* If new artifacts were received, we want to repeat all prior
** remotes on the second pass */
nextIEnd = i;
}
nErr += rc;
if( rc==0 && iPass==0 ){
if( i==0 ){
url_remember();
}else if( (g.url.flags & URL_REMEMBER_PW)!=0 ){
char *zKey = mprintf("sync-pw:%s", azOther[i-1]);
char *zPw = obscure(g.url.passwd);
if( zPw && zPw[0] ){
db_set(zKey/*works-like:""*/, zPw, 0);
}
fossil_free(zPw);
fossil_free(zKey);
}
}
if( i==0 ){
url_move_parse(&baseUrl, &g.url); /* Don't forget canonical URL */
}else{
url_unparse(&g.url); /* Delete auxiliary URL parses */
}
}
iEnd = nextIEnd;
}
for(i=0; i<nOther; i++){
fossil_free(azOther[i]);
azOther[i] = 0;
}
fossil_free(azOther);
url_move_parse(&g.url, &baseUrl); /* Restore the canonical URL parse */
return nErr;
}
/*
** If the repository is configured for autosyncing, then do an
** autosync. Bits of the "flags" parameter determine details of behavior:
|
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
-
+
|
g.zHttpAuth = get_httpauth();
if( sqlite3_strglob("*all*", zAutosync)==0 ){
rc = client_sync_all_urls(flags|SYNC_ALLURL, configSync, 0, 0);
}else{
url_remember();
sync_explain(flags);
url_enable_proxy("via proxy: ");
rc = client_sync(flags, configSync, 0, 0);
rc = client_sync(flags, configSync, 0, 0, 0);
}
return rc;
}
/*
** This routine will try a number of times to perform autosync with a
** 0.5 second sleep between attempts. The number of attempts is determined
|
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
|
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
|
-
+
|
** commands.
*/
void sync_unversioned(unsigned syncFlags){
unsigned configFlags = 0;
(void)find_option("uv-noop",0,0);
process_sync_args(&configFlags, &syncFlags, 1, 0);
verify_all_options();
client_sync(syncFlags, 0, 0, 0);
client_sync(syncFlags, 0, 0, 0, 0);
}
/*
** COMMAND: remote
** COMMAND: remote-url*
**
** Usage: %fossil remote ?SUBCOMMAND ...?
|