summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java57
1 files changed, 37 insertions, 20 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
index 338106f8e7..c5723c0594 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
@@ -175,13 +175,17 @@ public class GC {
/**
* Delete old pack files. What is 'old' is defined by specifying a set of
* old pack files and a set of new pack files. Each pack file contained in
- * old pack files but not contained in new pack files will be deleted.
+ * old pack files but not contained in new pack files will be deleted. If an
+ * expirationDate is set then pack files which are younger than the
+ * expirationDate will not be deleted.
*
* @param oldPacks
* @param newPacks
+ * @throws ParseException
*/
private void deleteOldPacks(Collection<PackFile> oldPacks,
- Collection<PackFile> newPacks) {
+ Collection<PackFile> newPacks) throws ParseException {
+ long expireDate = getExpireDate();
oldPackLoop: for (PackFile oldPack : oldPacks) {
String oldName = oldPack.getPackName();
// check whether an old pack file is also among the list of new
@@ -190,7 +194,8 @@ public class GC {
if (oldName.equals(newPack.getPackName()))
continue oldPackLoop;
- if (!oldPack.shouldBeKept()) {
+ if (!oldPack.shouldBeKept()
+ && oldPack.getPackFile().lastModified() < expireDate) {
oldPack.close();
prunePack(oldName);
}
@@ -303,22 +308,7 @@ public class GC {
*/
public void prune(Set<ObjectId> objectsToKeep) throws IOException,
ParseException {
- long expireDate = Long.MAX_VALUE;
-
- if (expire == null && expireAgeMillis == -1) {
- String pruneExpireStr = repo.getConfig().getString(
- ConfigConstants.CONFIG_GC_SECTION, null,
- ConfigConstants.CONFIG_KEY_PRUNEEXPIRE);
- if (pruneExpireStr == null)
- pruneExpireStr = PRUNE_EXPIRE_DEFAULT;
- expire = GitDateParser.parse(pruneExpireStr, null, SystemReader
- .getInstance().getLocale());
- expireAgeMillis = -1;
- }
- if (expire != null)
- expireDate = expire.getTime();
- if (expireAgeMillis != -1)
- expireDate = System.currentTimeMillis() - expireAgeMillis;
+ long expireDate = getExpireDate();
// Collect all loose objects which are old enough, not referenced from
// the index and not in objectsToKeep
@@ -435,6 +425,26 @@ public class GC {
repo.getObjectDatabase().close();
}
+ private long getExpireDate() throws ParseException {
+ long expireDate = Long.MAX_VALUE;
+
+ if (expire == null && expireAgeMillis == -1) {
+ String pruneExpireStr = repo.getConfig().getString(
+ ConfigConstants.CONFIG_GC_SECTION, null,
+ ConfigConstants.CONFIG_KEY_PRUNEEXPIRE);
+ if (pruneExpireStr == null)
+ pruneExpireStr = PRUNE_EXPIRE_DEFAULT;
+ expire = GitDateParser.parse(pruneExpireStr, null, SystemReader
+ .getInstance().getLocale());
+ expireAgeMillis = -1;
+ }
+ if (expire != null)
+ expireDate = expire.getTime();
+ if (expireAgeMillis != -1)
+ expireDate = System.currentTimeMillis() - expireAgeMillis;
+ return expireDate;
+ }
+
/**
* Remove all entries from a map which key is the id of an object referenced
* by the given ObjectWalk
@@ -559,7 +569,14 @@ public class GC {
if (rest != null)
ret.add(rest);
}
- deleteOldPacks(toBeDeleted, ret);
+ try {
+ deleteOldPacks(toBeDeleted, ret);
+ } catch (ParseException e) {
+ // TODO: the exception has to be wrapped into an IOException because
+ // throwing the ParseException directly would break the API, instead
+ // we should throw a ConfigInvalidException
+ throw new IOException(e);
+ }
prunePacked();
lastPackedRefs = refsBefore;