Fossil SCM

Fix directory naming issue with with the --hard option as reported via the mailing list.

mistachkin 2016-03-17 19:30 trunk merge
Commit 1f694e17046a8c8c7ebbbdebb6b9017bb50757f3
+12 -4
--- src/add.c
+++ src/add.c
@@ -785,16 +785,24 @@
785785
db_prepare(&move, "SELECT x, y FROM fmove ORDER BY x;");
786786
while( db_step(&move)==SQLITE_ROW ){
787787
const char *zOldName = db_column_text(&move, 0);
788788
const char *zNewName = db_column_text(&move, 1);
789789
if( !dryRunFlag ){
790
- if( file_wd_islink(zOldName) ){
791
- symlink_copy(zOldName, zNewName);
790
+ int isOldDir = file_isdir(zOldName);
791
+ if( isOldDir==1 ){
792
+ int isNewDir = file_isdir(zNewName);
793
+ if( isNewDir==0 ){
794
+ file_rename(zOldName, zNewName, isOldDir, isNewDir);
795
+ }
792796
}else{
793
- file_copy(zOldName, zNewName);
797
+ if( file_wd_islink(zOldName) ){
798
+ symlink_copy(zOldName, zNewName);
799
+ }else{
800
+ file_copy(zOldName, zNewName);
801
+ }
802
+ file_delete(zOldName);
794803
}
795
- file_delete(zOldName);
796804
}
797805
fossil_print("MOVED_FILE %s\n", zOldName);
798806
}
799807
db_finalize(&move);
800808
db_multi_exec("DROP TABLE fmove;");
801809
--- src/add.c
+++ src/add.c
@@ -785,16 +785,24 @@
785 db_prepare(&move, "SELECT x, y FROM fmove ORDER BY x;");
786 while( db_step(&move)==SQLITE_ROW ){
787 const char *zOldName = db_column_text(&move, 0);
788 const char *zNewName = db_column_text(&move, 1);
789 if( !dryRunFlag ){
790 if( file_wd_islink(zOldName) ){
791 symlink_copy(zOldName, zNewName);
 
 
 
 
792 }else{
793 file_copy(zOldName, zNewName);
 
 
 
 
 
794 }
795 file_delete(zOldName);
796 }
797 fossil_print("MOVED_FILE %s\n", zOldName);
798 }
799 db_finalize(&move);
800 db_multi_exec("DROP TABLE fmove;");
801
--- src/add.c
+++ src/add.c
@@ -785,16 +785,24 @@
785 db_prepare(&move, "SELECT x, y FROM fmove ORDER BY x;");
786 while( db_step(&move)==SQLITE_ROW ){
787 const char *zOldName = db_column_text(&move, 0);
788 const char *zNewName = db_column_text(&move, 1);
789 if( !dryRunFlag ){
790 int isOldDir = file_isdir(zOldName);
791 if( isOldDir==1 ){
792 int isNewDir = file_isdir(zNewName);
793 if( isNewDir==0 ){
794 file_rename(zOldName, zNewName, isOldDir, isNewDir);
795 }
796 }else{
797 if( file_wd_islink(zOldName) ){
798 symlink_copy(zOldName, zNewName);
799 }else{
800 file_copy(zOldName, zNewName);
801 }
802 file_delete(zOldName);
803 }
 
804 }
805 fossil_print("MOVED_FILE %s\n", zOldName);
806 }
807 db_finalize(&move);
808 db_multi_exec("DROP TABLE fmove;");
809
+26
--- src/file.c
+++ src/file.c
@@ -24,10 +24,11 @@
2424
*/
2525
#include "config.h"
2626
#include <sys/types.h>
2727
#include <sys/stat.h>
2828
#include <unistd.h>
29
+#include <stdio.h>
2930
#include <string.h>
3031
#include <errno.h>
3132
#include "file.h"
3233
3334
/*
@@ -398,10 +399,35 @@
398399
return mprintf("%.*s", (int)(zTail-z-1), z);
399400
}else{
400401
return 0;
401402
}
402403
}
404
+
405
+/*
406
+** Rename a file or directory.
407
+** Returns zero upon success.
408
+*/
409
+int file_rename(
410
+ const char *zFrom,
411
+ const char *zTo,
412
+ int isFromDir,
413
+ int isToDir
414
+){
415
+ int rc;
416
+#if defined(_WIN32)
417
+ wchar_t *zMbcsFrom = fossil_utf8_to_path(zFrom, isFromDir);
418
+ wchar_t *zMbcsTo = fossil_utf8_to_path(zTo, isToDir);
419
+ rc = _wrename(zMbcsFrom, zMbcsTo);
420
+#else
421
+ char *zMbcsFrom = fossil_utf8_to_path(zFrom, isFromDir);
422
+ char *zMbcsTo = fossil_utf8_to_path(zTo, isToDir);
423
+ rc = rename(zMbcsFrom, zMbcsTo);
424
+#endif
425
+ fossil_path_free(zMbcsTo);
426
+ fossil_path_free(zMbcsFrom);
427
+ return rc;
428
+}
403429
404430
/*
405431
** Copy the content of a file from one place to another.
406432
*/
407433
void file_copy(const char *zFrom, const char *zTo){
408434
--- src/file.c
+++ src/file.c
@@ -24,10 +24,11 @@
24 */
25 #include "config.h"
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <unistd.h>
 
29 #include <string.h>
30 #include <errno.h>
31 #include "file.h"
32
33 /*
@@ -398,10 +399,35 @@
398 return mprintf("%.*s", (int)(zTail-z-1), z);
399 }else{
400 return 0;
401 }
402 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
403
404 /*
405 ** Copy the content of a file from one place to another.
406 */
407 void file_copy(const char *zFrom, const char *zTo){
408
--- src/file.c
+++ src/file.c
@@ -24,10 +24,11 @@
24 */
25 #include "config.h"
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <unistd.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <errno.h>
32 #include "file.h"
33
34 /*
@@ -398,10 +399,35 @@
399 return mprintf("%.*s", (int)(zTail-z-1), z);
400 }else{
401 return 0;
402 }
403 }
404
405 /*
406 ** Rename a file or directory.
407 ** Returns zero upon success.
408 */
409 int file_rename(
410 const char *zFrom,
411 const char *zTo,
412 int isFromDir,
413 int isToDir
414 ){
415 int rc;
416 #if defined(_WIN32)
417 wchar_t *zMbcsFrom = fossil_utf8_to_path(zFrom, isFromDir);
418 wchar_t *zMbcsTo = fossil_utf8_to_path(zTo, isToDir);
419 rc = _wrename(zMbcsFrom, zMbcsTo);
420 #else
421 char *zMbcsFrom = fossil_utf8_to_path(zFrom, isFromDir);
422 char *zMbcsTo = fossil_utf8_to_path(zTo, isToDir);
423 rc = rename(zMbcsFrom, zMbcsTo);
424 #endif
425 fossil_path_free(zMbcsTo);
426 fossil_path_free(zMbcsFrom);
427 return rc;
428 }
429
430 /*
431 ** Copy the content of a file from one place to another.
432 */
433 void file_copy(const char *zFrom, const char *zTo){
434
+50 -1
--- test/mv-rm.test
+++ test/mv-rm.test
@@ -46,12 +46,13 @@
4646
write_file [file join $rootDir subdirB f9] "f9"
4747
4848
file mkdir [file join $rootDir subdirC]
4949
write_file [file join $rootDir subdirC f10] "f10"
5050
write_file [file join $rootDir subdirC f11] "f11"
51
+write_file f12 "f12"
5152
52
-fossil add f1 f2 f3 f4 f5 f6 f7 f8 subdirB/f9 subdirC/f10 subdirC/f11
53
+fossil add f1 f2 f3 f4 f5 f6 f7 f8 subdirB/f9 subdirC/f10 subdirC/f11 f12
5354
fossil commit -m "c1"
5455
5556
########################################
5657
# Test 1: Soft Move Relative Directory #
5758
########################################
@@ -380,10 +381,58 @@
380381
fossil revert
381382
test rm-hard-absolute-6 {
382383
[normalize_result] eq "REVERT f8${undoMsg}"
383384
}
384385
386
+cd $rootDir
387
+
388
+#######################################
389
+# Test 17: Move File to New Directory #
390
+#######################################
391
+
392
+fossil mv --hard f12 d2/f13
393
+test mv-file-new-directory-1 {
394
+ [normalize_result] eq "RENAME f12 d2/f13\nMOVED_FILE ${rootDir}/f12"
395
+}
396
+
397
+test mv-file-new-directory-2 {[file size d2/f13] == 3}
398
+test mv-file-new-directory-3 {[read_file d2/f13] eq "f12"}
399
+
400
+fossil revert
401
+test mv-file-new-directory-4 {
402
+ [normalize_result] eq "DELETE d2/f13\nREVERT f12${undoMsg}"
403
+}
404
+
405
+test mv-file-new-directory-5 {[file size f12] == 3}
406
+test mv-file-new-directory-6 {[read_file f12] eq "f12"}
407
+
408
+cd $rootDir
409
+
410
+############################################
411
+# Test 18: Move Directory to New Directory #
412
+############################################
413
+
414
+fossil mv --hard subdirC subdirD
415
+test mv-file-new-directory-7 {
416
+ [normalize_result] eq "RENAME subdirC subdirD\nMOVED_FILE ${rootDir}/subdirC"
417
+}
418
+
419
+test mv-file-new-directory-8 {[file size subdirD/f10] == 3}
420
+test mv-file-new-directory-9 {[read_file subdirD/f10] eq "f10"}
421
+test mv-file-new-directory-10 {[file size subdirD/f11] == 3}
422
+test mv-file-new-directory-11 {[read_file subdirD/f11] eq "f11"}
423
+
424
+fossil revert
425
+test mv-file-new-directory-12 {
426
+ [normalize_result] eq "REVERT subdirC/f10\nREVERT subdirC/f11${undoMsg}"
427
+}
428
+
429
+test mv-file-new-directory-13 {[file size subdirC/f10] == 3}
430
+test mv-file-new-directory-14 {[read_file subdirC/f10] eq "f10"}
431
+test mv-file-new-directory-15 {[file size subdirC/f11] == 3}
432
+test mv-file-new-directory-16 {[read_file subdirC/f11] eq "f11"}
433
+
385434
cd $rootDir
386435
387436
###############################################################################
388437
389438
test_cleanup
390439
--- test/mv-rm.test
+++ test/mv-rm.test
@@ -46,12 +46,13 @@
46 write_file [file join $rootDir subdirB f9] "f9"
47
48 file mkdir [file join $rootDir subdirC]
49 write_file [file join $rootDir subdirC f10] "f10"
50 write_file [file join $rootDir subdirC f11] "f11"
 
51
52 fossil add f1 f2 f3 f4 f5 f6 f7 f8 subdirB/f9 subdirC/f10 subdirC/f11
53 fossil commit -m "c1"
54
55 ########################################
56 # Test 1: Soft Move Relative Directory #
57 ########################################
@@ -380,10 +381,58 @@
380 fossil revert
381 test rm-hard-absolute-6 {
382 [normalize_result] eq "REVERT f8${undoMsg}"
383 }
384
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
385 cd $rootDir
386
387 ###############################################################################
388
389 test_cleanup
390
--- test/mv-rm.test
+++ test/mv-rm.test
@@ -46,12 +46,13 @@
46 write_file [file join $rootDir subdirB f9] "f9"
47
48 file mkdir [file join $rootDir subdirC]
49 write_file [file join $rootDir subdirC f10] "f10"
50 write_file [file join $rootDir subdirC f11] "f11"
51 write_file f12 "f12"
52
53 fossil add f1 f2 f3 f4 f5 f6 f7 f8 subdirB/f9 subdirC/f10 subdirC/f11 f12
54 fossil commit -m "c1"
55
56 ########################################
57 # Test 1: Soft Move Relative Directory #
58 ########################################
@@ -380,10 +381,58 @@
381 fossil revert
382 test rm-hard-absolute-6 {
383 [normalize_result] eq "REVERT f8${undoMsg}"
384 }
385
386 cd $rootDir
387
388 #######################################
389 # Test 17: Move File to New Directory #
390 #######################################
391
392 fossil mv --hard f12 d2/f13
393 test mv-file-new-directory-1 {
394 [normalize_result] eq "RENAME f12 d2/f13\nMOVED_FILE ${rootDir}/f12"
395 }
396
397 test mv-file-new-directory-2 {[file size d2/f13] == 3}
398 test mv-file-new-directory-3 {[read_file d2/f13] eq "f12"}
399
400 fossil revert
401 test mv-file-new-directory-4 {
402 [normalize_result] eq "DELETE d2/f13\nREVERT f12${undoMsg}"
403 }
404
405 test mv-file-new-directory-5 {[file size f12] == 3}
406 test mv-file-new-directory-6 {[read_file f12] eq "f12"}
407
408 cd $rootDir
409
410 ############################################
411 # Test 18: Move Directory to New Directory #
412 ############################################
413
414 fossil mv --hard subdirC subdirD
415 test mv-file-new-directory-7 {
416 [normalize_result] eq "RENAME subdirC subdirD\nMOVED_FILE ${rootDir}/subdirC"
417 }
418
419 test mv-file-new-directory-8 {[file size subdirD/f10] == 3}
420 test mv-file-new-directory-9 {[read_file subdirD/f10] eq "f10"}
421 test mv-file-new-directory-10 {[file size subdirD/f11] == 3}
422 test mv-file-new-directory-11 {[read_file subdirD/f11] eq "f11"}
423
424 fossil revert
425 test mv-file-new-directory-12 {
426 [normalize_result] eq "REVERT subdirC/f10\nREVERT subdirC/f11${undoMsg}"
427 }
428
429 test mv-file-new-directory-13 {[file size subdirC/f10] == 3}
430 test mv-file-new-directory-14 {[read_file subdirC/f10] eq "f10"}
431 test mv-file-new-directory-15 {[file size subdirC/f11] == 3}
432 test mv-file-new-directory-16 {[read_file subdirC/f11] eq "f11"}
433
434 cd $rootDir
435
436 ###############################################################################
437
438 test_cleanup
439
+50 -1
--- test/mv-rm.test
+++ test/mv-rm.test
@@ -46,12 +46,13 @@
4646
write_file [file join $rootDir subdirB f9] "f9"
4747
4848
file mkdir [file join $rootDir subdirC]
4949
write_file [file join $rootDir subdirC f10] "f10"
5050
write_file [file join $rootDir subdirC f11] "f11"
51
+write_file f12 "f12"
5152
52
-fossil add f1 f2 f3 f4 f5 f6 f7 f8 subdirB/f9 subdirC/f10 subdirC/f11
53
+fossil add f1 f2 f3 f4 f5 f6 f7 f8 subdirB/f9 subdirC/f10 subdirC/f11 f12
5354
fossil commit -m "c1"
5455
5556
########################################
5657
# Test 1: Soft Move Relative Directory #
5758
########################################
@@ -380,10 +381,58 @@
380381
fossil revert
381382
test rm-hard-absolute-6 {
382383
[normalize_result] eq "REVERT f8${undoMsg}"
383384
}
384385
386
+cd $rootDir
387
+
388
+#######################################
389
+# Test 17: Move File to New Directory #
390
+#######################################
391
+
392
+fossil mv --hard f12 d2/f13
393
+test mv-file-new-directory-1 {
394
+ [normalize_result] eq "RENAME f12 d2/f13\nMOVED_FILE ${rootDir}/f12"
395
+}
396
+
397
+test mv-file-new-directory-2 {[file size d2/f13] == 3}
398
+test mv-file-new-directory-3 {[read_file d2/f13] eq "f12"}
399
+
400
+fossil revert
401
+test mv-file-new-directory-4 {
402
+ [normalize_result] eq "DELETE d2/f13\nREVERT f12${undoMsg}"
403
+}
404
+
405
+test mv-file-new-directory-5 {[file size f12] == 3}
406
+test mv-file-new-directory-6 {[read_file f12] eq "f12"}
407
+
408
+cd $rootDir
409
+
410
+############################################
411
+# Test 18: Move Directory to New Directory #
412
+############################################
413
+
414
+fossil mv --hard subdirC subdirD
415
+test mv-file-new-directory-7 {
416
+ [normalize_result] eq "RENAME subdirC subdirD\nMOVED_FILE ${rootDir}/subdirC"
417
+}
418
+
419
+test mv-file-new-directory-8 {[file size subdirD/f10] == 3}
420
+test mv-file-new-directory-9 {[read_file subdirD/f10] eq "f10"}
421
+test mv-file-new-directory-10 {[file size subdirD/f11] == 3}
422
+test mv-file-new-directory-11 {[read_file subdirD/f11] eq "f11"}
423
+
424
+fossil revert
425
+test mv-file-new-directory-12 {
426
+ [normalize_result] eq "REVERT subdirC/f10\nREVERT subdirC/f11${undoMsg}"
427
+}
428
+
429
+test mv-file-new-directory-13 {[file size subdirC/f10] == 3}
430
+test mv-file-new-directory-14 {[read_file subdirC/f10] eq "f10"}
431
+test mv-file-new-directory-15 {[file size subdirC/f11] == 3}
432
+test mv-file-new-directory-16 {[read_file subdirC/f11] eq "f11"}
433
+
385434
cd $rootDir
386435
387436
###############################################################################
388437
389438
test_cleanup
390439
--- test/mv-rm.test
+++ test/mv-rm.test
@@ -46,12 +46,13 @@
46 write_file [file join $rootDir subdirB f9] "f9"
47
48 file mkdir [file join $rootDir subdirC]
49 write_file [file join $rootDir subdirC f10] "f10"
50 write_file [file join $rootDir subdirC f11] "f11"
 
51
52 fossil add f1 f2 f3 f4 f5 f6 f7 f8 subdirB/f9 subdirC/f10 subdirC/f11
53 fossil commit -m "c1"
54
55 ########################################
56 # Test 1: Soft Move Relative Directory #
57 ########################################
@@ -380,10 +381,58 @@
380 fossil revert
381 test rm-hard-absolute-6 {
382 [normalize_result] eq "REVERT f8${undoMsg}"
383 }
384
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
385 cd $rootDir
386
387 ###############################################################################
388
389 test_cleanup
390
--- test/mv-rm.test
+++ test/mv-rm.test
@@ -46,12 +46,13 @@
46 write_file [file join $rootDir subdirB f9] "f9"
47
48 file mkdir [file join $rootDir subdirC]
49 write_file [file join $rootDir subdirC f10] "f10"
50 write_file [file join $rootDir subdirC f11] "f11"
51 write_file f12 "f12"
52
53 fossil add f1 f2 f3 f4 f5 f6 f7 f8 subdirB/f9 subdirC/f10 subdirC/f11 f12
54 fossil commit -m "c1"
55
56 ########################################
57 # Test 1: Soft Move Relative Directory #
58 ########################################
@@ -380,10 +381,58 @@
381 fossil revert
382 test rm-hard-absolute-6 {
383 [normalize_result] eq "REVERT f8${undoMsg}"
384 }
385
386 cd $rootDir
387
388 #######################################
389 # Test 17: Move File to New Directory #
390 #######################################
391
392 fossil mv --hard f12 d2/f13
393 test mv-file-new-directory-1 {
394 [normalize_result] eq "RENAME f12 d2/f13\nMOVED_FILE ${rootDir}/f12"
395 }
396
397 test mv-file-new-directory-2 {[file size d2/f13] == 3}
398 test mv-file-new-directory-3 {[read_file d2/f13] eq "f12"}
399
400 fossil revert
401 test mv-file-new-directory-4 {
402 [normalize_result] eq "DELETE d2/f13\nREVERT f12${undoMsg}"
403 }
404
405 test mv-file-new-directory-5 {[file size f12] == 3}
406 test mv-file-new-directory-6 {[read_file f12] eq "f12"}
407
408 cd $rootDir
409
410 ############################################
411 # Test 18: Move Directory to New Directory #
412 ############################################
413
414 fossil mv --hard subdirC subdirD
415 test mv-file-new-directory-7 {
416 [normalize_result] eq "RENAME subdirC subdirD\nMOVED_FILE ${rootDir}/subdirC"
417 }
418
419 test mv-file-new-directory-8 {[file size subdirD/f10] == 3}
420 test mv-file-new-directory-9 {[read_file subdirD/f10] eq "f10"}
421 test mv-file-new-directory-10 {[file size subdirD/f11] == 3}
422 test mv-file-new-directory-11 {[read_file subdirD/f11] eq "f11"}
423
424 fossil revert
425 test mv-file-new-directory-12 {
426 [normalize_result] eq "REVERT subdirC/f10\nREVERT subdirC/f11${undoMsg}"
427 }
428
429 test mv-file-new-directory-13 {[file size subdirC/f10] == 3}
430 test mv-file-new-directory-14 {[read_file subdirC/f10] eq "f10"}
431 test mv-file-new-directory-15 {[file size subdirC/f11] == 3}
432 test mv-file-new-directory-16 {[read_file subdirC/f11] eq "f11"}
433
434 cd $rootDir
435
436 ###############################################################################
437
438 test_cleanup
439

Keyboard Shortcuts

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