コード例 #1
0
ファイル: MainViewModel.cs プロジェクト: vidstige/TimelapsGit
        public LineAndCommit[] Blame(Commit commit, string path)
        {
            var leaf = commit.Tree[path] as Leaf;

            if (leaf == null)
            {
                throw new ArgumentException("The given path does not exist in this commit: " + path);
            }

            byte[]  data    = leaf.RawData;
            IntList lineMap = RawParseUtils.lineMap(data, 0, data.Length);
            var     lines   = new LineAndCommit[lineMap.size()];
            var     curText = new RawText(data);

            Commit prevAncestor = commit;

            Leaf   prevLeaf   = null;
            Commit prevCommit = null;
            int    emptyLines = lineMap.size();

            foreach (Commit ancestor in commit.Ancestors)
            {
                var cleaf = ancestor.Tree[path] as Leaf;
                if (prevCommit != null && (cleaf == null || cleaf.Hash != prevLeaf.Hash))
                {
                    byte[] prevData = prevLeaf.RawData;
                    if (prevData == null)
                    {
                        break;
                    }
                    var prevText = new RawText(prevData);
                    var differ   = new MyersDiff(prevText, curText);
                    foreach (Edit e in differ.getEdits())
                    {
                        for (int n = e.BeginB; n < e.EndB; n++)
                        {
                            if (lines[n] == null)
                            {
                                lines[n] = CreateViewModel(GetLine(commit.Encoding, curText, n), prevCommit);
                                emptyLines--;
                            }
                        }
                    }
                    if (cleaf == null || emptyLines <= 0)
                    {
                        break;
                    }
                }
                prevCommit = ancestor;
                prevLeaf   = cleaf;
            }
            for (int n = 0; n < lines.Length; n++)
            {
                if (lines[n] == null)
                {
                    lines[n] = CreateViewModel(GetLine(commit.Encoding, curText, n), prevAncestor);
                }
            }
            return(lines);
        }
コード例 #2
0
ファイル: Commit.cs プロジェクト: yhtsnda/Bonobo-Git-Server
        public Commit[] Blame(string path)
        {
            Leaf leaf = Tree [path] as Leaf;

            if (leaf == null)
            {
                throw new ArgumentException("The given path does not exist in this commit: " + path);
            }
            byte[] data      = leaf.RawData;
            int    lineCount = RawParseUtils.lineMap(data, 0, data.Length).size();

            Commit[] lines        = new Commit [lineCount];
            var      curText      = new RawText(data);
            Commit   prevAncestor = this;

            Leaf   prevLeaf   = null;
            Commit prevCommit = null;
            int    emptyLines = lineCount;

            foreach (Commit ancestor in Ancestors)
            {
                Leaf cleaf = ancestor.Tree [path] as Leaf;
                if (prevCommit != null && (cleaf == null || cleaf.Hash != prevLeaf.Hash))
                {
                    byte[] prevData = prevLeaf.RawData;
                    if (prevData == null)
                    {
                        break;
                    }
                    var prevText = new RawText(prevData);
                    var differ   = new MyersDiff(prevText, curText);
                    foreach (Edit e in differ.getEdits())
                    {
                        for (int n = e.BeginB; n < e.EndB; n++)
                        {
                            if (lines [n] == null)
                            {
                                lines [n] = prevCommit;
                                emptyLines--;
                            }
                        }
                    }
                    if (cleaf == null || emptyLines <= 0)
                    {
                        break;
                    }
                }
                prevCommit = ancestor;
                prevLeaf   = cleaf;
            }
            for (int n = 0; n < lines.Length; n++)
            {
                if (lines [n] == null)
                {
                    lines [n] = prevAncestor;
                }
            }
            return(lines);
        }
コード例 #3
0
        public void testOneBlankLine()
        {
            IntList map = RawParseUtils.lineMap(new byte[] { (byte)'\n' }, 0, 1);

            Assert.AreEqual(3, map.size());
            Assert.AreEqual(int.MinValue, map.get(0));
            Assert.AreEqual(0, map.get(1));
            Assert.AreEqual(1, map.get(2));
        }
コード例 #4
0
        public void testEmpty()
        {
            IntList map = RawParseUtils.lineMap(new byte[] {}, 0, 0);

            Assert.IsNotNull(map);
            Assert.AreEqual(2, map.size());
            Assert.AreEqual(int.MinValue, map.get(0));
            Assert.AreEqual(0, map.get(1));
        }
コード例 #5
0
        public void testTwoLineNoLF()
        {
            byte[]  buf = "foo\nbar".getBytes("ISO-8859-1");
            IntList map = RawParseUtils.lineMap(buf, 0, buf.Length);

            Assert.AreEqual(4, map.size());
            Assert.AreEqual(int.MinValue, map.get(0));
            Assert.AreEqual(0, map.get(1));
            Assert.AreEqual(4, map.get(2));
            Assert.AreEqual(buf.Length, map.get(3));
        }
コード例 #6
0
        public void testFourLineBlanks()
        {
            byte[]  buf = "foo\n\n\nbar\n".getBytes("ISO-8859-1");
            IntList map = RawParseUtils.lineMap(buf, 0, buf.Length);

            Assert.AreEqual(6, map.size());
            Assert.AreEqual(int.MinValue, map.get(0));
            Assert.AreEqual(0, map.get(1));
            Assert.AreEqual(4, map.get(2));
            Assert.AreEqual(5, map.get(3));
            Assert.AreEqual(6, map.get(4));
            Assert.AreEqual(buf.Length, map.get(5));
        }
コード例 #7
0
 ///	<summary>
 /// Create a new sequence from an existing content byte array.
 ///	<para />
 ///	The entire array (indexes 0 through length-1) is used as the content.
 ///	</summary>
 ///	<param name="input">
 ///	the content array. The array is never modified, so passing
 ///	through cached arrays is safe.
 /// </param>
 public RawText(byte[] input)
 {
     content = input;
     lines   = RawParseUtils.lineMap(content, 0, content.Length);
     hashes  = computeHashes();
 }