]> source.dussan.org Git - jgit.git/commitdiff
Use constant for ".lock" 71/124271/3
authorMatthias Sohn <matthias.sohn@sap.com>
Fri, 8 Jun 2018 15:22:54 +0000 (17:22 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Fri, 8 Jun 2018 19:43:39 +0000 (21:43 +0200)
Change-Id: Id65dc94c970ffd3ca3d3d4a5d57123c95d29e8af
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogWriter.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportSftp.java

index 757ebb2987328e8f8ce3963410e016b916b40b17..b2fae316c3d17103551e70d50f06c23165d5185b 100644 (file)
@@ -45,8 +45,9 @@
 
 package org.eclipse.jgit.internal.storage.file;
 
-import static org.eclipse.jgit.lib.Constants.CHARSET;
 import static org.eclipse.jgit.junit.Assert.assertEquals;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
+import static org.eclipse.jgit.lib.Constants.LOCK_SUFFIX;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -819,11 +820,11 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
                        // Check that the involved refs are the same despite the failure
                        assertExists(false, toName);
                        if (!toLock.equals(toName))
-                               assertExists(false, toName + ".lock");
-                       assertExists(true, toLock + ".lock");
+                               assertExists(false, toName + LOCK_SUFFIX);
+                       assertExists(true, toLock + LOCK_SUFFIX);
                        if (!toLock.equals(fromName))
-                               assertExists(false, "logs/" + fromName + ".lock");
-                       assertExists(false, "logs/" + toName + ".lock");
+                               assertExists(false, "logs/" + fromName + LOCK_SUFFIX);
+                       assertExists(false, "logs/" + toName + LOCK_SUFFIX);
                        assertEquals(oldHeadId, db.resolve(Constants.HEAD));
                        assertEquals(oldfromId, db.resolve(fromName));
                        assertNull(db.resolve(toName));
index a11e4ffdfef86f85d5b55ba3c5df7d0539add9f6..da9a050bc3755dba822fc9512c3d6054d6f74ab0 100644 (file)
@@ -44,6 +44,8 @@
 
 package org.eclipse.jgit.internal.storage.file;
 
+import static org.eclipse.jgit.lib.Constants.LOCK_SUFFIX;
+
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -74,7 +76,6 @@ import org.eclipse.jgit.util.FileUtils;
  * name.
  */
 public class LockFile {
-       static final String SUFFIX = ".lock"; //$NON-NLS-1$
 
        /**
         * Unlock the given file.
@@ -106,14 +107,15 @@ public class LockFile {
         * @return lock file
         */
        static File getLockFile(File file) {
-               return new File(file.getParentFile(), file.getName() + SUFFIX);
+               return new File(file.getParentFile(),
+                               file.getName() + LOCK_SUFFIX);
        }
 
        /** Filter to skip over active lock files when listing a directory. */
        static final FilenameFilter FILTER = new FilenameFilter() {
                @Override
                public boolean accept(File dir, String name) {
-                       return !name.endsWith(SUFFIX);
+                       return !name.endsWith(LOCK_SUFFIX);
                }
        };
 
index b366eafe2f32c42732a0f62beca2f06ffe3a0121..495c752360fe7060726f0d8ecf889834ebcce0d4 100644 (file)
@@ -46,6 +46,7 @@
 package org.eclipse.jgit.internal.storage.file;
 
 import static org.eclipse.jgit.lib.Constants.HEAD;
+import static org.eclipse.jgit.lib.Constants.LOCK_SUFFIX;
 import static org.eclipse.jgit.lib.Constants.R_HEADS;
 import static org.eclipse.jgit.lib.Constants.R_NOTES;
 import static org.eclipse.jgit.lib.Constants.R_REFS;
@@ -84,7 +85,7 @@ public class ReflogWriter {
         * @return the name of the ref's lock ref.
         */
        public static String refLockFor(String name) {
-               return name + LockFile.SUFFIX;
+               return name + LOCK_SUFFIX;
        }
 
        private final RefDirectory refdb;
index a119480ea4fbdb6a0ea05d8e5bc5b059a7e08dca..ecebd54089314f0a3d1b91b6cf0a0528d02f000c 100644 (file)
@@ -691,6 +691,13 @@ public final class Constants {
        public static final ObjectId EMPTY_BLOB_ID = ObjectId
                        .fromString("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391");
 
+       /**
+        * Suffix of lock file name
+        *
+        * @since 5.0
+        */
+       public static final String LOCK_SUFFIX = ".lock"; //$NON-NLS-1$
+
        private Constants() {
                // Hide the default constructor
        }
index fa283d01290d45ecf82a4e4db34e0f915638b766..29cc19c43cdfb5b55ec4b31845e9eaa93292a75e 100644 (file)
@@ -48,6 +48,8 @@
 
 package org.eclipse.jgit.lib;
 
+import static org.eclipse.jgit.lib.Constants.LOCK_SUFFIX;
+
 import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileNotFoundException;
@@ -1366,10 +1368,12 @@ public abstract class Repository implements AutoCloseable {
         */
        public static boolean isValidRefName(String refName) {
                final int len = refName.length();
-               if (len == 0)
+               if (len == 0) {
                        return false;
-               if (refName.endsWith(".lock")) //$NON-NLS-1$
+               }
+               if (refName.endsWith(LOCK_SUFFIX)) {
                        return false;
+               }
 
                // Refs may be stored as loose files so invalid paths
                // on the local system must also be invalid refs.
index d8f3a12bfe0aec8dad7edd422fad4ad5593c3c74..f129ba34da2d6a987ca5d58dfcf409e6af06fb0c 100644 (file)
@@ -43,6 +43,8 @@
 
 package org.eclipse.jgit.transport;
 
+import static org.eclipse.jgit.lib.Constants.LOCK_SUFFIX;
+
 import java.io.BufferedReader;
 import java.io.FileNotFoundException;
 import java.io.IOException;
@@ -344,7 +346,7 @@ public class TransportSftp extends SshTransport implements WalkTransport {
 
                @Override
                void writeFile(String path, byte[] data) throws IOException {
-                       final String lock = path + ".lock"; //$NON-NLS-1$
+                       final String lock = path + LOCK_SUFFIX;
                        try {
                                super.writeFile(lock, data);
                                try {