Error() private method

private Error ( byte buf, int ptr, string msg ) : void
buf byte
ptr int
msg string
return void
        internal override int ParseBody(NGit.Patch.Patch script, int end)
        {
            byte[] buf = file.buf;
            int    c   = RawParseUtils.NextLF(buf, startOffset);

            foreach (CombinedHunkHeader.CombinedOldImage o in old)
            {
                o.nDeleted = 0;
                o.nAdded   = 0;
                o.nContext = 0;
            }
            nContext = 0;
            int nAdded = 0;

            for (int eol; c < end; c = eol)
            {
                eol = RawParseUtils.NextLF(buf, c);
                if (eol - c < old.Length + 1)
                {
                    // Line isn't long enough to mention the state of each
                    // ancestor. It must be the end of the hunk.
                    goto SCAN_break;
                }
                switch (buf[c])
                {
                case (byte)(' '):
                case (byte)('-'):
                case (byte)('+'):
                {
                    break;
                }

                default:
                {
                    // Line can't possibly be part of this hunk; the first
                    // ancestor information isn't recognizable.
                    //
                    goto SCAN_break;
                    break;
                }
                }
                int localcontext = 0;
                for (int ancestor = 0; ancestor < old.Length; ancestor++)
                {
                    switch (buf[c + ancestor])
                    {
                    case (byte)(' '):
                    {
                        localcontext++;
                        old[ancestor].nContext++;
                        continue;
                        goto case (byte)('-');
                    }

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

                    case (byte)('+'):
                    {
                        old[ancestor].nAdded++;
                        nAdded++;
                        continue;
                        goto default;
                    }

                    default:
                    {
                        goto SCAN_break;
                        break;
                    }
                    }
                }
                if (localcontext == old.Length)
                {
                    nContext++;
                }
                SCAN_continue :;
            }
            SCAN_break :;
            for (int ancestor_1 = 0; ancestor_1 < old.Length; ancestor_1++)
            {
                CombinedHunkHeader.CombinedOldImage o_1 = old[ancestor_1];
                int cmp = o_1.nContext + o_1.nDeleted;
                if (cmp < o_1.lineCount)
                {
                    int missingCnt = o_1.lineCount - cmp;
                    script.Error(buf, startOffset, MessageFormat.Format(JGitText.Get().truncatedHunkLinesMissingForAncestor
                                                                        , Sharpen.Extensions.ValueOf(missingCnt), Sharpen.Extensions.ValueOf(ancestor_1
                                                                                                                                             + 1)));
                }
            }
            if (nContext + nAdded < newLineCount)
            {
                int missingCount = newLineCount - (nContext + nAdded);
                script.Error(buf, startOffset, MessageFormat.Format(JGitText.Get().truncatedHunkNewLinesMissing
                                                                    , Sharpen.Extensions.ValueOf(missingCount)));
            }
            return(c);
        }
Esempio n. 2
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);
        }