diff --git a/Documentation/cmd-query.txt b/Documentation/cmd-query.txt index b20ac92cc2..bc3950b2ca 100644 --- a/Documentation/cmd-query.txt +++ b/Documentation/cmd-query.txt @@ -12,6 +12,7 @@ SYNOPSIS [--format {TEXT | JSON}] [--current-patch-set] [--patch-sets | --all-approvals] + [--files] [--comments] [--] @@ -59,6 +60,10 @@ OPTIONS the --current-patch-set flag then the current patch set 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:: Include comments for all changes. If combined with the --patch-sets flag then all in-line comments are included for diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/events/EventFactory.java b/gerrit-server/src/main/java/com/google/gerrit/server/events/EventFactory.java index 6b60ee122c..58105333f8 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/events/EventFactory.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/events/EventFactory.java @@ -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 urlProvider; private final ApprovalTypes approvalTypes; + private final PatchListCache patchListCache; @Inject EventFactory(AccountCache accountCache, @CanonicalWebUrl @Nullable Provider 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 ps) { - addPatchSets(a, ps, null); + addPatchSets(a, ps, null, false, null); } public void addPatchSets(ChangeAttribute ca, Collection ps, Map> approvals) { + addPatchSets(ca, ps, approvals, false, null); + } + + public void addPatchSets(ChangeAttribute ca, Collection ps, + Map> approvals, + boolean includeFiles, Change change) { + if (!ps.isEmpty()) { ca.patchSets = new ArrayList(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 p = new PatchAttribute(); + p.file = patch.getNewName(); + p.type = patch.getChangeType(); + patchSetAttribute.files.add(p); + } + } + public void addComments(ChangeAttribute ca, Collection messages) { if (!messages.isEmpty()) { diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/events/PatchAttribute.java b/gerrit-server/src/main/java/com/google/gerrit/server/events/PatchAttribute.java new file mode 100644 index 0000000000..2b08fa763e --- /dev/null +++ b/gerrit-server/src/main/java/com/google/gerrit/server/events/PatchAttribute.java @@ -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; +} diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/events/PatchSetAttribute.java b/gerrit-server/src/main/java/com/google/gerrit/server/events/PatchSetAttribute.java index ee293146d0..dca44384ca 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/events/PatchSetAttribute.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/events/PatchSetAttribute.java @@ -25,4 +25,5 @@ public class PatchSetAttribute { public List approvals; public List comments; + public List files; } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/query/change/QueryProcessor.java b/gerrit-server/src/main/java/com/google/gerrit/server/query/change/QueryProcessor.java index 2abec9a1a2..2143b813fc 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/query/change/QueryProcessor.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/query/change/QueryProcessor.java @@ -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)); + } } } diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/Query.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/Query.java index b6f5d2627c..ff8d6bd38f 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/Query.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/Query.java @@ -56,6 +56,11 @@ class Query extends BaseCommand { 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") private List query;