views:

423

answers:

2

Hi,

I was wondering what could be the point in trying to delete committed changelists, because a committed changelist is not supposed to be empty.

But then I am playing with the tutorial depot, and using the obliterate command on a whole branch, I can see there are situation where you can end up with empty committed changelists (that need deletion with the -f flag).

However, I don't know how to find them with the command line, as I don't know how to look for changelists with no files associated with.

Is there an easy way to do that ?

Thanks,

Thomas

+3  A: 

Ah !

I should have browse more documentation before asking this...

http://public.perforce.com/wiki/Perforce%5FCommand%5FLine%5FRecipes

Description: Delete all empty submitted changelists.
Shell command: p4 changes -s submitted | cut -d " " -f 2 | xargs -n1 p4 change -d -f
Powershell: p4 changes -s submitted | %{p4 change -d -f $_.split()[1]}
px: px -F %change% changes -s submitted | px -X- change -d -f
Contributors: Sam Stafford, Philip Kania, Shawn Hladky

Duh.

Thomas

Thomas Corriol
You should accept your own answer (to mark the question as answered). :-)
PhiLho
I couldn't use the proposed answers on my Windows PC, so I have written a small PERL script to do the same. :-)
Thomas Corriol
A: 

As I am on Windows, I have created a little script doing the exact same thing in PERL, rather than Shell, powershell or px :) :

#*******************************************************************************
# Module:  delete_empty_changelist.pl
# Purpose: A script to delete empty changelist
# 

@list = `p4 changes -s submitted`;

foreach $chg (@list)
{
 $chgnbr = (split /\s+/, $chg)[1];
 print `p4 change -d -f $chgnbr`;
 }     
exit 0;

Note that in fact, in all cases, it's not a very clever script: It tries to delete absolutely every submitted changelist, and is prevented by perforce to do so, because if files are associated with it, you will get an error.

I suppose the result of the script should be sent to a log, and parse, so that only the relevant lines are highlighted.

Running the script will produce an output similar to:

Change 857 has 1 files associated with it and can't be deleted.
Change 856 has 1 fixes associated with it and can't be deleted.
Change 855 has 1 fixes associated with it and can't be deleted.
Change 854 deleted.
Change 853 has 1 fixes associated with it and can't be deleted.
Change 852 has 8 files associated with it and can't be deleted.
Change 851 has 1 files associated with it and can't be deleted.
Change 850 has 2 files associated with it and can't be deleted.
Change 849 has 2 files associated with it and can't be deleted.
Change 846 deleted.
Change 845 has 2 files associated with it and can't be deleted.

Cheers,

Thomas

Thomas Corriol