Exemplo n.º 1
0
        private int ParseHunks(FileHeader fh, int c, int end)
        {
            byte[] buf = fh.buf;
            while (c < end)
            {
                // If we see a file header at this point, we have all of the
                // hunks for our current file. We should stop and report back
                // with this position so it can be parsed again later.
                //
                if (RawParseUtils.Match(buf, c, DIFF_GIT) >= 0)
                {
                    break;
                }
                if (RawParseUtils.Match(buf, c, DIFF_CC) >= 0)
                {
                    break;
                }
                if (RawParseUtils.Match(buf, c, DIFF_COMBINED) >= 0)
                {
                    break;
                }
                if (RawParseUtils.Match(buf, c, FileHeader.OLD_NAME) >= 0)
                {
                    break;
                }
                if (RawParseUtils.Match(buf, c, FileHeader.NEW_NAME) >= 0)
                {
                    break;
                }
                if (FileHeader.IsHunkHdr(buf, c, end) == fh.GetParentCount())
                {
                    HunkHeader h = fh.NewHunkHeader(c);
                    h.ParseHeader();
                    c = h.ParseBody(this, end);
                    h.endOffset = c;
                    fh.AddHunk(h);
                    if (c < end)
                    {
                        switch (buf[c])
                        {
                            case (byte)('@'):
                            case (byte)('d'):
                            case (byte)('\n'):
                            {
                                break;
                            }

                            default:
                            {
                                if (RawParseUtils.Match(buf, c, SIG_FOOTER) < 0 && RawParseUtils.Match(buf, c, SIG_FOOTER_WINDOWS) < 0)
                                {
                                    Warn(buf, c, JGitText.Get().unexpectedHunkTrailer);
                                }
                                break;
                            }
                        }
                    }
                    continue;
                }
                int eol = RawParseUtils.NextLF(buf, c);
                if (fh.GetHunks().IsEmpty() && (RawParseUtils.Match(buf, c, GIT_BINARY) >= 0  || RawParseUtils.Match(buf, c, GIT_BINARY_WINDOWS) >= 0))
                {
                    fh.patchType = FileHeader.PatchType.GIT_BINARY;
                    return ParseGitBinary(fh, eol, end);
                }
                if (fh.GetHunks().IsEmpty() &&
                    ((BIN_TRAILER.Length < eol - c && RawParseUtils.Match(buf, eol - BIN_TRAILER.Length, BIN_TRAILER) >= 0 )
                    || (BIN_TRAILER_WINDOWS.Length < eol - c && RawParseUtils.Match(buf, eol - BIN_TRAILER_WINDOWS.Length, BIN_TRAILER_WINDOWS) >= 0))
                    && MatchAny(buf, c, BIN_HEADERS
                    ))
                {
                    // The patch is a binary file diff, with no deltas.
                    //
                    fh.patchType = FileHeader.PatchType.BINARY;
                    return eol;
                }
                // Skip this line and move to the next. Its probably garbage
                // after the last hunk of a file.
                //
                c = eol;
            }
            if (fh.GetHunks().IsEmpty() && fh.GetPatchType() == FileHeader.PatchType.UNIFIED
                && !fh.HasMetaDataChanges())
            {
                // Hmm, an empty patch? If there is no metadata here we
                // really have a binary patch that we didn't notice above.
                //
                fh.patchType = FileHeader.PatchType.BINARY;
            }
            return c;
        }
Exemplo n.º 2
0
        private int ParseHunks(FileHeader fh, int c, int end)
        {
            byte[] buf = fh.buf;
            while (c < end)
            {
                // If we see a file header at this point, we have all of the
                // hunks for our current file. We should stop and report back
                // with this position so it can be parsed again later.
                //
                if (RawParseUtils.Match(buf, c, DIFF_GIT) >= 0)
                {
                    break;
                }
                if (RawParseUtils.Match(buf, c, DIFF_CC) >= 0)
                {
                    break;
                }
                if (RawParseUtils.Match(buf, c, DIFF_COMBINED) >= 0)
                {
                    break;
                }
                if (RawParseUtils.Match(buf, c, FileHeader.OLD_NAME) >= 0)
                {
                    break;
                }
                if (RawParseUtils.Match(buf, c, FileHeader.NEW_NAME) >= 0)
                {
                    break;
                }
                if (FileHeader.IsHunkHdr(buf, c, end) == fh.GetParentCount())
                {
                    HunkHeader h = fh.NewHunkHeader(c);
                    h.ParseHeader();
                    c           = h.ParseBody(this, end);
                    h.endOffset = c;
                    fh.AddHunk(h);
                    if (c < end)
                    {
                        switch (buf[c])
                        {
                        case (byte)('@'):
                        case (byte)('d'):
                        case (byte)('\n'):
                        {
                            break;
                        }

                        default:
                        {
                            if (RawParseUtils.Match(buf, c, SIG_FOOTER) < 0 && RawParseUtils.Match(buf, c, SIG_FOOTER_WINDOWS) < 0)
                            {
                                Warn(buf, c, JGitText.Get().unexpectedHunkTrailer);
                            }
                            break;
                        }
                        }
                    }
                    continue;
                }
                int eol = RawParseUtils.NextLF(buf, c);
                if (fh.GetHunks().IsEmpty() && (RawParseUtils.Match(buf, c, GIT_BINARY) >= 0 || RawParseUtils.Match(buf, c, GIT_BINARY_WINDOWS) >= 0))
                {
                    fh.patchType = FileHeader.PatchType.GIT_BINARY;
                    return(ParseGitBinary(fh, eol, end));
                }
                if (fh.GetHunks().IsEmpty() &&
                    ((BIN_TRAILER.Length < eol - c && RawParseUtils.Match(buf, eol - BIN_TRAILER.Length, BIN_TRAILER) >= 0) ||
                     (BIN_TRAILER_WINDOWS.Length < eol - c && RawParseUtils.Match(buf, eol - BIN_TRAILER_WINDOWS.Length, BIN_TRAILER_WINDOWS) >= 0)) &&
                    MatchAny(buf, c, BIN_HEADERS
                             ))
                {
                    // The patch is a binary file diff, with no deltas.
                    //
                    fh.patchType = FileHeader.PatchType.BINARY;
                    return(eol);
                }
                // Skip this line and move to the next. Its probably garbage
                // after the last hunk of a file.
                //
                c = eol;
            }
            if (fh.GetHunks().IsEmpty() && fh.GetPatchType() == FileHeader.PatchType.UNIFIED &&
                !fh.HasMetaDataChanges())
            {
                // Hmm, an empty patch? If there is no metadata here we
                // really have a binary patch that we didn't notice above.
                //
                fh.patchType = FileHeader.PatchType.BINARY;
            }
            return(c);
        }