From 971dafd302ae4bb2d69345f9624774ff226feebd Mon Sep 17 00:00:00 2001 From: Nasser Grainawi Date: Wed, 10 Feb 2021 22:51:05 -0700 Subject: Create a PackFile class for Pack filenames The PackFile class is intended to be a central place to do all common pack filename manipulation and parsing to help reduce repeated code and bugs. Use the PackFile class in the Pack class and in many tests to ensure it works well in a variety of situations. Later changes will expand use of PackFiles to even more areas. Change-Id: I921b30f865759162bae46ddd2c6d669de06add4a Signed-off-by: Nasser Grainawi Signed-off-by: Matthias Sohn --- .../src/org/eclipse/jgit/junit/TestRepository.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'org.eclipse.jgit.junit/src/org/eclipse/jgit') diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java index e3eb2c5367..24f7741f16 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java @@ -44,7 +44,9 @@ import org.eclipse.jgit.internal.storage.file.FileRepository; import org.eclipse.jgit.internal.storage.file.LockFile; import org.eclipse.jgit.internal.storage.file.ObjectDirectory; import org.eclipse.jgit.internal.storage.file.Pack; +import org.eclipse.jgit.internal.storage.file.PackFile; import org.eclipse.jgit.internal.storage.file.PackIndex.MutableEntry; +import org.eclipse.jgit.internal.storage.pack.PackExt; import org.eclipse.jgit.internal.storage.pack.PackWriter; import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.Constants; @@ -906,7 +908,7 @@ public class TestRepository implements AutoCloseable { ObjectDirectory odb = (ObjectDirectory) db.getObjectDatabase(); NullProgressMonitor m = NullProgressMonitor.INSTANCE; - final File pack, idx; + final PackFile pack, idx; try (PackWriter pw = new PackWriter(db)) { Set all = new HashSet<>(); for (Ref r : db.getRefDatabase().getRefs()) @@ -922,7 +924,7 @@ public class TestRepository implements AutoCloseable { } pack.setReadOnly(); - idx = nameFor(odb, name, ".idx"); + idx = pack.create(PackExt.INDEX); try (OutputStream out = new BufferedOutputStream(new FileOutputStream(idx))) { pw.writeIndex(out); @@ -960,9 +962,10 @@ public class TestRepository implements AutoCloseable { } } - private static File nameFor(ObjectDirectory odb, ObjectId name, String t) { + private static PackFile nameFor(ObjectDirectory odb, ObjectId name, + String t) { File packdir = odb.getPackDirectory(); - return new File(packdir, "pack-" + name.name() + t); + return new PackFile(packdir, "pack-" + name.name() + t); } private void writeFile(File p, byte[] bin) throws IOException, -- cgit v1.2.3