Exemplo n.º 1
0
 public IEnumerable<GitExtLink> Parse(GitRevision revision)
 {
     return EffectiveLinkDefs.
         Where(linkDef => linkDef.Enabled).
         Select(linkDef => linkDef.Parse(revision)).
         Unwrap();
 }
Exemplo n.º 2
0
        public void LoadRevision(GitRevision revision)
        {
            _revision = revision;
            _revisionFileTreeController.ResetCache();

            try
            {
                tvGitTree.SuspendLayout();
                // Save state only when there is selected node
                if (tvGitTree.SelectedNode != null)
                {
                    var node = tvGitTree.SelectedNode;
                    FileText.SaveCurrentScrollPos();
                    _lastSelectedNodes.Clear();
                    while (node != null)
                    {
                        _lastSelectedNodes.Push(node.Text);
                        node = node.Parent;
                    }
                }

                // Refresh tree
                tvGitTree.Nodes.Clear();
                //restore selected file and scroll position when new selection is done
                if (_revision != null)
                {
                    _revisionFileTreeController.LoadChildren(_revision, tvGitTree.Nodes, tvGitTree.ImageList.Images);
                    //GitTree.Sort();
                    TreeNode lastMatchedNode = null;
                    // Load state
                    var      currenNodes = tvGitTree.Nodes;
                    TreeNode matchedNode = null;
                    while (_lastSelectedNodes.Count > 0 && currenNodes != null)
                    {
                        var next = _lastSelectedNodes.Pop();
                        foreach (TreeNode node in currenNodes)
                        {
                            if (node.Text != next && next.Length != 40)
                            {
                                continue;
                            }

                            node.Expand();
                            matchedNode = node;
                            break;
                        }
                        if (matchedNode == null)
                        {
                            currenNodes = null;
                        }
                        else
                        {
                            lastMatchedNode = matchedNode;
                            currenNodes     = matchedNode.Nodes;
                        }
                    }
                    //if there is no exact match, don't restore scroll position
                    if (lastMatchedNode != matchedNode)
                    {
                        FileText.ResetCurrentScrollPos();
                    }
                    tvGitTree.SelectedNode = lastMatchedNode;
                }
                if (tvGitTree.SelectedNode == null)
                {
                    FileText.ViewText("", "");
                }
            }
            finally
            {
                tvGitTree.ResumeLayout();
            }
        }
Exemplo n.º 3
0
        private void EnsureList()
        {
            if (RevisionResolver == null || GitOrigin == null)
                return;

            foreach (VisualGitRevisionType ri in new ArrayList(typeCombo.Items))
            {
                if (!ri.IsValidOn(GitOrigin))
                {
                    if (ri == _currentRevType)
                    {
                        _newValue = ri.CurrentValue;
                        _currentRevType = null;
                    }
                    typeCombo.Items.Remove(ri);
                }
            }

            if (_revTypes != null)
                foreach (VisualGitRevisionType rt in _revTypes)
                {
                    if (rt.IsValidOn(GitOrigin) && !typeCombo.Items.Contains(rt))
                        typeCombo.Items.Add(rt);
                }
            else
                _revTypes = new List<VisualGitRevisionType>();

            foreach (VisualGitRevisionType rt in RevisionResolver.GetRevisionTypes(GitOrigin))
            {
                if (_revTypes.Contains(rt))
                    continue;

                _revTypes.Add(rt);
                typeCombo.Items.Add(rt);
            }

            if (_currentRevType == null && _newValue != null && _newValue != GitRevision.None)
            {
                VisualGitRevisionType rt = RevisionResolver.Resolve(GitOrigin, _newValue);

                if (rt != null && !rt.IsValidOn(GitOrigin))
                {
                    _newValue = GitOrigin.Target.Revision;
                    if (_newValue == null || _newValue == GitRevision.None)
                        _newValue = GitRevision.Base;

                    rt = RevisionResolver.Resolve(GitOrigin, _newValue);
                }

                SetRevision(rt);
            }

            if (_currentRevType != typeCombo.SelectedItem)
                typeCombo.SelectedItem = _currentRevType;
        }
Exemplo n.º 4
0
        public static void BuildStatusImageColumnCellFormatting(DataGridViewCellFormattingEventArgs e, DataGridView grid, GitRevision revision)
        {
            e.FormattingApplied = false;
            var cell = grid.Rows[e.RowIndex].Cells[e.ColumnIndex];

            cell.ToolTipText = GetBuildStatusMessageText(revision);
        }
Exemplo n.º 5
0
                public SimpleRevisionType(GitRevision rev, string title)
                {
                    if (rev == null)
                        throw new ArgumentNullException("rev");
                    else if (string.IsNullOrEmpty(title))
                        throw new ArgumentNullException("title");

                    _rev = rev;
                    _title = title;
                }
Exemplo n.º 6
0
        public string GetTitle(GitTarget target, GitRevision revision)
        {
            if (target == null)
                throw new ArgumentNullException("target");
            if (revision == null)
                throw new ArgumentNullException("revision");

            return GetTitle(target.FileName, revision);
        }
Exemplo n.º 7
0
        string GetTempPath(string filename, GitRevision rev)
        {
            string name = GetName(filename, rev);
            string file;
            if (_lastDir == null || !Directory.Exists(_lastDir) || File.Exists(file = Path.Combine(_lastDir, name)))
            {
                _lastDir = GetService<IVisualGitTempDirManager>().GetTempDir();

                file = Path.Combine(_lastDir, name);
            }

            return file;
        }
