Esempio n. 1
0
        public Uri GetUri(string path, string revision)
        {
            var revisionValue = revision ?? this.repositoryInfo.Revision;
            var info          = SvnInfo.Run(path, revisionValue);

            return(new Uri($"{info.Uri}@{revisionValue}"));
        }
Esempio n. 2
0
        public string GetRevision(string path)
        {
            var info           = SvnInfo.Run(path);
            var repositoryInfo = SvnInfo.Run($"{info.Uri}");

            return(repositoryInfo.LastChangedRevision);
        }
Esempio n. 3
0
        public static SvnLogInfo GetFirstLog(string path)
        {
            var info      = SvnInfo.Run(path);
            var revision  = info.LastChangedRevision;
            var localPath = PathUtility.Separator + UriUtility.MakeRelativeOfDirectory(info.RepositoryRoot, info.Uri);

            while (revision != "1")
            {
                var logs = SvnLogInfo.Run(info.Uri.ToString(), "1", revision, 100);
                foreach (var item in logs)
                {
                    var renamed = false;
                    foreach (var changedPath in item.ChangedPaths)
                    {
                        if (changedPath.Action == "A" && changedPath.Path == localPath)
                        {
                            localPath = changedPath.CopyFromPath;
                            renamed   = true;
                            break;
                        }
                    }

                    var deleted = false;
                    if (renamed == true)
                    {
                        foreach (var changedPath in item.ChangedPaths)
                        {
                            if (changedPath.Action == "D" && changedPath.Path == localPath)
                            {
                                deleted = true;
                                break;
                            }
                        }

                        if (deleted == false)
                        {
                            return(item);
                        }
                    }
                }
                if (logs.Count() == 1)
                {
                    return(logs.First());
                }
                else
                {
                    revision = logs.Last().Revision;
                }
            }

            return(SvnLogInfo.GetLogs(info.Uri.ToString(), "1").First());
        }
        private void Pack(string sourcePath)
        {
            var info     = SvnInfo.Run(sourcePath);
            var rootPath = info.RepositoryRoot.LocalPath;

            if (rootPath.EndsWith($"{Path.DirectorySeparatorChar}") == true)
            {
                rootPath = Path.GetDirectoryName(rootPath);
            }
            var packCommand = new SvnAdminCommand("pack")
            {
                (SvnPath)rootPath
            };

            packCommand.Run();
        }
Esempio n. 5
0
        public static SvnInfo Parse(string text)
        {
            using var sr = new StringReader(text);
            var doc = XDocument.Load(sr);
            var obj = new SvnInfo()
            {
                Path                = doc.XPathSelectElement("/info/entry").Attribute("path").Value,
                RepositoryRoot      = new Uri(doc.XPathSelectElement("/info/entry/repository/root").Value + "/"),
                Revision            = doc.XPathSelectElement("/info/entry").Attribute("revision").Value,
                Uri                 = new Uri(doc.XPathSelectElement("/info/entry/url").Value, UriKind.RelativeOrAbsolute),
                LastChangedRevision = doc.XPathSelectElement("/info/entry/commit").Attribute("revision").Value,
                LastChangedAuthor   = doc.XPathSelectElement("/info/entry/commit/author").Value,
                LastChangedDate     = XmlConvert.ToDateTime(doc.XPathSelectElement("/info/entry/commit/date").Value, XmlDateTimeSerializationMode.Utc)
            };

            return(obj);
        }
Esempio n. 6
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;
        }
Esempio n. 7
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);
            }
        }