[p4] Can you find out which changelist your workspace has been synced to?

Bill Mauer bmauer at aspyr.com
Tue Jan 29 14:07:58 PST 2008


Good point.  Here is an example .awk file which will parse out
changelists from files at the head revision.  Once major assumption is
that at least one file is at the head revision.  Let's say this is
called p4_max_changelist.awk:

-------------------------------------------
BEGIN { x = 0; headRev = 0; haveRev = 0; headChange = 0; }
{
	if ( $2 == "headRev" )  headRev = $3;
	else if ( $2 == "headChange" ) headChange = $3;
	else if ( $2 == "haveRev" && $3 == headRev && headChange > x ) x
= headChange;
}
END { print "//workspace/...@"x }
--------------------------------

It could be done in perl or python just as well, I'm just in an awk
frame of mind.  In any case, you could then do the following to get what
the OP was looking for (again, one line):

p4 fstat -Rh //workspace/... | awk -f p4_max_changelist.awk | xargs p4
sync -n

That would give the actual result, but would fail if none of the files
were at the head revision.  I'm sure it could be modified to work in all
cases. Yes, you could also inline the above and wrap in single quotes to
replace the "-f p4_max_changelist.awk".  Again, it will give a list of
files if there are files not conforming to the highest changelist for a
file at the head revision, in which case they should be synced.

Bill Mauer
Lead Software Engineer
Aspyr Media
 
bmauer at aspyr.com
512-879-5936

-----Original Message-----
From: Jeff A. Bowles [mailto:jab at pobox.com] 
Sent: Tuesday, January 29, 2008 3:15 PM
To: Bill Mauer
Cc: Perforce Users
Subject: Re: [p4] Can you find out which changelist your workspace has
been synced to?

That's a very nifty way to do it. Thanks for the idea!

Also, I'll point out that "p4 fstat //myworkspace/..." is another  
command to exploit. It is especially fruitful at times. (E.g., the  
headache, "show files I need to open for add," becomes really easy if  
you have this 'fstat' command in your arsenal.)

    -Jeff Bowles

On Jan 29, 2008, at 8:07 AM, Bill Mauer wrote:

>
> Both of these posts point out why you may not be able to find a single
> changelist number.  Steve's answer is the best as it gives you the two
> outside changelists.  You can use that as a Boolean as to whether  
> all of
> the files in the workspace are synced to the same changelist, which  
> will
> then tell you the answer you are looking for:
>
> p4 changes -m 1 //myworkspace/... | awk '{print "// 
> myworkspace/...@"$2}'
> | xargs p4 sync -n
>
> The above is all one line.  If it says "file(s) up-to-date" after the
> changelist then you have your answer.  If it tells you it would update
> files, then you have syncs to various changelists within the workspace
> and that should be corrected if you need an answer.
>
> Bill Mauer
> Lead Software Engineer
> Aspyr Media
>
> bmauer at aspyr.com
> 512-879-5936
>
> -----Original Message-----
> From: perforce-user-bounces at perforce.com
> [mailto:perforce-user-bounces at perforce.com] On Behalf Of Stephen Vance
> Sent: Monday, January 28, 2008 5:31 PM
> To: Yamuna Ramasubramaniyan
> Cc: perforce-user at perforce.com
> Subject: Re: [p4] Can you find out which changelist your workspace has
> been synced to?
>
> p4 changes -m 1 //myworkspace/...
>
> will tell you the highest changelist number that had contributed to  
> your
>
> workspace.
>
> p4 sync -n @12345
>
> will tell you whether everything up to and including that changelist
> that is mapped into your workspace has been synced.
>
> Ignoring the possibility that there are things in that changelist that
> aren't mapped to your workspace, these represent the necessary and
> sufficient conditions for your workspace being at that change level.
>
> Steve
>
> Yamuna Ramasubramaniyan wrote:
>> Hello,
>>
>>
>>
>> I'd like to find out what changelist my workspace has been synced to.
>> P4 sync -n shows me which files would be updated if I were to do a
> sync,
>> but I'd like to find out which changelist I last synced to.  I recall
>> this could be done in svn.  Is this possible in P4?
>>
>>
>>
>> TIA for your help,
>>
>> Yamuna
>>
>> _______________________________________________
>> perforce-user mailing list  -  perforce-user at perforce.com
>> http://maillist.perforce.com/mailman/listinfo/perforce-user
>>
>>
>
> -- 
> Stephen Vance
> www.vance.com
> _______________________________________________
> perforce-user mailing list  -  perforce-user at perforce.com
> http://maillist.perforce.com/mailman/listinfo/perforce-user
>
> _______________________________________________
> perforce-user mailing list  -  perforce-user at perforce.com
> http://maillist.perforce.com/mailman/listinfo/perforce-user



More information about the perforce-user mailing list