Example #1
0
        internal virtual int ParseBody(NGit.Patch.Patch script, int end)
        {
            byte[] buf = file.buf;
            int c = RawParseUtils.NextLF(buf, startOffset);
            int last = c;
            old.nDeleted = 0;
            old.nAdded = 0;
            for (; c < end; last = c, c = RawParseUtils.NextLF(buf, c))
            {
                switch (buf[c])
                {
                    case (byte)(' '):
                    case (byte)('\n'):
                    {
                        nContext++;
                        continue;
                        goto case (byte)('-');
                    }

                    case (byte)('-'):
                    {
                        old.nDeleted++;
                        continue;
                        goto case (byte)('+');
                    }

                    case (byte)('+'):
                    {
                        old.nAdded++;
                        continue;
                        goto case (byte)('\\');
                    }

                    case (byte)('\\'):
                    {
                        // Matches "\ No newline at end of file"
                        continue;
                        goto default;
                    }

                    default:
                    {
                        goto SCAN_break;
                        break;
                    }
                }
            SCAN_continue: ;
            }
            SCAN_break: ;
            if (last < end && nContext + old.nDeleted - 1 == old.lineCount && nContext + old.
                nAdded == newLineCount && RawParseUtils.Match(buf, last, NGit.Patch.Patch.SIG_FOOTER
                ) >= 0)
            {
                // This is an extremely common occurrence of "corruption".
                // Users add footers with their signatures after this mark,
                // and git diff adds the git executable version number.
                // Let it slide; the hunk otherwise looked sound.
                //
                old.nDeleted--;
                return last;
            }
            if (nContext + old.nDeleted < old.lineCount)
            {
                int missingCount = old.lineCount - (nContext + old.nDeleted);
                script.Error(buf, startOffset, MessageFormat.Format(JGitText.Get().truncatedHunkOldLinesMissing
                    , missingCount));
            }
            else
            {
                if (nContext + old.nAdded < newLineCount)
                {
                    int missingCount = newLineCount - (nContext + old.nAdded);
                    script.Error(buf, startOffset, MessageFormat.Format(JGitText.Get().truncatedHunkNewLinesMissing
                        , missingCount));
                }
                else
                {
                    if (nContext + old.nDeleted > old.lineCount || nContext + old.nAdded > newLineCount)
                    {
                        string oldcnt = old.lineCount + ":" + newLineCount;
                        string newcnt = (nContext + old.nDeleted) + ":" + (nContext + old.nAdded);
                        script.Warn(buf, startOffset, MessageFormat.Format(JGitText.Get().hunkHeaderDoesNotMatchBodyLineCountOf
                            , oldcnt, newcnt));
                    }
                }
            }
            return c;
        }