Merge changes from topic 'ref-validation-fixes' into stable-2.14

* changes:
  DeleteRef: Pass project name into validateRefOperation
  Be more consistent about object ids used in ref operation validation
diff --git a/Documentation/config-gerrit.txt b/Documentation/config-gerrit.txt
index a60cb4a..2c34b2e 100644
--- a/Documentation/config-gerrit.txt
+++ b/Documentation/config-gerrit.txt
@@ -819,10 +819,6 @@
 is per-user, so 1024 items translates to 1024 unique user accounts.
 As each individual user account may configure multiple SSH keys,
 the total number of keys may be larger than the item count.
-+
-This cache is based off the `account_ssh_keys` table and the
-`accounts.ssh_user_name` column in the database.  If either is
-modified directly, this cache should be flushed.
 
 cache `"web_sessions"`::
 +
diff --git a/Documentation/dev-bazel.txt b/Documentation/dev-bazel.txt
index fb884d3..60a56dd 100644
--- a/Documentation/dev-bazel.txt
+++ b/Documentation/dev-bazel.txt
@@ -354,14 +354,9 @@
 
 [[consume-jgit-from-development-tree]]
 
-To consume the JGit dependency from the development tree, uncomment
-`local_repository` rule for `jgit` in WORKSPACE file and uncomment
-the lines in the `lib/jgit/**/BUILD` files for `jgit` rule aliases.
-`jgit-dev=1` must be passed in to bazel:
-
-----
-  $ bazel test --define jgit-dev=1 ...
-----
+To consume the JGit dependency from the development tree, edit
+`lib/jgit/jgit.bzl` setting LOCAL_JGIT_REPO to a directory holding a
+JGit repository.
 
 [[clean-cache]]
 === Cleaning The download cache
diff --git a/WORKSPACE b/WORKSPACE
index 0d725e8..fb0a1ab 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -130,34 +130,9 @@
     sha1 = "cdb2dcb4e22b83d6b32b93095f644c3462739e82",
 )
 
-load("//lib/jgit:jgit.bzl", "JGIT_VERS", "JGIT_REPO", "JGIT_SHA1", "JGIT_SRC_SHA1", "JGIT_SERVLET_SHA1", "JGIT_ARCHIVE_SHA1", "JGIT_JUNIT_SHA1")
+load("//lib/jgit:jgit.bzl", "jgit_repos")
 
-#
-# Uncomment jgit repository to route JGit dependency to development tree.
-# Pass jgit-dev=1 in to bazel: `bazel test --define jgit-dev=1 ...`
-# Due to: https://github.com/bazelbuild/bazel/issues/2707
-# aliases to jgit should be uncommented in lib/jgit/**/BUILD files.
-#local_repository(
-#    name = "jgit",
-#    path = "/home/<user>/projects/jgit",
-#)
-
-maven_jar(
-    name = "jgit_lib",
-    artifact = "org.eclipse.jgit:org.eclipse.jgit:" + JGIT_VERS,
-    repository = JGIT_REPO,
-    sha1 = JGIT_SHA1,
-    src_sha1 = JGIT_SRC_SHA1,
-    unsign = True,
-)
-
-maven_jar(
-    name = "jgit_servlet",
-    artifact = "org.eclipse.jgit:org.eclipse.jgit.http.server:" + JGIT_VERS,
-    repository = JGIT_REPO,
-    sha1 = JGIT_SERVLET_SHA1,
-    unsign = True,
-)
+jgit_repos()
 
 maven_jar(
     name = "javaewah",
@@ -167,21 +142,6 @@
 )
 
 maven_jar(
-    name = "jgit_archive",
-    artifact = "org.eclipse.jgit:org.eclipse.jgit.archive:" + JGIT_VERS,
-    repository = JGIT_REPO,
-    sha1 = JGIT_ARCHIVE_SHA1,
-)
-
-maven_jar(
-    name = "jgit_junit",
-    artifact = "org.eclipse.jgit:org.eclipse.jgit.junit:" + JGIT_VERS,
-    repository = JGIT_REPO,
-    sha1 = JGIT_JUNIT_SHA1,
-    unsign = True,
-)
-
-maven_jar(
     name = "gwtjsonrpc",
     artifact = "com.google.gerrit:gwtjsonrpc:1.11",
     sha1 = "0990e7eec9eec3a15661edcf9232acbac4aeacec",
@@ -449,8 +409,8 @@
 
 maven_jar(
     name = "auto_value",
-    artifact = "com.google.auto.value:auto-value:1.4-rc3",
-    sha1 = "b58e82f70576a951146ca61a00ef26806f8c4667",
+    artifact = "com.google.auto.value:auto-value:1.4",
+    sha1 = "6d1448fcd13074bd3658ef915022410b7c48343b",
 )
 
 maven_jar(
@@ -623,8 +583,8 @@
 
 maven_jar(
     name = "dropwizard_core",
-    artifact = "io.dropwizard.metrics:metrics-core:3.2.1",
-    sha1 = "f453a6b2660c369c62b83ded443391ae1bfd23a0",
+    artifact = "io.dropwizard.metrics:metrics-core:3.2.2",
+    sha1 = "cd9886f498ee2ab2d994f0c779e5553b2c450416",
 )
 
 # This version must match the version that also appears in
@@ -713,6 +673,13 @@
     sha1 = "42a25dc3219429f0e5d060061f71acb49bf010a0",
 )
 
+# Only needed when jgit is built from the development tree
+maven_jar(
+    name = "hamcrest_library",
+    artifact = "org.hamcrest:hamcrest-library:1.3",
+    sha1 = "4785a3c21320980282f9f33d0d1264a69040538f",
+)
+
 TRUTH_VERS = "0.32"
 
 maven_jar(
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/ArchiveFormat.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/ArchiveFormat.java
index 73ef23e..3fefcd4 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/change/ArchiveFormat.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/ArchiveFormat.java
@@ -68,6 +68,10 @@
     @SuppressWarnings("unchecked")
     ArchiveCommand.Format<T> fmt = (Format<T>) format;
     fmt.putEntry(
-        out, path, FileMode.REGULAR_FILE, new ObjectLoader.SmallObject(FileMode.TYPE_FILE, data));
+        out,
+        null,
+        path,
+        FileMode.REGULAR_FILE,
+        new ObjectLoader.SmallObject(FileMode.TYPE_FILE, data));
   }
 }
