private static SvnLogEventArgs Parse(XElement element) { var obj = new SvnLogEventArgs() { Author = element.XPathSelectElement("author").Value, Revision = long.Parse(element.Attribute("revision").Value), Comment = element.XPathSelectElement("msg").Value, DateTime = XmlConvert.ToDateTime(element.XPathSelectElement("date").Value, XmlDateTimeSerializationMode.Utc) }; var pathItems = element.XPathSelectElements("paths/path").ToArray(); var changedItemList = new List <SvnChangeItem>(); foreach (var item in pathItems) { var changedItem = SvnChangeItem.Parse(item); changedItemList.Add(changedItem); } obj.ChangedPaths = changedItemList.ToArray(); var propItems = element.XPathSelectElements("revprops/property").ToArray(); var propItemList = new List <SvnPropertyValue>(); foreach (var item in propItems) { var propItem = SvnPropertyValue.Parse(item); propItemList.Add(propItem); } obj.Properties = propItemList.ToArray(); return(obj); }
public static SvnLogEventArgs[] Run(string path, string arguments) { if (arguments.IndexOf("--xml") < 0) { arguments += " --xml"; } var text = SvnClientHost.Run("log", path.WrapQuot(), arguments); return(SvnLogEventArgs.Read(text)); }
public static SvnLogEventArgs[] Run(string path, long revision, int count) { var revisionText = revision.ToString(); if (revision == long.MaxValue) { revisionText = "head"; } var text = SvnClientHost.Run("log", path.WrapQuot(), "-r", $"{revisionText}:1", "--xml", "-v", "-l", count, "--with-all-revprops"); return(SvnLogEventArgs.Read(text)); }
public DateTime Commit(string path, string message, IEnumerable <Crema.ServiceModel.LogPropertyInfo> properties) { if (this.transactions.ContainsKey(path) == true) { var patchPath = Path.Combine(this.transactionPath, this.transactions[path] + ".patch"); var text = this.Run("diff", path.WrapQuot(), "--patch-compatible"); FileUtility.WriteAllText(text, patchPath); this.transactionMessages[path] = this.transactionMessages[path] + message + Environment.NewLine; return(DateTime.UtcNow); } var propText = string.Join(" ", properties.Select(item => $"--with-revprop \"{propertyPrefix}{item.Key}={item.Value}\"")); this.logService?.Debug($"repository committing {path.WrapQuot()}"); var result = string.Empty; try { if (this.needToUpdate == true) { this.Run("update", path.WrapQuot()); } result = this.Run("commit", path.WrapQuot(), "-m", message.WrapQuot(), propText); } catch (Exception e) { this.logService?.Warn(e); this.Run("update", path.WrapQuot()); result = this.Run("commit", path.WrapQuot(), "-m", message.WrapQuot(), propText); } finally { this.needToUpdate = false; } if (result.Trim() != string.Empty) { this.logService?.Debug($"repository committed {path.WrapQuot()}"); var match = Regex.Match(result, @"Committed revision (?<revision>\d+)[.]", RegexOptions.ExplicitCapture | RegexOptions.Multiline); this.revision = long.Parse(match.Groups["revision"].Value); var log = SvnLogEventArgs.Run(path, this.revision).First(); return(log.DateTime); } else { this.logService?.Debug("repository no changes. \"{0}\"", path); return(DateTime.MinValue); } }
public static SvnLogEventArgs[] Read(string text) { var logItemList = new List <SvnLogEventArgs>(); using (var sr = new StringReader(text)) { var doc = XDocument.Load(sr); var logItems = doc.XPathSelectElements("/log/logentry").ToArray(); foreach (var item in logItems) { var logItem = SvnLogEventArgs.Parse(item); logItemList.Add(logItem); } } return(logItemList.ToArray()); }
private void GetBranchRevision(Uri repositoryRoot, Uri uri, out long revision, out string source, out long sourceRevision) { var log = SvnLogEventArgs.Run($"{uri}", "--xml -v --stop-on-copy").Last(); var relativeUri = repositoryRoot.MakeRelativeUri(uri); var localPath = $"/{relativeUri}"; var oldPath = string.Empty; var oldRevision = (long)0; revision = log.Revision; source = null; sourceRevision = log.Revision; foreach (var item in log.ChangedPaths) { if (item.Action == "A" && item.Path == localPath) { oldPath = item.CopyFromPath; oldRevision = item.CopyFromRevision; source = Path.GetFileName(item.CopyFromPath); sourceRevision = item.CopyFromRevision; } } if (oldPath == string.Empty) { return; } foreach (var item in log.ChangedPaths) { if (item.Action == "D" && item.Path == oldPath) { var url = new Uri(repositoryRoot + item.Path.Substring(1) + "@" + oldRevision); GetBranchRevision(repositoryRoot, url, out revision, out source, out sourceRevision); return; } } }
public static SvnLogEventArgs[] Run(string path, long revision) { var text = SvnClientHost.Run("log", path.WrapQuot(), "-r", $"head:{revision}", "--xml", "-v"); return(SvnLogEventArgs.Read(text)); }
public LogInfo[] GetLog(string path, long revision, int count) { var logs = SvnLogEventArgs.Run(path, revision, count); return(logs.Select(item => (LogInfo)item).ToArray()); }