Avoid null PackConfig in GC

Initialize it using the repository's config already in the constructor.

Change-Id: I4ea620a7db72956e7109f739990f09644640206b
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
Matthias Sohn 2019-05-26 17:12:06 +02:00
parent 5d0286eb7c
commit 4904a625c9
1 changed files with 7 additions and 6 deletions

View File

@ -178,7 +178,7 @@ public static void setExecutor(ExecutorService e) {
private Date packExpire; private Date packExpire;
private PackConfig pconfig = null; private PackConfig pconfig;
/** /**
* the refs which existed during the last call to {@link #repack()}. This is * the refs which existed during the last call to {@link #repack()}. This is
@ -214,6 +214,7 @@ public static void setExecutor(ExecutorService e) {
*/ */
public GC(FileRepository repo) { public GC(FileRepository repo) {
this.repo = repo; this.repo = repo;
this.pconfig = new PackConfig(repo);
this.pm = NullProgressMonitor.INSTANCE; this.pm = NullProgressMonitor.INSTANCE;
} }
@ -398,7 +399,7 @@ private void deleteOldPacks(Collection<PackFile> oldPacks,
*/ */
private void removeOldPack(File packFile, String packName, PackExt ext, private void removeOldPack(File packFile, String packName, PackExt ext,
int deleteOptions) throws IOException { int deleteOptions) throws IOException {
if (pconfig != null && pconfig.isPreserveOldPacks()) { if (pconfig.isPreserveOldPacks()) {
File oldPackDir = repo.getObjectDatabase().getPreservedDirectory(); File oldPackDir = repo.getObjectDatabase().getPreservedDirectory();
FileUtils.mkdir(oldPackDir, true); FileUtils.mkdir(oldPackDir, true);
@ -414,7 +415,7 @@ private void removeOldPack(File packFile, String packName, PackExt ext,
* Delete the preserved directory including all pack files within * Delete the preserved directory including all pack files within
*/ */
private void prunePreserved() { private void prunePreserved() {
if (pconfig != null && pconfig.isPrunePreserved()) { if (pconfig.isPrunePreserved()) {
try { try {
FileUtils.delete(repo.getObjectDatabase().getPreservedDirectory(), FileUtils.delete(repo.getObjectDatabase().getPreservedDirectory(),
FileUtils.RECURSIVE | FileUtils.RETRY | FileUtils.SKIP_MISSING); FileUtils.RECURSIVE | FileUtils.RETRY | FileUtils.SKIP_MISSING);
@ -856,7 +857,7 @@ public Collection<PackFile> repack() throws IOException {
nonHeads.addAll(indexObjects); nonHeads.addAll(indexObjects);
// Combine the GC_REST objects into the GC pack if requested // Combine the GC_REST objects into the GC pack if requested
if (pconfig != null && pconfig.getSinglePack()) { if (pconfig.getSinglePack()) {
allHeadsAndTags.addAll(nonHeads); allHeadsAndTags.addAll(nonHeads);
nonHeads.clear(); nonHeads.clear();
} }
@ -1159,7 +1160,7 @@ private PackFile writePack(@NonNull Set<? extends ObjectId> want,
return Integer.signum(o1.hashCode() - o2.hashCode()); return Integer.signum(o1.hashCode() - o2.hashCode());
}); });
try (PackWriter pw = new PackWriter( try (PackWriter pw = new PackWriter(
(pconfig == null) ? new PackConfig(repo) : pconfig, pconfig,
repo.newObjectReader())) { repo.newObjectReader())) {
// prepare the PackWriter // prepare the PackWriter
pw.setDeltaBaseAsOffset(true); pw.setDeltaBaseAsOffset(true);
@ -1434,7 +1435,7 @@ public void setPackExpireAgeMillis(long packExpireAgeMillis) {
* the {@link org.eclipse.jgit.storage.pack.PackConfig} used when * the {@link org.eclipse.jgit.storage.pack.PackConfig} used when
* writing packs * writing packs
*/ */
public void setPackConfig(PackConfig pconfig) { public void setPackConfig(@NonNull PackConfig pconfig) {
this.pconfig = pconfig; this.pconfig = pconfig;
} }