views:

232

answers:

2

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.

A: 

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.

Mark
Rats, I was afraid that might be the answer. Hopefully someone else might know of some magic, otherwise I may just be out of luck.
Charlie
+2  A: 

"p4 resolved" does almost exactly what you want, but unfortunately it is new in 2007.2.

[C:\dfp\Common\Code\Python]p4 opened foo.py
//buddha/Common/Code/Python/foo.py#1 - add default change (kxtext)

[C:\dfp\Common\Code\Python]p4 resolved foo.py
c:\dfp\Common\Code\Python\foo.py - branch from //buddha/Common/Code/Python/memdump.py#1,#30

You probably won't be able to detect problems before the user runs "resolve", but they're going to have to resolve before they submit.

Paul Du Bois
Very interesting - thanks for the info. Even if it doesn't work with my older version, hopefully it may help someone else.
Charlie
This is exactly what our scripts do. Files that are open for edit are checked against the output of p4 resolved so if they were branched and from where. I'm not sure there's any better way to do it.
prestomation