Fossil SCM

Add the --verbose and --dryrun options to the "fossil unversioned revert" and "fossil unversioned sync" commands.

drh 2016-09-20 15:48 trunk
Commit b5641c5cffeef36f4bcaf8f93c90c50e5d7b5647
2 files changed +29 -7 +19 -1
--- src/unversioned.c
+++ src/unversioned.c
@@ -142,19 +142,20 @@
142142
db_unset("uv-hash", 0);
143143
}
144144
145145
146146
/*
147
-** Check the status of unversioned file zName. Return an integer status
148
-** code as follows:
147
+** Check the status of unversioned file zName. "mtime" and "zHash" are the
148
+** time of last change and SHA1 hash of a copy of this file on a remote
149
+** server. Return an integer status code as follows:
149150
**
150151
** 0: zName does not exist in the unversioned table.
151
-** 1: zName exists and should be replaced by mtime/zHash.
152
+** 1: zName exists and should be replaced by the mtime/zHash remote.
152153
** 2: zName exists and is the same as zHash but has a older mtime
153154
** 3: zName exists and is identical to mtime/zHash in all respects.
154155
** 4: zName exists and is the same as zHash but has a newer mtime.
155
-** 5: zName exists and should override mtime/zHash.
156
+** 5: zName exists and should override the mtime/zHash remote.
156157
*/
157158
int unversioned_status(const char *zName, sqlite3_int64 mtime, const char *zHash){
158159
int iStatus = 0;
159160
Stmt q;
160161
db_prepare(&q, "SELECT mtime, hash FROM unversioned WHERE name=%Q", zName);
@@ -174,10 +175,23 @@
174175
}
175176
}
176177
db_finalize(&q);
177178
return iStatus;
178179
}
180
+
181
+/*
182
+** Extract command-line options for the "revert" and "sync" subcommands
183
+*/
184
+static int unversioned_sync_flags(unsigned syncFlags){
185
+ if( find_option("verbose","v",0)!=0 ){
186
+ syncFlags |= SYNC_UV_TRACE | SYNC_VERBOSE;
187
+ }
188
+ if( find_option("dryrun","n",0)!=0 ){
189
+ syncFlags |= SYNC_UV_DRYRUN | SYNC_UV_TRACE | SYNC_VERBOSE;
190
+ }
191
+ return syncFlags;
192
+}
179193
180194
/*
181195
** COMMAND: unversioned
182196
**
183197
** Usage: %fossil unversioned SUBCOMMAND ARGS...
@@ -204,19 +218,25 @@
204218
**
205219
** list | ls Show all unversioned files held in the local repository.
206220
**
207221
** revert ?URL? Restore the state of all unversioned files in the local
208222
** repository to match the remote repository URL.
223
+** Options:
224
+** -v|--verbose Extra diagnostic output
225
+** -n|--dryrun Show what would have happened
209226
**
210227
** rm FILE ... Remove an unversioned files from the local repository.
211228
** Changes are not pushed to other repositories until
212
-** the next sync.
229
+** the next sync.
213230
**
214231
** sync ?URL? Synchronize the state of all unversioned files with
215232
** the remote repository URL. The most recent version of
216233
** each file is propagate to all repositories and all
217234
** prior versions are permanently forgotten.
235
+** Options:
236
+** -v|--verbose Extra diagnostic output
237
+** -n|--dryrun Show what would have happened
218238
**
219239
** touch FILE ... Update the TIMESTAMP on all of the listed files
220240
**
221241
** Options:
222242
**
@@ -365,13 +385,14 @@
365385
);
366386
}
367387
}
368388
db_finalize(&q);
369389
}else if( memcmp(zCmd, "revert", nCmd)==0 ){
390
+ unsigned syncFlags = unversioned_sync_flags(SYNC_UNVERSIONED|SYNC_UV_REVERT);
370391
g.argv[1] = "sync";
371392
g.argv[2] = "--uv-noop";
372
- sync_unversioned(SYNC_UNVERSIONED|SYNC_UV_REVERT);
393
+ sync_unversioned(syncFlags);
373394
}else if( memcmp(zCmd, "rm", nCmd)==0 ){
374395
int i;
375396
verify_all_options();
376397
db_begin_transaction();
377398
for(i=3; i<g.argc; i++){
@@ -382,13 +403,14 @@
382403
);
383404
}
384405
db_unset("uv-hash", 0);
385406
db_end_transaction(0);
386407
}else if( memcmp(zCmd,"sync",nCmd)==0 ){
408
+ unsigned syncFlags = unversioned_sync_flags(SYNC_UNVERSIONED);
387409
g.argv[1] = "sync";
388410
g.argv[2] = "--uv-noop";
389
- sync_unversioned(SYNC_UNVERSIONED);
411
+ sync_unversioned(syncFlags);
390412
}else if( memcmp(zCmd, "touch", nCmd)==0 ){
391413
int i;
392414
verify_all_options();
393415
db_begin_transaction();
394416
for(i=3; i<g.argc; i++){
395417
--- src/unversioned.c
+++ src/unversioned.c
@@ -142,19 +142,20 @@
142 db_unset("uv-hash", 0);
143 }
144
145
146 /*
147 ** Check the status of unversioned file zName. Return an integer status
148 ** code as follows:
 
149 **
150 ** 0: zName does not exist in the unversioned table.
151 ** 1: zName exists and should be replaced by mtime/zHash.
152 ** 2: zName exists and is the same as zHash but has a older mtime
153 ** 3: zName exists and is identical to mtime/zHash in all respects.
154 ** 4: zName exists and is the same as zHash but has a newer mtime.
155 ** 5: zName exists and should override mtime/zHash.
156 */
157 int unversioned_status(const char *zName, sqlite3_int64 mtime, const char *zHash){
158 int iStatus = 0;
159 Stmt q;
160 db_prepare(&q, "SELECT mtime, hash FROM unversioned WHERE name=%Q", zName);
@@ -174,10 +175,23 @@
174 }
175 }
176 db_finalize(&q);
177 return iStatus;
178 }
 
 
 
 
 
 
 
 
 
 
 
 
 
