Perforce:如何在文件被另一个提交的更改移动时解决挂起的更改

时间:2012-08-17 17:20:59

标签: perforce

上下文:有人在正在开发的大型Perforce软件仓库上进行一些重组工作,并且p4 move的文件在它们仍处于工作状态时进行。其他人都需要保留挂起的更改,但将它们移动到新目录结构中的新位置。

考虑我的待处理更改列表,其中包含各种文件的添加,修改,删除移动。

如果其他用户将所有这些文件中的p4 move提交到子目录中,而我的更改列表仍处于待处理状态,我该如何解决,以便对新位置中的相同文件应用相同的更改?

在其他用户移动文件后,我执行p4 sync将文件放在我工作区的新位置,p4 resolve只是说No file(s) to resolve

我已尝试为我的更改中的每个文件执行p4 move path newdir/path,但这不太有效:

  • 我添加的文件被移动到新位置添加。 GOOD。
  • 我编辑过的文件需要使用-f上的p4 move标记(如果没有//depot/newdir/path - is synced; use -f to force move)。行。
  • 我删除的文件无法移动(//depot/path - can't move (already opened for delete))。 BAD
  • 我移动的文件无法再次移动。如果我的待定更改从//depot/path移至//depot/newpath,而另一项更改已移至//depot/path//depot/newdir/path,那么我可以p4 move newpath newdir/newpath接受“移动/添加“部分更改,但我不能p4 move path newdir/path也选择更改的”移动/删除“部分(与上一点相同的错误)。 BAD。

如果裸p4命令不起作用,我将不得不破坏bash-fu来移动文件并将正确的命令粘合在一起。我需要一个自动化解决方案,因为大量用户可能会受到移动影响的大量待定更改,这些都需要尽可能轻松地解决。

我还考虑过调整Working Disconnected From The Perforce Server方法在新位置应用我的更改,但这会丢失“移动”元数据,更重要的是,如果多个人必须这样做,它将无法工作因为如果我进入他们之前,他们必须通过我所做的改变来解决这个问题。

如果您想玩玩具示例,请参阅我的再现测试案例步骤:

# Get p4 client and server, install in path (~/bin for me)
cd ~/bin
wget http://www.perforce.com/downloads/perforce/r12.1/bin.linux26x86/p4
chmod +x p4
wget http://www.perforce.com/downloads/perforce/r12.1/bin.linux26x86/p4d
chmod +x p4d

# Start p4 server in a test area (server dumps files in CWD)
mkdir -p ~/p4test/server
cd ~/p4test/server
p4d&
sleep 3
export P4PORT=localhost:1666
unset P4CONFIG # In case you use elsewhere :)

# Create some default client specs and workspaces for them.
mkdir ../workspace1
cd ../workspace1
export P4CLIENT=client1
p4 client -o | p4 client -i
mkdir ../workspace2
cd ../workspace2
export P4CLIENT=client2
p4 client -o | p4 client -i

# Create files and commit initial depot from client1
cd ../workspace1
export P4CLIENT=client1
for i in 1 2 3 4; do echo "This is file $i" > file$i; done
p4 add file*
p4 submit -d 'Initial files'

# Now make some changes to the files. But do not submit - leave pending.
# Add
echo "New file 0" > file0
p4 add file0
# Edit
p4 edit file1
echo "Edited $(date)" >> file1
# Delete
p4 delete file2
# Move
p4 edit file3
p4 move file3 file3.1

# Pending changelist looks like this:
# p4 opened
#//depot/file0#1 - add default change (text)
#//depot/file1#1 - edit default change (text)
#//depot/file2#1 - delete default change (text)
#//depot/file3#1 - move/delete default change (text)
#//depot/file3.1#1 - move/add default change (text)

# Meanwhile, in client2, another user moves everything to a new dir
cd ../workspace2
export P4CLIENT=client2
p4 sync
p4 edit file*
p4 move ... main/...
p4 submit -d 'Move everything to new "main" directory'

# Now what happens in client1?
cd ../workspace1
export P4CLIENT=client1
p4 sync

# //depot/file4#1 - deleted as /home/day/p4test/workspace1/file4
# //depot/file1#1 - is opened for edit - not changed
# //depot/file2#1 - is opened for delete - not changed
# //depot/file3#1 - is opened for move/delete - not changed
# //depot/file3.1#1 - is opened for move/add - not changed
# //depot/main/file1#1 - added as /home/day/p4test/workspace1/main/file1
# //depot/main/file2#1 - added as /home/day/p4test/workspace1/main/file2
# //depot/main/file3#1 - added as /home/day/p4test/workspace1/main/file3
# //depot/main/file4#1 - added as /home/day/p4test/workspace1/main/file4
# day@office:~/p4test/workspace1$ tree
# .
# ├── file0
# ├── file1
# ├── file3.1
# └── main
#     ├── file1
#     ├── file2
#     ├── file3
#     └── file4
#
# 1 directory, 7 files

# Now ... how to resolve?

1 个答案:

答案 0 :(得分:7)

理论上,您现在应该可以这样做:

p4 move -f ... main/...             # meld your opened files to their renamed files
p4 move -f main/file3.1 main/file3  # meld your renamed file to their renamed file
p4 revert '*'                       # revert your now-spurious pending deletes
p4 move main/file3 main/file3.1     # move their renamed file to the name you wanted
p4 resolve                          # merge their edits with your edits

但是第三次​​'p4 move'似乎有一个错误,它正在删除main / file3.1(fka main / file3)上的挂起解析。

但是,如果按此顺序执行此操作似乎正常:

p4 move -f ... main/...
p4 move -f main/file3.1 main/file3
p4 revert '*'
p4 resolve
p4 move main/file3 main/file3.1