diff options
author | James Moger <james.moger@gitblit.com> | 2013-11-13 17:56:50 -0500 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2013-11-13 17:56:50 -0500 |
commit | c44dd099a432094a12131cf60dfc8a19f5aa8101 (patch) | |
tree | d71d6130a1bd5a85a3c5b764a28b5eeebcc97906 /src/main/java/com/gitblit/GitBlit.java | |
parent | 064857d7b2a7e1a0c205dbecf7b5f147221898a2 (diff) | |
download | gitblit-c44dd099a432094a12131cf60dfc8a19f5aa8101.tar.gz gitblit-c44dd099a432094a12131cf60dfc8a19f5aa8101.zip |
Implement mirror executor (issue-5)
The mirror executor will fetch ref updates for repository mirrors. This
feature is disabled by default and can be enabled by setting
git.enableMirroring=true. The period between update checks is
configurable, but it is global. An individual rpeository may not set
it's own update schedule.
Requirements:
1. you must manually clone the repository using native git
git clone --mirror git://somewhere.com/myrepo.git
2. the "origin" remote must be the mirror source
3. the "origin" repository must be accessible without authentication OR
the credentials must be embedded in the origin url (not recommended)
Notes:
1. "origin" SSH urls are untested and not likely to work
2. mirrors cloned while Gitblit is running are likely to require
clearing the gitblit cache (link on the repositories page of an
administrator account)
3. Gitblit will automatically repair any invalid fetch refspecs with a
"//" sequence.
Change-Id: I4bbe3fb2df106366ae4c2313596d0fab0dfcac46
Diffstat (limited to 'src/main/java/com/gitblit/GitBlit.java')
-rw-r--r-- | src/main/java/com/gitblit/GitBlit.java | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/main/java/com/gitblit/GitBlit.java b/src/main/java/com/gitblit/GitBlit.java index f313b6e3..a0e8b0a3 100644 --- a/src/main/java/com/gitblit/GitBlit.java +++ b/src/main/java/com/gitblit/GitBlit.java @@ -164,7 +164,7 @@ public class GitBlit implements ServletContextListener { private final Logger logger = LoggerFactory.getLogger(GitBlit.class); - private final ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(5); + private final ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(10); private final List<FederationModel> federationRegistrations = Collections .synchronizedList(new ArrayList<FederationModel>()); @@ -207,6 +207,8 @@ public class GitBlit implements ServletContextListener { private GCExecutor gcExecutor; + private MirrorExecutor mirrorExecutor; + private TimeZone timezone; private FileBasedConfig projectConfigs; @@ -2035,6 +2037,7 @@ public class GitBlit implements ServletContextListener { model.origin = config.getString("remote", "origin", "url"); if (model.origin != null) { model.origin = model.origin.replace('\\', '/'); + model.isMirror = config.getBoolean("remote", "origin", "mirror", false); } model.preReceiveScripts = new ArrayList<String>(Arrays.asList(config.getStringList( Constants.CONFIG_GITBLIT, null, "preReceiveScript"))); @@ -3505,6 +3508,7 @@ public class GitBlit implements ServletContextListener { mailExecutor = new MailExecutor(settings); luceneExecutor = new LuceneExecutor(settings, repositoriesFolder); gcExecutor = new GCExecutor(settings); + mirrorExecutor = new MirrorExecutor(settings); // initialize utilities String prefix = settings.getString(Keys.git.userRepositoryPrefix, "~"); @@ -3544,6 +3548,7 @@ public class GitBlit implements ServletContextListener { configureMailExecutor(); configureLuceneIndexing(); configureGarbageCollector(); + configureMirrorExecutor(); if (startFederation) { configureFederation(); } @@ -3595,6 +3600,19 @@ public class GitBlit implements ServletContextListener { } } + protected void configureMirrorExecutor() { + if (mirrorExecutor.isReady()) { + int mins = TimeUtils.convertFrequencyToMinutes(settings.getString(Keys.git.mirrorPeriod, "30 mins")); + if (mins < 5) { + mins = 5; + } + int delay = 1; + scheduledExecutor.scheduleAtFixedRate(mirrorExecutor, delay, mins, TimeUnit.MINUTES); + logger.info("Mirror executor is scheduled to fetch updates every {} minutes.", mins); + logger.info("Next scheduled mirror fetch is in {} minutes", delay); + } + } + protected void configureJGit() { // Configure JGit WindowCacheConfig cfg = new WindowCacheConfig(); @@ -3864,6 +3882,7 @@ public class GitBlit implements ServletContextListener { scheduledExecutor.shutdownNow(); luceneExecutor.close(); gcExecutor.close(); + mirrorExecutor.close(); if (fanoutService != null) { fanoutService.stop(); } |