public static string GetSubmoduleText(GitModule superproject, string name, string hash) { StringBuilder sb = new StringBuilder(); sb.AppendLine("Submodule " + name); sb.AppendLine(); GitModule module = superproject.GetSubmodule(name); if (module.IsValidGitWorkingDir()) { // TEMP, will be moved in the follow up refactor ICommitDataManager commitDataManager = new CommitDataManager(() => module); string error = ""; CommitData data = commitDataManager.GetCommitData(hash, ref error); if (data == null) { sb.AppendLine("Commit hash:\t" + hash); return(sb.ToString()); } string header = PlainCommitDataHeaderRenderer.RenderPlain(data); string body = "\n" + data.Body.Trim(); sb.AppendLine(header); sb.Append(body); } else { sb.AppendLine("Commit hash:\t" + hash); } return(sb.ToString()); }
public static string GetSubmoduleText(GitModule superproject, string name, string hash, bool cache) { var sb = new StringBuilder(); sb.AppendLine("Submodule " + name); sb.AppendLine(); GitModule module = superproject.GetSubmodule(name); // Submodule directory must exist to run commands, unknown otherwise if (module.IsValidGitWorkingDir()) { // TEMP, will be moved in the follow up refactor ICommitDataManager commitDataManager = new CommitDataManager(() => module); CommitData?data = commitDataManager.GetCommitData(hash, out _, cache); if (data is null) { sb.AppendLine("Commit hash:\t" + hash); return(sb.ToString()); } string header = PlainCommitDataHeaderRenderer.RenderPlain(data); string body = "\n" + data.Body.Trim(); sb.AppendLine(header); sb.Append(body); } else { sb.AppendLine("Commit hash:\t" + hash); } return(sb.ToString()); }
public void Setup() { _module = Substitute.For <IVsrModule>(); _module.ReEncodeStringFromLossless(Arg.Any <string>()).Returns(x => x[0]); _module.ReEncodeCommitMessage(Arg.Any <string>(), Arg.Any <string>()).Returns(x => x[0]); _getModule = () => _module; _commitDataManager = new CommitDataManager(_getModule); }
private DataManager() { var database = new VCSEntities(); userManager = new UserDataManager(database); repositoryManager = new RepositoryDataManager(database, this); fileManager = new FileDataManager(database); changeManager = new ChangeDataManager(database, this); commitManager = new CommitDataManager(database, this); }
/// <summary> /// Gets the commit info for module. /// </summary> /// <param name="module">Git module.</param> /// <param name="linkFactory"></param> /// <param name="sha1">The sha1.</param> /// <returns></returns> public static CommitInformation GetCommitInfo(GitModule module, LinkFactory linkFactory, string sha1) { // TEMP, will be moved in the follow up refactor ICommitDataManager commitDataManager = new CommitDataManager(() => module); string error = ""; CommitData data = commitDataManager.GetCommitData(sha1, ref error); if (data == null) { return(new CommitInformation(error, "")); } string header = data.GetHeader(linkFactory, false); string body = "\n" + WebUtility.HtmlEncode(data.Body.Trim()); return(new CommitInformation(header, body)); }
public void CanCreateCommitInformationFromFormatedData() { LinkFactory linkFactory = new LinkFactory(); var commitGuid = Guid.NewGuid(); var treeGuid = Guid.NewGuid(); var parentGuid1 = Guid.NewGuid().ToString(); var parentGuid2 = Guid.NewGuid().ToString(); var authorTime = DateTime.UtcNow.AddDays(-3); var commitTime = DateTime.UtcNow.AddDays(-2); var authorUnixTime = (int)(authorTime - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds; var commitUnixTime = (int)(commitTime - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds; var rawData = commitGuid + "\n" + treeGuid + "\n" + parentGuid1 + " " + parentGuid2 + "\n" + "John Doe (Acme Inc) <*****@*****.**>\n" + authorUnixTime + "\n" + "Jane Doe (Acme Inc) <*****@*****.**>\n" + commitUnixTime + "\n" + "\n" + "\tI made a really neato change.\n\n" + "Notes (p4notes):\n" + "\tP4@547123"; var expectedHeader = "Author: <a href='mailto:[email protected]'>John Doe (Acme Inc) <[email protected]></a>" + Environment.NewLine + "Author date: 3 days ago (" + LocalizationHelpers.GetFullDateString(authorTime) + ")" + Environment.NewLine + "Committer: <a href='mailto:[email protected]'>Jane Doe (Acme Inc) <[email protected]></a>" + Environment.NewLine + "Commit date: 2 days ago (" + LocalizationHelpers.GetFullDateString(commitTime) + ")" + Environment.NewLine + "Commit hash: " + commitGuid + Environment.NewLine + "Parent(s): <a href='gitext://gotocommit/" + parentGuid1 + "'>" + parentGuid1.Substring(0, 10) + "</a> <a href='gitext://gotocommit/" + parentGuid2 + "'>" + parentGuid2.Substring(0, 10) + "</a>"; var expectedBody = "\nI made a really neato change." + Environment.NewLine + Environment.NewLine + "Notes (p4notes):" + Environment.NewLine + "\tP4@547123"; // TEMP, will be refactored in the follow up refactor var commitData = new CommitDataManager(() => new GitModule("")).CreateFromFormatedData(rawData); var commitInformation = CommitInformation.GetCommitInfo(commitData, linkFactory, true); Assert.AreEqual(expectedHeader, commitInformation.Header); Assert.AreEqual(expectedBody, commitInformation.Body); }
public static string ProcessSubmoduleStatus([NotNull] GitModule module, [NotNull] GitSubmoduleStatus status) { if (module == null) { throw new ArgumentNullException(nameof(module)); } if (status == null) { throw new ArgumentNullException(nameof(status)); } GitModule gitModule = module.GetSubmodule(status.Name); StringBuilder sb = new StringBuilder(); sb.AppendLine("Submodule " + status.Name + " Change"); // TEMP, will be moved in the follow up refactor ICommitDataManager commitDataManager = new CommitDataManager(() => gitModule); sb.AppendLine(); sb.AppendLine("From:\t" + (status.OldCommit ?? "null")); CommitData oldCommitData = null; if (gitModule.IsValidGitWorkingDir()) { string error = ""; if (status.OldCommit != null) { oldCommitData = commitDataManager.GetCommitData(status.OldCommit, ref error); } if (oldCommitData != null) { sb.AppendLine("\t\t\t\t\t" + GetRelativeDateString(DateTime.UtcNow, oldCommitData.CommitDate.UtcDateTime) + " (" + GetFullDateString(oldCommitData.CommitDate) + ")"); var delim = new char[] { '\n', '\r' }; var lines = oldCommitData.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 ?? "null") + dirty); CommitData commitData = null; if (gitModule.IsValidGitWorkingDir()) { string error = ""; if (status.Commit != null) { commitData = commitDataManager.GetCommitData(status.Commit, ref error); } if (commitData != null) { sb.AppendLine("\t\t\t\t\t" + GetRelativeDateString(DateTime.UtcNow, commitData.CommitDate.UtcDateTime) + " (" + GetFullDateString(commitData.CommitDate) + ")"); 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(); var submoduleStatus = gitModule.CheckSubmoduleStatus(status.Commit, status.OldCommit, commitData, oldCommitData); sb.Append("Type: "); switch (submoduleStatus) { case SubmoduleStatus.NewSubmodule: sb.AppendLine("New submodule"); break; case SubmoduleStatus.FastForward: sb.AppendLine("Fast Forward"); break; case SubmoduleStatus.Rewind: sb.AppendLine("Rewind"); break; case SubmoduleStatus.NewerTime: sb.AppendLine("Newer commit time"); break; case SubmoduleStatus.OlderTime: sb.AppendLine("Older commit time"); break; case SubmoduleStatus.SameTime: sb.AppendLine("Same commit time"); break; default: sb.AppendLine("Unknown"); break; } if (status.AddedCommits != null && status.RemovedCommits != null && (status.AddedCommits != 0 || status.RemovedCommits != 0)) { sb.Append("\nCommits: "); if (status.RemovedCommits > 0) { sb.Append(status.RemovedCommits + " removed"); if (status.AddedCommits > 0) { sb.Append(", "); } } if (status.AddedCommits > 0) { sb.Append(status.AddedCommits + " added"); } 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 ProcessSubmoduleStatus(GitModule module, GitSubmoduleStatus status, bool moduleIsParent = true, bool limitOutput = false) { if (module is null) { throw new ArgumentNullException(nameof(module)); } if (status is null) { throw new ArgumentNullException(nameof(status)); } GitModule gitModule = moduleIsParent ? module.GetSubmodule(status.Name) : module; var sb = new StringBuilder(); sb.AppendLine("Submodule " + status.Name + " Change"); // TEMP, will be moved in the follow up refactor ICommitDataManager commitDataManager = new CommitDataManager(() => gitModule); CommitData?oldCommitData = null; if (status.OldCommit != status.Commit) { sb.AppendLine(); sb.AppendLine("From:\t" + (status.OldCommit?.ToString() ?? "null")); // Submodule directory must exist to run commands, unknown otherwise if (gitModule.IsValidGitWorkingDir()) { if (status.OldCommit is not null) { oldCommitData = commitDataManager.GetCommitData(status.OldCommit.ToString(), out _, cache: true); } if (oldCommitData is not null) { sb.AppendLine("\t\t\t\t\t" + GetRelativeDateString(DateTime.UtcNow, oldCommitData.CommitDate.UtcDateTime) + " (" + GetFullDateString(oldCommitData.CommitDate) + ")"); var delimiter = new[] { '\n', '\r' }; var lines = oldCommitData.Body.Trim(delimiter).Split(new[] { "\r\n" }, 0); foreach (var line in lines) { sb.AppendLine("\t\t" + line); } } } else { sb.AppendLine(); } } sb.AppendLine(); string dirty = !status.IsDirty ? "" : " (dirty)"; sb.Append(status.OldCommit != status.Commit ? "To:\t" : "Commit:\t"); sb.AppendLine((status.Commit?.ToString() ?? "null") + dirty); CommitData?commitData = null; // Submodule directory must exist to run commands, unknown otherwise if (gitModule.IsValidGitWorkingDir()) { if (status.Commit is not null) { commitData = commitDataManager.GetCommitData(status.Commit.ToString(), out _, cache: true); } if (commitData is not null) { sb.AppendLine("\t\t\t\t\t" + GetRelativeDateString(DateTime.UtcNow, commitData.CommitDate.UtcDateTime) + " (" + GetFullDateString(commitData.CommitDate) + ")"); var delimiter = new[] { '\n', '\r' }; var lines = commitData.Body.Trim(delimiter).Split(new[] { "\r\n" }, 0); foreach (var line in lines) { sb.AppendLine("\t\t" + line); } } if (status.OldCommit == status.Commit) { oldCommitData = commitData; } } else { sb.AppendLine(); } sb.AppendLine(); var submoduleStatus = gitModule.CheckSubmoduleStatus(status.Commit, status.OldCommit, commitData, oldCommitData); sb.Append("Type: "); switch (submoduleStatus) { case SubmoduleStatus.NewSubmodule: sb.AppendLine("New submodule"); break; case SubmoduleStatus.FastForward: sb.AppendLine("Fast Forward"); break; case SubmoduleStatus.Rewind: sb.AppendLine("Rewind"); break; case SubmoduleStatus.NewerTime: sb.AppendLine("Newer commit time"); break; case SubmoduleStatus.OlderTime: sb.AppendLine("Older commit time"); break; case SubmoduleStatus.SameTime: sb.AppendLine("Same commit time"); break; default: sb.AppendLine(status.IsDirty ? "Dirty" : "Unknown"); break; } if (status.AddedCommits is not null && status.RemovedCommits is not null && (status.AddedCommits != 0 || status.RemovedCommits != 0)) { sb.Append("\nCommits: "); if (status.RemovedCommits > 0) { sb.Append(status.RemovedCommits + " removed"); if (status.AddedCommits > 0) { sb.Append(", "); } } if (status.AddedCommits > 0) { sb.Append(status.AddedCommits + " added"); } sb.AppendLine(); } if (status.Commit is not null && status.OldCommit is not null) { const int maxLimitedLines = 5; if (status.IsDirty) { string statusText = gitModule.GetStatusText(untracked: false); if (!string.IsNullOrEmpty(statusText)) { sb.AppendLine("\nStatus:"); if (limitOutput) { var txt = statusText.SplitLines(); if (txt.Length > maxLimitedLines) { statusText = new List <string>(txt).Take(maxLimitedLines).Join(Environment.NewLine) + $"{Environment.NewLine} {txt.Length - maxLimitedLines} more changes"; } } sb.Append(statusText); } } string diffs = gitModule.GetDiffFiles(status.OldCommit.ToString(), status.Commit.ToString(), nullSeparated: false); if (!string.IsNullOrEmpty(diffs)) { sb.AppendLine("\nDifferences:"); if (limitOutput) { var txt = diffs.SplitLines(); if (txt.Length > maxLimitedLines) { diffs = new List <string>(txt).Take(maxLimitedLines).Join(Environment.NewLine) + $"{Environment.NewLine} {txt.Length - maxLimitedLines} more differences"; } } sb.Append(diffs); } } return(sb.ToString()); }