Merge changes from topic 'patch-set-groups-2'

* changes:
  Convert GetRelated to use patch set groups where present
  Add patch set group field to secondary index
  Add a "groups" field to PatchSet
  Add a helper for assigning commits to groups heuristically
  Add a helper to sort ChangeDatas in RevWalk order
diff --git a/.buckversion b/.buckversion
index 9c09744..46408a5 100644
--- a/.buckversion
+++ b/.buckversion
@@ -1 +1 @@
-79d36de9f5284f6e833cca81867d6088a25685fb
+8204fddf60b25a3c2090f3ef0742fca5d466d562
diff --git a/Documentation/config-labels.txt b/Documentation/config-labels.txt
index ce49d31..a40c5f3 100644
--- a/Documentation/config-labels.txt
+++ b/Documentation/config-labels.txt
@@ -243,7 +243,7 @@
 This is the case if the change was rebased onto a different parent.
 This can be used to enable sticky approvals, reducing turn-around for
 trivial rebases prior to submitting a change.
-It is recommended to enable this for the Code-Review label.
+For the pre-installed Code-Review label this is enabled by default.
 Defaults to false.
 
 [[label_copyAllScoresIfNoCodeChange]]
@@ -255,7 +255,8 @@
 the commit message is different. This can be used to enable sticky
 approvals on labels that only depend on the code, reducing turn-around
 if only the commit message is changed prior to submitting a change.
-It is recommended to enable this for the Verified label if enabled.
+For the Verified label that is installed by the link:pgm-init.html[init]
+site program this is enabled by default.
 Defaults to false.
 
 [[label_copyAllScoresIfNoChange]]
diff --git a/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/Resources.java b/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/Resources.java
index c4e2167..0db7ea4 100644
--- a/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/Resources.java
+++ b/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/Resources.java
@@ -18,90 +18,90 @@
 import com.google.gwt.resources.client.ImageResource;
 
 public interface Resources extends ClientBundle {
+  @Source("addFileComment.png")
+  public ImageResource addFileComment();
+
+  @Source("arrowDown.png")
+  public ImageResource arrowDown();
+
   @Source("arrowRight.png")
   public ImageResource arrowRight();
 
   @Source("arrowUp.png")
   public ImageResource arrowUp();
 
-  @Source("arrowDown.png")
-  public ImageResource arrowDown();
-
-  @Source("editText.png")
-  public ImageResource edit();
-
-  @Source("mediaFloppy.png")
-  public ImageResource save();
-
-  @Source("starOpen.png")
-  public ImageResource starOpen();
-
-  @Source("starFilled.png")
-  public ImageResource starFilled();
-
-  @Source("greenCheck.png")
-  public ImageResource greenCheck();
-
-  @Source("redNot.png")
-  public ImageResource redNot();
-
-  @Source("editUndo.png")
-  public ImageResource editUndo();
-
-  @Source("downloadIcon.png")
-  public ImageResource downloadIcon();
-
-  @Source("queryIcon.png")
-  public ImageResource queryIcon();
-
-  @Source("addFileComment.png")
-  public ImageResource addFileComment();
-
-  @Source("diffy26.png")
-  public ImageResource gerritAvatar26();
-
-  @Source("draftComments.png")
-  public ImageResource draftComments();
-
-  @Source("readOnly.png")
-  public ImageResource readOnly();
-
-  @Source("gear.png")
-  public ImageResource gear();
-
-  @Source("info.png")
-  public ImageResource info();
-
-  @Source("warning.png")
-  public ImageResource warning();
-
-  @Source("listAdd.png")
-  public ImageResource listAdd();
-
-  @Source("merge.png")
-  public ImageResource merge();
+  @Source("deleteHover.png")
+  public ImageResource deleteHover();
 
   @Source("deleteNormal.png")
   public ImageResource deleteNormal();
 
-  @Source("deleteHover.png")
-  public ImageResource deleteHover();
+  @Source("diffy26.png")
+  public ImageResource gerritAvatar26();
 
-  @Source("undoNormal.png")
-  public ImageResource undoNormal();
+  @Source("downloadIcon.png")
+  public ImageResource downloadIcon();
 
-  @Source("goPrev.png")
-  public ImageResource goPrev();
+  @Source("draftComments.png")
+  public ImageResource draftComments();
+
+  @Source("editText.png")
+  public ImageResource edit();
+
+  @Source("editUndo.png")
+  public ImageResource editUndo();
+
+  @Source("gear.png")
+  public ImageResource gear();
 
   @Source("goNext.png")
   public ImageResource goNext();
 
+  @Source("goPrev.png")
+  public ImageResource goPrev();
+
   @Source("goUp.png")
   public ImageResource goUp();
 
+  @Source("greenCheck.png")
+  public ImageResource greenCheck();
+
+  @Source("info.png")
+  public ImageResource info();
+
+  @Source("listAdd.png")
+  public ImageResource listAdd();
+
+  @Source("mediaFloppy.png")
+  public ImageResource save();
+
+  @Source("merge.png")
+  public ImageResource merge();
+
+  @Source("queryIcon.png")
+  public ImageResource queryIcon();
+
+  @Source("readOnly.png")
+  public ImageResource readOnly();
+
+  @Source("redNot.png")
+  public ImageResource redNot();
+
   @Source("sideBySideDiff.png")
   public ImageResource sideBySideDiff();
 
+  @Source("starFilled.png")
+  public ImageResource starFilled();
+
+  @Source("starOpen.png")
+  public ImageResource starOpen();
+
+  @Source("undoNormal.png")
+  public ImageResource undoNormal();
+
   @Source("unifiedDiff.png")
   public ImageResource unifiedDiff();
+
+  @Source("warning.png")
+  public ImageResource warning();
 }
diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitLabels.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitLabels.java
index 8fb05ca..b6b4cc1 100644
--- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitLabels.java
+++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitLabels.java
@@ -26,6 +26,8 @@
 
 @Singleton
 public class InitLabels implements InitStep {
+  private static final String KEY_COPY_ALL_SCORES_IF_NO_CODE_CHANGE =
+      "copyAllScoresIfNoCodeChange";
   private static final String KEY_LABEL = "label";
   private static final String KEY_FUNCTION = "function";
   private static final String KEY_VALUE = "value";
@@ -58,6 +60,7 @@
       cfg.setString(KEY_LABEL, LABEL_VERIFIED, KEY_FUNCTION, "MaxWithBlock");
       cfg.setStringList(KEY_LABEL, LABEL_VERIFIED, KEY_VALUE,
           Arrays.asList(new String[] {"-1 Fails", " 0 No score", "+1 Verified"}));
+      cfg.setBoolean(KEY_LABEL, LABEL_VERIFIED, KEY_COPY_ALL_SCORES_IF_NO_CODE_CHANGE, true);
       allProjectsConfig.save("Configure 'Verified' label");
     }
   }
diff --git a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/Account.java b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/Account.java
index d4fb311..2750380 100644
--- a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/Account.java
+++ b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/Account.java
@@ -14,7 +14,7 @@
 
 package com.google.gerrit.reviewdb.client;
 
-import static com.google.gerrit.reviewdb.client.RefNames.REFS_USER;
+import static com.google.gerrit.reviewdb.client.RefNames.REFS_USERS;
 
 import com.google.gwtorm.client.Column;
 import com.google.gwtorm.client.IntKey;
@@ -111,8 +111,8 @@
       if (name == null) {
         return null;
       }
-      if (name.startsWith(REFS_USER)) {
-        return fromRefPart(name.substring(REFS_USER.length()));
+      if (name.startsWith(REFS_USERS)) {
+        return fromRefPart(name.substring(REFS_USERS.length()));
       }
       return null;
     }
diff --git a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/RefNames.java b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/RefNames.java
index e6015e6..4154913 100644
--- a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/RefNames.java
+++ b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/RefNames.java
@@ -30,7 +30,10 @@
   public static final String REFS_CONFIG = "refs/meta/config";
 
   /** Preference settings for a user {@code refs/users} */
-  public static final String REFS_USER = "refs/users/";
+  public static final String REFS_USERS = "refs/users/";
+
+  /** Default user preference settings */
+  public static final String REFS_USERS_DEFAULT = RefNames.REFS_USERS + "default";
 
   /** Configurations of project-specific dashboards (canned search queries). */
   public static final String REFS_DASHBOARDS = "refs/meta/dashboards/";
