git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Shawn O. Pearce" <spearce@spearce.org>
To: Robin Rosenberg <robin.rosenberg@dewire.com>
Cc: git@vger.kernel.org
Subject: [JGIT PATCH 1/2] Add raw buffer fetch methods to FileHeader, HunkHeader
Date: Fri, 12 Dec 2008 18:42:25 -0800	[thread overview]
Message-ID: <1229136146-15359-1-git-send-email-spearce@spearce.org> (raw)

These permit application level code to read back the patch
script, for example to slice it up and output parts into a
UI on a per-file or per-hunk basis.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---

 Two last-minute patches.  While using this code in Gerrit 2 I
 realized I forgot to add a way to get the script back after its
 been parsed by the library.  :-)

 .../src/org/spearce/jgit/patch/BinaryHunk.java     |   15 +++++++++++++++
 .../src/org/spearce/jgit/patch/FileHeader.java     |   15 +++++++++++++++
 .../src/org/spearce/jgit/patch/HunkHeader.java     |   15 +++++++++++++++
 3 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/patch/BinaryHunk.java b/org.spearce.jgit/src/org/spearce/jgit/patch/BinaryHunk.java
index 92eab86..f43a1b9 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/patch/BinaryHunk.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/patch/BinaryHunk.java
@@ -81,6 +81,21 @@ public FileHeader getFileHeader() {
 		return file;
 	}
 
+	/** @return the byte array holding this hunk's patch script. */
+	public byte[] getBuffer() {
+		return file.buf;
+	}
+
+	/** @return offset the start of this hunk in {@link #getBuffer()}. */
+	public int getStartOffset() {
+		return startOffset;
+	}
+
+	/** @return offset one past the end of the hunk in {@link #getBuffer()}. */
+	public int getEndOffset() {
+		return endOffset;
+	}
+
 	/** @return type of this binary hunk */
 	public Type getType() {
 		return type;
diff --git a/org.spearce.jgit/src/org/spearce/jgit/patch/FileHeader.java b/org.spearce.jgit/src/org/spearce/jgit/patch/FileHeader.java
index 79e4b0a..7c3a45a 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/patch/FileHeader.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/patch/FileHeader.java
@@ -173,6 +173,21 @@ int getParentCount() {
 		return 1;
 	}
 
+	/** @return the byte array holding this file's patch script. */
+	public byte[] getBuffer() {
+		return buf;
+	}
+
+	/** @return offset the start of this file's script in {@link #getBuffer()}. */
+	public int getStartOffset() {
+		return startOffset;
+	}
+
+	/** @return offset one past the end of the file script. */
+	public int getEndOffset() {
+		return endOffset;
+	}
+
 	/**
 	 * Get the old name associated with this file.
 	 * <p>
diff --git a/org.spearce.jgit/src/org/spearce/jgit/patch/HunkHeader.java b/org.spearce.jgit/src/org/spearce/jgit/patch/HunkHeader.java
index fc149ac..12c670d 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/patch/HunkHeader.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/patch/HunkHeader.java
@@ -123,6 +123,21 @@ public FileHeader getFileHeader() {
 		return file;
 	}
 
+	/** @return the byte array holding this hunk's patch script. */
+	public byte[] getBuffer() {
+		return file.buf;
+	}
+
+	/** @return offset the start of this hunk in {@link #getBuffer()}. */
+	public int getStartOffset() {
+		return startOffset;
+	}
+
+	/** @return offset one past the end of the hunk in {@link #getBuffer()}. */
+	public int getEndOffset() {
+		return endOffset;
+	}
+
 	/** @return information about the old image mentioned in this hunk. */
 	public OldImage getOldImage() {
 		return old;
-- 
1.6.1.rc2.306.ge5d5e

             reply	other threads:[~2008-12-13  2:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-13  2:42 Shawn O. Pearce [this message]
2008-12-13  2:42 ` [JGIT PATCH 2/2] Add getPatchText functions to obtain the plain-text version of a patch Shawn O. Pearce
2008-12-13 11:02   ` Robin Rosenberg
2008-12-13 21:26     ` Robin Rosenberg
2008-12-17 20:13       ` [JGIT PATCH 2/2 v2] Add getScriptText " Shawn O. Pearce

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1229136146-15359-1-git-send-email-spearce@spearce.org \
    --to=spearce@spearce.org \
    --cc=git@vger.kernel.org \
    --cc=robin.rosenberg@dewire.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).