GitCommands.GitCommands.Blame C# (CSharp) Method

Blame() public static method

public static Blame ( string filename, string from ) : List
filename string
from string
return List
        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;
        }
GitCommands