public FormFileHistory(GitUICommands aCommands, string fileName, GitRevision revision, bool filterByRevision)
            : this(aCommands)
        {
            FileChanges.SetInitialRevision(revision);
            Translate();

            FileChanges.ShowBuildServerInfo = true;

            FileName = fileName;
            SetTitle(string.Empty);

            Diff.ExtraDiffArgumentsChanged += DiffExtraDiffArgumentsChanged;

            bool isSubmodule = GitModule.IsValidGitWorkingDir(Path.Combine(Module.WorkingDir, FileName));
            if (revision != null && revision.IsArtificial() || isSubmodule) //no blame for artificial
            {
                tabControl1.RemoveIfExists(BlameTab);
            }
            FileChanges.SelectionChanged += FileChangesSelectionChanged;
            FileChanges.DisableContextMenu();

            UpdateFollowHistoryMenuItems();
            fullHistoryToolStripMenuItem.Checked       = AppSettings.FullHistoryInFileHistory;
            loadHistoryOnShowToolStripMenuItem.Checked = AppSettings.LoadFileHistoryOnShow;
            loadBlameOnShowToolStripMenuItem.Checked   = AppSettings.LoadBlameOnShow && tabControl1.Contains(BlameTab);
            saveAsToolStripMenuItem.Visible            = !isSubmodule;

            if (filterByRevision && revision != null && revision.Guid != null)
            {
                _filterBranchHelper.SetBranchFilter(revision.Guid, false);
            }
        }
Esempio n. 2
0
        private static PatchApply.Patch GetItemPatch(GitModule module, GitItemStatus file,
                                                     string firstRevision, string secondRevision, string diffArgs, Encoding encoding)
        {
            bool cacheResult = true;

            if (GitRevision.IsArtificial(firstRevision))
            {
                bool staged = firstRevision == GitRevision.IndexGuid;
                if (secondRevision == null || secondRevision == GitRevision.IndexGuid)
                {
                    return(module.GetCurrentChanges(file.Name, file.OldName, staged,
                                                    diffArgs, encoding));
                }

                cacheResult    = false;
                firstRevision  = secondRevision;
                secondRevision = string.Empty;
                if (staged)
                {
                    diffArgs = string.Join(" ", diffArgs, "--cached");
                }
            }
            else if (secondRevision == null)
            {
                secondRevision = firstRevision + "^";
            }

            return(module.GetSingleDiff(firstRevision, secondRevision, file.Name, file.OldName,
                                        diffArgs, encoding, cacheResult));
        }
Esempio n. 3
0
        /// <summary>
        /// Generate header.
        /// </summary>
        /// <returns></returns>
        public string Render(CommitData commitData, bool showRevisionsAsLinks)
        {
            if (commitData == null)
            {
                throw new ArgumentNullException(nameof(commitData));
            }

            bool   isArtificial     = GitRevision.IsArtificial(commitData.Guid);
            bool   authorIsCommiter = string.Equals(commitData.Author, commitData.Committer, StringComparison.CurrentCulture);
            bool   datesEqual       = commitData.AuthorDate.EqualsExact(commitData.CommitDate);
            var    padding          = _headerRendererStyleProvider.GetMaxWidth();
            string authorEmail      = GetEmail(commitData.Author);

            StringBuilder header = new StringBuilder();

            header.AppendLine(_labelFormatter.FormatLabel(Strings.GetAuthorText(), padding) + _linkFactory.CreateLink(commitData.Author, "mailto:" + authorEmail));

            if (!isArtificial)
            {
                header.AppendLine(_labelFormatter.FormatLabel(datesEqual ? Strings.GetDateText() : Strings.GetAuthorDateText(), padding) + WebUtility.HtmlEncode(_dateFormatter.FormatDateAsRelativeLocal(commitData.AuthorDate)));
            }

            if (!authorIsCommiter)
            {
                string committerEmail = GetEmail(commitData.Committer);
                header.AppendLine(_labelFormatter.FormatLabel(Strings.GetCommitterText(), padding) + _linkFactory.CreateLink(commitData.Committer, "mailto:" + committerEmail));
            }

            if (!isArtificial)
            {
                if (!datesEqual)
                {
                    header.AppendLine(_labelFormatter.FormatLabel(Strings.GetCommitDateText(), padding) + WebUtility.HtmlEncode(_dateFormatter.FormatDateAsRelativeLocal(commitData.CommitDate)));
                }

                header.AppendLine(_labelFormatter.FormatLabel(Strings.GetCommitHashText(), padding) + WebUtility.HtmlEncode(commitData.Guid));
            }

            if (commitData.ChildrenGuids != null && commitData.ChildrenGuids.Count != 0)
            {
                header.AppendLine(_labelFormatter.FormatLabel(Strings.GetChildrenText(), padding) + RenderHashCollection(commitData.ChildrenGuids, showRevisionsAsLinks));
            }

            var parentGuids = commitData.ParentGuids.Where(s => !string.IsNullOrEmpty(s)).ToList();

            if (parentGuids.Any())
            {
                header.AppendLine(_labelFormatter.FormatLabel(Strings.GetParentsText(), padding) + RenderHashCollection(parentGuids, showRevisionsAsLinks));
            }

            // remove the trailing newline character
            header.Length = header.Length - Environment.NewLine.Length;

            return(header.ToString());
        }
