diff --git a/scm-core/src/main/java/sonia/scm/repository/work/SimpleCachingWorkingCopyPool.java b/scm-core/src/main/java/sonia/scm/repository/work/SimpleCachingWorkingCopyPool.java index 7033d59772..1cb38a72f0 100644 --- a/scm-core/src/main/java/sonia/scm/repository/work/SimpleCachingWorkingCopyPool.java +++ b/scm-core/src/main/java/sonia/scm/repository/work/SimpleCachingWorkingCopyPool.java @@ -40,7 +40,7 @@ import java.util.concurrent.ConcurrentHashMap; * requested for a repository with {@link #getWorkingCopy(SimpleWorkingCopyFactory.WorkingCopyContext)}, * this implementation fetches a new directory from the {@link WorkdirProvider}. * On {@link #contextClosed(SimpleWorkingCopyFactory.WorkingCopyContext, File)}, - * the directory is not deleted, buy put into a map with the repository id as key. + * the directory is not deleted, but put into a map with the repository id as key. * When a working copy is requested with {@link #getWorkingCopy(SimpleWorkingCopyFactory.WorkingCopyContext)} * for a repository with such an existing directory, it is taken from the map, reclaimed and * returned as {@link WorkingCopy}. diff --git a/scm-core/src/main/java/sonia/scm/repository/work/SimpleWorkingCopyFactory.java b/scm-core/src/main/java/sonia/scm/repository/work/SimpleWorkingCopyFactory.java index 0b842ad78c..0905ce1081 100644 --- a/scm-core/src/main/java/sonia/scm/repository/work/SimpleWorkingCopyFactory.java +++ b/scm-core/src/main/java/sonia/scm/repository/work/SimpleWorkingCopyFactory.java @@ -55,97 +55,10 @@ import java.io.File; *
{@link #closeRepository(R)}
*
Closes resources allocated for the central repository.
* - *
- *                     ┌─────────────┐          ┌───────────────────────────┐                                        ┌───────────────┐                                 ┌───────────────┐
- *                     │ModifyCommand│          │SimpleGitWorkingCopyFactory│                                        │WorkingCopyPool│                                 │WorkdirProvider│
- *                     └──────┬──────┘          └─────────────┬─────────────┘                                        └───────┬───────┘                                 └───────┬───────┘
- *                            │      createWorkingCopy        │                                                              │                                                 │
- *                            │──────────────────────────────>│                                                              │                                                 │
- *                            │                               │                                                              │                                                 │
- *                            │                               │        create          ┌──────────────────┐                  │                                                 │
- *                            │                               │──────────────────────> │WorkingCopyContext│                  │                                                 │
- *                            │                               │                        └────────┬─────────┘                  │                                                 │
- *                            │                               │                       getWorkingCopy                         │                                                 │
- *                            │                               │─────────────────────────────────────────────────────────────>│                                                 │
- *                            │                               │                                 │                            │                                                 │
- *                            │                               │                                 │                            │                                                 │
- *                            │                               │                                 │                            │                                                 │
- *                            │                               │                                 │                            │                                                 │
- *                            │                               │                                 │          reclaim           │                                                 │
- *                            │                               │                                 │ <──────────────────────────│                                                 │
- *                            │                               │                                 │                            │                                                 │
- *                            │                               │                                 │                            │                                                 │
- *                            │                               │              ╔══════╤═══════════╪════════════════════════════╪═════════════════════════════════════════════════╪═════════════════╗
- *                            │                               │              ║ ALT  │  reclaim successful                    │                                                 │                 ║
- *                            │                               │              ╟──────┘           │                            │                                                 │                 ║
- *                            │                               │              ║                  │                            │                  ┌───────────┐                  │                 ║
- *                            │                               │              ║                  │ ─────────────────────────────────────────────>│WorkingCopy│                  │                 ║
- *                            │                               │              ║                  │                            │                  └─────┬─────┘                  │                 ║
- *                            │                               │              ║                  │        WorkingCopy         │                                                 │                 ║
- *                            │                               │              ║                  │ ──────────────────────────>│                                                 │                 ║
- *                            │                               │              ╠══════════════════╪════════════════════════════╪═════════════════════════════════════════════════╪═════════════════╣
- *                            │                               │              ║ [reclaim fails; create new]                   │                                                 │                 ║
- *                            │                               │              ║                  │   ReclaimFailedException   │                                                 │                 ║
- *                            │                               │              ║                  │ ──────────────────────────>│                                                 │                 ║
- *                            │                               │              ║                  │                            │                                                 │                 ║
- *                            │                               │              ║                  │                            │                createNewWorkdir                 │                 ║
- *                            │                               │              ║                  │                            │────────────────────────────────────────────────>│                 ║
- *                            │                               │              ║                  │                            │                                                 │                 ║
- *                            │                               │              ║                  │                            │                                                 │                 ║
- *                            │                               │              ║                  │                            │<────────────────────────────────────────────────│                 ║
- *                            │                               │              ║                  │                            │                                                 │                 ║
- *                            │                               │              ║                  │         initialize         │                                                 │                 ║
- *                            │                               │              ║                  │ <──────────────────────────│                                                 │                 ║
- *                            │                               │              ║                  │                            │                                                 │                 ║
- *                            │                               │              ║                  │                            │                  ┌───────────┐                  │                 ║
- *                            │                               │              ║                  │ ─────────────────────────────────────────────>│WorkingCopy│                  │                 ║
- *                            │                               │              ║                  │                            │                  └─────┬─────┘                  │                 ║
- *                            │                               │              ║                  │        WorkingCopy         │                        │                        │                 ║
- *                            │                               │              ║                  │ ──────────────────────────>│                        │                        │                 ║
- *                            │                               │              ╚══════════════════╪════════════════════════════╪════════════════════════╪════════════════════════╪═════════════════╝
- *                            │                               │                                 │                            │                        │                        │
- *                            │                               │                         WorkingCopy                          │                        │                        │
- *                            │                               │<─────────────────────────────────────────────────────────────│                        │                        │
- *                            │                               │                                 │                            │                        │                        │
- *                            │         WorkingCopy           │                                 │                            │                        │                        │
- *                            │<──────────────────────────────│                                 │                            │                        │                        │
- *                            │                               │                                 │                            │                        │                        │
- *                            .                               .                                 .                            .                        .                        .
- *                            .                               .                                 .                            .                        .                        .
- *                            .                               .                                 .                            .                        .                        .
- *                            .                               .                                 .                            .                        .                        .
- *                            │                               │                        doWork   │                            │                        │                        │
- *                            │──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────>│                        │
- *                            │                               │                                 │                            │                        │                        │
- *                            .                               .                                 .                            .                        .                        .
- *                            .                               .                                 .                            .                        .                        .
- *                            .                               .                                 .                            .                        .                        .
- *                            .                               .                                 .                            .                        .                        .
- *                            │                               │                        close    │                            │                        │                        │
- *                            │──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────>│                        │
- *                            │                               │                                 │                            │                        │                        │
- *                            │                               │                                 │      close                 │                        │                        │
- *                            │                               │<──────────────────────────────────────────────────────────────────────────────────────│                        │
- *                            │                               │                                 │                            │                        │                        │
- *                            │                               ────┐                             │                            │                        │                        │
- *                            │                                   │ closeWorkingCopy            │                            │                        │                        │
- *                            │                               <───┘                             │                            │                        │                        │
- *                            │                               │                                 │                            │                        │                        │
- *                            │                               ────┐                             │                            │                        │                        │
- *                            │                                   │ closeRepository             │                            │                        │                        │
- *                            │                               <───┘                             │                            │                        │                        │
- *                            │                               │                                 │                            │                        │                        │
- *                            │                               │                        contextClosed                         │                        │                        │
- *                            │                               │─────────────────────────────────────────────────────────────>│                        │                        │
- *                            │                               │                                 │                            │                        │                        │
- *                            │                               │                                 │                            ────┐                    │                        │
- *                            │                               │                                 │                                │ cacheDirectory     │                        │
- *                            │                               │                                 │                            <───┘                    │                        │
- *                     ┌──────┴──────┐          ┌─────────────┴─────────────┐          ┌────────┴─────────┐          ┌───────┴───────┐          ┌─────┴─────┐          ┌───────┴───────┐
- *                     │ModifyCommand│          │SimpleGitWorkingCopyFactory│          │WorkingCopyContext│          │WorkingCopyPool│          │WorkingCopy│          │WorkdirProvider│
- *                     └─────────────┘          └───────────────────────────┘          └──────────────────┘          └───────────────┘          └───────────┘          └───────────────┘
- * 
- * + *
+ * The general process looks like this: + *
+ * * @param Type of central repository location * @param Type of working copy for repository * @param Type of repository context diff --git a/scm-core/src/main/java/sonia/scm/repository/work/doc-files/SimpleWorkingCopyFactory_Sequence.png b/scm-core/src/main/java/sonia/scm/repository/work/doc-files/SimpleWorkingCopyFactory_Sequence.png new file mode 100644 index 0000000000..6e9306bddd Binary files /dev/null and b/scm-core/src/main/java/sonia/scm/repository/work/doc-files/SimpleWorkingCopyFactory_Sequence.png differ diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitWorkingCopyInitializer.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitWorkingCopyInitializer.java index d48a64cc25..11019b288c 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitWorkingCopyInitializer.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitWorkingCopyInitializer.java @@ -24,6 +24,7 @@ package sonia.scm.repository.spi; +import com.google.common.base.Stopwatch; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.lib.Constants; @@ -54,7 +55,7 @@ class GitWorkingCopyInitializer { public ParentAndClone initialize(File target, String initialBranch) { LOG.trace("clone repository {}", context.getRepository().getId()); - long start = System.nanoTime(); + Stopwatch stopwatch = Stopwatch.createStarted(); try { Repository clone = Git.cloneRepository() .setURI(simpleGitWorkingCopyFactory.createScmTransportProtocolUri(context.getDirectory())) @@ -73,9 +74,7 @@ class GitWorkingCopyInitializer { } catch (GitAPIException | IOException e) { throw new InternalRepositoryException(context.getRepository(), "could not clone working copy of repository", e); } finally { - long end = System.nanoTime(); - long duration = end - start; - LOG.trace("took {} ns to clone repository {}", duration, context.getRepository().getId()); + LOG.trace("took {} to clone repository {}", stopwatch.stop(), context.getRepository().getId()); } } } diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitWorkingCopyReclaimer.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitWorkingCopyReclaimer.java index c5ffd24aa7..3b605b531e 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitWorkingCopyReclaimer.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitWorkingCopyReclaimer.java @@ -24,6 +24,7 @@ package sonia.scm.repository.spi; +import com.google.common.base.Stopwatch; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.ResetCommand; import org.eclipse.jgit.api.errors.GitAPIException; @@ -49,7 +50,7 @@ class GitWorkingCopyReclaimer { public ParentAndClone reclaim(File target, String initialBranch) throws SimpleWorkingCopyFactory.ReclaimFailedException { LOG.trace("reclaim repository {}", context.getRepository().getId()); - long start = System.nanoTime(); + Stopwatch stopwatch = Stopwatch.createStarted(); Repository repo = openTarget(target); try (Git git = Git.open(target)) { git.reset().setMode(ResetCommand.ResetType.HARD).call(); @@ -62,9 +63,7 @@ class GitWorkingCopyReclaimer { } catch (GitAPIException | IOException e) { throw new SimpleWorkingCopyFactory.ReclaimFailedException(e); } finally { - long end = System.nanoTime(); - long duration = end - start; - LOG.trace("took {} ns to reclaim repository {}\n", duration, context.getRepository().getId()); + LOG.trace("took {} to reclaim repository {}", stopwatch.stop(), context.getRepository().getId()); } } diff --git a/scm-webapp/src/main/java/sonia/scm/lifecycle/modules/WorkingCopyPoolModule.java b/scm-webapp/src/main/java/sonia/scm/lifecycle/modules/WorkingCopyPoolModule.java index 209e8263d0..a6871b8b74 100644 --- a/scm-webapp/src/main/java/sonia/scm/lifecycle/modules/WorkingCopyPoolModule.java +++ b/scm-webapp/src/main/java/sonia/scm/lifecycle/modules/WorkingCopyPoolModule.java @@ -45,7 +45,7 @@ public class WorkingCopyPoolModule extends AbstractModule { Class strategyClass = (Class) classLoader.loadClass(workingCopyPoolStrategy); bind(WorkingCopyPool.class).to(strategyClass); } catch (Exception e) { - throw new RuntimeException("could not instantiate class for working copy pool: " + workingCopyPoolStrategy, e); + throw new IllegalStateException("could not instantiate class for working copy pool: " + workingCopyPoolStrategy, e); } } }