Merge "Improve documentation of buck settings override"
diff --git a/Documentation/rest-api-accounts.txt b/Documentation/rest-api-accounts.txt
index 7db83a4..02bb549 100644
--- a/Documentation/rest-api-accounts.txt
+++ b/Documentation/rest-api-accounts.txt
@@ -977,12 +977,15 @@
 |Field Name    ||Description
 |`_account_id` ||The numeric ID of the account.
 |`name`        |optional|The full name of the user. +
-Only set if detailed account information is requested.
+Only set if link:rest-api-changes.html#detailed-accounts[detailed
+account information] is requested.
 |`email`       |optional|
 The email address the user prefers to be contacted through. +
-Only set if detailed account information is requested.
+Only set if link:rest-api-changes.html#detailed-accounts[detailed
+account information] is requested.
 |`username`    |optional|The username of the user. +
-Only set if detailed account information is requested.
+Only set if link:rest-api-changes.html#detailed-accounts[detailed
+account information] is requested.
 |===========================
 
 [[account-input]]
diff --git a/Documentation/rest-api-changes.txt b/Documentation/rest-api-changes.txt
index 08411f5..8c1fa16 100644
--- a/Documentation/rest-api-changes.txt
+++ b/Documentation/rest-api-changes.txt
@@ -209,8 +209,8 @@
 
 [[detailed-accounts]]
 --
-* `DETAILED_ACCOUNTS`: include `_account_id` and `email` fields when
-  referencing accounts.
+* `DETAILED_ACCOUNTS`: include `_account_id`, `email` and `username`
+  fields when referencing accounts.
 --
 
 [[messages]]
