Before I sync my Perforce client in the morning, I'd like to read the diffs and log messages for any changelists that will affect me. Unfortunately, though, I can't find a simple way to list such changelists using either p4 changes
or P4V. I suspect I'm missing something simple, though.
Is there a way that I can list all the changelists submitted since I last sync'ed my client? If I can get the full descriptions and diffs from previous depot revisions, as p4 describe
does for a single changelist, that would be even better.
The p4 changes command, when involked with @clientname as a revision specifier, shows the highest changelist associated with file revisions in your workspace.
To submit a pending changelist, issue the p4 submit command. When you issue the p4 submit command, a form is displayed, listing the files in the changelist. You can remove files from this list. The files you remove remain open in the default pending changelist until you submit them or revert them.
When you check out a file, Perforce adds information about the file to a changelist and changes the writable attribute of the file in your local workspace from read-only to read/write. A changelist defines a logical grouping of work across a set of files and folders.
p4 sync brings the client workspace into sync with the depot by copying files matching its file pattern arguments from the depot to the client workspace. When no file patterns are specified on the command line, p4 sync copies a particular depot file if it meets all three criteria: Visible through the client view.
The simple answer is:
p4 changes -l "...#>have"
You need the quotes to avoid your shell doing redirection.
You can trivially iterate over the changes and call "p4 describe" on each one.
You can get a full diff by using "p4 diff2" (assuming you want a unidiff):
p4 diff2 -du ...#have ...#head
But that doesn't give you a per-changelist diff.
Beware!
p4 changes "...#>have"
does not list changelists that contain only new/added files.
Your best bet is to cache the last sync point, something like
HEAD=`p4 counter change`
if [ -f lastbuild.txt ]
then
OLDHEAD=`cat lastbuild.txt`
else
OLDHEAD=`p4 changes -m1 ...#have`
echo lastbuild.txt not found! I will guess that your last sync was @$OLDHEAD
fi
p4 changes ...@$OLDHEAD,$HEAD > changes.txt
# -snip- review changes.txt, perhaps prompt "Continue with sync to $HEAD?"
p4 sync ...@$HEAD
echo $HEAD > lastbuild.txt
With this method you will get false positives if you have submitted or cherry-pick-synced any changelists since the last time you updated the sync point cache, but it's better to list an extra changelist for review than to miss one, especially one containing all new code.
Don't try this at home
For posterity, here are a couple other things I've tried in the past that ultimately failed:
p4 changes ...#have > have.txt
p4 changes ...#head > head.txt
diff have.txt head.txt
covers the case of changelists containing all adds, but the final output falsely includes older changelists for files that are deleted at #have. Also perf can be pretty bad if you have a lot of history in the depot.
p4 sync -n ... | cut -f1 -d' ' | p4 -x- changes -m1 | sort | uniq
gets pretty close, but fails to list older changelists if a file has been edited multiple times since you last synced. It's also hitting the depot once for every file that will sync, so perf can be really poor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With