Fossil SCM

Add the --out option to the "cat" command to specify an output file - only if a single historical file is requested.

danield 2023-03-14 17:18 trunk
Commit 8975472d2651b49bb629ba23248b54488a265701a13518f5919208335664d6b4
1 file changed +14 -3
+14 -3
--- src/finfo.c
+++ src/finfo.c
@@ -272,30 +272,41 @@
272272
** Print on standard output the content of one or more files as they exist
273273
** in the repository. The version currently checked out is shown by default.
274274
** Other versions may be specified using the -r option.
275275
**
276276
** 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
279280
**
280281
** See also: [[finfo]]
281282
*/
282283
void cat_cmd(void){
283284
int i;
284285
Blob content, fname;
285286
const char *zRev;
287
+ const char *zFileName;
286288
db_find_and_open_repository(0, 0);
287289
zRev = find_option("r","r",1);
290
+ zFileName = find_option("out","o",1);
288291
289292
/* We should be done with options.. */
290293
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
+ }
291298
292299
for(i=2; i<g.argc; i++){
293300
file_tree_name(g.argv[i], &fname, 0, 1);
294301
blob_zero(&content);
295302
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
+ }
297308
blob_reset(&fname);
298309
blob_reset(&content);
299310
}
300311
}
301312
302313
--- 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

Keyboard Shortcuts

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