@@ -422,7 +422,8 @@
     "owner": {
       "_account_id": 1000096,
       "name": "John Doe",
-      "email": "john.doe@example.com"
+      "email": "john.doe@example.com",
+      "username": "jdoe"
     },
     "labels": {
       "Verified": {
@@ -431,13 +432,15 @@
             "value": 0,
             "_account_id": 1000096,
             "name": "John Doe",
-            "email": "john.doe@example.com"
+            "email": "john.doe@example.com",
+            "username": "jdoe"
           },
           {
             "value": 0,
             "_account_id": 1000097,
             "name": "Jane Roe",
-            "email": "jane.roe@example.com"
+            "email": "jane.roe@example.com",
+            "username": "jroe"
           }
         ],
         "values": {
@@ -450,25 +453,29 @@
         "recommended": {
           "_account_id": 1000097,
           "name": "Jane Roe",
-          "email": "jane.roe@example.com"
+          "email": "jane.roe@example.com",
+          "username": "jroe"
         },
         "disliked": {
           "_account_id": 1000096,
           "name": "John Doe",
-          "email": "john.doe@example.com"
+          "email": "john.doe@example.com",
+          "username": "jdoe"
         },
         "all": [
           {
             "value": -1,
             "_account_id": 1000096,
             "name": "John Doe",
-            "email": "john.doe@example.com"
+            "email": "john.doe@example.com",
+            "username": "jdoe"
           },
           {
             "value": 1,
             "_account_id": 1000097,
             "name": "Jane Roe",
-            "email": "jane.roe@example.com"
+            "email": "jane.roe@example.com",
+            "username": "jroe"
           }
         ]
         "values": {
@@ -498,12 +505,14 @@
       {
         "_account_id": 1000096,
         "name": "John Doe",
-        "email": "john.doe@example.com"
+        "email": "john.doe@example.com",
+        "username": "jdoe"
       },
       {
         "_account_id": 1000097,
         "name": "Jane Roe",
-        "email": "jane.roe@example.com"
+        "email": "jane.roe@example.com",
+        "username": "jroe"
       }
     ],
     "messages": [
@@ -512,7 +521,8 @@
         "author": {
           "_account_id": 1000096,
           "name": "John Doe",
-          "email": "john.doe@example.com"
+          "email": "john.doe@example.com",
+          "username": "jdoe"
         },
         "updated": "2013-03-23 21:34:02.419000000",
         "message": "Patch Set 1:\n\nThis is the first message.",
@@ -523,7 +533,8 @@
         "author": {
           "_account_id": 1000097,
           "name": "Jane Roe",
-          "email": "jane.roe@example.com"
+          "email": "jane.roe@example.com",
+          "username": "jroe"
         },
         "updated": "2013-03-23 21:36:52.332000000",
         "message": "Patch Set 1:\n\nThis is the second message.\n\nWith a line break.",
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectInfoScreen.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectInfoScreen.java
index 7ec0844..f4db4ff 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectInfoScreen.java
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectInfoScreen.java
@@ -326,6 +326,9 @@
   }
 
   private void initProjectActions(ConfigInfo info) {
+    actionsGrid.clear(true);
+    actionsGrid.removeAllRows();
+
     NativeMap<ActionInfo> actions = info.actions();
     if (actions == null || actions.isEmpty()) {
       return;
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/ChangeUtil.java b/gerrit-server/src/main/java/com/google/gerrit/server/ChangeUtil.java
index 560bee3..3c460b8 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/ChangeUtil.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/ChangeUtil.java
@@ -15,8 +15,12 @@
 package com.google.gerrit.server;
 
 import static com.google.gerrit.server.change.PatchSetInserter.ValidatePolicy.RECEIVE_COMMITS;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.concurrent.TimeUnit.MINUTES;
+import static java.util.concurrent.TimeUnit.SECONDS;
 
 import com.google.common.annotations.VisibleForTesting;
+import com.google.common.primitives.Ints;
 import com.google.gerrit.common.ChangeHooks;
 import com.google.gerrit.common.errors.EmailException;
 import com.google.gerrit.reviewdb.client.Change;
@@ -80,8 +84,14 @@
 import java.util.regex.Matcher;
 
 public class ChangeUtil {
+  /**
+   * Epoch for sort key calculations, Tue Sep 30 2008 17:00:00.
+   * <p>
+   * We overrun approximately 4,083 years later, so ~6092.
+   */
   @VisibleForTesting
-  public static final long SORT_KEY_EPOCH = 1222819200L; // Oct 1 2008 00:00
+  public static final long SORT_KEY_EPOCH_MINS =
+      MINUTES.convert(1222819200L, SECONDS);
 
   private static final Object uuidLock = new Object();
   private static final int SEED = 0x2418e6f9;
@@ -465,14 +475,12 @@
     db.patchSets().delete(Collections.singleton(patch));
   }
 
-  public static String sortKey(long lastUpdated, int id){
-    // The encoding uses minutes since Wed Oct 1 00:00:00 2008 UTC.
-    // We overrun approximately 4,085 years later, so ~6093.
-    //
-    final long lastUpdatedOn = (lastUpdated / 1000L) - SORT_KEY_EPOCH;
-    final StringBuilder r = new StringBuilder(16);
+  public static String sortKey(long lastUpdatedMs, int id){
+    long lastUpdatedMins = MINUTES.convert(lastUpdatedMs, MILLISECONDS);
+    long minsSinceEpoch = lastUpdatedMins - SORT_KEY_EPOCH_MINS;
+    StringBuilder r = new StringBuilder(16);
     r.setLength(16);
-    formatHexInt(r, 0, (int) (lastUpdatedOn / 60));
+    formatHexInt(r, 0, Ints.checkedCast(minsSinceEpoch));
     formatHexInt(r, 8, id);
     return r.toString();
   }
@@ -484,10 +492,10 @@
     return Long.parseLong(sortKey, 16);
   }
 
-  public static void computeSortKey(final Change c) {
-    long lastUpdated = c.getLastUpdatedOn().getTime();
+  public static void computeSortKey(Change c) {
+    long lastUpdatedMs = c.getLastUpdatedOn().getTime();
     int id = c.getId().get();
-    c.setSortKey(sortKey(lastUpdated, id));
+    c.setSortKey(sortKey(lastUpdatedMs, id));
   }
 
   public static PatchSet.Id nextPatchSetId(Map<String, Ref> allRefs,
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountInfo.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountInfo.java
index cde59e1..7498002 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountInfo.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountInfo.java
@@ -38,6 +38,7 @@
         Collections.unmodifiableSet(EnumSet.of(
             FillOptions.NAME,
             FillOptions.EMAIL,
+            FillOptions.USERNAME,
             FillOptions.AVATARS));
 
     public interface Factory {
diff --git a/gerrit-server/src/test/java/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java b/gerrit-server/src/test/java/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java
index 9829c98..e57ceab 100644
--- a/gerrit-server/src/test/java/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java
+++ b/gerrit-server/src/test/java/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java
@@ -14,6 +14,9 @@
 
 package com.google.gerrit.server.query.change;
 
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.concurrent.TimeUnit.MINUTES;
+import static java.util.concurrent.TimeUnit.DAYS;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
@@ -85,7 +88,9 @@
   protected Account.Id userId;
   protected CurrentUser user;
   protected int clockStepMs = 1;
-  private long ts = ChangeUtil.SORT_KEY_EPOCH * 1000;
+  private long clockMs =
+      MILLISECONDS.convert(ChangeUtil.SORT_KEY_EPOCH_MINS, MINUTES)
+      + MILLISECONDS.convert(60, DAYS);
 
   protected abstract Injector createInjector();
 
@@ -416,8 +421,8 @@
 
     Change change = new Change(new Change.Key(key), id, ownerId,
         new Branch.NameKey(project, branch));
-    change.setLastUpdatedOn(new Timestamp(ts));
-    ts += clockStepMs;
+    change.setLastUpdatedOn(new Timestamp(clockMs));
+    clockMs += clockStepMs;
     return changeFactory.create(
         projectControlFactory.controlFor(project,
           userFactory.create(ownerId)).controlFor(change).getRefControl(),