Fossil SCM
Add the --out option to the "cat" command to specify an output file - only if a single historical file is requested.
Commit
8975472d2651b49bb629ba23248b54488a265701a13518f5919208335664d6b4
Parent
d2c93a417e8f988…
1 file changed
+14
-3
+14
-3
| --- src/finfo.c | ||
| +++ src/finfo.c | ||
| @@ -272,30 +272,41 @@ | ||
| 272 | 272 | ** Print on standard output the content of one or more files as they exist |
| 273 | 273 | ** in the repository. The version currently checked out is shown by default. |
| 274 | 274 | ** Other versions may be specified using the -r option. |
| 275 | 275 | ** |
| 276 | 276 | ** Options: |
| 277 | -** -R|--repository REPO Extract artifacts from repository REPO | |
| 278 | -** -r VERSION The specific check-in containing the file | |
| 277 | +** -o|--out OUTFILE For exactly one given FILENAME, write to OUTFILE | |
| 278 | +** -R|--repository REPO Extract artifacts from repository REPO | |
| 279 | +** -r VERSION The specific check-in containing the file | |
| 279 | 280 | ** |
| 280 | 281 | ** See also: [[finfo]] |
| 281 | 282 | */ |
| 282 | 283 | void cat_cmd(void){ |
| 283 | 284 | int i; |
| 284 | 285 | Blob content, fname; |
| 285 | 286 | const char *zRev; |
| 287 | + const char *zFileName; | |
| 286 | 288 | db_find_and_open_repository(0, 0); |
| 287 | 289 | zRev = find_option("r","r",1); |
| 290 | + zFileName = find_option("out","o",1); | |
| 288 | 291 | |
| 289 | 292 | /* We should be done with options.. */ |
| 290 | 293 | verify_all_options(); |
| 294 | + | |
| 295 | + if ( zFileName && g.argc>3 ){ | |
| 296 | + fossil_fatal("output file can only be given when retrieving a single file"); | |
| 297 | + } | |
| 291 | 298 | |
| 292 | 299 | for(i=2; i<g.argc; i++){ |
| 293 | 300 | file_tree_name(g.argv[i], &fname, 0, 1); |
| 294 | 301 | blob_zero(&content); |
| 295 | 302 | historical_blob(zRev, blob_str(&fname), &content, 1); |
| 296 | - blob_write_to_file(&content, "-"); | |
| 303 | + if ( g.argc==3 && zFileName ){ | |
| 304 | + blob_write_to_file(&content, zFileName); | |
| 305 | + }else{ | |
| 306 | + blob_write_to_file(&content, "-"); | |
| 307 | + } | |
| 297 | 308 | blob_reset(&fname); |
| 298 | 309 | blob_reset(&content); |
| 299 | 310 | } |
| 300 | 311 | } |
| 301 | 312 | |
| 302 | 313 |
| --- src/finfo.c | |
| +++ src/finfo.c | |
| @@ -272,30 +272,41 @@ | |
| 272 | ** Print on standard output the content of one or more files as they exist |
| 273 | ** in the repository. The version currently checked out is shown by default. |
| 274 | ** Other versions may be specified using the -r option. |
| 275 | ** |
| 276 | ** Options: |
| 277 | ** -R|--repository REPO Extract artifacts from repository REPO |
| 278 | ** -r VERSION The specific check-in containing the file |
| 279 | ** |
| 280 | ** See also: [[finfo]] |
| 281 | */ |
| 282 | void cat_cmd(void){ |
| 283 | int i; |
| 284 | Blob content, fname; |
| 285 | const char *zRev; |
| 286 | db_find_and_open_repository(0, 0); |
| 287 | zRev = find_option("r","r",1); |
| 288 | |
| 289 | /* We should be done with options.. */ |
| 290 | verify_all_options(); |
| 291 | |
| 292 | for(i=2; i<g.argc; i++){ |
| 293 | file_tree_name(g.argv[i], &fname, 0, 1); |
| 294 | blob_zero(&content); |
| 295 | historical_blob(zRev, blob_str(&fname), &content, 1); |
| 296 | blob_write_to_file(&content, "-"); |
| 297 | blob_reset(&fname); |
| 298 | blob_reset(&content); |
| 299 | } |
| 300 | } |
| 301 | |
| 302 |
| --- src/finfo.c | |
| +++ src/finfo.c | |
| @@ -272,30 +272,41 @@ | |
| 272 | ** Print on standard output the content of one or more files as they exist |
| 273 | ** in the repository. The version currently checked out is shown by default. |
| 274 | ** Other versions may be specified using the -r option. |
| 275 | ** |
| 276 | ** Options: |
| 277 | ** -o|--out OUTFILE For exactly one given FILENAME, write to OUTFILE |
| 278 | ** -R|--repository REPO Extract artifacts from repository REPO |
| 279 | ** -r VERSION The specific check-in containing the file |
| 280 | ** |
| 281 | ** See also: [[finfo]] |
| 282 | */ |
| 283 | void cat_cmd(void){ |
| 284 | int i; |
| 285 | Blob content, fname; |
| 286 | const char *zRev; |
| 287 | const char *zFileName; |
| 288 | db_find_and_open_repository(0, 0); |
| 289 | zRev = find_option("r","r",1); |
| 290 | zFileName = find_option("out","o",1); |
| 291 | |
| 292 | /* We should be done with options.. */ |
| 293 | verify_all_options(); |
| 294 | |
| 295 | if ( zFileName && g.argc>3 ){ |
| 296 | fossil_fatal("output file can only be given when retrieving a single file"); |
| 297 | } |
| 298 | |
| 299 | for(i=2; i<g.argc; i++){ |
| 300 | file_tree_name(g.argv[i], &fname, 0, 1); |
| 301 | blob_zero(&content); |
| 302 | historical_blob(zRev, blob_str(&fname), &content, 1); |
| 303 | if ( g.argc==3 && zFileName ){ |
| 304 | blob_write_to_file(&content, zFileName); |
| 305 | }else{ |
| 306 | blob_write_to_file(&content, "-"); |
| 307 | } |
| 308 | blob_reset(&fname); |
| 309 | blob_reset(&content); |
| 310 | } |
| 311 | } |
| 312 | |
| 313 |