public IEnumerable <KeyValuePair <string, Uri> > GetRepositoryPaths(string basePath)
        {
            var uri         = new Uri(basePath);
            var listCommand = new SvnCommand("list")
            {
                (SvnPath)uri
            };
            var lines = listCommand.ReadLines();

            foreach (var line in lines)
            {
                if (line.EndsWith(PathUtility.Separator) == true)
                {
                    var name = line.Substring(0, line.Length - PathUtility.Separator.Length);
                    if (name == SvnString.Trunk)
                    {
                        yield return(new KeyValuePair <string, Uri>(SvnString.Default, UriUtility.Combine(uri, name)));
                    }
                    else if (name == SvnString.Tags || name == SvnString.Branches)
                    {
                        var subPath = Path.Combine(basePath, name);
                        foreach (var item in this.GetRepositoryPaths(subPath))
                        {
                            yield return(item);
                        }
                    }
                    else
                    {
                        yield return(new KeyValuePair <string, Uri>(name, UriUtility.Combine(uri, name)));
                    }
                }
            }
        }
        public IRepository CreateInstance(RepositorySettings settings)
        {
            var baseUri        = new Uri(settings.RemotePath);
            var repositoryName = settings.RepositoryName == string.Empty ? SvnString.Default : settings.RepositoryName;
            var url            = repositoryName == SvnString.Default ? UriUtility.Combine(baseUri, SvnString.Trunk) : UriUtility.Combine(baseUri, SvnString.Branches, settings.RepositoryName);

            if (Directory.Exists(settings.BasePath) == false)
            {
                var checkoutCommand = new SvnCommand("checkout")
                {
                    (SvnPath)url,
                    (SvnPath)settings.BasePath,
                };
                checkoutCommand.Run();
            }
            else
            {
                var updateCommand = new SvnCommand("update")
                {
                    (SvnPath)settings.BasePath,
                };
                updateCommand.Run();
            }

            var repositoryInfo = this.GetRepositoryInfo(settings.RemotePath, repositoryName);

            return(new SvnRepository(settings.LogService, settings.BasePath, settings.TransactionPath, repositoryInfo));
        }
        private IEnumerable <string> EnumerateRepositories(string basePath)
        {
            var uri         = new Uri(basePath);
            var listCommand = new SvnCommand("list")
            {
                (SvnPath)uri
            };
            var lines = listCommand.ReadLines();

            foreach (var line in lines)
            {
                if (line.EndsWith(PathUtility.Separator) == true)
                {
                    var name = line.Substring(0, line.Length - PathUtility.Separator.Length);
                    if (name == SvnString.Trunk)
                    {
                        yield return("default");
                    }
                    else if (name == SvnString.Tags || name == SvnString.Branches)
                    {
                        var subPath = Path.Combine(basePath, name);
                        foreach (var item in this.EnumerateRepositories(subPath))
                        {
                            yield return(item);
                        }
                    }
                    else
                    {
                        yield return(name);
                    }
                }
            }
        }
        public void InitializeRepository(string basePath, string initPath, params LogPropertyInfo[] properties)
        {
            var baseUri      = new Uri(basePath);
            var tempPath     = PathUtility.GetTempPath(true);
            var tagsPath     = DirectoryUtility.Prepare(tempPath, SvnString.Tags);
            var branchesPath = DirectoryUtility.Prepare(tempPath, SvnString.Branches);
            var trunkPath    = DirectoryUtility.Prepare(tempPath, SvnString.Trunk);

            if (baseUri.Scheme == Uri.UriSchemeFile)
            {
                var createCommand = new SvnAdminCommand("create")
                {
                    (SvnPath)basePath,
                    "--fs-type",
                    "fsfs"
                };
                createCommand.Run();
            }

            DirectoryUtility.Copy(initPath, trunkPath);

            var importCommand = new SvnCommand("import")
            {
                SvnCommandItem.FromMessage("first"),
                (SvnPath)tempPath,
                (SvnPath)baseUri,
            };

            importCommand.Run();
        }
