Use ObjectId instead of RevId in PatchSet, and remove RevId

RevId began its existence in I43a6d6e4:

  Introduce RevId as an abstraction around revision strings

  This may make it easier to replace Git with some other tool like
  Hg or SVN, but it also offers us a convenient way to abstract the
  data type and improve type safety within Gerrit's code tree.

There are no plans to support another VCS in Gerrit in the foreseeable
future; that would be a huge project. Even if we were to start, moving
away from ObjectId in the storage layer is just a drop in the ocean,
considering the heavy usage of ObjectId elsewhere in Gerrit (to say
nothing of other JGit APIs).

The arguments around encapsulating the type and improving compile-time
safety still apply, but ObjectId serves the same purposes--arguably
better, since ObjectId has useful and well-tested and -benchmarked
methods upstream in JGit.

There were other arguments for using RevId in the past: ObjectId
couldn't be used as a field type in ReviewDb, and isn't GWT-compatible.
These arguments no longer hold, since both ReviewDb and GWT are gone.

The specific implementation of RevId itself had some shortcomings:

 * It didn't validate that the underlying value was a valid hex SHA-1.
 * It allowed null as a value, although nearly all callers assumed it
   didn't.
 * The id field was non-final. (In practice it was not possible to
   reassign it without using either gwtorm libraries or direct
   reflection.)
 * There were no convenient methods for converting to/from ObjectId,
   a very frequent operation, largely because of the historical GWT
   incompatibility.

Of course, these problems are fixable, but why bother? ObjectId serves
the purpose, and this way contributors don't have the cognitive overhead
of deciding which of two similar types to use.

Change-Id: Iff5644e21c51a7a8c12a113fd5a6a6ffaf60ae20
This commit is contained in:
Dave Borowitz
2019-04-24 08:09:34 -07:00
parent b663cd6ec2
commit ef40918fb4
82 changed files with 319 additions and 431 deletions

View File

@@ -181,18 +181,18 @@ public class Rebase extends RetryingRestModifyView<RevisionResource, RebaseInput
+ baseChange.getKey()
+ " is a descendant of the current change - recursion not allowed");
}
return ObjectId.fromString(base.patchSet().getRevision().get());
return base.patchSet().getCommitId();
}
private boolean isMergedInto(RevWalk rw, PatchSet base, PatchSet tip) throws IOException {
ObjectId baseId = ObjectId.fromString(base.getRevision().get());
ObjectId tipId = ObjectId.fromString(tip.getRevision().get());
ObjectId baseId = base.getCommitId();
ObjectId tipId = tip.getCommitId();
return rw.isMergedInto(rw.parseCommit(baseId), rw.parseCommit(tipId));
}
private boolean hasOneParent(RevWalk rw, PatchSet ps) throws IOException {
// Prevent rebase of exotic changes (merge commit, no ancestor).
RevCommit c = rw.parseCommit(ObjectId.fromString(ps.getRevision().get()));
RevCommit c = rw.parseCommit(ps.getCommitId());
return c.getParentCount() == 1;
}