Diff
Not logged in

Differences From:

File src/update.c part of check-in [fff234b77c] - Updates to the autosync logic. Add the "setting" command. by drh on 2007-09-25 20:23:52. [view]

To:

File src/update.c part of check-in [574763bab9] - Added revision support to diff and revert by jnc on 2007-09-26 03:37:12. Also file src/update.c part of check-in [8d55aa3597] - Merged in new revision support for diff and revert commands into mainstream by jnc on 2007-09-26 03:38:58. [view]

@@ -222,22 +222,24 @@
 
 /*
 ** COMMAND: revert
 **
-** Usage: %fossil revert ?-yes FILE
+** Usage: %fossil revert ?-yes ?-r REVISION FILE
 **
 ** Revert to the current repository version of FILE. This
 ** command will confirm your operation, unless you do so
 ** at the command line via the -yes option.
 **/
 void revert_cmd(void){
   const char *zFile;
+  const char *zRevision;
   Blob fname;
   Blob record;
   Blob ans;
-  int rid, yesRevert;
+  int rid = 0, yesRevert;
 
-  yesRevert = find_option("yes","y", 0)!=0;
+  yesRevert = find_option("yes", "y", 0)!=0;
+  zRevision = find_option("revision", "r", 1);
   verify_all_options();
 
   if( g.argc<3 ){
     usage("?OPTIONS FILE");
@@ -244,15 +246,11 @@
   }
   db_must_be_within_tree();
 
   zFile = g.argv[g.argc-1];
+
   if( !file_tree_name(zFile, &fname) ){
     fossil_panic("unknown file: %s", zFile);
-  }
-  rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname);
-
-  if( rid==0 ){
-    fossil_panic("no history for file: %b", &fname);
   }
 
   if( yesRevert==0 ){
     char *prompt = mprintf("revert file %B? this will destroy local changes [y/N]? ",
@@ -262,10 +260,20 @@
     if( blob_str(&ans)[0]=='y' ){
       yesRevert = 1;
     }
   }
-  if( yesRevert==1 ){
+
+  if( yesRevert==1 && zRevision!=0 ){
+    content_get_historical_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, blob_str(&fname));
     printf("%s reverted\n", blob_str(&fname));
     blob_reset(&record);
     blob_reset(&fname);