149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
-
+
|
int nErr = 0;
int nResumes = 0;
int urlFlags = URL_PROMPT_PW | URL_REMEMBER;
int syncFlags = SYNC_CLONE;
int noCompress = find_option("nocompress",0,0)!=0;
int noOpen = find_option("no-open",0,0)!=0;
int allowNested = find_option("nested",0,0)!=0; /* Used by open */
int bResume = 0; /* Set if a previous clone failed */
int nResumeSeqno = 0; /* Last seqno from which to resume clone */
const char *zNewProjCode; /* New Project code obtained during clone */
const char *zOldProjCode; /* Old project code stored in resuming clone */
const char *zRepo = 0; /* Name of the new local repository file */
const char *zWorkDir = 0; /* Open in this directory, if not zero */
/* Also clone private branches */
|
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
-
+
-
+
|
if( zWorkDir==0 ){
zWorkDir = mprintf("./%s", zBase);
}
fossil_free(zBase);
}
if( -1 != file_size(zRepo, ExtFILE) ){
db_open_repository(zRepo);
bResume = db_get_int("aux-clone-seqno",0)!=0;
nResumeSeqno = db_get_int("aux-clone-seqno",0);
db_close(0);
if( !bResume ){
if( !nResumeSeqno ){
fossil_fatal("file already exists: %s", zRepo);
}
}
/* Fail before clone if open will fail because inside an open check-out */
if( zWorkDir!=0 && zWorkDir[0]!=0 && !noOpen ){
if( db_open_local_v2(0, allowNested) ){
fossil_fatal("there is already an open tree at %s", g.zLocalRoot);
|
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
-
+
-
-
+
-
-
-
-
-
+
|
g.zLogin = zDefaultUser;
}else{
g.zLogin = db_text(0, "SELECT login FROM user WHERE cap LIKE '%%s%%'");
}
fossil_print("Repository cloned into %s\n", zRepo);
}else{
db_close_config();
if( bResume ){
if( nResumeSeqno>1 ){
db_open_repository(zRepo);
db_open_config(0,0);
db_begin_transaction();
db_unprotect(PROTECT_CONFIG);
zOldProjCode = db_get("project-code",0);
fossil_print("Resuming clone of project-id %s\n",zOldProjCode);
db_multi_exec(
db_create_default_users(1, zDefaultUser);
"DELETE FROM config WHERE name = 'project-code';"
"DELETE FROM config WHERE name = 'server-code';"
);
db_protect_pop();
db_initial_setup(0, 0, zDefaultUser);
if( zDefaultUser ) g.zLogin = zDefaultUser;
user_select();
}else{
db_create_repository(zRepo);
db_open_repository(zRepo);
db_open_config(0,0);
db_begin_transaction();
db_record_repository_filename(zRepo);
|
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
|
-
-
-
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
|
url_enable_proxy(0);
clone_ssh_db_set_options();
url_get_password_if_needed();
g.xlinkClusterOnly = 1;
while( nResumes++<3 && sync_interrupted()==0
&& (nErr = client_sync(syncFlags,CONFIGSET_ALL,0,0))
){
if( sync_interrupted()!=0 ){
fossil_warning("cloning encountered errors, trying again.");
sqlite3_sleep(500);
if( sync_interrupted() ) break;
if( db_get_int("aux-clone-seqno",1)==1 ){
fossil_fatal("server returned an error - clone aborted");
}
fossil_warning("cloning encountered errors, trying again.");
sqlite3_sleep(500);
}
}
g.xlinkClusterOnly = 0;
verify_cancel();
if( nResumeSeqno>1 ){
if( nResumeSeqno==db_get_int("aux-clone-seqno",0) ){
fossil_fatal("No progress was made - aborting");
}
zNewProjCode = db_get("project-code",0);
if( zOldProjCode && zOldProjCode[0]
&& fossil_strcmp(zOldProjCode, zNewProjCode)!=0 ){
fossil_fatal("project-id changed\nwas %s\nis %s"
"\nrolling back changes",
zOldProjCode, zNewProjCode);
}
}
if( nErr ){
fossil_warning("server returned an error - clone incomplete");
}else if( sync_interrupted()==1 ){
fossil_warning("clone was interrupted");
}else{
db_unprotect(PROTECT_CONFIG);
db_multi_exec("DELETE FROM config WHERE name = 'aux-clone-seqno';");
db_protect_pop();
}
zNewProjCode = db_get("project-code",0);
if( bResume && zOldProjCode && zOldProjCode[0]
&& fossil_strcmp(zOldProjCode, zNewProjCode)!=0 ){
fossil_warning("project-id changed\nwas %s\nis %s\nrolling back changes",
zOldProjCode, zNewProjCode);
db_end_transaction(1);
db_close(1);
fossil_exit(1);
}else{
db_end_transaction(0);
db_close(1);
db_end_transaction(0);
db_close(1);
}
db_open_repository(zRepo);
#if !defined(_WIN32)
signal(SIGINT, SIG_DFL);
#endif
}
db_begin_transaction();
if( db_exists("SELECT 1 FROM delta WHERE srcId IN phantom") ){
if( db_get_int("aux-clone-seqno",0)==0 ){
fossil_fatal("there are unresolved deltas -"
" the clone is probabaly incomplete and unusable.");
}
}
if( db_get_int("aux-clone-seqno",0)>0 ){
if( db_get_int("aux-clone-seqno",0)>1 ){
fossil_warning("It may be possible to resume the"
" clone by running the same command again.");
}else{
fossil_print("Rebuilding repository meta-data...\n");
rebuild_db(1, 0);
if( !noCompress ){
int nDelta = 0;
|