Fossil SCM

Add --nochanges and --verbose options to the "update" command. Tickets [4d6b7d4e1] and [7a27e10f1fe].

drh 2009-12-17 16:17 trunk
Commit 1d9ebd9e4a5a05ba85279792deb8771d94b84450
1 file changed +37 -23
+37 -23
--- src/update.c
+++ src/update.c
@@ -36,31 +36,40 @@
3636
}
3737
3838
/*
3939
** COMMAND: update
4040
**
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.
5158
*/
5259
void update_cmd(void){
5360
int vid; /* Current version */
5461
int tid=0; /* Target version - version we are changing to */
5562
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 */
5866
5967
url_proxy_options();
6068
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;
6271
if( g.argc!=3 && g.argc!=2 ){
6372
usage("?VERSION?");
6473
}
6574
db_must_be_within_tree();
6675
vid = db_lget_int("checkout", 0);
@@ -78,11 +87,11 @@
7887
}
7988
if( !is_a_version(tid) ){
8089
fossil_fatal("not a version: %s", g.argv[2]);
8190
}
8291
}
83
- autosync(AUTOSYNC_PULL);
92
+ if( !nochangeFlag ) autosync(AUTOSYNC_PULL);
8493
8594
if( tid==0 ){
8695
compute_leaves(vid, 1);
8796
if( !latestFlag && db_int(0, "SELECT count(*) FROM leaves")>1 ){
8897
db_prepare(&q,
@@ -171,16 +180,16 @@
171180
printf("CONFLICT %s\n", zName);
172181
}else if( idt>0 && idv==0 ){
173182
/* File added in the target. */
174183
printf("ADD %s\n", zName);
175184
undo_save(zName);
176
- vfile_to_disk(0, idt, 0);
185
+ if( !nochangeFlag ) vfile_to_disk(0, idt, 0);
177186
}else if( idt>0 && idv>0 && ridt!=ridv && chnged==0 ){
178187
/* The file is unedited. Change it to the target version */
179188
printf("UPDATE %s\n", zName);
180189
undo_save(zName);
181
- vfile_to_disk(0, idt, 0);
190
+ if( !nochangeFlag ) vfile_to_disk(0, idt, 0);
182191
}else if( idt==0 && idv>0 ){
183192
if( ridv==0 ){
184193
/* Added in current checkout. Continue to hold the file as
185194
** as an addition */
186195
db_multi_exec("UPDATE vfile SET vid=%d WHERE id=%d", tid, idv);
@@ -189,11 +198,11 @@
189198
}else{
190199
char *zFullPath;
191200
printf("REMOVE %s\n", zName);
192201
undo_save(zName);
193202
zFullPath = mprintf("%s/%s", g.zLocalRoot, zName);
194
- unlink(zFullPath);
203
+ if( !nochangeFlag ) unlink(zFullPath);
195204
free(zFullPath);
196205
}
197206
}else if( idt>0 && idv>0 && ridt!=ridv && chnged ){
198207
/* Merge the changes in the current tree into the target version */
199208
Blob e, r, t, v;
@@ -206,11 +215,11 @@
206215
content_get(ridv, &v);
207216
blob_zero(&e);
208217
blob_read_from_file(&e, zFullPath);
209218
rc = blob_merge(&v, &e, &t, &r);
210219
if( rc>=0 ){
211
- blob_write_to_file(&r, zFullPath);
220
+ if( !nochangeFlag ) blob_write_to_file(&r, zFullPath);
212221
if( rc>0 ){
213222
printf("***** %d merge conflicts in %s\n", rc, zName);
214223
}
215224
}else{
216225
printf("***** Cannot merge binary file %s\n", zName);
@@ -218,22 +227,27 @@
218227
free(zFullPath);
219228
blob_reset(&v);
220229
blob_reset(&e);
221230
blob_reset(&t);
222231
blob_reset(&r);
223
-
232
+ }else if( verboseFlag ){
233
+ printf("UNCHANGED %s\n", zName);
224234
}
225235
}
226236
db_finalize(&q);
227237
228238
/*
229239
** Clean up the mid and pid VFILE entries. Then commit the changes.
230240
*/
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
+ }
235249
}
236250
237251
238252
/*
239253
** Get the contents of a file within a given revision.
240254
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button