Do not store ObjectId subclasses in RefDatabase caches
We cannot permit an ObjectId subclass, such as RevCommit, to be
cached inside of the RefDatabase cache. Instead of toObjectId()
use copy() to ensure we get exactly an ObjectId for the new value,
as that is the instance we will cache in the RefDatabase.
Caching the ObjectId subclass in RefDatabase will cause any later
cached read of the ref to return that RevCommit, confusing all
application code using "ref.getObjectId().equals(...)" due to the
overridden definition of equals(ObjectId).
ReceivePack was bitten by this, sometimes reporting "invalid old id"
to clients if the ref was last updated using a RevCommit instead
of an ObjectId. It also caused the history of that repository to
be pinned in memory as RevCommit instances, all of them reachable
from the RefDatabase cache of the last updated Ref.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>