Exemplo n.º 8
0
        private System.Drawing.Rectangle _headerResize; // Cache desired size for commit header

        private void ReloadCommitInfo()
        {
            _RevisionHeader.BackColor = ColorHelper.MakeColorDarker(BackColor);

            showContainedInBranchesToolStripMenuItem.Checked                = AppSettings.CommitInfoShowContainedInBranchesLocal;
            showContainedInBranchesRemoteToolStripMenuItem.Checked          = AppSettings.CommitInfoShowContainedInBranchesRemote;
            showContainedInBranchesRemoteIfNoLocalToolStripMenuItem.Checked = AppSettings.CommitInfoShowContainedInBranchesRemoteIfNoLocal;
            showContainedInTagsToolStripMenuItem.Checked         = AppSettings.CommitInfoShowContainedInTags;
            showMessagesOfAnnotatedTagsToolStripMenuItem.Checked = AppSettings.ShowAnnotatedTagsMessages;

            ResetTextAndImage();

            if (string.IsNullOrEmpty(_revision.Guid))
            {
                Debug.Assert(false, "Unexpectedly called ReloadCommitInfo() with empty revision");
                return;
            }

            _RevisionHeader.Text = string.Empty;
            _RevisionHeader.Refresh();
            string     error = "";
            CommitData data  = _commitDataManager.CreateFromRevision(_revision);

            if (_revision.Body == null)
            {
                _commitDataManager.UpdateCommitMessage(data, _revision.Guid, ref error);
                _revision.Body = data.Body;
            }

            ThreadPool.QueueUserWorkItem(_ => loadLinksForRevision(_revision));

            if (_sortedRefs == null)
            {
                ThreadPool.QueueUserWorkItem(_ => loadSortedRefs());
            }

            data.ChildrenGuids = _children;
            var header = _commitDataHeaderRenderer.Render(data, CommandClick != null);
            var body   = _commitDataBodyRenderer.Render(data, CommandClick != null);

            _RevisionHeader.SetXHTMLText(header);
            _RevisionHeader.Height = GetRevisionHeaderHeight();
            _revisionInfo          = body;

            UpdateRevisionInfo();
            LoadAuthorImage(data.Author ?? data.Committer);

            //No branch/tag data for artificial commands
            if (GitRevision.IsArtificial(_revision.Guid))
            {
                return;
            }

            if (AppSettings.CommitInfoShowContainedInBranches)
            {
                ThreadPool.QueueUserWorkItem(_ => loadBranchInfo(_revision.Guid));
            }

            if (AppSettings.ShowAnnotatedTagsMessages)
            {
                ThreadPool.QueueUserWorkItem(_ => loadAnnotatedTagInfo(_revision));
            }

            if (AppSettings.CommitInfoShowContainedInTags)
            {
                ThreadPool.QueueUserWorkItem(_ => loadTagInfo(_revision.Guid));
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// Checks if it is possible to reset to the revision.
 /// For artificial is Index is possible but not WorkTree or Combined
 /// </summary>
 /// <param name="rev">The GitRevision</param>
 /// <returns>If it is possible to reset to the revisions</returns>
 private bool CanResetToRevision(GitRevision rev)
 {
     return(rev.ObjectId != ObjectId.WorkTreeId &&
            rev.ObjectId != ObjectId.CombinedDiffId);
 }
Exemplo n.º 10
0
 public void SetDiffSelectedRevision(GitRevision revision)
 {
     checkboxRevisionFilter.Checked = revision != null;
     DiffSelectedRevision           = revision;
 }
Exemplo n.º 11
0
        public static (string arguments, bool abort) Parse(string arguments, IGitModule module, IWin32Window owner, RevisionGridControl revisionGrid)
        {
            GitRevision selectedRevision = null;
            GitRevision currentRevision  = null;

            IReadOnlyList <GitRevision> allSelectedRevisions = Array.Empty <GitRevision>();
            var selectedLocalBranches  = new List <IGitRef>();
            var selectedRemoteBranches = new List <IGitRef>();
            var selectedRemotes        = new List <string>();
            var selectedBranches       = new List <IGitRef>();
            var selectedTags           = new List <IGitRef>();
            var currentLocalBranches   = new List <IGitRef>();
            var currentRemoteBranches  = new List <IGitRef>();
            var currentRemote          = "";
            var currentBranches        = new List <IGitRef>();
            var currentTags            = new List <IGitRef>();

            foreach (string option in Options)
            {
                if (string.IsNullOrEmpty(arguments))
                {
                    continue;
                }

                if (!Contains(arguments, option))
                {
                    continue;
                }

                if (currentRevision == null && option.StartsWith("c"))
                {
                    currentRevision = GetCurrentRevision(module, revisionGrid, currentTags, currentLocalBranches, currentRemoteBranches, currentBranches);
                    if (currentRevision == null)
                    {
                        return(arguments : null, abort : true);
                    }

                    if (currentLocalBranches.Count == 1)
                    {
                        currentRemote = module.GetSetting(string.Format(SettingKeyString.BranchRemote, currentLocalBranches[0].Name));
                    }
                    else
                    {
                        currentRemote = module.GetCurrentRemote();
                        if (string.IsNullOrEmpty(currentRemote))
                        {
                            currentRemote = module.GetSetting(string.Format(SettingKeyString.BranchRemote,
                                                                            AskToSpecify(currentLocalBranches, revisionGrid)));
                        }
                    }
                }
                else if (selectedRevision == null && revisionGrid != null && DependsOnSelectedRevision(option))
                {
                    allSelectedRevisions = revisionGrid.GetSelectedRevisions();
                    selectedRevision     = CalculateSelectedRevision(revisionGrid, selectedRemoteBranches, selectedRemotes, selectedLocalBranches, selectedBranches, selectedTags);
                    if (selectedRevision == null)
                    {
                        return(arguments : null, abort : true);
                    }
                }

                arguments = ParseScriptArguments(arguments, option, owner, revisionGrid, module, allSelectedRevisions, selectedTags, selectedBranches, selectedLocalBranches, selectedRemoteBranches, selectedRemotes, selectedRevision, currentTags, currentBranches, currentLocalBranches, currentRemoteBranches, currentRevision, currentRemote);
                if (arguments == null)
                {
                    return(arguments : null, abort : true);
                }
            }

            return(arguments, abort : false);
        }
Exemplo n.º 12
0
        internal static bool RunScript(IWin32Window owner, GitModule aModule, ScriptInfo scriptInfo, RevisionGrid revisionGrid)
        {
            string originalCommand = scriptInfo.Command;
            string argument        = scriptInfo.Arguments;

            string command = OverrideCommandWhenNecessary(originalCommand);

            GitRevision selectedRevision = null;
            GitRevision currentRevision  = null;

            var selectedLocalBranches  = new List <GitRef>();
            var selectedRemoteBranches = new List <GitRef>();
            var selectedRemotes        = new List <string>();
            var selectedBranches       = new List <GitRef>();
            var selectedTags           = new List <GitRef>();
            var currentLocalBranches   = new List <GitRef>();
            var currentRemoteBranches  = new List <GitRef>();
            var currentRemote          = "";
            var currentBranches        = new List <GitRef>();
            var currentTags            = new List <GitRef>();

            foreach (string option in Options)
            {
                if (string.IsNullOrEmpty(argument) || !argument.Contains(option))
                {
                    continue;
                }
                if (option.StartsWith("{c") || selectedRevision != null)
                {
                    currentRevision = GetCurrentRevision(aModule, revisionGrid, currentTags, currentLocalBranches, currentRemoteBranches, currentBranches, currentRevision, option);

                    if (currentLocalBranches.Count == 1)
                    {
                        currentRemote = aModule.GetSetting(string.Format("branch.{0}.remote", currentLocalBranches[0].Name));
                    }
                    else
                    {
                        currentRemote = aModule.GetCurrentRemote();
                        if (string.IsNullOrEmpty(currentRemote))
                        {
                            currentRemote = aModule.GetSetting(string.Format("branch.{0}.remote",
                                                                             askToSpecify(currentLocalBranches, "Current Revision Branch")));
                        }
                    }
                }
                else if (revisionGrid != null)
                {
                    selectedRevision = CalculateSelectedRevision(revisionGrid, selectedRemoteBranches, selectedRemotes, selectedLocalBranches, selectedBranches, selectedTags);
                }

                string remote;
                string url;
                switch (option)
                {
                case "{sTag}":
                    if (selectedTags.Count == 1)
                    {
                        argument = argument.Replace(option, selectedTags[0].Name);
                    }
                    else if (selectedTags.Count != 0)
                    {
                        argument = argument.Replace(option, askToSpecify(selectedTags, "Selected Revision Tag"));
                    }
                    else
                    {
                        argument = argument.Replace(option, "");
                    }
                    break;

                case "{sBranch}":
                    if (selectedBranches.Count == 1)
                    {
                        argument = argument.Replace(option, selectedBranches[0].Name);
                    }
                    else if (selectedBranches.Count != 0)
                    {
                        argument = argument.Replace(option,
                                                    askToSpecify(selectedBranches, "Selected Revision Branch"));
                    }
                    else
                    {
                        argument = argument.Replace(option, "");
                    }
                    break;

                case "{sLocalBranch}":
                    if (selectedLocalBranches.Count == 1)
                    {
                        argument = argument.Replace(option, selectedLocalBranches[0].Name);
                    }
                    else if (selectedLocalBranches.Count != 0)
                    {
                        argument = argument.Replace(option,
                                                    askToSpecify(selectedLocalBranches,
                                                                 "Selected Revision Local Branch"));
                    }
                    else
                    {
                        argument = argument.Replace(option, "");
                    }
                    break;

                case "{sRemoteBranch}":
                    if (selectedRemoteBranches.Count == 1)
                    {
                        argument = argument.Replace(option, selectedRemoteBranches[0].Name);
                    }
                    else if (selectedRemoteBranches.Count != 0)
                    {
                        argument = argument.Replace(option,
                                                    askToSpecify(selectedRemoteBranches,
                                                                 "Selected Revision Remote Branch"));
                    }
                    else
                    {
                        argument = argument.Replace(option, "");
                    }
                    break;

                case "{sRemote}":
                    if (selectedRemotes.Count == 0)
                    {
                        argument = argument.Replace(option, "");
                        break;
                    }
                    if (selectedRemotes.Count == 1)
                    {
                        remote = selectedRemotes[0];
                    }
                    else
                    {
                        remote = askToSpecify(selectedRemotes, "Selected Revision Remote");
                    }
                    argument = argument.Replace(option, remote);
                    break;

                case "{sRemoteUrl}":
                    if (selectedRemotes.Count == 0)
                    {
                        argument = argument.Replace(option, "");
                        break;
                    }
                    if (selectedRemotes.Count == 1)
                    {
                        remote = selectedRemotes[0];
                    }
                    else
                    {
                        remote = askToSpecify(selectedRemotes, "Selected Revision Remote");
                    }
                    url      = aModule.GetPathSetting(string.Format(SettingKeyString.RemoteUrl, remote));
                    argument = argument.Replace(option, url);
                    break;

                case "{sRemotePathFromUrl}":
                    if (selectedRemotes.Count == 0)
                    {
                        argument = argument.Replace(option, "");
                        break;
                    }
                    if (selectedRemotes.Count == 1)
                    {
                        remote = selectedRemotes[0];
                    }
                    else
                    {
                        remote = askToSpecify(selectedRemotes, "Selected Revision Remote");
                    }
                    url      = aModule.GetPathSetting(string.Format(SettingKeyString.RemoteUrl, remote));
                    argument = argument.Replace(option, GetRemotePath(url));
                    break;

                case "{sHash}":
                    argument = argument.Replace(option, selectedRevision.Guid);
                    break;

                case "{sMessage}":
                    argument = argument.Replace(option, selectedRevision.Message);
                    break;

                case "{sAuthor}":
                    argument = argument.Replace(option, selectedRevision.Author);
                    break;

                case "{sCommitter}":
                    argument = argument.Replace(option, selectedRevision.Committer);
                    break;

                case "{sAuthorDate}":
                    argument = argument.Replace(option, selectedRevision.AuthorDate.ToString());
                    break;

                case "{sCommitDate}":
                    argument = argument.Replace(option, selectedRevision.CommitDate.ToString());
                    break;

                case "{cTag}":
                    if (currentTags.Count == 1)
                    {
                        argument = argument.Replace(option, currentTags[0].Name);
                    }
                    else if (currentTags.Count != 0)
                    {
                        argument = argument.Replace(option, askToSpecify(currentTags, "Current Revision Tag"));
                    }
                    else
                    {
                        argument = argument.Replace(option, "");
                    }
                    break;

                case "{cBranch}":
                    if (currentBranches.Count == 1)
                    {
                        argument = argument.Replace(option, currentBranches[0].Name);
                    }
                    else if (currentBranches.Count != 0)
                    {
                        argument = argument.Replace(option,
                                                    askToSpecify(currentBranches, "Current Revision Branch"));
                    }
                    else
                    {
                        argument = argument.Replace(option, "");
                    }
                    break;

                case "{cLocalBranch}":
                    if (currentLocalBranches.Count == 1)
                    {
                        argument = argument.Replace(option, currentLocalBranches[0].Name);
                    }
                    else if (currentLocalBranches.Count != 0)
                    {
                        argument = argument.Replace(option,
                                                    askToSpecify(currentLocalBranches,
                                                                 "Current Revision Local Branch"));
                    }
                    else
                    {
                        argument = argument.Replace(option, "");
                    }
                    break;

                case "{cRemoteBranch}":
                    if (currentRemoteBranches.Count == 1)
                    {
                        argument = argument.Replace(option, currentRemoteBranches[0].Name);
                    }
                    else if (currentRemoteBranches.Count != 0)
                    {
                        argument = argument.Replace(option,
                                                    askToSpecify(currentRemoteBranches,
                                                                 "Current Revision Remote Branch"));
                    }
                    else
                    {
                        argument = argument.Replace(option, "");
                    }
                    break;

                case "{cHash}":
                    argument = argument.Replace(option, currentRevision.Guid);
                    break;

                case "{cMessage}":
                    argument = argument.Replace(option, currentRevision.Message);
                    break;

                case "{cAuthor}":
                    argument = argument.Replace(option, currentRevision.Author);
                    break;

                case "{cCommitter}":
                    argument = argument.Replace(option, currentRevision.Committer);
                    break;

                case "{cAuthorDate}":
                    argument = argument.Replace(option, currentRevision.AuthorDate.ToString());
                    break;

                case "{cCommitDate}":
                    argument = argument.Replace(option, currentRevision.CommitDate.ToString());
                    break;

                case "{cDefaultRemote}":
                    if (string.IsNullOrEmpty(currentRemote))
                    {
                        argument = argument.Replace(option, "");
                        break;
                    }
                    argument = argument.Replace(option, currentRemote);
                    break;

                case "{cDefaultRemoteUrl}":
                    if (string.IsNullOrEmpty(currentRemote))
                    {
                        argument = argument.Replace(option, "");
                        break;
                    }
                    url      = aModule.GetPathSetting(string.Format(SettingKeyString.RemoteUrl, currentRemote));
                    argument = argument.Replace(option, url);
                    break;

                case "{cDefaultRemotePathFromUrl}":
                    if (string.IsNullOrEmpty(currentRemote))
                    {
                        argument = argument.Replace(option, "");
                        break;
                    }
                    url      = aModule.GetPathSetting(string.Format(SettingKeyString.RemoteUrl, currentRemote));
                    argument = argument.Replace(option, GetRemotePath(url));
                    break;

                case "{UserInput}":
                    using (SimplePrompt Prompt = new SimplePrompt())
                    {
                        Prompt.ShowDialog();
                        argument = argument.Replace(option, Prompt.UserInput);
                    }
                    break;
                }
            }

            if (!scriptInfo.RunInBackground)
            {
                FormProcess.ShowDialog(owner, command, argument, aModule.WorkingDir, null, true);
            }
            else
            {
                if (originalCommand.Equals("{openurl}", StringComparison.CurrentCultureIgnoreCase))
                {
                    Process.Start(argument);
                }
                else
                {
                    aModule.RunExternalCmdDetached(command, argument);
                }
            }
            return(!scriptInfo.RunInBackground);
        }
Exemplo n.º 13
0
 public FormDiff(GitUICommands aCommands, GitRevision revision)
     : this(aCommands)
 {
     RevisionGrid.SetSelectedRevision(revision);
 }
Exemplo n.º 14
0
 public static void BuildStatusMessageCellFormatting(DataGridViewCellFormattingEventArgs e, GitRevision revision)
 {
     e.Value = GetBuildStatusMessageText(revision);
 }
Exemplo n.º 15
0
        private void MergeDialog_Load(object sender, EventArgs e)
        {
            strategyBox.Image = Properties.Resources.MergeGraph;

            foreach (var strategy in MergeStrategy.All)
            {
                mergeStrategyBox.Items.Add(strategy);
            }

            mergeStrategyBox.SelectedIndex = 0;

            using (var client = Context.GetService<IGitClientPool>().GetNoUIClient())
            {
                currentBranchBox.Text = client.GetCurrentBranch(RepositoryPath).ShortName;

                localBranchBox.BeginUpdate();
                localBranchBox.Items.Clear();
                trackingBranchBox.BeginUpdate();
                trackingBranchBox.Items.Clear();
                tagBox.BeginUpdate();
                tagBox.Items.Clear();

                // When a revision ref was provided, try to resolve it to a branch,
                // tag or remote branch.

                bool resolved = Revision == null;

                GitRef resolvedRef = null;

                foreach (var @ref in client.GetRefs(RepositoryPath))
                {
                    bool setCurrent = false;

                    if (
                        !resolved &&
                        String.Equals(Revision.Revision, @ref.Revision, StringComparison.OrdinalIgnoreCase)
                    )
                    {
                        resolvedRef = @ref;
                        resolved = true;
                        setCurrent = true;
                    }

                    switch (@ref.Type)
                    {
                        case GitRefType.Branch:
                            localBranchBox.Items.Add(@ref);
                            if (setCurrent)
                            {
                                localBranchRadioBox.Checked = true;
                                localBranchBox.SelectedIndex = localBranchBox.Items.Count - 1;
                            }
                            break;

                        case GitRefType.RemoteBranch:
                            trackingBranchBox.Items.Add(@ref);
                            if (setCurrent)
                            {
                                trackingBranchRadioBox.Checked = true;
                                trackingBranchBox.SelectedIndex = trackingBranchBox.Items.Count - 1;
                            }
                            break;

                        case GitRefType.Tag:
                            tagBox.Items.Add(@ref);
                            if (setCurrent)
                            {
                                tagRadioBox.Checked = true;
                                tagBox.SelectedIndex = tagBox.Items.Count - 1;
                            }
                            break;
                    }
                }

                if (resolvedRef != null)
                    Revision = resolvedRef;

                localBranchBox.EndUpdate();
                trackingBranchBox.EndUpdate();
                tagBox.EndUpdate();

                UpdateEnabled();
            }
        }
Exemplo n.º 16
0
 public FormLog(GitUICommands commands, GitRevision revision)
     : this(commands)
 {
     RevisionGrid.SetSelectedRevision(revision);
 }
Exemplo n.º 17
0
        public string GetTempFile(GitTarget target, GitRevision revision, bool withProgress)
        {
            if (target == null)
                throw new ArgumentNullException("target");
            else if (revision == null)
                throw new ArgumentNullException("revision");

            string file = GetTempPath(target.FileName, revision);
            bool unrelated = false;

            ProgressRunnerResult r = GetService<IProgressRunner>().RunModal("Getting file",
                delegate(object sender, ProgressWorkerArgs aa)
                {
                    GitWriteArgs wa = new GitWriteArgs();
                    wa.Revision = revision;

                    using (Stream s = File.Create(file))
                        aa.Client.Write(target, s, wa);
                });

            if (!r.Succeeded || unrelated)
                return null; // User canceled

            if (File.Exists(file))
                File.SetAttributes(file, FileAttributes.ReadOnly); // A readonly file does not allow editting from many diff tools

            return file;
        }
Exemplo n.º 18
0
 static string GetParentRef(GitRevision revision)
 {
     return(revision.FirstParentId?.ToString() ?? revision.Guid + '^');
 }
Exemplo n.º 19
0
 static string PathSafeRevision(GitRevision revision)
 {
     if (revision.RevisionType == GitRevisionType.Time)
         return revision.Time.ToLocalTime().ToString("yyyyMMdd_hhmmss");
     return revision.ToString();
 }
        public void FillBuildReport(GitRevision revision)
        {
            if (EnvUtils.IsMonoRuntime())
            {
                return;
            }

            if (selectedGitRevision != null)
            {
                selectedGitRevision.PropertyChanged -= RevisionPropertyChanged;
            }
            selectedGitRevision = revision;
            if (selectedGitRevision != null)
            {
                selectedGitRevision.PropertyChanged += RevisionPropertyChanged;
            }

            var buildInfoIsAvailable =
                !(revision == null || revision.BuildStatus == null || string.IsNullOrEmpty(revision.BuildStatus.Url));

            tabControl.SuspendLayout();

            try
            {
                if (buildInfoIsAvailable)
                {
                    if (buildReportTabPage == null)
                    {
                        CreateBuildReportTabPage(tabControl);
                    }

                    var isFavIconMissing = buildReportTabPage.ImageIndex < 0;

                    if (isFavIconMissing || tabControl.SelectedTab == buildReportTabPage)
                    {
                        buildReportWebBrowser.Navigate(revision.BuildStatus.Url);

                        if (isFavIconMissing)
                        {
                            buildReportWebBrowser.Navigated += BuildReportWebBrowserOnNavigated;
                        }
                    }

                    if (!tabControl.Controls.Contains(buildReportTabPage))
                    {
                        tabControl.Controls.Add(buildReportTabPage);
                    }
                }
                else
                {
                    if (buildReportTabPage != null && tabControl.Controls.Contains(buildReportTabPage))
                    {
                        buildReportWebBrowser.Stop();
                        buildReportWebBrowser.Document.Write(string.Empty);
                        tabControl.Controls.Remove(buildReportTabPage);
                    }
                }
            }
            finally
            {
                tabControl.ResumeLayout();
            }
        }
Exemplo n.º 21
0
        public bool EvaluateCheckable(GitItem item, GitRevision from, GitRevision to)
        {
            if (_checkableFilter == null)
                return true;

            foreach (SelectableFilter i in _checkableFilter.GetInvocationList())
            {
                if (!i(item, from, to))
                    return false;
            }
            return true;
        }
Exemplo n.º 22
0
 public void SetRevisionWithChildren(GitRevision revision, List <string> children)
 {
     _revision = revision;
     _children = children;
     ReloadCommitInfo();
 }
Exemplo n.º 23
0
        public void StartLog(GitOrigin target, GitRevision start, GitRevision end)
        {
            if (target == null)
                throw new ArgumentNullException("target");

            StartLog(new GitOrigin[] { target }, start, end);
        }
Exemplo n.º 24
0
 private void loadAnnotatedTagInfo(GitRevision revision)
 {
     _annotatedTagsMessages = GetAnnotatedTagsMessages(revision);
     this.InvokeAsync(UpdateRevisionInfo);
 }
Exemplo n.º 25
0
        public IEnumerable<GitExtLink> ParsePart(string part, GitRevision revision)
        {
            if (SearchPattern.IsNullOrEmpty() || SearchPatternRegex.Value == null)
                yield break;

            IList<Match> allMatches = new List<Match>();

            MatchCollection matches = SearchPatternRegex.Value.Matches(part);
            for (var i = 0; i < matches.Count; i++)
            {
                var match = matches[i];
                if (NestedSearchPattern.IsNullOrEmpty())
                {
                    allMatches.Add(match);
                }
                else if (NestedSearchPatternRegex.Value != null)
                {
                    MatchCollection nestedMatches = NestedSearchPatternRegex.Value.Matches(match.Value);

                    for (var n = 0; n < nestedMatches.Count; n++)
                    {
                        allMatches.Add(nestedMatches[n]);
                    }
                }
            }
            
            foreach (var match in allMatches.Where(m => m.Success))
            {
                foreach (var format in LinkFormats)
                {
                    yield return format.ToGitExtLink(match, revision);
                }
            }
        }
        public void FillBuildReport(GitRevision revision)
        {
            if (_selectedGitRevision != null)
            {
                _selectedGitRevision.PropertyChanged -= RevisionPropertyChanged;
            }

            _selectedGitRevision = revision;

            if (_selectedGitRevision != null)
            {
                _selectedGitRevision.PropertyChanged += RevisionPropertyChanged;
            }

            _tabControl.SuspendLayout();

            try
            {
                var buildInfoIsAvailable = !string.IsNullOrEmpty(revision?.BuildStatus?.Url);

                if (buildInfoIsAvailable)
                {
                    if (_buildReportTabPage == null)
                    {
                        CreateBuildReportTabPage(_tabControl);
                    }

                    var isFavIconMissing = _buildReportTabPage.ImageIndex < 0;

                    if (isFavIconMissing || _tabControl.SelectedTab == _buildReportTabPage)
                    {
                        try
                        {
                            if (revision.BuildStatus.ShowInBuildReportTab)
                            {
                                _url = null;
                                _buildReportWebBrowser.Navigate(revision.BuildStatus.Url);
                            }
                            else
                            {
                                _url = revision.BuildStatus.Url;
                                _buildReportWebBrowser.Navigate("about:blank");
                            }

                            if (isFavIconMissing)
                            {
                                _buildReportWebBrowser.Navigated += BuildReportWebBrowserOnNavigated;
                            }
                        }
                        catch
                        {
                            // No propagation to the user if the report fails
                        }
                    }

                    if (!_tabControl.Controls.Contains(_buildReportTabPage))
                    {
                        _tabControl.Controls.Add(_buildReportTabPage);
                    }
                }
                else
                {
                    if (_buildReportTabPage != null && _tabControl.Controls.Contains(_buildReportTabPage))
                    {
                        _buildReportWebBrowser.Stop();
                        _buildReportWebBrowser.Document.Write(string.Empty);
                        _tabControl.Controls.Remove(_buildReportTabPage);
                    }
                }
            }
            finally
            {
                _tabControl.ResumeLayout();
            }
        }
Exemplo n.º 27
0
 public DoubleClickRevisionEventArgs(GitRevision revision)
 {
     Revision = revision;
 }
Exemplo n.º 28
0
        private DialogResult OkClick()
        {
            // Ok button set as the "AcceptButton" for the form
            // if the user hits [Enter] at any point, we need to trigger txtCustomBranchName Leave event
            Ok.Focus();

            GitCheckoutBranchCmd cmd = new GitCheckoutBranchCmd(Branches.Text.Trim(), Remotebranch.Checked);

            if (Remotebranch.Checked)
            {
                if (rbCreateBranchWithCustomName.Checked)
                {
                    cmd.NewBranchName   = txtCustomBranchName.Text.Trim();
                    cmd.NewBranchAction = GitCheckoutBranchCmd.NewBranch.Create;
                    if (cmd.NewBranchName.IsNullOrWhiteSpace())
                    {
                        MessageBox.Show(_customBranchNameIsEmpty.Text, Text);
                        DialogResult = DialogResult.None;
                        return(DialogResult.None);
                    }
                    if (!Module.CheckBranchFormat(cmd.NewBranchName))
                    {
                        MessageBox.Show(string.Format(_customBranchNameIsNotValid.Text, cmd.NewBranchName), Text);
                        DialogResult = DialogResult.None;
                        return(DialogResult.None);
                    }
                }
                else if (rbResetBranch.Checked)
                {
                    IGitRef localBranchRef  = GetLocalBranchRef(_localBranchName);
                    IGitRef remoteBranchRef = GetRemoteBranchRef(cmd.BranchName);
                    if (localBranchRef != null && remoteBranchRef != null)
                    {
                        string mergeBaseGuid      = Module.GetMergeBase(localBranchRef.Guid, remoteBranchRef.Guid);
                        bool   isResetFastForward = localBranchRef.Guid.Equals(mergeBaseGuid);
                        if (!isResetFastForward)
                        {
                            string mergeBaseText = mergeBaseGuid.IsNullOrWhiteSpace()
                                ? "merge base"
                                : GitRevision.ToShortSha(mergeBaseGuid);

                            string warningMessage = string.Format(_resetNonFastForwardBranch.Text, _localBranchName, mergeBaseText);
                            if (MessageBox.Show(this, warningMessage, resetCaption.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No)
                            {
                                DialogResult = DialogResult.None;
                                return(DialogResult.None);
                            }
                        }
                    }
                    cmd.NewBranchAction = GitCheckoutBranchCmd.NewBranch.Reset;
                    cmd.NewBranchName   = _localBranchName;
                }
                else
                {
                    cmd.NewBranchAction = GitCheckoutBranchCmd.NewBranch.DontCreate;
                    cmd.NewBranchName   = null;
                }
            }

            LocalChangesAction changes = ChangesMode;

            if (changes != LocalChangesAction.Reset &&
                chkSetLocalChangesActionAsDefault.Checked)
            {
                AppSettings.CheckoutBranchAction = changes;
            }

            if ((Visible || AppSettings.UseDefaultCheckoutBranchAction) && IsThereUncommittedChanges())
            {
                cmd.LocalChanges = changes;
            }
            else
            {
                cmd.LocalChanges = LocalChangesAction.DontChange;
            }

            IWin32Window owner = Visible ? this : Owner;

            bool stash = false;

            if (changes == LocalChangesAction.Stash)
            {
                if (_isDirtyDir == null && Visible)
                {
                    _isDirtyDir = Module.IsDirtyDir();
                }
                stash = _isDirtyDir == true;
                if (stash)
                {
                    UICommands.StashSave(owner, AppSettings.IncludeUntrackedFilesInAutoStash);
                }
            }

            ScriptManager.RunEventScripts(this, ScriptEvent.BeforeCheckout);

            if (UICommands.StartCommandLineProcessDialog(cmd, owner))
            {
                if (stash)
                {
                    bool?messageBoxResult = AppSettings.AutoPopStashAfterCheckoutBranch;
                    if (messageBoxResult == null)
                    {
                        DialogResult res = PSTaskDialog.cTaskDialog.MessageBox(
                            this,
                            _applyShashedItemsAgainCaption.Text,
                            "",
                            _applyShashedItemsAgain.Text,
                            "",
                            "",
                            _dontShowAgain.Text,
                            PSTaskDialog.eTaskDialogButtons.YesNo,
                            PSTaskDialog.eSysIcons.Question,
                            PSTaskDialog.eSysIcons.Question);
                        messageBoxResult = (res == DialogResult.Yes);
                        if (PSTaskDialog.cTaskDialog.VerificationChecked)
                        {
                            AppSettings.AutoPopStashAfterCheckoutBranch = messageBoxResult;
                        }
                    }
                    if (messageBoxResult ?? false)
                    {
                        UICommands.StashPop(this);
                    }
                }

                UICommands.UpdateSubmodules(this);

                ScriptManager.RunEventScripts(this, ScriptEvent.AfterCheckout);

                return(DialogResult.OK);
            }

            return(DialogResult.None);
        }
Exemplo n.º 29
0
        public static void OpenWithDifftool(this RevisionGrid grid, string fileName, string oldFileName, DiffWithRevisionKind diffKind, string parentGuid)
        {
            IList <GitRevision> revisions = grid.GetSelectedRevisions();

            if (revisions.Count == 0 || revisions.Count > 2)
            {
                return;
            }

            string output;

            if (diffKind == DiffWithRevisionKind.DiffAB)
            {
                string firstRevision  = revisions[0].Guid;
                var    secondRevision = revisions.Count == 2 ? revisions[1].Guid : null;

                //to simplify if-ology
                if (GitRevision.IsArtificial(secondRevision) && firstRevision != GitRevision.UnstagedGuid)
                {
                    firstRevision  = secondRevision;
                    secondRevision = revisions[0].Guid;
                }

                string extraDiffArgs = "-M -C";

                if (GitRevision.IsArtificial(firstRevision))
                {
                    bool staged = firstRevision == GitRevision.IndexGuid;
                    if (secondRevision == null || secondRevision == GitRevision.IndexGuid)
                    {
                        firstRevision = string.Empty;
                    }
                    else
                    {
                        firstRevision = secondRevision;
                    }
                    secondRevision = string.Empty;
                    if (staged) //rev1 vs index
                    {
                        extraDiffArgs = string.Join(" ", extraDiffArgs, "--cached");
                    }
                }
                else if (secondRevision == null)
                {
                    secondRevision = parentGuid ?? firstRevision + "^";
                }

                output = grid.Module.OpenWithDifftool(fileName, oldFileName, firstRevision, secondRevision, extraDiffArgs);
            }
            else
            {
                string revisionToCmp;
                if (revisions.Count == 1)
                {
                    GitRevision revision = revisions[0];
                    if (diffKind == DiffWithRevisionKind.DiffALocal)
                    {
                        revisionToCmp = parentGuid ?? revision.FirstParentGuid;
                    }
                    else if (diffKind == DiffWithRevisionKind.DiffBLocal)
                    {
                        revisionToCmp = revision.Guid;
                    }
                    else
                    {
                        revisionToCmp = null;
                    }
                }
                else
                {
                    switch (diffKind)
                    {
                    case DiffWithRevisionKind.DiffALocal:
                        revisionToCmp = revisions[1].Guid;
                        break;

                    case DiffWithRevisionKind.DiffBLocal:
                        revisionToCmp = revisions[0].Guid;
                        break;

                    case DiffWithRevisionKind.DiffAParentLocal:
                        revisionToCmp = revisions[1].FirstParentGuid;
                        break;

                    case DiffWithRevisionKind.DiffBParentLocal:
                        revisionToCmp = revisions[0].FirstParentGuid;
                        break;

                    default:
                        revisionToCmp = null;
                        break;
                    }
                }

                if (revisionToCmp == null)
                {
                    return;
                }

                output = grid.Module.OpenWithDifftool(fileName, null, revisionToCmp);
            }

            if (!string.IsNullOrEmpty(output))
            {
                MessageBox.Show(grid, output);
            }
        }
Exemplo n.º 30
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)
            {
                View.Encoding = Diff.Encoding;
                View.ViewGitItemRevisionAsync(fileName, revision.ObjectId);
            }
            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(() => Module, tabControl1, _buildReportTabCaption.Text);
            }

            _buildReportTabPageExtension.FillBuildReport(selectedRevisions.Count == 1 ? revision : null);
        }
