Esempio n. 1
0
        private void FileHistoryContextMenuOpening(object sender, CancelEventArgs e)
        {
            var selectedRevisions = FileChanges.GetSelectedRevisions();

            diffToolremotelocalStripMenuItem.Enabled =
                selectedRevisions.Count == 1 && selectedRevisions[0].Guid != GitRevision.UnstagedGuid &&
                File.Exists(_fullPathResolver.Resolve(FileName));
            openWithDifftoolToolStripMenuItem.Enabled =
                selectedRevisions.Count >= 1 && selectedRevisions.Count <= 2;
            manipuleerCommitToolStripMenuItem.Enabled =
                viewCommitToolStripMenuItem.Enabled   =
                    selectedRevisions.Count == 1 && !selectedRevisions[0].IsArtificial();
            saveAsToolStripMenuItem.Enabled = selectedRevisions.Count == 1;
        }
Esempio n. 2
0
        private FormFileHistory([NotNull] GitUICommands commands)
            : base(commands)
        {
            InitializeComponent();
            ConfigureTabControl();

            _filterBranchHelper    = new FilterBranchHelper(toolStripBranchFilterComboBox, toolStripBranchFilterDropDownButton, FileChanges);
            _filterRevisionsHelper = new FilterRevisionsHelper(toolStripRevisionFilterTextBox, toolStripRevisionFilterDropDownButton, FileChanges, toolStripRevisionFilterLabel, ShowFirstParent, form: this);

            _formBrowseMenus = new FormBrowseMenus(FileHistoryContextMenu);
            _formBrowseMenus.ResetMenuCommandSets();
            _formBrowseMenus.AddMenuCommandSet(MainMenuItem.NavigateMenu, FileChanges.MenuCommands.NavigateMenuCommands);
            _formBrowseMenus.AddMenuCommandSet(MainMenuItem.ViewMenu, FileChanges.MenuCommands.ViewMenuCommands);
            _formBrowseMenus.InsertAdditionalMainMenuItems(toolStripSeparator4);

            _commitDataManager = new CommitDataManager(() => Module);
            _fullPathResolver  = new FullPathResolver(() => Module.WorkingDir);

            CommitDiff.EscapePressed += Close;
            View.EscapePressed       += Close;
            Diff.EscapePressed       += Close;
            Blame.EscapePressed      += Close;

            copyToClipboardToolStripMenuItem.SetRevisionFunc(() => FileChanges.GetSelectedRevisions());

            InitializeComplete();

            return;

            void ConfigureTabControl()
            {
                tabControl1.ImageList = new ImageList
                {
                    ColorDepth = ColorDepth.Depth8Bit,
                    ImageSize  = DpiUtil.Scale(new Size(16, 16)),
                    Images     =
                    {
                        Images.CommitSummary,
                        Images.Diff,
                        Images.ViewFile,
                        Images.Blame
                    }
                };
                tabControl1.TabPages[0].ImageIndex = 0;
                tabControl1.TabPages[1].ImageIndex = 1;
                tabControl1.TabPages[2].ImageIndex = 2;
                tabControl1.TabPages[3].ImageIndex = 3;
            }
        }
Esempio n. 3
0
        public FormFileHistory(GitUICommands commands, string fileName, GitRevision revision = null, bool filterByRevision = false)
            : this(commands)
        {
            FileChanges.InitialObjectId     = revision?.ObjectId;
            FileChanges.ShowBuildServerInfo = true;

            FileName = fileName;
            SetTitle();

            Diff.ExtraDiffArgumentsChanged += (sender, e) => UpdateSelectedFileViewers();

            var isSubmodule = GitModule.IsValidGitWorkingDir(_fullPathResolver.Resolve(FileName));

            if (isSubmodule)
            {
                tabControl1.RemoveIfExists(BlameTab);
            }

            FileChanges.SelectionChanged += FileChangesSelectionChanged;
            FileChanges.DisableContextMenu();

            bool blameTabExists = tabControl1.Contains(BlameTab);

            UpdateFollowHistoryMenuItems();

            fullHistoryToolStripMenuItem.Checked     = AppSettings.FullHistoryInFileHistory;
            showFullHistoryToolStripMenuItem.Checked = AppSettings.FullHistoryInFileHistory;
            simplifyMergesToolStripMenuItem.Checked  = AppSettings.SimplifyMergesInFileHistory;
            simplifyMergesToolStripMenuItem.Enabled  = AppSettings.FullHistoryInFileHistory;
            simplifyMergesContextMenuItem.Checked    = AppSettings.SimplifyMergesInFileHistory;
            simplifyMergesContextMenuItem.Enabled    = AppSettings.FullHistoryInFileHistory;

            loadHistoryOnShowToolStripMenuItem.Checked = AppSettings.LoadFileHistoryOnShow;
            loadBlameOnShowToolStripMenuItem.Checked   = AppSettings.LoadBlameOnShow && blameTabExists;
            saveAsToolStripMenuItem.Visible            = !isSubmodule;

            toolStripBlameOptions.Visible = blameTabExists;
            if (blameTabExists)
            {
                ignoreWhitespaceToolStripMenuItem.Checked            = AppSettings.IgnoreWhitespaceOnBlame;
                detectMoveAndCopyInAllFilesToolStripMenuItem.Checked = AppSettings.DetectCopyInAllOnBlame;
                detectMoveAndCopyInThisFileToolStripMenuItem.Checked = AppSettings.DetectCopyInFileOnBlame;
            }

            if (filterByRevision && revision?.Guid != null)
            {
                _filterBranchHelper.SetBranchFilter(revision.Guid, false);
            }
        }
