/// <summary> /// Generate header. /// </summary> /// <returns></returns> public string GetHeader(bool showRevisionsAsLinks) { StringBuilder header = new StringBuilder(); string authorEmail = GetEmail(Author); header.AppendLine(FillToLength(WebUtility.HtmlEncode(Strings.GetAuthorText()) + ":", COMMITHEADER_STRING_LENGTH) + "<a href='mailto:" + WebUtility.HtmlEncode(authorEmail) + "'>" + WebUtility.HtmlEncode(Author) + "</a>"); header.AppendLine(FillToLength(WebUtility.HtmlEncode(Strings.GetAuthorDateText()) + ":", COMMITHEADER_STRING_LENGTH) + WebUtility.HtmlEncode(GitCommandHelpers.GetRelativeDateString(DateTime.UtcNow, AuthorDate.UtcDateTime) + " (" + GitCommandHelpers.GetFullDateString(AuthorDate) + ")")); string committerEmail = GetEmail(Committer); header.AppendLine(FillToLength(WebUtility.HtmlEncode(Strings.GetCommitterText()) + ":", COMMITHEADER_STRING_LENGTH) + "<a href='mailto:" + WebUtility.HtmlEncode(committerEmail) + "'>" + WebUtility.HtmlEncode(Committer) + "</a>"); header.AppendLine(FillToLength(WebUtility.HtmlEncode(Strings.GetCommitDateText()) + ":", COMMITHEADER_STRING_LENGTH) + WebUtility.HtmlEncode(GitCommandHelpers.GetRelativeDateString(DateTime.UtcNow, CommitDate.UtcDateTime) + " (" + GitCommandHelpers.GetFullDateString(CommitDate) + ")")); header.Append(FillToLength(WebUtility.HtmlEncode(Strings.GetCommitHashText()) + ":", COMMITHEADER_STRING_LENGTH) + WebUtility.HtmlEncode(Guid)); if (ChildrenGuids != null && ChildrenGuids.Count != 0) { header.AppendLine(); string commitsString; if (showRevisionsAsLinks) { commitsString = ChildrenGuids.Select(LinkFactory.CreateCommitLink).Join(" "); } else { commitsString = ChildrenGuids.Select(guid => guid.Substring(0, 10)).Join(" "); } header.Append(FillToLength(WebUtility.HtmlEncode(Strings.GetChildrenText()) + ":", COMMITHEADER_STRING_LENGTH) + commitsString); } var parentGuids = ParentGuids.Where(s => !string.IsNullOrEmpty(s)); if (parentGuids.Any()) { header.AppendLine(); string commitsString; if (showRevisionsAsLinks) { commitsString = parentGuids.Select(LinkFactory.CreateCommitLink).Join(" "); } else { commitsString = parentGuids.Select(guid => guid.Substring(0, 10)).Join(" "); } header.Append(FillToLength(WebUtility.HtmlEncode(Strings.GetParentsText()) + ":", COMMITHEADER_STRING_LENGTH) + commitsString); } return(RemoveRedundancies(header.ToString())); }
/// <summary> /// Generate header. /// </summary> /// <returns></returns> public string GetHeaderPlain() { StringBuilder header = new StringBuilder(); header.AppendLine(FillToLength(Strings.GetAuthorText() + ":", COMMITHEADER_STRING_LENGTH) + Author); header.AppendLine(FillToLength(Strings.GetAuthorDateText() + ":", COMMITHEADER_STRING_LENGTH) + GitCommandHelpers.GetRelativeDateString(DateTime.UtcNow, AuthorDate.UtcDateTime) + " (" + GitCommandHelpers.GetFullDateString(AuthorDate) + ")"); header.AppendLine(FillToLength(Strings.GetCommitterText() + ":", COMMITHEADER_STRING_LENGTH) + Committer); header.AppendLine(FillToLength(Strings.GetCommitDateText() + ":", COMMITHEADER_STRING_LENGTH) + GitCommandHelpers.GetRelativeDateString(DateTime.UtcNow, CommitDate.UtcDateTime) + " (" + GitCommandHelpers.GetFullDateString(CommitDate) + ")"); header.Append(FillToLength(Strings.GetCommitHashText() + ":", COMMITHEADER_STRING_LENGTH) + Guid); return(RemoveRedundancies(header.ToString())); }
/// <summary> /// Generate header. /// </summary> /// <returns></returns> public string GetHeader() { StringBuilder header = new StringBuilder(); string authorEmail = GetEmail(Author); header.AppendLine(FillToLength(HttpUtility.HtmlEncode(Strings.GetAuthorText()) + ":", COMMITHEADER_STRING_LENGTH) + "<a href='mailto:" + authorEmail + "'>" + HttpUtility.HtmlEncode(Author) + "</a>"); header.AppendLine(FillToLength(HttpUtility.HtmlEncode(Strings.GetAuthorDateText()) + ":", COMMITHEADER_STRING_LENGTH) + HttpUtility.HtmlEncode(GitCommandHelpers.GetRelativeDateString(DateTime.UtcNow, AuthorDate.UtcDateTime) + " (" + AuthorDate.LocalDateTime.ToString("ddd MMM dd HH':'mm':'ss yyyy")) + ")"); string committerEmail = GetEmail(Committer); header.AppendLine(FillToLength(HttpUtility.HtmlEncode(Strings.GetCommitterText()) + ":", COMMITHEADER_STRING_LENGTH) + "<a href='mailto:" + committerEmail + "'>" + HttpUtility.HtmlEncode(Committer) + "</a>"); header.AppendLine(FillToLength(HttpUtility.HtmlEncode(Strings.GetCommitDateText()) + ":", COMMITHEADER_STRING_LENGTH) + HttpUtility.HtmlEncode(GitCommandHelpers.GetRelativeDateString(DateTime.UtcNow, CommitDate.UtcDateTime) + " (" + CommitDate.LocalDateTime.ToString("ddd MMM dd HH':'mm':'ss yyyy")) + ")"); header.Append(FillToLength(HttpUtility.HtmlEncode(Strings.GetCommitHashText()) + ":", COMMITHEADER_STRING_LENGTH) + HttpUtility.HtmlEncode(Guid)); return(RemoveRedundancies(header.ToString())); }
public static string ProcessSubmodulePatch(GitModule module, string text) { var status = GetSubmoduleStatus(text); GitModule gitmodule = module.GetSubmodule(status.Name); StringBuilder sb = new StringBuilder(); sb.AppendLine("Submodule " + status.Name + " Change"); sb.AppendLine(); sb.AppendLine("From:\t" + status.OldCommit); if (gitmodule.ValidWorkingDir()) { string error = ""; CommitData commitData = CommitData.GetCommitData(gitmodule, status.OldCommit, ref error); if (commitData != null) { sb.AppendLine("\t\t\t\t\t" + GitCommandHelpers.GetRelativeDateString(DateTime.UtcNow, commitData.CommitDate.UtcDateTime) + commitData.CommitDate.LocalDateTime.ToString(" (ddd MMM dd HH':'mm':'ss yyyy)")); var delim = new char[] { '\n', '\r' }; var lines = commitData.Body.Trim(delim).Split(new string[] { "\r\n" }, 0); foreach (var curline in lines) { sb.AppendLine("\t\t" + curline); } } } else { sb.AppendLine(); } sb.AppendLine(); string dirty = !status.IsDirty ? "" : " (dirty)"; sb.AppendLine("To:\t\t" + status.Commit + dirty); if (gitmodule.ValidWorkingDir()) { string error = ""; CommitData commitData = CommitData.GetCommitData(gitmodule, status.Commit, ref error); if (commitData != null) { sb.AppendLine("\t\t\t\t\t" + GitCommandHelpers.GetRelativeDateString(DateTime.UtcNow, commitData.CommitDate.UtcDateTime) + commitData.CommitDate.LocalDateTime.ToString(" (ddd MMM dd HH':'mm':'ss yyyy)")); var delim = new char[] { '\n', '\r' }; var lines = commitData.Body.Trim(delim).Split(new string[] { "\r\n" }, 0); foreach (var curline in lines) { sb.AppendLine("\t\t" + curline); } } } else { sb.AppendLine(); } if (status.Commit != null && status.OldCommit != null) { if (status.IsDirty) { string statusText = gitmodule.GetStatusText(false); if (!String.IsNullOrEmpty(statusText)) { sb.AppendLine("\nStatus:"); sb.Append(statusText); } } string diffs = gitmodule.GetDiffFilesText(status.OldCommit, status.Commit); if (!String.IsNullOrEmpty(diffs)) { sb.AppendLine("\nDifferences:"); sb.Append(diffs); } } return(sb.ToString()); }
public static string ProcessSubmodulePatch(string text) { StringBuilder sb = new StringBuilder(); using (StringReader reader = new StringReader(text)) { string line; string module = ""; while ((line = reader.ReadLine()) != null) { if (line.StartsWith("+++ ")) { module = line.Substring("+++ ".Length); var list = module.Split(new char[] { ' ' }, 2); module = list.Length > 0 ? list[0] : ""; if (module.Length > 2 && module[1] == '/') { module = module.Substring(2); break; } } } sb.AppendLine("Submodule " + module + " Change"); while ((line = reader.ReadLine()) != null) { if (line.Contains("Subproject")) { sb.AppendLine(); char c = line[0]; const string commit = "commit "; string hash = ""; int pos = line.IndexOf(commit); if (pos >= 0) { hash = line.Substring(pos + commit.Length); } bool bdirty = hash.EndsWith("-dirty"); hash = hash.Replace("-dirty", ""); string dirty = !bdirty ? "" : " (dirty)"; if (c == '-') { sb.AppendLine("From:\t" + hash + dirty); } else if (c == '+') { sb.AppendLine("To:\t\t" + hash + dirty); } string path = Settings.Module.GetSubmoduleFullPath(module); GitModule gitmodule = new GitModule(path); if (gitmodule.ValidWorkingDir()) { string error = ""; CommitData commitData = CommitData.GetCommitData(gitmodule, hash, ref error); if (commitData != null) { sb.AppendLine("\t\t\t\t\t" + GitCommandHelpers.GetRelativeDateString(DateTime.UtcNow, commitData.CommitDate.UtcDateTime) + commitData.CommitDate.LocalDateTime.ToString(" (ddd MMM dd HH':'mm':'ss yyyy)")); var delim = new char[] { '\n', '\r' }; var lines = commitData.Body.Trim(delim).Split(new string[] { "\r\n" }, 0); foreach (var curline in lines) { sb.AppendLine("\t\t" + curline); } } } else { sb.AppendLine(); } } } } return(sb.ToString()); }
/// <summary> /// Creates a CommitInformation object from raw commit info data from git. The string passed in should be /// exact output of a log or show command using --format=raw. /// </summary> /// <param name="rawData">Raw commit data from git.</param> /// <returns>CommitInformation object populated with parsed info from git string.</returns> public static CommitInformation CreateFromRawData(string rawData) { var lines = new List <string>(rawData.Split('\n')); var commit = lines.Single(l => l.StartsWith(COMMIT_LABEL)); var guid = commit.Substring(COMMIT_LABEL.Length); lines.Remove(commit); // TODO: we can use this to add more relationship info like gitk does if wanted var tree = lines.Single(l => l.StartsWith(TREE_LABEL)); var treeGuid = tree.Substring(TREE_LABEL.Length); lines.Remove(tree); // TODO: we can use this to add more relationship info like gitk does if wanted List <string> parentLines = lines.FindAll(l => l.StartsWith(PARENT_LABEL)); var parentGuids = parentLines.Select(parent => parent.Substring(PARENT_LABEL.Length)).ToArray(); lines.RemoveAll(parentLines.Contains); var authorInfo = lines.Single(l => l.StartsWith(AUTHOR_LABEL)); var author = GetPersonFromAuthorInfoLine(authorInfo, AUTHOR_LABEL.Length); var authorDate = GetTimeFromAuthorInfoLine(authorInfo); lines.Remove(authorInfo); var committerInfo = lines.Single(l => l.StartsWith(COMMITTER_LABEL)); var committer = GetPersonFromAuthorInfoLine(committerInfo, COMMITTER_LABEL.Length); var commitDate = GetTimeFromAuthorInfoLine(committerInfo); lines.Remove(committerInfo); var message = new StringBuilder(); foreach (var line in lines) { message.AppendFormat("{0}\n", line); } var body = "\n\n" + message.ToString().TrimStart().TrimEnd() + "\n\n"; //We need to recode the commit message because of a bug in Git. //We cannot let git recode the message to Settings.Encoding which is //needed to allow the "git log" to print the filename in Settings.Encoding Encoding logoutputEncoding = GitCommandHelpers.GetLogoutputEncoding(); if (logoutputEncoding != Settings.Encoding) { body = logoutputEncoding.GetString(Settings.Encoding.GetBytes(body)); } var header = FillToLenght(Strings.GetAuthorText() + ":", COMMITHEADER_STRING_LENGTH) + author + "\n" + FillToLenght(Strings.GetAuthorDateText() + ":", COMMITHEADER_STRING_LENGTH) + GitCommandHelpers.GetRelativeDateString(DateTime.UtcNow, authorDate.UtcDateTime) + " (" + authorDate.LocalDateTime.ToString("ddd MMM dd HH':'mm':'ss yyyy") + ")\n" + FillToLenght(Strings.GetCommitterText() + ":", COMMITHEADER_STRING_LENGTH) + committer + "\n" + FillToLenght(Strings.GetCommitterDateText() + ":", COMMITHEADER_STRING_LENGTH) + GitCommandHelpers.GetRelativeDateString(DateTime.UtcNow, commitDate.UtcDateTime) + " (" + commitDate.LocalDateTime.ToString("ddd MMM dd HH':'mm':'ss yyyy") + ")\n" + FillToLenght(Strings.GetCommitHashText() + ":", COMMITHEADER_STRING_LENGTH) + guid; header = RemoveRedundancies(header); var commitInformation = new CommitInformation(header, body); return(commitInformation); }
public static string ProcessSubmodulePatch(GitModule module, string text) { StringBuilder sb = new StringBuilder(); using (StringReader reader = new StringReader(text)) { string line = reader.ReadLine(); string moduleName = ""; if (line != null) { var match = Regex.Match(line, @"diff --git a/(\S+) b/(\S+)"); if (match != null && match.Groups.Count > 0) { moduleName = match.Groups[1].Value; } } sb.AppendLine("Submodule " + moduleName + " Change"); string fromHash = null; string toHash = null; bool dirtyFlag = false; while ((line = reader.ReadLine()) != null) { if (line.Contains("Subproject")) { sb.AppendLine(); char c = line[0]; const string commit = "commit "; string hash = ""; int pos = line.IndexOf(commit); if (pos >= 0) { hash = line.Substring(pos + commit.Length); } bool bdirty = hash.EndsWith("-dirty"); dirtyFlag |= bdirty; hash = hash.Replace("-dirty", ""); string dirty = !bdirty ? "" : " (dirty)"; if (c == '-') { fromHash = hash; sb.AppendLine("From:\t" + hash + dirty); } else if (c == '+') { toHash = hash; sb.AppendLine("To:\t\t" + hash + dirty); } GitModule gitmodule = module.GetSubmodule(moduleName); if (gitmodule.ValidWorkingDir()) { string error = ""; CommitData commitData = CommitData.GetCommitData(gitmodule, hash, ref error); if (commitData != null) { sb.AppendLine("\t\t\t\t\t" + GitCommandHelpers.GetRelativeDateString(DateTime.UtcNow, commitData.CommitDate.UtcDateTime) + commitData.CommitDate.LocalDateTime.ToString(" (ddd MMM dd HH':'mm':'ss yyyy)")); var delim = new char[] { '\n', '\r' }; var lines = commitData.Body.Trim(delim).Split(new string[] { "\r\n" }, 0); foreach (var curline in lines) { sb.AppendLine("\t\t" + curline); } } if (fromHash != null && toHash != null) { if (dirtyFlag) { string status = gitmodule.GetStatusText(false); if (!String.IsNullOrEmpty(status)) { sb.AppendLine("\nStatus:"); sb.Append(status); } } string diffs = gitmodule.GetDiffFilesText(fromHash, toHash); if (!String.IsNullOrEmpty(diffs)) { sb.AppendLine("\nDifferences:"); sb.Append(diffs); } } } else { sb.AppendLine(); } } } } return(sb.ToString()); }