/// <summary> /// Generate header. /// </summary> /// <param name="commitData"></param> /// <returns></returns> public static string GetHeaderPlain(this CommitData commitData) { StringBuilder header = new StringBuilder(); bool authorIsCommiter = String.Equals(commitData.Author, commitData.Committer, StringComparison.CurrentCulture); bool datesEqual = commitData.AuthorDate.EqualsExact(commitData.CommitDate); header.AppendLine((Strings.GetAuthorText() + ":").PadRight(GetHeaderPadding()) + commitData.Author); header.AppendLine((datesEqual ? Strings.GetDateText() : Strings.GetAuthorDateText() + ":").PadRight(GetHeaderPadding()) + LocalizationHelpers.GetRelativeDateString(DateTime.UtcNow, commitData.AuthorDate.UtcDateTime) + " (" + LocalizationHelpers.GetFullDateString(commitData.AuthorDate) + ")"); if (!authorIsCommiter) { header.AppendLine((Strings.GetCommitterText() + ":").PadRight(GetHeaderPadding()) + commitData.Committer); } if (!datesEqual) { header.AppendLine((Strings.GetCommitDateText() + ":").PadRight(GetHeaderPadding()) + LocalizationHelpers.GetRelativeDateString(DateTime.UtcNow, commitData.CommitDate.UtcDateTime) + " (" + LocalizationHelpers.GetFullDateString(commitData.CommitDate) + ")"); header.Append((Strings.GetCommitHashText() + ":").PadRight(GetHeaderPadding()) + commitData.Guid); } return(header.ToString()); }
/// <inheritdoc /> /// <summary> /// Generate header. /// </summary> /// <param name="commitData"></param> /// <returns></returns> public string RenderPlain(CommitData commitData) { if (commitData == null) { throw new ArgumentNullException(nameof(commitData)); } StringBuilder header = new StringBuilder(); bool authorIsCommiter = string.Equals(commitData.Author, commitData.Committer, StringComparison.CurrentCulture); bool datesEqual = commitData.AuthorDate.EqualsExact(commitData.CommitDate); header.AppendLine((Strings.GetAuthorText() + ":").PadRight(GetHeaderPadding()) + commitData.Author); header.AppendLine((datesEqual ? Strings.GetDateText() : Strings.GetAuthorDateText() + ":").PadRight(GetHeaderPadding()) + LocalizationHelpers.GetRelativeDateString(DateTime.UtcNow, commitData.AuthorDate.UtcDateTime) + " (" + LocalizationHelpers.GetFullDateString(commitData.AuthorDate) + ")"); if (!authorIsCommiter) { header.AppendLine((Strings.GetCommitterText() + ":").PadRight(GetHeaderPadding()) + commitData.Committer); } if (!datesEqual) { header.AppendLine((Strings.GetCommitDateText() + ":").PadRight(GetHeaderPadding()) + LocalizationHelpers.GetRelativeDateString(DateTime.UtcNow, commitData.CommitDate.UtcDateTime) + " (" + LocalizationHelpers.GetFullDateString(commitData.CommitDate) + ")"); header.Append((Strings.GetCommitHashText() + ":").PadRight(GetHeaderPadding()) + commitData.Guid); } header.Append( (WebUtility.HtmlEncode(Strings.GetCommitHashText()) + ":").PadRight(GetHeaderPadding()) + WebUtility.HtmlEncode(commitData.Guid)); return(header.ToString()); }
private static string RemoveRedundancies(string info) { string author = GetField(info, Strings.GetAuthorText() + ":"); string committer = GetField(info, Strings.GetCommitterText() + ":"); if (String.Equals(author, committer, StringComparison.CurrentCulture)) { info = RemoveField(info, Strings.GetCommitterText() + ":"); } string authorDate = GetField(info, Strings.GetAuthorDateText() + ":"); string commitDate = GetField(info, Strings.GetCommitDateText() + ":"); if (String.Equals(authorDate, commitDate, StringComparison.CurrentCulture)) { info = RemoveField(info, Strings.GetCommitDateText() + ":").Replace( (string)FillToLength(Strings.GetAuthorDateText() + ":", COMMITHEADER_STRING_LENGTH), FillToLength(Strings.GetDateText() + ":", COMMITHEADER_STRING_LENGTH)); } return(info); }
/// <summary> /// Generate header. /// </summary> /// <returns></returns> public static string GetHeader(this CommitData commitData, LinkFactory linkFactory, bool showRevisionsAsLinks) { StringBuilder header = new StringBuilder(); bool authorIsCommiter = String.Equals(commitData.Author, commitData.Committer, StringComparison.CurrentCulture); bool datesEqual = commitData.AuthorDate.EqualsExact(commitData.CommitDate); string authorEmail = GetEmail(commitData.Author); header.AppendLine( (WebUtility.HtmlEncode(Strings.GetAuthorText()) + ":").PadRight(GetHeaderPadding()) + linkFactory.CreateLink(commitData.Author, "mailto:" + authorEmail)); header.AppendLine( (WebUtility.HtmlEncode(datesEqual ? Strings.GetDateText() : Strings.GetAuthorDateText()) + ":").PadRight(GetHeaderPadding()) + WebUtility.HtmlEncode( LocalizationHelpers.GetRelativeDateString(DateTime.UtcNow, commitData.AuthorDate.UtcDateTime) + " (" + LocalizationHelpers.GetFullDateString(commitData.AuthorDate) + ")")); if (!authorIsCommiter) { string committerEmail = GetEmail(commitData.Committer); header.AppendLine( (WebUtility.HtmlEncode(Strings.GetCommitterText()) + ":").PadRight(GetHeaderPadding()) + "<a href='mailto:" + WebUtility.HtmlEncode(committerEmail) + "'>" + WebUtility.HtmlEncode(commitData.Committer) + "</a>"); } if (!datesEqual) { header.AppendLine( (WebUtility.HtmlEncode(Strings.GetCommitDateText()) + ":").PadRight(GetHeaderPadding()) + WebUtility.HtmlEncode( LocalizationHelpers.GetRelativeDateString(DateTime.UtcNow, commitData.CommitDate.UtcDateTime) + " (" + LocalizationHelpers.GetFullDateString(commitData.CommitDate) + ")")); } header.Append( (WebUtility.HtmlEncode(Strings.GetCommitHashText()) + ":").PadRight(GetHeaderPadding()) + WebUtility.HtmlEncode(commitData.Guid)); if (commitData.ChildrenGuids != null && commitData.ChildrenGuids.Count != 0) { header.AppendLine(); string commitsString; if (showRevisionsAsLinks) { commitsString = commitData.ChildrenGuids.Select(g => linkFactory.CreateCommitLink(g)).Join(" "); } else { commitsString = commitData.ChildrenGuids.Select(guid => guid.Substring(0, 10)).Join(" "); } header.Append((WebUtility.HtmlEncode(Strings.GetChildrenText()) + ":").PadRight(GetHeaderPadding()) + commitsString); } var parentGuids = commitData.ParentGuids.Where(s => !String.IsNullOrEmpty(s)); if (parentGuids.Any()) { header.AppendLine(); string commitsString; if (showRevisionsAsLinks) { commitsString = parentGuids.Select(g => linkFactory.CreateCommitLink(g)).Join(" "); } else { commitsString = parentGuids.Select(guid => guid.Substring(0, 10)).Join(" "); } header.Append((WebUtility.HtmlEncode(Strings.GetParentsText()) + ":").PadRight(GetHeaderPadding()) + commitsString); } return(header.ToString()); }