Exemplo n.º 31
0
        static void PerformLog(IVisualGitServiceProvider context, ICollection<GitOrigin> targets, GitRevision start, GitRevision end)
        {
            IVisualGitPackage package = context.GetService<IVisualGitPackage>();

            package.ShowToolWindow(VisualGitToolWindow.Log);

            LogToolWindowControl logToolControl = context.GetService<ISelectionContext>().ActiveFrameControl as LogToolWindowControl;
            if (logToolControl != null)
                logToolControl.StartLog(targets, start, end);
        }
Exemplo n.º 32
0
        private void resetFileToToolStripMenuItem_DropDownOpening(object sender, EventArgs e)
        {
            IList <GitRevision> revisions = _revisionGrid.GetSelectedRevisions();
            int selectedRevsCount         = revisions.Count;

            if (selectedRevsCount == 1)
            {
                if (revisions[0].Guid == GitRevision.UnstagedGuid)
                {
                    resetFileToSelectedToolStripMenuItem.Visible = false;
                }
                else
                {
                    resetFileToSelectedToolStripMenuItem.Visible = true;
                    TranslateItem(resetFileToSelectedToolStripMenuItem.Name, resetFileToSelectedToolStripMenuItem);
                    resetFileToSelectedToolStripMenuItem.Text += " (" + _revisionGrid.DescribeRevision(revisions[0], 50) + ")";
                }

                if (revisions[0].HasParent)
                {
                    resetFileToParentToolStripMenuItem.Visible = true;
                    TranslateItem(resetFileToParentToolStripMenuItem.Name, resetFileToParentToolStripMenuItem);
                    GitRevision parentRev = _revisionGrid.GetRevision(revisions[0].FirstParentGuid);
                    if (parentRev != null)
                    {
                        resetFileToParentToolStripMenuItem.Text += " (" + _revisionGrid.DescribeRevision(parentRev, 50) + ")";
                    }
                }
                else
                {
                    resetFileToParentToolStripMenuItem.Visible = false;
                }
            }
            else
            {
                resetFileToSelectedToolStripMenuItem.Visible = false;
                resetFileToParentToolStripMenuItem.Visible   = false;
            }

            if (selectedRevsCount == 2)
            {
                if (revisions[1].Guid == GitRevision.UnstagedGuid)
                {
                    resetFileToFirstToolStripMenuItem.Visible = false;
                }
                else
                {
                    resetFileToFirstToolStripMenuItem.Visible = true;
                    TranslateItem(resetFileToFirstToolStripMenuItem.Name, resetFileToFirstToolStripMenuItem);
                    resetFileToFirstToolStripMenuItem.Text += " (" + _revisionGrid.DescribeRevision(revisions[1], 50) + ")";
                }

                if (revisions[0].Guid == GitRevision.UnstagedGuid)
                {
                    resetFileToSecondToolStripMenuItem.Visible = false;
                }
                else
                {
                    resetFileToSecondToolStripMenuItem.Visible = true;
                    TranslateItem(resetFileToSecondToolStripMenuItem.Name, resetFileToSecondToolStripMenuItem);
                    resetFileToSecondToolStripMenuItem.Text += " (" + _revisionGrid.DescribeRevision(revisions[0], 50) + ")";
                }
            }
            else
            {
                resetFileToFirstToolStripMenuItem.Visible  = false;
                resetFileToSecondToolStripMenuItem.Visible = false;
            }
        }
