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 . Assuming a star formation threshold density supported by both theory and observations this model predicts HI masses that are much too large . The reason is simple : supernova feedback requires star formation , which in turn requires a high surface density for the gas . Heating by the UV background can reduce the amount of cold gas in haloes with masses < 10 ^ { 9.5 } h ^ { -1 } { M } _ { \odot } , but is insufficient to explain the observed HI mass function . A consistent model can be found if low-mass haloes are embedded in a preheated medium , with a specific gas entropy \sim 10 { keV cm ^ { 2 } } . In addition , such a model simultaneously matches the faint-end slope of the galaxy luminosity function without the need for any supernova driven outflows . 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 \la 10 ^ { 12 } h ^ { -1 } \ > { M _ { \odot } } were embedded in pancakes of masses \sim 5 \times 10 ^ { 12 } h ^ { -1 } \ > { M _ { \odot } } at z \sim 2 . The formation of such pancakes heats the gas to a temperature of 5 \times 10 ^ { 5 } { K } and compresses it to an overdensity of \sim 10 . Such gas has a cooling time that exceeds the age of the Universe at z \la 2 , and has a specific entropy of \sim 15 { keV cm ^ { 2 } } , almost exactly the amount required to explain the stellar and HI mass functions .