Ensure reader always exists for VersionedMetaData.onLoad()

This simplifies implementations of onLoad() that may want to depend on
reader not being null. Since createInMemory() resulted in a null
reader, remove that method and replace it with usages of
InMemoryRepository (which is easy enough since it was only used in
tests).

Change-Id: I8b534ef041ff7f3f54b0e744d36e99a0c8c1bb24
This commit is contained in:
Dave Borowitz
2013-12-05 15:44:21 -08:00
parent cb8fc9b4b5
commit 826a7b6dda
6 changed files with 49 additions and 45 deletions

View File

@@ -71,18 +71,6 @@ public abstract class VersionedMetaData {
return revision != null ? revision.copy() : null;
}
/** Initialize in-memory as though the repository branch doesn't exist. */
public void createInMemory() {
try {
revision = null;
onLoad();
} catch (IOException err) {
throw new RuntimeException("Unexpected IOException", err);
} catch (ConfigInvalidException err) {
throw new RuntimeException("Unexpected ConfigInvalidException", err);
}
}
/**
* Load the current version from the branch.
* <p>
@@ -116,19 +104,13 @@ public abstract class VersionedMetaData {
*/
public void load(Repository db, ObjectId id) throws IOException,
ConfigInvalidException {
if (id != null) {
reader = db.newObjectReader();
try {
revision = new RevWalk(reader).parseCommit(id);
onLoad();
} finally {
reader.release();
reader = null;
}
} else {
// The branch does not yet exist.
revision = null;
reader = db.newObjectReader();
try {
revision = id != null ? new RevWalk(reader).parseCommit(id) : null;
onLoad();
} finally {
reader.release();
reader = null;
}
}