Esempio n. 4
0
        private void UpdateSelectedFileViewers(bool force = false)
        {
            var selectedRows = FileChanges.GetSelectedRevisions();

            if (selectedRows.Count == 0)
            {
                return;
            }

            GitRevision revision = selectedRows[0];
            var         children = FileChanges.GetRevisionChildren(revision.Guid);

            var fileName = revision.Name;

            if (string.IsNullOrEmpty(fileName))
            {
                fileName = FileName;
            }

            SetTitle(fileName);

            if (tabControl1.SelectedTab == BlameTab)
            {
                Blame.LoadBlame(revision, children, fileName, FileChanges, BlameTab, Diff.Encoding, force: force);
            }
            else if (tabControl1.SelectedTab == ViewTab)
            {
                var scrollpos = View.ScrollPos;

                View.Encoding = Diff.Encoding;
                View.ViewGitItemRevision(fileName, revision.Guid);
                View.ScrollPos = scrollpos;
            }
            else if (tabControl1.SelectedTab == DiffTab)
            {
                GitItemStatus file = new GitItemStatus();
                file.IsTracked   = true;
                file.Name        = fileName;
                file.IsSubmodule = GitModule.IsValidGitWorkingDir(_fullPathResolver.Resolve(fileName));
                Diff.ViewChanges(FileChanges.GetSelectedRevisions(), file, "You need to select at least one revision to view diff.");
            }

            if (_buildReportTabPageExtension == null)
            {
                _buildReportTabPageExtension = new BuildReportTabPageExtension(tabControl1, _buildReportTabCaption.Text);
            }

            _buildReportTabPageExtension.FillBuildReport(selectedRows.Count == 1 ? revision : null);
        }
        private void FileChangesDoubleClick(object sender, EventArgs e)
        {
            if (FileChanges.GetRevisions().Count == 0)
            {
                GitUICommands.Instance.StartCompareRevisionsDialog();
                return;
            }

            IGitItem revision = FileChanges.GetRevisions()[0];

            var form = new FormDiffSmall();

            form.SetRevision(revision.Guid);
            form.ShowDialog();
        }
        public FormFileHistory(string fileName, GitRevision revision)
        {
            InitializeComponent();
            FileChanges.SetInitialRevision(revision);
            Translate();

            this.FileName = fileName;

            Diff.ExtraDiffArgumentsChanged += DiffExtraDiffArgumentsChanged;

            FileChanges.SelectionChanged += FileChangesSelectionChanged;
            FileChanges.DisableContextMenu();

            followFileHistoryToolStripMenuItem.Checked = Settings.FollowRenamesInFileHistory;
        }
Esempio n. 7
0
        private void FileHistoryContextMenuOpening(object sender, CancelEventArgs e)
        {
            var selectedRevisions = FileChanges.GetSelectedRevisions();

            diffToolRemoteLocalStripMenuItem.Enabled =
                selectedRevisions.Count == 1 && selectedRevisions[0].Guid != GitRevision.WorkTreeGuid &&
                File.Exists(_fullPathResolver.Resolve(FileName));
            openWithDifftoolToolStripMenuItem.Enabled =
                selectedRevisions.Count >= 1 && selectedRevisions.Count <= 2;
            manipulateCommitToolStripMenuItem.Enabled =
                selectedRevisions.Count == 1 && !selectedRevisions[0].IsArtificial;
            saveAsToolStripMenuItem.Enabled          = selectedRevisions.Count == 1;
            copyToClipboardToolStripMenuItem.Enabled =
                selectedRevisions.Count >= 1 && !selectedRevisions[0].IsArtificial;
        }
