Search code examples
perforceshelveunshelve

How do I checkout a perforce shelf at the changelist it was shelved at?


I have a perforce shelf that's CL 1000. It was shelved by someone else at some unknown CL X.

I'm at CL 2000. I'd like to sync to whatever X is and unshelf 1000 so my code is exactly the same as when it was shelved. How do I do this?


Solution

  • Unfortunately, there's no guarantee that their entire client workspace was synced to just one changelist when they shelved. In the extreme case, they could have synced each file at a different change number.

    That said, they were probably synced to one point in time, and you can extrapolate this from the revision numbers of the files in their shelf.

    $ p4 files @=1000
    //depot/foo/bar.txt#3 - edit change 1000 (text)
    //depot/baz/quux.c#5 - edit change 1000 (text)
    

    The revision numbers after the filenames indicate the revision of each shelved file that the user synced before opening them for edit.

    Then, you can run p4 files with each of the file paths and revisions to get change numbers:

    $ p4 files //depot/foo/bar.txt#3 //depot/baz/quux.c#5
    //depot/foo/bar.txt#3 - edit change 983 (text)
    //depot/baz/quux.c#5 - edit change 998 (text)
    

    Pick the largest of the change numbers from the second command, and try syncing your client to that.

    Caveats to the above

    Even if we assume they synced to a single point in time, the above isn't foolproof. It only tells us they synced to a change after or including 998 and before 1000.

    Let's say they synced to change 999. Their client workspace might have looked like this:

    $ p4 have
    //depot/an/otherfile#7 - /home/user/a/an/otherfile
    //depot/foo/bar.txt#3 - /home/user/a/foo/bar.txt
    //depot/baz/quux.c#5 - /home/user/a/baz/quux.c
    

    Let's further say that it was change 999 that updated otherfile to revision 7, and that change 999 only contained otherfile.

    Since otherfile was never shelved, and the latest shelved revision above came from change 998, you can't conclude based on the shelf whether the client workspace was synced to change 998 or change 999.

    The even bigger caveat is that this all falls apart if they synced different files to different change numbers, but usually people don't do that.