  We use recent observations of the HI-mass function to constrain galaxy
formation. The data conflicts with the standard model where most of the gas in
a low-mass dark matter halo is assumed to settle into a disk of cold gas that
is depleted by star formation and supernova-driven outflows until the disk
becomes gravitationally stable. A consistent model can be found if low-mass
haloes are embedded in a preheated medium, with a specific gas entropy ~ 10Kev
cm^2. Such a model simultaneously matches the faint-end slope of the galaxy
luminosity function. We propose a preheating model where the medium around
low-mass haloes is preheated by gravitational pancaking. Since gravitational
tidal fields suppress the formation of low-mass haloes while promoting that of
pancakes, the formation of massive pancakes precedes that of the low-mass
haloes within them. We demonstrate that the progenitors of present-day dark
matter haloes with M<10^{12}h^{-1}\msun were embedded in pancakes of masses
$~5x10^{12}h^{-1}\msun$ at z~2. The formation of such pancakes heats the gas to
a temperature of 5x10^5K and compresses it to an overdensity of ~10. Such gas
has a cooling time that exceeds the age of the Universe at z~2, and has a
specific entropy of ~15Kev cm^2, almost exactly the amount required to explain
the stellar and HI mass functions. (Abridged)