Exemplo n.º 33
0
 public GitRevisionRange(GitRevision start, GitRevision end)
 {
     StartRevision = start;
     EndRevision = end;
 }
Exemplo n.º 34
0
 private void PickAnotherBranch(GitRevision preSelectCommit, ref string displayStr, ref GitRevision revision)
 {
     using (var form = new FormCompareToBranch(UICommands, preSelectCommit.Guid))
     {
         if (form.ShowDialog(this) == DialogResult.OK)
         {
             displayStr = form.BranchName;
             revision   = new GitRevision(Module, Module.RevParse(form.BranchName));
             PopulateDiffFiles();
         }
     }
 }
Exemplo n.º 35
0
        public string[] GetTempFiles(GitTarget target, GitRevision from, GitRevision to, bool withProgress)
        {
            if (target == null)
                throw new ArgumentNullException("target");
            else if (from == null)
                throw new ArgumentNullException("from");
            else if (to == null)
                throw new ArgumentNullException("to");

            string f1 = GetTempFile(target, from, withProgress);
            if (f1 == null)
                return null; // Canceled
            string f2 = GetTempFile(target, to, withProgress);

            if (string.IsNullOrEmpty(f1) || string.IsNullOrEmpty(f2))
                return null;

            string[] files = new string[] { f1, f2 };

            foreach (string f in files)
            {
                if (File.Exists(f))
                    File.SetAttributes(f, FileAttributes.ReadOnly);
            }

            return files;
        }
