Fossil

Diff
Login

Differences From Artifact [9bd5608f8a]:

To Artifact [53c87bdfed]:


127
128
129
130
131
132
133

134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153

154
155
156
157
158
159
160
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162







+




















+







**    -B|--httpauth USER:PASS    Add HTTP Basic Authorization to requests
**    --nested                   Allow opening a repository inside an opened
**                               check-out
**    --nocompress               Omit extra delta compression
**    --no-open                  Clone only.  Do not open a check-out.
**    --once                     Don't remember the URI.
**    --private                  Also clone private branches
**    --resume                   Resume a failed clone
**    --save-http-password       Remember the HTTP password without asking
**    -c|--ssh-command SSH       Use SSH as the "ssh" command
**    --ssl-identity FILENAME    Use the SSL identity if requested by the server
**    --transport-command CMD    Use CMD to move messages to the server and back
**    -u|--unversioned           Also sync unversioned content
**    -v|--verbose               Show more statistics in output
**    --workdir DIR              Also open a check-out in DIR
**
** See also: [[init]], [[open]]
*/
void clone_cmd(void){
  char *zPassword;
  const char *zDefaultUser;   /* Optional name of the default user */
  const char *zHttpAuth;      /* HTTP Authorization user:pass information */
  int nErr = 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 = find_option("resume",0,0)!=0; /* Resume a failed 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 */
  if( find_option("private",0,0)!=0 ) syncFlags |= SYNC_PRIVATE;
  if( find_option("once",0,0)!=0) urlFlags &= ~URL_REMEMBER;
195
196
197
198
199
200
201
202

203
204
205
206
207
208
209
197
198
199
200
201
202
203

204
205
206
207
208
209
210
211







-
+







    }
    zRepo = mprintf("./%s.fossil", zBase);
    if( zWorkDir==0 ){
      zWorkDir = mprintf("./%s", zBase);
    }
    fossil_free(zBase);
  }  
  if( -1 != file_size(zRepo, ExtFILE) ){
  if( -1 != file_size(zRepo, ExtFILE) && bResume==0 ){
    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);
    }
224
225
226
227
228
229
230






231
232
233
234
235
236
237
238
239











240
241
242
243
244
245
246
226
227
228
229
230
231
232
233
234
235
236
237
238









239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256







+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+







      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 ){
      db_open_repository(zRepo);
      db_open_config(0,0);
      db_begin_transaction();
      user_select();
    }else{
    db_create_repository(zRepo);
    db_open_repository(zRepo);
    db_open_config(0,0);
    db_begin_transaction();
    db_record_repository_filename(zRepo);
    db_initial_setup(0, 0, zDefaultUser);
    user_select();
    db_set("content-schema", CONTENT_SCHEMA, 0);
    db_set("aux-schema", AUX_SCHEMA_MAX, 0);
      db_create_repository(zRepo);
      db_open_repository(zRepo);
      db_open_config(0,0);
      db_begin_transaction();
      db_record_repository_filename(zRepo);
      db_initial_setup(0, 0, zDefaultUser);
      user_select();
      db_set("content-schema", CONTENT_SCHEMA, 0);
      db_set("aux-schema", AUX_SCHEMA_MAX, 0);
      db_set_int("aux-clone-seqno", 1, 0);
    }
    db_set("rebuilt", get_version(), 0);
    db_unset("hash-policy", 0);
    remember_or_get_http_auth(zHttpAuth, urlFlags & URL_REMEMBER, g.argv[2]);
    url_remember();
    if( g.zSSLIdentity!=0 ){
      /* If the --ssl-identity option was specified, store it as a setting */
      Blob fn;
261
262
263
264
265
266
267
268
269
270
271
272





273


274
275
276
277
278
279



280
281
282
283
284
285
286
271
272
273
274
275
276
277


278


279
280
281
282
283
284
285
286
287
288
289
290


291
292
293
294
295
296
297
298
299
300







-
-

-
-
+
+
+
+
+

+
+




-
-
+
+
+







    url_enable_proxy(0);
    clone_ssh_db_set_options();
    url_get_password_if_needed();
    g.xlinkClusterOnly = 1;
    nErr = client_sync(syncFlags,CONFIGSET_ALL,0,0);
    g.xlinkClusterOnly = 0;
    verify_cancel();
    db_end_transaction(0);
    db_close(1);
    if( nErr ){
      file_delete(zRepo);
      fossil_fatal("server returned an error - clone aborted");
      fossil_warning("server returned an error - clone incomplete");
    }else{
      db_unprotect(PROTECT_CONFIG);
      db_multi_exec("DELETE FROM config WHERE name = 'aux-clone-seqno';");
      db_protect_pop();
    }
    db_end_transaction(0);
    db_close(1);
    db_open_repository(zRepo);
  }
  db_begin_transaction();
  if( db_exists("SELECT 1 FROM delta WHERE srcId IN phantom") ){
    fossil_fatal("there are unresolved deltas -"
                 " the clone is probably incomplete and unusable.");
    fossil_warning("there are unresolved deltas -"
                 " the clone is probably incomplete and unusable.\n"
                 "It may be possible to continue clone with --resume.");
  }
  fossil_print("Rebuilding repository meta-data...\n");
  rebuild_db(1, 0);
  if( !noCompress ){
    int nDelta = 0;
    i64 nByte;
    fossil_print("Extra delta compression... "); fflush(stdout);