Insert Change-Id into access right changes

When modifications of access rights are saved for review, a new change
is created. Now this change has a Change-Id in the commit message, so
that it's easier to manually rework the change and push further patch
sets.

Bug: issue 2817
Change-Id: I0a6399d731644bdc28147cfd8527e3b692c953da
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
(cherry picked from commit 8d17f7e5e7)
This commit is contained in:
Edwin Kempin
2015-02-18 13:50:18 +01:00
committed by David Pursehouse
parent a709dc1271
commit 5eb53d7ffd
3 changed files with 29 additions and 1 deletions

View File

@@ -14,6 +14,7 @@
package com.google.gerrit.httpd.rpc.project;
import com.google.gerrit.common.FooterConstants;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.TimeUtil;
import com.google.gerrit.common.data.AccessSection;
@@ -100,6 +101,7 @@ public class ReviewProjectAccess extends ProjectAccessHandler<Change.Id> {
protected Change.Id updateProjectConfig(ProjectControl ctl,
ProjectConfig config, MetaDataUpdate md, boolean parentProjectUpdate)
throws IOException, OrmException {
md.setInsertChangeId(true);
Change.Id changeId = new Change.Id(db.nextChangeId());
RevCommit commit =
config.commitToNewRef(md, new PatchSet.Id(changeId,
@@ -109,7 +111,7 @@ public class ReviewProjectAccess extends ProjectAccessHandler<Change.Id> {
}
Change change = new Change(
new Change.Key("I" + commit.name()),
getChangeId(commit),
changeId,
user.getAccountId(),
new Branch.NameKey(
@@ -133,6 +135,14 @@ public class ReviewProjectAccess extends ProjectAccessHandler<Change.Id> {
return changeId;
}
private static Change.Key getChangeId(RevCommit commit) {
List<String> idList = commit.getFooterLines(FooterConstants.CHANGE_ID);
Change.Key changeKey = !idList.isEmpty()
? new Change.Key(idList.get(idList.size() - 1).trim())
: new Change.Key("I" + commit.name());
return changeKey;
}
private void addProjectOwnersAsReviewers(ChangeResource rsrc) {
final String projectOwners =
groupBackend.get(SystemGroupBackend.PROJECT_OWNERS).getName();

View File

@@ -148,6 +148,7 @@ public class MetaDataUpdate {
private final BatchRefUpdate batch;
private final CommitBuilder commit;
private boolean allowEmpty;
private boolean insertChangeId;
@AssistedInject
public MetaDataUpdate(GitReferenceUpdated gitRefUpdated,
@@ -180,6 +181,10 @@ public class MetaDataUpdate {
this.allowEmpty = allowEmpty;
}
public void setInsertChangeId(boolean insertChangeId) {
this.insertChangeId = insertChangeId;
}
/** @return batch in which to run the update, or {@code null} for no batch. */
BatchRefUpdate getBatch() {
return batch;
@@ -202,6 +207,10 @@ public class MetaDataUpdate {
return allowEmpty;
}
boolean insertChangeId() {
return insertChangeId;
}
public CommitBuilder getCommitBuilder() {
return commit;
}

View File

@@ -43,6 +43,7 @@ import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.transport.ReceiveCommand;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.util.ChangeIdUtil;
import org.eclipse.jgit.util.RawParseUtils;
import java.io.BufferedReader;
@@ -271,6 +272,14 @@ public abstract class VersionedMetaData {
commit.addParentId(src);
}
if (update.insertChangeId()) {
ObjectId id =
ChangeIdUtil.computeChangeId(res, getRevision(),
commit.getAuthor(), commit.getCommitter(),
commit.getMessage());
commit.setMessage(ChangeIdUtil.insertId(commit.getMessage(), id));
}
src = inserter.insert(commit);
srcTree = res;
}