Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Added --dry-run support to add/rm/addremove --reset. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | unaddremove-command |
| Files: | files | file ages | folders |
| SHA3-256: |
a7a75e7d412130d6d63afe4120b41409 |
| User & Date: | stephan 2020-04-23 13:49:01.093 |
Context
|
2020-05-04
| ||
| 07:54 | Merged in trunk. ... (check-in: 628c39fb60 user: stephan tags: unaddremove-command) | |
|
2020-04-23
| ||
| 13:49 | Added --dry-run support to add/rm/addremove --reset. ... (check-in: a7a75e7d41 user: stephan tags: unaddremove-command) | |
| 11:30 | Refactored unaddremove into (add|rm|addremove --reset). ... (check-in: 72fdb21ae8 user: stephan tags: unaddremove-command) | |
Changes
Changes to src/add.c.
| ︙ | ︙ | |||
240 241 242 243 244 245 246 | } db_finalize(&loop); blob_reset(&repoName); return nAdd; } /* | | | | > | > > > > | | | | | | | > | > > | < < < | < > > > | | | > | > > | > | | 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
}
db_finalize(&loop);
blob_reset(&repoName);
return nAdd;
}
/*
** Resets the ADDED/DELETED state of a checkout, such that all
** newly-added (but not yet committed) files are no longer added and
** newly-removed (but not yet committed) files are no longer
** removed. If bIsAdd is true, it operates on the "add" state, else it
** operates on the "rm" state.
**
** If bDryRun is true it outputs what it would have done, but does not
** actually do it. In this case it rolls back the transaction it
** starts (so don't start a transaction before calling this).
**
** If bVerbose is true it outputs the name of each reset entry.
**
** This is intended to be called only in the context of the
** add/rm/addremove commands, after a call to verify_all_options().
**
** Un-added files are not modified but any un-rm'd files which are
** missing from the checkout are restored from the repo. un-rm'd files
** which exist in the checkout are left as-is, rather than restoring
** them using vfile_to_disk(), to avoid overwriting any local changes
** made to those files.
*/
static void addremove_reset(int bIsAdd, int bDryRun, int bVerbose){
int nReset = 0; /* # of entries which get reset */
Stmt stmt; /* vfile loop query */
db_begin_transaction();
db_prepare(&stmt, "SELECT id, pathname FROM vfile "
"WHERE %s ORDER BY pathname",
bIsAdd==0 ? "deleted<>0" : "rid=0"/*safe-for-%s*/);
while( db_step(&stmt)==SQLITE_ROW ){
/* This loop exists only so we can restore the contents of un-rm'd
** files and support verbose mode. All manipulation of vfile's
** contents happens after the loop. For the ADD case in non-verbose
** mode we "could" skip this loop entirely.
*/
int const id = db_column_int(&stmt, 0);
char const * zPathname = db_column_text(&stmt, 1);
Blob relName = empty_blob;
if(bIsAdd==0 || bVerbose!=0){
/* Make filename relative... */
char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
file_relative_name(zFullName, &relName, 0);
fossil_free(zFullName);
}
if(bIsAdd==0){
/* Restore contents of missing un-rm'd files. We don't do this
** unconditionally because we might cause data loss if a file
** is modified, rm'd, then un-rm'd.
*/
++nReset;
if(!file_isfile_or_link(blob_str(&relName))){
if(bDryRun==0){
vfile_to_disk(0, id, 0, 0);
if(bVerbose){
fossil_print("Restored missing file: %b\n", &relName);
}
}else{
fossil_print("Dry-run: not restoring missing file: %b\n", &relName);
}
}
if(bVerbose){
fossil_print("Un-removed: %b\n", &relName);
}
}else{
/* un-add... */
++nReset;
if(bVerbose){
fossil_print("Un-added: %b\n", &relName);
}
}
blob_reset(&relName);
}
db_finalize(&stmt);
if(nReset>0){
if(bIsAdd==0){
if(bDryRun==0){
db_exec_sql("UPDATE vfile SET deleted=0 WHERE deleted<>0");
}
fossil_print("Un-removed %d file(s).\n", nReset);
}else{
if(bDryRun==0){
db_exec_sql("DELETE FROM vfile WHERE rid=0");
}
fossil_print("Un-added %d file(s).\n", nReset);
}
}
db_end_transaction(bDryRun ? 1 : 0);
}
/*
** COMMAND: add
**
** Usage: %fossil add ?OPTIONS? FILE1 ?FILE2 ...?
|
| ︙ | ︙ | |||
354 355 356 357 358 359 360 |
** --case-sensitive <BOOL> Override the case-sensitive setting.
** --dotfiles include files beginning with a dot (".")
** -f|--force Add files without prompting
** --ignore <CSG> Ignore unmanaged files matching patterns from
** the comma separated list of glob patterns.
** --clean <CSG> Also ignore files matching patterns from
** the comma separated list of glob patterns.
| | | > | | | > | | 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
** --case-sensitive <BOOL> Override the case-sensitive setting.
** --dotfiles include files beginning with a dot (".")
** -f|--force Add files without prompting
** --ignore <CSG> Ignore unmanaged files matching patterns from
** the comma separated list of glob patterns.
** --clean <CSG> Also ignore files matching patterns from
** the comma separated list of glob patterns.
** --reset Reset the ADDEd state of a checkout, such that
** all newly-added (but not yet committed) files
** are no longer added.
**
** The following options are only valid with --reset:
** -v|--verbose Outputs information about each --reset file.
** -n|--dry-run Display instead of run actions.
**
** See also: addremove, rm
*/
void add_cmd(void){
int i; /* Loop counter */
int vid; /* Currently checked out version */
int nRoot; /* Full path characters in g.zLocalRoot */
const char *zCleanFlag; /* The --clean option or clean-glob setting */
const char *zIgnoreFlag; /* The --ignore option or ignore-glob setting */
Glob *pIgnore, *pClean; /* Ignore everything matching the glob patterns */
unsigned scanFlags = 0; /* Flags passed to vfile_scan() */
int forceFlag;
if(0!=find_option("reset",0,0)){
int const verboseFlag = find_option("verbose","v",0)!=0;
int const dryRunFlag = find_option("dry-run","n",0)!=0;
db_must_be_within_tree();
verify_all_options();
addremove_reset(1, dryRunFlag, verboseFlag);
return;
}
zCleanFlag = find_option("clean",0,1);
zIgnoreFlag = find_option("ignore",0,1);
forceFlag = find_option("force","f",0)!=0;
if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL;
|
| ︙ | ︙ | |||
546 547 548 549 550 551 552 |
** Only usable with --reset.
**
** See also: addremove, add
*/
void delete_cmd(void){
int i;
int removeFiles;
| | | < | 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 |
** Only usable with --reset.
**
** See also: addremove, add
*/
void delete_cmd(void){
int i;
int removeFiles;
int dryRunFlag = find_option("dry-run","n",0)!=0;
int softFlag;
int hardFlag;
Stmt loop;
if(0!=find_option("reset",0,0)){
int const verboseFlag = find_option("verbose","v",0)!=0;
db_must_be_within_tree();
verify_all_options();
addremove_reset(0, dryRunFlag, verboseFlag);
return;
}
softFlag = find_option("soft",0,0)!=0;
hardFlag = find_option("hard",0,0)!=0;
/* We should be done with options.. */
verify_all_options();
db_must_be_within_tree();
|
| ︙ | ︙ | |||
732 733 734 735 736 737 738 | ** the comma separated list of glob patterns. ** --clean <CSG> Also ignore files matching patterns from ** the comma separated list of glob patterns. ** -n|--dry-run If given, display instead of run actions. ** --reset Reset the ADDED/DELETED state of a checkout, ** such that all newly-added (but not yet committed) ** files are no longer added and all newly-removed | | | | | > > > > | | < < < < | 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 |
** the comma separated list of glob patterns.
** --clean <CSG> Also ignore files matching patterns from
** the comma separated list of glob patterns.
** -n|--dry-run If given, display instead of run actions.
** --reset Reset the ADDED/DELETED state of a checkout,
** such that all newly-added (but not yet committed)
** files are no longer added and all newly-removed
** (but not yet committed) files are no longer
** removed. No flags other than --verbose and
** --dry-run may be used with --reset.
** --verbose|-v Outputs information about each --reset file.
** Only usable with --reset.
**
** See also: add, rm
*/
void addremove_cmd(void){
Blob path;
const char *zCleanFlag;
const char *zIgnoreFlag;
unsigned scanFlags;
int dryRunFlag = find_option("dry-run","n",0)!=0;
int n;
Stmt q;
int vid;
int nAdd = 0;
int nDelete = 0;
Glob *pIgnore, *pClean;
if( !dryRunFlag ){
dryRunFlag = find_option("test",0,0)!=0; /* deprecated */
}
if(0!=find_option("reset",0,0)){
int const verboseFlag = find_option("verbose","v",0)!=0;
db_must_be_within_tree();
verify_all_options();
addremove_reset(0, dryRunFlag, verboseFlag);
addremove_reset(1, dryRunFlag, verboseFlag);
return;
}
zCleanFlag = find_option("clean",0,1);
zIgnoreFlag = find_option("ignore",0,1);
scanFlags = find_option("dotfiles",0,0)!=0 ? SCAN_ALL : 0;
/* We should be done with options.. */
verify_all_options();
/* Fail if unprocessed arguments are present, in case user expect the
** addremove command to accept a list of file or directory.
*/
|
| ︙ | ︙ |