Fossil SCM
Add comments and simplify use of temporary tables.
Commit
90ee7bcb765375ea3ab955e8fd04e79f24658e08
Parent
99c57b3eb3f21a0…
1 file changed
+46
-12
+46
-12
| --- src/add.c | ||
| +++ src/add.c | ||
| @@ -366,24 +366,42 @@ | ||
| 366 | 366 | |
| 367 | 367 | add_files_in_sfile(vid); |
| 368 | 368 | db_end_transaction(0); |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | -static void init_files_to_remove(){ | |
| 372 | - db_multi_exec("CREATE TEMP TABLE fremove(x TEXT PRIMARY KEY %s)", | |
| 373 | - filename_collation()); | |
| 374 | -} | |
| 375 | - | |
| 371 | +/* | |
| 372 | +** This function adds a file to list of files to delete from disk after | |
| 373 | +** the other actions required for the parent operation have completed | |
| 374 | +** successfully. The first time it is called for the current process, | |
| 375 | +** it creates a temporary table named "fremove", to keep track of these | |
| 376 | +** files. | |
| 377 | +*/ | |
| 376 | 378 | static void add_file_to_remove( |
| 377 | 379 | const char *zOldName /* The old name of the file on disk. */ |
| 378 | 380 | ){ |
| 381 | + static int tableCreated = 0; | |
| 379 | 382 | Blob fullOldName; |
| 383 | + if( !tableCreated ){ | |
| 384 | + db_multi_exec("CREATE TEMP TABLE fremove(x TEXT PRIMARY KEY %s)", | |
| 385 | + filename_collation()); | |
| 386 | + tableCreated = 1; | |
| 387 | + } | |
| 380 | 388 | file_canonical_name(zOldName, &fullOldName, 0); |
| 381 | 389 | db_multi_exec("INSERT INTO fremove VALUES('%q');", blob_str(&fullOldName)); |
| 382 | 390 | blob_reset(&fullOldName); |
| 383 | 391 | } |
| 384 | 392 | |
| 393 | +/* | |
| 394 | +** This function deletes files from the checkout, using the file names | |
| 395 | +** contained in the temporary table "fremove". The temporary table is | |
| 396 | +** created on demand by the add_file_to_remove() function. | |
| 397 | +** | |
| 398 | +** If dryRunFlag is non-zero, no files will be removed; however, their | |
| 399 | +** names will still be output. | |
| 400 | +** | |
| 401 | +** The temporary table "fremove" is dropped after being processed. | |
| 402 | +*/ | |
| 385 | 403 | static void process_files_to_remove( |
| 386 | 404 | int dryRunFlag /* Zero to actually operate on the file-system. */ |
| 387 | 405 | ){ |
| 388 | 406 | Stmt remove; |
| 389 | 407 | db_prepare(&remove, "SELECT x FROM fremove ORDER BY x;"); |
| @@ -474,11 +492,10 @@ | ||
| 474 | 492 | removeFiles = db_get_boolean("remove-files",0); |
| 475 | 493 | #else |
| 476 | 494 | removeFiles = FOSSIL_RM_CHECKOUT_FILE_ON_RM; |
| 477 | 495 | #endif |
| 478 | 496 | } |
| 479 | - if( removeFiles ) init_files_to_remove(); | |
| 480 | 497 | db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY %s)", |
| 481 | 498 | filename_collation()); |
| 482 | 499 | for(i=2; i<g.argc; i++){ |
| 483 | 500 | Blob treeName; |
| 484 | 501 | char *zTreeName; |
| @@ -736,29 +753,47 @@ | ||
| 736 | 753 | zNew, zOrig, filename_collation(), vid |
| 737 | 754 | ); |
| 738 | 755 | } |
| 739 | 756 | } |
| 740 | 757 | |
| 741 | -static void init_files_to_move(){ | |
| 742 | - db_multi_exec("CREATE TEMP TABLE fmove(x TEXT PRIMARY KEY %s, y TEXT %s)", | |
| 743 | - filename_collation(), filename_collation()); | |
| 744 | -} | |
| 745 | - | |
| 758 | +/* | |
| 759 | +** This function adds a file to list of files to move on disk after the | |
| 760 | +** other actions required for the parent operation have completed | |
| 761 | +** successfully. The first time it is called for the current process, | |
| 762 | +** it creates a temporary table named "fmove", to keep track of these | |
| 763 | +** files. | |
| 764 | +*/ | |
| 746 | 765 | static void add_file_to_move( |
| 747 | 766 | const char *zOldName, /* The old name of the file on disk. */ |
| 748 | 767 | const char *zNewName /* The new name of the file on disk. */ |
| 749 | 768 | ){ |
| 769 | + static int tableCreated = 0; | |
| 750 | 770 | Blob fullOldName; |
| 751 | 771 | Blob fullNewName; |
| 772 | + if( !tableCreated ){ | |
| 773 | + db_multi_exec("CREATE TEMP TABLE fmove(x TEXT PRIMARY KEY %s, y TEXT %s)", | |
| 774 | + filename_collation(), filename_collation()); | |
| 775 | + tableCreated = 1; | |
| 776 | + } | |
| 752 | 777 | file_canonical_name(zOldName, &fullOldName, 0); |
| 753 | 778 | file_canonical_name(zNewName, &fullNewName, 0); |
| 754 | 779 | db_multi_exec("INSERT INTO fmove VALUES('%q','%q');", |
| 755 | 780 | blob_str(&fullOldName), blob_str(&fullNewName)); |
| 756 | 781 | blob_reset(&fullNewName); |
| 757 | 782 | blob_reset(&fullOldName); |
| 758 | 783 | } |
| 759 | 784 | |
| 785 | +/* | |
| 786 | +** This function moves files within the checkout, using the file names | |
| 787 | +** contained in the temporary table "fmove". The temporary table is | |
| 788 | +** created on demand by the add_file_to_move() function. | |
| 789 | +** | |
| 790 | +** If dryRunFlag is non-zero, no files will be moved; however, their | |
| 791 | +** names will still be output. | |
| 792 | +** | |
| 793 | +** The temporary table "fmove" is dropped after being processed. | |
| 794 | +*/ | |
| 760 | 795 | static void process_files_to_move( |
| 761 | 796 | int dryRunFlag /* Zero to actually operate on the file-system. */ |
| 762 | 797 | ){ |
| 763 | 798 | Stmt move; |
| 764 | 799 | db_prepare(&move, "SELECT x, y FROM fmove ORDER BY x;"); |
| @@ -851,11 +886,10 @@ | ||
| 851 | 886 | moveFiles = db_get_boolean("move-files",0); |
| 852 | 887 | #else |
| 853 | 888 | moveFiles = FOSSIL_MV_CHECKOUT_FILE_ON_MV; |
| 854 | 889 | #endif |
| 855 | 890 | } |
| 856 | - if( moveFiles ) init_files_to_move(); | |
| 857 | 891 | file_tree_name(zDest, &dest, 1); |
| 858 | 892 | db_multi_exec( |
| 859 | 893 | "UPDATE vfile SET origname=pathname WHERE origname IS NULL;" |
| 860 | 894 | ); |
| 861 | 895 | db_multi_exec( |
| 862 | 896 |
| --- src/add.c | |
| +++ src/add.c | |
| @@ -366,24 +366,42 @@ | |
| 366 | |
| 367 | add_files_in_sfile(vid); |
| 368 | db_end_transaction(0); |
| 369 | } |
| 370 | |
| 371 | static void init_files_to_remove(){ |
| 372 | db_multi_exec("CREATE TEMP TABLE fremove(x TEXT PRIMARY KEY %s)", |
| 373 | filename_collation()); |
| 374 | } |
| 375 | |
| 376 | static void add_file_to_remove( |
| 377 | const char *zOldName /* The old name of the file on disk. */ |
| 378 | ){ |
| 379 | Blob fullOldName; |
| 380 | file_canonical_name(zOldName, &fullOldName, 0); |
| 381 | db_multi_exec("INSERT INTO fremove VALUES('%q');", blob_str(&fullOldName)); |
| 382 | blob_reset(&fullOldName); |
| 383 | } |
| 384 | |
| 385 | static void process_files_to_remove( |
| 386 | int dryRunFlag /* Zero to actually operate on the file-system. */ |
| 387 | ){ |
| 388 | Stmt remove; |
| 389 | db_prepare(&remove, "SELECT x FROM fremove ORDER BY x;"); |
| @@ -474,11 +492,10 @@ | |
| 474 | removeFiles = db_get_boolean("remove-files",0); |
| 475 | #else |
| 476 | removeFiles = FOSSIL_RM_CHECKOUT_FILE_ON_RM; |
| 477 | #endif |
| 478 | } |
| 479 | if( removeFiles ) init_files_to_remove(); |
| 480 | db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY %s)", |
| 481 | filename_collation()); |
| 482 | for(i=2; i<g.argc; i++){ |
| 483 | Blob treeName; |
| 484 | char *zTreeName; |
| @@ -736,29 +753,47 @@ | |
| 736 | zNew, zOrig, filename_collation(), vid |
| 737 | ); |
| 738 | } |
| 739 | } |
| 740 | |
| 741 | static void init_files_to_move(){ |
| 742 | db_multi_exec("CREATE TEMP TABLE fmove(x TEXT PRIMARY KEY %s, y TEXT %s)", |
| 743 | filename_collation(), filename_collation()); |
| 744 | } |
| 745 | |
| 746 | static void add_file_to_move( |
| 747 | const char *zOldName, /* The old name of the file on disk. */ |
| 748 | const char *zNewName /* The new name of the file on disk. */ |
| 749 | ){ |
| 750 | Blob fullOldName; |
| 751 | Blob fullNewName; |
| 752 | file_canonical_name(zOldName, &fullOldName, 0); |
| 753 | file_canonical_name(zNewName, &fullNewName, 0); |
| 754 | db_multi_exec("INSERT INTO fmove VALUES('%q','%q');", |
| 755 | blob_str(&fullOldName), blob_str(&fullNewName)); |
| 756 | blob_reset(&fullNewName); |
| 757 | blob_reset(&fullOldName); |
| 758 | } |
| 759 | |
| 760 | static void process_files_to_move( |
| 761 | int dryRunFlag /* Zero to actually operate on the file-system. */ |
| 762 | ){ |
| 763 | Stmt move; |
| 764 | db_prepare(&move, "SELECT x, y FROM fmove ORDER BY x;"); |
| @@ -851,11 +886,10 @@ | |
| 851 | moveFiles = db_get_boolean("move-files",0); |
| 852 | #else |
| 853 | moveFiles = FOSSIL_MV_CHECKOUT_FILE_ON_MV; |
| 854 | #endif |
| 855 | } |
| 856 | if( moveFiles ) init_files_to_move(); |
| 857 | file_tree_name(zDest, &dest, 1); |
| 858 | db_multi_exec( |
| 859 | "UPDATE vfile SET origname=pathname WHERE origname IS NULL;" |
| 860 | ); |
| 861 | db_multi_exec( |
| 862 |
| --- src/add.c | |
| +++ src/add.c | |
| @@ -366,24 +366,42 @@ | |
| 366 | |
| 367 | add_files_in_sfile(vid); |
| 368 | db_end_transaction(0); |
| 369 | } |
| 370 | |
| 371 | /* |
| 372 | ** This function adds a file to list of files to delete from disk after |
| 373 | ** the other actions required for the parent operation have completed |
| 374 | ** successfully. The first time it is called for the current process, |
| 375 | ** it creates a temporary table named "fremove", to keep track of these |
| 376 | ** files. |
| 377 | */ |
| 378 | static void add_file_to_remove( |
| 379 | const char *zOldName /* The old name of the file on disk. */ |
| 380 | ){ |
| 381 | static int tableCreated = 0; |
| 382 | Blob fullOldName; |
| 383 | if( !tableCreated ){ |
| 384 | db_multi_exec("CREATE TEMP TABLE fremove(x TEXT PRIMARY KEY %s)", |
| 385 | filename_collation()); |
| 386 | tableCreated = 1; |
| 387 | } |
| 388 | file_canonical_name(zOldName, &fullOldName, 0); |
| 389 | db_multi_exec("INSERT INTO fremove VALUES('%q');", blob_str(&fullOldName)); |
| 390 | blob_reset(&fullOldName); |
| 391 | } |
| 392 | |
| 393 | /* |
| 394 | ** This function deletes files from the checkout, using the file names |
| 395 | ** contained in the temporary table "fremove". The temporary table is |
| 396 | ** created on demand by the add_file_to_remove() function. |
| 397 | ** |
| 398 | ** If dryRunFlag is non-zero, no files will be removed; however, their |
| 399 | ** names will still be output. |
| 400 | ** |
| 401 | ** The temporary table "fremove" is dropped after being processed. |
| 402 | */ |
| 403 | static void process_files_to_remove( |
| 404 | int dryRunFlag /* Zero to actually operate on the file-system. */ |
| 405 | ){ |
| 406 | Stmt remove; |
| 407 | db_prepare(&remove, "SELECT x FROM fremove ORDER BY x;"); |
| @@ -474,11 +492,10 @@ | |
| 492 | removeFiles = db_get_boolean("remove-files",0); |
| 493 | #else |
| 494 | removeFiles = FOSSIL_RM_CHECKOUT_FILE_ON_RM; |
| 495 | #endif |
| 496 | } |
| 497 | db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY %s)", |
| 498 | filename_collation()); |
| 499 | for(i=2; i<g.argc; i++){ |
| 500 | Blob treeName; |
| 501 | char *zTreeName; |
| @@ -736,29 +753,47 @@ | |
| 753 | zNew, zOrig, filename_collation(), vid |
| 754 | ); |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | /* |
| 759 | ** This function adds a file to list of files to move on disk after the |
| 760 | ** other actions required for the parent operation have completed |
| 761 | ** successfully. The first time it is called for the current process, |
| 762 | ** it creates a temporary table named "fmove", to keep track of these |
| 763 | ** files. |
| 764 | */ |
| 765 | static void add_file_to_move( |
| 766 | const char *zOldName, /* The old name of the file on disk. */ |
| 767 | const char *zNewName /* The new name of the file on disk. */ |
| 768 | ){ |
| 769 | static int tableCreated = 0; |
| 770 | Blob fullOldName; |
| 771 | Blob fullNewName; |
| 772 | if( !tableCreated ){ |
| 773 | db_multi_exec("CREATE TEMP TABLE fmove(x TEXT PRIMARY KEY %s, y TEXT %s)", |
| 774 | filename_collation(), filename_collation()); |
| 775 | tableCreated = 1; |
| 776 | } |
| 777 | file_canonical_name(zOldName, &fullOldName, 0); |
| 778 | file_canonical_name(zNewName, &fullNewName, 0); |
| 779 | db_multi_exec("INSERT INTO fmove VALUES('%q','%q');", |
| 780 | blob_str(&fullOldName), blob_str(&fullNewName)); |
| 781 | blob_reset(&fullNewName); |
| 782 | blob_reset(&fullOldName); |
| 783 | } |
| 784 | |
| 785 | /* |
| 786 | ** This function moves files within the checkout, using the file names |
| 787 | ** contained in the temporary table "fmove". The temporary table is |
| 788 | ** created on demand by the add_file_to_move() function. |
| 789 | ** |
| 790 | ** If dryRunFlag is non-zero, no files will be moved; however, their |
| 791 | ** names will still be output. |
| 792 | ** |
| 793 | ** The temporary table "fmove" is dropped after being processed. |
| 794 | */ |
| 795 | static void process_files_to_move( |
| 796 | int dryRunFlag /* Zero to actually operate on the file-system. */ |
| 797 | ){ |
| 798 | Stmt move; |
| 799 | db_prepare(&move, "SELECT x, y FROM fmove ORDER BY x;"); |
| @@ -851,11 +886,10 @@ | |
| 886 | moveFiles = db_get_boolean("move-files",0); |
| 887 | #else |
| 888 | moveFiles = FOSSIL_MV_CHECKOUT_FILE_ON_MV; |
| 889 | #endif |
| 890 | } |
| 891 | file_tree_name(zDest, &dest, 1); |
| 892 | db_multi_exec( |
| 893 | "UPDATE vfile SET origname=pathname WHERE origname IS NULL;" |
| 894 | ); |
| 895 | db_multi_exec( |
| 896 |