Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Tool to convert the output of git diff to JSON for further processing

License

Notifications You must be signed in to change notification settings

petereon/diffparser

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

diffparser

Tool to convert the output of git diff to JSON for further processing.

Please note, for the most part this is an exercise of parsing simple structured text in Haskell and I do not promise support or feature-completeness.

Example

Consider a git diff output looking as such:

diff --git a/factorial.py b/factorial.py
index abcdef1..1234567 100644
--- a/factorial.py
+++ b/factorial.py
@@ -1,6 +1,7 @@
 def factorial(n):
+    # Calculate the factorial of a number recursively
     if n == 0:
         return 1
     else:
-        return n * factorial(n - 1)
+        return n * factorial(n - 1)
 
-num = 5
+num = 6
 print(f"The factorial of {num} is {factorial(num)}")

We can pipe this output to diffparser binary and jq for formatting:

git diff | diffparser | jq

Output:

[
  {
    "oldName": "factorial.py",
    "newName": "factorial.py",
    "index": "index abcdef1..1234567 100644",
    "hunks": [
      {
        "oldRange": {
          "from": 1,
          "range": 6
        },
        "newRange": {
          "from": 1,
          "range": 7
        },
        "lines": [
          {
            "type": "context",
            "line": "def factorial(n):"
          },
          {
            "type": "added",
            "line": "    # Calculate the factorial of a number recursively"
          },
          {
            "type": "context",
            "line": "    if n == 0:"
          },
          {
            "type": "context",
            "line": "        return 1"
          },
          {
            "type": "context",
            "line": "    else:"
          },
          {
            "type": "removed",
            "line": "        return n * factorial(n - 1)"
          },
          {
            "type": "added",
            "line": "        return n * factorial(n - 1)"
          },
          {
            "type": "context",
            "line": ""
          },
          {
            "type": "removed",
            "line": "num = 5"
          },
          {
            "type": "added",
            "line": "num = 6"
          },
          {
            "type": "context",
            "line": "print(f\"The factorial of {num} is {factorial(num)}\")"
          }
        ]
      }
    ]
  }
]

About

Tool to convert the output of git diff to JSON for further processing

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
Morty Proxy This is a proxified and sanitized view of the page, visit original site.