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)); } }
/** * 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); }
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; }
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; }
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; }
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; }
internal HunkHeader(FileHeader fh, int offset, OldImage oi) { _file = fh; _startOffset = offset; _oldImage = oi; }
public OldImageInstance(FileHeader fh) { this.fh = fh; }
public OldImage(FileHeader fh, AbbreviatedObjectId id) { _fh = fh; _id = id; }
public OldImage(FileHeader fh) : this(fh, fh.getOldId()) { }
public CombinedOldImage(FileHeader fh, int imagePos) : base(fh, ((CombinedFileHeader)fh).getOldId(imagePos)) { _imagePos = imagePos; }
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]; }
public HunkHeader(FileHeader fh, int offset, OldImage oi) { file = fh; startOffset = offset; old = oi; }
/// <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()); }
public BinaryHunk(FileHeader fh, int offset) { file = fh; startOffset = offset; }
public HunkHeader(FileHeader fh, int offset) : this(fh, offset, new OldImage(fh)) { }