Determining the last changelist synced to in Perforce

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

提交回复
热议问题