R – how to detect use of Perforce’s “reopen for edit” from a script

perforcescripting

I'm working on a script to interact with Perforce, which among other things needs to be able to understand pending changelists. For this I use 'p4 describe' and 'p4 opened', which are pretty straightforward. For instance, a file opened for edit shows up like this (from p4 opened):

//source/stuff/things.h#1 add default change (text)

What I can't seem to figure out is how to detect cases where a user has branched a file and then used the 'Reopen for edit' command on that file (which amounts to using 'p4 edit' on the file to be branched) prior to submitting it. Same thing goes for integrating a file and then using 'Reopen for edit' before submitting the integration. In the branch case, the file shows up as an 'add' with no indication that there's also a branch going on (so the above example could be either a true add or a reopened branch). In the integrate case it, shows up as an 'edit'. In both cases, after I submit the change I can see that the file was branched/integrated, but I need to be able to do this for pending changes. In theory I would hope to see something like this, where things.h is being branched and edited from thangs.h:

//source/stuff/things.h#1 add default change (text)
  branch from //source/other/thangs.h#42

Does anybody know of a way to accomplish this? I'll also mention that I'm running an old-ish version of Perforce (from 2004), so perhaps it's doable in newer versions and I just need to update my software.

Best Answer

I do not think that this is possible when issuing a "reopen for edit". As you have already indicated, the reopen command will change a files status to something different. I ran a local test (I'm running 2008.2). There do seem to be some changes in the way that perforce reports on the add/edit status of files since your version, but what you are trying to do still doesn't seem possible

d:\sandbox\ctg_test>p4 integ test.txt test_branch.txt
//ctg_test/test_branch.txt#1 - branch/sync from //ctg_test/Test.txt#1,#15

d:\sandbox\ctg_test>p4 opened
//ctg_test/test_branch.txt#1 - branch default change (text)

Note that the opened command now shows 'branch' for the file status instead of add which I think it might have shown with your version of the server. But the kicker:

d:\sandbox\ctg_test>p4 edit test_branch.txt
//ctg_test/test_branch.txt#1 - reopened for add

d:\sandbox\ctg_test>p4 opened
//ctg_test/test_branch.txt#1 - add default change (text)

I tried looking with the -ztag option to see if more info was given:

d:\sandbox\ctg_test>p4 -ztag opened
... depotFile //ctg_test/test_branch.txt
... clientFile //client-mark.allender/ctg_test/test_branch.txt
... rev 1
... action add
... change default
... type text
... user mark.allender
... client client-mark.allender

p4 fstat was no help either.