Determining the last changelist synced to in Perforce

后端 未结 10 1762
执念已碎
执念已碎 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:27

    For a serious build (one that is being prepared for testing), explicitly specify the desired label or changelist number, sync to label, and imbed it in build artifacts.

    If a changelist (or label) is not given, use p4 counter change to get the current change number, and record it. But you still need to sync everything using that change number.

    I don't think you can achieve exactly what you want, because in general, an entire workspace isn't synced to a particular changelist number. One can explicitly sync some files to older revisions, and then a single changelist number is meaningless. That's why a fresh sync is required to ensure that a single changelist number accurately represents the code version.


    Regarding the comments: Yes, my answer is intended for use by configuration managers preparing a build to give to QA. Our developers don't normally sync as part of a build; they do a build prior to submitting—so that they can make sure their changes don't break the build or tests. In that context, we don't bother to embed a repository label.

    With your approach, you are making the assumption that your whole workspace was synced to head at the time of your last changelist submission, and that changelist included all of your open files. It's too easy to be mistaken in those assumptions, hard to detect, and horribly expensive in terms of lost time. On the other hand, solving the problem is easy, with no drawbacks. And because a changelist number can be explicitly specified, it doesn't matter what revision you need or how quickly the codebase is changing.

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

    You may try finding the maximum change number in the output of the "p4 files" command. The working directory should not contain post-sync commits, though. This is just a tad better than

    p4 changes -m1 "./...#have"
    

    as the latter seems to run on the server and may fail on big source trees due to "MaxResults" limits.

    $ p4 changes -m1 "./...#have"
    Request too large (over 850000); see 'p4 help maxresults'.
    
    $ p4 -G files "./...#have" | python c:/cygwin/usr/local/bin/p4lastchange.py
    Files: 266948
    2427657
    

    where p4lastchange.py is based on the code from the Using P4G.py From the Command Line presentation by J.T.Goldstone, Kodak Information Network/Ofoto, April 15, 2005.

    #! /usr/bin/env python
    import sys, os, marshal
    
    if os.name == "nt":
        # Disable newline translation in Windows.  Other operating systems do not
        # translate file contents.
        import msvcrt
        msvcrt.setmode( sys.stdin.fileno(), os.O_BINARY )
    
    lastcl = 0
    num = 0
    try:
        while 1:
            dict = marshal.load(sys.stdin)
            num = num + 1
            for key in dict.keys():
                # print "%s: %s" % (key,dict[key])
                if key == "change":
                    cl = int(dict[key])
                    if cl > lastcl:
                        lastcl = cl
    except EOFError:
        pass
    print "Files: %s" % num
    print lastcl
    
    0 讨论(0)
  • 2021-01-29 19:35

    I am not sure if you got the answer you needed but I had a similar problem. The goal was to write in our logger the specific version of the project. The problem was that while we are making our own makefile, the overall build system is controlled by our configuration management. This means that all the solutions which say "sync to something then do something" don't really work and I didn't want to manually change the version whenever we commit (a sure source for errors). The solution (which is actually hinted in some of the answers above) is this: in our makefile, I do p4 changes -m1 "./...#have" The result for this is Change change_number on date by user@client 'msg' I simply create the message into a string which is printed by the logger (the change number is the important element but the other is also useful to quickly decide if a certain version contains changes you know you made yourself without going to perforce to check). Hope this helps.

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

    p4 changes -m1 @clientname which is the "recommended" way to do it for my client takes about 10 minutes

    this is what I use:

    p4 cstat ...#have | grep change | awk '$3 > x { x = $3 };END { print x }'
    

    for the same client takes 2.1 seconds

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