179
180 /*
181 ** COMMAND: unversioned
182 **
183 ** Usage: %fossil unversioned SUBCOMMAND ARGS...
@@ -204,19 +218,25 @@
204 **
205 ** list | ls Show all unversioned files held in the local repository.
206 **
207 ** revert ?URL? Restore the state of all unversioned files in the local
208 ** repository to match the remote repository URL.
 
 
 
209 **
210 ** rm FILE ... Remove an unversioned files from the local repository.
211 ** Changes are not pushed to other repositories until
212 ** the next sync.
213 **
214 ** sync ?URL? Synchronize the state of all unversioned files with
215 ** the remote repository URL. The most recent version of
216 ** each file is propagate to all repositories and all
217 ** prior versions are permanently forgotten.
 
 
 
218 **
219 ** touch FILE ... Update the TIMESTAMP on all of the listed files
220 **
221 ** Options:
222 **
@@ -365,13 +385,14 @@
365 );
366 }
367 }
368 db_finalize(&q);
369 }else if( memcmp(zCmd, "revert", nCmd)==0 ){
 
370 g.argv[1] = "sync";
371 g.argv[2] = "--uv-noop";
372 sync_unversioned(SYNC_UNVERSIONED|SYNC_UV_REVERT);
373 }else if( memcmp(zCmd, "rm", nCmd)==0 ){
374 int i;
375 verify_all_options();
376 db_begin_transaction();
377 for(i=3; i<g.argc; i++){
@@ -382,13 +403,14 @@
382 );
383 }
384 db_unset("uv-hash", 0);
385 db_end_transaction(0);
386 }else if( memcmp(zCmd,"sync",nCmd)==0 ){
 
387 g.argv[1] = "sync";
388 g.argv[2] = "--uv-noop";
389 sync_unversioned(SYNC_UNVERSIONED);
390 }else if( memcmp(zCmd, "touch", nCmd)==0 ){
391 int i;
392 verify_all_options();
393 db_begin_transaction();
394 for(i=3; i<g.argc; i++){
395
--- src/unversioned.c
+++ src/unversioned.c
@@ -142,19 +142,20 @@
142 db_unset("uv-hash", 0);
143 }
144
145
146 /*
147 ** Check the status of unversioned file zName. "mtime" and "zHash" are the
148 ** time of last change and SHA1 hash of a copy of this file on a remote
149 ** server. Return an integer status code as follows:
150 **
151 ** 0: zName does not exist in the unversioned table.
152 ** 1: zName exists and should be replaced by the mtime/zHash remote.
153 ** 2: zName exists and is the same as zHash but has a older mtime
154 ** 3: zName exists and is identical to mtime/zHash in all respects.
155 ** 4: zName exists and is the same as zHash but has a newer mtime.
156 ** 5: zName exists and should override the mtime/zHash remote.
157 */
158 int unversioned_status(const char *zName, sqlite3_int64 mtime, const char *zHash){
159 int iStatus = 0;
160 Stmt q;
161 db_prepare(&q, "SELECT mtime, hash FROM unversioned WHERE name=%Q", zName);
@@ -174,10 +175,23 @@
175 }
176 }
177 db_finalize(&q);
178 return iStatus;
179 }
180
181 /*
182 ** Extract command-line options for the "revert" and "sync" subcommands
183 */
184 static int unversioned_sync_flags(unsigned syncFlags){
185 if( find_option("verbose","v",0)!=0 ){
186 syncFlags |= SYNC_UV_TRACE | SYNC_VERBOSE;
187 }
188 if( find_option("dryrun","n",0)!=0 ){
189 syncFlags |= SYNC_UV_DRYRUN | SYNC_UV_TRACE | SYNC_VERBOSE;
190 }
191 return syncFlags;
192 }
193
194 /*
195 ** COMMAND: unversioned
196 **
197 ** Usage: %fossil unversioned SUBCOMMAND ARGS...
@@ -204,19 +218,25 @@
218 **
219 ** list | ls Show all unversioned files held in the local repository.
220 **
221 ** revert ?URL? Restore the state of all unversioned files in the local
222 ** repository to match the remote repository URL.
223 ** Options:
224 ** -v|--verbose Extra diagnostic output
225 ** -n|--dryrun Show what would have happened
226 **
227 ** rm FILE ... Remove an unversioned files from the local repository.
228 ** Changes are not pushed to other repositories until
229 ** the next sync.
230 **
231 ** sync ?URL? Synchronize the state of all unversioned files with
232 ** the remote repository URL. The most recent version of
233 ** each file is propagate to all repositories and all
234 ** prior versions are permanently forgotten.
235 ** Options:
236 ** -v|--verbose Extra diagnostic output
237 ** -n|--dryrun Show what would have happened
238 **
239 ** touch FILE ... Update the TIMESTAMP on all of the listed files
240 **
241 ** Options:
242 **
@@ -365,13 +385,14 @@
385 );
386 }
387 }
388 db_finalize(&q);
389 }else if( memcmp(zCmd, "revert", nCmd)==0 ){
390 unsigned syncFlags = unversioned_sync_flags(SYNC_UNVERSIONED|SYNC_UV_REVERT);
391 g.argv[1] = "sync";
392 g.argv[2] = "--uv-noop";
393 sync_unversioned(syncFlags);
394 }else if( memcmp(zCmd, "rm", nCmd)==0 ){
395 int i;
396 verify_all_options();
397 db_begin_transaction();
398 for(i=3; i<g.argc; i++){
@@ -382,13 +403,14 @@
403 );
404 }
405 db_unset("uv-hash", 0);
406 db_end_transaction(0);
407 }else if( memcmp(zCmd,"sync",nCmd)==0 ){
408 unsigned syncFlags = unversioned_sync_flags(SYNC_UNVERSIONED);
409 g.argv[1] = "sync";
410 g.argv[2] = "--uv-noop";
411 sync_unversioned(syncFlags);
412 }else if( memcmp(zCmd, "touch", nCmd)==0 ){
413 int i;
414 verify_all_options();
415 db_begin_transaction();
416 for(i=3; i<g.argc; i++){
417
+19 -1
--- src/xfer.c
+++ src/xfer.c
@@ -1656,10 +1656,12 @@
16561656
#define SYNC_VERBOSE 0x0010 /* Extra diagnostics */
16571657
#define SYNC_RESYNC 0x0020 /* --verily */
16581658
#define SYNC_UNVERSIONED 0x0040 /* Sync unversioned content */
16591659
#define SYNC_UV_REVERT 0x0080 /* Copy server unversioned to client */
16601660
#define SYNC_FROMPARENT 0x0100 /* Pull from the parent project */
1661
+#define SYNC_UV_TRACE 0x0200 /* Describe UV activities */
1662
+#define SYNC_UV_DRYRUN 0x0400 /* Do not actually exchange files */
16611663
#endif
16621664
16631665
/*
16641666
** Floating-point absolute value
16651667
*/
@@ -1896,11 +1898,13 @@
18961898
** need to be sent until after the uvigot cards from the first exchange
18971899
** have been processed.
18981900
*/
18991901
if( uvDoPush ){
19001902
assert( (syncFlags & SYNC_UNVERSIONED)!=0 );
1901
- if( syncFlags & SYNC_UV_REVERT ){
1903
+ if( syncFlags & SYNC_UV_DRYRUN ){
1904
+ uvDoPush = 0;
1905
+ }else if( syncFlags & SYNC_UV_REVERT ){
19021906
db_multi_exec(
19031907
"DELETE FROM unversioned"
19041908
" WHERE name IN (SELECT name FROM uv_tosend);"
19051909
"DELETE FROM uv_tosend;"
19061910
);
@@ -2122,10 +2126,24 @@
21222126
int iStatus;
21232127
iStatus = unversioned_status(zName, mtime, zHash);
21242128
if( (syncFlags & SYNC_UV_REVERT)!=0 ){
21252129
if( iStatus==4 ) iStatus = 2;
21262130
if( iStatus==5 ) iStatus = 1;
2131
+ }
2132
+ if( syncFlags & (SYNC_UV_TRACE|SYNC_UV_DRYRUN) ){
2133
+ const char *zMsg = 0;
2134
+ switch( iStatus ){
2135
+ case 0:
2136
+ case 1: zMsg = "UV-PULL"; break;
2137
+ case 2: zMsg = "UV-PULL-MTIME-ONLY"; break;
2138
+ case 4: zMsg = "UV-PUSH-MTIME-ONLY"; break;
2139
+ case 5: zMsg = "UV-PUSH"; break;
2140
+ }
2141
+ if( zMsg ) fossil_print("\r%s: %s\n", zMsg, zName);
2142
+ if( syncFlags & SYNC_UV_DRYRUN ){
2143
+ iStatus = 99; /* Prevent any changes or reply messages */
2144
+ }
21272145
}
21282146
if( iStatus<=1 ){
21292147
if( zHash[0]!='-' ){
21302148
blob_appendf(xfer.pOut, "uvgimme %s\n", zName);
21312149
nCardSent++;
21322150
--- src/xfer.c
+++ src/xfer.c
@@ -1656,10 +1656,12 @@
1656 #define SYNC_VERBOSE 0x0010 /* Extra diagnostics */
1657 #define SYNC_RESYNC 0x0020 /* --verily */
1658 #define SYNC_UNVERSIONED 0x0040 /* Sync unversioned content */
1659 #define SYNC_UV_REVERT 0x0080 /* Copy server unversioned to client */
1660 #define SYNC_FROMPARENT 0x0100 /* Pull from the parent project */
 
 
1661 #endif
1662
1663 /*
1664 ** Floating-point absolute value
1665 */
@@ -1896,11 +1898,13 @@
1896 ** need to be sent until after the uvigot cards from the first exchange
1897 ** have been processed.
1898 */
1899 if( uvDoPush ){
1900 assert( (syncFlags & SYNC_UNVERSIONED)!=0 );
1901 if( syncFlags & SYNC_UV_REVERT ){
 
 
1902 db_multi_exec(
1903 "DELETE FROM unversioned"
1904 " WHERE name IN (SELECT name FROM uv_tosend);"
1905 "DELETE FROM uv_tosend;"
1906 );
@@ -2122,10 +2126,24 @@
2122 int iStatus;
2123 iStatus = unversioned_status(zName, mtime, zHash);
2124 if( (syncFlags & SYNC_UV_REVERT)!=0 ){
2125 if( iStatus==4 ) iStatus = 2;
2126 if( iStatus==5 ) iStatus = 1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2127 }
2128 if( iStatus<=1 ){
2129 if( zHash[0]!='-' ){
2130 blob_appendf(xfer.pOut, "uvgimme %s\n", zName);
2131 nCardSent++;
2132
--- src/xfer.c
+++ src/xfer.c
@@ -1656,10 +1656,12 @@
1656 #define SYNC_VERBOSE 0x0010 /* Extra diagnostics */
1657 #define SYNC_RESYNC 0x0020 /* --verily */
1658 #define SYNC_UNVERSIONED 0x0040 /* Sync unversioned content */
1659 #define SYNC_UV_REVERT 0x0080 /* Copy server unversioned to client */
1660 #define SYNC_FROMPARENT 0x0100 /* Pull from the parent project */
1661 #define SYNC_UV_TRACE 0x0200 /* Describe UV activities */
1662 #define SYNC_UV_DRYRUN 0x0400 /* Do not actually exchange files */
1663 #endif
1664
1665 /*
1666 ** Floating-point absolute value
1667 */
@@ -1896,11 +1898,13 @@
1898 ** need to be sent until after the uvigot cards from the first exchange
1899 ** have been processed.
1900 */
1901 if( uvDoPush ){
1902 assert( (syncFlags & SYNC_UNVERSIONED)!=0 );
1903 if( syncFlags & SYNC_UV_DRYRUN ){
1904 uvDoPush = 0;
1905 }else if( syncFlags & SYNC_UV_REVERT ){
1906 db_multi_exec(
1907 "DELETE FROM unversioned"
1908 " WHERE name IN (SELECT name FROM uv_tosend);"
1909 "DELETE FROM uv_tosend;"
1910 );
@@ -2122,10 +2126,24 @@
2126 int iStatus;
2127 iStatus = unversioned_status(zName, mtime, zHash);
2128 if( (syncFlags & SYNC_UV_REVERT)!=0 ){
2129 if( iStatus==4 ) iStatus = 2;
2130 if( iStatus==5 ) iStatus = 1;
2131 }
2132 if( syncFlags & (SYNC_UV_TRACE|SYNC_UV_DRYRUN) ){
2133 const char *zMsg = 0;
2134 switch( iStatus ){
2135 case 0:
2136 case 1: zMsg = "UV-PULL"; break;
2137 case 2: zMsg = "UV-PULL-MTIME-ONLY"; break;
2138 case 4: zMsg = "UV-PUSH-MTIME-ONLY"; break;
2139 case 5: zMsg = "UV-PUSH"; break;
2140 }
2141 if( zMsg ) fossil_print("\r%s: %s\n", zMsg, zName);
2142 if( syncFlags & SYNC_UV_DRYRUN ){
2143 iStatus = 99; /* Prevent any changes or reply messages */
2144 }
2145 }
2146 if( iStatus<=1 ){
2147 if( zHash[0]!='-' ){
2148 blob_appendf(xfer.pOut, "uvgimme %s\n", zName);
2149 nCardSent++;
2150

Keyboard Shortcuts

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