Perforce resolve 无法正确处理重命名
Posted
技术标签:
【中文标题】Perforce resolve 无法正确处理重命名【英文标题】:Perforce resolve doesn't handle renames correctly 【发布时间】:2021-10-05 16:19:14 【问题描述】:假设我们在仓库中有这些流
main
/ \
A B
所有这些流都有以下文件:
01.txt:01
02.txt:02
我从 A 提交这两个变更列表。
#1:p4 move 01.txt legacy_01.txt
#2:p4 move 02.txt 01.txt
然后我将这些更改列表复制到主目录。 至此,main 的文件和预期的一样。
legacy_01.txt:01
01.txt:02
但是,当我合并到 B 时,问题就出现了。
经过一些自动解析(不管你已经 p4 resolve
然后盲目接受所有,甚至使用 p4v 的安全不合并自动解析),文件变成:
legacy_01.txt:02
(其他文件被删除)
问题更大,因为即使您使用了 p4v 的安全自动解析,它也会发生。 当然,我可以仔细调整解析顺序来防止这种情况,但为什么这是默认值?
【问题讨论】:
【参考方案1】:tl;dr:将文件重命名到彼此的位置,然后压缩生成的更改列表是有问题的。
复制到 main 时出现问题。
C:\Perforce\test\seongchan-test>p4 copy A/... main/...
//stream/main/seongchan-test/main/02.txt#1 - delete from //stream/main/seongchan-test/A/02.txt#1,#2
//stream/main/seongchan-test/main/01.txt#1 - sync/integrate from //stream/main/seongchan-test/A/01.txt#1,#3
//stream/main/seongchan-test/main/legacy_01.txt#1 - branch/sync from //stream/main/seongchan-test/A/legacy_01.txt#1
C:\Perforce\test\seongchan-test>p4 opened
//stream/main/seongchan-test/main/01.txt#1 - integrate default change (text)
//stream/main/seongchan-test/main/02.txt#1 - delete default change (text)
//stream/main/seongchan-test/main/legacy_01.txt#1 - branch default change (text)
C:\Perforce\test\seongchan-test>p4 resolved
c:\Perforce\test\seongchan-test\main\01.txt - copy from //stream/main/seongchan-test/A/01.txt#1,#3
c:\Perforce\test\seongchan-test\main\02.txt - delete from //stream/main/seongchan-test/A/02.txt#1,#2
c:\Perforce\test\seongchan-test\main\legacy_01.txt - branch from //stream/main/seongchan-test/A/legacy_01.txt#1
请注意,没有任何文件是为“移动”打开的——01->legacy_01
和 02->01
操作的顺序(由以特定顺序发生的 move/add
和 move/delete
操作表示)已经由于这两个变更列表的“挤压”而丢失!
这最终会混淆后续的合并/解析;它试图一次完成所有操作,并且它最大的努力是将02->01
和01->legacy_01
组合成02->legacy_01
,考虑到这些操作最初发生的顺序,这实际上并不是您想要的。
有一个 undoc 设置会在 copy
操作期间向您发出警告:
C:\Perforce\test\seongchan-test>p4 configure set dm.copy.movewarn=1
For server 'any', configuration variable 'dm.copy.movewarn' set to '1'
C:\Perforce\test\seongchan-test>p4 copy A/... main/...
//stream/main/seongchan-test/main/02.txt#1 - delete from //stream/main/seongchan-test/A/02.txt#1,#2
//stream/main/seongchan-test/main/01.txt#1 - sync/integrate from //stream/main/seongchan-test/A/01.txt#1,#3
... can't open as move/add because a file already exists in this location.
//stream/main/seongchan-test/main/legacy_01.txt#1 - branch/sync from //stream/main/seongchan-test/A/legacy_01.txt#1
... can't open as move/add because //stream/main/seongchan-test/main/01.txt is not being opened for delete.
Some files couldn't be opened for move. Try copying from @268 instead?
如果我接受错误消息的建议,我最终会分阶段进行复制,每个阶段都会复制move
操作之一:
C:\Perforce\test\seongchan-test>p4 revert ...
//stream/main/seongchan-test/main/legacy_01.txt#none - was branch, deleted
//stream/main/seongchan-test/main/01.txt#1 - was integrate, reverted
//stream/main/seongchan-test/main/02.txt#1 - was delete, reverted
C:\Perforce\test\seongchan-test>p4 copy A/...@268 main/...
//stream/main/seongchan-test/main/01.txt#1 - move/delete from //stream/main/seongchan-test/A/01.txt#1,#2
//stream/main/seongchan-test/main/legacy_01.txt#1 - move/add/sync from //stream/main/seongchan-test/A/legacy_01.txt#1
C:\Perforce\test\seongchan-test>p4 submit -d "copy from A@268"
Submitting change 271.
Locking 2 files ...
move/delete //stream/main/seongchan-test/main/01.txt#2
move/add //stream/main/seongchan-test/main/legacy_01.txt#1
Change 271 submitted.
C:\Perforce\test\seongchan-test>p4 copy A/... main/...
//stream/main/seongchan-test/main/02.txt#1 - move/delete from //stream/main/seongchan-test/A/02.txt#1,#2
//stream/main/seongchan-test/main/01.txt#2 - move/add/sync from //stream/main/seongchan-test/A/01.txt#3
C:\Perforce\test\seongchan-test>p4 submit -d "finish copy from A"
Submitting change 272.
Locking 2 files ...
move/add //stream/main/seongchan-test/main/01.txt#3
move/delete //stream/main/seongchan-test/main/02.txt#2
Change 272 submitted.
现在,当我们合并到 B 时,它会看到这两个动作并尝试解决它们——而不是像 copy
那样尝试“挤压”它们,resolve
会警告你你不能同时做这两个:
c:\Perforce\test\seongchan-test\B\02.txt - resolving move to //stream/main/seongchan-test/B/01.txt
//Samwise-dvcs-1509687817/seongchan-test/B/01.txt - can't move to an existing file
此时的修复与之前类似;您必须一次备份并执行一个更改列表(在两者之间提交)才能成功合并。
C:\Perforce\test\seongchan-test>p4 merge main/...@271 B/...
//stream/main/seongchan-test/B/01.txt#1 - integrate from //stream/main/seongchan-test/main/legacy_01.txt#1 (remapped from //stream/main/seongchan-test/B/legacy_01.txt)
... must resolve content from //stream/main/seongchan-test/main/legacy_01.txt#1
... must resolve move to //stream/main/seongchan-test/B/legacy_01.txt
C:\Perforce\test\seongchan-test>p4 resolve -as
c:\Perforce\test\seongchan-test\B\01.txt - merging //stream/main/seongchan-test/main/legacy_01.txt#1
Diff chunks: 0 yours + 0 theirs + 0 both + 0 conflicting
//Samwise-dvcs-1509687817/seongchan-test/B/01.txt - copy from //stream/main/seongchan-test/main/legacy_01.txt
c:\Perforce\test\seongchan-test\B\01.txt - resolving move to //stream/main/seongchan-test/B/legacy_01.txt
//stream/main/seongchan-test/B/legacy_01.txt - moved from //stream/main/seongchan-test/B/01.txt
C:\Perforce\test\seongchan-test>p4 submit -d "merge from main@271"
Submitting change 273.
Locking 2 files ...
move/delete //stream/main/seongchan-test/B/01.txt#2
move/add //stream/main/seongchan-test/B/legacy_01.txt#1
Change 273 submitted.
C:\Perforce\test\seongchan-test>p4 merge main/... B/...
//stream/main/seongchan-test/B/02.txt#1 - integrate from //stream/main/seongchan-test/main/01.txt#3 (remapped from //stream/main/seongchan-test/B/01.txt)
... must resolve content from //stream/main/seongchan-test/main/01.txt#3
... must resolve move to //stream/main/seongchan-test/B/01.txt
C:\Perforce\test\seongchan-test>p4 resolve -as
c:\Perforce\test\seongchan-test\B\02.txt - merging //stream/main/seongchan-test/main/01.txt#3
Diff chunks: 0 yours + 0 theirs + 0 both + 0 conflicting
//Samwise-dvcs-1509687817/seongchan-test/B/02.txt - copy from //stream/main/seongchan-test/main/01.txt
c:\Perforce\test\seongchan-test\B\02.txt - resolving move to //stream/main/seongchan-test/B/01.txt
//stream/main/seongchan-test/B/01.txt - moved from //stream/main/seongchan-test/B/02.txt
C:\Perforce\test\seongchan-test>p4 submit -d "finish merge from main"
Submitting change 274.
Locking 2 files ...
move/add //stream/main/seongchan-test/B/01.txt#3
move/delete //stream/main/seongchan-test/B/02.txt#2
Change 274 submitted.
与复制一样,我们可以看到现在每个合并操作“重播”源的一个移动操作;它们必须一次发生一个,因为第二次合并需要将文件移动到第一次删除的路径中。
【讨论】:
以上是关于Perforce resolve 无法正确处理重命名的主要内容,如果未能解决你的问题,请参考以下文章
Webpack - resolve-url-loader 无法正确解析路径
正确使用 Promise.resolve().then() 错误:未捕获(在承诺中):TypeError:无法读取属性
Perforce:从 Windows 到 Linux 的交叉迁移无法重放检查点
如何获取待处理的 Perforce 更改列表中所有文件的差异?