@@ -64,7 +67,7 @@
 
   public static String refsUsers(Account.Id accountId) {
     StringBuilder r = new StringBuilder();
-    r.append(REFS_USER);
+    r.append(REFS_USERS);
     int account = accountId.get();
     int m = account % 100;
     if (m < 10) {
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/VersionedAccountPreferences.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/VersionedAccountPreferences.java
index c4d4b06..da7d141 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/account/VersionedAccountPreferences.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/VersionedAccountPreferences.java
@@ -27,7 +27,6 @@
 
 /** Preferences for user accounts. */
 public class VersionedAccountPreferences extends VersionedMetaData {
-  private static final String REFS_USER_DEFAULT = RefNames.REFS_USER + "default";
   private static final String PREFERENCES = "preferences.config";
 
   public static VersionedAccountPreferences forUser(Account.Id id) {
@@ -35,7 +34,7 @@
   }
 
   public static VersionedAccountPreferences forDefault() {
-    return new VersionedAccountPreferences(REFS_USER_DEFAULT);
+    return new VersionedAccountPreferences(RefNames.REFS_USERS_DEFAULT);
   }
 
   private final String ref;
@@ -46,7 +45,7 @@
   }
 
   public boolean isDefaults() {
-    return REFS_USER_DEFAULT.equals(getRefName());
+    return RefNames.REFS_USERS_DEFAULT.equals(getRefName());
   }
 
   @Override
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/MergeUtil.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/MergeUtil.java
index b123429..da38a58 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/git/MergeUtil.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/MergeUtil.java
@@ -677,7 +677,7 @@
       }
 
       @Override
-      public void release() {
+      public void close() {
       }
     });
     return (ThreeWayMerger) m;
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListLoader.java b/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListLoader.java
index c381261..b8caa62 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListLoader.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListLoader.java
@@ -338,7 +338,7 @@
         }
 
         @Override
-        public void release() {
+        public void close() {
         }
       });
 
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/project/ListBranches.java b/gerrit-server/src/main/java/com/google/gerrit/server/project/ListBranches.java
index 85a9264..8195c2a 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/project/ListBranches.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/project/ListBranches.java
@@ -113,10 +113,11 @@
     try (Repository db = repoManager.openRepository(rsrc.getNameKey())) {
       Collection<Ref> heads =
           db.getRefDatabase().getRefs(Constants.R_HEADS).values();
-      refs = new ArrayList<>(heads.size() + 2);
+      refs = new ArrayList<>(heads.size() + 3);
       refs.addAll(heads);
       addRef(db, refs, Constants.HEAD);
       addRef(db, refs, RefNames.REFS_CONFIG);
+      addRef(db, refs, RefNames.REFS_USERS_DEFAULT);
     } catch (RepositoryNotFoundException noGitRepository) {
       throw new ResourceNotFoundException();
     }
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/schema/AclUtil.java b/gerrit-server/src/main/java/com/google/gerrit/server/schema/AclUtil.java
new file mode 100644
index 0000000..ced8cd0
--- /dev/null
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/schema/AclUtil.java
@@ -0,0 +1,59 @@
+// Copyright (C) 2015 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.schema;
+
+import com.google.gerrit.common.data.AccessSection;
+import com.google.gerrit.common.data.GroupReference;
+import com.google.gerrit.common.data.LabelType;
+import com.google.gerrit.common.data.Permission;
+import com.google.gerrit.common.data.PermissionRule;
+import com.google.gerrit.server.git.ProjectConfig;
+
+public class AclUtil {
+  public static void grant(ProjectConfig config, AccessSection section,
+      String permission, GroupReference... groupList) {
+    grant(config, section, permission, false, groupList);
+  }
+
+  public static void grant(ProjectConfig config, AccessSection section,
+      String permission, boolean force, GroupReference... groupList) {
+    Permission p = section.getPermission(permission, true);
+    for (GroupReference group : groupList) {
+      if (group != null) {
+        PermissionRule r = rule(config, group);
+        r.setForce(force);
+        p.add(r);
+      }
+    }
+  }
+
+  public static void grant(ProjectConfig config,
+      AccessSection section, LabelType type,
+      int min, int max, GroupReference... groupList) {
+    String name = Permission.LABEL + type.getName();
+    Permission p = section.getPermission(name, true);
+    for (GroupReference group : groupList) {
+      if (group != null) {
+        PermissionRule r = rule(config, group);
+        r.setRange(min, max);
+        p.add(r);
+      }
+    }
+  }
+
+  public static PermissionRule rule(ProjectConfig config, GroupReference group) {
+    return new PermissionRule(config.resolve(group));
+  }
+}
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/schema/AllProjectsCreator.java b/gerrit-server/src/main/java/com/google/gerrit/server/schema/AllProjectsCreator.java
index 1eefbf9..1198176 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/schema/AllProjectsCreator.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/schema/AllProjectsCreator.java
@@ -17,6 +17,8 @@
 import static com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS;
 import static com.google.gerrit.server.group.SystemGroupBackend.PROJECT_OWNERS;
 import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
