Esempio n. 1
0
        public override string ToString()
        {
            if (messages.Count == 0)
            {
                return(string.Empty);
            }

            CommitMessageStyle message_style = MessageFormat.Style;

            TextFormatter formatter = new TextFormatter();

            formatter.MaxColumns   = MessageFormat.MaxColumns;
            formatter.TabWidth     = MessageFormat.TabWidth;
            formatter.TabsAsSpaces = MessageFormat.TabsAsSpaces;

            if (message_style.Header.Length > 0)
            {
                string [,] tags = new string[, ] {
                    { "AuthorName", uinfo.Name }, { "AuthorEmail", uinfo.Email }
                };
                formatter.Append(StringParserService.Parse(message_style.Header, tags));
            }

            formatter.IndentString = message_style.Indent;

            int m_i = 0;

            string fileSeparator1 = message_style.FileSeparator;
            string fileSeparator2 = string.Empty;

            int si = message_style.FileSeparator.IndexOf('\n');

            if (si != -1 && si < message_style.FileSeparator.Length - 1)
            {
                fileSeparator1 = message_style.FileSeparator.Substring(0, si + 1);
                fileSeparator2 = message_style.FileSeparator.Substring(si + 1);
            }

            formatter.Wrap                 = WrappingType.Word;
            formatter.LeftMargin           = message_style.LineAlign;
            formatter.ParagraphStartMargin = 0;

            foreach (KeyValuePair <string, List <string> > message in messages)
            {
                List <string> paths = message.Value;
                paths.Sort((a, b) => a.Length.CompareTo(b.Length));

                formatter.BeginWord();

                formatter.Append(message_style.FirstFilePrefix);
                for (int i = 0, n = paths.Count; i < n; i++)
                {
                    if (i > 0)
                    {
                        formatter.Append(fileSeparator1);
                        formatter.EndWord();
                        formatter.BeginWord();
                        formatter.Append(fileSeparator2);
                    }
                    formatter.Append(paths [i]);
                }

                formatter.Append(message_style.LastFilePostfix);
                formatter.EndWord();
                formatter.Append(message.Key);

                if (m_i++ < messages.Count - 1)
                {
                    formatter.AppendLine();
                    for (int n = 0; n < message_style.InterMessageLines; n++)
                    {
                        formatter.AppendLine();
                    }
                }
            }

            for (int i = 0; i < MessageFormat.AppendNewlines; i++)
            {
                formatter.AppendLine();
            }

            return(formatter.ToString());
        }