3490: rbt post with Perforce fails when a file has been renamed twice

sam***@samdem******* (Google Code) (Is this you? Claim this profile.)
What version are you running?
RBTools 0.6.2

What's the URL of the page containing the problem?
N/A

What steps will reproduce the problem?
1. In any Perforce repository, create a file named TestHistory.txt and submit it, creating changelist A.
2. Rename the file to TestHistory2.txt and submit the change, creating changelist B.
3. Rename the file to TestHistory3.txt and submit the change, creating changelist C.
4. Run rbt post <changelist C>

What is the expected output? What do you see instead?
- The expected output is: 
Generating diff for range of submitted changes: <changelist B> to <changelist C>
Review request #XY posted. 
[...]

- Instead, the output is:
Generating diff for range of submitted changes: <changelist B> to <changelist C>
CRITICAL: 'file1,0'

- If I enable debugging: rbt post -d <changelist C>, the output is:
>>> RBTools 0.6.2
>>> Python 2.7.5 (default, Aug 25 2013, 00:04:04) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)]
>>> Running on Darwin-13.1.0-x86_64-i386-64bit
>>> Home = /Users/samuel
>>> Current directory = /Users/samuel/Perforce/Samuel_samuels-mbp_PerforceTest_7554
>>> Checking for a Subversion repository...
>>> Running: svn info --non-interactive
>>> Command exited with rc 1: ['svn', 'info', '--non-interactive']
svn: E155007: '/Users/samuel/Perforce/Samuel_samuels-mbp_PerforceTest_7554' is not a working copy
---
>>> Checking for a Git repository...
>>> Running: git rev-parse --git-dir
>>> Command exited with rc 128: ['git', 'rev-parse', '--git-dir']
fatal: Not a git repository (or any of the parent directories): .git
---
>>> Checking for a Mercurial repository...
>>> Unable to execute "hg --help": skipping Mercurial
>>> Checking for a CVS repository...
>>> Unable to execute "cvs": skipping CVS
>>> Checking for a Perforce repository...
>>> Running: p4 info
>>> Running: diff --version
>>> repository info: Path: centauri:1666, Base path: None, Supports changesets: True
>>> Making HTTP GET request to http://192.168.1.201/reviewboard/api/
Generating diff for range of submitted changes: 3310 to 3311
Traceback (most recent call last):
  File "/usr/local/bin/rbt", line 8, in <module>
    load_entry_point('RBTools==0.6.2', 'console_scripts', 'rbt')()
  File "/Library/Python/2.7/site-packages/RBTools-0.6.2-py2.7.egg/rbtools/commands/main.py", line 134, in main
    command.run_from_argv([RB_MAIN, command_name] + args)
  File "/Library/Python/2.7/site-packages/RBTools-0.6.2-py2.7.egg/rbtools/commands/__init__.py", line 416, in run_from_argv
    exit_code = self.main(*args) or 0
  File "/Library/Python/2.7/site-packages/RBTools-0.6.2-py2.7.egg/rbtools/commands/post.py", line 738, in main
    extra_args=extra_args)
  File "/Library/Python/2.7/site-packages/RBTools-0.6.2-py2.7.egg/rbtools/clients/perforce.py", line 460, in diff
    base, tip, depot_include_files, local_include_files)
  File "/Library/Python/2.7/site-packages/RBTools-0.6.2-py2.7.egg/rbtools/clients/perforce.py", line 672, in _compute_range_changes
    change['newFilename'] = file_entry['file1,%d' % cid]
KeyError: 'file1,0'

What operating system are you using? What browser?
 - Mac OS X 10.9.2
 - Python 2.7.5
 - P4 Rev. P4/MACOSX105X86_64/2014.1/821990 (2014/04/08)

Please provide any additional information below.

In the logs we can see that the key "file1,0" is absent from the file entry returned by p4. If I edit perforce.py to print the contents of file_entry just before the exception is raised, I get this:
{'code': 'stat', 'desc0': 'Rename TestHistory2.txt. ', 'user0': 'Samuel', 'client0': 'Samuel_samuels-mbp_PerforceTest_7554', 'time0': '1406067096', 'action0': 'move/delete', 'depotFile': '//[...]/PerforceTest/TestHistory2.txt', 'rev0': '2', 'type0': 'text', 'change0': '3311'}
#1 mgulick
I have run across this issue as well.  I believe the issue is that the 'move/delete' record doesn't have the 'moved into' field.  You need to use the file log of the previous revision to find the 'moved into' field.

i.e.
p4 filelog //depot/path/to/originalfile.txt#2
//depot/path/to/originalfile.txt
... #2 change 1235 move/delete on 2014/11/04 by user@client (text) 'rename file'
... #1 change 1234 add on 2014/10/30 by user@client (text) 'create file'
... ... moved into //depot/path/to/renamedfile.txt#1

Note that the 'moved into' record is associated with the previous revision of the file, because that is the revision that was moved (if you were to 'p4 print //depot/path/to/originalfile.txt#2' you would get an empty file)
david
#2 david
  • -reviewboard
    +rbtools