+import static com.google.gerrit.server.schema.AclUtil.grant;
+import static com.google.gerrit.server.schema.AclUtil.rule;
 
 import com.google.common.base.MoreObjects;
 import com.google.common.base.Strings;
@@ -183,41 +185,6 @@
     config.commitToNewRef(md, RefNames.REFS_CONFIG);
   }
 
-  private void grant(ProjectConfig config, AccessSection section,
-      String permission, GroupReference... groupList) {
-    grant(config, section, permission, false, groupList);
-  }
-
-  private void grant(ProjectConfig config, AccessSection section,
-      String permission, boolean force, GroupReference... groupList) {
-    Permission p = section.getPermission(permission, true);
-    for (GroupReference group : groupList) {
-      if (group != null) {
-        PermissionRule r = rule(config, group);
-        r.setForce(force);
-        p.add(r);
-      }
-    }
-  }
-
-  private void grant(ProjectConfig config,
-      AccessSection section, LabelType type,
-      int min, int max, GroupReference... groupList) {
-    String name = Permission.LABEL + type.getName();
-    Permission p = section.getPermission(name, true);
-    for (GroupReference group : groupList) {
-      if (group != null) {
-        PermissionRule r = rule(config, group);
-        r.setRange(min, max);
-        p.add(r);
-      }
-    }
-  }
-
-  private PermissionRule rule(ProjectConfig config, GroupReference group) {
-    return new PermissionRule(config.resolve(group));
-  }
-
   public static LabelType initCodeReviewLabel(ProjectConfig c) {
     LabelType type = new LabelType("Code-Review", ImmutableList.of(
         new LabelValue((short) 2, "Looks good to me, approved"),
@@ -226,6 +193,7 @@
         new LabelValue((short) -1, "I would prefer this is not merged as is"),
         new LabelValue((short) -2, "This shall not be merged")));
     type.setCopyMinScore(true);
+    type.setCopyAllScoresOnTrivialRebase(true);
     c.getLabelSections().put(type.getName(), type);
     return type;
   }
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/schema/AllUsersCreator.java b/gerrit-server/src/main/java/com/google/gerrit/server/schema/AllUsersCreator.java
index fda5306..3fa7986 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/schema/AllUsersCreator.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/schema/AllUsersCreator.java
@@ -14,8 +14,11 @@
 
 package com.google.gerrit.server.schema;
 
+import static com.google.gerrit.server.schema.AclUtil.grant;
+
 import com.google.gerrit.common.Version;
 import com.google.gerrit.common.data.AccessSection;
+import com.google.gerrit.common.data.GroupReference;
 import com.google.gerrit.common.data.Permission;
 import com.google.gerrit.reviewdb.client.Project;
 import com.google.gerrit.reviewdb.client.RefNames;
@@ -40,6 +43,8 @@
   private final AllUsersName allUsersName;
   private final PersonIdent serverUser;
 
+  private GroupReference admin;
+
   @Inject
   AllUsersCreator(
       GitRepositoryManager mgr,
@@ -50,6 +55,11 @@
     this.serverUser = serverUser;
   }
 
