aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Frade <ifrade@google.com>2024-11-08 08:49:09 -0800
committerIvan Frade <ifrade@google.com>2024-11-08 15:06:16 -0800
commit9ea537d5c44876c12d154331c94a7ba14eaa64f8 (patch)
treeef868efd39d528bba3ea88e1f2fe99fd04b99f84
parenta903ab5fa3defdef06b4eba316ef2436533416fb (diff)
downloadjgit-9ea537d5c44876c12d154331c94a7ba14eaa64f8.tar.gz
jgit-9ea537d5c44876c12d154331c94a7ba14eaa64f8.zip
DfsGarbageCollector: #setReflogExpire with Instant instead of Date
The Date API is full of major design flaws and pitfalls and should be avoided at all costs. Prefer the java.time APIs, specifically, java.time.Instant (for physical time) and java.time.LocalDate[Time] (for civil time). [1] Replace the Date with Instant in the DfsGarbageCollector#setReflogExpire method. [1] https://errorprone.info/bugpattern/JavaUtilDate Change-Id: Ie98e426e63621e8bef96c31bca56aec0c8eef5a6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java3
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java11
2 files changed, 8 insertions, 6 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java
index 3edd1056be..f9fbfe8db0 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java
@@ -16,6 +16,7 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
+import java.time.Instant;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
@@ -1331,7 +1332,7 @@ public class DfsGarbageCollectorTest {
gc = new DfsGarbageCollector(repo);
gc.setReftableConfig(new ReftableConfig());
// Expire ref log entries older than 30 days
- gc.setRefLogExpire(new Date(thirty_days_ago));
+ gc.setRefLogExpire(Instant.ofEpochMilli(thirty_days_ago));
run(gc);
// Single GC pack present with all objects.
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java
index 6861fe8099..e6068a15ec 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java
@@ -24,11 +24,11 @@ import static org.eclipse.jgit.internal.storage.pack.PackExt.REFTABLE;
import static org.eclipse.jgit.internal.storage.pack.PackWriter.NONE;
import java.io.IOException;
+import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
-import java.util.Date;
import java.util.EnumSet;
import java.util.GregorianCalendar;
import java.util.HashSet;
@@ -100,7 +100,7 @@ public class DfsGarbageCollector {
private Set<ObjectId> allTags;
private Set<ObjectId> nonHeads;
private Set<ObjectId> tagTargets;
- private Date refLogExpire;
+ private Instant refLogExpire;
/**
* Initialize a garbage collector.
@@ -212,8 +212,8 @@ public class DfsGarbageCollector {
* instant in time which defines refLog expiration
* @return {@code this}
*/
- public DfsGarbageCollector setRefLogExpire(Date refLogExpire) {
- this.refLogExpire = refLogExpire ;
+ public DfsGarbageCollector setRefLogExpire(Instant refLogExpire) {
+ this.refLogExpire = refLogExpire;
return this;
}
@@ -752,7 +752,8 @@ public class DfsGarbageCollector {
compact.setIncludeDeletes(includeDeletes);
compact.setConfig(configureReftable(reftableConfig, out));
if(refLogExpire != null ){
- compact.setReflogExpireOldestReflogTimeMillis(refLogExpire.getTime());
+ compact.setReflogExpireOldestReflogTimeMillis(
+ refLogExpire.toEpochMilli());
}
compact.compact();
pack.addFileExt(REFTABLE);