示例#5
0
 public static               SvnLogInfo[] GetLogs(string path, string revision)
 {
     if (revision == null)
     {
         var logCommand = new SvnCommand("log")
         {
             (SvnPath)path,
             SvnCommandItem.FromRevision($"head:1"),
             SvnCommandItem.Xml,
             SvnCommandItem.Verbose,
             SvnCommandItem.FromMaxCount(MaxLogCount),
             SvnCommandItem.WithAllRevprops
         };
         return(SvnLogInfo.Read(logCommand.Run()));
     }
     else
     {
         var logCommand = new SvnCommand("log")
         {
             (SvnPath)path,
             SvnCommandItem.FromRevision($"{revision}:1"),
             SvnCommandItem.Xml,
             SvnCommandItem.Verbose,
             SvnCommandItem.FromMaxCount(MaxLogCount),
             SvnCommandItem.WithAllRevprops
         };
         return(SvnLogInfo.Read(logCommand.Run()));
     }
 }
        private void MoveTagsToBranches(string dataBasesPath)
        {
            var dataBaseUrl = new Uri(dataBasesPath);
            var tagsUrl     = UriUtility.Combine(dataBaseUrl, SvnString.Tags);
            var branchesUri = UriUtility.Combine(dataBaseUrl, SvnString.Branches);
            var listCommand = new SvnCommand("list")
            {
                (SvnPath)tagsUrl
            };
            var list = listCommand.ReadLines();

            foreach (var item in list)
            {
                if (item.EndsWith(PathUtility.Separator) == true)
                {
                    var name      = item.Remove(item.Length - PathUtility.Separator.Length);
                    var sourceUri = UriUtility.Combine(tagsUrl, name);
                    var destUri   = UriUtility.Combine(branchesUri, name);
                    //var log = SvnLogInfo.Run(sourceUri.ToString(), null, 1).First();
                    var moveCommand = new SvnCommand("mv")
                    {
                        (SvnPath)sourceUri,
                        (SvnPath)destUri,
                        SvnCommandItem.FromMessage($"Migrate: move {name} from tags to branches"),
                        SvnCommandItem.FromUsername(nameof(SvnRepositoryMigrator)),
                    };
                    moveCommand.Run();
                    //var propText = string.Join(" ", log.Properties.Select(i => $"--with-revprop \"{i.Prefix}{i.Key}={i.Value}\""));
                    //SvnClientHost.Run($"mv \"{sourceUri}\" \"{destUri}\" -m \"Migrate: move {name} from tags to branches\"", propText, $"--username {nameof(SvnRepositoryMigrator)}");
                }
            }
        }
示例#7
0
        public void Copy(string srcPath, string toPath)
        {
            var copyCommand = new SvnCommand("copy")
            {
                (SvnPath)srcPath,
                (SvnPath)toPath
            };

            copyCommand.Run(this.logService);
        }
示例#8
0
        public void Add(string path)
        {
            var addCommand = new SvnCommand("add")
            {
                new SvnCommandItem("depth", "files"),
                (SvnPath)path,
            };

            addCommand.Run(this.logService);
        }
示例#9
0
        public static SvnInfo Run(string path)
        {
            var infoCommand = new SvnCommand("info")
            {
                (SvnPath)path,
                SvnCommandItem.Xml,
            };

            return(Parse(infoCommand.Run()));
        }
        public string GetRevision(string basePath, string repositoryName)
        {
            var url         = this.GetUrl(basePath, repositoryName);
            var infoCommand = new SvnCommand("info")
            {
                (SvnPath)url,
                new SvnCommandItem("show-item", "last-changed-revision"),
            };

            return(infoCommand.ReadLine());
        }
示例#11
0
        public static               SvnLogInfo[] RunForGetBranch(Uri uri)
        {
            var logCommand = new SvnCommand("log")
            {
                (SvnPath)uri,
                SvnCommandItem.Xml,
                SvnCommandItem.Verbose,
                new SvnCommandItem("stop-on-copy")
            };

            return(SvnLogInfo.Read(logCommand.Run()));
        }
        private void DeleteUsers(string dataBasesPath)
        {
            var usersUrl      = UriUtility.Combine(new Uri(dataBasesPath), "users.xml");
            var deleteCommand = new SvnCommand("rm")
            {
                (SvnPath)usersUrl,
                SvnCommandItem.FromMessage("Migrate: delete users"),
                SvnCommandItem.FromUsername(nameof(SvnRepositoryMigrator)),
            };

            deleteCommand.Run();
        }
