NEW YORK ( TheStreet) -- Five years after the Deepwater Horizon oil spill, BP (BP) - Get BP p.l.c. Sponsored ADR Report has recovered most of the $40 billion it lost in market value. 

The rebound, though, has had little to do with the billions of dollars the company spent to revive the Gulf of Mexico coastline -- and its battered reputation -- after the worst environmental accident in U.S. history. Instead, shareholders have focused more on the energy company's profitable exploration-and-production business.

"Shareholders don't care about" BP's public-relations efforts, said Raymond James energy analyst Pavel Molcanov. "Much as they don't care about scholarship programs or charitable contributions."

What matters, Molcanov said, is BP's profitability from its  core business of exploration and production, its "cash cow."

Social protests also didn't have much impact. Consumers were encouraged by environmental groups to boycott BP gas stations. The boycotts, however, "were not a needle mover for a highly profitable oil company like BP," Mocanov said, in part because BP stations are all franchised rather than owned outright.

Although the company reported a loss of $17.15 billion for the quarter in which the oil spill occurred, largely from a $32.2 billion pre-tax charge, BP swung to a profit the following quarter.

TheStreet Recommends

From third quarter 2010 until the second quarter of 2014 -- before oil prices went into a freefall -- BP earned $5 billion or more each quarter more than half the time, even though the company has spent $28 billion so far in claim payments, restoration work and clean-up costs.

BPs oil rigs in the Gulf of Mexico have increased from five to 10 between 2011 and 2013. Last year, the company was the highest bidder for 24 out of 31 blocks in Gulf of Mexico lease sales. It plans to invest $1 billion over five years starting in 2015 in the Alaska North Slope.

Risk-averse investors may still be spooked by litigation against BP, but even the worst-case scenario is unlikely to cause much of a panic among shareholders.

Last September, BP appealed a ruling by the U.S. District Court for the Eastern District of Louisiana which found BP guilty of "gross negligence" and levied a fine of $18.5 billion. If BP can strike the word "gross" from the ruling, the fine could be cut by more than a third, which would likely drive the stock price higher.

Even if the penalty stays at $18.5 billion, it's not big in terms of BP's annual revenue. In 2014, the company had $358.7 billion in revenue, down 9% from 2013, but 16% higher than the same year as the accident. Also, an $18.5 billion penalty would most likely be spread over five years.

In short, legal issues and negative publicity are unlikely to dent the long-term outlook for the British oil giant.

This article is commentary by an independent contributor. At the time of publication, the author held no positions in the stock mentioned.