Esempio n. 8
0
        private void LoadFileHistory()
        {
            FileChanges.Visible = true;

            asyncLoader.Load(() => BuildFilter(FileName), (filter) =>
            {
                if (filter == null)
                {
                    return;
                }
                FileChanges.FixedFilter          = filter;
                FileChanges.AllowGraphWithFilter = true;
                FileChanges.Load();
            });
        }
Esempio n. 9
0
 private void Blame_CommandClick(object sender, CommitInfo.CommandEventArgs e)
 {
     if (e.Command == "gotocommit")
     {
         FileChanges.SetSelectedRevision(new GitRevision(Module, e.Data));
     }
     else if (e.Command == "gotobranch" || e.Command == "gototag")
     {
         string     error  = "";
         CommitData commit = CommitData.GetCommitData(Module, e.Data, ref error);
         if (commit != null)
         {
             FileChanges.SetSelectedRevision(new GitRevision(Module, commit.Guid));
         }
     }
 }
Esempio n. 10
0
        private void UpdateSelectedFileViewers()
        {
            var selectedRows = FileChanges.GetSelectedRevisions();

            if (selectedRows.Count == 0)
            {
                return;
            }

            IGitItem revision = selectedRows[0];

            var fileName = revision.Name;

            if (string.IsNullOrEmpty(fileName))
            {
                fileName = FileName;
            }

            Text = string.Format("File History - {0}", FileName);
            if (!fileName.Equals(FileName))
            {
                Text = Text + string.Format(" ({0})", fileName);
            }

            if (tabControl1.SelectedTab == BlameTab)
            {
                Blame.LoadBlame(revision.Guid, fileName, FileChanges, BlameTab, Diff.Encoding);
            }
            if (tabControl1.SelectedTab == ViewTab)
            {
                var scrollpos = View.ScrollPos;

                View.Encoding = Diff.Encoding;
                View.ViewGitItemRevision(fileName, revision.Guid);
                View.ScrollPos = scrollpos;
            }

            if (tabControl1.SelectedTab == DiffTab)
            {
                GitItemStatus file = new GitItemStatus();
                file.IsTracked = true;
                file.Name      = fileName;
                Diff.ViewPatch(FileChanges, file, "You need to select at least one revision to view diff.");
            }
        }
Esempio n. 11
0
        public void Visit(Commit commit, FileChanges fileChanges)
        {
            if (!GitFileInfos.ContainsKey(fileChanges.Path))
            {
                GitFileInfos.Add(
                    fileChanges.Path,
                    new GitFileInfo()
                {
                    Path            = fileChanges.Path,
                    LinesAdded      = 0,
                    LinesDeleted    = 0,
                    NumberOfCommits = 0
                });
            }

            GitFileInfos[fileChanges.Path].LinesAdded   += fileChanges.LinesAdded;
            GitFileInfos[fileChanges.Path].LinesDeleted += fileChanges.LinesDeleted;
            GitFileInfos[fileChanges.Path].NumberOfCommits++;
        }
Esempio n. 12
0
        public void Visit(Commit commit, FileChanges fileChanges)
        {
            if (!GitFileInfos.ContainsKey(fileChanges.Path))
            {
                GitFileInfos.Add(
                    fileChanges.Path,
                    new GitFileInfo()
                    {
                        Path = fileChanges.Path,
                        LinesAdded = 0,
                        LinesDeleted = 0,
                        NumberOfCommits = 0
                    });
            }

            GitFileInfos[fileChanges.Path].LinesAdded += fileChanges.LinesAdded;
            GitFileInfos[fileChanges.Path].LinesDeleted += fileChanges.LinesDeleted;
            GitFileInfos[fileChanges.Path].NumberOfCommits++;
        }