diff --git a/lib/jgit/BUILD b/lib/jgit/BUILD
index f0d25e6..e69de29 100644
--- a/lib/jgit/BUILD
+++ b/lib/jgit/BUILD
@@ -1,7 +0,0 @@
-config_setting(
-    name = "dev",
-    values = {
-        "define": "jgit-dev=1",
-    },
-    visibility = ["//visibility:public"],
-)
diff --git a/lib/jgit/jgit.bzl b/lib/jgit/jgit.bzl
index ac843d8..679e9df 100644
--- a/lib/jgit/jgit.bzl
+++ b/lib/jgit/jgit.bzl
@@ -1,19 +1,66 @@
-load("//tools/bzl:maven_jar.bzl", "GERRIT", "MAVEN_LOCAL", "MAVEN_CENTRAL")
+load("//tools/bzl:maven_jar.bzl", "GERRIT", "MAVEN_LOCAL", "MAVEN_CENTRAL", "maven_jar")
 
-JGIT_VERS = "4.6.0.201612231935-r.30-gd3148f300"
+_JGIT_VERS = "4.6.1.201703071140-r.149-g61f830d3a"
 
-DOC_VERS = "4.6.0.201612231935-r" # Set to JGIT_VERS unless using a snapshot
+_DOC_VERS = "4.6.0.201612231935-r" # Set to _JGIT_VERS unless using a snapshot
 
-JGIT_DOC_URL = "http://download.eclipse.org/jgit/site/" + DOC_VERS + "/apidocs"
+JGIT_DOC_URL = "http://download.eclipse.org/jgit/site/" + _DOC_VERS + "/apidocs"
 
-JGIT_REPO = GERRIT # Leave here even if set to MAVEN_CENTRAL.
+_JGIT_REPO = GERRIT # Leave here even if set to MAVEN_CENTRAL.
 
-JGIT_SHA1 = "a2b5970b853f8fee64589fc1103c0ceb7677ba63"
+# set this to use a local version.
+# "/home/<user>/projects/jgit"
+LOCAL_JGIT_REPO = ""
 
-JGIT_SRC_SHA1 = "765f955774c36c226aa41fba7c20119451de2db7"
+def jgit_repos():
+  if LOCAL_JGIT_REPO:
+    native.local_repository(
+        name = "jgit",
+        path = LOCAL_JGIT_REPO,
+    )
+  else:
+    jgit_maven_repos()
 
