예제 #1
0
 public CombinedHunkHeader(FileHeader fh, int offset)
     : base(fh, offset, null)
 {
     int size = fh.ParentCount;
     _old = new List<CombinedOldImage>(size);
     for (int i = 0; i < size; i++)
     {
         _old.Add(new CombinedOldImage(fh, i));
     }
 }
예제 #2
0
	    /**
	     * Add a single file to this patch.
	     * <p>
	     * Typically files should be added by parsing the text through one of this
	     * class's parse methods.
	     *
	     * @param fh
	     *            the header of the file.
	     */
	    public void addFile(FileHeader fh)
        {
		    files.Add(fh);
	    }
예제 #3
0
	    private int parseGitBinary(FileHeader fh, int c, int end) {
		    BinaryHunk postImage = new BinaryHunk(fh, c);
		    int nEnd = postImage.parseHunk(c, end);
		    if (nEnd < 0) {
			    // Not a binary hunk.
			    //
			    error(fh.buf, c, "Missing forward-image in GIT binary patch");
			    return c;
		    }
		    c = nEnd;
		    postImage.endOffset = c;
		    fh.forwardBinaryHunk = postImage;

		    BinaryHunk preImage = new BinaryHunk(fh, c);
		    int oEnd = preImage.parseHunk(c, end);
		    if (oEnd >= 0) {
			    c = oEnd;
			    preImage.endOffset = c;
			    fh.reverseBinaryHunk = preImage;
		    }

		    return c;
	    }
예제 #4
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)
							    warn(buf, c, "Unexpected hunk trailer");
                            break;
					    }
				    }
				    continue;
			    }

			    int eol = RawParseUtils.nextLF(buf, c);
			    if (fh.getHunks().isEmpty() && RawParseUtils.match(buf, c, GIT_BINARY) >= 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
					    && 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;
	    }
예제 #5
0
	    private int parseTraditionalPatch(byte[] buf, int start, int end)
        {
		    FileHeader fh = new FileHeader(buf, start);
		    int ptr = fh.parseTraditionalHeaders(start, end);
		    ptr = parseHunks(fh, ptr, end);
		    fh.endOffset = ptr;
		    addFile(fh);
		    return ptr;
	    }
예제 #6
0
	    private int parseDiffGit(byte[] buf, int start, int end)
        {
		    FileHeader fh = new FileHeader(buf, start);
		    int ptr = fh.parseGitFileName(start + DIFF_GIT.Length, end);
		    if (ptr < 0)
			    return skipFile(buf, start);

		    ptr = fh.parseGitHeaders(ptr, end);
		    ptr = parseHunks(fh, ptr, end);
		    fh.endOffset = ptr;
		    addFile(fh);
		    return ptr;
	    }
예제 #7
0
 internal HunkHeader(FileHeader fh, int offset, OldImage oi)
 {
     _file = fh;
     _startOffset = offset;
     _oldImage = oi;
 }
예제 #8
0
 public OldImageInstance(FileHeader fh)
 {
     this.fh = fh;
 }
예제 #9
0
 public OldImage(FileHeader fh, AbbreviatedObjectId id)
 {
     _fh = fh;
     _id = id;
 }
예제 #10
0
 public OldImage(FileHeader fh)
     : this(fh, fh.getOldId())
 {
 }
예제 #11
0
 public CombinedOldImage(FileHeader fh, int imagePos)
     : base(fh, ((CombinedFileHeader)fh).getOldId(imagePos))
 {
     _imagePos = imagePos;
 }
예제 #12
0
	    private static void assertParse(FileHeader fh)
        {
		    int ptr = fh.parseGitFileName(0, fh.buf.Length);
		    Assert.IsTrue(ptr > 0);
		    ptr = fh.parseGitHeaders(ptr, fh.buf.Length);
		    Assert.IsTrue(ptr > 0);
	    }
 private void Init(string name)
 {
     a = new RawText(ReadFile(name + "_PreImage"));
     b = new RawText(ReadFile(name + "_PostImage"));
     file = ParseTestPatchFile(DiffsDir + name + ".patch").getFiles()[0];
 }
예제 #14
0
	    public HunkHeader(FileHeader fh, int offset, OldImage oi)
        {
		    file = fh;
		    startOffset = offset;
		    old = oi;
	    }
예제 #15
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>
        public void format(Stream @out, FileHeader head, RawText a, RawText b)
        {
            // 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());
        }
예제 #16
0
	    public BinaryHunk(FileHeader fh, int offset)
        {
		    file = fh;
		    startOffset = offset;
	    }
예제 #17
0
 public HunkHeader(FileHeader fh, int offset)
     : this(fh, offset, new OldImage(fh))
 {
 }