Beispiel #1
0
        public void LoadBlame(string guid, string fileName, RevisionGrid revGrid)
        {
            var scrollpos = BlameFile.ScrollPos;

            var blameCommitter = new StringBuilder();
            var blameFile = new StringBuilder();
            _revGrid = revGrid;

            _blame = GitCommandHelpers.Blame(fileName, guid);

            for (int i = 0; i < _blame.Lines.Count; i++ )
            {
                GitBlameLine blameLine = _blame.Lines[i];
                GitBlameHeader blameHeader = _blame.FindHeaderForCommitGuid(blameLine.CommitGuid);
                if (i > 0 && _blame.Lines[i-1].CommitGuid == blameLine.CommitGuid)
                {
                    blameCommitter.AppendLine(new string(' ', 200));
                } else
                {
                    blameCommitter.AppendLine((blameHeader.Author + " - " + blameHeader.AuthorTime.ToString() + " - " + blameHeader.FileName + new string(' ', 100)).Trim(new char[] { '\r', '\n' }));
                }
                if (blameLine.LineText == null )
                    blameFile.AppendLine("");
                else
                    blameFile.AppendLine(blameLine.LineText.Trim(new char[] { '\r', '\n' }));
            }

            BlameCommitter.ViewText("committer.txt", blameCommitter.ToString());
            BlameFile.ViewText(fileName, blameFile.ToString());
            BlameFile.ScrollPos = scrollpos;

            BlameFile_SelectedLineChanged(null, 0);
        }
 public void TestConstructor()
 {
     GitBlame blame = new GitBlame();
     Assert.IsNotNull(blame);
     Assert.IsNotNull(blame.Headers);
     Assert.IsNotNull(blame.Lines);
 }
        public void TestFindHeaderForCommitGuid()
        {
            GitBlame blame = new GitBlame();
            string expectedCommitGuid = Guid.NewGuid().ToString();

            GitBlameHeader expectedHeader = new GitBlameHeader { CommitGuid = expectedCommitGuid };

            blame.Headers.Add(expectedHeader);
            Assert.IsTrue(blame.FindHeaderForCommitGuid(expectedCommitGuid).Equals(expectedHeader));
        }
        public void LoadBlame(string guid, string fileName, RevisionGrid revGrid = null)
        {
            var scrollpos = BlameFile.ScrollPos;

            _revGrid = revGrid;
            Blame = Settings.Module.Blame(fileName, guid);

            LoadBlame_SetupBlameCommitter();
            LoadBlame_SetupBlameFile(fileName, scrollpos);
            commitInfo.SetRevision(guid);
        }
Beispiel #5
0
        public void LoadBlame(GitRevision revision, List<string> children, string fileName, RevisionGrid revGrid, Control controlToMask, Encoding encoding)
        {
            //refresh only when something changed
            if (revision.Equals(CommitInfo.Revision) && fileName == _fileName && revGrid == _revGrid && encoding == _encoding)
                return;

            if (controlToMask != null)
                controlToMask.Mask();

            var scrollpos = BlameFile.ScrollPos;

            var blameCommitter = new StringBuilder();
            var blameFile = new StringBuilder();
            _revGrid = revGrid;
            _fileName = fileName;
            _encoding = encoding;
            string guid = revision.Guid;

            blameLoader.Load(() =>
            {
                _blame = Module.Blame(fileName, guid, encoding);
            },
            () =>
            {

                for (int i = 0; i < _blame.Lines.Count; i++)
                {
                    GitBlameLine blameLine = _blame.Lines[i];
                    GitBlameHeader blameHeader = _blame.FindHeaderForCommitGuid(blameLine.CommitGuid);
                    if (i > 0 && _blame.Lines[i - 1].CommitGuid == blameLine.CommitGuid)
                    {
                        blameCommitter.AppendLine(new string(' ', 200));
                    }
                    else
                    {
                        blameCommitter.AppendLine((blameHeader.Author + " - " + blameHeader.AuthorTime + " - " + blameHeader.FileName + new string(' ', 100)).Trim(new[] { '\r', '\n' }));
                    }
                    if (blameLine.LineText == null)
                        blameFile.AppendLine("");
                    else
                        blameFile.AppendLine(blameLine.LineText.Trim(new char[] { '\r', '\n' }));
                }

                BlameCommitter.ViewText("committer.txt", blameCommitter.ToString());
                BlameFile.ViewText(fileName, blameFile.ToString());
                BlameFile.ScrollPos = scrollpos;

                CommitInfo.SetRevisionWithChildren(revision, children);

                if (controlToMask != null)
                    controlToMask.UnMask();
            });
        }
        public void LoadBlame(GitRevision revision, List<string> children, string fileName, RevisionGrid revGrid, Control controlToMask, Encoding encoding)
        {
            //refresh only when something changed
            if (revision.Equals(CommitInfo.Revision) && fileName == _fileName && revGrid == _revGrid && encoding == _encoding)
                return;

            if (controlToMask != null)
                controlToMask.Mask();

            var scrollpos = BlameFile.ScrollPos;

            _revGrid = revGrid;
            _fileName = fileName;
            _encoding = encoding;
            string guid = revision.Guid;

            blameLoader.Load(() => _blame = Module.Blame(fileName, guid, encoding),
                () => ProcessBlame(revision, children, controlToMask, scrollpos));
        }
