Ejemplo n.º 1
0
        /**
         * Tests the performance of MyersDiff for texts which are similar (not
         * random data). The CPU time is measured and returned. Because of bad
         * accuracy of CPU time information the diffs are repeated. During each
         * repetition the interim CPU time is checked. The diff operation is
         * repeated until we have seen the CPU time clock changed its value at least
         * {@link #minCPUTimerTicks} times.
         *
         * @param characters
         *            the size of the diffed character sequences.
         * @return performance data
         */
        private PerfData test(int characters)
        {
            PerfData  ret            = new PerfData();
            string    a              = DiffTestDataGenerator.generateSequence(characters, 971, 3);
            string    b              = DiffTestDataGenerator.generateSequence(characters, 1621, 5);
            CharArray ac             = new CharArray(a);
            CharArray bc             = new CharArray(b);
            MyersDiff myersDiff      = null;
            int       cpuTimeChanges = 0;
            long      lastReadout    = 0;
            long      interimTime    = 0;
            int       repetitions    = 0;

            stopwatch.start();
            while (cpuTimeChanges < minCPUTimerTicks && interimTime < longTaskBoundary)
            {
                myersDiff = new MyersDiff(ac, bc);
                repetitions++;
                interimTime = stopwatch.readout();
                if (interimTime != lastReadout)
                {
                    cpuTimeChanges++;
                    lastReadout = interimTime;
                }
            }
            ret.runningTime = stopwatch.stop() / repetitions;
            ret.N           = (ac.size() + bc.size());
            ret.D           = myersDiff.getEdits().size();

            return(ret);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a line-based diff from the the given byte arrays.
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        public Diff(byte[] a, byte[] b)
        {
            m_sequence_a = new Text(a);
            m_sequence_b = new Text(b);
            var diff = new MyersDiff((RawText)m_sequence_a, (RawText)m_sequence_b);             // <--- using the undocumented cast operator of Text

            m_edits = diff.getEdits();
        }
Ejemplo n.º 5
0
        public void assertDiff(string a, string b, string edits)
        {
            MyersDiff diff = new MyersDiff(toCharArray(a), toCharArray(b));

            Assert.AreEqual(edits, toString(diff.getEdits()));
        }