private MatchResult match(DiffRefs diffRefs, DiffToolInfo difftoolInfo) { FullContextDiffProvider provider = new FullContextDiffProvider(_gitRepository); FullContextDiff context = provider.GetFullContextDiff(diffRefs.LeftSHA, diffRefs.RightSHA, difftoolInfo.Left?.FileName ?? null, difftoolInfo.Right?.FileName ?? null); Debug.Assert(context.Left.Count == context.Right.Count); bool isCurrentSideLeft = difftoolInfo.IsLeftSideCurrent; DiffToolInfo.Side currentSide = isCurrentSideLeft ? difftoolInfo.Left.Value : difftoolInfo.Right.Value; SparsedList <string> firstList = isCurrentSideLeft ? context.Left : context.Right; SparsedList <string> secondList = isCurrentSideLeft ? context.Right : context.Left; SparsedListIterator <string> itFirst = SparsedListUtils.FindNth(firstList.Begin(), currentSide.LineNumber - 1); SparsedListIterator <string> itSecond = SparsedListUtils.Advance(secondList.Begin(), itFirst.Position); return(new MatchResult { LeftLineNumber = isCurrentSideLeft ? currentSide.LineNumber : itSecond.LineNumber + 1, RightLineNumber = isCurrentSideLeft ? itSecond.LineNumber + 1 : currentSide.LineNumber }); }
private void getPositionPaths(ref DiffToolInfo difftoolInfo, ref string LeftPath, ref string RightPath) { if (difftoolInfo.Left.HasValue && !difftoolInfo.Right.HasValue) { // When a file is removed, diff tool does not provide a right-side file name LeftPath = difftoolInfo.Left.Value.FileName; RightPath = LeftPath; } else if (!difftoolInfo.Left.HasValue && difftoolInfo.Right.HasValue) { // When a file is added, diff tool does not provide a left-side file name LeftPath = difftoolInfo.Right.Value.FileName; RightPath = LeftPath; } else if (difftoolInfo.Left.HasValue && difftoolInfo.Right.HasValue) { // Filenames may be different and may be the same, it does not matter here LeftPath = difftoolInfo.Left.Value.FileName; RightPath = difftoolInfo.Right.Value.FileName; } else { Debug.Assert(false); } }
/// <summary> /// Throws GitOperationException in case of problems with git. /// </summary> public bool Process(DiffToolInfo source, Core.Matching.DiffRefs refs, out DiffToolInfo dest) { string currentName; string anotherName; bool moved; bool renamed; try { renamed = checkForRenamedFile(refs, source, out currentName, out anotherName, out moved); } catch (GitOperationException) { throw; // fatal error } if (renamed) { Trace.TraceInformation("Detected file {0}. Git repository path: {1}. DiffRefs: {2}\nDiffToolInfo: {3}", (moved ? "move" : "rename"), _gitRepository.Path, refs.ToString(), source.ToString()); } dest = source; return(!renamed || handleFileRename(source, currentName, anotherName, moved, out dest)); }
/// <summary> /// Return DiffPosition if match succeeded and throw if match failed /// Throws ArgumentException in case of bad arguments. /// Throws GitOperationException in case of problems with git. /// </summary> public DiffPosition Match(DiffRefs diffRefs, DiffToolInfo difftoolInfo) { if (!difftoolInfo.IsValid()) { throw new ArgumentException( String.Format("Bad diff tool info: {0}", difftoolInfo.ToString())); } MatchResult matchResult = match(diffRefs, difftoolInfo); return(createPosition(matchResult, diffRefs, difftoolInfo)); }
private static void submitDiscussion(Snapshot snapshot, DiffToolInfo diffToolInfo, DiffPosition position, string body, bool includeContext) { if (body.Length == 0) { MessageBox.Show("Discussion text cannot be empty", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } NewDiscussionParameters parameters = new NewDiscussionParameters { Body = body, Position = includeContext ? createPositionParameters(position) : new Nullable <PositionParameters>() }; MergeRequestDescriptor mergeRequestDescriptor = new MergeRequestDescriptor { HostName = snapshot.Host, ProjectName = snapshot.Project, IId = snapshot.MergeRequestIId }; UserDefinedSettings settings = new UserDefinedSettings(false); DiscussionManager manager = new DiscussionManager(settings); DiscussionCreator creator = manager.GetDiscussionCreator(mergeRequestDescriptor); try { creator.CreateDiscussionAsync(parameters).Wait(); } catch (DiscussionCreatorException ex) { Trace.TraceInformation( "Additional information about exception:\n" + "Position: {0}\n" + "Include context: {1}\n" + "Snapshot refs: {2}\n" + "DiffToolInfo: {3}\n" + "Body:\n{4}", position.ToString(), includeContext.ToString(), snapshot.Refs.ToString(), diffToolInfo.ToString(), body); if (!ex.Handled) { throw; } } }
/// <summary> /// Throws GitOperationException and GitObjectException in case of problems with git. /// </summary> private bool checkForRenamedFile(Core.Matching.DiffRefs refs, DiffToolInfo diffToolInfo, out string currentName, out string anotherName, out bool moved) { GitRenameDetector renameChecker = new GitRenameDetector(_gitRepository); if (!diffToolInfo.Left.HasValue) { Debug.Assert(diffToolInfo.Right.HasValue); currentName = diffToolInfo.Right.Value.FileName; anotherName = renameChecker.IsRenamed( refs.LeftSHA, refs.RightSHA, diffToolInfo.Right.Value.FileName, false, out moved); if (anotherName == diffToolInfo.Right.Value.FileName) { // it is not a renamed but removed file return(false); } } else if (!diffToolInfo.Right.HasValue) { Debug.Assert(diffToolInfo.Left.HasValue); currentName = diffToolInfo.Left.Value.FileName; anotherName = renameChecker.IsRenamed( refs.LeftSHA, refs.RightSHA, diffToolInfo.Left.Value.FileName, true, out moved); if (anotherName == diffToolInfo.Left.Value.FileName) { // it is not a renamed but added file return(false); } } else { // If even two names are given, we need to check here because use might selected manually two // versions of a moved file bool isLeftSide = diffToolInfo.IsLeftSideCurrent; currentName = isLeftSide ? diffToolInfo.Left.Value.FileName : diffToolInfo.Right.Value.FileName; anotherName = renameChecker.IsRenamed( refs.LeftSHA, refs.RightSHA, currentName, isLeftSide, out moved); return(moved); } return(true); }
/// <summary> /// Throws GitOperationException in case of problems with git. /// </summary> internal NewDiscussionForm(Snapshot snapshot, DiffToolInfo difftoolInfo, DiffPosition position, IGitRepository gitRepository) { _interprocessSnapshot = snapshot; _difftoolInfo = difftoolInfo; _position = position; _gitRepository = gitRepository; InitializeComponent(); htmlPanel.BorderStyle = BorderStyle.FixedSingle; htmlPanel.Location = new Point(12, 73); htmlPanel.Size = new Size(860, 76); Controls.Add(htmlPanel); this.ActiveControl = textBoxDiscussionBody; showDiscussionContext(htmlPanel, textBoxFileName); }
private void CheckDiff() { DiffToolInfo info = new DiffToolInfo(this.TargetFile.WorkspaceFolder.Path, this.m_OutputFolder.Path); ExternalToolResult result = this.m_DiffTool.Start(info); if (result.ResultCode == ExternalToolResultCode.Failed) { //Failedの場合、詳細を確認 if (result is DiffToolResult diffResult) { //ツールが存在しなかった場合(未指定含む)、標準のFolderCompareWindowを表示 if (!diffResult.ExistTool) { this.ShowCompareWindow(); } } } }
private static DiffToolInfo createDiffToolInfoCloneWithFakeSide(DiffToolInfo source, string anotherName) { bool isLeftSide = source.IsLeftSideCurrent; return(new DiffToolInfo { IsLeftSideCurrent = isLeftSide, Left = new DiffToolInfo.Side { FileName = isLeftSide ? source.Left.Value.FileName : anotherName, LineNumber = isLeftSide ? source.Left.Value.LineNumber : DiffToolInfo.Side.UninitializedLineNumber }, Right = new DiffToolInfo.Side { FileName = isLeftSide ? anotherName : source.Right.Value.FileName, LineNumber = isLeftSide ? DiffToolInfo.Side.UninitializedLineNumber : source.Right.Value.LineNumber }, }); }
private static bool handleFileRename(DiffToolInfo source, string currentName, string anotherName, bool moved, out DiffToolInfo dest) { dest = source; if (moved) { MessageBox.Show( "Merge Request Helper detected that current file is a moved version of another file. " + "GitLab does not allow to create discussions on moved files.\n\n" + "Current file:\n" + currentName + "\n\n" + "Another file:\n" + anotherName, "Cannot create a discussion", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } bool isLeftSide = source.IsLeftSideCurrent; string fileStatus = isLeftSide ? "new" : "deleted"; if (MessageBox.Show( "Merge Request Helper detected that current file is a renamed version of another file. " + "Do you really want to review this file as a " + fileStatus + " file? " + "It is recommended to press \"No\" and match files manually in the diff tool.\n" + "Current file:\n" + currentName + "\n\n" + "Another file:\n" + anotherName, "Cannot create a discussion", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) == DialogResult.No) { Trace.TraceInformation("User decided to match files manually"); return(false); } dest = createDiffToolInfoCloneWithFakeSide(source, anotherName); Trace.TraceInformation("Updated DiffToolInfo: {0}", dest.ToString()); return(true); }
private DiffPosition createPosition(MatchResult matchResult, DiffRefs diffRefs, DiffToolInfo difftoolInfo) { string leftPath = String.Empty; string rightPath = String.Empty; getPositionPaths(ref difftoolInfo, ref leftPath, ref rightPath); string leftLine = String.Empty; string rightLine = String.Empty; getPositionLines(matchResult, ref leftLine, ref rightLine); DiffPosition position = new DiffPosition { Refs = diffRefs, LeftPath = leftPath, LeftLine = leftLine, RightPath = rightPath, RightLine = rightLine }; return(position); }
internal DiffCallHandler(DiffToolInfo diffToolInfo) { _originalDiffToolInfo = diffToolInfo; }