Beispiel #7
0
        public GitBlame Blame(string filename, string from, string lines, Encoding encoding)
        {
            from = FixPath(from);
            filename = FixPath(filename);
            string blameCommand = string.Format("blame --porcelain -M -w -l{0} \"{1}\" -- \"{2}\"", lines != null ? " -L " + lines : "", from, filename);
            var itemsStrings =
                RunCacheableCmd(
                    AppSettings.GitCommand,
                    blameCommand,
                    LosslessEncoding
                    )
                    .Split('\n');

            GitBlame blame = new GitBlame();

            GitBlameHeader blameHeader = null;
            GitBlameLine blameLine = null;

            for (int i = 0; i < itemsStrings.GetLength(0); i++)
            {
                try
                {
                    string line = itemsStrings[i];

                    //The contents of the actual line is output after the above header, prefixed by a TAB. This is to allow adding more header elements later.
                    if (line.StartsWith("\t"))
                    {
                        blameLine.LineText = line.Substring(1) //trim ONLY first tab
                                                 .Trim(new char[] { '\r' }); //trim \r, this is a workaround for a \r\n bug
                        blameLine.LineText = ReEncodeStringFromLossless(blameLine.LineText, encoding);
                    }
                    else if (line.StartsWith("author-mail"))
                        blameHeader.AuthorMail = ReEncodeStringFromLossless(line.Substring("author-mail".Length).Trim());
                    else if (line.StartsWith("author-time"))
                        blameHeader.AuthorTime = DateTimeUtils.ParseUnixTime(line.Substring("author-time".Length).Trim());
                    else if (line.StartsWith("author-tz"))
                        blameHeader.AuthorTimeZone = line.Substring("author-tz".Length).Trim();
                    else if (line.StartsWith("author"))
                    {
                        blameHeader = new GitBlameHeader();
                        blameHeader.CommitGuid = blameLine.CommitGuid;
                        blameHeader.Author = ReEncodeStringFromLossless(line.Substring("author".Length).Trim());
                        blame.Headers.Add(blameHeader);
                    }
                    else if (line.StartsWith("committer-mail"))
                        blameHeader.CommitterMail = line.Substring("committer-mail".Length).Trim();
                    else if (line.StartsWith("committer-time"))
                        blameHeader.CommitterTime = DateTimeUtils.ParseUnixTime(line.Substring("committer-time".Length).Trim());
                    else if (line.StartsWith("committer-tz"))
                        blameHeader.CommitterTimeZone = line.Substring("committer-tz".Length).Trim();
                    else if (line.StartsWith("committer"))
                        blameHeader.Committer = ReEncodeStringFromLossless(line.Substring("committer".Length).Trim());
                    else if (line.StartsWith("summary"))
                        blameHeader.Summary = ReEncodeStringFromLossless(line.Substring("summary".Length).Trim());
                    else if (line.StartsWith("filename"))
                        blameHeader.FileName = ReEncodeFileNameFromLossless(line.Substring("filename".Length).Trim());
                    else if (line.IndexOf(' ') == 40) //SHA1, create new line!
                    {
                        blameLine = new GitBlameLine();
                        var headerParams = line.Split(' ');
                        blameLine.CommitGuid = headerParams[0];
                        if (headerParams.Length >= 3)
                        {
                            blameLine.OriginLineNumber = int.Parse(headerParams[1]);
                            blameLine.FinalLineNumber = int.Parse(headerParams[2]);
                        }
                        blame.Lines.Add(blameLine);
                    }
                }
                catch
                {
                    //Catch all parser errors, and ignore them all!
                    //We should never get here...
                    AppSettings.GitLog.Log("Error parsing output from command: " + blameCommand + "\n\nPlease report a bug!");
                }
            }

            return blame;
        }
        public static GitBlame Blame(string filename, string from)
        {
            from = FixPath(from);
            filename = FixPath(filename);
            string blameCommand = string.Format("blame --porcelain -M -w -l \"{0}\" -- \"{1}\"", from, filename);
            var itemsStrings =
                RunCmd(
                    Settings.GitCommand,
                    blameCommand
                    )
                    .Split('\n');

            GitBlame blame = new GitBlame();

            GitBlameHeader blameHeader = null;
            GitBlameLine blameLine = null;

            for (int i = 0; i < itemsStrings.GetLength(0); i++)
            {
                try
                {
                    string line = itemsStrings[i];

                    //The contents of the actual line is output after the above header, prefixed by a TAB. This is to allow adding more header elements later.
                    if (line.StartsWith("\t"))
                        blameLine.LineText = line.Substring(1).Trim(new char[] { '\r' });//trim first tab
                    else
                        if (line.StartsWith("author-mail"))
                            blameHeader.AuthorMail = line.Substring("author-mail".Length).Trim();
                        else
                            if (line.StartsWith("author-time"))
                                blameHeader.AuthorTime = (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).AddSeconds(int.Parse(line.Substring("author-time".Length).Trim()));
                            else
                                if (line.StartsWith("author-tz"))
                                    blameHeader.AuthorTimeZone = line.Substring("author-tz".Length).Trim();
                                else
                                    if (line.StartsWith("author"))
                                    {
                                        blameHeader = new GitBlameHeader();
                                        blameHeader.CommitGuid = blameLine.CommitGuid;
                                        blameHeader.Author = line.Substring("author".Length).Trim();
                                        blame.Headers.Add(blameHeader);
                                    }
                                    else
                                        if (line.StartsWith("committer-mail"))
                                            blameHeader.CommitterMail = line.Substring("committer-mail".Length).Trim();
                                        else
                                            if (line.StartsWith("committer-time"))
                                                blameHeader.CommitterTime = (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).AddSeconds(int.Parse(line.Substring("committer-time".Length).Trim()));
                                            else
                                                if (line.StartsWith("committer-tz"))
                                                    blameHeader.CommitterTimeZone = line.Substring("committer-tz".Length).Trim();
                                                else
                                                    if (line.StartsWith("committer"))
                                                        blameHeader.Committer = line.Substring("committer".Length).Trim();
                                                    else
                                                        if (line.StartsWith("summary"))
                                                            blameHeader.Summary = line.Substring("summary".Length).Trim();
                                                        else
                                                            if (line.StartsWith("filename"))
                                                                blameHeader.FileName = line.Substring("filename".Length).Trim();
                                                            else
                                                                if (line.IndexOf(' ') == 40) //SHA1, create new line!
                                                                {
                                                                    blameLine = new GitBlameLine();
                                                                    blameLine.CommitGuid = line.Substring(0, 40);
                                                                    blame.Lines.Add(blameLine);
                                                                }
                }
                catch
                {
                    //Catch all parser errors, and ignore them all!
                    //We should never get here...
                    Settings.GitLog.Log("Error parsing output from command: " + blameCommand + "\n\nPlease report a bug!");
                }
            }

            return blame;
        }
