Fossil SCM

Add comments and simplify use of temporary tables.

mistachkin 2015-04-10 00:02 UTC mvAndRmFiles
Commit 90ee7bcb765375ea3ab955e8fd04e79f24658e08
1 file changed +46 -12
+46 -12
--- src/add.c
+++ src/add.c
@@ -366,24 +366,42 @@
366366
367367
add_files_in_sfile(vid);
368368
db_end_transaction(0);
369369
}
370370
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
+*/
376378
static void add_file_to_remove(
377379
const char *zOldName /* The old name of the file on disk. */
378380
){
381
+ static int tableCreated = 0;
379382
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
+ }
380388
file_canonical_name(zOldName, &fullOldName, 0);
381389
db_multi_exec("INSERT INTO fremove VALUES('%q');", blob_str(&fullOldName));
382390
blob_reset(&fullOldName);
383391
}
384392
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
+*/
385403
static void process_files_to_remove(
386404
int dryRunFlag /* Zero to actually operate on the file-system. */
387405
){
388406
Stmt remove;
389407
db_prepare(&remove, "SELECT x FROM fremove ORDER BY x;");
@@ -474,11 +492,10 @@
474492
removeFiles = db_get_boolean("remove-files",0);
475493
#else
476494
removeFiles = FOSSIL_RM_CHECKOUT_FILE_ON_RM;
477495
#endif
478496
}
479
- if( removeFiles ) init_files_to_remove();
480497
db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY %s)",
481498
filename_collation());
482499
for(i=2; i<g.argc; i++){
483500
Blob treeName;
484501
char *zTreeName;
@@ -736,29 +753,47 @@
736753
zNew, zOrig, filename_collation(), vid
737754
);
738755
}
739756
}
740757
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
+*/
746765
static void add_file_to_move(
747766
const char *zOldName, /* The old name of the file on disk. */
748767
const char *zNewName /* The new name of the file on disk. */
749768
){
769
+ static int tableCreated = 0;
750770
Blob fullOldName;
751771
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
+ }
752777
file_canonical_name(zOldName, &fullOldName, 0);
753778
file_canonical_name(zNewName, &fullNewName, 0);
754779
db_multi_exec("INSERT INTO fmove VALUES('%q','%q');",
755780
blob_str(&fullOldName), blob_str(&fullNewName));
756781
blob_reset(&fullNewName);
757782
blob_reset(&fullOldName);
758783
}
759784
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
+*/
760795
static void process_files_to_move(
761796
int dryRunFlag /* Zero to actually operate on the file-system. */
762797
){
763798
Stmt move;
764799
db_prepare(&move, "SELECT x, y FROM fmove ORDER BY x;");
@@ -851,11 +886,10 @@
851886
moveFiles = db_get_boolean("move-files",0);
852887
#else
853888
moveFiles = FOSSIL_MV_CHECKOUT_FILE_ON_MV;
854889
#endif
855890
}
856
- if( moveFiles ) init_files_to_move();
857891
file_tree_name(zDest, &dest, 1);
858892
db_multi_exec(
859893
"UPDATE vfile SET origname=pathname WHERE origname IS NULL;"
860894
);
861895
db_multi_exec(
862896
--- 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

Keyboard Shortcuts

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