Bash script to batch obliterate revisions with p4 perforce

Aug 3rd, 2017 | By | Category: Linux / Freebsd

Ok, so you have a project with a 1GB file and the devs have committed 120 revisions of that file, meaning they are probably taking up somewhere between 50-100GB worth of space on the server.  One option is to nuke the file entirely and re-upload it but then you look the version history and it’ll likely take a few minutes at least to do all that.  An easier option would just be to delete revisions 1-98 and reduce it’s size by 98%.  p4 obliterate -y let’s you do this but the genius over at Perforce decided to only allow you to obliterate 2 revisions at a time, so you have to manually remove them 2 by 2.  In the face of this lunacy I wrote a little script that does it for you in a matter of seconds(instead of minutes or hours), enjoy:

 

#!/bin/bash

read -p “What is the starting revisions? ” start
read -p “What is the last revision you want to trim to? ” end
read -p “What server(port) are we working on? ” port
read -p “Enter full P4 path (//depot/whatever NOT the server path) to file you want to trim ” file

for ((i=$start;i<=$end;++i)) do

p4 -p localhost:$port obliterate -y “$file#$i”
sleep .025
done

Tags: , , , , , ,

Leave a Comment