  In this paper we analyze the local and global boundary rigidity problem for
general Riemannian manifolds with boundary $(M,g)$. We show that the boundary
distance function, i.e., $d_g|_{\partial M\times\partial M}$, known near a
point $p\in \partial M$ at which $\partial M$ is strictly convex, determines
$g$ in a suitable neighborhood of $p$ in $M$, up to the natural diffeomorphism
invariance of the problem.
  We also consider the closely related lens rigidity problem which is a more
natural formulation if the boundary distance is not realized by unique
minimizing geodesics. The lens relation measures the point and the direction of
exit from $M$ of geodesics issued from the boundary and the length of the
geodesic. The lens rigidity problem is whether we can determine the metric up
to isometry from the lens relation. We solve the lens rigidity problem under
the assumption that there is a function on $M$ with suitable convexity
properties relative to $g$. This can be considered as a complete solution of a
problem formulated first by Herglotz in 1905. We also prove a semi-global
results given semi-global data. This shows, for instance, that simply connected
manifolds with strictly convex boundaries are lens rigid if the sectional
curvature is non-positive or non-negative or if there are no focal points.
  The key tool is the analysis of the geodesic X-ray transform on 2-tensors,
corresponding to a metric $g$, in the normal gauge, such as normal coordinates
relative to a hypersurface, where one also needs to allow weights. This is
handled by refining and extending our earlier results in the solenoidal gauge.