Esempio n. 4
0
        private void fileHistoryDiffToolstripMenuItem_Click(object sender, EventArgs e)
        {
            GitItemStatus item = DiffFiles.SelectedItem;

            if (item.IsTracked)
            {
                IList <GitRevision> revisions = _revisionGrid.GetSelectedRevisions();

                if (revisions.Count == 0 || GitRevision.IsArtificial(revisions[0].Guid))
                {
                    UICommands.StartFileHistoryDialog(this, item.Name);
                }
                else
                {
                    UICommands.StartFileHistoryDialog(this, item.Name, revisions[0], false);
                }
            }
        }
Esempio n. 5
0
        private void fileHistoryItem_Click(object sender, EventArgs e)
        {
            var item = tvGitTree.SelectedNode.Tag as GitItem;

            if (item == null)
            {
                return;
            }

            if (GitRevision.IsArtificial(_revision.Guid))
            {
                UICommands.StartFileHistoryDialog(this, item.FileName);
            }
            else
            {
                UICommands.StartFileHistoryDialog(this, item.FileName, _revision, false, false);
            }
        }
Esempio n. 6
0
        public static string GetSelectedPatch(this FileViewer diffViewer, string firstRevision, string secondRevision, GitItemStatus file)
        {
            if (firstRevision == null)
            {
                return(null);
            }

            //to simplify if-ology
            if (GitRevision.IsArtificial(secondRevision) && firstRevision != GitRevision.UnstagedGuid)
            {
                string temp = firstRevision;
                firstRevision  = secondRevision;
                secondRevision = temp;
            }

            if (IsItemUntracked(file, firstRevision, secondRevision))
            {
                var fullPath = Path.Combine(diffViewer.Module.WorkingDir, file.Name);
                if (Directory.Exists(fullPath) && GitModule.IsValidGitWorkingDir(fullPath))
                {
                    return(LocalizationHelpers.GetSubmoduleText(diffViewer.Module, file.Name.TrimEnd('/'), ""));
                }
                return(FileReader.ReadFileContent(fullPath, diffViewer.Encoding));
            }

            if (file.IsSubmodule && file.SubmoduleStatus != null)
            {
                return(LocalizationHelpers.ProcessSubmoduleStatus(diffViewer.Module, file.SubmoduleStatus.Result));
            }

            PatchApply.Patch patch = GetItemPatch(diffViewer.Module, file, firstRevision, secondRevision,
                                                  diffViewer.GetExtraDiffArguments(), diffViewer.Encoding);

            if (patch == null)
            {
                return(string.Empty);
            }

            if (file.IsSubmodule)
            {
                return(LocalizationHelpers.ProcessSubmodulePatch(diffViewer.Module, file.Name, patch));
            }
            return(patch.Text);
        }
Esempio n. 7
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();
        }
        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. 9
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 ?? revision.Guid + '^';
                    }
                    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 ?? revisions[1].Guid + '^';
                        break;

                    case DiffWithRevisionKind.DiffBParentLocal:
                        revisionToCmp = revisions[0].FirstParentGuid ?? revisions[0].Guid + '^';
                        break;

                    default:
                        revisionToCmp = null;
                        break;
                    }
                }

                if (revisionToCmp == null)
                {
                    return;
                }

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

            if (!string.IsNullOrEmpty(output))
            {
                MessageBox.Show(grid, output);
            }
        }
