Christian Specht avatar Christian Specht committed d7e2ce4

use new timeout value when pulling hg repositories (fixes #15)

Comments (0)

Files changed (8)

src/BitbucketBackup/BitbucketBackup.csproj

     <Compile Include="IConfig.cs">
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="IRepository.cs" />
+    <Compile Include="IRepositoryFactory.cs" />
     <Compile Include="IRepositoryUpdater.cs" />
     <Compile Include="MercurialRepository.cs" />
     <Compile Include="Properties\Settings.Designer.cs">

src/BitbucketBackup/IRepository.cs

+
+namespace BitbucketBackup
+{
+    internal interface IRepository
+    {
+        /// <summary>
+        /// Message to display when pulling from the remote repository
+        /// </summary>
+        string PullingMessage { get; }
+
+        /// <summary>
+        /// Pulls from the remote repository to the local one.
+        /// </summary>
+        void Pull();
+    }
+}

src/BitbucketBackup/IRepositoryFactory.cs

+
+namespace BitbucketBackup
+{
+    internal interface IRepositoryFactory
+    {
+        /// <summary>
+        /// Creates a new instance of the given repository type
+        /// </summary>
+        /// <param name="repoType">The desired repository type</param>
+        /// <param name="remoteUri">The URI of the remote repository</param>
+        /// <param name="localFolder">The folder where the local repository is (or will be)</param>
+        /// <returns>new repository instance</returns>
+        IRepository Create(string repoType, string remoteUri, string localFolder);
+    }
+}

src/BitbucketBackup/MercurialRepository.cs

     internal class MercurialRepository : RepositoryBase
     {
         private Repository repo;
+        private IConfig config;
 
-        public MercurialRepository(string remoteUri, string folder) : base(remoteUri, folder) { }
+        public MercurialRepository(string remoteUri, string folder, IConfig config) : base(remoteUri, folder)
+        {
+            this.config = config;
+        }
 
         public override string PullingMessage
         {
                 throw new InvalidOperationException("You need to call Init() first!");
             }
 
-            this.repo.Pull(this.remoteuri, new PullCommand().WithUpdate(false));
+            this.repo.Pull(this.remoteuri, new PullCommand().WithUpdate(false).WithTimeout(this.config.PullTimeout));
         }
     }
 }

src/BitbucketBackup/Program.cs

             kernel.Bind<IBitbucketBackup>().To<BitbucketBackup>();
             kernel.Bind<IBitbucketRequest>().To<BitbucketRequest>();
             kernel.Bind<IRepositoryUpdater>().To<RepositoryUpdater>();
+            kernel.Bind<IRepositoryFactory>().To<RepositoryFactory>();
             kernel.Bind<IConfig>().To<Config>().InSingletonScope();
 
             kernel.Get<IBitbucketBackup>().Execute();

src/BitbucketBackup/RepositoryBase.cs

     /// <summary>
     /// Abstract base class for repository implementations
     /// </summary>
-    internal abstract class RepositoryBase
+    internal abstract class RepositoryBase : IRepository
     {
         protected string remoteuri;
         protected string folder;

src/BitbucketBackup/RepositoryFactory.cs

 
 namespace BitbucketBackup
 {
-    internal class RepositoryFactory
+    internal class RepositoryFactory : IRepositoryFactory
     {
+        private IConfig config;
+
+        public RepositoryFactory(IConfig config)
+        {
+            this.config = config;
+        }
+
         /// <summary>
         /// Creates a new instance of the given repository type
         /// </summary>
         /// <param name="remoteUri">The URI of the remote repository</param>
         /// <param name="localFolder">The folder where the local repository is (or will be)</param>
         /// <returns>new repository instance</returns>
-        public static RepositoryBase Create(string repoType, string remoteUri, string localFolder)
+        public IRepository Create(string repoType, string remoteUri, string localFolder)
         {
             switch (repoType.ToLower())
             {
                 case "hg":
-                    return new MercurialRepository(remoteUri, localFolder);
+                    return new MercurialRepository(remoteUri, localFolder, this.config);
                 case "git":
                     return new GitRepository(remoteUri, localFolder);
                 default:

src/BitbucketBackup/RepositoryUpdater.cs

     internal class RepositoryUpdater : IRepositoryUpdater
     {
         private IConfig config;
+        private IRepositoryFactory factory;
 
         /// <summary>
         /// Creates a new RepositoryUpdater instance
         /// </summary>
         /// <param name="config">configuration settings</param>
-        public RepositoryUpdater(IConfig config)
+        public RepositoryUpdater(IConfig config, IRepositoryFactory factory)
         {
             this.config = config;
+            this.factory = factory;
         }
 
         /// <summary>
         {
             var uriWithAuth = this.BuildUriWithAuth(repoUri);
 
-            var repo = RepositoryFactory.Create(repoType, uriWithAuth.ToString(), localFolder);
+            var repo = this.factory.Create(repoType, uriWithAuth.ToString(), localFolder);
             
             if (repo.PullingMessage.Contains("{0}"))
             {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.