Exemple #1
0
 private static void WriteLine(Stream @out, char prefix, RawText text, int cur)
 {
     @out.WriteByte(Convert.ToByte(prefix));
     text.writeLine(@out, cur);
     @out.WriteByte(Convert.ToByte('\n'));
     if (cur + 1 == text.size() && text.isMissingNewlineAtEnd())
     {
         @out.Write(NoNewLine, 0, NoNewLine.Length);
     }
 }
Exemple #2
0
 internal Text(RawText raw_text, Encoding encoding)
 {
     m_raw_text = raw_text;
     Encoding = encoding;
 }
Exemple #3
0
        /*
        /// <summary>
        /// Format a patch script, reusing a previously parsed FileHeader.
        ///	<para />
        ///	This formatter is primarily useful for editing an existing patch script
        ///	to increase or reduce the number of lines of context within the script.
        ///	All header lines are reused as-is from the supplied FileHeader.
        /// </summary>
        /// <param name="out">stream to write the patch script out to.</param>
        /// <param name="head">existing file header containing the header lines to copy.</param>
        /// <param name="a">
        /// Text source for the pre-image version of the content.
        /// This must match the content of <seealso cref="FileHeader.getOldId()"/>.
        /// </param>
        /// <param name="b">writing to the supplied stream failed.</param>
        internal void format(Stream @out, FileHeader head, RawText a, RawText b)
        {
            if ( head == null)
            {
                throw new System.ArgumentNullException("head");
            }
            if ( @out == null)
            {
                throw new System.ArgumentNullException("out");
            }

            // Reuse the existing FileHeader as-is by blindly copying its
            // header lines, but avoiding its hunks. Instead we recreate
            // the hunks from the text instances we have been supplied.
            //
            int start = head.StartOffset;
            int end = head.EndOffset;

            if (!head.Hunks.isEmpty())
            {
                end = head.Hunks[0].StartOffset;
            }

            @out.Write(head.Buffer, start, end - start);

            FormatEdits(@out, a, b, head.ToEditList());
        }
        */
        /// <summary>
        /// Formats a list of edits in unified diff format
        /// </summary>
        /// <param name="out">where the unified diff is written to</param>
        /// <param name="a">the text A which was compared</param>
        /// <param name="b">the text B which was compared</param>
        /// <param name="edits">some differences which have been calculated between A and B</param>
        internal void FormatEdits(Stream @out, RawText a, RawText b, EditList edits)
        {
            for (int curIdx = 0; curIdx < edits.Count; /* */)
            {
                Edit curEdit = edits.get(curIdx);
                int endIdx = FindCombinedEnd(edits, curIdx);
                Edit endEdit = edits.get(endIdx);

                int aCur = Math.Max(0, curEdit.BeginA - _context);
                int bCur = Math.Max(0, curEdit.BeginB - _context);
                int aEnd = Math.Min(a.size(), endEdit.EndA + _context);
                int bEnd = Math.Min(b.size(), endEdit.EndB + _context);

                WriteHunkHeader(@out, aCur, aEnd, bCur, bEnd);

                while (aCur < aEnd || bCur < bEnd)
                {
                    if (aCur < curEdit.BeginA || endIdx + 1 < curIdx)
                    {
                        WriteLine(@out, ' ', a, aCur);
                        aCur++;
                        bCur++;
                    }
                    else if (aCur < curEdit.EndA)
                    {
                        WriteLine(@out, '-', a, aCur++);

                    }
                    else if (bCur < curEdit.EndB)
                    {
                        WriteLine(@out, '+', b, bCur++);
                    }

                    if (End(curEdit, aCur, bCur) && ++curIdx < edits.Count)
                    {
                        curEdit = edits.get(curIdx);
                    }
                }
            }
        }
Exemple #4
0
        private static bool equals(RawText a, int ai, RawText b, int bi)
        {
            if (a.hashes.get(ai) != b.hashes.get(bi))
                return false;

            int a_start = a.lines.get(ai);
            int b_start = b.lines.get(bi);
            int a_end = a.lines.get(ai + 1);
            int b_end = b.lines.get(bi + 1);

            if (a_end - a_start != b_end - b_start)
                return false;

            while (a_start < a_end) {
                if (a.content[a_start++] != b.content[b_start++])
                    return false;
            }
            return true;
        }