Merge "Support for --file option for ssh queries."

This commit is contained in:
Shawn Pearce
2011-11-03 16:39:31 -07:00
committed by gerrit code review
6 changed files with 84 additions and 4 deletions

View File

@@ -12,6 +12,7 @@ SYNOPSIS
[--format {TEXT | JSON}] [--format {TEXT | JSON}]
[--current-patch-set] [--current-patch-set]
[--patch-sets | --all-approvals] [--patch-sets | --all-approvals]
[--files]
[--comments] [--comments]
[--] [--]
<query> <query>
@@ -59,6 +60,10 @@ OPTIONS
the --current-patch-set flag then the current patch set the --current-patch-set flag then the current patch set
information will be output twice, once in each field. information will be output twice, once in each field.
--files::
Support for listing files with patch sets and their
attributes (ADDED, MODIFIED, DELETED, RENAMED, COPIED).
--comments:: --comments::
Include comments for all changes. If combined with the Include comments for all changes. If combined with the
--patch-sets flag then all in-line comments are included for --patch-sets flag then all in-line comments are included for

View File

@@ -26,6 +26,9 @@ import com.google.gerrit.reviewdb.PatchSetApproval;
import com.google.gerrit.reviewdb.TrackingId; import com.google.gerrit.reviewdb.TrackingId;
import com.google.gerrit.server.account.AccountCache; import com.google.gerrit.server.account.AccountCache;
import com.google.gerrit.server.config.CanonicalWebUrl; 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.Inject;
import com.google.inject.Provider; import com.google.inject.Provider;
import com.google.inject.Singleton; import com.google.inject.Singleton;
@@ -43,14 +46,17 @@ public class EventFactory {
private final AccountCache accountCache; private final AccountCache accountCache;
private final Provider<String> urlProvider; private final Provider<String> urlProvider;
private final ApprovalTypes approvalTypes; private final ApprovalTypes approvalTypes;
private final PatchListCache patchListCache;
@Inject @Inject
EventFactory(AccountCache accountCache, EventFactory(AccountCache accountCache,
@CanonicalWebUrl @Nullable Provider<String> urlProvider, @CanonicalWebUrl @Nullable Provider<String> urlProvider,
ApprovalTypes approvalTypes) { ApprovalTypes approvalTypes,
PatchListCache patchListCache) {
this.accountCache = accountCache; this.accountCache = accountCache;
this.urlProvider = urlProvider; this.urlProvider = urlProvider;
this.approvalTypes = approvalTypes; this.approvalTypes = approvalTypes;
this.patchListCache = patchListCache;
} }
/** /**
@@ -114,11 +120,18 @@ public class EventFactory {
} }
public void addPatchSets(ChangeAttribute a, Collection<PatchSet> ps) { 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, public void addPatchSets(ChangeAttribute ca, Collection<PatchSet> ps,
Map<PatchSet.Id,Collection<PatchSetApproval>> approvals) { 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()) { if (!ps.isEmpty()) {
ca.patchSets = new ArrayList<PatchSetAttribute>(ps.size()); ca.patchSets = new ArrayList<PatchSetAttribute>(ps.size());
for (PatchSet p : ps) { for (PatchSet p : ps) {
@@ -127,6 +140,9 @@ public class EventFactory {
addApprovals(psa, p.getId(), approvals); addApprovals(psa, p.getId(), approvals);
} }
ca.patchSets.add(psa); 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, public void addComments(ChangeAttribute ca,
Collection<ChangeMessage> messages) { Collection<ChangeMessage> messages) {
if (!messages.isEmpty()) { if (!messages.isEmpty()) {

View File

@@ -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;
}

View File

@@ -25,4 +25,5 @@ public class PatchSetAttribute {
public List<ApprovalAttribute> approvals; public List<ApprovalAttribute> approvals;
public List<PatchSetCommentAttribute> comments; public List<PatchSetCommentAttribute> comments;
public List<PatchAttribute> files;
} }

View File

@@ -73,6 +73,7 @@ public class QueryProcessor {
private boolean includeCurrentPatchSet; private boolean includeCurrentPatchSet;
private boolean includeApprovals; private boolean includeApprovals;
private boolean includeComments; private boolean includeComments;
private boolean includeFiles;
private OutputStream outputStream = DisabledOutputStream.INSTANCE; private OutputStream outputStream = DisabledOutputStream.INSTANCE;
private PrintWriter out; private PrintWriter out;
@@ -106,6 +107,10 @@ public class QueryProcessor {
includeComments = on; includeComments = on;
} }
public void setIncludeFiles(boolean on) {
includeFiles = on;
}
public void setOutput(OutputStream out, OutputFormat fmt) { public void setOutput(OutputStream out, OutputFormat fmt) {
this.outputStream = out; this.outputStream = out;
this.outputFormat = fmt; this.outputFormat = fmt;
@@ -173,8 +178,14 @@ public class QueryProcessor {
eventFactory.addTrackingIds(c, d.trackingIds(db)); eventFactory.addTrackingIds(c, d.trackingIds(db));
if (includePatchSets) { if (includePatchSets) {
eventFactory.addPatchSets(c, d.patches(db), if (includeFiles) {
includeApprovals ? d.approvalsMap(db) : null); 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) { if (includeCurrentPatchSet) {
@@ -183,6 +194,11 @@ public class QueryProcessor {
c.currentPatchSet = eventFactory.asPatchSetAttribute(current); c.currentPatchSet = eventFactory.asPatchSetAttribute(current);
eventFactory.addApprovals(c.currentPatchSet, // eventFactory.addApprovals(c.currentPatchSet, //
d.approvalsFor(db, current.getId())); d.approvalsFor(db, current.getId()));
if (includeFiles) {
eventFactory.addPatchSetFileNames(c.currentPatchSet,
d.change(db), d.currentPatchSet(db));
}
} }
} }

View File

@@ -56,6 +56,11 @@ class Query extends BaseCommand {
processor.setIncludeComments(on); processor.setIncludeComments(on);
} }
@Option(name = "--files", usage = "Include file list on patch sets")
void setFiles(boolean on) {
processor.setIncludeFiles(on);
}
@Argument(index = 0, required = true, multiValued = true, metaVar = "QUERY", usage = "Query to execute") @Argument(index = 0, required = true, multiValued = true, metaVar = "QUERY", usage = "Query to execute")
private List<String> query; private List<String> query;