private void RevisionGridSelectionChanged(object sender, EventArgs e) { try { Cursor.Current = Cursors.WaitCursor; DiffFiles.GitItemStatuses = null; var revisions = RevisionGrid.GetSelectedRevisions(); if (revisions.Count == 1) { DiffFiles.GitItemStatuses = module_.GetDiffFiles( revisions[0].Guid, revisions[0].ParentGuids[0]); } else if (revisions.Count == 2) { DiffFiles.GitItemStatuses = module_.GetDiffFiles( revisions[0].Guid, revisions[1].Guid); } } catch (Exception ex) { Trace.WriteLine(ex.Message); } Cursor.Current = Cursors.Default; }
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()); }