Exemplo n.º 36
0
            public void Add(string aId, string[] aParentIds, DataType aType, GitRevision aData)
            {
                // If we haven't seen this node yet, create a new junction.
                Node node;

                if (!GetNode(aId, out node) && (aParentIds == null || aParentIds.Length == 0))
                {
                    var newJunction = new Junction(node, node);
                    junctions.Add(newJunction);
                }
                nodeCount++;
                node.Data     = aData;
                node.DataType = aType;
                node.Index    = AddedNodes.Count;
                AddedNodes.Add(node);

                foreach (string parentId in aParentIds)
                {
                    Node parent;
                    GetNode(parentId, out parent);
                    if (parent.Index < node.Index)
                    {
                        // TODO: We might be able to recover from this with some work, but
                        // since we build the graph async it might be tough to figure out.
                        Debug.WriteLine("The nodes must be added such that all children are added before their parents");
                        continue;
                    }

                    if (node.Descendants.Count == 1 && node.Ancestors.Count <= 1 &&
                        node.Descendants[0].Parent == node &&
                        parent.Ancestors.Count == 0
                        //If this is true, the current revision is in the middle of a branch
                        //and is about to start a new branch. This will also mean that the last
                        //revisions are non-relative. Make sure a new junction is added and this
                        //is the start of a new branch (and color!)
                        && (aType & DataType.Active) != DataType.Active
                        )
                    {
                        // The node isn't a junction point. Just the parent to the node's
                        // (only) ancestor junction.
                        node.Descendants[0].Add(parent);
                    }
                    else if (node.Ancestors.Count == 1 && node.Ancestors[0].Child != node)
                    {
                        // The node is in the middle of a junction. We need to split it.
                        Junction splitNode = node.Ancestors[0].Split(node);
                        junctions.Add(splitNode);

                        // The node is a junction point. We are a new junction
                        var junction = new Junction(node, parent);
                        junctions.Add(junction);
                    }
                    else if (parent.Descendants.Count == 1 && parent.Descendants[0].Parent != parent)
                    {
                        // The parent is in the middle of a junction. We need to split it.
                        Junction splitNode = parent.Descendants[0].Split(parent);
                        junctions.Add(splitNode);

                        // The node is a junction point. We are a new junction
                        var junction = new Junction(node, parent);
                        junctions.Add(junction);
                    }
                    else
                    {
                        // The node is a junction point. We are a new junction
                        var junction = new Junction(node, parent);
                        junctions.Add(junction);
                    }
                }

                bool isRelative = (aType & DataType.Active) == DataType.Active;

                if (!isRelative && node.Descendants.Any(d => d.IsRelative))
                {
                    isRelative = true;
                }

                bool isRebuild = false;

                foreach (Junction d in node.Ancestors)
                {
                    d.IsRelative = isRelative || d.IsRelative;

                    // Uh, oh, we've already processed this lane. We'll have to update some rows.
                    var parent = d.TryGetParent(node);
                    if (parent != null && parent.InLane != int.MaxValue)
                    {
                        int resetTo = d.Parent.Descendants.Aggregate(d.Parent.InLane, (current, dd) => Math.Min(current, dd.Child.InLane));
                        Debug.WriteLine("We have to start over at lane {0} because of {1}", resetTo, node);
                        isRebuild = true;
                        break;
                    }
                }

                if (isRebuild)
                {
                    // TODO: It would be nice if we didn't have to start completely over...but it wouldn't
                    // be easy since we don't keep around all of the necessary lane state for each step.
                    int lastLane = lanes.Count - 1;
                    lanes.Clear();
                    lanes.CacheTo(lastLane);

                    // We need to signal the DvcsGraph object that it needs to redraw everything.
                    if (Updated != null)
                    {
                        Updated(this);
                    }
                }
                else
                {
                    lanes.Update(node);
                }
            }
