Fossil SCM
Add the --verbose and --dryrun options to the "fossil unversioned revert" and "fossil unversioned sync" commands.
Commit
b5641c5cffeef36f4bcaf8f93c90c50e5d7b5647
Parent
122ab3fbfdb12ee…
2 files changed
+29
-7
+19
-1
+29
-7
| --- src/unversioned.c | ||
| +++ src/unversioned.c | ||
| @@ -142,19 +142,20 @@ | ||
| 142 | 142 | db_unset("uv-hash", 0); |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | |
| 146 | 146 | /* |
| 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: | |
| 149 | 150 | ** |
| 150 | 151 | ** 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. | |
| 152 | 153 | ** 2: zName exists and is the same as zHash but has a older mtime |
| 153 | 154 | ** 3: zName exists and is identical to mtime/zHash in all respects. |
| 154 | 155 | ** 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. | |
| 156 | 157 | */ |
| 157 | 158 | int unversioned_status(const char *zName, sqlite3_int64 mtime, const char *zHash){ |
| 158 | 159 | int iStatus = 0; |
| 159 | 160 | Stmt q; |
| 160 | 161 | db_prepare(&q, "SELECT mtime, hash FROM unversioned WHERE name=%Q", zName); |
| @@ -174,10 +175,23 @@ | ||
| 174 | 175 | } |
| 175 | 176 | } |
| 176 | 177 | db_finalize(&q); |
| 177 | 178 | return iStatus; |
| 178 | 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 | +} | |
| 179 | 193 | |
| 180 | 194 | /* |
| 181 | 195 | ** COMMAND: unversioned |
| 182 | 196 | ** |
| 183 | 197 | ** Usage: %fossil unversioned SUBCOMMAND ARGS... |
| @@ -204,19 +218,25 @@ | ||
| 204 | 218 | ** |
| 205 | 219 | ** list | ls Show all unversioned files held in the local repository. |
| 206 | 220 | ** |
| 207 | 221 | ** revert ?URL? Restore the state of all unversioned files in the local |
| 208 | 222 | ** repository to match the remote repository URL. |
| 223 | +** Options: | |
| 224 | +** -v|--verbose Extra diagnostic output | |
| 225 | +** -n|--dryrun Show what would have happened | |
| 209 | 226 | ** |
| 210 | 227 | ** rm FILE ... Remove an unversioned files from the local repository. |
| 211 | 228 | ** Changes are not pushed to other repositories until |
| 212 | -** the next sync. | |
| 229 | +** the next sync. | |
| 213 | 230 | ** |
| 214 | 231 | ** sync ?URL? Synchronize the state of all unversioned files with |
| 215 | 232 | ** the remote repository URL. The most recent version of |
| 216 | 233 | ** each file is propagate to all repositories and all |
| 217 | 234 | ** prior versions are permanently forgotten. |
| 235 | +** Options: | |
| 236 | +** -v|--verbose Extra diagnostic output | |
| 237 | +** -n|--dryrun Show what would have happened | |
| 218 | 238 | ** |
| 219 | 239 | ** touch FILE ... Update the TIMESTAMP on all of the listed files |
| 220 | 240 | ** |
| 221 | 241 | ** Options: |
| 222 | 242 | ** |
| @@ -365,13 +385,14 @@ | ||
| 365 | 385 | ); |
| 366 | 386 | } |
| 367 | 387 | } |
| 368 | 388 | db_finalize(&q); |
| 369 | 389 | }else if( memcmp(zCmd, "revert", nCmd)==0 ){ |
| 390 | + unsigned syncFlags = unversioned_sync_flags(SYNC_UNVERSIONED|SYNC_UV_REVERT); | |
| 370 | 391 | g.argv[1] = "sync"; |
| 371 | 392 | g.argv[2] = "--uv-noop"; |
| 372 | - sync_unversioned(SYNC_UNVERSIONED|SYNC_UV_REVERT); | |
| 393 | + sync_unversioned(syncFlags); | |
| 373 | 394 | }else if( memcmp(zCmd, "rm", nCmd)==0 ){ |
| 374 | 395 | int i; |
| 375 | 396 | verify_all_options(); |
| 376 | 397 | db_begin_transaction(); |
| 377 | 398 | for(i=3; i<g.argc; i++){ |
| @@ -382,13 +403,14 @@ | ||
| 382 | 403 | ); |
| 383 | 404 | } |
| 384 | 405 | db_unset("uv-hash", 0); |
| 385 | 406 | db_end_transaction(0); |
| 386 | 407 | }else if( memcmp(zCmd,"sync",nCmd)==0 ){ |
| 408 | + unsigned syncFlags = unversioned_sync_flags(SYNC_UNVERSIONED); | |
| 387 | 409 | g.argv[1] = "sync"; |
| 388 | 410 | g.argv[2] = "--uv-noop"; |
| 389 | - sync_unversioned(SYNC_UNVERSIONED); | |
| 411 | + sync_unversioned(syncFlags); | |
| 390 | 412 | }else if( memcmp(zCmd, "touch", nCmd)==0 ){ |
| 391 | 413 | int i; |
| 392 | 414 | verify_all_options(); |
| 393 | 415 | db_begin_transaction(); |
| 394 | 416 | for(i=3; i<g.argc; i++){ |
| 395 | 417 |
| --- 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 @@ | ||
| 1656 | 1656 | #define SYNC_VERBOSE 0x0010 /* Extra diagnostics */ |
| 1657 | 1657 | #define SYNC_RESYNC 0x0020 /* --verily */ |
| 1658 | 1658 | #define SYNC_UNVERSIONED 0x0040 /* Sync unversioned content */ |
| 1659 | 1659 | #define SYNC_UV_REVERT 0x0080 /* Copy server unversioned to client */ |
| 1660 | 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 */ | |
| 1661 | 1663 | #endif |
| 1662 | 1664 | |
| 1663 | 1665 | /* |
| 1664 | 1666 | ** Floating-point absolute value |
| 1665 | 1667 | */ |
| @@ -1896,11 +1898,13 @@ | ||
| 1896 | 1898 | ** need to be sent until after the uvigot cards from the first exchange |
| 1897 | 1899 | ** have been processed. |
| 1898 | 1900 | */ |
| 1899 | 1901 | if( uvDoPush ){ |
| 1900 | 1902 | 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 ){ | |
| 1902 | 1906 | db_multi_exec( |
| 1903 | 1907 | "DELETE FROM unversioned" |
| 1904 | 1908 | " WHERE name IN (SELECT name FROM uv_tosend);" |
| 1905 | 1909 | "DELETE FROM uv_tosend;" |
| 1906 | 1910 | ); |
| @@ -2122,10 +2126,24 @@ | ||
| 2122 | 2126 | int iStatus; |
| 2123 | 2127 | iStatus = unversioned_status(zName, mtime, zHash); |
| 2124 | 2128 | if( (syncFlags & SYNC_UV_REVERT)!=0 ){ |
| 2125 | 2129 | if( iStatus==4 ) iStatus = 2; |
| 2126 | 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 | + } | |
| 2127 | 2145 | } |
| 2128 | 2146 | if( iStatus<=1 ){ |
| 2129 | 2147 | if( zHash[0]!='-' ){ |
| 2130 | 2148 | blob_appendf(xfer.pOut, "uvgimme %s\n", zName); |
| 2131 | 2149 | nCardSent++; |
| 2132 | 2150 |
| --- 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 |