Diff
Not logged in

Differences From:

File src/update.c part of check-in [36b96b8616] - Rework the merge algorithm. It now only works for text files. But, it no longer gets confused by line endings (\r\n versus \n) and it reports conflicts. by drh on 2007-11-16 20:42:31. [view]

To:

File src/update.c part of check-in [371dd6574c] - Fix the revert command so that it works from subdirectories. Other minor comment and help-text changes. by drh on 2007-12-04 01:26:21. Also file src/update.c part of check-in [d0305b305a] - Merged mainline into my branch to get the newest application. by aku on 2007-12-05 08:07:46. [view]

@@ -244,16 +244,48 @@
   db_lset_int("checkout", tid);
   db_end_transaction(0);
 }
 
+
+/*
+** Get the contents of a file within a given revision.
+*/
+int historical_version_of_file(
+  const char *revision,    /* The baseline name containing the file */
+  const char *file,        /* Full treename of the file */
+  Blob *content            /* Put the content here */
+){
+  Blob mfile;
+  Manifest m;
+  int i, rid=0;
+
+  rid = name_to_rid(revision);
+  content_get(rid, &mfile);
+
+  if( manifest_parse(&m, &mfile) ){
+    for(i=0; i<m.nFile; i++){
+      if( strcmp(m.aFile[i].zName, file)==0 ){
+        rid = uuid_to_rid(m.aFile[i].zUuid, 0);
+        return content_get(rid, content);
+      }
+    }
+    fossil_fatal("file %s does not exist in baseline: %s", file, revision);
+  }else{
+    fossil_panic("could not parse manifest for baseline: %s", revision);
+  }
+  return 0;
+}
+
+
 /*
 ** COMMAND: revert
 **
 ** 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.
+** 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;
   const char *zRevision;
@@ -270,14 +302,15 @@
     usage("?OPTIONS FILE");
   }
   db_must_be_within_tree();
 
-  zFile = g.argv[g.argc-1];
+  zFile = mprintf("%/", g.argv[g.argc-1]);
 
   if( !file_tree_name(zFile, &fname) ){
     fossil_panic("unknown file: %s", zFile);
   }
 
+  if( access(zFile, 0) ) yesRevert = 1;
   if( yesRevert==0 ){
     char *prompt = mprintf("revert file %B? this will"
                            " destroy local changes [y/N]? ",
                            &fname);
@@ -288,9 +321,9 @@
     }
   }
 
   if( yesRevert==1 && zRevision!=0 ){
-    content_get_historical_file(zRevision, zFile, &record);
+    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);
@@ -298,12 +331,12 @@
     content_get(rid, &record);
   }
 
   if( yesRevert==1 ){
-    blob_write_to_file(&record, blob_str(&fname));
-    printf("%s reverted\n", blob_str(&fname));
+    blob_write_to_file(&record, zFile);
+    printf("%s reverted\n", zFile);
     blob_reset(&record);
     blob_reset(&fname);
   }else{
     printf("revert canceled\n");
   }
 }