Beispiel #9
0
        public static List<GitBlame> Blame(string filename, string from)
        {
            from = FixPath(from);
            filename = FixPath(filename);
            string[] itemsStrings = RunCmd(Settings.GitCommand, "blame -M -w -l \"" + from + "\" -- \"" + filename + "\"").Split('\n');

            List<GitBlame> items = new List<GitBlame>();

            GitBlame item = null;
            string lastCommitGuid = "";

            Color color1 = Color.Azure;
            Color color2 = Color.Ivory;
            Color currentColor = color1;

            foreach (string itemsString in itemsStrings)
            {
                if (itemsString.Length > 50)
                {
                    string commitGuid = itemsString.Substring(0, 40).Trim();

                    if (lastCommitGuid != commitGuid)
                    {
                        if (currentColor == color1)
                            currentColor = color2;
                        else
                            currentColor = color1;
                    }

                    {
                        item = new GitBlame();
                        item.color = currentColor;
                        item.CommitGuid = commitGuid;
                        items.Add(item);
                    }

                    int codeIndex = itemsString.IndexOf(')', 41) + 1;
                    if (codeIndex > 41)
                    {
                        if (lastCommitGuid != commitGuid)
                            item.Author = itemsString.Substring(41, codeIndex - 41).Trim();

                        if (!string.IsNullOrEmpty(item.Text))
                            item.Text += Environment.NewLine;
                        item.Text += itemsString.Substring(codeIndex).Trim(new char[] { '\r' });
                    }

                    lastCommitGuid = commitGuid;
                }
            }

            return items;
        }
        public static List<GitBlame> Blame(string filename, string from)
        {
            from = FixPath(from);
            filename = FixPath(filename);
            var itemsStrings =
                RunCmd(
                    Settings.GitCommand,
                    string.Format("blame -M -w -l \"{0}\" -- \"{1}\"", from, filename))
                    .Split('\n');

            var items = new List<GitBlame>();

            GitBlame item;
            var lastCommitGuid = "";

            var color1 = Color.Azure;
            var color2 = Color.Ivory;
            var currentColor = color1;

            foreach (var itemsString in itemsStrings)
            {
                if (itemsString.Length <= 50)
                    continue;

                var commitGuid = itemsString.Substring(0, 40).Trim();

                if (lastCommitGuid != commitGuid)
                    currentColor = currentColor == color1 ? color2 : color1;

                item = new GitBlame {color = currentColor, CommitGuid = commitGuid};
                items.Add(item);

                var codeIndex = itemsString.IndexOf(')', 41) + 1;
                if (codeIndex > 41)
                {
                    if (lastCommitGuid != commitGuid)
                        item.Author = itemsString.Substring(41, codeIndex - 41).Trim();

                    if (!string.IsNullOrEmpty(item.Text))
                        item.Text += Environment.NewLine;
                    item.Text += itemsString.Substring(codeIndex).Trim(new[] {'\r'});
                }

                lastCommitGuid = commitGuid;
            }

            return items;
        }
Beispiel #11
0
        public void LoadBlame(GitRevision revision, List<string> children, string fileName, RevisionGrid revGrid, Control controlToMask, Encoding encoding)
        {
            //refresh only when something changed
            string guid = revision.Guid;
            if (guid.Equals(_blameHash) && fileName == _fileName && revGrid == _revGrid && encoding == _encoding)
                return;

            if (controlToMask != null)
                controlToMask.Mask();

            var scrollpos = BlameFile.ScrollPos;

            int line = 0;
            if (_clickedBlameLine.CommitGuid == guid)
                line = _clickedBlameLine.OriginLineNumber;
            _revGrid = revGrid;
            _fileName = fileName;
            _encoding = encoding;

            blameLoader.Load(() => _blame = Module.Blame(fileName, guid, encoding),
                () => ProcessBlame(revision, children, controlToMask, line, scrollpos));
        }