git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[JGIT PATCH 0/5] Patch parsing API

From
Shawn O. Pearce <spearce@spearce.org>
Date
Dec 11, 2008, 04:58 UTC
Message-ID
<1228971522-28764-1-git-send-email-spearce@spearce.org>

This is an API to parse a Git style patch file and extract the critical metadata from the header lines, including the hunk headers and what lines they correspond to in the pre and post image files.

It requires the two other series I already sent out today for QuotedString and AbbreviatedObjectId.

There's TODO markers left where we still need to insert code to create some sort of warning object, and then hang the warnings off the Patch class. Given the size of the code I'm inclined to do that as yet an additional patch, rather than squash it into this series.

My short-term roadmap related to this part of JGit:
 * Compute and collect warnings from malformed git-style patches
 * Correctly parse "git diff --cc" style output
 * Get it into egit.git

I'm stopping development once I have the diff --cc output parsing correctly. My rationale is right now I need the patch metadata parsing in Gerrit 2, so that's what I'm teaching JGit to do. Maybe later in the month or early next I'll add patch application support, because I also want that in Gerrit 2. Patch application is not currently a blocking item for me; but reading the patch metadata is.

Traditional patch support is really stubbed out too; there's a very small subset of traditional (non-git) style patches this code can scan the metadata from, but no tests to verify it. Gerrit 2 gets all of its data from a "git diff" process, so I only need support for git diffs right now. Yes, I'd like to add traditional patch support too, but it won't be until later in 2009 that I would even think about working on that myself.

Shawn O. Pearce (5):
  Add toByteArray() to TemporaryBuffer
  Add copy(InputStream) to TemporaryBuffer
  Define FileHeader to parse the header block of a git diff
  Define Patch to parse a sequence of patch FileHeaders
  Add HunkHeader to represent a single hunk of a file within a patch
 .../tst/org/spearce/jgit/patch/FileHeaderTest.java |  395 ++++++++++++++++
 .../tst/org/spearce/jgit/patch/PatchTest.java      |  155 +++++++
 .../patch/testParse_ConfigCaseInsensitive.patch    |   67 +++
 .../src/org/spearce/jgit/patch/FileHeader.java     |  480 ++++++++++++++++++++
 .../src/org/spearce/jgit/patch/HunkHeader.java     |  185 ++++++++
 .../src/org/spearce/jgit/patch/Patch.java          |  267 +++++++++++
 .../src/org/spearce/jgit/util/TemporaryBuffer.java |   51 ++
 7 files changed, 1600 insertions(+), 0 deletions(-)
 create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/FileHeaderTest.java
 create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchTest.java
 create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_ConfigCaseInsensitive.patch
 create mode 100644 org.spearce.jgit/src/org/spearce/jgit/patch/FileHeader.java
 create mode 100644 org.spearce.jgit/src/org/spearce/jgit/patch/HunkHeader.java
 create mode 100644 org.spearce.jgit/src/org/spearce/jgit/patch/Patch.java
Next: Shawn O. Pearce
Message 1 of 15 in “Patch parsing API”
  1. 0/5 Patch parsing APIShawn O. Pearce, Dec 11, 2008
  2. 1/5 Add toByteArray() to TemporaryBufferShawn O. Pearce, Dec 11, 2008
  3. 2/5 Add copy(InputStream) to TemporaryBufferShawn O. Pearce, Dec 11, 2008
  4. 3/5 Define FileHeader to parse the header block of a git diffShawn O. Pearce, Dec 11, 2008
  5. 4/5 Define Patch to parse a sequence of patch FileHeadersShawn O. Pearce, Dec 11, 2008
  6. 5/5 Add HunkHeader to represent a single hunk of a file within a patchShawn O. Pearce, Dec 11, 2008
  7. Robin RosenbergDec 11, 2008
  8. Shawn O. PearceDec 11, 2008
  9. Robin RosenbergDec 11, 2008
  10. Shawn O. PearceDec 11, 2008
  11. Robin RosenbergDec 11, 2008
  12. Shawn O. PearceDec 11, 2008
  13. Robin RosenbergDec 11, 2008
  14. Shawn O. PearceDec 11, 2008
  15. 2/5 Add copy(InputStream) to TemporaryBufferShawn O. Pearce, Dec 11, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.