summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Hamalainen <mika.hamalainen@accenture.com>2011-08-18 10:51:11 +0300
committerMika Hamalainen <mika.hamalainen@accenture.com>2011-08-18 12:04:33 +0300
commit7cf342c74c77ea88fc0de1512de1fdf1a09d84a0 (patch)
treeffd2e9270574ba7cd785d7eec4edadac7a511d54
parent9cb9b1a6edd6e0ce269a2589ee6df62171024c2c (diff)
Fixed staging-ls destination branch check
The destination branch check was not working correctly when listing changes in refs/staging or refs/builds. Added convertion from other branch for refs/heads when checking for destination branch. Staging-ls now requires a new paramater, --destination, to get information about the destination branch. Change-Id: I877c8d504e4eef0214f328b8cf94ed66da5b0210
-rw-r--r--gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/StagingApprove.java3
-rw-r--r--gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/StagingCommand.java45
-rw-r--r--gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/StagingListChanges.java26
-rw-r--r--gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/StagingNewBuild.java7
4 files changed, 57 insertions, 24 deletions
diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/StagingApprove.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/StagingApprove.java
index 5e2badf428..2ec11326fd 100644
--- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/StagingApprove.java
+++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/StagingApprove.java
@@ -193,7 +193,8 @@ public class StagingApprove extends BaseCommand {
openRepository(project);
// Initialize and populate open changes list.
- toApprove = StagingCommand.openChanges(git, db, buildBranchNameKey);
+ toApprove = StagingCommand.openChanges(git, db, buildBranchNameKey,
+ destination);
// Notify user that build did not have any open changes. The build has
// already been approved.
diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/StagingCommand.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/StagingCommand.java
index e30e1123ac..91fa618369 100644
--- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/StagingCommand.java
+++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/StagingCommand.java
@@ -22,6 +22,7 @@ import com.google.gerrit.reviewdb.RevId;
import com.google.gerrit.reviewdb.ReviewDb;
import com.google.gwtorm.client.OrmException;
+import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
@@ -74,7 +75,7 @@ public class StagingCommand {
*/
public static Branch.NameKey getNameKey(final String project,
final String prefix, final String branch) {
- final Project.NameKey projectKey = new Project.NameKey(project);
+ final Project.NameKey projectKey = getProjectKey(project);
if (branch.startsWith(prefix)) {
return new Branch.NameKey(projectKey, branch);
} else {
@@ -91,7 +92,7 @@ public class StagingCommand {
*/
public static Branch.NameKey getShortNameKey(final String project,
final String prefix, final String branch) {
- final Project.NameKey projectKey = new Project.NameKey(project);
+ final Project.NameKey projectKey = getProjectKey(project);
if (branch.startsWith(prefix)) {
return new Branch.NameKey(projectKey, branch.substring(prefix.length()));
} else {
@@ -99,19 +100,43 @@ public class StagingCommand {
}
}
+ public static Branch.NameKey getDestinationKey(final Branch.NameKey key) {
+ final String branch = key.get();
+ if (branch.startsWith(R_STAGING)) {
+ return new Branch.NameKey(key.getParentKey(),
+ R_HEADS + branch.substring(R_STAGING.length()));
+ } else if (branch.startsWith(R_BUILDS)) {
+ return new Branch.NameKey(key.getParentKey(),
+ R_HEADS + branch.substring(R_BUILDS.length()));
+ } else {
+ return key;
+ }
+ }
+
+ public static Project.NameKey getProjectKey(final String project) {
+ String projectName = project;
+ if (project.endsWith(Constants.DOT_GIT_EXT)) {
+ projectName = project.substring(0, //
+ project.length() - Constants.DOT_GIT_EXT.length());
+ }
+
+ return new Project.NameKey(projectName);
+ }
+
/**
* Lists open changes in a branch.
* @param git jGit Repository. Must be open.
* @param db ReviewDb of a Gerrit site.
- * @param branch Branch to search for open changes-
+ * @param branch Branch to search for open changes.
+ * @param destination Destination branch for changes.
* @return List of open changes.
* @throws IOException Thrown by Repository or RevWalk if repository is not
* accessible.
* @throws OrmException Thrown if ReviewDb is not accessible.
*/
public static List<PatchSet> openChanges(Repository git, ReviewDb db,
- final Branch.NameKey branch) throws IOException, OrmException,
- BranchNotFoundException {
+ final Branch.NameKey branch, final Branch.NameKey destination)
+ throws IOException, OrmException, BranchNotFoundException {
List<PatchSet> open = new ArrayList<PatchSet>();
PatchSetAccess patchSetAccess = db.patchSets();
@@ -138,20 +163,26 @@ public class StagingCommand {
List<PatchSet> patchSets = patchSetAccess.byRevision(revId).toList();
for (PatchSet patchSet : patchSets) {
Change.Id changeId = patchSet.getId().getParentKey();
- Change change = db.changes().get(changeId);
+ final Change change = db.changes().get(changeId);
if (change.getStatus().isOpen()) {
open.add(patchSet);
break;
}
}
} else {
+ final Branch.NameKey destinationKey =
+ getNameKey(destination.getParentKey().get(), R_HEADS,
+ destination.get());
// Change-Id footer found in commit message. Search by Change-Id
// value. Usually, there is only 1 Change-Id footer.
for (String changeId : changeIds) {
List<Change> changes =
db.changes().byKey(Change.Key.parse(changeId)).toList();
for (Change change : changes) {
- if (change.getStatus().isOpen() && change.getDest().equals(branch)) {
+ if (!change.getDest().equals(destinationKey)) {
+ continue;
+ }
+ if (change.getStatus().isOpen()) {
open.add(patchSetAccess.get(change.currentPatchSetId()));
}
}
diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/StagingListChanges.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/StagingListChanges.java
index 2b70afd510..b3fdd8f139 100644
--- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/StagingListChanges.java
+++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/StagingListChanges.java
@@ -25,7 +25,6 @@ import com.google.gwtorm.client.OrmException;
import com.google.inject.Inject;
import org.apache.sshd.server.Environment;
-import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.Repository;
import org.kohsuke.args4j.Option;
@@ -48,9 +47,13 @@ public class StagingListChanges extends BaseCommand {
private String project;
@Option(name = "--branch", aliases = {"-b"},
- required = true, usage = "branch name, e.g. refs/builds/1")
+ required = true, usage = "branch name, e.g. refs/staging/master")
private String branch;
+ @Option(name = "--destination", aliases = {"-d"},
+ required = true, usage = "desitnation branch name, e.g. refs/heads/master")
+ private String destination;
+
@Override
public void start(final Environment env) {
startThread(new CommandRunnable() {
@@ -65,15 +68,17 @@ public class StagingListChanges extends BaseCommand {
private void list() throws UnloggedFailure {
final PrintWriter stdout = toPrintWriter(out);
try {
- openRepository(project);
-
- final Project.NameKey projectKey = new Project.NameKey(project);
+ final Project.NameKey projectKey = StagingCommand.getProjectKey(project);
+ git = gitManager.openRepository(projectKey);
final Branch.NameKey branchKey = new Branch.NameKey(projectKey, branch);
- List<PatchSet> open = StagingCommand.openChanges(git, db, branchKey);
+ final Branch.NameKey destinationKey = new Branch.NameKey(projectKey,
+ destination);
+ final List<PatchSet> open = StagingCommand.openChanges(git, db,
+ branchKey, destinationKey);
for (PatchSet patchSet : open) {
- Change.Id changeId = patchSet.getId().getParentKey();
- Change change = db.changes().get(changeId);
+ final Change.Id changeId = patchSet.getId().getParentKey();
+ final Change change = db.changes().get(changeId);
if (change.getStatus().isOpen()) {
stdout.println(patchSet.getRevision().get() + " " + patchSet.getId() + " " + change.getSubject());
}
@@ -91,9 +96,4 @@ public class StagingListChanges extends BaseCommand {
}
}
}
-
- public void openRepository(final String project) throws RepositoryNotFoundException {
- Project.NameKey projectNameKey = new Project.NameKey(project);
- git = gitManager.openRepository(projectNameKey);
- }
}
diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/StagingNewBuild.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/StagingNewBuild.java
index 83cf163f6b..dd9ec56a77 100644
--- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/StagingNewBuild.java
+++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/StagingNewBuild.java
@@ -93,7 +93,8 @@ public class StagingNewBuild extends BaseCommand {
StagingCommand.getShortNameKey(project, R_STAGING, stagingBranch);
// Make sure that are changes in the staging branch.
- if (StagingCommand.openChanges(git, db, stagingBranchKey).isEmpty()) {
+ if (StagingCommand.openChanges(git, db, stagingBranchKey, branchNameKey)
+ .isEmpty()) {
stdout.println("No changes in staging branch. Not creating a build reference");
return;
}
@@ -137,10 +138,10 @@ public class StagingNewBuild extends BaseCommand {
}
private void updateChangeStatus(final Branch.NameKey buildBranchKey,
- final Branch.NameKey destBranchKey)
+ final Branch.NameKey destinationKey)
throws IOException, OrmException, BranchNotFoundException {
List<PatchSet> patchSets =
- StagingCommand.openChanges(git, db, buildBranchKey);
+ StagingCommand.openChanges(git, db, buildBranchKey, destinationKey);
for (PatchSet patchSet : patchSets) {
ChangeUtil.setIntegrating(patchSet.getId(), db);
Change change = db.changes().get(patchSet.getId().getParentKey());