Fossil SCM

Add the "fossil cat" command, which is an alias for "fossil finfo -p"

drh 2012-11-28 20:37 trunk
Commit 607ff0855c203c7c32dd469e538e6398d58225db
1 file changed +44 -8
+44 -8
--- src/finfo.c
+++ src/finfo.c
@@ -24,23 +24,23 @@
2424
** COMMAND: finfo
2525
**
2626
** Usage: %fossil finfo ?OPTIONS? FILENAME
2727
**
2828
** Print the complete change history for a single file going backwards
29
-** in time. The default is -l.
29
+** in time. The default mode is -l.
3030
**
31
-** For the -l|--log option: If "-b|--brief" is specified one line per revision
31
+** For the -l|--log mode: If "-b|--brief" is specified one line per revision
3232
** is printed, otherwise the full comment is printed. The "--limit N"
3333
** and "--offset P" options limits the output to the first N changes
3434
** after skipping P changes.
3535
**
36
-** In the -s form prints the status as <status> <revision>. This is
36
+** In the -s mode prints the status as <status> <revision>. This is
3737
** a quick status and does not check for up-to-date-ness of the file.
3838
**
39
-** In the -p form, there's an optional flag "-r|--revision REVISION".
39
+** In the -p mode, there's an optional flag "-r|--revision REVISION".
4040
** The specified version (or the latest checked out version) is printed
41
-** to stdout.
41
+** to stdout. The -p mode is another form of the "cat" command.
4242
**
4343
** Options:
4444
** --brief|-b display a brief (one line / revision) summary
4545
** --limit N display the first N changes
4646
** --log|-l select log mode (the default)
@@ -50,11 +50,11 @@
5050
** to stdout (only in print mode)
5151
** -s select status mode (print a status indicator for FILE)
5252
** --case-sensitive B Enable or disable case-sensitive filenames. B is a
5353
** boolean: "yes", "no", "true", "false", etc.
5454
**
55
-** See also: artifact, descendants, info, leaves
55
+** See also: artifact, cat, descendants, info, leaves
5656
*/
5757
void finfo_cmd(void){
5858
capture_case_sensitive_option();
5959
db_must_be_within_tree();
6060
if (find_option("status","s",0)) {
@@ -185,12 +185,13 @@
185185
const char *zBr = db_column_text(&q, 5);
186186
char *zOut;
187187
if( zBr==0 ) zBr = "trunk";
188188
if( iBrief ){
189189
fossil_print("%s ", zDate);
190
- zOut = sqlite3_mprintf("[%.10s] %s (user: %s, artifact: [%.10s], branch: %s)",
191
- zCiUuid, zCom, zUser, zFileUuid, zBr);
190
+ zOut = sqlite3_mprintf(
191
+ "[%.10s] %s (user: %s, artifact: [%.10s], branch: %s)",
192
+ zCiUuid, zCom, zUser, zFileUuid, zBr);
192193
comment_print(zOut, 11, 79);
193194
sqlite3_free(zOut);
194195
}else{
195196
blob_reset(&line);
196197
blob_appendf(&line, "%.10s ", zCiUuid);
@@ -203,10 +204,45 @@
203204
}
204205
db_finalize(&q);
205206
blob_reset(&fname);
206207
}
207208
}
209
+
210
+/*
211
+** COMMAND: cat
212
+**
213
+** Usage: %fossil cat FILENAME ... ?OPTIONS?
214
+**
215
+** Print on standard output the content of one or more files as they exist
216
+** in the repository. The version currently checked out is shown by default.
217
+** Other versions may be specified using the -r option.
218
+**
219
+** Options:
220
+** -R|--repository FILE Extract artifacts from repository FILE
221
+** -r VERSION The specific check-in containing the file
222
+**
223
+** See also: finfo
224
+*/
225
+void cat_cmd(void){
226
+ int i;
227
+ int rc;
228
+ Blob content, fname;
229
+ const char *zRev;
230
+ db_find_and_open_repository(0, 0);
231
+ zRev = find_option("r","r",1);
232
+ for(i=2; i<g.argc; i++){
233
+ file_tree_name(g.argv[i], &fname, 1);
234
+ blob_zero(&content);
235
+ rc = historical_version_of_file(zRev, blob_str(&fname), &content, 0,0,0,0);
236
+ if( rc==0 ){
237
+ fossil_fatal("no such file: %s", g.argv[i]);
238
+ }
239
+ blob_write_to_file(&content, "-");
240
+ blob_reset(&fname);
241
+ blob_reset(&content);
242
+ }
243
+}
208244
209245
/* Values for the debug= query parameter to finfo */
210246
#define FINFO_DEBUG_MLINK 0x01
211247
212248
/*
213249
--- src/finfo.c
+++ src/finfo.c
@@ -24,23 +24,23 @@
24 ** COMMAND: finfo
25 **
26 ** Usage: %fossil finfo ?OPTIONS? FILENAME
27 **
28 ** Print the complete change history for a single file going backwards
29 ** in time. The default is -l.
30 **
31 ** For the -l|--log option: If "-b|--brief" is specified one line per revision
32 ** is printed, otherwise the full comment is printed. The "--limit N"
33 ** and "--offset P" options limits the output to the first N changes
34 ** after skipping P changes.
35 **
36 ** In the -s form prints the status as <status> <revision>. This is
37 ** a quick status and does not check for up-to-date-ness of the file.
38 **
39 ** In the -p form, there's an optional flag "-r|--revision REVISION".
40 ** The specified version (or the latest checked out version) is printed
41 ** to stdout.
42 **
43 ** Options:
44 ** --brief|-b display a brief (one line / revision) summary
45 ** --limit N display the first N changes
46 ** --log|-l select log mode (the default)
@@ -50,11 +50,11 @@
50 ** to stdout (only in print mode)
51 ** -s select status mode (print a status indicator for FILE)
52 ** --case-sensitive B Enable or disable case-sensitive filenames. B is a
53 ** boolean: "yes", "no", "true", "false", etc.
54 **
55 ** See also: artifact, descendants, info, leaves
56 */
57 void finfo_cmd(void){
58 capture_case_sensitive_option();
59 db_must_be_within_tree();
60 if (find_option("status","s",0)) {
@@ -185,12 +185,13 @@
185 const char *zBr = db_column_text(&q, 5);
186 char *zOut;
187 if( zBr==0 ) zBr = "trunk";
188 if( iBrief ){
189 fossil_print("%s ", zDate);
190 zOut = sqlite3_mprintf("[%.10s] %s (user: %s, artifact: [%.10s], branch: %s)",
191 zCiUuid, zCom, zUser, zFileUuid, zBr);
 
192 comment_print(zOut, 11, 79);
193 sqlite3_free(zOut);
194 }else{
195 blob_reset(&line);
196 blob_appendf(&line, "%.10s ", zCiUuid);
@@ -203,10 +204,45 @@
203 }
204 db_finalize(&q);
205 blob_reset(&fname);
206 }
207 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
209 /* Values for the debug= query parameter to finfo */
210 #define FINFO_DEBUG_MLINK 0x01
211
212 /*
213
--- src/finfo.c
+++ src/finfo.c
@@ -24,23 +24,23 @@
24 ** COMMAND: finfo
25 **
26 ** Usage: %fossil finfo ?OPTIONS? FILENAME
27 **
28 ** Print the complete change history for a single file going backwards
29 ** in time. The default mode is -l.
30 **
31 ** For the -l|--log mode: If "-b|--brief" is specified one line per revision
32 ** is printed, otherwise the full comment is printed. The "--limit N"
33 ** and "--offset P" options limits the output to the first N changes
34 ** after skipping P changes.
35 **
36 ** In the -s mode prints the status as <status> <revision>. This is
37 ** a quick status and does not check for up-to-date-ness of the file.
38 **
39 ** In the -p mode, there's an optional flag "-r|--revision REVISION".
40 ** The specified version (or the latest checked out version) is printed
41 ** to stdout. The -p mode is another form of the "cat" command.
42 **
43 ** Options:
44 ** --brief|-b display a brief (one line / revision) summary
45 ** --limit N display the first N changes
46 ** --log|-l select log mode (the default)
@@ -50,11 +50,11 @@
50 ** to stdout (only in print mode)
51 ** -s select status mode (print a status indicator for FILE)
52 ** --case-sensitive B Enable or disable case-sensitive filenames. B is a
53 ** boolean: "yes", "no", "true", "false", etc.
54 **
55 ** See also: artifact, cat, descendants, info, leaves
56 */
57 void finfo_cmd(void){
58 capture_case_sensitive_option();
59 db_must_be_within_tree();
60 if (find_option("status","s",0)) {
@@ -185,12 +185,13 @@
185 const char *zBr = db_column_text(&q, 5);
186 char *zOut;
187 if( zBr==0 ) zBr = "trunk";
188 if( iBrief ){
189 fossil_print("%s ", zDate);
190 zOut = sqlite3_mprintf(
191 "[%.10s] %s (user: %s, artifact: [%.10s], branch: %s)",
192 zCiUuid, zCom, zUser, zFileUuid, zBr);
193 comment_print(zOut, 11, 79);
194 sqlite3_free(zOut);
195 }else{
196 blob_reset(&line);
197 blob_appendf(&line, "%.10s ", zCiUuid);
@@ -203,10 +204,45 @@
204 }
205 db_finalize(&q);
206 blob_reset(&fname);
207 }
208 }
209
210 /*
211 ** COMMAND: cat
212 **
213 ** Usage: %fossil cat FILENAME ... ?OPTIONS?
214 **
215 ** Print on standard output the content of one or more files as they exist
216 ** in the repository. The version currently checked out is shown by default.
217 ** Other versions may be specified using the -r option.
218 **
219 ** Options:
220 ** -R|--repository FILE Extract artifacts from repository FILE
221 ** -r VERSION The specific check-in containing the file
222 **
223 ** See also: finfo
224 */
225 void cat_cmd(void){
226 int i;
227 int rc;
228 Blob content, fname;
229 const char *zRev;
230 db_find_and_open_repository(0, 0);
231 zRev = find_option("r","r",1);
232 for(i=2; i<g.argc; i++){
233 file_tree_name(g.argv[i], &fname, 1);
234 blob_zero(&content);
235 rc = historical_version_of_file(zRev, blob_str(&fname), &content, 0,0,0,0);
236 if( rc==0 ){
237 fossil_fatal("no such file: %s", g.argv[i]);
238 }
239 blob_write_to_file(&content, "-");
240 blob_reset(&fname);
241 blob_reset(&content);
242 }
243 }
244
245 /* Values for the debug= query parameter to finfo */
246 #define FINFO_DEBUG_MLINK 0x01
247
248 /*
249

Keyboard Shortcuts

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