+  public AllUsersCreator setAdministrators(GroupReference admin) {
+    this.admin = admin;
+    return this;
+  }
+
   public void create() throws IOException, ConfigInvalidException {
     Repository git = null;
     try {
@@ -84,8 +94,17 @@
     Project project = config.getProject();
     project.setDescription("Individual user settings and preferences.");
 
-    AccessSection all = config.getAccessSection(RefNames.REFS_USER + "*", true);
+    AccessSection all = config.getAccessSection(RefNames.REFS_USERS + "*", true);
     all.getPermission(Permission.READ, true).setExclusiveGroup(true);
+
+    AccessSection defaults = config.getAccessSection(RefNames.REFS_USERS_DEFAULT, true);
+    defaults.getPermission(Permission.READ, true).setExclusiveGroup(true);
+    grant(config, defaults, Permission.READ, admin);
+    defaults.getPermission(Permission.PUSH, true).setExclusiveGroup(true);
+    grant(config, defaults, Permission.PUSH, admin);
+    defaults.getPermission(Permission.CREATE, true).setExclusiveGroup(true);
+    grant(config, defaults, Permission.CREATE, admin);
+
     config.commit(md);
   }
 }
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/schema/SchemaCreator.java b/gerrit-server/src/main/java/com/google/gerrit/server/schema/SchemaCreator.java
index bfb9604..2581d56 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/schema/SchemaCreator.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/schema/SchemaCreator.java
@@ -87,7 +87,9 @@
       .setAdministrators(GroupReference.forGroup(admin))
       .setBatchUsers(GroupReference.forGroup(batch))
       .create();
-    allUsersCreator.create();
+    allUsersCreator
+      .setAdministrators(GroupReference.forGroup(admin))
+      .create();
     dataSourceType.getIndexScript().run(db);
   }
 
diff --git a/lib/jgit/BUCK b/lib/jgit/BUCK
index dcefb64..9dc2e73 100644
--- a/lib/jgit/BUCK
+++ b/lib/jgit/BUCK
@@ -1,13 +1,13 @@
 include_defs('//lib/maven.defs')
 
-REPO = MAVEN_CENTRAL # Leave here even if set to MAVEN_CENTRAL.
-VERS = '4.0.0.201505050340-m2'
+REPO = GERRIT # Leave here even if set to MAVEN_CENTRAL.
+VERS = '4.0.0.201505191015-rc1.19-g1773002'
 
 maven_jar(
   name = 'jgit',
   id = 'org.eclipse.jgit:org.eclipse.jgit:' + VERS,
-  bin_sha1 = '1cc3120d39ed2b55584e631634e65c5d2e6c1cf7',
-  src_sha1 = '425f578cc9d5ccb8f3b050a5ab1e2d7a0becb25d',
+  bin_sha1 = '4db24b39dab8dc0e889807383728032945f461be',
+  src_sha1 = '1723a2855f50493b7c0b216aae97909a7ea59962',
   license = 'jgit',
   repository = REPO,
   unsign = True,
@@ -22,7 +22,7 @@
 maven_jar(
   name = 'jgit-servlet',
   id = 'org.eclipse.jgit:org.eclipse.jgit.http.server:' + VERS,
-  sha1 = '2a9f55d1d92afef795542b995db6ab261007857f',
+  sha1 = '7bfdbddea56a87f3f2687ae6abf2c5bdae649f0c',
   license = 'jgit',
   repository = REPO,
   deps = [':jgit'],
@@ -36,7 +36,7 @@
 maven_jar(
   name = 'jgit-archive',
   id = 'org.eclipse.jgit:org.eclipse.jgit.archive:' + VERS,
-  sha1 = 'ee3954753067818f8f734981a01c13ac33425f2c',
+  sha1 = '08fce6b89f6d1e78f99869d542d70899f3be9c9f',
   license = 'jgit',
   repository = REPO,
   deps = [':jgit',
@@ -53,7 +53,7 @@
 maven_jar(
   name = 'junit',
   id = 'org.eclipse.jgit:org.eclipse.jgit.junit:' + VERS,
-  sha1 = '6cc19f8f0a1791e26d4225625ecba6a31d9b830e',
+  sha1 = 'a54c16076e6cbdb9113565a82cffa5f268ae8e3b',
   license = 'DO_NOT_DISTRIBUTE',
   repository = REPO,
   unsign = True,