Also hooked-up GC settings in the Manager.
\r
# Enable JGit-based garbage collection. (!!EXPERIMENTAL!!)\r
#\r
+# USE AT YOUR OWN RISK!\r
+#\r
# If enabled, the garbage collection executor scans all repositories once a day\r
# at the hour of your choosing. The GC executor will take each repository "offline",\r
# one-at-a-time, to check if the repository satisfies it's GC trigger requirements.\r
# especially on Windows systems, so if you are using other tools please coordinate\r
# their usage with your GC Executor schedule or do not use this feature.\r
#\r
-# Use this feature at your own risk!\r
-#\r
# The GC algorithm complex and the JGit team advises caution when using their\r
# young implementation of GC.\r
#\r
# SINCE 1.2.0\r
git.defaultGarbageCollectionThreshold = 500k\r
\r
-# The default period between GCs for a repository. If the total filesize of the\r
-# loose object exceeds *git.garbageCollectionThreshold* or the repository's\r
+# The default period, in days, between GCs for a repository. If the total filesize\r
+# of the loose object exceeds *git.garbageCollectionThreshold* or the repository's\r
# custom threshold, this period will be short-circuited. \r
#\r
# e.g. if a repository collects 100KB of loose objects every day with a 500KB\r
# The minimum value is 1 day since the GC Executor only runs once a day.\r
#\r
# SINCE 1.2.0\r
-git.defaultGarbageCollectionPeriod = 7 days\r
+git.defaultGarbageCollectionPeriod = 7\r
\r
# Number of bytes of a pack file to load into memory in a single read operation.\r
# This is the "page size" of the JGit buffer cache, used for all pack access\r
\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.utils.FileUtils;\r
-import com.gitblit.utils.TimeUtils;\r
\r
/**\r
* The GC executor handles periodic garbage collection in repositories.\r
RepoStatistics stats = gc.getStatistics();\r
\r
// determine if this is a scheduled GC\r
- int gcPeriodInDays = TimeUtils.convertFrequencyToMinutes(model.gcPeriod)/(60*24);\r
Calendar cal = Calendar.getInstance();\r
cal.setTime(model.lastGC);\r
cal.set(Calendar.HOUR_OF_DAY, 0);\r
cal.set(Calendar.MINUTE, 0);\r
cal.set(Calendar.SECOND, 0);\r
cal.set(Calendar.MILLISECOND, 0);\r
- cal.add(Calendar.DATE, gcPeriodInDays);\r
+ cal.add(Calendar.DATE, model.gcPeriod);\r
Date gcDate = cal.getTime();\r
boolean shouldCollectGarbage = now.after(gcDate);\r
\r
Constants.CONFIG_GITBLIT, null, "federationSets")));\r
model.isFederated = getConfig(config, "isFederated", false);\r
model.gcThreshold = getConfig(config, "gcThreshold", settings.getString(Keys.git.defaultGarbageCollectionThreshold, "500KB"));\r
- model.gcPeriod = getConfig(config, "gcPeriod", settings.getString(Keys.git.defaultGarbageCollectionPeriod, "7 days"));\r
+ model.gcPeriod = getConfig(config, "gcPeriod", settings.getInteger(Keys.git.defaultGarbageCollectionPeriod, 7));\r
try {\r
model.lastGC = new SimpleDateFormat(Constants.ISO8601).parse(getConfig(config, "lastGC", "1970-01-01'T'00:00:00Z"));\r
} catch (Exception e) {\r
private boolean getConfig(StoredConfig config, String field, boolean defaultValue) {\r
return config.getBoolean(Constants.CONFIG_GITBLIT, field, defaultValue);\r
}\r
+ \r
+ /**\r
+ * Returns the gitblit string value for the specified key. If key is not\r
+ * set, returns defaultValue.\r
+ * \r
+ * @param config\r
+ * @param field\r
+ * @param defaultValue\r
+ * @return field value or defaultValue\r
+ */\r
+ private int getConfig(StoredConfig config, String field, int defaultValue) {\r
+ String value = config.getString(Constants.CONFIG_GITBLIT, null, field);\r
+ if (StringUtils.isEmpty(value)) {\r
+ return defaultValue;\r
+ }\r
+ try {\r
+ return Integer.parseInt(value);\r
+ } catch (Exception e) {\r
+ }\r
+ return defaultValue;\r
+ }\r
\r
/**\r
* Creates/updates the repository model keyed by reopsitoryName. Saves all\r
repository.federationStrategy.name());\r
config.setBoolean(Constants.CONFIG_GITBLIT, null, "isFederated", repository.isFederated);\r
config.setString(Constants.CONFIG_GITBLIT, null, "gcThreshold", repository.gcThreshold);\r
- config.setString(Constants.CONFIG_GITBLIT, null, "gcPeriod", repository.gcPeriod);\r
+ config.setInt(Constants.CONFIG_GITBLIT, null, "gcPeriod", repository.gcPeriod);\r
if (repository.lastGC != null) {\r
config.setString(Constants.CONFIG_GITBLIT, null, "lastGC", new SimpleDateFormat(Constants.ISO8601).format(repository.lastGC));\r
}\r
private JComboBox ownerField;\r
\r
private JComboBox headRefField;\r
+ \r
+ private JComboBox gcPeriod;\r
+ \r
+ private JTextField gcThreshold;\r
\r
private RegistrantPermissionsPanel usersPalette;\r
\r
anRepository.availableRefs.toArray());\r
headRefField.setSelectedItem(anRepository.HEAD);\r
}\r
+ \r
+ Integer [] gcPeriods = { 1, 2, 3, 4, 5, 7, 10, 14 };\r
+ gcPeriod = new JComboBox(gcPeriods);\r
+ gcPeriod.setSelectedItem(anRepository.gcPeriod);\r
+ \r
+ gcThreshold = new JTextField(8);\r
+ gcThreshold.setText(anRepository.gcThreshold);\r
\r
ownerField = new JComboBox();\r
\r
.add(newFieldPanel(Translation.get("gb.origin"), originField));\r
fieldsPanel.add(newFieldPanel(Translation.get("gb.headRef"), headRefField));\r
fieldsPanel.add(newFieldPanel(Translation.get("gb.owner"), ownerField));\r
+ fieldsPanel.add(newFieldPanel(Translation.get("gb.gcPeriod"), gcPeriod));\r
+ fieldsPanel.add(newFieldPanel(Translation.get("gb.gcThreshold"), gcThreshold));\r
\r
fieldsPanel.add(newFieldPanel(Translation.get("gb.enableTickets"),\r
useTickets));\r
: ownerField.getSelectedItem().toString();\r
repository.HEAD = headRefField.getSelectedItem() == null ? null\r
: headRefField.getSelectedItem().toString();\r
+ repository.gcPeriod = (Integer) gcPeriod.getSelectedItem();\r
+ repository.gcThreshold = gcThreshold.getText();\r
repository.useTickets = useTickets.isSelected();\r
repository.useDocs = useDocs.isSelected();\r
repository.showRemoteBranches = showRemoteBranches.isSelected();\r
public String originRepository;\r
public boolean verifyCommitter;\r
public String gcThreshold;\r
- public String gcPeriod;\r
+ public int gcPeriod;\r
\r
public transient boolean isCollectingGarbage;\r
public Date lastGC;\r
}\r
form.add(new DropDownChoice<String>("HEAD", availableRefs).setEnabled(availableRefs.size() > 0));\r
\r
- List<String> gcPeriods = Arrays.asList("1 day", "2 days", "3 days", "4 days", "5 days", "7 days", "10 days", "14 days");\r
- form.add(new DropDownChoice<String>("gcPeriod", gcPeriods));\r
- form.add(new TextField<String>("gcThreshold"));\r
+ boolean gcEnabled = GitBlit.getBoolean(Keys.git.enableGarbageCollection, false); \r
+ List<Integer> gcPeriods = Arrays.asList(1, 2, 3, 4, 5, 7, 10, 14 );\r
+ form.add(new DropDownChoice<Integer>("gcPeriod", gcPeriods, new GCPeriodRenderer()).setEnabled(gcEnabled));\r
+ form.add(new TextField<String>("gcThreshold").setEnabled(gcEnabled));\r
\r
// federation strategies - remove ORIGIN choice if this repository has\r
// no origin.\r
return Integer.toString(index);\r
}\r
}\r
+ \r
+ private class GCPeriodRenderer implements IChoiceRenderer<Integer> {\r
+\r
+ private static final long serialVersionUID = 1L;\r
+\r
+ public GCPeriodRenderer() {\r
+ }\r
+\r
+ @Override\r
+ public String getDisplayValue(Integer value) {\r
+ if (value == 1) {\r
+ return getString("gb.duration.oneDay");\r
+ } else {\r
+ return MessageFormat.format(getString("gb.duration.days"), value);\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public String getIdValue(Integer value, int index) {\r
+ return Integer.toString(index);\r
+ }\r
+ }\r
+ \r
}\r