public override void OnExecute(CommandEventArgs e)
        {
            IVisualGitDiffHandler diff = e.GetService<IVisualGitDiffHandler>();
            IGitRepositoryItem reposItem = EnumTools.GetSingle(e.Selection.GetSelection<IGitRepositoryItem>());

            if (reposItem == null)
                return;

            GitRevision from;
            GitRevision to;
            if (e.Command == VisualGitCommand.RepositoryCompareWithWc)
            {
                from = reposItem.Revision;
                to = GitRevision.Working;
            }
            else
            {
                from = reposItem.Revision - 1;
                to = reposItem.Revision;
            }
            VisualGitDiffArgs da = new VisualGitDiffArgs();

            if (to == GitRevision.Working)
            {
                da.BaseFile = diff.GetTempFile(reposItem.Origin.Target, from, true);

                if (da.BaseFile == null)
                    return; // User canceled

                da.MineFile = reposItem.Origin.Target.FullPath;
            }
            else
            {
                string[] files = diff.GetTempFiles(reposItem.Origin.Target, from, to, true);

                if (files == null)
                    return; // User canceled
                da.BaseFile = files[0];
                da.MineFile = files[1];
                System.IO.File.SetAttributes(da.MineFile, System.IO.FileAttributes.ReadOnly | System.IO.FileAttributes.Normal);
            }

            da.BaseTitle = diff.GetTitle(reposItem.Origin.Target, from);
            da.MineTitle = diff.GetTitle(reposItem.Origin.Target, to);
            diff.RunDiff(da);
        }
예제 #2
0
        public void Reset(int n, VisualGitDiffArgs args)
        {
            _nFrame = n;
            Clear();

            Collection<string> A, B;
            GetFileLines(args.BaseFile, args.MineFile, out A, out B);
            TextDiff Diff = new TextDiff(HashType.HashCode, false, false);
            EditScript Script = Diff.Execute(A, B);

            string strCaptionA = args.BaseTitle ?? Path.GetFileName(args.BaseFile);
            string strCaptionB = args.MineTitle ?? Path.GetFileName(args.MineFile);
            //VisualGit.Diff.FileName fnA = new VisualGit.Diff.FileName(mine);
            //VisualGit.Diff.FileName fnB = new VisualGit.Diff.FileName(theirs);
            diffControl1.SetData(A, B, Script, strCaptionA, strCaptionB);

            ToolWindowHost.Title = Path.GetFileName(args.MineFile) + " - Diff";
        }
예제 #3
0
        public void OnExecute(CommandEventArgs e)
        {
            // All checked in OnUpdate
            ILogControl logWindow = e.Selection.GetActiveControl<ILogControl>();
            GitOrigin origin = EnumTools.GetSingle(logWindow.Origins);
            IGitLogItem item = EnumTools.GetSingle(e.Selection.GetSelection<IGitLogItem>());

            IVisualGitDiffHandler diff = e.GetService<IVisualGitDiffHandler>();

            VisualGitDiffArgs da = new VisualGitDiffArgs();

            da.BaseFile = diff.GetTempFile(origin.Target, item.Revision, true);
            if (da.BaseFile == null)
                return; // User cancel
            da.MineFile = origin.Target.FullPath;
            da.BaseTitle = string.Format("Base (r{0})", item.Revision);
            da.MineTitle = "Working";

            diff.RunDiff(da);
        }
예제 #4
0
        private bool RunInternalDiff(VisualGitDiffArgs args)
        {
            IVisualGitPackage pkg = GetService<IVisualGitPackage>();

            int nWnd;

            if (_freeDiffs.Count > 0)
            {
                nWnd = _freeDiffs[0];
                _freeDiffs.RemoveAt(0);
            }
            else
                nWnd = _nNext++;

            pkg.ShowToolWindow(VisualGitToolWindow.Diff, nWnd, true);

            DiffToolWindowControl twc = GetService<ISelectionContext>().ActiveFrameControl as DiffToolWindowControl;

            if (twc != null)
                twc.Reset(nWnd, args);

            return false;
        }