Exemplo n.º 37
0
        static string GetTitle(string fileName, GitRevision revision)
        {
            string strRev = revision.RevisionType == GitRevisionType.Time ?
                revision.Time.ToLocalTime().ToString("g") : revision.ToString();

            return fileName + " - " + strRev;
        }
Exemplo n.º 38
0
 private void PickAnotherBranch(GitRevision preSelectCommit, ref string displayStr, [CanBeNull] ref GitRevision revision)
 {
     using (var form = new FormCompareToBranch(UICommands, preSelectCommit.ObjectId))
     {
         if (form.ShowDialog(this) == DialogResult.OK)
         {
             displayStr = form.BranchName;
             var objectId = Module.RevParse(form.BranchName);
             revision = objectId == null ? null : new GitRevision(objectId);
             PopulateDiffFiles();
         }
     }
 }
Exemplo n.º 39
0
        string GetName(string filename, GitRevision rev)
        {
            if (string.IsNullOrEmpty(filename))
                throw new ArgumentNullException("filename");
            else if (rev == null)
                throw new ArgumentNullException("rev");

            return (Path.GetFileNameWithoutExtension(filename) + "." + PathSafeRevision(rev) + Path.GetExtension(filename)).Trim('.');
        }
Exemplo n.º 40
0
        public RunScript(string script, RevisionGrid RevisionGrid)
        {
            string[] scriptInfo = Settings.GetScript(script);
            string   command;
            string   argument;

            if (scriptInfo == null)
            {
                command  = "cmd";
                argument = "echo \'Cannot find script: " + script + "\'";
            }
            else
            {
                command  = scriptInfo[1];
                argument = scriptInfo[2];
            }

            string[] options =
            {
                "{sTag}",
                "{sBranch}",
                "{sLocalBranch}",
                "{sRemoteBranch}",
                "{sRemote}",
                "{sHash}",
                "{sMessage}",
                "{sAuthor}",
                "{sCommitter}",
                "{sAuthorDate}",
                "{sCommitDate}",
                "{cTag}",
                "{cBranch}",
                "{cLocalBranch}",
                "{cRemoteBranch}",
                "{cHash}",
                "{cMessage}",
                "{cAuthor}",
                "{cCommitter}",
                "{cAuthorDate}",
                "{cCommitDate}"
            };

            GitRevision selectedRevision = null;
            GitRevision currentRevision  = null;

            var selectedLocalBranches  = new List <GitHead>();
            var selectedRemoteBranches = new List <GitHead>();
            var selectedRemotes        = new List <string>();
            var selectedBranches       = new List <GitHead>();
            var selectedTags           = new List <GitHead>();
            var currentLocalBranches   = new List <GitHead>();
            var currentRemoteBranches  = new List <GitHead>();
            var currentBranches        = new List <GitHead>();
            var currentTags            = new List <GitHead>();

            foreach (string option in options)
            {
                if (argument.Contains(option))
                {
                    if (option.StartsWith("{s") && selectedRevision == null)
                    {
                        selectedRevision = RevisionGrid.GetRevision(RevisionGrid.LastRow);
                        foreach (GitHead head in selectedRevision.Heads)
                        {
                            if (head.IsTag)
                            {
                                selectedTags.Add(head);
                            }

                            else if (head.IsHead || head.IsRemote)
                            {
                                selectedBranches.Add(head);
                                if (head.IsRemote)
                                {
                                    selectedRemoteBranches.Add(head);
                                    if (!selectedRemotes.Contains(head.Remote))
                                    {
                                        selectedRemotes.Add(head.Remote);
                                    }
                                }
                                else
                                {
                                    selectedLocalBranches.Add(head);
                                }
                            }
                        }
                    }
                    else if (option.StartsWith("{c") && currentRevision == null)
                    {
                        currentRevision = RevisionGrid.GetCurrentRevision();

                        foreach (GitHead head in currentRevision.Heads)
                        {
                            if (head.IsTag)
                            {
                                currentTags.Add(head);
                            }
                            else if (head.IsHead || head.IsRemote)
                            {
                                currentBranches.Add(head);
                                if (head.IsRemote)
                                {
                                    currentRemoteBranches.Add(head);
                                }
                                else
                                {
                                    currentLocalBranches.Add(head);
                                }
                            }
                        }
                    }

                    switch (option)
                    {
                    case "{sTag}":
                        if (selectedTags.Count == 1)
                        {
                            argument = argument.Replace(option, selectedTags[0].Name);
                        }
                        else if (selectedTags.Count != 0)
                        {
                            argument = argument.Replace(option, askToSpecify(selectedTags, "Selected Revision Tag"));
                        }
                        else
                        {
                            argument = argument.Replace(option, "");
                        }
                        break;

                    case "{sBranch}":
                        if (selectedBranches.Count == 1)
                        {
                            argument = argument.Replace(option, selectedBranches[0].Name);
                        }
                        else if (selectedBranches.Count != 0)
                        {
                            argument = argument.Replace(option,
                                                        askToSpecify(selectedBranches, "Selected Revision Branch"));
                        }
                        else
                        {
                            argument = argument.Replace(option, "");
                        }
                        break;

                    case "{sLocalBranch}":
                        if (selectedLocalBranches.Count == 1)
                        {
                            argument = argument.Replace(option, selectedLocalBranches[0].Name);
                        }
                        else if (selectedLocalBranches.Count != 0)
                        {
                            argument = argument.Replace(option,
                                                        askToSpecify(selectedLocalBranches,
                                                                     "Selected Revision Local Branch"));
                        }
                        else
                        {
                            argument = argument.Replace(option, "");
                        }
                        break;

                    case "{sRemoteBranch}":
                        if (selectedRemoteBranches.Count == 1)
                        {
                            argument = argument.Replace(option, selectedRemoteBranches[0].Name);
                        }
                        else if (selectedRemoteBranches.Count != 0)
                        {
                            argument = argument.Replace(option,
                                                        askToSpecify(selectedRemoteBranches,
                                                                     "Selected Revision Remote Branch"));
                        }
                        else
                        {
                            argument = argument.Replace(option, "");
                        }
                        break;

                    case "{sRemote}":
                        if (selectedRemotes.Count == 1)
                        {
                            argument = argument.Replace(option, selectedRemotes[0]);
                        }
                        else if (selectedRemotes.Count != 0)
                        {
                            argument = argument.Replace(option,
                                                        askToSpecify(selectedRemotes, "Selected Revision Remote"));
                        }
                        else
                        {
                            argument = argument.Replace(option, "");
                        }
                        break;

                    case "{sHash}":
                        argument = argument.Replace(option, selectedRevision.Guid);
                        break;

                    case "{sMessage}":
                        argument = argument.Replace(option, selectedRevision.Message);
                        break;

                    case "{sAuthor}":
                        argument = argument.Replace(option, selectedRevision.Author);
                        break;

                    case "{sCommitter}":
                        argument = argument.Replace(option, selectedRevision.Committer);
                        break;

                    case "{sAuthorDate}":
                        argument = argument.Replace(option, selectedRevision.AuthorDate.ToString());
                        break;

                    case "{sCommitDate}":
                        argument = argument.Replace(option, selectedRevision.CommitDate.ToString());
                        break;

                    case "{cTag}":
                        if (currentTags.Count == 1)
                        {
                            argument = argument.Replace(option, currentTags[0].Name);
                        }
                        else if (currentTags.Count != 0)
                        {
                            argument = argument.Replace(option, askToSpecify(currentTags, "Current Revision Tag"));
                        }
                        else
                        {
                            argument = argument.Replace(option, "");
                        }
                        break;

                    case "{cBranch}":
                        if (currentBranches.Count == 1)
                        {
                            argument = argument.Replace(option, currentBranches[0].Name);
                        }
                        else if (currentBranches.Count != 0)
                        {
                            argument = argument.Replace(option,
                                                        askToSpecify(currentBranches, "Current Revision Branch"));
                        }
                        else
                        {
                            argument = argument.Replace(option, "");
                        }
                        break;

                    case "{cLocalBranch}":
                        if (currentLocalBranches.Count == 1)
                        {
                            argument = argument.Replace(option, currentLocalBranches[0].Name);
                        }
                        else if (currentLocalBranches.Count != 0)
                        {
                            argument = argument.Replace(option,
                                                        askToSpecify(currentLocalBranches,
                                                                     "Current Revision Local Branch"));
                        }
                        else
                        {
                            argument = argument.Replace(option, "");
                        }
                        break;

                    case "{cRemoteBranch}":
                        if (currentRemoteBranches.Count == 1)
                        {
                            argument = argument.Replace(option, currentRemoteBranches[0].Name);
                        }
                        else if (currentRemoteBranches.Count != 0)
                        {
                            argument = argument.Replace(option,
                                                        askToSpecify(currentRemoteBranches,
                                                                     "Current Revision Remote Branch"));
                        }
                        else
                        {
                            argument = argument.Replace(option, "");
                        }
                        break;

                    case "{cHash}":
                        argument = argument.Replace(option, currentRevision.Guid);
                        break;

                    case "{cMessage}":
                        argument = argument.Replace(option, currentRevision.Message);
                        break;

                    case "{cAuthor}":
                        argument = argument.Replace(option, currentRevision.Author);
                        break;

                    case "{cCommitter}":
                        argument = argument.Replace(option, currentRevision.Committer);
                        break;

                    case "{cAuthorDate}":
                        argument = argument.Replace(option, currentRevision.AuthorDate.ToString());
                        break;

                    case "{cCommitDate}":
                        argument = argument.Replace(option, currentRevision.CommitDate.ToString());
                        break;

                    default:
                        break;
                    }
                }
            }

            new FormProcess(command, argument).ShowDialog();
        }
