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)); } }
private int ParseGitBinary(FileHeader fh, int c, int end) { var postImage = new BinaryHunk(fh, c); int nEnd = postImage.parseHunk(c, end); if (nEnd < 0) { // Not a binary hunk. // error(fh.Buffer, c, "Missing forward-image in GIT binary patch"); return c; } c = nEnd; postImage.endOffset = c; fh.ForwardBinaryHunk = postImage; var 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 ParseDiffGit(byte[] buf, int start, int end) { var fileHeader = new FileHeader(buf, start); int ptr = fileHeader.parseGitFileName(start + DiffGit.Length, end); if (ptr < 0) { return SkipFile(buf, start); } ptr = fileHeader.parseGitHeaders(ptr, end); ptr = ParseHunks(fileHeader, ptr, end); fileHeader.EndOffset = ptr; addFile(fileHeader); return ptr; }
/** * Add a single file to this patch. * <para /> * 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); }
internal HunkHeader(FileHeader fh, int offset, OldImage oi) { _file = fh; _startOffset = offset; _oldImage = oi; }
public OldImage(FileHeader fh) : this(fh, fh.getOldId()) { }
public BinaryHunk(FileHeader fh, int offset) { file = fh; startOffset = offset; }
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) : this(fh, offset, new OldImage(fh)) { }
public CombinedOldImage(FileHeader fh, int imagePos) : base(fh, ((CombinedFileHeader)fh).getOldId(imagePos)) { _imagePos = imagePos; }
public OldImage(FileHeader fh, AbbreviatedObjectId id) { _fh = fh; _id = id; }
private int ParseHunks(FileHeader fh, int c, int end) { byte[] buf = fh.Buffer; 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, DiffGit) >= 0) break; if (RawParseUtils.match(buf, c, DiffCc) >= 0) break; if (RawParseUtils.match(buf, c, DiffCombined) >= 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.ParentCount) { 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, SigFooter) < 0) warn(buf, c, "Unexpected hunk trailer"); break; } } continue; } int eol = RawParseUtils.nextLF(buf, c); if (fh.Hunks.isEmpty() && RawParseUtils.match(buf, c, GitBinary) >= 0) { fh.PatchType = FileHeader.PatchTypeEnum.GIT_BINARY; return ParseGitBinary(fh, eol, end); } if (fh.Hunks.isEmpty() && BinTrailer.Length < eol - c && RawParseUtils.match(buf, eol - BinTrailer.Length, BinTrailer) >= 0 && MatchAny(buf, c, BinHeaders)) { // The patch is a binary file diff, with no deltas. // fh.PatchType = FileHeader.PatchTypeEnum.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.Hunks.isEmpty() && fh.getPatchType() == FileHeader.PatchTypeEnum.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.PatchTypeEnum.BINARY; } return c; }
private int ParseTraditionalPatch(byte[] buf, int start, int end) { var fh = new FileHeader(buf, start); int ptr = fh.parseTraditionalHeaders(start, end); ptr = ParseHunks(fh, ptr, end); fh.EndOffset = ptr; addFile(fh); return ptr; }
private static void AssertParse(FileHeader fh) { int ptr = fh.parseGitFileName(0, fh.Buffer.Length); Assert.IsTrue(ptr > 0); ptr = fh.parseGitHeaders(ptr, fh.Buffer.Length); Assert.IsTrue(ptr > 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()); }