by chriswarbo · 6y ago · 0 comments
I've changed my mind now that they're tracking byte ranges instead of lines, with ranges decided in a customisable way at commit time. Semantic/format-aware versioning would be really nice. The easiest plugins to write would be s-expressions and JSON, and I could definitely see myself choosing Pijul for such repos in the future. If the patch-based approach is truly as nice as it appears, that might push me to use it more generally.
In fact, making an s-expression plugin which is robust across various Lisp dialects might be a good way to bootstrap the user community.
It would be nice to have for other languages too (C, Python, etc.), but they'd (a) be more complicated and (b) more subject to churn.
I explored using an off the shelf syntax highlighting tokenizer (Pygments specifically as a it was a Python prototype) [1] to build character-based diffs. Got surprisingly good results from what I tested. Most off the shelf syntax highlighters support a huge variety of languages. One advantage to using a syntax highlighting tokenizer/lexer is that they are designed to be fast (many of them need to be real time in text editors after all), and handle "degenerate cases" very well (text editors spend a lot of time on work in progress code that doesn't fully describe a complete compilable unit; version control systems just as well need to be good at storing work in progress states).
The finished prototype I built created standard character-based unidiffs, and it sounds like could possibly be slotted directly into Pijul now. I'd be very interested to experiment further with it now that one of the patch algebra VCSes has finally adopted a "chunk" option.
[1] https://github.com/WorldMaker/tokdiff
(ETA: Suppose the first step is that it is time to get the band back together and update the prototype to Python 3.)
> The finished prototype I built created standard character-based unidiffs, and it sounds like could possibly be slotted directly into Pijul now.
The diff algorithm, acting on lines, is pretty generic in Pijul, but there is a crucial and nontrivial pass after that, to get from a line diff to a graph diff.
(Or the vast number of TextMate grammars in the wild, such as editors like VS Code have standardized on.)
The "universality" of tokenizers is tough to beat, and though the tokenizers seem "dumber" than parser brethren, it's at a nice maxima for "good enough" for things like character-based diffs.
I believe the Unison language [1] does this for their code storage system. (Unison does not use traditional text storage but stores code in a normalized repository)
One property you might want would be that, in some sense, parentheses would always remain balanced. I think this would be very hard if not impossible to get from the graph-of-byte-ranges representation. But I’d be excited if someone figured out how to do it.
I think a particular part of the problem is to get the diff algorithm to match parentheses correctly. Consider some changes from A to B:
1A (a b)
1B (a b) (c d)
2A (define p () (a) (b) (c))
2B (define q () (a) (b) ) (define q () (p) (c))
3A (a b c d)
3B (a b) (c d)
4A (a b c )
4B (a b) (c d)
5A (a b c)
5B (a b) (d)
I think in these examples it’s relatively easy to pair up parentheses in a reasonable way though there are already some tricky cases. As you get more of a tree structure and want a diff algorithm that can think of operations like wrapping, splitting, and spreading as basic operations as well as appending and deleting, I think it becomes even harder to make the right call. Indeed I think computing this kind of diff of s-expressions is computationally a harder search problem than diffing files. -def foo()
-{
+def bar()
+{
+ doBarThing;
- doFooThing;
}
There are many ways to represent the same diff, but this sort of half-and-half result happens so often, and is such a minor problem, that it's usually not worth bothering to fix when committing. Yet it's the sort of weird input that can complicate later merges, cherry-picking, etc.A semantic-aware diff could do better. Again, there are many ways to represent the diff, but it could be as fine-grained as the token-level, e.g.
def -foo+bar()
{
-doFooThing+doBarThing;
}
Or as coarse-grained as the definition level, e.g. -def foo()
-{
- doFooThing;
-}
+def bar()
+{
+ doBarThing;
+}
Either way (or something in-between), these represent more meaningful changes, and hence provide more useful input to subsequent processing (e.g. merging).From my understanding of the post:
- Pijul patches were storing raw lines of text
- Word-based diffing was suggested as an option
- This option wasn't implemented due to complexity, and having to decide at repo creation time whether to store lines or words
- Unrelated improvements to Pijul's performance resulted in patches storing offsets into a byte array, rather than raw text
- Since offsets can point anywhere, patches are no longer limited to being line-based
Lines are still the default.