Esempio n. 13
0
        public void FSWTest()
        {
            System.Random rand = new System.Random();

            string tempDir = Path.GetTempPath();
            string file1   = Path.Combine(tempDir, String.Format("test{0}.meeptest", rand.Next(1000)));

            if (File.Exists(file1))
            {
                File.Delete(file1);
            }

            var Watcher = new FileChanges
            {
                Path     = tempDir,
                DryStart = true,
                Filter   = "*.meeptest"
            };

            Message   lastReceived = null;
            Exception lastEx       = null;

            using (IDisposable subscription = Watcher.Pipeline.Subscribe <Message>(
                       msg => lastReceived = msg,
                       ex => lastEx = ex,
                       () => Console.WriteLine("Pipeline completed")))
            {
                var fstream = File.Create(file1);
                fstream.Close();
                System.Threading.Thread.Sleep(300);
                Assert.NotNull(lastReceived);
                Assert.Null(lastEx);

                Assert.IsType(typeof(FileChanged), lastReceived);
                FileChanged change = lastReceived as FileChanged;
                Assert.Equal(file1, change.FullPath);
                Assert.Equal(WatcherChangeTypes.Created, change.ChangeType);
            }


            File.Delete(file1);
        }
Esempio n. 14
0
        private void UpdateSelectedFileViewers()
        {
            var selectedRows = FileChanges.GetSelectedRevisions();

            if (selectedRows.Count == 0)
            {
                return;
            }

            GitRevision revision = selectedRows[0];
            var         children = FileChanges.GetRevisionChildren(revision.Guid);

            var fileName = revision.Name;

            if (string.IsNullOrEmpty(fileName))
            {
                fileName = FileName;
            }

            SetTitle(fileName);

            if (tabControl1.SelectedTab == BlameTab)
            {
                Blame.LoadBlame(revision, children, fileName, FileChanges, BlameTab, Diff.Encoding);
            }
            else if (tabControl1.SelectedTab == ViewTab)
            {
                var scrollpos = View.ScrollPos;

                View.Encoding = Diff.Encoding;
                View.ViewGitItemRevision(fileName, revision.Guid);
                View.ScrollPos = scrollpos;
            }
            else if (tabControl1.SelectedTab == DiffTab)
            {
                GitItemStatus file = new GitItemStatus();
                file.IsTracked   = true;
                file.Name        = fileName;
                file.IsSubmodule = GitModule.IsValidGitWorkingDir(Path.Combine(Module.WorkingDir, fileName));
                Diff.ViewChanges(FileChanges.GetSelectedRevisions(), file, "You need to select at least one revision to view diff.");
            }
        }
Esempio n. 15
0
        private void FileChangesSelectionChanged(object sender, EventArgs e)
        {
            View.SaveCurrentScrollPos();
            Diff.SaveCurrentScrollPos();

            var selectedRows = FileChanges.GetSelectedRevisions();

            if (selectedRows.Count > 0)
            {
                GitRevision revision = selectedRows[0];
                if (revision.IsArtificial())
                {
                    tabControl1.RemoveIfExists(BlameTab);
                }
                else
                {
                    tabControl1.InsertIfNotExists(2, BlameTab);
                }
            }
            UpdateSelectedFileViewers();
        }
Esempio n. 16
0
        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var selectedRows = FileChanges.GetSelectedRevisions();

            if (selectedRows.Count > 0)
            {
                string orgFileName = selectedRows[0].Name;

                if (string.IsNullOrEmpty(orgFileName))
                {
                    orgFileName = FileName;
                }

                string fullName = _fullPathResolver.Resolve(orgFileName);
                if (string.IsNullOrWhiteSpace(fullName))
                {
                    return;
                }

                fullName = fullName.ToNativePath();
                using (var fileDialog = new SaveFileDialog
                {
                    InitialDirectory = Path.GetDirectoryName(fullName),
                    FileName = Path.GetFileName(fullName),
                    DefaultExt = Path.GetExtension(fullName),
                    AddExtension = true
                })
                {
                    fileDialog.Filter =
                        "Current format (*." +
                        fileDialog.DefaultExt + ")|*." +
                        fileDialog.DefaultExt +
                        "|All files (*.*)|*.*";
                    if (fileDialog.ShowDialog(this) == DialogResult.OK)
                    {
                        Module.SaveBlobAs(fileDialog.FileName, selectedRows[0].Guid + ":\"" + orgFileName + "\"");
                    }
                }
            }
        }
Esempio n. 17
0
        private void FileChangesSelectionChanged(object sender, EventArgs e)
        {
            View.SaveCurrentScrollPos();
            Diff.SaveCurrentScrollPos();

            var selectedRows = FileChanges.GetSelectedRevisions();

            if (selectedRows.Count > 0)
            {
                bool        isSubmodule = GitModule.IsValidGitWorkingDir(Path.Combine(Module.WorkingDir, FileName));
                GitRevision revision    = selectedRows[0];
                if (revision.IsArtificial() || isSubmodule)
                {
                    tabControl1.RemoveIfExists(BlameTab);
                }
                else
                {
                    tabControl1.InsertIfNotExists(2, BlameTab);
                }
            }
            UpdateSelectedFileViewers();
        }
