Danone has agreed to sell its 51% stake in a joint venture with China's Wahaha, bringing to an end their long-running dispute.