예제 #5
0
        void ExecuteDiff(CommandEventArgs e, ICollection<GitOrigin> targets, GitRevisionRange range)
        {
            if (targets.Count != 1)
                return;

            var target = EnumTools.GetSingle(targets);
            GitTarget diffTarget = target.Target;

            IVisualGitDiffHandler diff = e.GetService<IVisualGitDiffHandler>();
            VisualGitDiffArgs da = new VisualGitDiffArgs();

            string[] files = diff.GetTempFiles(diffTarget, range.StartRevision, range.EndRevision, true);

            if (files == null)
                return;

            da.BaseFile = files[0];
            da.MineFile = files[1];
            da.BaseTitle = diff.GetTitle(diffTarget, range.StartRevision);
            da.MineTitle = diff.GetTitle(diffTarget, range.EndRevision);
            da.ReadOnly = true;
            diff.RunDiff(da);
        }
예제 #6
0
        public override void OnExecute(CommandEventArgs e)
        {
            List<GitItem> selectedFiles = new List<GitItem>();
            bool selectionHasDeleted = false;

            if (e.Command == VisualGitCommand.DocumentShowChanges)
            {
                GitItem item = e.Selection.ActiveDocumentItem;

                if(item == null)
                    return;
                selectedFiles.Add(item);
            }
            else
                foreach (GitItem item in e.Selection.GetSelectedGitItems(false))
                {
                    if (!item.IsVersioned || (item.Status.State == GitStatus.Added && !item.Status.IsCopied))
                        continue;

                    if ( e.Command == VisualGitCommand.ItemCompareBase
                         || e.Command == VisualGitCommand.ItemShowChanges)
                    {
                        if (!(item.IsModified || item.IsDocumentDirty)
                            || !item.IsLocalDiffAvailable // exclude if local diff is not available
                            )
                            continue;
                    }

                    if (e.Command == VisualGitCommand.DiffLocalItem)
                    {
                        selectionHasDeleted |= !NotDeletedFilter(item);
                    }

                    selectedFiles.Add(item);
                }

            GitRevisionRange revRange = null;
            switch (e.Command)
            {
                case VisualGitCommand.DiffLocalItem:
                    break; // revRange null -> show selector
                case VisualGitCommand.ItemCompareBase:
                case VisualGitCommand.ItemShowChanges:
                case VisualGitCommand.DocumentShowChanges:
                    revRange = new GitRevisionRange(GitRevision.Base, GitRevision.Working);
                    break;
                case VisualGitCommand.ItemCompareCommitted:
                    revRange = new GitRevisionRange(GitRevision.Committed, GitRevision.Working);
                    break;
                case VisualGitCommand.ItemCompareLatest:
                    revRange = new GitRevisionRange(GitRevision.Head, GitRevision.Working);
                    break;
                case VisualGitCommand.ItemComparePrevious:
                    revRange = new GitRevisionRange(GitRevision.Previous, GitRevision.Working);
                    break;
            }

            if (e.PromptUser || selectedFiles.Count > 1 || revRange == null)
            {
                PathSelectorInfo info = new PathSelectorInfo("Select item for Diff", selectedFiles);
                info.SingleSelection = false;
                info.RevisionStart = revRange == null ? GitRevision.Base : revRange.StartRevision;
                info.RevisionEnd = revRange == null ? GitRevision.Working : revRange.EndRevision;
                if (selectionHasDeleted)
                {
                    // do not allow selecting deleted items if the revision combination includes GitRevision.Working
                    info.CheckableFilter += new PathSelectorInfo.SelectableFilter(delegate(GitItem item, GitRevision from, GitRevision to)
                    {
                        if (item != null
                            && (from == GitRevision.Working
                                || to == GitRevision.Working
                                )
                            )
                        {
                            return NotDeletedFilter(item);
                        }
                        return true;
                    });
                }
                info.EnableRecursive = false;
                info.Depth = GitDepth.Infinity;

                PathSelectorResult result;
                // should we show the path selector?
                if (e.PromptUser || !Shift)
                {
                    IUIShell ui = e.GetService<IUIShell>();

                    result = ui.ShowPathSelector(info);
                    if (!result.Succeeded)
                        return;
                }
                else
                    result = info.DefaultResult;

                selectedFiles.Clear();
                selectedFiles.AddRange(result.Selection);
                revRange = new GitRevisionRange(result.RevisionStart, result.RevisionEnd);
            }

            if (revRange.EndRevision.RevisionType == GitRevisionType.Working ||
                revRange.StartRevision.RevisionType == GitRevisionType.Working)
            {
                // Save only the files needed

                IVisualGitOpenDocumentTracker tracker = e.GetService<IVisualGitOpenDocumentTracker>();
                if (tracker != null)
                    tracker.SaveDocuments(GitItem.GetPaths(selectedFiles));
            }

            IVisualGitDiffHandler diff = e.GetService<IVisualGitDiffHandler>();
            foreach (GitItem item in selectedFiles)
            {
                VisualGitDiffArgs da = new VisualGitDiffArgs();

                if (item.Status.IsCopied &&
                    (!revRange.StartRevision.RequiresWorkingCopy || !revRange.EndRevision.RequiresWorkingCopy))
                {
                    // The file is copied, use its origins history instead of that of the new file
                    GitTarget copiedFrom = diff.GetCopyOrigin(item);

                    // TODO: Maybe handle Previous/Committed as history

                    if (copiedFrom != null && !revRange.StartRevision.RequiresWorkingCopy)
                    {
                        if (null == (da.BaseFile = diff.GetTempFile(copiedFrom, revRange.StartRevision, true)))
                            return; // Canceled
                        da.BaseTitle = diff.GetTitle(copiedFrom, revRange.StartRevision);
                    }

                    if (copiedFrom != null && !revRange.EndRevision.RequiresWorkingCopy)
                    {
                        if (null == (da.MineFile = diff.GetTempFile(copiedFrom, revRange.EndRevision, true)))
                            return; // Canceled
                        da.MineTitle = diff.GetTitle(copiedFrom, revRange.EndRevision);
                    }
                }

                if (da.BaseFile == null)
                {
                    if (null == (da.BaseFile = (revRange.StartRevision == GitRevision.Working) ? item.FullPath :
                        diff.GetTempFile(item, revRange.StartRevision, true)))
                    {
                        return; // Canceled
                    }

                    da.BaseTitle = diff.GetTitle(item, revRange.StartRevision);
                }

                if (da.MineFile == null)
                {
                    if (null == (da.MineFile = (revRange.EndRevision == GitRevision.Working) ? item.FullPath :
                        diff.GetTempFile(item, revRange.EndRevision, true)))
                    {
                        return; // Canceled
                    }

                    da.MineTitle = diff.GetTitle(item, revRange.EndRevision);
                }

                if (!String.Equals(da.MineFile, item.FullPath, StringComparison.OrdinalIgnoreCase))
                    da.ReadOnly = true;

                diff.RunDiff(da);
            }
        }