示例#13
0
        public static               SvnStatusInfo[] Run(params string[] paths)
        {
            var statusCommand = new SvnCommand("status")
            {
                SvnCommandItem.Xml
            };

            foreach (var item in paths)
            {
                statusCommand.Add((SvnPath)item);
            }
            return(Parse(statusCommand.Run()));
        }
        public string[] GetRepositoryItemList(string basePath, string repositoryName)
        {
            var uri         = this.GetUrl(basePath, repositoryName);
            var listCommand = new SvnCommand("list")
            {
                (SvnPath)uri, SvnCommandItem.Recursive
            };
            var lines = listCommand.ReadLines();
            var query = from item in lines
                        where item.Trim() != string.Empty
                        select PathUtility.Separator + item;

            return(query.ToArray());
        }
示例#15
0
        public string Export(Uri uri, string exportPath)
        {
            var pureUri       = new Uri(Regex.Replace($"{uri}", "@\\d+$", string.Empty));
            var relativeUri   = UriUtility.MakeRelativeOfDirectory(this.repositoryUri, pureUri);
            var uriTarget     = uri.LocalPath;
            var filename      = FileUtility.Prepare(exportPath, $"{relativeUri}");
            var exportCommand = new SvnCommand("export")
            {
                (SvnPath)uri, (SvnPath)filename
            };
            var result = exportCommand.Run(this.logService);

            return(new FileInfo(Path.Combine(exportPath, $"{relativeUri}")).FullName);
        }
示例#16
0
        public static               SvnLogInfo[] Run(string path, string minRevision, string maxRevision, int count)
        {
            var logCommand = new SvnCommand("log")
            {
                (SvnPath)path,
                SvnCommandItem.FromRevision($"{maxRevision}:{minRevision}"),
                SvnCommandItem.Xml,
                SvnCommandItem.Verbose,
                SvnCommandItem.FromMaxCount(count),
                SvnCommandItem.WithAllRevprops,
            };

            return(SvnLogInfo.Read(logCommand.Run()));
        }
        public void DeleteRepository(string author, string basePath, string repositoryName, string comment, params LogPropertyInfo[] properties)
        {
            var uri           = this.GetUrl(basePath, repositoryName);
            var props         = GeneratePropertiesArgument(properties);
            var deleteCommand = new SvnCommand("delete")
            {
                SvnCommandItem.FromMessage(comment),
                (SvnPath)uri,
                props,
                SvnCommandItem.FromUsername(author),
            };

            deleteCommand.Run();
        }
示例#18
0
        public static SvnLogInfo GetLatestLog(string path)
        {
            var logCommand = new SvnCommand("log")
            {
                (SvnPath)path,
                SvnCommandItem.FromRevision($"head:1"),
                SvnCommandItem.Xml,
                SvnCommandItem.Verbose,
                SvnCommandItem.FromMaxCount(1),
                SvnCommandItem.WithAllRevprops
            };

            return(SvnLogInfo.Read(logCommand.Run()).First());
        }
示例#19
0
        public void Revert()
        {
            this.revertCommand.Run(this.logService);
            this.cleanupCommand.Run(this.logService);

            if (File.Exists(this.transactionPatchPath) == true)
            {
                var patchCommand = new SvnCommand("patch")
                {
                    (SvnPath)this.transactionPatchPath,
                    (SvnPath)this.BasePath,
                };
                patchCommand.Run(this.logService);
            }
        }
        public void CloneRepository(string author, string basePath, string repositoryName, string newRepositoryName, string comment, string revision, params LogPropertyInfo[] properties)
        {
            var uri         = this.GetUrl(basePath, repositoryName);
            var newUri      = this.GenerateUrl(basePath, newRepositoryName);
            var props       = GeneratePropertiesArgument(properties);
            var copyCommand = new SvnCommand("copy")
            {
                SvnCommandItem.FromMessage(comment),
                (SvnPath)uri,
                (SvnPath)newUri,
                props,
                SvnCommandItem.FromUsername(author),
            };

            copyCommand.Run();
        }
