Fossil SCM
Add --nochanges and --verbose options to the "update" command. Tickets [4d6b7d4e1] and [7a27e10f1fe].
Commit
1d9ebd9e4a5a05ba85279792deb8771d94b84450
Parent
4b0d2fbefbd5955…
1 file changed
+37
-23
+37
-23
| --- src/update.c | ||
| +++ src/update.c | ||
| @@ -36,31 +36,40 @@ | ||
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /* |
| 39 | 39 | ** COMMAND: update |
| 40 | 40 | ** |
| 41 | -** Usage: %fossil update ?VERSION? ?--latest? | |
| 42 | -** | |
| 43 | -** The optional argument is a version that should become the current | |
| 44 | -** version. If the argument is omitted, then use the leaf of the | |
| 45 | -** tree that begins with the current version, if there is only a | |
| 46 | -** single leaf. If there are a multiple leaves, the latest is used | |
| 47 | -** if the --latest flag is present. | |
| 48 | -** | |
| 49 | -** This command is different from the "checkout" in that edits are | |
| 50 | -** not overwritten. Edits are merged into the new version. | |
| 41 | +** Usage: %fossil update ?VERSION? ?OPTIONS? | |
| 42 | +** | |
| 43 | +** Change the version of the current checkout to VERSION. Any uncommitted | |
| 44 | +** changes are retained and applied to the new checkout. | |
| 45 | +** | |
| 46 | +** The VERSION argument can be a specific version or tag or branch name. | |
| 47 | +** If the VERSION argument is omitted, then the leaf of the the subtree | |
| 48 | +** that begins at the current version is used, if there is only a single | |
| 49 | +** leaf. Instead of specifying VERSION, use the --latest option to update | |
| 50 | +** to the most recent check-in. | |
| 51 | +** | |
| 52 | +** The -n or --nochange option causes this command to do a "dry run". It | |
| 53 | +** prints out what would have happened but does not actually make any | |
| 54 | +** changes to the current checkout or the repository. | |
| 55 | +** | |
| 56 | +** The -v or --verbose option prints status information about unchanged | |
| 57 | +** files in addition to those file that actually do change. | |
| 51 | 58 | */ |
| 52 | 59 | void update_cmd(void){ |
| 53 | 60 | int vid; /* Current version */ |
| 54 | 61 | int tid=0; /* Target version - version we are changing to */ |
| 55 | 62 | Stmt q; |
| 56 | - int latestFlag; /* Pick the latest version if true */ | |
| 57 | - int forceFlag; /* True force the update */ | |
| 63 | + int latestFlag; /* --latest. Pick the latest version if true */ | |
| 64 | + int nochangeFlag; /* -n or --nochange. Do a dry run */ | |
| 65 | + int verboseFlag; /* -v or --verbose. Output extra information */ | |
| 58 | 66 | |
| 59 | 67 | url_proxy_options(); |
| 60 | 68 | latestFlag = find_option("latest",0, 0)!=0; |
| 61 | - forceFlag = find_option("force","f",0)!=0; | |
| 69 | + nochangeFlag = find_option("nochange","n",0)!=0; | |
| 70 | + verboseFlag = find_option("verbose","v",0)!=0; | |
| 62 | 71 | if( g.argc!=3 && g.argc!=2 ){ |
| 63 | 72 | usage("?VERSION?"); |
| 64 | 73 | } |
| 65 | 74 | db_must_be_within_tree(); |
| 66 | 75 | vid = db_lget_int("checkout", 0); |
| @@ -78,11 +87,11 @@ | ||
| 78 | 87 | } |
| 79 | 88 | if( !is_a_version(tid) ){ |
| 80 | 89 | fossil_fatal("not a version: %s", g.argv[2]); |
| 81 | 90 | } |
| 82 | 91 | } |
| 83 | - autosync(AUTOSYNC_PULL); | |
| 92 | + if( !nochangeFlag ) autosync(AUTOSYNC_PULL); | |
| 84 | 93 | |
| 85 | 94 | if( tid==0 ){ |
| 86 | 95 | compute_leaves(vid, 1); |
| 87 | 96 | if( !latestFlag && db_int(0, "SELECT count(*) FROM leaves")>1 ){ |
| 88 | 97 | db_prepare(&q, |
| @@ -171,16 +180,16 @@ | ||
| 171 | 180 | printf("CONFLICT %s\n", zName); |
| 172 | 181 | }else if( idt>0 && idv==0 ){ |
| 173 | 182 | /* File added in the target. */ |
| 174 | 183 | printf("ADD %s\n", zName); |
| 175 | 184 | undo_save(zName); |
| 176 | - vfile_to_disk(0, idt, 0); | |
| 185 | + if( !nochangeFlag ) vfile_to_disk(0, idt, 0); | |
| 177 | 186 | }else if( idt>0 && idv>0 && ridt!=ridv && chnged==0 ){ |
| 178 | 187 | /* The file is unedited. Change it to the target version */ |
| 179 | 188 | printf("UPDATE %s\n", zName); |
| 180 | 189 | undo_save(zName); |
| 181 | - vfile_to_disk(0, idt, 0); | |
| 190 | + if( !nochangeFlag ) vfile_to_disk(0, idt, 0); | |
| 182 | 191 | }else if( idt==0 && idv>0 ){ |
| 183 | 192 | if( ridv==0 ){ |
| 184 | 193 | /* Added in current checkout. Continue to hold the file as |
| 185 | 194 | ** as an addition */ |
| 186 | 195 | db_multi_exec("UPDATE vfile SET vid=%d WHERE id=%d", tid, idv); |
| @@ -189,11 +198,11 @@ | ||
| 189 | 198 | }else{ |
| 190 | 199 | char *zFullPath; |
| 191 | 200 | printf("REMOVE %s\n", zName); |
| 192 | 201 | undo_save(zName); |
| 193 | 202 | zFullPath = mprintf("%s/%s", g.zLocalRoot, zName); |
| 194 | - unlink(zFullPath); | |
| 203 | + if( !nochangeFlag ) unlink(zFullPath); | |
| 195 | 204 | free(zFullPath); |
| 196 | 205 | } |
| 197 | 206 | }else if( idt>0 && idv>0 && ridt!=ridv && chnged ){ |
| 198 | 207 | /* Merge the changes in the current tree into the target version */ |
| 199 | 208 | Blob e, r, t, v; |
| @@ -206,11 +215,11 @@ | ||
| 206 | 215 | content_get(ridv, &v); |
| 207 | 216 | blob_zero(&e); |
| 208 | 217 | blob_read_from_file(&e, zFullPath); |
| 209 | 218 | rc = blob_merge(&v, &e, &t, &r); |
| 210 | 219 | if( rc>=0 ){ |
| 211 | - blob_write_to_file(&r, zFullPath); | |
| 220 | + if( !nochangeFlag ) blob_write_to_file(&r, zFullPath); | |
| 212 | 221 | if( rc>0 ){ |
| 213 | 222 | printf("***** %d merge conflicts in %s\n", rc, zName); |
| 214 | 223 | } |
| 215 | 224 | }else{ |
| 216 | 225 | printf("***** Cannot merge binary file %s\n", zName); |
| @@ -218,22 +227,27 @@ | ||
| 218 | 227 | free(zFullPath); |
| 219 | 228 | blob_reset(&v); |
| 220 | 229 | blob_reset(&e); |
| 221 | 230 | blob_reset(&t); |
| 222 | 231 | blob_reset(&r); |
| 223 | - | |
| 232 | + }else if( verboseFlag ){ | |
| 233 | + printf("UNCHANGED %s\n", zName); | |
| 224 | 234 | } |
| 225 | 235 | } |
| 226 | 236 | db_finalize(&q); |
| 227 | 237 | |
| 228 | 238 | /* |
| 229 | 239 | ** Clean up the mid and pid VFILE entries. Then commit the changes. |
| 230 | 240 | */ |
| 231 | - db_multi_exec("DELETE FROM vfile WHERE vid!=%d", tid); | |
| 232 | - manifest_to_disk(tid); | |
| 233 | - db_lset_int("checkout", tid); | |
| 234 | - db_end_transaction(0); | |
| 241 | + if( nochangeFlag ){ | |
| 242 | + db_end_transaction(1); /* With --nochange, rollback changes */ | |
| 243 | + }else{ | |
| 244 | + db_multi_exec("DELETE FROM vfile WHERE vid!=%d", tid); | |
| 245 | + manifest_to_disk(tid); | |
| 246 | + db_lset_int("checkout", tid); | |
| 247 | + db_end_transaction(0); | |
| 248 | + } | |
| 235 | 249 | } |
| 236 | 250 | |
| 237 | 251 | |
| 238 | 252 | /* |
| 239 | 253 | ** Get the contents of a file within a given revision. |
| 240 | 254 |
| --- src/update.c | |
| +++ src/update.c | |
| @@ -36,31 +36,40 @@ | |
| 36 | } |
| 37 | |
| 38 | /* |
| 39 | ** COMMAND: update |
| 40 | ** |
| 41 | ** Usage: %fossil update ?VERSION? ?--latest? |
| 42 | ** |
| 43 | ** The optional argument is a version that should become the current |
| 44 | ** version. If the argument is omitted, then use the leaf of the |
| 45 | ** tree that begins with the current version, if there is only a |
| 46 | ** single leaf. If there are a multiple leaves, the latest is used |
| 47 | ** if the --latest flag is present. |
| 48 | ** |
| 49 | ** This command is different from the "checkout" in that edits are |
| 50 | ** not overwritten. Edits are merged into the new version. |
| 51 | */ |
| 52 | void update_cmd(void){ |
| 53 | int vid; /* Current version */ |
| 54 | int tid=0; /* Target version - version we are changing to */ |
| 55 | Stmt q; |
| 56 | int latestFlag; /* Pick the latest version if true */ |
| 57 | int forceFlag; /* True force the update */ |
| 58 | |
| 59 | url_proxy_options(); |
| 60 | latestFlag = find_option("latest",0, 0)!=0; |
| 61 | forceFlag = find_option("force","f",0)!=0; |
| 62 | if( g.argc!=3 && g.argc!=2 ){ |
| 63 | usage("?VERSION?"); |
| 64 | } |
| 65 | db_must_be_within_tree(); |
| 66 | vid = db_lget_int("checkout", 0); |
| @@ -78,11 +87,11 @@ | |
| 78 | } |
| 79 | if( !is_a_version(tid) ){ |
| 80 | fossil_fatal("not a version: %s", g.argv[2]); |
| 81 | } |
| 82 | } |
| 83 | autosync(AUTOSYNC_PULL); |
| 84 | |
| 85 | if( tid==0 ){ |
| 86 | compute_leaves(vid, 1); |
| 87 | if( !latestFlag && db_int(0, "SELECT count(*) FROM leaves")>1 ){ |
| 88 | db_prepare(&q, |
| @@ -171,16 +180,16 @@ | |
| 171 | printf("CONFLICT %s\n", zName); |
| 172 | }else if( idt>0 && idv==0 ){ |
| 173 | /* File added in the target. */ |
| 174 | printf("ADD %s\n", zName); |
| 175 | undo_save(zName); |
| 176 | vfile_to_disk(0, idt, 0); |
| 177 | }else if( idt>0 && idv>0 && ridt!=ridv && chnged==0 ){ |
| 178 | /* The file is unedited. Change it to the target version */ |
| 179 | printf("UPDATE %s\n", zName); |
| 180 | undo_save(zName); |
| 181 | vfile_to_disk(0, idt, 0); |
| 182 | }else if( idt==0 && idv>0 ){ |
| 183 | if( ridv==0 ){ |
| 184 | /* Added in current checkout. Continue to hold the file as |
| 185 | ** as an addition */ |
| 186 | db_multi_exec("UPDATE vfile SET vid=%d WHERE id=%d", tid, idv); |
| @@ -189,11 +198,11 @@ | |
| 189 | }else{ |
| 190 | char *zFullPath; |
| 191 | printf("REMOVE %s\n", zName); |
| 192 | undo_save(zName); |
| 193 | zFullPath = mprintf("%s/%s", g.zLocalRoot, zName); |
| 194 | unlink(zFullPath); |
| 195 | free(zFullPath); |
| 196 | } |
| 197 | }else if( idt>0 && idv>0 && ridt!=ridv && chnged ){ |
| 198 | /* Merge the changes in the current tree into the target version */ |
| 199 | Blob e, r, t, v; |
| @@ -206,11 +215,11 @@ | |
| 206 | content_get(ridv, &v); |
| 207 | blob_zero(&e); |
| 208 | blob_read_from_file(&e, zFullPath); |
| 209 | rc = blob_merge(&v, &e, &t, &r); |
| 210 | if( rc>=0 ){ |
| 211 | blob_write_to_file(&r, zFullPath); |
| 212 | if( rc>0 ){ |
| 213 | printf("***** %d merge conflicts in %s\n", rc, zName); |
| 214 | } |
| 215 | }else{ |
| 216 | printf("***** Cannot merge binary file %s\n", zName); |
| @@ -218,22 +227,27 @@ | |
| 218 | free(zFullPath); |
| 219 | blob_reset(&v); |
| 220 | blob_reset(&e); |
| 221 | blob_reset(&t); |
| 222 | blob_reset(&r); |
| 223 | |
| 224 | } |
| 225 | } |
| 226 | db_finalize(&q); |
| 227 | |
| 228 | /* |
| 229 | ** Clean up the mid and pid VFILE entries. Then commit the changes. |
| 230 | */ |
| 231 | db_multi_exec("DELETE FROM vfile WHERE vid!=%d", tid); |
| 232 | manifest_to_disk(tid); |
| 233 | db_lset_int("checkout", tid); |
| 234 | db_end_transaction(0); |
| 235 | } |
| 236 | |
| 237 | |
| 238 | /* |
| 239 | ** Get the contents of a file within a given revision. |
| 240 |
| --- src/update.c | |
| +++ src/update.c | |
| @@ -36,31 +36,40 @@ | |
| 36 | } |
| 37 | |
| 38 | /* |
| 39 | ** COMMAND: update |
| 40 | ** |
| 41 | ** Usage: %fossil update ?VERSION? ?OPTIONS? |
| 42 | ** |
| 43 | ** Change the version of the current checkout to VERSION. Any uncommitted |
| 44 | ** changes are retained and applied to the new checkout. |
| 45 | ** |
| 46 | ** The VERSION argument can be a specific version or tag or branch name. |
| 47 | ** If the VERSION argument is omitted, then the leaf of the the subtree |
| 48 | ** that begins at the current version is used, if there is only a single |
| 49 | ** leaf. Instead of specifying VERSION, use the --latest option to update |
| 50 | ** to the most recent check-in. |
| 51 | ** |
| 52 | ** The -n or --nochange option causes this command to do a "dry run". It |
| 53 | ** prints out what would have happened but does not actually make any |
| 54 | ** changes to the current checkout or the repository. |
| 55 | ** |
| 56 | ** The -v or --verbose option prints status information about unchanged |
| 57 | ** files in addition to those file that actually do change. |
| 58 | */ |
| 59 | void update_cmd(void){ |
| 60 | int vid; /* Current version */ |
| 61 | int tid=0; /* Target version - version we are changing to */ |
| 62 | Stmt q; |
| 63 | int latestFlag; /* --latest. Pick the latest version if true */ |
| 64 | int nochangeFlag; /* -n or --nochange. Do a dry run */ |
| 65 | int verboseFlag; /* -v or --verbose. Output extra information */ |
| 66 | |
| 67 | url_proxy_options(); |
| 68 | latestFlag = find_option("latest",0, 0)!=0; |
| 69 | nochangeFlag = find_option("nochange","n",0)!=0; |
| 70 | verboseFlag = find_option("verbose","v",0)!=0; |
| 71 | if( g.argc!=3 && g.argc!=2 ){ |
| 72 | usage("?VERSION?"); |
| 73 | } |
| 74 | db_must_be_within_tree(); |
| 75 | vid = db_lget_int("checkout", 0); |
| @@ -78,11 +87,11 @@ | |
| 87 | } |
| 88 | if( !is_a_version(tid) ){ |
| 89 | fossil_fatal("not a version: %s", g.argv[2]); |
| 90 | } |
| 91 | } |
| 92 | if( !nochangeFlag ) autosync(AUTOSYNC_PULL); |
| 93 | |
| 94 | if( tid==0 ){ |
| 95 | compute_leaves(vid, 1); |
| 96 | if( !latestFlag && db_int(0, "SELECT count(*) FROM leaves")>1 ){ |
| 97 | db_prepare(&q, |
| @@ -171,16 +180,16 @@ | |
| 180 | printf("CONFLICT %s\n", zName); |
| 181 | }else if( idt>0 && idv==0 ){ |
| 182 | /* File added in the target. */ |
| 183 | printf("ADD %s\n", zName); |
| 184 | undo_save(zName); |
| 185 | if( !nochangeFlag ) vfile_to_disk(0, idt, 0); |
| 186 | }else if( idt>0 && idv>0 && ridt!=ridv && chnged==0 ){ |
| 187 | /* The file is unedited. Change it to the target version */ |
| 188 | printf("UPDATE %s\n", zName); |
| 189 | undo_save(zName); |
| 190 | if( !nochangeFlag ) vfile_to_disk(0, idt, 0); |
| 191 | }else if( idt==0 && idv>0 ){ |
| 192 | if( ridv==0 ){ |
| 193 | /* Added in current checkout. Continue to hold the file as |
| 194 | ** as an addition */ |
| 195 | db_multi_exec("UPDATE vfile SET vid=%d WHERE id=%d", tid, idv); |
| @@ -189,11 +198,11 @@ | |
| 198 | }else{ |
| 199 | char *zFullPath; |
| 200 | printf("REMOVE %s\n", zName); |
| 201 | undo_save(zName); |
| 202 | zFullPath = mprintf("%s/%s", g.zLocalRoot, zName); |
| 203 | if( !nochangeFlag ) unlink(zFullPath); |
| 204 | free(zFullPath); |
| 205 | } |
| 206 | }else if( idt>0 && idv>0 && ridt!=ridv && chnged ){ |
| 207 | /* Merge the changes in the current tree into the target version */ |
| 208 | Blob e, r, t, v; |
| @@ -206,11 +215,11 @@ | |
| 215 | content_get(ridv, &v); |
| 216 | blob_zero(&e); |
| 217 | blob_read_from_file(&e, zFullPath); |
| 218 | rc = blob_merge(&v, &e, &t, &r); |
| 219 | if( rc>=0 ){ |
| 220 | if( !nochangeFlag ) blob_write_to_file(&r, zFullPath); |
| 221 | if( rc>0 ){ |
| 222 | printf("***** %d merge conflicts in %s\n", rc, zName); |
| 223 | } |
| 224 | }else{ |
| 225 | printf("***** Cannot merge binary file %s\n", zName); |
| @@ -218,22 +227,27 @@ | |
| 227 | free(zFullPath); |
| 228 | blob_reset(&v); |
| 229 | blob_reset(&e); |
| 230 | blob_reset(&t); |
| 231 | blob_reset(&r); |
| 232 | }else if( verboseFlag ){ |
| 233 | printf("UNCHANGED %s\n", zName); |
| 234 | } |
| 235 | } |
| 236 | db_finalize(&q); |
| 237 | |
| 238 | /* |
| 239 | ** Clean up the mid and pid VFILE entries. Then commit the changes. |
| 240 | */ |
| 241 | if( nochangeFlag ){ |
| 242 | db_end_transaction(1); /* With --nochange, rollback changes */ |
| 243 | }else{ |
| 244 | db_multi_exec("DELETE FROM vfile WHERE vid!=%d", tid); |
| 245 | manifest_to_disk(tid); |
| 246 | db_lset_int("checkout", tid); |
| 247 | db_end_transaction(0); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | |
| 252 | /* |
| 253 | ** Get the contents of a file within a given revision. |
| 254 |