Check-in [1d9ebd9e4a]
Not logged in
Overview

SHA1 Hash:1d9ebd9e4a5a05ba85279792deb8771d94b84450
Date: 2009-12-17 16:17:11
User: drh
Comment:Add --nochanges and --verbose options to the "update" command. Tickets 4d6b7d4e1 and 7a27e10f1fe.
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Modified src/update.c from [dcbce47915] to [af63100f92].

@@ -36,31 +36,40 @@
 }
 
 /*
 ** COMMAND: update
 **
-** Usage: %fossil update ?VERSION? ?--latest?
+** Usage: %fossil update ?VERSION? ?OPTIONS?
+**
+** Change the version of the current checkout to VERSION.  Any uncommitted
+** changes are retained and applied to the new checkout.
+**
+** The VERSION argument can be a specific version or tag or branch name.
+** If the VERSION argument is omitted, then the leaf of the the subtree
+** that begins at the current version is used, if there is only a single
+** leaf.  Instead of specifying VERSION, use the --latest option to update
+** to the most recent check-in.
 **
-** The optional argument is a version that should become the current
-** version.  If the argument is omitted, then use the leaf of the
-** tree that begins with the current version, if there is only a
-** single leaf.  If there are a multiple leaves, the latest is used
-** if the --latest flag is present.
+** The -n or --nochange option causes this command to do a "dry run".  It
+** prints out what would have happened but does not actually make any
+** changes to the current checkout or the repository.
 **
-** This command is different from the "checkout" in that edits are
-** not overwritten.  Edits are merged into the new version.
+** The -v or --verbose option prints status information about unchanged
+** files in addition to those file that actually do change.
 */
 void update_cmd(void){
   int vid;              /* Current version */
   int tid=0;            /* Target version - version we are changing to */
   Stmt q;
-  int latestFlag;       /* Pick the latest version if true */
-  int forceFlag;        /* True force the update */
+  int latestFlag;       /* --latest.  Pick the latest version if true */
+  int nochangeFlag;     /* -n or --nochange.  Do a dry run */
+  int verboseFlag;      /* -v or --verbose.  Output extra information */
 
   url_proxy_options();
   latestFlag = find_option("latest",0, 0)!=0;
-  forceFlag = find_option("force","f",0)!=0;
+  nochangeFlag = find_option("nochange","n",0)!=0;
+  verboseFlag = find_option("verbose","v",0)!=0;
   if( g.argc!=3 && g.argc!=2 ){
     usage("?VERSION?");
   }
   db_must_be_within_tree();
   vid = db_lget_int("checkout", 0);
@@ -78,11 +87,11 @@
     }
     if( !is_a_version(tid) ){
       fossil_fatal("not a version: %s", g.argv[2]);
     }
   }
-  autosync(AUTOSYNC_PULL);
+  if( !nochangeFlag ) autosync(AUTOSYNC_PULL);
 
   if( tid==0 ){
     compute_leaves(vid, 1);
     if( !latestFlag && db_int(0, "SELECT count(*) FROM leaves")>1 ){
       db_prepare(&q,
@@ -171,16 +180,16 @@
       printf("CONFLICT %s\n", zName);
     }else if( idt>0 && idv==0 ){
       /* File added in the target. */
       printf("ADD %s\n", zName);
       undo_save(zName);
-      vfile_to_disk(0, idt, 0);
+      if( !nochangeFlag ) vfile_to_disk(0, idt, 0);
     }else if( idt>0 && idv>0 && ridt!=ridv && chnged==0 ){
       /* The file is unedited.  Change it to the target version */
       printf("UPDATE %s\n", zName);
       undo_save(zName);
-      vfile_to_disk(0, idt, 0);
+      if( !nochangeFlag ) vfile_to_disk(0, idt, 0);
     }else if( idt==0 && idv>0 ){
       if( ridv==0 ){
         /* Added in current checkout.  Continue to hold the file as
         ** as an addition */
         db_multi_exec("UPDATE vfile SET vid=%d WHERE id=%d", tid, idv);
@@ -189,11 +198,11 @@
       }else{
         char *zFullPath;
         printf("REMOVE %s\n", zName);
         undo_save(zName);
         zFullPath = mprintf("%s/%s", g.zLocalRoot, zName);
-        unlink(zFullPath);
+        if( !nochangeFlag ) unlink(zFullPath);
         free(zFullPath);
       }
     }else if( idt>0 && idv>0 && ridt!=ridv && chnged ){
       /* Merge the changes in the current tree into the target version */
       Blob e, r, t, v;
@@ -206,11 +215,11 @@
       content_get(ridv, &v);
       blob_zero(&e);
       blob_read_from_file(&e, zFullPath);
       rc = blob_merge(&v, &e, &t, &r);
       if( rc>=0 ){
-        blob_write_to_file(&r, zFullPath);
+        if( !nochangeFlag ) blob_write_to_file(&r, zFullPath);
         if( rc>0 ){
           printf("***** %d merge conflicts in %s\n", rc, zName);
         }
       }else{
         printf("***** Cannot merge binary file %s\n", zName);
@@ -218,22 +227,27 @@
       free(zFullPath);
       blob_reset(&v);
       blob_reset(&e);
       blob_reset(&t);
       blob_reset(&r);
-
+    }else if( verboseFlag ){
+      printf("UNCHANGED %s\n", zName);
     }
   }
   db_finalize(&q);
 
   /*
   ** Clean up the mid and pid VFILE entries.  Then commit the changes.
   */
-  db_multi_exec("DELETE FROM vfile WHERE vid!=%d", tid);
-  manifest_to_disk(tid);
-  db_lset_int("checkout", tid);
-  db_end_transaction(0);
+  if( nochangeFlag ){
+    db_end_transaction(1);  /* With --nochange, rollback changes */
+  }else{
+    db_multi_exec("DELETE FROM vfile WHERE vid!=%d", tid);
+    manifest_to_disk(tid);
+    db_lset_int("checkout", tid);
+    db_end_transaction(0);
+  }
 }
 
 
 /*
 ** Get the contents of a file within a given revision.