Esempio n. 10
0
        public static void OpenWithDifftool(this RevisionGrid grid, string fileName, DiffWithRevisionKind diffKind)
        {
            IList <GitRevision> revisions = grid.GetSelectedRevisions();

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

            string output;

            if (diffKind == DiffWithRevisionKind.DiffBaseLocal)
            {
                if (revisions[0].ParentGuids.Length == 0)
                {
                    return;
                }
                output = GitModule.Current.OpenWithDifftool(fileName, revisions[0].ParentGuids[0]);
            }
            else if (diffKind == DiffWithRevisionKind.DiffRemoteLocal)
            {
                output = GitModule.Current.OpenWithDifftool(fileName, revisions[0].Guid);
            }
            else
            {
                string firstRevision  = revisions[0].Guid;
                var    secondRevision = revisions.Count == 2 ? revisions[1].Guid : null;

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

                string extraDiffArgs = null;

                if (firstRevision == GitRevision.UncommittedWorkingDirGuid) //working dir changes
                {
                    if (secondRevision == null || secondRevision == GitRevision.IndexGuid)
                    {
                        firstRevision  = string.Empty;
                        secondRevision = string.Empty;
                    }
                    else
                    {
                        // rev2 vs working dir changes
                        firstRevision  = secondRevision;
                        secondRevision = string.Empty;
                    }
                }
                if (firstRevision == GitRevision.IndexGuid) //index
                {
                    if (secondRevision == null)
                    {
                        firstRevision  = string.Empty;
                        secondRevision = string.Empty;
                        extraDiffArgs  = string.Join(" ", extraDiffArgs, "--cached");
                    }
                    else //rev1 vs index
                    {
                        firstRevision  = secondRevision;
                        secondRevision = string.Empty;
                        extraDiffArgs  = string.Join(" ", extraDiffArgs, "--cached");
                    }
                }

                Debug.Assert(!GitRevision.IsArtificial(firstRevision), string.Join(" ", firstRevision, secondRevision));

                if (secondRevision == null)
                {
                    secondRevision = firstRevision + "^";
                }

                output = GitModule.Current.OpenWithDifftool(fileName, firstRevision, secondRevision, extraDiffArgs);
            }

            if (!string.IsNullOrEmpty(output))
            {
                MessageBox.Show(grid, output);
            }
        }
Esempio n. 11
0
        public static string GetSelectedPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file)
        {
            IList <GitRevision> revisions = grid.GetSelectedRevisions();

            if (revisions.Count == 0)
            {
                return(null);
            }

            string firstRevision  = revisions[0].Guid;
            var    secondRevision = revisions.Count == 2 ? revisions[1].Guid : null;

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

            string extraDiffArgs = null;

            if (firstRevision == GitRevision.UncommittedWorkingDirGuid) //working dir changes
            {
                if (secondRevision == null || secondRevision == GitRevision.IndexGuid)
                {
                    if (file.IsTracked)
                    {
                        return(ProcessDiffText(GitModule.Current.GetCurrentChanges(file.Name, file.OldName, false,
                                                                                   diffViewer.GetExtraDiffArguments(), diffViewer.Encoding), file.IsSubmodule));
                    }

                    return(FileReader.ReadFileContent(GitModule.CurrentWorkingDir + file.Name, diffViewer.Encoding));
                }
                else
                {
                    firstRevision  = secondRevision;
                    secondRevision = string.Empty;
                }
            }
            if (firstRevision == GitRevision.IndexGuid) //index
            {
                if (secondRevision == null)
                {
                    return(ProcessDiffText(GitModule.Current.GetCurrentChanges(file.Name, file.OldName, true,
                                                                               diffViewer.GetExtraDiffArguments(), diffViewer.Encoding), file.IsSubmodule));
                }

                //rev1 vs index
                firstRevision  = secondRevision;
                secondRevision = string.Empty;
                extraDiffArgs  = string.Join(" ", extraDiffArgs, "--cached");
            }

            Debug.Assert(!GitRevision.IsArtificial(firstRevision), string.Join(" ", firstRevision, secondRevision));

            if (secondRevision == null)
            {
                secondRevision = firstRevision + "^";
            }

            PatchApply.Patch patch = GitModule.Current.GetSingleDiff(firstRevision, secondRevision, file.Name, file.OldName,
                                                                     string.Join(" ", diffViewer.GetExtraDiffArguments(), extraDiffArgs), diffViewer.Encoding);

            if (patch == null)
            {
                return(string.Empty);
            }

            return(ProcessDiffText(patch.Text, file.IsSubmodule));
        }
