Merge branch 'stable-2.14'
* stable-2.14:
Update bazlets to latest revision on stable-2.14
WORKSPACE: Reuse external plugin dependencies
Follow up to adding global configuration to locks directory
Add global configuration for LFS file locks storage
Change-Id: I7e057fed9f2fb7e0833e780ab02c9130ce49497e
diff --git a/WORKSPACE b/WORKSPACE
index 68322be..0be9dc1 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -7,36 +7,6 @@
# local_path = "/home/<user>/projects/bazlets",
)
-load("@com_googlesource_gerrit_bazlets//tools:maven_jar.bzl",
- "maven_jar",
- "GERRIT",
- "MAVEN_CENTRAL")
-
-JGIT_VERS = "4.8.0.201706111038-r"
-
-JGIT_REPO = MAVEN_CENTRAL
-
-maven_jar(
- name = "jgit_http_apache",
- artifact = "org.eclipse.jgit:org.eclipse.jgit.http.apache:" + JGIT_VERS,
- sha1 = "78e55a9537e5f6b6fc196d72ad74009550dd3ed9",
- repository = JGIT_REPO,
-)
-
-maven_jar(
- name = "jgit_lfs",
- artifact = "org.eclipse.jgit:org.eclipse.jgit.lfs:" + JGIT_VERS,
- sha1 = "7f9906508cb129022120a998bdfb662748a52a79",
- repository = JGIT_REPO,
-)
-
-maven_jar(
- name = "jgit_lfs_server",
- artifact = "org.eclipse.jgit:org.eclipse.jgit.lfs.server:" + JGIT_VERS,
- sha1 = "d0631e2b55aeb41ddad167849f33f53a7eb58726",
- repository = JGIT_REPO,
-)
-
# Release Plugin API
#load("@com_googlesource_gerrit_bazlets//:gerrit_api.bzl",
# "gerrit_api")
@@ -52,3 +22,7 @@
# Load snapshot Plugin API
gerrit_api_maven_local()
+
+load(":external_plugin_deps.bzl", "external_plugin_deps")
+
+external_plugin_deps()
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/locks/LfsLocksPathProvider.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/locks/LfsLocksPathProvider.java
new file mode 100644
index 0000000..b31c8be
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/locks/LfsLocksPathProvider.java
@@ -0,0 +1,42 @@
+// Copyright (C) 2017 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.googlesource.gerrit.plugins.lfs.locks;
+
+import com.google.common.base.MoreObjects;
+import com.google.gerrit.extensions.annotations.PluginData;
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.google.inject.Singleton;
+import com.googlesource.gerrit.plugins.lfs.LfsConfigurationFactory;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+@Singleton
+class LfsLocksPathProvider implements Provider<String> {
+ private final String path;
+
+ @Inject
+ LfsLocksPathProvider(LfsConfigurationFactory configFactory, @PluginData Path defaultDataDir) {
+ String locksDir = configFactory.getGlobalConfig().getString("locks", null, "directory");
+ this.path =
+ MoreObjects.firstNonNull(
+ locksDir, Paths.get(defaultDataDir.toString(), "lfs_locks").toString());
+ }
+
+ @Override
+ public String get() {
+ return path;
+ }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/locks/LfsProjectLocks.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/locks/LfsProjectLocks.java
index 934ee00..346bdad 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/locks/LfsProjectLocks.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/locks/LfsProjectLocks.java
@@ -16,7 +16,6 @@
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
-import com.google.gerrit.extensions.annotations.PluginData;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.CurrentUser;
import com.google.gson.FieldNamingPolicy;
@@ -62,10 +61,10 @@
@Inject
LfsProjectLocks(
- PathToLockId toLockId, @PluginData Path defaultDataDir, @Assisted Project.NameKey project) {
+ PathToLockId toLockId, LfsLocksPathProvider locksPath, @Assisted Project.NameKey project) {
this.toLockId = toLockId;
this.project = project.get();
- this.locksPath = Paths.get(defaultDataDir.toString(), "lfs_locks", this.project);
+ this.locksPath = Paths.get(locksPath.get(), this.project);
this.locks = CacheBuilder.newBuilder().build();
}
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md
index 53bad5a..fdcee4c 100644
--- a/src/main/resources/Documentation/config.md
+++ b/src/main/resources/Documentation/config.md
@@ -93,6 +93,29 @@
The following options can be configured in `$GERRIT_SITE/etc/@PLUGIN@.config`
and `$GERRIT_SITE/etc/@PLUGIN@.secure.config.`
+### Section `locks`
+
+locks.directory
+: The directory in which to store Git LFS file locks.
+[Git LFS File Locking API](https://github.com/git-lfs/git-lfs/blob/master/docs/api/locking.md)
+specifies that certain path can be locked by user. It prevents from accidental file overwrite
+by different user and costly (manual in most cases) binary file merge.
+Each lock is represented by JSON structure:
+
+```
+ {
+ "id":"[lock id the same as lock file name]",
+ "path":"[path to the resource being locked]",
+ "locked_at":"[timestamp the lock was created in ISO 8601 format]",
+ "owner":{
+ "name":"[the name of the user that created the lock]"
+ }
+ }
+```
+
+It is stored in a file with name computed as SHA256 of path being locked and is stored under `directory` followed by project name.
+: Default is `$GERRIT_SITE/data/@PLUGIN@/lfs_locks`.
+
### Section `auth`
auth.sshExpirationSeconds
diff --git a/tools/bzl/maven_jar.bzl b/tools/bzl/maven_jar.bzl
new file mode 100644
index 0000000..4bc37e1
--- /dev/null
+++ b/tools/bzl/maven_jar.bzl
@@ -0,0 +1 @@
+load("@com_googlesource_gerrit_bazlets//tools:maven_jar.bzl", "maven_jar", "GERRIT", "MAVEN_LOCAL", "MAVEN_CENTRAL")