4 ms·
It'd be even nicer if git could figure it out. From those two examples only, looks like fewer hunks are better, but so are smaller hunks, at least when the num
by swinglock 6y ago
It'd be even nicer if git could figure it out.
From those two examples only, looks like fewer hunks are better, but so are smaller hunks, at least when the number of hunks are equal.
- GolDDranks 6y agoI hazard a guess that there doesn't exist a simple heuristic (such as "number of chunks") that always does the right thing. I think that to achieve better diffs, the diff tool should have some understanding over the structural properties of the language – but that would, of course, mean that the diff tool should be different for each language. (Or more like, there should be a parsing frontend that parses a "labeled tree" structure, and then a generic diffing algorithm over those kinds of trees.)
- yencabulator 6y agogit's diff already has language-specific configurability, for example xfuncname sets a "function declaration" or similar header (e.g. markdown heading, org-mode section) that is shown in a diff. Similarly, one could imagine a language-specific regexp that gives "anchor points" such as declaration start, where one would prefer that a single diff hunk doesn't mutate things across that anchor, if it doesn't have to.