Fossil

Diff
Login

Differences From Artifact [74a2862e7d]:

To Artifact [dcbce47915]:


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
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
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
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







-
+







-
+




+






-
-
+
+


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

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

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


  return 0;
}


/*
** COMMAND: revert
**
** Usage: %fossil revert ?--yes? ?-r REVISION? FILE
** Usage: %fossil revert ?--yes? ?-r REVISION? FILE ...
**
** Revert to the current repository version of FILE, or to
** the version associated with baseline REVISION if the -r flag
** appears.  This command will confirm your operation unless the
** file is missing or the --yes option is used.
**/
void revert_cmd(void){
  const char *zFile;
  char *zFile;
  const char *zRevision;
  Blob fname;
  Blob record;
  Blob ans;
  int i;
  int rid = 0, yesRevert;
  
  yesRevert = find_option("yes", "y", 0)!=0;
  zRevision = find_option("revision", "r", 1);
  verify_all_options();
  
  if( g.argc!=3 ){
    usage("?OPTIONS FILE");
  if( g.argc<3 ){
    usage("?OPTIONS FILE ...");
  }
  db_must_be_within_tree();
  
  zFile = mprintf("%/", g.argv[g.argc-1]);

  for(i=2; i<g.argc; i++){  
    zFile = mprintf("%/", g.argv[i]);

  file_tree_name(zFile, &fname, 1);
    file_tree_name(zFile, &fname, 1);

  if( access(zFile, 0) ) yesRevert = 1;  
  if( yesRevert==0 ){
    char *prompt = mprintf("revert file %B? this will"
                           " destroy local changes (y/N)? ",
                           &fname);
    blob_zero(&ans);
    prompt_user(prompt, &ans);
    free( prompt );
    if( blob_str(&ans)[0]=='y' ){
      yesRevert = 1;
    }
  }
    if( access(zFile, 0) ) yesRevert = 1;  
    if( yesRevert==0 ){
      char *prompt = mprintf("revert file %B? this will"
                             " destroy local changes (y/N)? ",
                             &fname);
      blob_zero(&ans);
      prompt_user(prompt, &ans);
      free( prompt );
      if( blob_str(&ans)[0]=='y' ){
        yesRevert = 1;
      }
      blob_reset(&ans);
    }

  if( yesRevert==1 && zRevision!=0 ){
    historical_version_of_file(zRevision, zFile, &record);
  }else if( yesRevert==1 ){
    rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname);
    if( rid==0 ){
      fossil_panic("no history for file: %b", &fname);
    }
    content_get(rid, &record);
  }
    if( yesRevert==1 && zRevision!=0 ){
      historical_version_of_file(zRevision, zFile, &record);
    }else if( yesRevert==1 ){
      rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname);
      if( rid==0 ){
        fossil_panic("no history for file: %b", &fname);
      }
      content_get(rid, &record);
    }
  
  if( yesRevert==1 ){
    blob_write_to_file(&record, zFile);
    printf("%s reverted\n", zFile);
    blob_reset(&record);
    blob_reset(&fname);
  }else{
    printf("revert canceled\n");
    if( yesRevert==1 ){
      blob_write_to_file(&record, zFile);
      printf("%s reverted\n", zFile);
      blob_reset(&record);
      blob_reset(&fname);
    }else{
      printf("revert canceled\n");
    }
    free(zFile);
  }
}