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