public static Task ViewChangesAsync(this FileViewer diffViewer, [CanBeNull] ObjectId firstId, [CanBeNull] GitRevision selectedRevision, [NotNull] GitItemStatus file, [NotNull] string defaultText, [CanBeNull] Action openWithDifftool = null) { if (firstId == null && selectedRevision != null) { firstId = selectedRevision.FirstParentGuid; } openWithDifftool = openWithDifftool ?? OpenWithDifftool; if (file.IsNew && selectedRevision?.ObjectId == ObjectId.WorkTreeId) { return(diffViewer.ViewFileAsync(file.Name, openWithDifftool: openWithDifftool)); } if (firstId == null || FileHelper.IsImage(file.Name)) { // The previous commit does not exist, nothing to compare with if (file.TreeGuid != null) { // blob guid exists return(diffViewer.ViewGitItemAsync(file, openWithDifftool)); } if (selectedRevision == null) { throw new ArgumentNullException(nameof(selectedRevision)); } // Get blob guid from revision return(diffViewer.ViewGitItemRevisionAsync(file, selectedRevision.ObjectId, openWithDifftool)); } string selectedPatch = diffViewer.GetSelectedPatch(firstId, selectedRevision.ObjectId, file); if (selectedPatch == null) { return(diffViewer.ViewPatchAsync(file.Name, text: defaultText, openWithDifftool: null /* not applicable */, isText: true)); } return(diffViewer.ViewPatchAsync(file.Name, text: selectedPatch, openWithDifftool: openWithDifftool, isText: file.IsSubmodule)); void OpenWithDifftool() { diffViewer.Module.OpenWithDifftool( file.Name, file.OldName, firstId?.ToString(), selectedRevision?.ToString(), "", file.IsTracked); } }
public override string ToString() { if (Data == null) { string name = Id.ToString(); if (name.Length > 8) { name = name.Substring(0, 4) + ".." + name.Substring(name.Length - 4, 4); } return(string.Format("{0} ({1})", name, Index)); } return(Data.ToString()); }
/// <summary> /// View the changes between the revisions, if possible as a diff /// </summary> /// <param name="fileViewer">Current FileViewer</param> /// <param name="firstId">The first (A) commit</param> /// <param name="selectedRev">The selected (B) commit</param> /// <param name="file">The git item to view</param> /// <param name="defaultText">default text if no diff is possible</param> /// <param name="openWithDiffTool">The difftool command to open with</param> /// <returns>Task to view</returns> public static Task ViewChangesAsync(this FileViewer fileViewer, [CanBeNull] ObjectId firstId, [CanBeNull] GitRevision selectedRev, [CanBeNull] GitItemStatus file, [NotNull] string defaultText = "", [CanBeNull] Action openWithDiffTool = null) { if (!string.IsNullOrWhiteSpace(file?.ErrorMessage)) { // Present error (e.g. parsing Git) return(fileViewer.ViewTextAsync(file.Name, file.ErrorMessage)); } if (file == null || selectedRev?.ObjectId == null) { if (!string.IsNullOrWhiteSpace(defaultText)) { return(fileViewer.ViewTextAsync(file?.Name, defaultText, openWithDiffTool)); } fileViewer.Clear(); return(Task.CompletedTask); } firstId ??= selectedRev.FirstParentGuid; openWithDiffTool ??= OpenWithDiffTool; if (file.IsNew || firstId == null || FileHelper.IsImage(file.Name)) { // View blob guid from revision, or file for worktree return(fileViewer.ViewGitItemRevisionAsync(file, selectedRev.ObjectId, openWithDiffTool)); } string selectedPatch = GetSelectedPatch(fileViewer, firstId, selectedRev.ObjectId, file); return(file.IsSubmodule || selectedPatch == null ? fileViewer.ViewTextAsync(file.Name, text : selectedPatch ?? defaultText, openWithDifftool : openWithDiffTool) : fileViewer.ViewPatchAsync(file.Name, text: selectedPatch, openWithDifftool: openWithDiffTool)); void OpenWithDiffTool() { fileViewer.Module.OpenWithDifftool( file.Name, file.OldName, firstId?.ToString(), selectedRev?.ToString(), "", file.IsTracked); }
public static Task ViewChangesAsync(this FileViewer diffViewer, [CanBeNull] ObjectId firstId, [CanBeNull] GitRevision selectedRevision, [NotNull] GitItemStatus file, [NotNull] string defaultText, [CanBeNull] Action openWithDifftool = null) { if (firstId == null && selectedRevision != null) { firstId = selectedRevision.FirstParentGuid; } openWithDifftool ??= OpenWithDifftool; if (file.IsNew || firstId == null || FileHelper.IsImage(file.Name)) { // The previous commit does not exist, nothing to compare with if (selectedRevision == null) { throw new ArgumentNullException(nameof(selectedRevision)); } // View blob guid from revision, or file for worktree return(diffViewer.ViewGitItemRevisionAsync(file, selectedRevision.ObjectId, openWithDifftool)); } string selectedPatch = diffViewer.GetSelectedPatch(firstId, selectedRevision.ObjectId, file); return(diffViewer.ViewPatchAsync(file.Name, text: selectedPatch ?? defaultText, openWithDifftool: openWithDifftool, isText: file.IsSubmodule || selectedPatch == null)); void OpenWithDifftool() { diffViewer.Module.OpenWithDifftool( file.Name, file.OldName, firstId?.ToString(), selectedRevision?.ToString(), "", file.IsTracked); } }
static string PathSafeRevision(GitRevision revision) { if (revision.RevisionType == GitRevisionType.Time) return revision.Time.ToLocalTime().ToString("yyyyMMdd_hhmmss"); return revision.ToString(); }
static string GetTitle(string fileName, GitRevision revision) { string strRev = revision.RevisionType == GitRevisionType.Time ? revision.Time.ToLocalTime().ToString("g") : revision.ToString(); return fileName + " - " + strRev; }