Exemplo n.º 1
0
 public IBlame Blame(string revision, string filePath)
 {
     using (var blame = git.Blame(revision, filePath))
     {
         return(GitBlame.Parse(blame));
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Parse blame stream.
        /// </summary>
        /// <param name="blameData">Git blame in incremental format.</param>
        /// <returns>Dictionary of line numbers (from 1) with revisions.</returns>
        public static GitBlame Parse(Stream blameData)
        {
            TextReader reader = new StreamReader(blameData);
            GitBlame   blame  = new GitBlame();
            string     line;

            while ((line = reader.ReadLine()) != null)
            {
                if ((line.Length >= 46) && (line.Length < 100))
                {
                    string[] parts = line.Split(' ');
                    if ((parts.Length == 4) && (parts[0].Length == 40))
                    {
                        int lines     = Convert.ToInt32(parts[3]);
                        int startLine = Convert.ToInt32(parts[2]);
                        for (int i = 0; i < lines; i++)
                        {
                            blame.Add(startLine + i, parts[0]);
                        }
                    }
                }
            }

            return(blame);
        }
Exemplo n.º 3
0
        public void Should_keep_revisions_for_each_line()
        {
            blame = GitBlame.Parse(blame0.ToStream());

            blame.Where(x => x.Value == "a59b276e18f3d4a548caf549e05188cb1bd3a709").Count()
            .Should().Be(15);
            blame.Where(x => x.Value == "54988bdad7dc3f09e40752221c144bf470d73aa7").Count()
            .Should().Be(3);
            blame.Where(x => x.Value == "54988bdad7dc3f09e40752221c144bf470d73aa7")
            .Select(x => x.Key)
            .Should().Have.SameSequenceAs(new int[]
            {
                5, 15, 16
            });
        }