  We prove conjectures of Breuil and Breuil-Dembele (C. Breuil, "Sur un
probleme de compatibilite local-global modulo p pour GL(2)"), including a
generalisation from the principal series to the cuspidal case, subject to a
mild global hypothesis that we make in order to apply certain R=T theorems.
More precisely, we prove a multiplicity one result for the mod p cohomology of
a Shimura curve at Iwahori level, and we show that certain apparently globally
defined lattices in the cohomology of Shimura curves are determined by the
corresponding local p-adic Galois representations. We also indicate a new proof
of the Buzzard-Diamond-Jarvis conjecture in generic cases. Our main tools are
the geometric Breuil-Mezard philosophy developed by two of the authors, and a
new and more functorial perspective on the Taylor-Wiles-Kisin patching method.
Along the way, we determine the tamely potentially Barsotti-Tate deformation
rings of generic two-dimensional mod p representations, generalising a result
of Breuil-Mezard in the principal series case.
