Allow VersionedMetaData.onSave to skip committing
Change-Id: I65349b2fde9fd22381fa5e4a35f6265924c626f0
This commit is contained in:
@@ -88,7 +88,7 @@ public class AllProjectsConfig extends VersionedMetaData {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSave(CommitBuilder commit) throws IOException,
|
||||
protected boolean onSave(CommitBuilder commit) throws IOException,
|
||||
ConfigInvalidException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@@ -746,7 +746,7 @@ public class ProjectConfig extends VersionedMetaData {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSave(CommitBuilder commit) throws IOException,
|
||||
protected boolean onSave(CommitBuilder commit) throws IOException,
|
||||
ConfigInvalidException {
|
||||
if (commit.getMessage() == null || "".equals(commit.getMessage())) {
|
||||
commit.setMessage("Updated project configuration\n");
|
||||
@@ -786,6 +786,7 @@ public class ProjectConfig extends VersionedMetaData {
|
||||
|
||||
saveConfig(PROJECT_CONFIG, rc);
|
||||
saveGroupList();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static final String validMaxObjectSizeLimit(String value)
|
||||
|
||||
@@ -88,11 +88,12 @@ public class ProjectLevelConfig extends VersionedMetaData {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSave(CommitBuilder commit) throws IOException,
|
||||
protected boolean onSave(CommitBuilder commit) throws IOException,
|
||||
ConfigInvalidException {
|
||||
if (commit.getMessage() == null || "".equals(commit.getMessage())) {
|
||||
commit.setMessage("Updated configuration\n");
|
||||
}
|
||||
saveConfig(fileName, cfg);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,9 +61,17 @@ public abstract class VersionedMetaData {
|
||||
/** @return name of the reference storing this configuration. */
|
||||
protected abstract String getRefName();
|
||||
|
||||
/** Set up the metadata, parsing any state from the loaded revision. */
|
||||
protected abstract void onLoad() throws IOException, ConfigInvalidException;
|
||||
|
||||
protected abstract void onSave(CommitBuilder commit) throws IOException,
|
||||
/**
|
||||
* Save any changes to the metadata in a commit.
|
||||
*
|
||||
* @return true if the commit should proceed, false to abort.
|
||||
* @throws IOException
|
||||
* @throws ConfigInvalidException
|
||||
*/
|
||||
protected abstract boolean onSave(CommitBuilder commit) throws IOException,
|
||||
ConfigInvalidException;
|
||||
|
||||
/** @return revision of the metadata that was loaded. */
|
||||
@@ -189,7 +197,7 @@ public abstract class VersionedMetaData {
|
||||
write(VersionedMetaData.this, commit);
|
||||
}
|
||||
|
||||
private void doSave(VersionedMetaData config, CommitBuilder commit) throws IOException {
|
||||
private boolean doSave(VersionedMetaData config, CommitBuilder commit) throws IOException {
|
||||
DirCache nt = config.newTree;
|
||||
ObjectReader r = config.reader;
|
||||
ObjectInserter i = config.inserter;
|
||||
@@ -197,7 +205,7 @@ public abstract class VersionedMetaData {
|
||||
config.newTree = newTree;
|
||||
config.reader = reader;
|
||||
config.inserter = inserter;
|
||||
config.onSave(commit);
|
||||
return config.onSave(commit);
|
||||
} catch (ConfigInvalidException e) {
|
||||
throw new IOException("Cannot update " + getRefName() + " in "
|
||||
+ db.getDirectory() + ": " + e.getMessage(), e);
|
||||
@@ -210,7 +218,9 @@ public abstract class VersionedMetaData {
|
||||
|
||||
@Override
|
||||
public void write(VersionedMetaData config, CommitBuilder commit) throws IOException {
|
||||
doSave(config, commit);
|
||||
if (!doSave(config, commit)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ObjectId res = newTree.writeTree(inserter);
|
||||
if (res.equals(srcTree) && !update.allowEmpty()) {
|
||||
|
||||
@@ -307,7 +307,7 @@ public class ChangeNotes extends VersionedMetaData {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSave(CommitBuilder commit) {
|
||||
protected boolean onSave(CommitBuilder commit) {
|
||||
throw new UnsupportedOperationException(
|
||||
getClass().getSimpleName() + " is read-only");
|
||||
}
|
||||
|
||||
@@ -265,9 +265,9 @@ public class ChangeUpdate extends VersionedMetaData {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSave(CommitBuilder commit) {
|
||||
protected boolean onSave(CommitBuilder commit) {
|
||||
if (approvals.isEmpty() && reviewers.isEmpty()) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
int ps = psId != null ? psId.get() : change.currentPatchSetId().get();
|
||||
StringBuilder msg = new StringBuilder();
|
||||
@@ -293,6 +293,7 @@ public class ChangeUpdate extends VersionedMetaData {
|
||||
}
|
||||
}
|
||||
commit.setMessage(msg.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
private static StringBuilder addFooter(StringBuilder sb, FooterKey footer) {
|
||||
|
||||
Reference in New Issue
Block a user