Well I'm not going to change how the engine calculates and updates Ship.Sail.SP value.
The scripts update that number using .dmg, in function CalculateShipSP. The engine uses a percentage based on numHoles/maxHoles; both of those are available in the .hc and .mhc attributes of the sails. You can either change CalculateShipSP to use the same calculation I provided, instead of .dmg, so they will always match. Or, you can store CalculateShipSP in a different attribute within your scripts (example Ship.Sail.SP2) and use that new attribute everywhere in your scripts when you repair, but then adjust the engines hole count to match your desired SP value that you calculate in the scripts, by using DeleteOneSailHole, to inform the engine to adjust the hole count that will cause the engine to calculate a similar Ship.Sail.SP value when it employs holes/maxHoles.