Consistent naming in MergeOp

Refactoring MergeOp variables, which names ReviewDb as schema
and Repository as db. To avoid confusion and to be consistent
with the rest of the codebase the variables are renamed.

ReviewDb is now db and Repository is renamed to repo.

Change-Id: I49878632331fec6624bcc93cbb9d767419456666
This commit is contained in:
Deniz Turkoglu
2012-03-01 17:05:03 +01:00
parent 4f37db90ef
commit c35fb07721

View File

@@ -150,8 +150,8 @@ public class MergeOp {
private final List<CodeReviewCommit> toMerge; private final List<CodeReviewCommit> toMerge;
private List<Change> submitted; private List<Change> submitted;
private final Map<Change.Id, CodeReviewCommit> commits; private final Map<Change.Id, CodeReviewCommit> commits;
private ReviewDb schema; private ReviewDb db;
private Repository db; private Repository repo;
private RevWalk rw; private RevWalk rw;
private RevFlag CAN_MERGE; private RevFlag CAN_MERGE;
private CodeReviewCommit branchTip; private CodeReviewCommit branchTip;
@@ -208,7 +208,7 @@ public class MergeOp {
try { try {
setDestProject(); setDestProject();
openRepository(); openRepository();
final Ref destBranchRef = db.getRef(destBranch.get()); final Ref destBranchRef = repo.getRef(destBranch.get());
submitted = new ArrayList<Change>(); submitted = new ArrayList<Change>();
submitted.add(change); submitted.add(change);
@@ -230,7 +230,7 @@ public class MergeOp {
change.setLastSha1MergeTested(new RevId("")); change.setLastSha1MergeTested(new RevId(""));
} }
change.setMergeable(isMergeable(change)); change.setMergeable(isMergeable(change));
schema.changes().update(Collections.singleton(change)); db.changes().update(Collections.singleton(change));
} }
} catch (MergeException e) { } catch (MergeException e) {
log.error("Test merge attempt for change: " + change.getId() log.error("Test merge attempt for change: " + change.getId()
@@ -242,10 +242,10 @@ public class MergeOp {
log.error("Test merge attempt for change: " + change.getId() log.error("Test merge attempt for change: " + change.getId()
+ " failed", e); + " failed", e);
} finally { } finally {
if (schema != null) { if (db != null) {
schema.close(); db.close();
} }
schema = null; db = null;
} }
} }
@@ -258,8 +258,8 @@ public class MergeOp {
} }
private void openSchema() throws OrmException { private void openSchema() throws OrmException {
if (schema == null) { if (db == null) {
schema = schemaFactory.open(); db = schemaFactory.open();
} }
} }
@@ -268,7 +268,7 @@ public class MergeOp {
try { try {
openSchema(); openSchema();
openRepository(); openRepository();
submitted = schema.changes().submitted(destBranch).toList(); submitted = db.changes().submitted(destBranch).toList();
preMerge(); preMerge();
updateBranch(); updateBranch();
updateChangeStatus(); updateChangeStatus();
@@ -279,11 +279,11 @@ public class MergeOp {
if (rw != null) { if (rw != null) {
rw.release(); rw.release();
} }
if (db != null) { if (repo != null) {
db.close(); repo.close();
} }
schema.close(); db.close();
schema = null; db = null;
} }
} }
@@ -310,13 +310,13 @@ public class MergeOp {
private void openRepository() throws MergeException { private void openRepository() throws MergeException {
final Project.NameKey name = destBranch.getParentKey(); final Project.NameKey name = destBranch.getParentKey();
try { try {
db = repoManager.openRepository(name); repo = repoManager.openRepository(name);
} catch (RepositoryNotFoundException notGit) { } catch (RepositoryNotFoundException notGit) {
final String m = "Repository \"" + name.get() + "\" unknown."; final String m = "Repository \"" + name.get() + "\" unknown.";
throw new MergeException(m, notGit); throw new MergeException(m, notGit);
} }
rw = new RevWalk(db) { rw = new RevWalk(repo) {
@Override @Override
protected RevCommit createCommit(final AnyObjectId id) { protected RevCommit createCommit(final AnyObjectId id) {
return new CodeReviewCommit(id); return new CodeReviewCommit(id);
@@ -331,7 +331,7 @@ public class MergeOp {
alreadyAccepted = new HashSet<RevCommit>(); alreadyAccepted = new HashSet<RevCommit>();
try { try {
branchUpdate = db.updateRef(destBranch.get()); branchUpdate = repo.updateRef(destBranch.get());
if (branchUpdate.getOldObjectId() != null) { if (branchUpdate.getOldObjectId() != null) {
branchTip = branchTip =
(CodeReviewCommit) rw.parseCommit(branchUpdate.getOldObjectId()); (CodeReviewCommit) rw.parseCommit(branchUpdate.getOldObjectId());
@@ -340,7 +340,7 @@ public class MergeOp {
branchTip = null; branchTip = null;
} }
for (final Ref r : db.getAllRefs().values()) { for (final Ref r : repo.getAllRefs().values()) {
if (r.getName().startsWith(Constants.R_HEADS) if (r.getName().startsWith(Constants.R_HEADS)
|| r.getName().startsWith(Constants.R_TAGS)) { || r.getName().startsWith(Constants.R_TAGS)) {
try { try {
@@ -357,7 +357,7 @@ public class MergeOp {
private void validateChangeList() throws MergeException { private void validateChangeList() throws MergeException {
final Set<ObjectId> tips = new HashSet<ObjectId>(); final Set<ObjectId> tips = new HashSet<ObjectId>();
for (final Ref r : db.getAllRefs().values()) { for (final Ref r : repo.getAllRefs().values()) {
tips.add(r.getObjectId()); tips.add(r.getObjectId());
} }
@@ -372,7 +372,7 @@ public class MergeOp {
final PatchSet ps; final PatchSet ps;
try { try {
ps = schema.patchSets().get(chg.currentPatchSetId()); ps = db.patchSets().get(chg.currentPatchSetId());
} catch (OrmException e) { } catch (OrmException e) {
throw new MergeException("Cannot query the database", e); throw new MergeException("Cannot query the database", e);
} }
@@ -501,11 +501,11 @@ public class MergeOp {
// Settings for this project allow us to try and // Settings for this project allow us to try and
// automatically resolve conflicts within files if needed. // automatically resolve conflicts within files if needed.
// Use ResolveMerge and instruct to operate in core. // Use ResolveMerge and instruct to operate in core.
m = MergeStrategy.RESOLVE.newMerger(db, true); m = MergeStrategy.RESOLVE.newMerger(repo, true);
} else { } else {
// No auto conflict resolving allowed. If any of the // No auto conflict resolving allowed. If any of the
// affected files was modified, merge will fail. // affected files was modified, merge will fail.
m = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db); m = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(repo);
} }
try { try {
@@ -688,11 +688,11 @@ public class MergeOp {
// Settings for this project allow us to try and // Settings for this project allow us to try and
// automatically resolve conflicts within files if needed. // automatically resolve conflicts within files if needed.
// Use ResolveMerge and instruct to operate in core. // Use ResolveMerge and instruct to operate in core.
m = MergeStrategy.RESOLVE.newMerger(db, true); m = MergeStrategy.RESOLVE.newMerger(repo, true);
} else { } else {
// No auto conflict resolving allowed. If any of the // No auto conflict resolving allowed. If any of the
// affected files was modified, merge will fail. // affected files was modified, merge will fail.
m = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db); m = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(repo);
} }
try { try {
@@ -807,7 +807,7 @@ public class MergeOp {
List<PatchSetApproval> approvalList = null; List<PatchSetApproval> approvalList = null;
try { try {
approvalList = approvalList =
schema.patchSetApprovals().byPatchSet(n.patchsetId).toList(); db.patchSetApprovals().byPatchSet(n.patchsetId).toList();
Collections.sort(approvalList, new Comparator<PatchSetApproval>() { Collections.sort(approvalList, new Comparator<PatchSetApproval>() {
public int compare(final PatchSetApproval a, final PatchSetApproval b) { public int compare(final PatchSetApproval a, final PatchSetApproval b) {
return a.getGranted().compareTo(b.getGranted()); return a.getGranted().compareTo(b.getGranted());
@@ -893,7 +893,7 @@ public class MergeOp {
final CodeReviewCommit newCommit = (CodeReviewCommit) rw.parseCommit(id); final CodeReviewCommit newCommit = (CodeReviewCommit) rw.parseCommit(id);
n.change = n.change =
schema.changes().atomicUpdate(n.change.getId(), db.changes().atomicUpdate(n.change.getId(),
new AtomicUpdate<Change>() { new AtomicUpdate<Change>() {
@Override @Override
public Change update(Change change) { public Change update(Change change) {
@@ -907,10 +907,10 @@ public class MergeOp {
ps.setUploader(submitAudit.getAccountId()); ps.setUploader(submitAudit.getAccountId());
ps.setRevision(new RevId(id.getName())); ps.setRevision(new RevId(id.getName()));
insertAncestors(ps.getId(), newCommit); insertAncestors(ps.getId(), newCommit);
schema.patchSets().insert(Collections.singleton(ps)); db.patchSets().insert(Collections.singleton(ps));
n.change = n.change =
schema.changes().atomicUpdate(n.change.getId(), db.changes().atomicUpdate(n.change.getId(),
new AtomicUpdate<Change>() { new AtomicUpdate<Change>() {
@Override @Override
public Change update(Change change) { public Change update(Change change) {
@@ -922,7 +922,7 @@ public class MergeOp {
if (approvalList != null) { if (approvalList != null) {
for (PatchSetApproval a : approvalList) { for (PatchSetApproval a : approvalList) {
schema.patchSetApprovals().insert( db.patchSetApprovals().insert(
Collections.singleton(new PatchSetApproval(ps.getId(), a))); Collections.singleton(new PatchSetApproval(ps.getId(), a)));
} }
} }
@@ -945,7 +945,7 @@ public class MergeOp {
a.setAncestorRevision(new RevId(src.getParent(p).getId().name())); a.setAncestorRevision(new RevId(src.getParent(p).getId().name()));
toInsert.add(a); toInsert.add(a);
} }
schema.patchSetAncestors().insert(toInsert); db.patchSetAncestors().insert(toInsert);
} }
private ObjectId commit(final Merger m, final CommitBuilder mergeCommit) private ObjectId commit(final Merger m, final CommitBuilder mergeCommit)
@@ -992,7 +992,7 @@ public class MergeOp {
if (GitRepositoryManager.REF_CONFIG.equals(branchUpdate.getName())) { if (GitRepositoryManager.REF_CONFIG.equals(branchUpdate.getName())) {
try { try {
ProjectConfig cfg = new ProjectConfig(destProject.getNameKey()); ProjectConfig cfg = new ProjectConfig(destProject.getNameKey());
cfg.load(db, mergeTip); cfg.load(repo, mergeTip);
} catch (Exception e) { } catch (Exception e) {
throw new MergeException("Submit would store invalid" throw new MergeException("Submit would store invalid"
+ " project configuration " + mergeTip.name() + " for " + " project configuration " + mergeTip.name() + " for "
@@ -1111,7 +1111,7 @@ public class MergeOp {
} }
CreateCodeReviewNotes codeReviewNotes = CreateCodeReviewNotes codeReviewNotes =
codeReviewNotesFactory.create(schema, db); codeReviewNotesFactory.create(db, repo);
try { try {
codeReviewNotes.create(merged, computeAuthor(merged)); codeReviewNotes.create(merged, computeAuthor(merged));
} catch (CodeReviewNoteCreationException e) { } catch (CodeReviewNoteCreationException e) {
@@ -1124,7 +1124,7 @@ public class MergeOp {
private void updateSubscriptions() throws MergeException { private void updateSubscriptions() throws MergeException {
if (mergeTip != null && (branchTip == null || branchTip != mergeTip)) { if (mergeTip != null && (branchTip == null || branchTip != mergeTip)) {
SubmoduleOp subOp = SubmoduleOp subOp =
subOpFactory.create(destBranch, mergeTip, rw, db, destProject, subOpFactory.create(destBranch, mergeTip, rw, repo, destProject,
submitted, commits); submitted, commits);
try { try {
subOp.update(); subOp.update();
@@ -1236,11 +1236,11 @@ public class MergeOp {
if (commit.patchsetId == null) { if (commit.patchsetId == null) {
try { try {
List<PatchSet> matches = List<PatchSet> matches =
schema.patchSets().byRevision(new RevId(commit.name())).toList(); db.patchSets().byRevision(new RevId(commit.name())).toList();
if (matches.size() == 1) { if (matches.size() == 1) {
final PatchSet ps = matches.get(0); final PatchSet ps = matches.get(0);
commit.patchsetId = ps.getId(); commit.patchsetId = ps.getId();
commit.change = schema.changes().get(ps.getId().getParentKey()); commit.change = db.changes().get(ps.getId().getParentKey());
} }
} catch (OrmException e) { } catch (OrmException e) {
} }
@@ -1250,7 +1250,7 @@ public class MergeOp {
private boolean isAlreadySent(final Change c, final String prefix) { private boolean isAlreadySent(final Change c, final String prefix) {
try { try {
final List<ChangeMessage> msgList = final List<ChangeMessage> msgList =
schema.changeMessages().byChange(c.getId()).toList(); db.changeMessages().byChange(c.getId()).toList();
if (msgList.size() > 0) { if (msgList.size() > 0) {
final ChangeMessage last = msgList.get(msgList.size() - 1); final ChangeMessage last = msgList.get(msgList.size() - 1);
if (last.getAuthor() == null && last.getMessage().startsWith(prefix)) { if (last.getAuthor() == null && last.getMessage().startsWith(prefix)) {
@@ -1274,7 +1274,7 @@ public class MergeOp {
private ChangeMessage message(final Change c, final String body) { private ChangeMessage message(final Change c, final String body) {
final String uuid; final String uuid;
try { try {
uuid = ChangeUtil.messageUUID(schema); uuid = ChangeUtil.messageUUID(db);
} catch (OrmException e) { } catch (OrmException e) {
return null; return null;
} }
@@ -1292,7 +1292,7 @@ public class MergeOp {
PatchSetApproval submitter = null; PatchSetApproval submitter = null;
try { try {
final List<PatchSetApproval> approvals = final List<PatchSetApproval> approvals =
schema.patchSetApprovals().byPatchSet(c).toList(); db.patchSetApprovals().byPatchSet(c).toList();
for (PatchSetApproval a : approvals) { for (PatchSetApproval a : approvals) {
if (a.getValue() > 0 if (a.getValue() > 0
&& ApprovalCategory.SUBMIT.equals(a.getCategoryId())) { && ApprovalCategory.SUBMIT.equals(a.getCategoryId())) {
@@ -1315,7 +1315,7 @@ public class MergeOp {
final PatchSet.Id merged = commit.change.currentPatchSetId(); final PatchSet.Id merged = commit.change.currentPatchSetId();
try { try {
schema.changes().atomicUpdate(changeId, new AtomicUpdate<Change>() { db.changes().atomicUpdate(changeId, new AtomicUpdate<Change>() {
@Override @Override
public Change update(Change c) { public Change update(Change c) {
c.setStatus(Change.Status.MERGED); c.setStatus(Change.Status.MERGED);
@@ -1328,7 +1328,7 @@ public class MergeOp {
// Go back to the patch set that was actually merged. // Go back to the patch set that was actually merged.
// //
try { try {
c.setCurrentPatchSet(patchSetInfoFactory.get(schema, merged)); c.setCurrentPatchSet(patchSetInfoFactory.get(db, merged));
} catch (PatchSetInfoNotAvailableException e1) { } catch (PatchSetInfoNotAvailableException e1) {
log.error("Cannot read merged patch set " + merged, e1); log.error("Cannot read merged patch set " + merged, e1);
} }
@@ -1352,7 +1352,7 @@ public class MergeOp {
try { try {
c.setStatus(Change.Status.MERGED); c.setStatus(Change.Status.MERGED);
final List<PatchSetApproval> approvals = final List<PatchSetApproval> approvals =
schema.patchSetApprovals().byChange(changeId).toList(); db.patchSetApprovals().byChange(changeId).toList();
final FunctionState fs = functionState.create( final FunctionState fs = functionState.create(
changeControlFactory.controlFor( changeControlFactory.controlFor(
c, c,
@@ -1372,7 +1372,7 @@ public class MergeOp {
} }
a.cache(c); a.cache(c);
} }
schema.patchSetApprovals().update(approvals); db.patchSetApprovals().update(approvals);
} catch (NoSuchChangeException err) { } catch (NoSuchChangeException err) {
log.warn("Cannot normalize approvals for change " + changeId, err); log.warn("Cannot normalize approvals for change " + changeId, err);
} catch (OrmException err) { } catch (OrmException err) {
@@ -1384,7 +1384,7 @@ public class MergeOp {
msg.setAuthor(submitter.getAccountId()); msg.setAuthor(submitter.getAccountId());
} }
try { try {
schema.changeMessages().insert(Collections.singleton(msg)); db.changeMessages().insert(Collections.singleton(msg));
} catch (OrmException err) { } catch (OrmException err) {
log.warn("Cannot store message on change", err); log.warn("Cannot store message on change", err);
} }
@@ -1395,7 +1395,7 @@ public class MergeOp {
if (submitter != null) { if (submitter != null) {
cm.setFrom(submitter.getAccountId()); cm.setFrom(submitter.getAccountId());
} }
cm.setPatchSet(schema.patchSets().get(c.currentPatchSetId())); cm.setPatchSet(db.patchSets().get(c.currentPatchSetId()));
cm.send(); cm.send();
} catch (OrmException e) { } catch (OrmException e) {
log.error("Cannot send email for submitted patch set " + c.getId(), e); log.error("Cannot send email for submitted patch set " + c.getId(), e);
@@ -1406,7 +1406,7 @@ public class MergeOp {
try { try {
hooks.doChangeMergedHook(c, // hooks.doChangeMergedHook(c, //
accountCache.get(submitter.getAccountId()).getAccount(), // accountCache.get(submitter.getAccountId()).getAccount(), //
schema.patchSets().get(c.currentPatchSetId()), schema); db.patchSets().get(c.currentPatchSetId()), db);
} catch (OrmException ex) { } catch (OrmException ex) {
log.error("Cannot run hook for submitted patch set " + c.getId(), ex); log.error("Cannot run hook for submitted patch set " + c.getId(), ex);
} }
@@ -1418,14 +1418,14 @@ public class MergeOp {
private void sendMergeFail(Change c, ChangeMessage msg, final boolean makeNew) { private void sendMergeFail(Change c, ChangeMessage msg, final boolean makeNew) {
try { try {
schema.changeMessages().insert(Collections.singleton(msg)); db.changeMessages().insert(Collections.singleton(msg));
} catch (OrmException err) { } catch (OrmException err) {
log.warn("Cannot record merge failure message", err); log.warn("Cannot record merge failure message", err);
} }
if (makeNew) { if (makeNew) {
try { try {
schema.changes().atomicUpdate(c.getId(), new AtomicUpdate<Change>() { db.changes().atomicUpdate(c.getId(), new AtomicUpdate<Change>() {
@Override @Override
public Change update(Change c) { public Change update(Change c) {
if (c.getStatus().isOpen()) { if (c.getStatus().isOpen()) {
@@ -1441,7 +1441,7 @@ public class MergeOp {
} }
} else { } else {
try { try {
ChangeUtil.touch(c, schema); ChangeUtil.touch(c, db);
} catch (OrmException err) { } catch (OrmException err) {
log.warn("Cannot update change timestamp", err); log.warn("Cannot update change timestamp", err);
} }
@@ -1453,7 +1453,7 @@ public class MergeOp {
if (submitter != null) { if (submitter != null) {
cm.setFrom(submitter.getAccountId()); cm.setFrom(submitter.getAccountId());
} }
cm.setPatchSet(schema.patchSets().get(c.currentPatchSetId())); cm.setPatchSet(db.patchSets().get(c.currentPatchSetId()));
cm.setChangeMessage(msg); cm.setChangeMessage(msg);
cm.send(); cm.send();
} catch (OrmException e) { } catch (OrmException e) {