开发者

Currently checked out version of a directory/file in perforce

I'm trying to automate some builds for a project kept in perforce. I'd like to extract the current changelist number as a way of tagging the build version.

This command:

p4 changes -s submitted  ...  | head -1

goes very close to doing what I need, except in the case where I don't have the latest version checked out from perforce. The above command (appears to) display all the changelists, not just the ones in my check out.

Is there a way to get the change开发者_运维问答list number of the most recently synced-to changelist?

Note: I come from more of a CVS / git background so my terminology may be off.


Try running 'p4 cstat ...'. That'll tell you, for every changelist that affects the set of files in '...', whether you have that changelist, need it, or have it partially synced.


I agree with the "p4 cstat" approach.

I use it like: p4 cstat| p4-version.awk which is the following script:

 #! /usr/bin/awk -f

 # The input format is:
 # ... change 654056
 # ... status have|need|partial


 # So what we do:
 # find the first "need" or "partial"

 # and we might add +N as the number of other changes we have

 # Major is never 0. Hence End is set only once, to a non-zero.

 # Note: it's assumed that 0 is not a valid P4 changelist.
 # so  0+1-1 means: no entire changelist (i.e. the initial one)
 # has been (entirely) synced.

 # major is the last p4 CL processed
 # end   is the last CL, up to which _fully_ synced.
 # plus/minus  additional/missing CLs.

 BEGIN {end=0; contiguous=1; plus=0; minus=0}

 /^... change ([0-9])+/ {
         change=$3;
 };


 # we have 2 states: 1/ until now all have -- contiguous=1
 #                   2/ already something not "have"

 # (end=0) state 1

 /^... status have/ {
         if (!contiguous)
                  plus++;
         else
           end=change;
 };


 /^... status (partial|need)/ {
         minus++;
         if (contiguous) {
                 contiguous = 0;
         };
 }


 END {
         if (!contiguous)
                 printf "%d+%d-%d\n", end, plus, minus;
         else
                 printf "%d\n", end;
 }


Though I am not sure if it is applicable for this question I want to show a solution that lets you get the latest changelist up to the one you have synced without gaps (i.e. you can have synced new changelists on your client leaving out some older ones, for example if you have submitted changes yourself without previously syncing a few changes that were submitted by other people).

With the following command you list all changes not synced to your client:

p4 changes ..."#>have" 

If you extract the last changelist of that list and subtract 1 you get the changelist number up to which you have synced everything without gaps:

echo $((`p4 changes ..."#>have" | tail -1 | awk '{print $2}'`-1))


To find the latest changelist on your client, use this command:

p4 changes -m 1 @name_of_your_client_here

Client names can act like labels.


I think that the following will do what you want:

p4 fstat -T headChange ... | cut -d' ' -f3 | sort -nr | head -1

p4 fstat is really nice in that it takes not only a filter (via the -F option) but a field selection parameter (using the -T option).


What you want is the 'haveRev' of your file:

rev = `p4 fstat -T haveRev <filename>|cut -d' ' -f3`

and then you can look up the changenumber like so:

p4 filelog <filename>|grep $rev|cut -d' ' -f4

Note that I used a specific file of the checked out tree.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