Esempio n. 18
0
        private void OpenWithDifftoolToolStripMenuItemClick(object sender, EventArgs e)
        {
            var    selectedRows = FileChanges.GetSelectedRevisions();
            string rev1;
            string rev2;

            switch (selectedRows.Count)
            {
            case 1:
            {
                rev1 = selectedRows[0].Guid;
                var parentGuids = selectedRows[0].ParentGuids;
                if (parentGuids != null && parentGuids.Length > 0)
                {
                    rev2 = parentGuids[0];
                }
                else
                {
                    rev2 = rev1;
                }
            }
            break;

            case 0:
                return;

            default:
                rev1 = selectedRows[0].Guid;
                rev2 = selectedRows[1].Guid;
                break;
            }

            var output = Settings.Module.OpenWithDifftool(FileName, rev1, rev2);

            if (!string.IsNullOrEmpty(output))
            {
                MessageBox.Show(this, output);
            }
        }
        public async Task <RunCodeActionResponse> Handle(RunCodeActionRequest request)
        {
            var response = new RunCodeActionResponse();

            var actions = await CodeActionHelper.GetActions(_workspace, _codeActionProviders, _logger, request);

            var action = actions.FirstOrDefault(a => a.GetIdentifier().Equals(request.Identifier));

            if (action == null)
            {
                return(new RunCodeActionResponse());
            }

            _logger.LogInformation("Applying " + action);
            var operations = await action.GetOperationsAsync(CancellationToken.None);

            var solution      = _workspace.CurrentSolution;
            var changes       = Enumerable.Empty <OmniSharp.Models.ModifiedFileResponse>();
            var directoryName = Path.GetDirectoryName(request.FileName);

            foreach (var o in operations)
            {
                var applyChangesOperation = o as ApplyChangesOperation;
                if (applyChangesOperation != null)
                {
                    changes  = changes.Concat(await FileChanges.GetFileChangesAsync(applyChangesOperation.ChangedSolution, solution, directoryName, request.WantsTextChanges));
                    solution = applyChangesOperation.ChangedSolution;
                }
            }

            if (request.ApplyTextChanges)
            {
                _workspace.TryApplyChanges(solution);
            }

            response.Changes = changes;
            return(response);
        }
Esempio n. 20
0
 private void Blame_CommandClick(object sender, CommitInfo.CommandEventArgs e)
 {
     if (e.Command == "gotocommit")
     {
         FileChanges.SetSelectedRevision(_longShaProvider.Get(e.Data));
     }
     else if (e.Command == "gotobranch" || e.Command == "gototag")
     {
         CommitData commit = _commitDataManager.GetCommitData(e.Data, out _);
         if (commit != null)
         {
             FileChanges.SetSelectedRevision(new GitRevision(commit.Guid));
         }
     }
     else if (e.Command == "navigatebackward")
     {
         FileChanges.NavigateBackward();
     }
     else if (e.Command == "navigateforward")
     {
         FileChanges.NavigateForward();
     }
 }
Esempio n. 21
0
        private void LoadFileHistory()
        {
            FileChanges.Visible = true;

            if (string.IsNullOrEmpty(FileName))
            {
                return;
            }

            _asyncLoader.LoadAsync(
                () => BuildFilter(FileName),
                filter =>
            {
                var(revisionFilter, pathFilter) = BuildFilter(FileName);

                FileChanges.FixedRevisionFilter  = revisionFilter;
                FileChanges.FixedPathFilter      = pathFilter;
                FileChanges.FiltredFileName      = FileName;
                FileChanges.AllowGraphWithFilter = true;

                FileChanges.Load();
            });
        }
Esempio n. 22
0
        public FormFileHistory(GitUICommands aCommands, string fileName, GitRevision revision, bool filterByRevision)
            : this(aCommands)
        {
            FileChanges.SetInitialRevision(revision);
            Translate();

            FileName = fileName;

            Diff.ExtraDiffArgumentsChanged += DiffExtraDiffArgumentsChanged;

            FileChanges.SelectionChanged += FileChangesSelectionChanged;
            FileChanges.DisableContextMenu();

            followFileHistoryToolStripMenuItem.Checked = Settings.FollowRenamesInFileHistory;
            fullHistoryToolStripMenuItem.Checked       = Settings.FullHistoryInFileHistory;
            loadHistoryOnShowToolStripMenuItem.Checked = Settings.LoadFileHistoryOnShow;
            loadBlameOnShowToolStripMenuItem.Checked   = Settings.LoadBlameOnShow;

            if (filterByRevision && revision != null && revision.Guid != null)
            {
                filterBranchHelper.SetBranchFilter(revision.Guid, false);
            }
        }
