]> source.dussan.org Git - gitblit.git/commitdiff
Refactor GC period into an integer for simpler translations
authorJames Moger <james.moger@gitblit.com>
Tue, 30 Oct 2012 21:01:57 +0000 (17:01 -0400)
committerJames Moger <james.moger@gitblit.com>
Tue, 30 Oct 2012 21:01:57 +0000 (17:01 -0400)
Also hooked-up GC settings in the Manager.

distrib/gitblit.properties
src/com/gitblit/GCExecutor.java
src/com/gitblit/GitBlit.java
src/com/gitblit/client/EditRepositoryDialog.java
src/com/gitblit/models/RepositoryModel.java
src/com/gitblit/wicket/pages/EditRepositoryPage.java

index 434322946ef5735d36f34e814164306019a7b10e..411699ff91472d752d9abfe71ce3e68fdf5b2761 100644 (file)
@@ -110,6 +110,8 @@ git.defaultAuthorizationControl = NAMED
 \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
@@ -121,8 +123,6 @@ git.defaultAuthorizationControl = NAMED
 # 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
@@ -148,8 +148,8 @@ git.garbageCollectionHour = 0
 # 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
@@ -167,7 +167,7 @@ git.defaultGarbageCollectionThreshold = 500k
 # 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
index c5fe43b4e974b4765196e3c44ae4c2535214798a..243cbb92db14c2761b59527e10b1a0ae9232176b 100644 (file)
@@ -33,7 +33,6 @@ import org.slf4j.LoggerFactory;
 \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
@@ -162,14 +161,13 @@ public class GCExecutor implements Runnable {
                                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
index 6e587caa1c4d1c8d81198feca7c5146a29c0ef8e..e7b7bb9bae346180b8d7d4aa88b093d604da0719 100644 (file)
@@ -1445,7 +1445,7 @@ public class GitBlit implements ServletContextListener {
                                        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
@@ -1730,6 +1730,27 @@ public class GitBlit implements ServletContextListener {
        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
@@ -1896,7 +1917,7 @@ public class GitBlit implements ServletContextListener {
                                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
index 06621c21b823f6780034ebf558b597c7ae8a4192..d91d18dd387366d8c1bdd519633706d0e5aab5df 100644 (file)
@@ -120,6 +120,10 @@ public class EditRepositoryDialog extends JDialog {
        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
@@ -193,6 +197,13 @@ public class EditRepositoryDialog extends JDialog {
                                        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
@@ -288,6 +299,8 @@ public class EditRepositoryDialog extends JDialog {
                                .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
@@ -534,6 +547,8 @@ public class EditRepositoryDialog extends JDialog {
                                : 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
index 23ce9e3bf39bc56d9c3c3cc68acb63d870f714de..ed9e7188d0a03b964cde0ff5a201012f8709ae21 100644 (file)
@@ -77,7 +77,7 @@ public class RepositoryModel implements Serializable, Comparable<RepositoryModel
        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
index 58fdf66b3aa3763ddf8a902db2d69b77965d8384..f791cf608e3c99b9b276dcf6858f30ccf144d6b9 100644 (file)
@@ -389,9 +389,10 @@ public class EditRepositoryPage extends RootSubPage {
                }\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
@@ -619,4 +620,27 @@ public class EditRepositoryPage extends RootSubPage {
                        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