Theory of mercury porosimetry hysteresis