Exemplo n.º 41
0
        static void DoBlame(CommandEventArgs e, GitOrigin item, GitRevision revisionEnd, GitIgnoreSpacing ignoreSpacing)
        {
            GitWriteArgs wa = new GitWriteArgs();
            wa.Revision = revisionEnd;

            GitBlameArgs ba = new GitBlameArgs();
            ba.End = revisionEnd;
            ba.IgnoreSpacing = ignoreSpacing;

            GitTarget target = item.Target;

            IVisualGitTempFileManager tempMgr = e.GetService<IVisualGitTempFileManager>();
            string tempFile = tempMgr.GetTempFileNamed(target.FileName);

            Collection<GitBlameEventArgs> blameResult = null;
            Dictionary<string, string> logMessages = new Dictionary<string, string>();

            bool retry = false;
            ProgressRunnerResult r = e.GetService<IProgressRunner>().RunModal(CommandStrings.Annotating, delegate(object sender, ProgressWorkerArgs ee)
            {
                using (FileStream fs = File.Create(tempFile))
                {
                    ee.Client.Write(target, fs, wa);
                }
                try
                {
                    ee.Client.GetBlame(target, ba, out blameResult);
                }
                catch (GitClientBinaryFileException)
                {
                    retry = true;
                }
            });

            if (retry)
            {
                using (VisualGitMessageBox mb = new VisualGitMessageBox(e.Context))
                {
                    if (DialogResult.Yes == mb.Show(
                                                CommandStrings.AnnotateBinaryFileContinueAnywayText,
                                                CommandStrings.AnnotateBinaryFileContinueAnywayTitle,
                                                MessageBoxButtons.YesNo, MessageBoxIcon.Information))
                    {
                        r = e.GetService<IProgressRunner>()
                            .RunModal(CommandStrings.Annotating,
                                      delegate(object sender, ProgressWorkerArgs ee)
                                      {
                                          ee.Client.GetBlame(target, ba, out blameResult);
                                      });
                    }
                }
            }

            if (!r.Succeeded)
                return;

            AnnotateEditorControl annEditor = new AnnotateEditorControl();
            IVisualGitEditorResolver er = e.GetService<IVisualGitEditorResolver>();

            annEditor.Create(e.Context, tempFile);
            annEditor.LoadFile(tempFile);
            annEditor.AddLines(item, blameResult, logMessages);

            // Detect and set the language service
            Guid language;
            if (er.TryGetLanguageService(Path.GetExtension(target.FileName), out language))
            {
                // Extension is mapped -> user
                annEditor.SetLanguageService(language);
            }
            else if (blameResult != null && blameResult.Count > 0 && blameResult[0].Line != null)
            {
                // Extension is not mapped -> Check if this is xml (like project files)
                string line = blameResult[0].Line.Trim();

                if (line.StartsWith("<?xml")
                    || (line.StartsWith("<") && line.Contains("xmlns=\"http://schemas.microsoft.com/developer/msbuild/")))
                {
                    if (er.TryGetLanguageService(".xml", out language))
                    {
                        annEditor.SetLanguageService(language);
                    }
                }
            }
        }
