Determining the last changelist synced to in Perforce

后端 未结 10 1761
执念已碎
执念已碎 2021-01-29 18:35

A question that occasionally arises is what is the best way to determine the changelist that you last synced to in Perforce. This is often needed for things like injecting the c

相关标签:
10条回答
  • 2021-01-29 19:18

    I recommend the opposite for automatic build systems: you should first get the latest changelist from the server using:

    p4 changes -s submitted -m1
    

    then sync to that change and record it in the revision info. The reason is as follows. Although Perforce recommends the following to determine the changelist to which the workspace is synced:

    p4 changes -m1 @clientname
    

    they note a few gotchas:

    • This only works if you have not submitted anything from the workspace in question.
    • It is also possible that a client workspace is not synced to any specific changelist.

    and there's an additional gotcha they don't mention:

    • If the highest changelist to which the sync occured strictly deleted files from the workspace, the next-highest changelist will be reported (unless it, too, strictly deleted files).

    If you must sync first and record later, Perforce recommends running the following command to determine if you've been bit by the above gotchas; it should indicate nothing was synced or removed:

    p4 sync -n @changelist_number
    
    0 讨论(0)
  • 2021-01-29 19:18

    You could also use the cstat command:

    p4 help cstat

    cstat -- Dump change/sync status for current client
    
    p4 cstat [files...]
    
    Lists changes that are needed, had or partially synced in the current
    client. The output is returned in tagged format, similar to the fstat
    command.
    
    The fields that cstat displays are:
    
        change   changelist number
        status   'have', 'need' or 'partial'
    
    0 讨论(0)
  • 2021-01-29 19:18

    The best I've found so far is to do your sync to whatever changelist you want to build and then use changes -m1 //...#have to get the current local changelist (revision).

    p4 sync @CHANGELIST_NUM p4 changes -m1 //...#have | awk '{print $2}'

    Gives you the changelist number that you can the use wherever you want. I am currently looking for a simpler way than p4 changes -m1 //...#have.

    0 讨论(0)
  • 2021-01-29 19:20

    If you are using P4V you can do this graphically:

    • In the Dashboard tab (View->Dashboard) choose a folder and you will see a list of changelists that the folder isn't yet updated with. Note the lowest number (in the highest row).
    • Make sure that in the Workspace Tree you have selected the same folder as previously in the Dashboard. Then go to the History tab (View->History) and scroll down to the number noted previously. The number just below that number is the number of your current changelist.
    0 讨论(0)
  • 2021-01-29 19:25

    For the whole depot (not just your workspace/client)

    p4 counter change
    

    does the job, just telling the last changelist.

    0 讨论(0)
  • 2021-01-29 19:27

    Just to answer this myself in keeping with Jeff's suggestion of using Stackoverflow as a place to keep technical snippets....

    From the command line use:

    p4 changes -m1 @<clientname>
    

    And just replace with the name of your client spec. This will produce output of the form:

    Change 12345 on 2008/08/21 by joebloggs@mainline-client '....top line of description...'
    

    Which is easily parsed to extract the changelist number.

    0 讨论(0)
提交回复
热议问题