Fossil SCM

Added -- support to: (branch new) (uv add/cat/edit/export/rm)

stephan 2019-09-27 11:47 UTC double-dash-flag
Commit 78a30d8d7c3d5e2e2591f9d29938ae64a7673a489fb7e6f3e6e9c4f977e62ef5
3 files changed +10 -1 +11 -5 +28 -16
+10 -1
--- src/branch.c
+++ src/branch.c
@@ -49,10 +49,16 @@
4949
}
5050
5151
/*
5252
** fossil branch new NAME BASIS ?OPTIONS?
5353
** argv0 argv1 argv2 argv3 argv4
54
+**
55
+** Or:
56
+**
57
+** fossil branch new ?OPTIONS? NAME BASIS
58
+**
59
+** with the "--" flag before NAME *or* BASIS.
5460
*/
5561
void branch_new(void){
5662
int rootid; /* RID of the root check-in - what we branch off of */
5763
int brid; /* RID of the branch check-in */
5864
int noSign; /* True if the branch is unsigned */
@@ -73,11 +79,11 @@
7379
noSign = find_option("nosign","",0)!=0;
7480
zColor = find_option("bgcolor","c",1);
7581
isPrivate = find_option("private",0,0)!=0;
7682
zDateOvrd = find_option("date-override",0,1);
7783
zUserOvrd = find_option("user-override",0,1);
78
- verify_all_options();
84
+ verify_all_options2();
7985
if( g.argc<5 ){
8086
usage("new BRANCH-NAME BASIS ?OPTIONS?");
8187
}
8288
db_find_and_open_repository(0, 0);
8389
noSign = db_get_boolean("omitsign", 0)|noSign;
@@ -351,18 +357,21 @@
351357
** -c|--closed List closed branches.
352358
** -r Reverse the sort order
353359
** -t Show recently changed branches first
354360
**
355361
** fossil branch new BRANCH-NAME BASIS ?OPTIONS?
362
+** fossil branch new ?OPTIONS? -- BRANCH-NAME BASIS
356363
**
357364
** Create a new branch BRANCH-NAME off of check-in BASIS.
358365
** Supported options for this subcommand include:
359366
** --private branch is private (i.e., remains local)
360367
** --bgcolor COLOR use COLOR instead of automatic background
361368
** --nosign do not sign contents on this branch
362369
** --date-override DATE DATE to use instead of 'now'
363370
** --user-override USER USER to use instead of the current default
371
+** -- All arguments after this are treated as
372
+** non-flags.
364373
**
365374
** DATE may be "now" or "YYYY-MM-DDTHH:MM:SS.SSS". If in
366375
** year-month-day form, it may be truncated, the "T" may be
367376
** replaced by a space, and it may also name a timezone offset
368377
** from UTC as "-HH:MM" (westward) or "+HH:MM" (eastward).
369378
--- src/branch.c
+++ src/branch.c
@@ -49,10 +49,16 @@
49 }
50
51 /*
52 ** fossil branch new NAME BASIS ?OPTIONS?
53 ** argv0 argv1 argv2 argv3 argv4
 
 
 
 
 
 
54 */
55 void branch_new(void){
56 int rootid; /* RID of the root check-in - what we branch off of */
57 int brid; /* RID of the branch check-in */
58 int noSign; /* True if the branch is unsigned */
@@ -73,11 +79,11 @@
73 noSign = find_option("nosign","",0)!=0;
74 zColor = find_option("bgcolor","c",1);
75 isPrivate = find_option("private",0,0)!=0;
76 zDateOvrd = find_option("date-override",0,1);
77 zUserOvrd = find_option("user-override",0,1);
78 verify_all_options();
79 if( g.argc<5 ){
80 usage("new BRANCH-NAME BASIS ?OPTIONS?");
81 }
82 db_find_and_open_repository(0, 0);
83 noSign = db_get_boolean("omitsign", 0)|noSign;
@@ -351,18 +357,21 @@
351 ** -c|--closed List closed branches.
352 ** -r Reverse the sort order
353 ** -t Show recently changed branches first
354 **
355 ** fossil branch new BRANCH-NAME BASIS ?OPTIONS?
 
356 **
357 ** Create a new branch BRANCH-NAME off of check-in BASIS.
358 ** Supported options for this subcommand include:
359 ** --private branch is private (i.e., remains local)
360 ** --bgcolor COLOR use COLOR instead of automatic background
361 ** --nosign do not sign contents on this branch
362 ** --date-override DATE DATE to use instead of 'now'
363 ** --user-override USER USER to use instead of the current default
 
 
364 **
365 ** DATE may be "now" or "YYYY-MM-DDTHH:MM:SS.SSS". If in
366 ** year-month-day form, it may be truncated, the "T" may be
367 ** replaced by a space, and it may also name a timezone offset
368 ** from UTC as "-HH:MM" (westward) or "+HH:MM" (eastward).
369
--- src/branch.c
+++ src/branch.c
@@ -49,10 +49,16 @@
49 }
50
51 /*
52 ** fossil branch new NAME BASIS ?OPTIONS?
53 ** argv0 argv1 argv2 argv3 argv4
54 **
55 ** Or:
56 **
57 ** fossil branch new ?OPTIONS? NAME BASIS
58 **
59 ** with the "--" flag before NAME *or* BASIS.
60 */
61 void branch_new(void){
62 int rootid; /* RID of the root check-in - what we branch off of */
63 int brid; /* RID of the branch check-in */
64 int noSign; /* True if the branch is unsigned */
@@ -73,11 +79,11 @@
79 noSign = find_option("nosign","",0)!=0;
80 zColor = find_option("bgcolor","c",1);
81 isPrivate = find_option("private",0,0)!=0;
82 zDateOvrd = find_option("date-override",0,1);
83 zUserOvrd = find_option("user-override",0,1);
84 verify_all_options2();
85 if( g.argc<5 ){
86 usage("new BRANCH-NAME BASIS ?OPTIONS?");
87 }
88 db_find_and_open_repository(0, 0);
89 noSign = db_get_boolean("omitsign", 0)|noSign;
@@ -351,18 +357,21 @@
357 ** -c|--closed List closed branches.
358 ** -r Reverse the sort order
359 ** -t Show recently changed branches first
360 **
361 ** fossil branch new BRANCH-NAME BASIS ?OPTIONS?
362 ** fossil branch new ?OPTIONS? -- BRANCH-NAME BASIS
363 **
364 ** Create a new branch BRANCH-NAME off of check-in BASIS.
365 ** Supported options for this subcommand include:
366 ** --private branch is private (i.e., remains local)
367 ** --bgcolor COLOR use COLOR instead of automatic background
368 ** --nosign do not sign contents on this branch
369 ** --date-override DATE DATE to use instead of 'now'
370 ** --user-override USER USER to use instead of the current default
371 ** -- All arguments after this are treated as
372 ** non-flags.
373 **
374 ** DATE may be "now" or "YYYY-MM-DDTHH:MM:SS.SSS". If in
375 ** year-month-day form, it may be truncated, the "T" may be
376 ** replaced by a space, and it may also name a timezone offset
377 ** from UTC as "-HH:MM" (westward) or "+HH:MM" (eastward).
378
+11 -5
--- src/main.c
+++ src/main.c
@@ -1042,27 +1042,32 @@
10421042
** inspected by this function (they are assumed to be
10431043
** file/wiki/branch/etc. names, even if they syntactically look like
10441044
** flags). If fAllowDoubleDash is false then the "--" flag will
10451045
** trigger a fatal error exactly as if an unprocessed flag were
10461046
** encountered.
1047
+**
1048
+** Returns false (0) if fAllowDoubleDash is false or if "--" is not
1049
+** encountered. If fAllowDoubleDash is true and "--" is encountered,
1050
+** the argument index (in g.argv) at which "--" was encountered (and
1051
+** removed) is returned.
10471052
**
10481053
** Sidebar: the question of whether fAllowDoubleDash should be true or
10491054
** false would seem to boil down to: does the calling routine
10501055
** expect/allow arbitrary file/page/branch/whatever name arguments
10511056
** after its required arguments?
10521057
*/
1053
-static void verify_all_options_impl(int fAllowDoubleDash){
1058
+static int verify_all_options_impl(int fAllowDoubleDash){
10541059
int i;
10551060
for(i=1; i<g.argc; i++){
10561061
const char * arg = g.argv[i];
10571062
if( arg[0]=='-' ){
10581063
if( arg[1]=='-' && arg[2]==0 ){
10591064
if(fAllowDoubleDash){
10601065
/* Remove "--" from the list and assume any following
10611066
** arguments are file names. */
10621067
remove_from_argv(i, 1);
1063
- break;
1068
+ return i;
10641069
}else{
10651070
fossil_fatal("The -- flag is not allowed here.");
10661071
}
10671072
}else if( arg[1]!=0 ){
10681073
fossil_fatal(
@@ -1069,10 +1074,11 @@
10691074
"unrecognized command-line option, or missing argument: %s",
10701075
arg);
10711076
}
10721077
}
10731078
}
1079
+ return 0;
10741080
}
10751081
10761082
/*
10771083
** Must be called by all commands which process CLI flags, after
10781084
** consuming those flags (via find_option() and friends), to confirm
@@ -1084,14 +1090,14 @@
10841090
verify_all_options_impl(0);
10851091
}
10861092
10871093
/*
10881094
** Identical to verify_all_options() except that it honors the "--"
1089
-** flag.
1095
+** flag and returns true (non-0) if that flag was encountered/consumed.
10901096
*/
1091
-void verify_all_options2(void){
1092
- verify_all_options_impl(1);
1097
+int verify_all_options2(void){
1098
+ return verify_all_options_impl(1);
10931099
}
10941100
10951101
/*
10961102
** This function returns a human readable version string.
10971103
*/
10981104
--- src/main.c
+++ src/main.c
@@ -1042,27 +1042,32 @@
1042 ** inspected by this function (they are assumed to be
1043 ** file/wiki/branch/etc. names, even if they syntactically look like
1044 ** flags). If fAllowDoubleDash is false then the "--" flag will
1045 ** trigger a fatal error exactly as if an unprocessed flag were
1046 ** encountered.
 
 
 
 
 
1047 **
1048 ** Sidebar: the question of whether fAllowDoubleDash should be true or
1049 ** false would seem to boil down to: does the calling routine
1050 ** expect/allow arbitrary file/page/branch/whatever name arguments
1051 ** after its required arguments?
1052 */
1053 static void verify_all_options_impl(int fAllowDoubleDash){
1054 int i;
1055 for(i=1; i<g.argc; i++){
1056 const char * arg = g.argv[i];
1057 if( arg[0]=='-' ){
1058 if( arg[1]=='-' && arg[2]==0 ){
1059 if(fAllowDoubleDash){
1060 /* Remove "--" from the list and assume any following
1061 ** arguments are file names. */
1062 remove_from_argv(i, 1);
1063 break;
1064 }else{
1065 fossil_fatal("The -- flag is not allowed here.");
1066 }
1067 }else if( arg[1]!=0 ){
1068 fossil_fatal(
@@ -1069,10 +1074,11 @@
1069 "unrecognized command-line option, or missing argument: %s",
1070 arg);
1071 }
1072 }
1073 }
 
1074 }
1075
1076 /*
1077 ** Must be called by all commands which process CLI flags, after
1078 ** consuming those flags (via find_option() and friends), to confirm
@@ -1084,14 +1090,14 @@
1084 verify_all_options_impl(0);
1085 }
1086
1087 /*
1088 ** Identical to verify_all_options() except that it honors the "--"
1089 ** flag.
1090 */
1091 void verify_all_options2(void){
1092 verify_all_options_impl(1);
1093 }
1094
1095 /*
1096 ** This function returns a human readable version string.
1097 */
1098
--- src/main.c
+++ src/main.c
@@ -1042,27 +1042,32 @@
1042 ** inspected by this function (they are assumed to be
1043 ** file/wiki/branch/etc. names, even if they syntactically look like
1044 ** flags). If fAllowDoubleDash is false then the "--" flag will
1045 ** trigger a fatal error exactly as if an unprocessed flag were
1046 ** encountered.
1047 **
1048 ** Returns false (0) if fAllowDoubleDash is false or if "--" is not
1049 ** encountered. If fAllowDoubleDash is true and "--" is encountered,
1050 ** the argument index (in g.argv) at which "--" was encountered (and
1051 ** removed) is returned.
1052 **
1053 ** Sidebar: the question of whether fAllowDoubleDash should be true or
1054 ** false would seem to boil down to: does the calling routine
1055 ** expect/allow arbitrary file/page/branch/whatever name arguments
1056 ** after its required arguments?
1057 */
1058 static int verify_all_options_impl(int fAllowDoubleDash){
1059 int i;
1060 for(i=1; i<g.argc; i++){
1061 const char * arg = g.argv[i];
1062 if( arg[0]=='-' ){
1063 if( arg[1]=='-' && arg[2]==0 ){
1064 if(fAllowDoubleDash){
1065 /* Remove "--" from the list and assume any following
1066 ** arguments are file names. */
1067 remove_from_argv(i, 1);
1068 return i;
1069 }else{
1070 fossil_fatal("The -- flag is not allowed here.");
1071 }
1072 }else if( arg[1]!=0 ){
1073 fossil_fatal(
@@ -1069,10 +1074,11 @@
1074 "unrecognized command-line option, or missing argument: %s",
1075 arg);
1076 }
1077 }
1078 }
1079 return 0;
1080 }
1081
1082 /*
1083 ** Must be called by all commands which process CLI flags, after
1084 ** consuming those flags (via find_option() and friends), to confirm
@@ -1084,14 +1090,14 @@
1090 verify_all_options_impl(0);
1091 }
1092
1093 /*
1094 ** Identical to verify_all_options() except that it honors the "--"
1095 ** flag and returns true (non-0) if that flag was encountered/consumed.
1096 */
1097 int verify_all_options2(void){
1098 return verify_all_options_impl(1);
1099 }
1100
1101 /*
1102 ** This function returns a human readable version string.
1103 */
1104
+28 -16
--- src/unversioned.c
+++ src/unversioned.c
@@ -218,27 +218,30 @@
218218
** of each UV-file is retained. Changes to an UV-file are permanent and cannot
219219
** be undone, so use appropriate caution with this command.
220220
**
221221
** Subcommands:
222222
**
223
-** add FILE ... Add or update one or more unversioned files in
223
+** add [--] FILE ... Add or update one or more unversioned files in
224224
** the local repository so that they match FILEs
225225
** on disk. Changes are not pushed to other
226226
** repositories until the next sync.
227227
**
228
-** add FILE --as UVFILE Add or update a single file named FILE on disk
228
+** add FILE --as UVFILE
229
+** add --as UVFILE -- FILE
230
+** Add or update a single file named FILE on disk
229231
** and UVFILE in the repository unversioned file
230232
** namespace. This variant of the 'add' command allows
231233
** the name to be different in the repository versus
232234
** what appears on disk, but it only allows adding
233235
** a single file at a time.
234236
**
235
-** cat FILE ... Concatenate the content of FILEs to stdout.
237
+** cat [--] FILE ... Concatenate the content of FILEs to stdout.
236238
**
237
-** edit FILE Bring up FILE in a text editor for modification.
239
+** edit [--] FILE Bring up FILE in a text editor for modification.
238240
**
239
-** export FILE OUTPUT Write the content of FILE into OUTPUT on disk
241
+** export [--] FILE OUTPUT
242
+** Write the content of FILE into OUTPUT on disk
240243
**
241244
** list | ls Show all unversioned files held in the local
242245
** repository.
243246
**
244247
** revert ?URL? Restore the state of all unversioned files in the
@@ -247,11 +250,11 @@
247250
**
248251
** Options:
249252
** -v|--verbose Extra diagnostic output
250253
** -n|--dryrun Show what would have happened
251254
**
252
-** remove|rm|delete FILE ...
255
+** remove|rm|delete [--] FILE ...
253256
** Remove unversioned files from the local repository.
254257
** Changes are not pushed to other repositories until
255258
** the next sync.
256259
**
257260
** sync ?URL? Synchronize the state of all unversioned files with
@@ -261,16 +264,19 @@
261264
**
262265
** Options:
263266
** -v|--verbose Extra diagnostic output
264267
** -n|--dryrun Show what would have happened
265268
**
266
-** touch FILE ... Update the TIMESTAMP on all of the listed files
269
+** touch [--] FILE ... Update the TIMESTAMP on all of the listed files
267270
**
268271
** Options:
269272
**
270273
** --mtime TIMESTAMP Use TIMESTAMP instead of "now" for the "add",
271274
** "edit", "remove", and "touch" subcommands.
275
+** -- For commands which support this, it means to treat
276
+** all subsequent arguments as file names even if they
277
+** start with a "-".
272278
*/
273279
void unversioned_cmd(void){
274280
const char *zCmd;
275281
int nCmd;
276282
const char *zMtime = find_option("mtime", 0, 1);
@@ -287,16 +293,17 @@
287293
}
288294
if( memcmp(zCmd, "add", nCmd)==0 ){
289295
const char *zError = 0;
290296
const char *zIn;
291297
const char *zAs;
298
+ const char *zFileArg;
292299
Blob file;
293300
int i;
294
-
301
+ int fDoubleDash; /* True if "--" flag is provided */
295302
zAs = find_option("as",0,1);
303
+ fDoubleDash = verify_all_options2();
296304
if( zAs && g.argc!=4 ) usage("add DISKFILE --as UVFILE");
297
- verify_all_options();
298305
db_begin_transaction();
299306
content_rcvid_init("#!fossil unversioned add");
300307
for(i=3; i<g.argc; i++){
301308
zIn = zAs ? zAs : g.argv[i];
302309
if( zIn[0]==0 ){
@@ -310,18 +317,23 @@
310317
}
311318
if( zError ){
312319
fossil_fatal("unversioned filenames may not %s: %Q", zError, zIn);
313320
}
314321
blob_init(&file,0,0);
315
- blob_read_from_file(&file, g.argv[i], ExtFILE);
322
+ zFileArg = g.argv[i];
323
+ if(fDoubleDash>0 && fDoubleDash<=i
324
+ && fossil_strcmp("-",zFileArg)==0){
325
+ zFileArg = "./-" /* do not treat "-" as stdin! */;
326
+ }
327
+ blob_read_from_file(&file, zFileArg, ExtFILE);
316328
unversioned_write(zIn, &file, mtime);
317329
blob_reset(&file);
318330
}
319331
db_end_transaction(0);
320332
}else if( memcmp(zCmd, "cat", nCmd)==0 ){
321333
int i;
322
- verify_all_options();
334
+ verify_all_options2();
323335
db_begin_transaction();
324336
for(i=3; i<g.argc; i++){
325337
Blob content;
326338
if( unversioned_content(g.argv[i], &content)==0 ){
327339
blob_write_to_file(&content, "-");
@@ -334,12 +346,12 @@
334346
const char *zTFile; /* Temporary file */
335347
const char *zUVFile; /* Name of the unversioned file */
336348
char *zCmd; /* Command to run the text editor */
337349
Blob content; /* Content of the unversioned file */
338350
339
- verify_all_options();
340
- if( g.argc!=4) usage("edit UVFILE");
351
+ verify_all_options2();
352
+ if( g.argc!=4) usage("edit [--] UVFILE");
341353
zUVFile = g.argv[3];
342354
zEditor = fossil_text_editor();
343355
if( zEditor==0 ) fossil_fatal("no text editor - set the VISUAL env variable");
344356
zTFile = fossil_temp_filename();
345357
if( zTFile==0 ) fossil_fatal("cannot find a temporary filename");
@@ -370,11 +382,11 @@
370382
unversioned_write(zUVFile, &content, mtime);
371383
db_end_transaction(0);
372384
blob_reset(&content);
373385
}else if( memcmp(zCmd, "export", nCmd)==0 ){
374386
Blob content;
375
- verify_all_options();
387
+ verify_all_options2();
376388
if( g.argc!=5 ) usage("export UVFILE OUTPUT");
377389
if( unversioned_content(g.argv[3], &content) ){
378390
fossil_fatal("no such uv-file: %Q", g.argv[3]);
379391
}
380392
blob_write_to_file(&content, g.argv[4]);
@@ -430,11 +442,11 @@
430442
g.argv[2] = "--uv-noop";
431443
sync_unversioned(syncFlags);
432444
}else if( memcmp(zCmd, "remove", nCmd)==0 || memcmp(zCmd, "rm", nCmd)==0
433445
|| memcmp(zCmd, "delete", nCmd)==0 ){
434446
int i;
435
- verify_all_options();
447
+ verify_all_options2();
436448
db_begin_transaction();
437449
for(i=3; i<g.argc; i++){
438450
db_multi_exec(
439451
"UPDATE unversioned"
440452
" SET hash=NULL, content=NULL, mtime=%lld, sz=0 WHERE name=%Q",
@@ -448,11 +460,11 @@
448460
g.argv[1] = "sync";
449461
g.argv[2] = "--uv-noop";
450462
sync_unversioned(syncFlags);
451463
}else if( memcmp(zCmd, "touch", nCmd)==0 ){
452464
int i;
453
- verify_all_options();
465
+ verify_all_options2();
454466
db_begin_transaction();
455467
for(i=3; i<g.argc; i++){
456468
db_multi_exec(
457469
"UPDATE unversioned SET mtime=%lld WHERE name=%Q",
458470
mtime, g.argv[i]
459471
--- src/unversioned.c
+++ src/unversioned.c
@@ -218,27 +218,30 @@
218 ** of each UV-file is retained. Changes to an UV-file are permanent and cannot
219 ** be undone, so use appropriate caution with this command.
220 **
221 ** Subcommands:
222 **
223 ** add FILE ... Add or update one or more unversioned files in
224 ** the local repository so that they match FILEs
225 ** on disk. Changes are not pushed to other
226 ** repositories until the next sync.
227 **
228 ** add FILE --as UVFILE Add or update a single file named FILE on disk
 
 
229 ** and UVFILE in the repository unversioned file
230 ** namespace. This variant of the 'add' command allows
231 ** the name to be different in the repository versus
232 ** what appears on disk, but it only allows adding
233 ** a single file at a time.
234 **
235 ** cat FILE ... Concatenate the content of FILEs to stdout.
236 **
237 ** edit FILE Bring up FILE in a text editor for modification.
238 **
239 ** export FILE OUTPUT Write the content of FILE into OUTPUT on disk
 
240 **
241 ** list | ls Show all unversioned files held in the local
242 ** repository.
243 **
244 ** revert ?URL? Restore the state of all unversioned files in the
@@ -247,11 +250,11 @@
247 **
248 ** Options:
249 ** -v|--verbose Extra diagnostic output
250 ** -n|--dryrun Show what would have happened
251 **
252 ** remove|rm|delete FILE ...
253 ** Remove unversioned files from the local repository.
254 ** Changes are not pushed to other repositories until
255 ** the next sync.
256 **
257 ** sync ?URL? Synchronize the state of all unversioned files with
@@ -261,16 +264,19 @@
261 **
262 ** Options:
263 ** -v|--verbose Extra diagnostic output
264 ** -n|--dryrun Show what would have happened
265 **
266 ** touch FILE ... Update the TIMESTAMP on all of the listed files
267 **
268 ** Options:
269 **
270 ** --mtime TIMESTAMP Use TIMESTAMP instead of "now" for the "add",
271 ** "edit", "remove", and "touch" subcommands.
 
 
 
272 */
273 void unversioned_cmd(void){
274 const char *zCmd;
275 int nCmd;
276 const char *zMtime = find_option("mtime", 0, 1);
@@ -287,16 +293,17 @@
287 }
288 if( memcmp(zCmd, "add", nCmd)==0 ){
289 const char *zError = 0;
290 const char *zIn;
291 const char *zAs;
 
292 Blob file;
293 int i;
294
295 zAs = find_option("as",0,1);
 
296 if( zAs && g.argc!=4 ) usage("add DISKFILE --as UVFILE");
297 verify_all_options();
298 db_begin_transaction();
299 content_rcvid_init("#!fossil unversioned add");
300 for(i=3; i<g.argc; i++){
301 zIn = zAs ? zAs : g.argv[i];
302 if( zIn[0]==0 ){
@@ -310,18 +317,23 @@
310 }
311 if( zError ){
312 fossil_fatal("unversioned filenames may not %s: %Q", zError, zIn);
313 }
314 blob_init(&file,0,0);
315 blob_read_from_file(&file, g.argv[i], ExtFILE);
 
 
 
 
 
316 unversioned_write(zIn, &file, mtime);
317 blob_reset(&file);
318 }
319 db_end_transaction(0);
320 }else if( memcmp(zCmd, "cat", nCmd)==0 ){
321 int i;
322 verify_all_options();
323 db_begin_transaction();
324 for(i=3; i<g.argc; i++){
325 Blob content;
326 if( unversioned_content(g.argv[i], &content)==0 ){
327 blob_write_to_file(&content, "-");
@@ -334,12 +346,12 @@
334 const char *zTFile; /* Temporary file */
335 const char *zUVFile; /* Name of the unversioned file */
336 char *zCmd; /* Command to run the text editor */
337 Blob content; /* Content of the unversioned file */
338
339 verify_all_options();
340 if( g.argc!=4) usage("edit UVFILE");
341 zUVFile = g.argv[3];
342 zEditor = fossil_text_editor();
343 if( zEditor==0 ) fossil_fatal("no text editor - set the VISUAL env variable");
344 zTFile = fossil_temp_filename();
345 if( zTFile==0 ) fossil_fatal("cannot find a temporary filename");
@@ -370,11 +382,11 @@
370 unversioned_write(zUVFile, &content, mtime);
371 db_end_transaction(0);
372 blob_reset(&content);
373 }else if( memcmp(zCmd, "export", nCmd)==0 ){
374 Blob content;
375 verify_all_options();
376 if( g.argc!=5 ) usage("export UVFILE OUTPUT");
377 if( unversioned_content(g.argv[3], &content) ){
378 fossil_fatal("no such uv-file: %Q", g.argv[3]);
379 }
380 blob_write_to_file(&content, g.argv[4]);
@@ -430,11 +442,11 @@
430 g.argv[2] = "--uv-noop";
431 sync_unversioned(syncFlags);
432 }else if( memcmp(zCmd, "remove", nCmd)==0 || memcmp(zCmd, "rm", nCmd)==0
433 || memcmp(zCmd, "delete", nCmd)==0 ){
434 int i;
435 verify_all_options();
436 db_begin_transaction();
437 for(i=3; i<g.argc; i++){
438 db_multi_exec(
439 "UPDATE unversioned"
440 " SET hash=NULL, content=NULL, mtime=%lld, sz=0 WHERE name=%Q",
@@ -448,11 +460,11 @@
448 g.argv[1] = "sync";
449 g.argv[2] = "--uv-noop";
450 sync_unversioned(syncFlags);
451 }else if( memcmp(zCmd, "touch", nCmd)==0 ){
452 int i;
453 verify_all_options();
454 db_begin_transaction();
455 for(i=3; i<g.argc; i++){
456 db_multi_exec(
457 "UPDATE unversioned SET mtime=%lld WHERE name=%Q",
458 mtime, g.argv[i]
459
--- src/unversioned.c
+++ src/unversioned.c
@@ -218,27 +218,30 @@
218 ** of each UV-file is retained. Changes to an UV-file are permanent and cannot
219 ** be undone, so use appropriate caution with this command.
220 **
221 ** Subcommands:
222 **
223 ** add [--] FILE ... Add or update one or more unversioned files in
224 ** the local repository so that they match FILEs
225 ** on disk. Changes are not pushed to other
226 ** repositories until the next sync.
227 **
228 ** add FILE --as UVFILE
229 ** add --as UVFILE -- FILE
230 ** Add or update a single file named FILE on disk
231 ** and UVFILE in the repository unversioned file
232 ** namespace. This variant of the 'add' command allows
233 ** the name to be different in the repository versus
234 ** what appears on disk, but it only allows adding
235 ** a single file at a time.
236 **
237 ** cat [--] FILE ... Concatenate the content of FILEs to stdout.
238 **
239 ** edit [--] FILE Bring up FILE in a text editor for modification.
240 **
241 ** export [--] FILE OUTPUT
242 ** Write the content of FILE into OUTPUT on disk
243 **
244 ** list | ls Show all unversioned files held in the local
245 ** repository.
246 **
247 ** revert ?URL? Restore the state of all unversioned files in the
@@ -247,11 +250,11 @@
250 **
251 ** Options:
252 ** -v|--verbose Extra diagnostic output
253 ** -n|--dryrun Show what would have happened
254 **
255 ** remove|rm|delete [--] FILE ...
256 ** Remove unversioned files from the local repository.
257 ** Changes are not pushed to other repositories until
258 ** the next sync.
259 **
260 ** sync ?URL? Synchronize the state of all unversioned files with
@@ -261,16 +264,19 @@
264 **
265 ** Options:
266 ** -v|--verbose Extra diagnostic output
267 ** -n|--dryrun Show what would have happened
268 **
269 ** touch [--] FILE ... Update the TIMESTAMP on all of the listed files
270 **
271 ** Options:
272 **
273 ** --mtime TIMESTAMP Use TIMESTAMP instead of "now" for the "add",
274 ** "edit", "remove", and "touch" subcommands.
275 ** -- For commands which support this, it means to treat
276 ** all subsequent arguments as file names even if they
277 ** start with a "-".
278 */
279 void unversioned_cmd(void){
280 const char *zCmd;
281 int nCmd;
282 const char *zMtime = find_option("mtime", 0, 1);
@@ -287,16 +293,17 @@
293 }
294 if( memcmp(zCmd, "add", nCmd)==0 ){
295 const char *zError = 0;
296 const char *zIn;
297 const char *zAs;
298 const char *zFileArg;
299 Blob file;
300 int i;
301 int fDoubleDash; /* True if "--" flag is provided */
302 zAs = find_option("as",0,1);
303 fDoubleDash = verify_all_options2();
304 if( zAs && g.argc!=4 ) usage("add DISKFILE --as UVFILE");
 
305 db_begin_transaction();
306 content_rcvid_init("#!fossil unversioned add");
307 for(i=3; i<g.argc; i++){
308 zIn = zAs ? zAs : g.argv[i];
309 if( zIn[0]==0 ){
@@ -310,18 +317,23 @@
317 }
318 if( zError ){
319 fossil_fatal("unversioned filenames may not %s: %Q", zError, zIn);
320 }
321 blob_init(&file,0,0);
322 zFileArg = g.argv[i];
323 if(fDoubleDash>0 && fDoubleDash<=i
324 && fossil_strcmp("-",zFileArg)==0){
325 zFileArg = "./-" /* do not treat "-" as stdin! */;
326 }
327 blob_read_from_file(&file, zFileArg, ExtFILE);
328 unversioned_write(zIn, &file, mtime);
329 blob_reset(&file);
330 }
331 db_end_transaction(0);
332 }else if( memcmp(zCmd, "cat", nCmd)==0 ){
333 int i;
334 verify_all_options2();
335 db_begin_transaction();
336 for(i=3; i<g.argc; i++){
337 Blob content;
338 if( unversioned_content(g.argv[i], &content)==0 ){
339 blob_write_to_file(&content, "-");
@@ -334,12 +346,12 @@
346 const char *zTFile; /* Temporary file */
347 const char *zUVFile; /* Name of the unversioned file */
348 char *zCmd; /* Command to run the text editor */
349 Blob content; /* Content of the unversioned file */
350
351 verify_all_options2();
352 if( g.argc!=4) usage("edit [--] UVFILE");
353 zUVFile = g.argv[3];
354 zEditor = fossil_text_editor();
355 if( zEditor==0 ) fossil_fatal("no text editor - set the VISUAL env variable");
356 zTFile = fossil_temp_filename();
357 if( zTFile==0 ) fossil_fatal("cannot find a temporary filename");
@@ -370,11 +382,11 @@
382 unversioned_write(zUVFile, &content, mtime);
383 db_end_transaction(0);
384 blob_reset(&content);
385 }else if( memcmp(zCmd, "export", nCmd)==0 ){
386 Blob content;
387 verify_all_options2();
388 if( g.argc!=5 ) usage("export UVFILE OUTPUT");
389 if( unversioned_content(g.argv[3], &content) ){
390 fossil_fatal("no such uv-file: %Q", g.argv[3]);
391 }
392 blob_write_to_file(&content, g.argv[4]);
@@ -430,11 +442,11 @@
442 g.argv[2] = "--uv-noop";
443 sync_unversioned(syncFlags);
444 }else if( memcmp(zCmd, "remove", nCmd)==0 || memcmp(zCmd, "rm", nCmd)==0
445 || memcmp(zCmd, "delete", nCmd)==0 ){
446 int i;
447 verify_all_options2();
448 db_begin_transaction();
449 for(i=3; i<g.argc; i++){
450 db_multi_exec(
451 "UPDATE unversioned"
452 " SET hash=NULL, content=NULL, mtime=%lld, sz=0 WHERE name=%Q",
@@ -448,11 +460,11 @@
460 g.argv[1] = "sync";
461 g.argv[2] = "--uv-noop";
462 sync_unversioned(syncFlags);
463 }else if( memcmp(zCmd, "touch", nCmd)==0 ){
464 int i;
465 verify_all_options2();
466 db_begin_transaction();
467 for(i=3; i<g.argc; i++){
468 db_multi_exec(
469 "UPDATE unversioned SET mtime=%lld WHERE name=%Q",
470 mtime, g.argv[i]
471

Keyboard Shortcuts

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