示例#21
0
        public static               SvnLogInfo[] GetLogs(string[] paths, string revision)
        {
            var logCommand = new SvnCommand("log")
            {
                SvnCommandItem.FromRevision($"{revision ?? "head"}:1"),
                SvnCommandItem.Xml,
                SvnCommandItem.Verbose,
                SvnCommandItem.FromMaxCount(MaxLogCount),
                SvnCommandItem.WithAllRevprops,
            };

            foreach (var item in paths)
            {
                logCommand.Add((SvnPath)item);
            }
            return(SvnLogInfo.Read(logCommand.Run()));
        }
        public void CreateRepository(string author, string basePath, string initPath, string comment, params LogPropertyInfo[] properties)
        {
            var repositoryName = Path.GetFileName(initPath);
            var uri            = UriUtility.Combine(new Uri(basePath), SvnString.Branches, repositoryName);
            var props          = GeneratePropertiesArgument(properties);
            var importCommand  = new SvnCommand("import")
            {
                (SvnPath)initPath,
                (SvnPath)uri,
                SvnCommandItem.FromMessage(comment),
                SvnCommandItem.Force,
                props,
                SvnCommandItem.FromUsername(author),
            };

            importCommand.Run();
        }
示例#23
0
        public void Delete(string path)
        {
            var deleteCommand = new SvnCommand("delete")
            {
                (SvnPath)path,
                SvnCommandItem.Force,
            };

            if (DirectoryUtility.IsDirectory(path) == true)
            {
                var updateCommand = new SvnCommand("update")
                {
                    (SvnPath)path
                };
                updateCommand.Run(this.logService);
            }

            deleteCommand.Run(this.logService);
        }
示例#24
0
        public void Move(string srcPath, string toPath)
        {
            var moveCommand = new SvnCommand("move")
            {
                (SvnPath)srcPath,
                (SvnPath)toPath,
            };

            if (DirectoryUtility.IsDirectory(srcPath) == true)
            {
                var updateCommand = new SvnCommand("update")
                {
                    (SvnPath)srcPath
                };
                updateCommand.Run(this.logService);
            }

            moveCommand.Run(this.logService);
        }
示例#25
0
        public void EndTransaction()
        {
            var transactionMessage = string.Join(Environment.NewLine, this.transactionMessageList);
            var messagePath        = FileUtility.WriteAllText(transactionMessage, Encoding.UTF8, PathUtility.GetTempFileName());

            try
            {
                var items = this.statCommand.ReadLines(true);
                if (items.Length != 0)
                {
                    var propText      = SvnRepositoryProvider.GeneratePropertiesArgument(this.transactionPropertyList.ToArray());
                    var updateCommand = new SvnCommand("update")
                    {
                        (SvnPath)this.BasePath
                    };
                    var commitCommand = new SvnCommand("commit")
                    {
                        (SvnPath)this.BasePath,
                        SvnCommandItem.FromFile(messagePath),
                        propText,
                        SvnCommandItem.FromEncoding(Encoding.UTF8),
                        SvnCommandItem.FromUsername(this.transactionAuthor),
                    };
                    updateCommand.Run(this.logService);
                    commitCommand.Run(this.logService);
                    FileUtility.Delete(this.transactionPatchPath);
                    this.transactionAuthor       = null;
                    this.transactionName         = null;
                    this.transactionMessageList  = null;
                    this.transactionPropertyList = null;
                    this.transactionPatchPath    = null;
                }
                else
                {
                    this.logService?.Debug("repository has no changes.");
                }
            }
            finally
            {
                FileUtility.Delete(messagePath);
            }
        }
        private void PrepareBranches(string dataBasesPath)
        {
            var dataBaseUrl = new Uri(dataBasesPath);
            var listCommand = new SvnCommand("list")
            {
                (SvnPath)dataBaseUrl
            };
            var list = listCommand.ReadLines();

            if (list.Contains($"{SvnString.Branches}{PathUtility.Separator}") == false)
            {
                var branchesUrl  = UriUtility.Combine(dataBaseUrl, SvnString.Branches);
                var mkdirCommand = new SvnCommand("mkdir")
                {
                    (SvnPath)branchesUrl,
                    SvnCommandItem.FromMessage("Migrate: create branches"),
                    SvnCommandItem.FromUsername(nameof(SvnRepositoryMigrator)),
                };
                mkdirCommand.Run();
            }
        }
        public void RevertRepository(string author, string basePath, string repositoryName, string revision, string comment)
        {
            var baseUri  = new Uri(basePath);
            var url      = repositoryName == SvnString.Default ? UriUtility.Combine(baseUri, SvnString.Trunk) : UriUtility.Combine(baseUri, SvnString.Branches, repositoryName);
            var tempPath = PathUtility.GetTempPath(false);

            try
            {
                var checkoutCommand = new SvnCommand("checkout")
                {
                    (SvnPath)url,
                    (SvnPath)tempPath,
                };
                checkoutCommand.Run();
                var mergeCommand = new SvnCommand("merge")
                {
                    new SvnCommandItem('r', $"head:{revision}"),
                    (SvnPath)tempPath,
                    (SvnPath)tempPath,
                };
                mergeCommand.Run();
                var commitCommand = new SvnCommand("commit")
                {
                    (SvnPath)tempPath,
                    SvnCommandItem.FromMessage(comment),
                    SvnCommandItem.FromEncoding(Encoding.UTF8),
                    SvnCommandItem.FromUsername(author),
                };
                commitCommand.Run();
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                DirectoryUtility.Delete(tempPath);
            }
        }
