jeffkaufman/icdiff

Add Support for custom patch hunk headers (with some builtins)

paulcavallaro opened this issue · 1 comments

From gitattributes(5) documentation: https://git-scm.com/docs/gitattributes#_defining_a_custom_hunk_header

Each group of changes (called a "hunk") in the textual diff output is prefixed with a line of the form:

@@ -k,l +n,m @@ TEXT

This is called a hunk header. The "TEXT" portion is by default a line that begins with an alphabet, an underscore or a dollar sign; this matches what GNU diff -p output uses. This default selection however is not suited for some contents, and you can use a customized pattern to make a selection.

git diff seems to ship with a number of built-in patterns for a good number of common languages.

While I am less interested in the exact format, the ability for the hunk to be prefixed with helpful contextual information, e.g., the function name where the change takes place is quite useful, for example:

@@ -107,6 +109,7 @@ class ConsoleDiff(object):
         self.highlight = highlight
         self.strip_trailing_cr = strip_trailing_cr
         self.truncate = truncate
+        self.ignore_case = ignore_case

The prefix line with class ConsoleDiff(object): gives us valuable context clues when looking at the subsequent diff.

Filing this as a potential feature request to add if someone has time to look at this more deeply.

Thanks for the suggestion! I'd be happy to have something along these lines, though I don't think I will get around to implementing it