-JGIT_SERVLET_SHA1 = "d3aa54bd610db9a5c246aa8fef13989982c98628"
+def jgit_maven_repos():
+    maven_jar(
+        name = "jgit_lib",
+        artifact = "org.eclipse.jgit:org.eclipse.jgit:" + _JGIT_VERS,
+        repository = _JGIT_REPO,
+        sha1 = "dbb390b827b968558342e882e0c9b90e1ed037a2",
+        src_sha1 = "05d8939d08fe75a080fbf84f3163df5127950985",
+        unsign = True,
+    )
+    maven_jar(
+        name = "jgit_servlet",
+        artifact = "org.eclipse.jgit:org.eclipse.jgit.http.server:" + _JGIT_VERS,
+        repository = _JGIT_REPO,
+        sha1 = "136026aa28b065d04194cadcb3371b5a3f6c7235",
+        unsign = True,
+    )
+    maven_jar(
+        name = "jgit_archive",
+        artifact = "org.eclipse.jgit:org.eclipse.jgit.archive:" + _JGIT_VERS,
+        repository = _JGIT_REPO,
+        sha1 = "8be5fa1000cf66ff3deae257bb29870c93f83363",
+    )
+    maven_jar(
+        name = "jgit_junit",
+        artifact = "org.eclipse.jgit:org.eclipse.jgit.junit:" + _JGIT_VERS,
+        repository = _JGIT_REPO,
+        sha1 = "d6a6c49b137a7f1a30ec55a228826d9146c0eba4",
+        unsign = True,
+    )
 
-JGIT_ARCHIVE_SHA1 = "a728cf277396f1227c5a8dffcf5dee0188fc0821"
+def jgit_dep(name):
+  mapping = {
+      "@jgit_junit//jar": "@jgit//org.eclipse.jgit.junit:junit",
+      "@jgit_lib//jar:src": "@jgit//org.eclipse.jgit:libjgit-src.jar",
+      "@jgit_lib//jar": "@jgit//org.eclipse.jgit:jgit",
+      "@jgit_servlet//jar":"@jgit//org.eclipse.jgit.http.server:jgit-servlet",
+      "@jgit_archive//jar": "@jgit//org.eclipse.jgit.archive:jgit-archive",
+  }
 
-JGIT_JUNIT_SHA1 = "6c2b2f192c95d25a2e1576aee5d1169dd8bd2266"
+  if LOCAL_JGIT_REPO:
+    return mapping[name]
+  else:
+    return name
diff --git a/lib/jgit/org.eclipse.jgit.archive/BUILD b/lib/jgit/org.eclipse.jgit.archive/BUILD
index 9a5633c..198ff25 100644
--- a/lib/jgit/org.eclipse.jgit.archive/BUILD
+++ b/lib/jgit/org.eclipse.jgit.archive/BUILD
@@ -1,10 +1,9 @@
+load("//lib/jgit:jgit.bzl", "jgit_dep")
+
 java_library(
     name = "jgit-archive",
     data = ["//lib:LICENSE-jgit"],
     visibility = ["//visibility:public"],
-    exports = select({
-        # "//lib/jgit:dev": ["@jgit//org.eclipse.jgit.archive:jgit-archive"],
-        "//conditions:default": ["@jgit_archive//jar"],
-    }),
+    exports = [jgit_dep("@jgit_archive//jar")],
     runtime_deps = ["//lib/jgit/org.eclipse.jgit:jgit"],
 )
diff --git a/lib/jgit/org.eclipse.jgit.http.server/BUILD b/lib/jgit/org.eclipse.jgit.http.server/BUILD
index 24a58ab..6b5bf78 100644
--- a/lib/jgit/org.eclipse.jgit.http.server/BUILD
+++ b/lib/jgit/org.eclipse.jgit.http.server/BUILD
@@ -1,10 +1,9 @@
+load("//lib/jgit:jgit.bzl", "jgit_dep")
+
 java_library(
     name = "jgit-servlet",
     data = ["//lib:LICENSE-jgit"],
     visibility = ["//visibility:public"],
-    exports = select({
-        # "//lib/jgit:dev": ["@jgit//org.eclipse.jgit.http.server:jgit-servlet"],
-        "//conditions:default": ["@jgit_servlet//jar"],
-    }),
+    exports = [jgit_dep("@jgit_servlet//jar")],
     runtime_deps = ["//lib/jgit/org.eclipse.jgit:jgit"],
 )
