Merge "Support for --file option for ssh queries."
This commit is contained in:
@@ -26,6 +26,9 @@ import com.google.gerrit.reviewdb.PatchSetApproval;
|
||||
import com.google.gerrit.reviewdb.TrackingId;
|
||||
import com.google.gerrit.server.account.AccountCache;
|
||||
import com.google.gerrit.server.config.CanonicalWebUrl;
|
||||
import com.google.gerrit.server.patch.PatchList;
|
||||
import com.google.gerrit.server.patch.PatchListCache;
|
||||
import com.google.gerrit.server.patch.PatchListEntry;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -43,14 +46,17 @@ public class EventFactory {
|
||||
private final AccountCache accountCache;
|
||||
private final Provider<String> urlProvider;
|
||||
private final ApprovalTypes approvalTypes;
|
||||
private final PatchListCache patchListCache;
|
||||
|
||||
@Inject
|
||||
EventFactory(AccountCache accountCache,
|
||||
@CanonicalWebUrl @Nullable Provider<String> urlProvider,
|
||||
ApprovalTypes approvalTypes) {
|
||||
ApprovalTypes approvalTypes,
|
||||
PatchListCache patchListCache) {
|
||||
this.accountCache = accountCache;
|
||||
this.urlProvider = urlProvider;
|
||||
this.approvalTypes = approvalTypes;
|
||||
this.patchListCache = patchListCache;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,11 +120,18 @@ public class EventFactory {
|
||||
}
|
||||
|
||||
public void addPatchSets(ChangeAttribute a, Collection<PatchSet> ps) {
|
||||
addPatchSets(a, ps, null);
|
||||
addPatchSets(a, ps, null, false, null);
|
||||
}
|
||||
|
||||
public void addPatchSets(ChangeAttribute ca, Collection<PatchSet> ps,
|
||||
Map<PatchSet.Id,Collection<PatchSetApproval>> approvals) {
|
||||
addPatchSets(ca, ps, approvals, false, null);
|
||||
}
|
||||
|
||||
public void addPatchSets(ChangeAttribute ca, Collection<PatchSet> ps,
|
||||
Map<PatchSet.Id,Collection<PatchSetApproval>> approvals,
|
||||
boolean includeFiles, Change change) {
|
||||
|
||||
if (!ps.isEmpty()) {
|
||||
ca.patchSets = new ArrayList<PatchSetAttribute>(ps.size());
|
||||
for (PatchSet p : ps) {
|
||||
@@ -127,6 +140,9 @@ public class EventFactory {
|
||||
addApprovals(psa, p.getId(), approvals);
|
||||
}
|
||||
ca.patchSets.add(psa);
|
||||
if (includeFiles && change != null) {
|
||||
addPatchSetFileNames(psa, change, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,6 +161,21 @@ public class EventFactory {
|
||||
}
|
||||
}
|
||||
|
||||
public void addPatchSetFileNames(PatchSetAttribute patchSetAttribute,
|
||||
Change change, PatchSet patchSet) {
|
||||
PatchList patchList = patchListCache.get(change, patchSet);
|
||||
for (PatchListEntry patch : patchList.getPatches()) {
|
||||
if (patchSetAttribute.files == null) {
|
||||
patchSetAttribute.files = new ArrayList<PatchAttribute>();
|
||||
}
|
||||
|
||||
PatchAttribute p = new PatchAttribute();
|
||||
p.file = patch.getNewName();
|
||||
p.type = patch.getChangeType();
|
||||
patchSetAttribute.files.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
public void addComments(ChangeAttribute ca,
|
||||
Collection<ChangeMessage> messages) {
|
||||
if (!messages.isEmpty()) {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright (C) 2011 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.events;
|
||||
|
||||
import com.google.gerrit.reviewdb.Patch.ChangeType;
|
||||
|
||||
public class PatchAttribute {
|
||||
public String file;
|
||||
public ChangeType type;
|
||||
}
|
||||
@@ -25,4 +25,5 @@ public class PatchSetAttribute {
|
||||
|
||||
public List<ApprovalAttribute> approvals;
|
||||
public List<PatchSetCommentAttribute> comments;
|
||||
public List<PatchAttribute> files;
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@ public class QueryProcessor {
|
||||
private boolean includeCurrentPatchSet;
|
||||
private boolean includeApprovals;
|
||||
private boolean includeComments;
|
||||
private boolean includeFiles;
|
||||
|
||||
private OutputStream outputStream = DisabledOutputStream.INSTANCE;
|
||||
private PrintWriter out;
|
||||
@@ -106,6 +107,10 @@ public class QueryProcessor {
|
||||
includeComments = on;
|
||||
}
|
||||
|
||||
public void setIncludeFiles(boolean on) {
|
||||
includeFiles = on;
|
||||
}
|
||||
|
||||
public void setOutput(OutputStream out, OutputFormat fmt) {
|
||||
this.outputStream = out;
|
||||
this.outputFormat = fmt;
|
||||
@@ -173,8 +178,14 @@ public class QueryProcessor {
|
||||
eventFactory.addTrackingIds(c, d.trackingIds(db));
|
||||
|
||||
if (includePatchSets) {
|
||||
eventFactory.addPatchSets(c, d.patches(db),
|
||||
includeApprovals ? d.approvalsMap(db) : null);
|
||||
if (includeFiles) {
|
||||
eventFactory.addPatchSets(c, d.patches(db),
|
||||
includeApprovals ? d.approvalsMap(db) : null,
|
||||
includeFiles, d.change(db));
|
||||
} else {
|
||||
eventFactory.addPatchSets(c, d.patches(db),
|
||||
includeApprovals ? d.approvalsMap(db) : null);
|
||||
}
|
||||
}
|
||||
|
||||
if (includeCurrentPatchSet) {
|
||||
@@ -183,6 +194,11 @@ public class QueryProcessor {
|
||||
c.currentPatchSet = eventFactory.asPatchSetAttribute(current);
|
||||
eventFactory.addApprovals(c.currentPatchSet, //
|
||||
d.approvalsFor(db, current.getId()));
|
||||
|
||||
if (includeFiles) {
|
||||
eventFactory.addPatchSetFileNames(c.currentPatchSet,
|
||||
d.change(db), d.currentPatchSet(db));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user