示例#28
0
        public SvnRepository(ILogService logService, string repositoryPath, string transactionPath, RepositoryInfo repositoryInfo)
        {
            this.logService      = logService;
            this.BasePath        = repositoryPath;
            this.transactionPath = transactionPath;
            this.repositoryInfo  = repositoryInfo;
            this.revertCommand   = new SvnCommand("revert")
            {
                (SvnPath)this.BasePath,
                SvnCommandItem.Recursive,
            };

            this.cleanupCommand = new SvnCommand("cleanup")
            {
                (SvnPath)this.BasePath
            };

            this.statCommand = new SvnCommand("stat")
            {
                (SvnPath)this.BasePath,
                SvnCommandItem.Quiet
            };
            var items = this.statCommand.ReadLines(true);

            if (items.Length != 0)
            {
                var sb = new StringBuilder();
                sb.AppendLine($"Repository is dirty. Please fix the problem before running the service.");
                sb.AppendLine();
                sb.AppendLine(string.Join(Environment.NewLine, items));
                throw new Exception($"{sb}");
            }

            this.info           = SvnInfo.Run(this.BasePath);
            this.RepositoryRoot = this.info.RepositoryRoot;
            this.repositoryUri  = this.info.Uri;
        }
示例#29
0
        public void Commit(string author, string comment, params LogPropertyInfo[] properties)
        {
            if (this.transactionName != null)
            {
                var diffCommand = new SvnCommand("diff")
                {
                    (SvnPath)this.BasePath,
                    new SvnCommandItem("patch-compatible")
                };
                var output = diffCommand.ReadLine();
                File.WriteAllText(this.transactionPatchPath, output);
                this.transactionMessageList.Add(comment);
                this.transactionPropertyList.AddRange(properties);
                return;
            }

            this.logService?.Debug($"repository committing {(SvnPath)this.BasePath}");
            var result        = string.Empty;
            var commentPath   = PathUtility.GetTempFileName();
            var propText      = SvnRepositoryProvider.GeneratePropertiesArgument(properties);
            var updateCommand = new SvnCommand("update")
            {
                (SvnPath)this.BasePath
            };
            var commitCommand = new SvnCommand("commit")
            {
                (SvnPath)this.BasePath,
                SvnCommandItem.FromMessage(comment),
                propText,
                SvnCommandItem.FromEncoding(Encoding.UTF8),
                SvnCommandItem.FromUsername(author),
            };

            try
            {
                if (this.needToUpdate == true)
                {
                    updateCommand.Run(this.logService);
                }

                result = commitCommand.Run(this.logService);
            }
            catch (Exception e)
            {
                this.logService?.Warn(e);
                updateCommand.Run(this.logService);
                result = commitCommand.Run(this.logService);
            }
            finally
            {
                this.needToUpdate = false;
                FileUtility.Delete(commentPath);
            }

            if (result.Trim() != string.Empty)
            {
                this.logService?.Debug(result);
                this.logService?.Debug($"repository committed {(SvnPath)this.BasePath}");
                this.info = SvnInfo.Run(this.BasePath);
                this.repositoryInfo.Revision         = this.info.LastChangedRevision;
                this.repositoryInfo.ModificationInfo = new SignatureDate(this.info.LastChangedAuthor, this.info.LastChangedDate);
            }
            else
            {
                this.logService?.Debug("repository no changes. \"{0}\"", this.BasePath);
            }
        }