コード例 #1
0
ファイル: HgRepository.cs プロジェクト: DinoV/kudu
 private ChangeSet CreateChangeSet(Mercurial.Changeset changeSet)
 {
     return(new ChangeSet(changeSet.Hash, changeSet.AuthorName, changeSet.AuthorEmailAddress, changeSet.CommitMessage, new DateTimeOffset(changeSet.Timestamp)));
 }
コード例 #2
0
ファイル: ChangesetXmlParser.cs プロジェクト: whir1/Hg.Net
        /// <summary>
        /// Parse the given XML lazily and return a collection of <see cref="Changeset"/>
        /// objects for the information contained in it, in the order the changesets
        /// appear in the xml.
        /// </summary>
        /// <param name="xml">
        /// The XML to parse.
        /// </param>
        /// <returns>
        /// A collection of <see cref="Changeset"/> objects.
        /// </returns>
        /// <exception cref="InvalidOperationException">
        /// <para>An unknown path action character was detected in the log output.</para>
        /// <para>- or -</para>
        /// <para>The XML content was not legal according to the expected format.</para>
        /// </exception>
        public static IEnumerable <Changeset> LazyParse(string xml)
        {
            if (StringEx.IsNullOrWhiteSpace(xml))
            {
                yield break;
            }

            var serializer = new XmlSerializer(typeof(LogEntryNode));

            foreach (string entryXml in LazyExtractChangesetXmlPieces(xml))
            {
                var entry     = (LogEntryNode)serializer.Deserialize(new StringReader(entryXml));
                var changeset = new Changeset
                {
                    Timestamp          = entry.Timestamp,
                    AuthorName         = (entry.Author ?? new LogEntryAuthorNode()).Name,
                    AuthorEmailAddress = (entry.Author ?? new LogEntryAuthorNode()).Email,
                    CommitMessage      = entry.CommitMessage ?? string.Empty,
                    Branch             = entry.Branch ?? "default",
                    Hash           = entry.Hash,
                    RevisionNumber = entry.Revision,
                    Revision       = RevSpec.Single(entry.Hash),
                    Tags           = entry.Tags.Select(t => t.Name).ToArray(),
                };

                switch (entry.Parents.Count)
                {
                case 2:
                    changeset.RightParentHash     = entry.Parents[1].Hash;
                    changeset.RightParentRevision = entry.Parents[1].Revision;
                    goto case 1;

                case 1:
                    changeset.LeftParentHash     = entry.Parents[0].Hash;
                    changeset.LeftParentRevision = entry.Parents[0].Revision;
                    break;

                case 0:
                    changeset.LeftParentRevision = changeset.RevisionNumber - 1;
                    break;
                }

                foreach (LogEntryPathNode action in entry.PathActions)
                {
                    var pathAction = new ChangesetPathAction
                    {
                        Path = action.Path,
                    };
                    switch (action.Action)
                    {
                    case "M":
                        pathAction.Action = ChangesetPathActionType.Modify;
                        break;

                    case "A":
                        pathAction.Action = ChangesetPathActionType.Add;
                        LogEntryCopyNode copySource = entry.Copies.Where(c => c.Destination == action.Path).FirstOrDefault();
                        if (copySource != null)
                        {
                            pathAction.Source = copySource.Source;
                        }
                        break;

                    case "R":
                        pathAction.Action = ChangesetPathActionType.Remove;
                        break;

                    default:
                        throw new InvalidOperationException("Unknown path action: " + action.Action);
                    }
                    changeset.PathActions.Add(pathAction);
                }

                yield return(changeset);
            }
        }