6
votes

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.

6
Thank you all, I will try these as I go and accept one if it turns out well. I was hoping to avoid the script approach, but it seems based on these answers that that's the way to go. ā€“ Michael Ratanapintha

6 Answers

9
votes

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.

4
votes

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.

1
votes

The newer versions of P4V (starting with 2009.2, maybe 2009.1) have something called a Dashboard that contains several "Tasks". One of these is Changelists that have not yet been synced to your workspace.

In the menu bar go to View -> DashBoard. There is a gear icon on the right of the DashBoard tab bar that allows you to configure your options. One of these is is "Files in my workspace are not at the latest revisions." The unsynced files are organized by changelist.

0
votes

Is the answer to this question at all helpful?

From what I remember you have to store the last date/time you synced and then parse the output of p4 changes -t to just display those changelists after your date.

0
votes

With time you may end up building a lot of little snippets of code around your use of Perforce. It may be a good idea to bundle them all into a wrapper script that invokes p4 for you and passes commands on to it, with or without extra, custom steps.

If you're using this kind of a wrapper with discipline (ie. not invoking p4 directly) it's trivial to make it store the last change you synced to.

0
votes

In a DOS batch file, you could do something like the following:

FOR /F "tokens=2 delims= " %%a IN ('p4 changes -m1') DO (SET TO_CHANGELIST=%%a)
FOR /F "tokens=2 delims= " %%a IN ('p4 changes -m1 -c <client_name>')
       DO (SET FROM_CHANGELIST=%%a)

p4 changes -s submitted @%TO_CHANGELIST%,@%FROM_CHANGELIST%

It will give you the list of all p4 changelists that are between the one that was last synced on your client and the changelist that was most recently submitted.

You can replace the last line with the following if you want to get the changelist descriptions and diffs:

FOR /F "tokens=2 delims= " %%a 
     IN ('p4 changes -s submitted @%TO_CHANGELIST%,@%FROM_CHANGELIST%') 
     DO (p4 describe %%a)

I would suggest that you pipe this data to a file so it will be easier to review.