Fossil SCM

Retain renames in local checkout when running fossil update.

preben 2024-01-12 16:11 trunk
Commit 7c284a8c62fba14da686d363856a903d0178b4026c77388cd237f133292f9c53
2 files changed +17 -2 +19 -2
+17 -2
--- src/update.c
+++ src/update.c
@@ -272,15 +272,17 @@
272272
" fnt TEXT %s" /* Filename of same file on target version */
273273
");",
274274
filename_collation(), filename_collation()
275275
);
276276
277
- /* Add files found in the current version
277
+ /* Add files found in the current version. If a file is renamed locally,
278
+ ** use origname to compare with the original pathname in the target.
278279
*/
279280
db_multi_exec(
280281
"INSERT OR IGNORE INTO fv(fn,fnt,idv,idt,ridv,ridt,isexe,chnged,deleted)"
281
- " SELECT pathname, pathname, id, 0, rid, 0, isexe, chnged, deleted"
282
+ " SELECT pathname, COALESCE(origname,pathname), id, 0, rid, 0,"
283
+ " isexe, chnged, deleted"
282284
" FROM vfile WHERE vid=%d",
283285
vid
284286
);
285287
286288
/* Compute file name changes on V->T. Record name changes in files that
@@ -628,10 +630,23 @@
628630
"SELECT rmdir(%Q||name) FROM dir_to_delete"
629631
" WHERE (%Q||name)<>%Q ORDER BY name DESC",
630632
g.zLocalRoot, g.zLocalRoot, zPwd
631633
);
632634
fossil_free(zPwd);
635
+ /* Before deleting the old vid, transfer renames from the current vid. */
636
+ db_multi_exec(
637
+ "WITH mv AS ("
638
+ " SELECT pathname AS path, origname AS orig"
639
+ " FROM vfile"
640
+ " WHERE vid=%i AND origname IS NOT NULL AND pathname!=origname"
641
+ ")"
642
+ " UPDATE vfile"
643
+ " SET pathname=path, origname=orig"
644
+ " FROM mv"
645
+ " WHERE vid=%i AND pathname=orig",
646
+ vid, tid
647
+ );
633648
if( g.argc<=3 ){
634649
/* All files updated. Shift the current check-out to the target. */
635650
db_multi_exec("DELETE FROM vfile WHERE vid!=%d", tid);
636651
checkout_set_all_exe(tid);
637652
manifest_to_disk(tid);
638653
--- src/update.c
+++ src/update.c
@@ -272,15 +272,17 @@
272 " fnt TEXT %s" /* Filename of same file on target version */
273 ");",
274 filename_collation(), filename_collation()
275 );
276
277 /* Add files found in the current version
 
278 */
279 db_multi_exec(
280 "INSERT OR IGNORE INTO fv(fn,fnt,idv,idt,ridv,ridt,isexe,chnged,deleted)"
281 " SELECT pathname, pathname, id, 0, rid, 0, isexe, chnged, deleted"
 
282 " FROM vfile WHERE vid=%d",
283 vid
284 );
285
286 /* Compute file name changes on V->T. Record name changes in files that
@@ -628,10 +630,23 @@
628 "SELECT rmdir(%Q||name) FROM dir_to_delete"
629 " WHERE (%Q||name)<>%Q ORDER BY name DESC",
630 g.zLocalRoot, g.zLocalRoot, zPwd
631 );
632 fossil_free(zPwd);
 
 
 
 
 
 
 
 
 
 
 
 
 
633 if( g.argc<=3 ){
634 /* All files updated. Shift the current check-out to the target. */
635 db_multi_exec("DELETE FROM vfile WHERE vid!=%d", tid);
636 checkout_set_all_exe(tid);
637 manifest_to_disk(tid);
638
--- src/update.c
+++ src/update.c
@@ -272,15 +272,17 @@
272 " fnt TEXT %s" /* Filename of same file on target version */
273 ");",
274 filename_collation(), filename_collation()
275 );
276
277 /* Add files found in the current version. If a file is renamed locally,
278 ** use origname to compare with the original pathname in the target.
279 */
280 db_multi_exec(
281 "INSERT OR IGNORE INTO fv(fn,fnt,idv,idt,ridv,ridt,isexe,chnged,deleted)"
282 " SELECT pathname, COALESCE(origname,pathname), id, 0, rid, 0,"
283 " isexe, chnged, deleted"
284 " FROM vfile WHERE vid=%d",
285 vid
286 );
287
288 /* Compute file name changes on V->T. Record name changes in files that
@@ -628,10 +630,23 @@
630 "SELECT rmdir(%Q||name) FROM dir_to_delete"
631 " WHERE (%Q||name)<>%Q ORDER BY name DESC",
632 g.zLocalRoot, g.zLocalRoot, zPwd
633 );
634 fossil_free(zPwd);
635 /* Before deleting the old vid, transfer renames from the current vid. */
636 db_multi_exec(
637 "WITH mv AS ("
638 " SELECT pathname AS path, origname AS orig"
639 " FROM vfile"
640 " WHERE vid=%i AND origname IS NOT NULL AND pathname!=origname"
641 ")"
642 " UPDATE vfile"
643 " SET pathname=path, origname=orig"
644 " FROM mv"
645 " WHERE vid=%i AND pathname=orig",
646 vid, tid
647 );
648 if( g.argc<=3 ){
649 /* All files updated. Shift the current check-out to the target. */
650 db_multi_exec("DELETE FROM vfile WHERE vid!=%d", tid);
651 checkout_set_all_exe(tid);
652 manifest_to_disk(tid);
653
+19 -2
--- test/update.test
+++ test/update.test
@@ -24,10 +24,11 @@
2424
2525
proc test_update_setup {desc} {
2626
global UPDATE_TEST
2727
incr UPDATE_TEST
2828
fossil revert
29
+ fossil clean
2930
fossil update
3031
return [format "test-%02u-%s.txt" $UPDATE_TEST $desc]
3132
}
3233
3334
# The output is in file name order, so massage $RESULT to remove initial UNCHANGED
@@ -38,11 +39,11 @@
3839
regsub {^(?:UNCHANGED [-a-z0-9.]+\n)*} $test_result {} test_result
3940
} else {
4041
set test_result $::RESULT
4142
}
4243
test "update-message-$testname" {$message == $test_result}
43
- fossil changes
44
+ fossil changes --differ
4445
test "update-changes-$testname" {$changes == $::RESULT}
4546
}
4647
4748
# Use a sequence number for file content that is not important for the test.
4849
set UPDATE_SEQ_NO 0
@@ -88,11 +89,11 @@
8889
test_update $testname $message $changes -expectError
8990
9091
set testname "add-overwrites"
9192
set fname [test_update_setup $testname]
9293
set message "ADD $fname - overwrites an unmanaged file, original copy backed up locally"
93
-set changes ""
94
+set changes "EXTRA $fname-original"
9495
write_seq_to_file $fname
9596
fossil add $fname
9697
fossil commit -m "Add $fname"
9798
fossil up previous
9899
write_seq_to_file $fname
@@ -182,10 +183,26 @@
182183
fossil mv --hard $fname "$fname.renamed"
183184
fossil commit -m "Update and rename $fname"
184185
fossil up previous
185186
write_file $fname "center\nbelow\n"
186187
test_update $testname $message $changes
188
+
189
+# Rename in current checkout with extra files in target.
190
+# Based on https://fossil-scm.org/forum/forumpost/2753239f00
191
+set testname "merge-renamed-current"
192
+set fname [test_update_setup $testname]
193
+set warning "UPDATE $fname.extra\nUNCHANGED $fname.renamed"
194
+set changes "RENAMED $fname -> $fname.renamed"
195
+write_seq_to_file $fname
196
+write_seq_to_file "$fname.extra"
197
+fossil add $fname "$fname.extra"
198
+fossil commit -m "Add $fname and $fname.extra"
199
+write_seq_to_file "$fname.extra"
200
+fossil commit -m "Update $fname.extra"
201
+fossil up previous
202
+fossil mv --hard $fname "$fname.renamed"
203
+test_update $testname $warning $changes
187204
188205
set testname "merge-standard"
189206
set fname [test_update_setup $testname]
190207
set message "MERGE $fname"
191208
set changes "EDITED $fname"
192209
--- test/update.test
+++ test/update.test
@@ -24,10 +24,11 @@
24
25 proc test_update_setup {desc} {
26 global UPDATE_TEST
27 incr UPDATE_TEST
28 fossil revert
 
29 fossil update
30 return [format "test-%02u-%s.txt" $UPDATE_TEST $desc]
31 }
32
33 # The output is in file name order, so massage $RESULT to remove initial UNCHANGED
@@ -38,11 +39,11 @@
38 regsub {^(?:UNCHANGED [-a-z0-9.]+\n)*} $test_result {} test_result
39 } else {
40 set test_result $::RESULT
41 }
42 test "update-message-$testname" {$message == $test_result}
43 fossil changes
44 test "update-changes-$testname" {$changes == $::RESULT}
45 }
46
47 # Use a sequence number for file content that is not important for the test.
48 set UPDATE_SEQ_NO 0
@@ -88,11 +89,11 @@
88 test_update $testname $message $changes -expectError
89
90 set testname "add-overwrites"
91 set fname [test_update_setup $testname]
92 set message "ADD $fname - overwrites an unmanaged file, original copy backed up locally"
93 set changes ""
94 write_seq_to_file $fname
95 fossil add $fname
96 fossil commit -m "Add $fname"
97 fossil up previous
98 write_seq_to_file $fname
@@ -182,10 +183,26 @@
182 fossil mv --hard $fname "$fname.renamed"
183 fossil commit -m "Update and rename $fname"
184 fossil up previous
185 write_file $fname "center\nbelow\n"
186 test_update $testname $message $changes
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
188 set testname "merge-standard"
189 set fname [test_update_setup $testname]
190 set message "MERGE $fname"
191 set changes "EDITED $fname"
192
--- test/update.test
+++ test/update.test
@@ -24,10 +24,11 @@
24
25 proc test_update_setup {desc} {
26 global UPDATE_TEST
27 incr UPDATE_TEST
28 fossil revert
29 fossil clean
30 fossil update
31 return [format "test-%02u-%s.txt" $UPDATE_TEST $desc]
32 }
33
34 # The output is in file name order, so massage $RESULT to remove initial UNCHANGED
@@ -38,11 +39,11 @@
39 regsub {^(?:UNCHANGED [-a-z0-9.]+\n)*} $test_result {} test_result
40 } else {
41 set test_result $::RESULT
42 }
43 test "update-message-$testname" {$message == $test_result}
44 fossil changes --differ
45 test "update-changes-$testname" {$changes == $::RESULT}
46 }
47
48 # Use a sequence number for file content that is not important for the test.
49 set UPDATE_SEQ_NO 0
@@ -88,11 +89,11 @@
89 test_update $testname $message $changes -expectError
90
91 set testname "add-overwrites"
92 set fname [test_update_setup $testname]
93 set message "ADD $fname - overwrites an unmanaged file, original copy backed up locally"
94 set changes "EXTRA $fname-original"
95 write_seq_to_file $fname
96 fossil add $fname
97 fossil commit -m "Add $fname"
98 fossil up previous
99 write_seq_to_file $fname
@@ -182,10 +183,26 @@
183 fossil mv --hard $fname "$fname.renamed"
184 fossil commit -m "Update and rename $fname"
185 fossil up previous
186 write_file $fname "center\nbelow\n"
187 test_update $testname $message $changes
188
189 # Rename in current checkout with extra files in target.
190 # Based on https://fossil-scm.org/forum/forumpost/2753239f00
191 set testname "merge-renamed-current"
192 set fname [test_update_setup $testname]
193 set warning "UPDATE $fname.extra\nUNCHANGED $fname.renamed"
194 set changes "RENAMED $fname -> $fname.renamed"
195 write_seq_to_file $fname
196 write_seq_to_file "$fname.extra"
197 fossil add $fname "$fname.extra"
198 fossil commit -m "Add $fname and $fname.extra"
199 write_seq_to_file "$fname.extra"
200 fossil commit -m "Update $fname.extra"
201 fossil up previous
202 fossil mv --hard $fname "$fname.renamed"
203 test_update $testname $warning $changes
204
205 set testname "merge-standard"
206 set fname [test_update_setup $testname]
207 set message "MERGE $fname"
208 set changes "EDITED $fname"
209

Keyboard Shortcuts

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