[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 <thomas.wolf@paranor.ch>
This commit is contained in:
Thomas Wolf 2021-11-07 21:43:07 +01:00 committed by Matthias Sohn
parent 1e37438cb7
commit 5154585439
12 changed files with 40 additions and 20 deletions

View File

@ -34,7 +34,6 @@
import org.eclipse.jgit.internal.storage.dfs.DfsGarbageCollector;
import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription;
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
import org.eclipse.jgit.internal.storage.file.PackLock;
import org.eclipse.jgit.internal.storage.pack.CachedPack;
import org.eclipse.jgit.internal.storage.pack.CachedPackUriProvider;
import org.eclipse.jgit.junit.TestRepository;

View File

@ -23,10 +23,10 @@
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;

View File

@ -34,6 +34,7 @@
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 @@ private PackLock renameAndOpenPack(String lockMessage)
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

View File

@ -14,6 +14,7 @@
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;
@ -21,7 +22,7 @@
* Keeps track of a {@link org.eclipse.jgit.internal.storage.file.Pack}'s
* associated <code>.keep</code> file.
*/
public class PackLock {
public class PackLockImpl implements PackLock {
private final File keepFile;
/**
@ -32,7 +33,7 @@ public class PackLock {
* @param fs
* the filesystem abstraction used by the repository.
*/
public PackLock(File packFile, FS fs) {
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$
@ -59,12 +60,7 @@ public boolean lock(String msg) throws IOException {
return lf.commit();
}
/**
* Remove the <code>.keep</code> file that holds this pack in place.
*
* @throws java.io.IOException
* if deletion of .keep file failed
*/
@Override
public void unlock() throws IOException {
FileUtils.delete(keepFile);
}

View File

@ -28,7 +28,6 @@
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;

View File

@ -35,7 +35,6 @@
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;

View File

@ -18,7 +18,6 @@
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;

View File

@ -37,7 +37,6 @@
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;

View File

@ -0,0 +1,31 @@
/*
* Copyright (C) 2021 Thomas Wolf <thomas.wolf@paranor.ch> 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;
}

View File

@ -29,7 +29,6 @@
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 ReceivedPackStatistics getReceivedPackStatistics() {
* {@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 final PackLock parse(ProgressMonitor progress) throws IOException {
* {@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 {

View File

@ -48,7 +48,6 @@
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;

View File

@ -32,7 +32,6 @@
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;