From 51545854392a08077631813dd8acdde3b642762c Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Sun, 7 Nov 2021 21:43:07 +0100 Subject: [6.0 API cleanup] Public interface for PackLock Provide a public interface PackLock exposing only the unlock() method. Rename the internal PackLock class to PackLockImpl and have it implement the new interface. This way PackParser doesn't expose an internal class via its API anymore, and client can still unlock pack locks that were created. Bug: 576340 Change-Id: I976739f4ab28fe1f9ba7f35653a69a913aa68841 Signed-off-by: Thomas Wolf --- .../jgit/internal/storage/dfs/DfsPackParser.java | 2 +- .../storage/file/ObjectDirectoryPackParser.java | 3 +- .../jgit/internal/storage/file/PackLock.java | 71 ---------------------- .../jgit/internal/storage/file/PackLockImpl.java | 67 ++++++++++++++++++++ .../jgit/transport/BasePackFetchConnection.java | 1 - .../jgit/transport/BundleFetchConnection.java | 1 - .../eclipse/jgit/transport/FetchConnection.java | 1 - .../org/eclipse/jgit/transport/FetchProcess.java | 1 - .../src/org/eclipse/jgit/transport/PackLock.java | 31 ++++++++++ .../src/org/eclipse/jgit/transport/PackParser.java | 5 +- .../org/eclipse/jgit/transport/ReceivePack.java | 1 - .../jgit/transport/WalkFetchConnection.java | 1 - 12 files changed, 103 insertions(+), 82 deletions(-) delete mode 100644 org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackLock.java create mode 100644 org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackLockImpl.java create mode 100644 org.eclipse.jgit/src/org/eclipse/jgit/transport/PackLock.java (limited to 'org.eclipse.jgit') diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackParser.java index 29d11104d4..d8e191c4e0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackParser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackParser.java @@ -23,10 +23,10 @@ import java.util.zip.CRC32; import java.util.zip.Deflater; import org.eclipse.jgit.internal.storage.file.PackIndex; -import org.eclipse.jgit.internal.storage.file.PackLock; import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ProgressMonitor; +import org.eclipse.jgit.transport.PackLock; import org.eclipse.jgit.transport.PackParser; import org.eclipse.jgit.transport.PackedObjectInfo; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryPackParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryPackParser.java index dba8ccd99b..1c23ff20c7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryPackParser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryPackParser.java @@ -34,6 +34,7 @@ import org.eclipse.jgit.lib.CoreConfig; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.storage.pack.PackConfig; +import org.eclipse.jgit.transport.PackLock; import org.eclipse.jgit.transport.PackParser; import org.eclipse.jgit.transport.PackedObjectInfo; import org.eclipse.jgit.util.FileUtils; @@ -431,7 +432,7 @@ public class ObjectDirectoryPackParser extends PackParser { File packDir = new File(db.getDirectory(), "pack"); //$NON-NLS-1$ PackFile finalPack = new PackFile(packDir, id, PackExt.PACK); PackFile finalIdx = finalPack.create(PackExt.INDEX); - final PackLock keep = new PackLock(finalPack, db.getFS()); + final PackLockImpl keep = new PackLockImpl(finalPack, db.getFS()); if (!packDir.exists() && !packDir.mkdir() && !packDir.exists()) { // The objects/pack directory isn't present, and we are unable diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackLock.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackLock.java deleted file mode 100644 index 482b143e33..0000000000 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackLock.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2009, Google Inc. and others - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0 which is available at - * https://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.eclipse.jgit.internal.storage.file; - -import java.io.File; -import java.io.IOException; - -import org.eclipse.jgit.lib.Constants; -import org.eclipse.jgit.util.FS; -import org.eclipse.jgit.util.FileUtils; - -/** - * Keeps track of a {@link org.eclipse.jgit.internal.storage.file.Pack}'s - * associated .keep file. - */ -public class PackLock { - private final File keepFile; - - /** - * Create a new lock for a pack file. - * - * @param packFile - * location of the pack-*.pack file. - * @param fs - * the filesystem abstraction used by the repository. - */ - public PackLock(File packFile, FS fs) { - final File p = packFile.getParentFile(); - final String n = packFile.getName(); - keepFile = new File(p, n.substring(0, n.length() - 5) + ".keep"); //$NON-NLS-1$ - } - - /** - * Create the pack-*.keep file, with the given message. - * - * @param msg - * message to store in the file. - * @return true if the keep file was successfully written; false otherwise. - * @throws java.io.IOException - * the keep file could not be written. - */ - public boolean lock(String msg) throws IOException { - if (msg == null) - return false; - if (!msg.endsWith("\n")) //$NON-NLS-1$ - msg += "\n"; //$NON-NLS-1$ - final LockFile lf = new LockFile(keepFile); - if (!lf.lock()) - return false; - lf.write(Constants.encode(msg)); - return lf.commit(); - } - - /** - * Remove the .keep file that holds this pack in place. - * - * @throws java.io.IOException - * if deletion of .keep file failed - */ - public void unlock() throws IOException { - FileUtils.delete(keepFile); - } -} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackLockImpl.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackLockImpl.java new file mode 100644 index 0000000000..7cc5f50549 --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackLockImpl.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2009, Google Inc. and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +package org.eclipse.jgit.internal.storage.file; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.transport.PackLock; +import org.eclipse.jgit.util.FS; +import org.eclipse.jgit.util.FileUtils; + +/** + * Keeps track of a {@link org.eclipse.jgit.internal.storage.file.Pack}'s + * associated .keep file. + */ +public class PackLockImpl implements PackLock { + private final File keepFile; + + /** + * Create a new lock for a pack file. + * + * @param packFile + * location of the pack-*.pack file. + * @param fs + * the filesystem abstraction used by the repository. + */ + public PackLockImpl(File packFile, FS fs) { + final File p = packFile.getParentFile(); + final String n = packFile.getName(); + keepFile = new File(p, n.substring(0, n.length() - 5) + ".keep"); //$NON-NLS-1$ + } + + /** + * Create the pack-*.keep file, with the given message. + * + * @param msg + * message to store in the file. + * @return true if the keep file was successfully written; false otherwise. + * @throws java.io.IOException + * the keep file could not be written. + */ + public boolean lock(String msg) throws IOException { + if (msg == null) + return false; + if (!msg.endsWith("\n")) //$NON-NLS-1$ + msg += "\n"; //$NON-NLS-1$ + final LockFile lf = new LockFile(keepFile); + if (!lf.lock()) + return false; + lf.write(Constants.encode(msg)); + return lf.commit(); + } + + @Override + public void unlock() throws IOException { + FileUtils.delete(keepFile); + } +} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java index d344deac26..f48e1e68cc 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java @@ -28,7 +28,6 @@ import org.eclipse.jgit.errors.PackProtocolException; import org.eclipse.jgit.errors.RemoteRepositoryException; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.internal.JGitText; -import org.eclipse.jgit.internal.storage.file.PackLock; import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.MutableObjectId; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java index 47d156b667..f04e573feb 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java @@ -35,7 +35,6 @@ import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.errors.PackProtocolException; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.internal.JGitText; -import org.eclipse.jgit.internal.storage.file.PackLock; import org.eclipse.jgit.lib.NullProgressMonitor; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectIdRef; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchConnection.java index d06ef65c76..9dc0620665 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchConnection.java @@ -18,7 +18,6 @@ import java.util.Collection; import java.util.Set; import org.eclipse.jgit.errors.TransportException; -import org.eclipse.jgit.internal.storage.file.PackLock; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.lib.Ref; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java index 34bad6e029..7d7b3ee0a0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java @@ -37,7 +37,6 @@ import org.eclipse.jgit.errors.NotSupportedException; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.storage.file.LockFile; -import org.eclipse.jgit.internal.storage.file.PackLock; import org.eclipse.jgit.lib.BatchRefUpdate; import org.eclipse.jgit.lib.BatchingProgressMonitor; import org.eclipse.jgit.lib.Constants; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackLock.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackLock.java new file mode 100644 index 0000000000..bf2140759f --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackLock.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2021 Thomas Wolf and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +package org.eclipse.jgit.transport; + +import java.io.IOException; + +/** + * A {@code PackLock} describes a {@code .keep} file that holds a pack in place. + * If {@link PackParser#parse(org.eclipse.jgit.lib.ProgressMonitor)} creates + * such a pack lock, it returns the lock so that it can be unlocked once the + * pack doesn't need a {@code .keep} file anymore. + * + * @since 6.0 + */ +public interface PackLock { + + /** + * Remove the {@code .keep} file that holds a pack in place. + * + * @throws java.io.IOException + * if deletion of the {@code .keep} file failed + */ + void unlock() throws IOException; +} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java index 715cbb48fb..e43ea0261e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java @@ -29,7 +29,6 @@ import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.errors.TooLargeObjectInPackException; import org.eclipse.jgit.internal.JGitText; -import org.eclipse.jgit.internal.storage.file.PackLock; import org.eclipse.jgit.internal.storage.pack.BinaryDelta; import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.BatchingProgressMonitor; @@ -490,7 +489,7 @@ public abstract class PackParser { * {@link #setLockMessage(String)}. * @throws java.io.IOException * the stream is malformed, or contains corrupt objects. - * @since 3.0 + * @since 6.0 */ public final PackLock parse(ProgressMonitor progress) throws IOException { return parse(progress, progress); @@ -509,7 +508,7 @@ public abstract class PackParser { * {@link #setLockMessage(String)}. * @throws java.io.IOException * the stream is malformed, or contains corrupt objects. - * @since 3.0 + * @since 6.0 */ public PackLock parse(ProgressMonitor receiving, ProgressMonitor resolving) throws IOException { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java index 58f8895e00..871ba50a6c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java @@ -48,7 +48,6 @@ import org.eclipse.jgit.errors.PackProtocolException; import org.eclipse.jgit.errors.TooLargePackException; import org.eclipse.jgit.errors.UnpackException; import org.eclipse.jgit.internal.JGitText; -import org.eclipse.jgit.internal.storage.file.PackLock; import org.eclipse.jgit.internal.submodule.SubmoduleValidator; import org.eclipse.jgit.internal.submodule.SubmoduleValidator.SubmoduleValidationException; import org.eclipse.jgit.internal.transport.connectivity.FullConnectivityChecker; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java index a6b20451dd..d67fe074e4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java @@ -32,7 +32,6 @@ import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.storage.file.ObjectDirectory; import org.eclipse.jgit.internal.storage.file.PackIndex; -import org.eclipse.jgit.internal.storage.file.PackLock; import org.eclipse.jgit.internal.storage.file.UnpackedObject; import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.Constants; -- cgit v1.2.3