예제 #7
0
            public Replacer(VisualGitDiff context, VisualGitDiffToolArgs args, DiffToolMode toolMode)
            {
                if (context == null)
                    throw new ArgumentNullException("context");
                else if (args == null)
                    throw new ArgumentNullException("args");

                _context = context;
                _toolArgs = args;
                _diffArgs = args as VisualGitDiffArgs;
                _mergeArgs = args as VisualGitMergeArgs;
                _patchArgs = args as VisualGitPatchArgs;
                _toolMode = toolMode;
            }
예제 #8
0
        public bool RunDiff(VisualGitDiffArgs args)
        {
            if (args == null)
                throw new ArgumentNullException("args");
            else if (!args.Validate())
                throw new ArgumentException("Arguments not filled correctly", "args");

            string diffApp = this.GetDiffPath(args.Mode);

            if (string.IsNullOrEmpty(diffApp))
                return RunInternalDiff(args);

            string program;
            string arguments;
            if (!Substitute(diffApp, args, DiffToolMode.Diff, out program, out arguments))
            {
                new VisualGitMessageBox(Context).Show(string.Format("Can't find diff program '{0}'", program ?? diffApp));
                return false;
            }

            Process p = new Process();
            p.StartInfo = new ProcessStartInfo(program, arguments);

            string mergedFile = args.MineFile;

            DiffToolMonitor monitor = null;
            if (!string.IsNullOrEmpty(mergedFile))
            {
                monitor = new DiffToolMonitor(Context, mergedFile, false);

                p.EnableRaisingEvents = true;
                monitor.Register(p);
            }

            bool started = false;
            try
            {
                return started = p.Start();
            }
            finally
            {
                if (!started)
                {
                    if (monitor != null)
                        monitor.Dispose();
                }
            }
        }