diff --git a/lib/jgit/org.eclipse.jgit.junit/BUILD b/lib/jgit/org.eclipse.jgit.junit/BUILD
index ebfefec..ba6c42f 100644
--- a/lib/jgit/org.eclipse.jgit.junit/BUILD
+++ b/lib/jgit/org.eclipse.jgit.junit/BUILD
@@ -1,11 +1,10 @@
+load("//lib/jgit:jgit.bzl", "jgit_dep")
+
 java_library(
     name = "junit",
     testonly = 1,
     data = ["//lib:LICENSE-DO_NOT_DISTRIBUTE"],
     visibility = ["//visibility:public"],
-    exports = select({
-        # "//lib/jgit:dev": ["@jgit//org.eclipse.jgit.junit:junit"],
-        "//conditions:default": ["@jgit_junit//jar"],
-    }),
+    exports = [jgit_dep("@jgit_junit//jar")],
     runtime_deps = ["//lib/jgit/org.eclipse.jgit:jgit"],
 )
diff --git a/lib/jgit/org.eclipse.jgit/BUILD b/lib/jgit/org.eclipse.jgit/BUILD
index 38bfd4b..5586cb1 100644
--- a/lib/jgit/org.eclipse.jgit/BUILD
+++ b/lib/jgit/org.eclipse.jgit/BUILD
@@ -1,20 +1,16 @@
+load("//lib/jgit:jgit.bzl", "jgit_dep")
+
 java_library(
     name = "jgit",
     data = ["//lib:LICENSE-jgit"],
     visibility = ["//visibility:public"],
-    exports = select({
-        # "//lib/jgit:dev": ["@jgit//org.eclipse.jgit:jgit"],
-        "//conditions:default": ["@jgit_lib//jar"],
-    }),
+    exports = [jgit_dep("@jgit_lib//jar")],
     runtime_deps = [":javaewah"],
 )
 
 alias(
     name = "jgit-source",
-    actual = select({
-        # "//lib/jgit:dev": "@jgit//org.eclipse.jgit:libjgit-src.jar",
-        "//conditions:default": "@jgit_lib//jar:src",
-    }),
+    actual = jgit_dep("@jgit_lib//jar:src"),
     visibility = ["//visibility:public"],
 )
 
diff --git a/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list.js b/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list.js
index 3fc9440..a0189f2 100644
--- a/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list.js
+++ b/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list.js
@@ -118,7 +118,7 @@
 
     observers: [
       '_expandedPathsChanged(_expandedFilePaths.splices)',
-      '_setReviewedFiles(_shownFiles, _files, _reviewed.*)',
+      '_setReviewedFiles(_shownFiles, _files, _reviewed.*, _loggedIn)',
     ],
 
     keyBindings: {
@@ -658,11 +658,12 @@
       return files.base.slice(0, numFilesShown);
     },
 
-    _setReviewedFiles: function(shownFiles, files, reviewedRecord) {
+    _setReviewedFiles: function(shownFiles, files, reviewedRecord, loggedIn) {
+      if (!loggedIn) { return; }
       var reviewed = reviewedRecord.base;
       var fileReviewed;
       for (var i = 0; i < files.length; i++) {
-        fileReviewed = this._computeReviewed(shownFiles[i], reviewed);
+        fileReviewed = this._computeReviewed(files[i], reviewed);
         this._files[i].isReviewed = fileReviewed;
         if (i < shownFiles.length) {
           this.set(['_shownFiles', i, 'isReviewed'], fileReviewed);
diff --git a/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list_test.html b/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list_test.html
index 18796f6..66ad66c 100644
--- a/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list_test.html
+++ b/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list_test.html
@@ -535,6 +535,7 @@
         {__path: 'myfile.txt'},
       ];
       element._reviewed = ['/COMMIT_MSG', 'myfile.txt'];
+      element._loggedIn = true;
       element.changeNum = '42';
       element.patchRange = {
         basePatchNum: 'PARENT',
@@ -704,7 +705,6 @@
 
     test('show/hide diffs disabled for large amounts of files', function(done) {
       var computeSpy = sandbox.spy(element, '_fileListActionsVisible');
-      sandbox.stub(element, '_setReviewedFiles');
       element._files = [];
       element.changeNum = '42';
       element.patchRange = {
@@ -868,6 +868,7 @@
           done();
         });
     });
+
     test('_renderInOrder logged in', function(done) {
       element._isLoggedIn = true;
       var reviewStub = sandbox.stub(element, '_reviewFile');