Esempio n. 23
0
 private void Blame_CommandClick(object sender, CommitInfo.CommandEventArgs e)
 {
     if (e.Command == "gotocommit")
     {
         FileChanges.SetSelectedRevision(GitRevision.CreateForShortSha1(Module, e.Data));
     }
     else if (e.Command == "gotobranch" || e.Command == "gototag")
     {
         string     error  = "";
         CommitData commit = _commitDataManager.GetCommitData(e.Data, ref error);
         if (commit != null)
         {
             FileChanges.SetSelectedRevision(new GitRevision(Module, commit.Guid));
         }
     }
     else if (e.Command == "navigatebackward")
     {
         FileChanges.NavigateBackward();
     }
     else if (e.Command == "navigateforward")
     {
         FileChanges.NavigateForward();
     }
 }
Esempio n. 24
0
 private void viewCommitToolStripMenuItem_Click(object sender, EventArgs e)
 {
     FileChanges.ViewSelectedRevisions();
 }
 public void Visit(Commit commit, FileChanges fileChanges)
 {
 }
Esempio n. 26
0
        private void UpdateSelectedFileViewers(bool force = false)
        {
            var selectedRevisions = FileChanges.GetSelectedRevisions();

            if (selectedRevisions.Count == 0)
            {
                return;
            }

            GitRevision revision = selectedRevisions[0];
            var         children = FileChanges.GetRevisionChildren(revision.ObjectId);

            var fileName = revision.Name;

            if (string.IsNullOrEmpty(fileName))
            {
                fileName = FileName;
            }

            SetTitle(fileName);

            if (revision.IsArtificial)
            {
                tabControl1.SelectedTab = DiffTab;

                CommitInfoTabPage.Parent = null;
                BlameTab.Parent          = null;
                ViewTab.Parent           = null;
            }
            else
            {
                if (CommitInfoTabPage.Parent == null)
                {
                    tabControl1.TabPages.Insert(0, CommitInfoTabPage);
                }

                if (ViewTab.Parent == null)
                {
                    var index = tabControl1.TabPages.IndexOf(DiffTab);
                    Debug.Assert(index != -1, "TabControl should contain diff tab page");
                    tabControl1.TabPages.Insert(index + 1, ViewTab);
                }

                if (BlameTab.Parent == null)
                {
                    var index = tabControl1.TabPages.IndexOf(ViewTab);
                    Debug.Assert(index != -1, "TabControl should contain view tab page");
                    tabControl1.TabPages.Insert(index + 1, BlameTab);
                }
            }

            if (tabControl1.SelectedTab == BlameTab)
            {
                Blame.LoadBlame(revision, children, fileName, FileChanges, BlameTab, Diff.Encoding, force: force);
            }
            else if (tabControl1.SelectedTab == ViewTab)
            {
                var scrollPos = View.ScrollPos;

                View.Encoding = Diff.Encoding;
                View.ViewGitItemRevisionAsync(fileName, revision.ObjectId);
                View.ScrollPos = scrollPos;
            }
            else if (tabControl1.SelectedTab == DiffTab)
            {
                var file = new GitItemStatus
                {
                    IsTracked   = true,
                    Name        = fileName,
                    IsSubmodule = GitModule.IsValidGitWorkingDir(_fullPathResolver.Resolve(fileName))
                };
                Diff.ViewChangesAsync(FileChanges.GetSelectedRevisions(), file, "You need to select at least one revision to view diff.");
            }
            else if (tabControl1.SelectedTab == CommitInfoTabPage)
            {
                CommitDiff.SetRevision(revision.ObjectId, fileName);
            }

            if (_buildReportTabPageExtension == null)
            {
                _buildReportTabPageExtension = new BuildReportTabPageExtension(tabControl1, _buildReportTabCaption.Text);
            }

            _buildReportTabPageExtension.FillBuildReport(selectedRevisions.Count == 1 ? revision : null);
        }
        public void Visit(Commit commit, FileChanges fileChanges)
        {
            if (!String.IsNullOrEmpty(this.author) && !String.Equals(commit.Committer.Email, this.author, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            string commitDate = commit.Committer.When.DateTime.ToString("dd/MM/yy");
            categoryDates.Add(commitDate);

            Dictionary<string, long> lineCountByDate = null;
            string extension = Path.GetExtension(fileChanges.Path);
            if (!lineCountByExtension.TryGetValue(extension, out lineCountByDate))
            {
                lineCountByDate = new Dictionary<string, long>();
                lineCountByExtension[extension] = lineCountByDate;
            }

            if (!lineCountByDate.ContainsKey(commitDate))
            {
                lineCountByDate[commitDate] = 0;
            }

            lineCountByDate[commitDate] += fileChanges.LinesAdded - fileChanges.LinesDeleted;
            totalLineCount += fileChanges.LinesAdded - fileChanges.LinesDeleted;
        }
Esempio n. 28
0
 private void diffToolremotelocalStripMenuItem_Click(object sender, EventArgs e)
 {
     FileChanges.OpenWithDifftool(FileName, string.Empty, RevisionDiffKind.DiffBLocal);
 }
Esempio n. 29
0
        private void LoadFileHistory()
        {
            FileChanges.Visible = true;

            if (string.IsNullOrEmpty(FileName))
            {
                return;
            }

            _asyncLoader.LoadAsync(
                () => BuildFilter(),
                filter =>
            {
                FileChanges.SetFilters(filter);
                FileChanges.Load();
            });

            return;

            (string revision, string path) BuildFilter()
            {
                var fileName = FileName;

                // Replace windows path separator to Linux path separator.
                // This is needed to keep the file history working when started from file tree in
                // browse dialog.
                fileName = fileName.ToPosixPath();

                // we will need this later to look up proper casing for the file
                var fullFilePath = _fullPathResolver.Resolve(fileName);

                // The section below contains native windows (kernel32) calls
                // and breaks on Linux. Only use it on Windows. Casing is only
                // a Windows problem anyway.
                if (EnvUtils.RunningOnWindows() && File.Exists(fullFilePath))
                {
                    // grab the 8.3 file path
                    var shortPath = new StringBuilder(4096);
                    NativeMethods.GetShortPathName(fullFilePath, shortPath, shortPath.Capacity);

                    // use 8.3 file path to get properly cased full file path
                    var longPath = new StringBuilder(4096);
                    NativeMethods.GetLongPathName(shortPath.ToString(), longPath, longPath.Capacity);

                    // remove the working directory and now we have a properly cased file name.
                    fileName = longPath.ToString().Substring(Module.WorkingDir.Length).ToPosixPath();
                }

                if (fileName.StartsWith(Module.WorkingDir, StringComparison.InvariantCultureIgnoreCase))
                {
                    fileName = fileName.Substring(Module.WorkingDir.Length);
                }

                FileName = fileName;

                var res = (revision : (string)null, path : $" \"{fileName}\"");

                if (AppSettings.FollowRenamesInFileHistory && !Directory.Exists(fullFilePath))
                {
                    // git log --follow is not working as expected (see  http://kerneltrap.org/mailarchive/git/2009/1/30/4856404/thread)
                    //
                    // But we can take a more complicated path to get reasonable results:
                    //  1. use git log --follow to get all previous filenames of the file we are interested in
                    //  2. use git log "list of files names" to get the history graph
                    //
                    // note: This implementation is quite a quick hack (by someone who does not speak C# fluently).
                    //

                    var args = new GitArgumentBuilder("log")
                    {
                        "--format=\"%n\"",
                        "--name-only",
                        "--format",
                        GitCommandHelpers.FindRenamesAndCopiesOpts(),
                        "--",
                        fileName.Quote()
                    };

                    var listOfFileNames = new StringBuilder(fileName.Quote());

                    // keep a set of the file names already seen
                    var setOfFileNames = new HashSet <string> {
                        fileName
                    };

                    var lines = Module.GetGitOutputLines(args, GitModule.LosslessEncoding);

                    foreach (var line in lines.Select(GitModule.ReEncodeFileNameFromLossless))
                    {
                        if (!string.IsNullOrEmpty(line) && setOfFileNames.Add(line))
                        {
                            listOfFileNames.Append(" \"");
                            listOfFileNames.Append(line);
                            listOfFileNames.Append('\"');
                        }
                    }

                    // here we need --name-only to get the previous filenames in the revision graph
                    res.path      = listOfFileNames.ToString();
                    res.revision += " --name-only --parents" + GitCommandHelpers.FindRenamesAndCopiesOpts();
                }
                else if (AppSettings.FollowRenamesInFileHistory)
                {
                    // history of a directory
                    // --parents doesn't work with --follow enabled, but needed to graph a filtered log
                    res.revision = " " + GitCommandHelpers.FindRenamesOpt() + " --follow --parents";
                }
                else
                {
                    // rename following disabled
                    res.revision = " --parents";
                }

                if (AppSettings.FullHistoryInFileHistory)
                {
                    res.revision = string.Concat(" --full-history --simplify-merges ", res.revision);
                }

                return(res);
            }
        }
Esempio n. 30
0
        private void LoadFileHistory()
        {
            FileChanges.Visible = true;

            if (string.IsNullOrEmpty(FileName))
            {
                return;
            }

            _asyncLoader.LoadAsync(
                () => BuildFilter(),
                filter =>
            {
                FileChanges.SetFilters(filter);
                FileChanges.Load();
            });

            return;

            (string revision, string path) BuildFilter()
            {
                var fileName = FileName;

                // Replace windows path separator to Linux path separator.
                // This is needed to keep the file history working when started from file tree in
                // browse dialog.
                FileName = fileName.ToPosixPath();

                var res          = (revision : (string)null, path : $" \"{fileName}\"");
                var fullFilePath = _fullPathResolver.Resolve(fileName);

                if (AppSettings.FollowRenamesInFileHistory && !Directory.Exists(fullFilePath))
                {
                    // git log --follow is not working as expected (see  http://kerneltrap.org/mailarchive/git/2009/1/30/4856404/thread)
                    //
                    // But we can take a more complicated path to get reasonable results:
                    //  1. use git log --follow to get all previous filenames of the file we are interested in
                    //  2. use git log "list of files names" to get the history graph
                    //
                    // note: This implementation is quite a quick hack (by someone who does not speak C# fluently).
                    //

                    var args = new GitArgumentBuilder("log")
                    {
                        "--format=\"%n\"",
                        "--name-only",
                        "--follow",
                        GitCommandHelpers.FindRenamesAndCopiesOpts(),
                        "--",
                        fileName.Quote()
                    };

                    var listOfFileNames = new StringBuilder(fileName.Quote());

                    // keep a set of the file names already seen
                    var setOfFileNames = new HashSet <string> {
                        fileName
                    };

                    var lines = Module.GitExecutable.GetOutputLines(args, outputEncoding: GitModule.LosslessEncoding);

                    foreach (var line in lines.Select(GitModule.ReEncodeFileNameFromLossless))
                    {
                        if (!string.IsNullOrEmpty(line) && setOfFileNames.Add(line))
                        {
                            listOfFileNames.Append(" \"");
                            listOfFileNames.Append(line);
                            listOfFileNames.Append('\"');
                        }
                    }

                    // here we need --name-only to get the previous filenames in the revision graph
                    res.path      = listOfFileNames.ToString();
                    res.revision += " --name-only --parents" + GitCommandHelpers.FindRenamesAndCopiesOpts();
                }
                else if (AppSettings.FollowRenamesInFileHistory)
                {
                    // history of a directory
                    // --parents doesn't work with --follow enabled, but needed to graph a filtered log
                    res.revision = " " + GitCommandHelpers.FindRenamesOpt() + " --follow --parents";
                }
                else
                {
                    // rename following disabled
                    res.revision = " --parents";
                }

                if (AppSettings.FullHistoryInFileHistory)
                {
                    res.revision = string.Concat(" --full-history ", AppSettings.SimplifyMergesInFileHistory ? "--simplify-merges " : string.Empty, res.revision);
                }

                return(res);
            }
        }
Esempio n. 31
0
 private void FileChangesDoubleClick(object sender, EventArgs e)
 {
     FileChanges.ViewSelectedRevisions();
 }
Esempio n. 32
0
 public void Visit(Commit commit, FileChanges fileChanges)
 {
 }
Esempio n. 33
0
 private void diffToolRemoteLocalStripMenuItem_Click(object sender, EventArgs e)
 {
     UICommands.OpenWithDifftool(this, FileChanges.GetSelectedRevisions(), FileName, string.Empty, RevisionDiffKind.DiffBLocal, true);
 }
 public void Visit(Commit commit, FileChanges fileChanges)
 {
     GitComitterInfos[commit.Committer.Name].LinesAdded += fileChanges.LinesAdded;
     GitComitterInfos[commit.Committer.Name].LinesDeleted += fileChanges.LinesDeleted;
 }