How do you quickly find/delete all empty changelists in Perforce?
-
21-09-2019 - |
Question
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
Solution 3
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
OTHER TIPS
Ah !
I should have browse more documentation before asking this...
http://public.perforce.com/wiki/Perforce_Command_Line_Recipes
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
To simply find all empty submitted changelists without deleting them, you can compare the output of these two commands:
p4 changes -s submitted
- all changelistsp4 changes -s submitted //...
- all changelists with associated files
In Windows PowerShell, for example, run
diff -ReferenceObject (p4 changes -s submitted) -DifferenceObject (p4 changes -s submitted //...)
Here is a DOS CMD only version. Just replace %p4streamsUser%.
for /f "tokens=* delims=" %%i in ('p4 changes -u %p4streamsUser% -s pending') do (
for /f "tokens=1-7*" %%a in ("%%i") do (
echo Deleting CL %%b %%h %%f
p4 change -d -f %%b
)
)
I'm on a Windows 7 machine. This will work on several other versions of windows/DOS.