Esempio n. 12
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));
            }
        }
Esempio n. 13
0
        private void openWithDifftoolToolStripMenuItem_DropDownOpening(object sender, System.ComponentModel.CancelEventArgs e)
        {
            aLocalToolStripMenuItem.Enabled = _baseRevision != null && _baseRevision.Guid != GitRevision.UnstagedGuid;
            bLocalToolStripMenuItem.Enabled = _headRevision != null && _headRevision.Guid != GitRevision.UnstagedGuid;
            bool isExactlyOneItemSelected = DiffFiles.SelectedItems.Count() == 1;

            blameToolStripMenuItem.Visible = isExactlyOneItemSelected && !(DiffFiles.SelectedItem.IsSubmodule || _baseRevision.IsArtificial());
        }
Esempio n. 14
0
        public static void OpenWithDifftool(this RevisionGrid grid, string fileName, string oldFileName, DiffWithRevisionKind diffKind)
        {
            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 (firstRevision == GitRevision.UnstagedGuid) //working dir changes
                {
                    if (secondRevision == null || secondRevision == GitRevision.IndexGuid)
                    {
                        firstRevision  = string.Empty;
                        secondRevision = string.Empty;
                    }
                    else
                    {
                        // rev2 vs working dir changes
                        firstRevision  = secondRevision;
                        secondRevision = string.Empty;
                    }
                }
                if (firstRevision == GitRevision.IndexGuid) //index
                {
                    if (secondRevision == null)
                    {
                        firstRevision  = string.Empty;
                        secondRevision = string.Empty;
                        extraDiffArgs  = string.Join(" ", extraDiffArgs, "--cached");
                    }
                    else //rev1 vs index
                    {
                        firstRevision  = secondRevision;
                        secondRevision = string.Empty;
                        extraDiffArgs  = string.Join(" ", extraDiffArgs, "--cached");
                    }
                }

                Debug.Assert(!GitRevision.IsArtificial(firstRevision), string.Join(" ", firstRevision, secondRevision));

                if (secondRevision == null)
                {
                    secondRevision = 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 = revision.ParentGuids.Length == 0 ? null : revision.ParentGuids[0];
                    }
                    else if (diffKind == DiffWithRevisionKind.DiffBLocal)
                    {
                        revisionToCmp = revision.Guid;
                    }
                    else
                    {
                        revisionToCmp = null;
                    }
                }
                else
                {
                    if (diffKind == DiffWithRevisionKind.DiffALocal)
                    {
                        revisionToCmp = revisions[0].Guid;
                    }
                    else if (diffKind == DiffWithRevisionKind.DiffBLocal)
                    {
                        revisionToCmp = revisions[1].Guid;
                    }
                    else if (diffKind == DiffWithRevisionKind.DiffAParentLocal)
                    {
                        revisionToCmp = revisions[0].ParentGuids.Length == 0 ? null : revisions[0].ParentGuids[0];
                    }
                    else if (diffKind == DiffWithRevisionKind.DiffBLocal)
                    {
                        revisionToCmp = revisions[1].ParentGuids.Length == 0 ? null : revisions[1].ParentGuids[0];
                    }
                    else
                    {
                        revisionToCmp = null;
                    }
                }

                if (revisionToCmp == null)
                {
                    return;
                }

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

            if (!string.IsNullOrEmpty(output))
            {
                MessageBox.Show(grid, output);
            }
        }
Esempio n. 15
0
 private static string GetCommitSubject(string sha, IGitRevisionProvider module)
 {
     return(GitRevision.IsArtificial(sha)
         ? ""
         : module.GetRevision(sha, shortFormat: true).Subject);
 }