Fossil SCM
Change the "revert" command so that it will take multiple file arguments and revert each one.
Commit
353297a149b49964445783d5e9e3bbb6b01f1b69
Parent
2f15cd805e03788…
1 file changed
+42
-39
+42
-39
| --- src/update.c | ||
| +++ src/update.c | ||
| @@ -273,65 +273,68 @@ | ||
| 273 | 273 | |
| 274 | 274 | |
| 275 | 275 | /* |
| 276 | 276 | ** COMMAND: revert |
| 277 | 277 | ** |
| 278 | -** Usage: %fossil revert ?--yes? ?-r REVISION? FILE | |
| 278 | +** Usage: %fossil revert ?--yes? ?-r REVISION? FILE ... | |
| 279 | 279 | ** |
| 280 | 280 | ** Revert to the current repository version of FILE, or to |
| 281 | 281 | ** the version associated with baseline REVISION if the -r flag |
| 282 | 282 | ** appears. This command will confirm your operation unless the |
| 283 | 283 | ** file is missing or the --yes option is used. |
| 284 | 284 | **/ |
| 285 | 285 | void revert_cmd(void){ |
| 286 | - const char *zFile; | |
| 286 | + char *zFile; | |
| 287 | 287 | const char *zRevision; |
| 288 | 288 | Blob fname; |
| 289 | 289 | Blob record; |
| 290 | 290 | Blob ans; |
| 291 | + int i; | |
| 291 | 292 | int rid = 0, yesRevert; |
| 292 | 293 | |
| 293 | 294 | yesRevert = find_option("yes", "y", 0)!=0; |
| 294 | 295 | zRevision = find_option("revision", "r", 1); |
| 295 | 296 | verify_all_options(); |
| 296 | 297 | |
| 297 | - if( g.argc!=3 ){ | |
| 298 | - usage("?OPTIONS FILE"); | |
| 298 | + if( g.argc<3 ){ | |
| 299 | + usage("?OPTIONS FILE ..."); | |
| 299 | 300 | } |
| 300 | 301 | db_must_be_within_tree(); |
| 301 | - | |
| 302 | - zFile = mprintf("%/", g.argv[g.argc-1]); | |
| 303 | - | |
| 304 | - file_tree_name(zFile, &fname, 1); | |
| 305 | - | |
| 306 | - if( access(zFile, 0) ) yesRevert = 1; | |
| 307 | - if( yesRevert==0 ){ | |
| 308 | - char *prompt = mprintf("revert file %B? this will" | |
| 309 | - " destroy local changes (y/N)? ", | |
| 310 | - &fname); | |
| 311 | - blob_zero(&ans); | |
| 312 | - prompt_user(prompt, &ans); | |
| 313 | - free( prompt ); | |
| 314 | - if( blob_str(&ans)[0]=='y' ){ | |
| 315 | - yesRevert = 1; | |
| 316 | - } | |
| 317 | - } | |
| 318 | - | |
| 319 | - if( yesRevert==1 && zRevision!=0 ){ | |
| 320 | - historical_version_of_file(zRevision, zFile, &record); | |
| 321 | - }else if( yesRevert==1 ){ | |
| 322 | - rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname); | |
| 323 | - if( rid==0 ){ | |
| 324 | - fossil_panic("no history for file: %b", &fname); | |
| 325 | - } | |
| 326 | - content_get(rid, &record); | |
| 327 | - } | |
| 328 | - | |
| 329 | - if( yesRevert==1 ){ | |
| 330 | - blob_write_to_file(&record, zFile); | |
| 331 | - printf("%s reverted\n", zFile); | |
| 332 | - blob_reset(&record); | |
| 333 | - blob_reset(&fname); | |
| 334 | - }else{ | |
| 335 | - printf("revert canceled\n"); | |
| 302 | + | |
| 303 | + for(i=2; i<g.argc; i++){ | |
| 304 | + zFile = mprintf("%/", g.argv[i]); | |
| 305 | + file_tree_name(zFile, &fname, 1); | |
| 306 | + if( access(zFile, 0) ) yesRevert = 1; | |
| 307 | + if( yesRevert==0 ){ | |
| 308 | + char *prompt = mprintf("revert file %B? this will" | |
| 309 | + " destroy local changes (y/N)? ", | |
| 310 | + &fname); | |
| 311 | + blob_zero(&ans); | |
| 312 | + prompt_user(prompt, &ans); | |
| 313 | + free( prompt ); | |
| 314 | + if( blob_str(&ans)[0]=='y' ){ | |
| 315 | + yesRevert = 1; | |
| 316 | + } | |
| 317 | + blob_reset(&ans); | |
| 318 | + } | |
| 319 | + | |
| 320 | + if( yesRevert==1 && zRevision!=0 ){ | |
| 321 | + historical_version_of_file(zRevision, zFile, &record); | |
| 322 | + }else if( yesRevert==1 ){ | |
| 323 | + rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname); | |
| 324 | + if( rid==0 ){ | |
| 325 | + fossil_panic("no history for file: %b", &fname); | |
| 326 | + } | |
| 327 | + content_get(rid, &record); | |
| 328 | + } | |
| 329 | + | |
| 330 | + if( yesRevert==1 ){ | |
| 331 | + blob_write_to_file(&record, zFile); | |
| 332 | + printf("%s reverted\n", zFile); | |
| 333 | + blob_reset(&record); | |
| 334 | + blob_reset(&fname); | |
| 335 | + }else{ | |
| 336 | + printf("revert canceled\n"); | |
| 337 | + } | |
| 338 | + free(zFile); | |
| 336 | 339 | } |
| 337 | 340 | } |
| 338 | 341 |
| --- src/update.c | |
| +++ src/update.c | |
| @@ -273,65 +273,68 @@ | |
| 273 | |
| 274 | |
| 275 | /* |
| 276 | ** COMMAND: revert |
| 277 | ** |
| 278 | ** Usage: %fossil revert ?--yes? ?-r REVISION? FILE |
| 279 | ** |
| 280 | ** Revert to the current repository version of FILE, or to |
| 281 | ** the version associated with baseline REVISION if the -r flag |
| 282 | ** appears. This command will confirm your operation unless the |
| 283 | ** file is missing or the --yes option is used. |
| 284 | **/ |
| 285 | void revert_cmd(void){ |
| 286 | const char *zFile; |
| 287 | const char *zRevision; |
| 288 | Blob fname; |
| 289 | Blob record; |
| 290 | Blob ans; |
| 291 | int rid = 0, yesRevert; |
| 292 | |
| 293 | yesRevert = find_option("yes", "y", 0)!=0; |
| 294 | zRevision = find_option("revision", "r", 1); |
| 295 | verify_all_options(); |
| 296 | |
| 297 | if( g.argc!=3 ){ |
| 298 | usage("?OPTIONS FILE"); |
| 299 | } |
| 300 | db_must_be_within_tree(); |
| 301 | |
| 302 | zFile = mprintf("%/", g.argv[g.argc-1]); |
| 303 | |
| 304 | file_tree_name(zFile, &fname, 1); |
| 305 | |
| 306 | if( access(zFile, 0) ) yesRevert = 1; |
| 307 | if( yesRevert==0 ){ |
| 308 | char *prompt = mprintf("revert file %B? this will" |
| 309 | " destroy local changes (y/N)? ", |
| 310 | &fname); |
| 311 | blob_zero(&ans); |
| 312 | prompt_user(prompt, &ans); |
| 313 | free( prompt ); |
| 314 | if( blob_str(&ans)[0]=='y' ){ |
| 315 | yesRevert = 1; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | if( yesRevert==1 && zRevision!=0 ){ |
| 320 | historical_version_of_file(zRevision, zFile, &record); |
| 321 | }else if( yesRevert==1 ){ |
| 322 | rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname); |
| 323 | if( rid==0 ){ |
| 324 | fossil_panic("no history for file: %b", &fname); |
| 325 | } |
| 326 | content_get(rid, &record); |
| 327 | } |
| 328 | |
| 329 | if( yesRevert==1 ){ |
| 330 | blob_write_to_file(&record, zFile); |
| 331 | printf("%s reverted\n", zFile); |
| 332 | blob_reset(&record); |
| 333 | blob_reset(&fname); |
| 334 | }else{ |
| 335 | printf("revert canceled\n"); |
| 336 | } |
| 337 | } |
| 338 |
| --- src/update.c | |
| +++ src/update.c | |
| @@ -273,65 +273,68 @@ | |
| 273 | |
| 274 | |
| 275 | /* |
| 276 | ** COMMAND: revert |
| 277 | ** |
| 278 | ** Usage: %fossil revert ?--yes? ?-r REVISION? FILE ... |
| 279 | ** |
| 280 | ** Revert to the current repository version of FILE, or to |
| 281 | ** the version associated with baseline REVISION if the -r flag |
| 282 | ** appears. This command will confirm your operation unless the |
| 283 | ** file is missing or the --yes option is used. |
| 284 | **/ |
| 285 | void revert_cmd(void){ |
| 286 | char *zFile; |
| 287 | const char *zRevision; |
| 288 | Blob fname; |
| 289 | Blob record; |
| 290 | Blob ans; |
| 291 | int i; |
| 292 | int rid = 0, yesRevert; |
| 293 | |
| 294 | yesRevert = find_option("yes", "y", 0)!=0; |
| 295 | zRevision = find_option("revision", "r", 1); |
| 296 | verify_all_options(); |
| 297 | |
| 298 | if( g.argc<3 ){ |
| 299 | usage("?OPTIONS FILE ..."); |
| 300 | } |
| 301 | db_must_be_within_tree(); |
| 302 | |
| 303 | for(i=2; i<g.argc; i++){ |
| 304 | zFile = mprintf("%/", g.argv[i]); |
| 305 | file_tree_name(zFile, &fname, 1); |
| 306 | if( access(zFile, 0) ) yesRevert = 1; |
| 307 | if( yesRevert==0 ){ |
| 308 | char *prompt = mprintf("revert file %B? this will" |
| 309 | " destroy local changes (y/N)? ", |
| 310 | &fname); |
| 311 | blob_zero(&ans); |
| 312 | prompt_user(prompt, &ans); |
| 313 | free( prompt ); |
| 314 | if( blob_str(&ans)[0]=='y' ){ |
| 315 | yesRevert = 1; |
| 316 | } |
| 317 | blob_reset(&ans); |
| 318 | } |
| 319 | |
| 320 | if( yesRevert==1 && zRevision!=0 ){ |
| 321 | historical_version_of_file(zRevision, zFile, &record); |
| 322 | }else if( yesRevert==1 ){ |
| 323 | rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname); |
| 324 | if( rid==0 ){ |
| 325 | fossil_panic("no history for file: %b", &fname); |
| 326 | } |
| 327 | content_get(rid, &record); |
| 328 | } |
| 329 | |
| 330 | if( yesRevert==1 ){ |
| 331 | blob_write_to_file(&record, zFile); |
| 332 | printf("%s reverted\n", zFile); |
| 333 | blob_reset(&record); |
| 334 | blob_reset(&fname); |
| 335 | }else{ |
| 336 | printf("revert canceled\n"); |
| 337 | } |
| 338 | free(zFile); |
| 339 | } |
| 340 | } |
| 341 |