Exemplo n.º 42
0
 public bool StartFileHistoryDialog(string fileName, GitRevision revision)
 {
     return(StartFileHistoryDialog(null, fileName, revision));
 }
Exemplo n.º 43
0
            public VisualGitRevisionType Resolve(GitOrigin origin, GitRevision revision)
            {
                if (revision == null)
                    throw new ArgumentNullException("revision");

                switch (revision.RevisionType)
                {
                    case GitRevisionType.Head:
                        return _head;
                    case GitRevisionType.Base:
                        return _base;
                    case GitRevisionType.Committed:
                        return _committed;
                    case GitRevisionType.Previous:
                        return _previous;
                    case GitRevisionType.Working:
                        return _working;
                }

                return null;
            }
Exemplo n.º 44
0
 private bool StartBlameDialog(string fileName, GitRevision revision)
 {
     return(StartBlameDialog(null, fileName, revision));
 }
Exemplo n.º 45
0
        /// <summary>
        /// Resolves the specified revision.
        /// </summary>
        /// <param name="origin"></param>
        /// <param name="revision">The revision.</param>
        /// <returns></returns>
        public VisualGitRevisionType Resolve(GitOrigin origin, GitRevision revision)
        {
            if (revision == null)
                throw new ArgumentNullException("revision");

            foreach (IVisualGitRevisionProvider p in _providers)
            {
                VisualGitRevisionType r = p.Resolve(origin, revision);

                if (r != null)
                    return r;
            }

            switch (revision.RevisionType)
            {
                case GitRevisionType.Hash:
                    ExplicitRevisionType ert = new ExplicitRevisionType(Context, origin);
                    ert.CurrentValue = revision;
                    return ert;
            }

            return null;
        }
 public override void OnCellPainting(DataGridViewCellPaintingEventArgs e, GitRevision revision, int rowHeight, in CellStyle style)
Exemplo n.º 47
0
        public void StartLog(ICollection<GitOrigin> targets, GitRevision start, GitRevision end)
        {
            if (targets == null)
                throw new ArgumentNullException("targets");

            _origins = new List<GitOrigin>(targets);

            UpdateTitle();

            logControl.StartLog(_origins, start, end);
        }
        public FormRevertCommitSmall(GitRevision Revision)
        {
            this.Revision = Revision;

            InitializeComponent(); Translate();
        }
Exemplo n.º 49
0
        public IEnumerable<GitExtLink> Parse(GitRevision revision)
        { 
            List<IEnumerable<GitExtLink>> links = new List<IEnumerable<GitExtLink>>();

            if (SearchInParts.Contains(RevisionPart.LocalBranches))
                foreach (var head in revision.Refs.Where(b => !b.IsRemote))
                    links.Add(ParsePart(head.LocalName, revision));

            if (SearchInParts.Contains(RevisionPart.RemoteBranches))
                foreach (var head in revision.Refs.Where(b => b.IsRemote))
                    links.Add(ParsePart(head.LocalName, revision));

            if (SearchInParts.Contains(RevisionPart.Message))
                links.Add(ParsePart(revision.Body, revision));

            return links.Unwrap();
        }
Exemplo n.º 50
0
 public RevisionGraphUpdatedEventArgs(GitRevision revision)
 {
     Revision = revision;
 }
Exemplo n.º 51
0
        public GitExtLink ToGitExtLink(Match match, GitRevision revision)
        {
            GitExtLink link = new GitExtLink();

            try
            {
                var groups = new List<string>();
                for (int i = match.Groups.Count > 1 ? 1 : 0; i < match.Groups.Count; i++)
                {
                    groups.Add(match.Groups[i].Value);
                }

                link.Caption = string.Format(Caption, groups.ToArray());
                link.URI = Format.Replace("%COMMIT_HASH%", revision.Guid);
                link.URI = string.Format(link.URI, groups.ToArray());
                IsValid = true;
            }
            catch (Exception e)
            {
                link.URI = e.Message + ": " + Format + " " + match.Value;
                IsValid = false;
            }

            return link;
        }
Exemplo n.º 52
0
        public static void BuildStatusMessageCellPainting(DataGridViewCellPaintingEventArgs e, GitRevision revision, Color foreColor, Font rowFont)
        {
            if (revision.BuildStatus != null)
            {
                var buildStatusForeColor = foreColor;

                switch (revision.BuildStatus.Status)
                {
                case BuildInfo.BuildStatus.Success:
                    buildStatusForeColor = Color.DarkGreen;
                    break;

                case BuildInfo.BuildStatus.Failure:
                    buildStatusForeColor = Color.DarkRed;
                    break;

                case BuildInfo.BuildStatus.InProgress:
                    buildStatusForeColor = Color.Blue;
                    break;

                case BuildInfo.BuildStatus.Unstable:
                    buildStatusForeColor = Color.OrangeRed;
                    break;

                case BuildInfo.BuildStatus.Stopped:
                    buildStatusForeColor = Color.Gray;
                    break;
                }

                var text = (string)e.FormattedValue;
                var rect = RevisionGridUtils.GetCellRectangle(e);
                RevisionGridUtils.DrawColumnText(e.Graphics, text, rowFont, buildStatusForeColor, rect);
            }
        }