• Stars
    star
    15,946
  • Rank 1,696 (Top 0.04 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 5 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

a structural diff that understands syntax 🟥🟩

it's difftastic!
English manual Chinese manual crates.io codecov.io

Difftastic is a structural diff tool that compares files based on their syntax.

For installation instructions, see Installation in the manual.

Basic Example

Screenshot of difftastic and JS

In this JavaScript example, we can see:

(1) Difftastic understands nesting. It highlights the matching { and }, but understands that foo() hasn't changed despite the leading whitespace.

(2) Difftastic understands which lines should be aligned. It's aligned bar(1) on the left with bar(2) on the right, even though the textual content isn't identical.

(3) Difftastic understands that line-wrapping isn't meaningful. "eric" is now on a new line, but it hasn't changed.

One Minute Demo

asciicast

This one minute screencast demonstrates difftastic usage with both standalone files and git.

Languages

Difftastic supports over 30 programming languages, see the manual for the full list.

If a file has an unrecognised extension, difftastic uses a textual diff with word highlighting.

Known Issues

Performance. Difftastic scales relatively poorly on files with a large number of changes, and can use a lot of memory.

Display. Difftastic has a side-by-side display which usually works well, but can be confusing.

Robustness. Difftastic regularly has releases that fix crashes.

Non-goals

Patching. Difftastic output is intended for human consumption, and it does not generate patches that you can apply later. Use diff if you need a patch.

(Patch files are also line-oriented, which is too limited for difftastic. Difftastic might find additions and removals on the same line, and it tracks the relationship between line numbers in the old and new file.)

Merging. AST merging is a hard problem that difftastic does not address.

FAQ

Isn't this basically --word-diff --ignore-all-space?

Word diffing can't do this.

Difftastic parses your code. It understands when whitespace matters, such as inside string literals or languages like Python. It understands that x-1 is three tokens in JS but one token in Lisp.

Can I use difftastic with git?

You can! The difftastic manual includes instructions for git usage. You can also use it with mercurial.

If you're a magit user, check out this blog post showing one way to use difftastic with magit.

Does difftastic integrate with my favourite tool?

Probably not. Difftastic is young. Consider writing a plugin for your favourite tool, and I will link it in the README!

Can difftastic help me with merge conflicts?

Yes! As of version 0.50, difftastic understands merge conflict markers (i.e. <<<<<<<, ======= and >>>>>>>).

Pass your file with conflicts as a single argument to difftastic. Difftastic will construct the two conflicting files and diff those.

$ difft file_with_conflicts.js

Can difftastic do merges?

No. AST merging is a hard problem that difftastic does not address.

AST diffing is a also lossy process from the perspective of a text diff. Difftastic will ignore whitespace that isn't syntactically significant, but merging requires tracking whitespace.

Can I use difftastic to check for syntactic changes without diffing?

Yes. Difftastic can check if the two files have the same AST, without calculating a diff. This is much faster than normal diffing, and useful for building tools that check for changes.

For example:

$ difft --check-only --exit-code before.js after.js

This will set the exit code to 0 if there are no syntactic changes, or 1 if there are changes found.

How does it work?

Difftastic treats structural diffing as a graph problem, and uses Dijkstra's algorithm.

My blog post describes the design, and there is also an internals section in the manual.

Translation

License

Difftastic is open source under the MIT license, see LICENSE for more details.

This repository also includes tree-sitter parsers by other authors in the vendored_parsers/ directory. These are a mix of the MIT license and the Apache license. See vendored_parsers/*/LICENSE for more details.

Files in sample_files/ are also under the MIT license unless stated otherwise in their header.

More Repositories

1

helpful

A better Emacs *help* buffer
Emacs Lisp
972
star
2

deadgrep

fast, friendly searching with ripgrep and Emacs
Emacs Lisp
671
star
3

ag.el

An Emacs frontend to The Silver Searcher
Emacs Lisp
521
star
4

babyc

A toy C compiler
C
496
star
5

bfc

An industrial-grade brainfuck compiler
Rust
479
star
6

suggest.el

discover elisp functions that do what you want
Emacs Lisp
344
star
7

emacs-refactor

language-specific refactoring in Emacs
Emacs Lisp
341
star
8

ht.el

The missing hash table library for Emacs
Emacs Lisp
235
star
9

elisp-refs

semantic code search for emacs lisp
Emacs Lisp
111
star
10

refine

interactive value editing in emacs lisp
Emacs Lisp
85
star
11

tco.el

Tail call optimisation in Emacs lisp
Emacs Lisp
76
star
12

pyimport

Manage Python imports from Emacs!
Emacs Lisp
73
star
13

mustache.el

A mustache templating library for Emacs
Emacs Lisp
68
star
14

elisp-def

Find Emacs Lisp definitions
Emacs Lisp
61
star
15

propcheck

Quickcheck/hypothesis style testing for elisp
Emacs Lisp
59
star
16

.emacs.d

My emacs configuration
Emacs Lisp
52
star
17

pip-requirements.el

Major mode for editing pip requirements files
Emacs Lisp
51
star
18

tree-sitter-elisp

tree-sitter grammar for emacs lisp
C
46
star
19

loop.el

friendly imperative loop structures for Emacs lisp
Emacs Lisp
36
star
20

simpla-vortaro

Inteligenta vortaro de Esperanto / An intelligent Esperanto dictionary
Python
34
star
21

python-info

The python manual in texinfo format, particularly for Emacs users
Makefile
31
star
22

Brainfrack

BF implementations in different languages
Smalltalk
29
star
23

bison-mode

Emacs major mode for Bison/Jison, Yacc and Lex grammars
Emacs Lisp
27
star
24

garden

an interactive programming language
Rust
26
star
25

company-try-hard

Get all completions from company-mode backends
Emacs Lisp
24
star
26

Minimal-scheme

A simple scheme interpreter in Python
Python
23
star
27

logstash-conf.el

Emacs major mode for editing logstash configuration files
Emacs Lisp
21
star
28

trifle

A friendly lisp with a focus on interactivity and collaboration
Python
21
star
29

django-test-mixins

Additional assertions and test conveniences for testing django sites
Python
19
star
30

linkdoc

Rust tool for finding dead links on a site
Rust
14
star
31

cask-mode

Major mode for editing Cask files
Emacs Lisp
12
star
32

flymake-jshint.el

JSHint with flymake for Emacs
Emacs Lisp
12
star
33

emacsbench

Benchmarking Emacs itself
C
12
star
34

Blackjack

Simple blackjack simulator in Haskell
Haskell
11
star
35

flycheck-title

show flycheck errors in the frame title
Emacs Lisp
11
star
36

flycheck-pyflakes

flycheck support for pyflakes
Emacs Lisp
10
star
37

flycheck-pkg-config

Configure flycheck using pkg-config
Emacs Lisp
10
star
38

dotfiles

Configuration files for unix utilities
Shell
10
star
39

ReVo-utilities

a few handy scripts to work with XML dumps from ReVo
XSLT
10
star
40

Lython

Toy Lisp to Python compiler
Python
9
star
41

ez-query-replace

query-replace in Emacs with smarts and history!
Emacs Lisp
9
star
42

mal_pharo

A Make A Lisp implementation in Pharo
Smalltalk
8
star
43

FuzzyBranch

git-checkout with fuzzy branch names
Haskell
7
star
44

peval

partial evaluator for elisp
Emacs Lisp
6
star
45

wilfred.github.com

My personal blog
HTML
6
star
46

versor

Mirror of https://sourceforge.net/projects/emacs-versor/
Emacs Lisp
5
star
47

django-function-cache

Cache (memoize) a function's output using Django's caching API
Python
5
star
48

elisp-complete

Emacs Lisp
5
star
49

metawiki

Proof-of-concept self-hosting metawiki
JavaScript
5
star
50

line-numbers

accessing line numbers by string offsets
Rust
4
star
51

autotoc

Generate and insert tables of contents in markdown files
Clojure
4
star
52

elisp-fu

Emacs Lisp
4
star
53

oosh

Object Oriented Shell
Python
4
star
54

the_end_times

comparing programming language implementation performance
Ruby
4
star
55

company-smart-elisp

a contextual company backend for elisp
Emacs Lisp
4
star
56

podkastaro

Podcast aggregator, targeted at Esperanto radio
PHP
3
star
57

gameboy_emulator

Rust code following along with http://imrannazar.com/GameBoy-Emulation-in-JavaScript
Rust
3
star
58

HandyBot

IRC Bot in Clojure
Clojure
3
star
59

with-namespace.el

interoperable elisp namespaces
Emacs Lisp
3
star
60

advent-of-code

Racket
2
star
61

not-quite-modal.el

Modal-inspired movement in Emacs
Emacs Lisp
2
star
62

srch

Emacs Lisp
2
star
63

sudoku

A sudoku solver in CoffeeScript
CSS
2
star
64

userinfo

cross-platform user details library in Rust
Rust
2
star
65

nmap-service

A service for telling clients what ports they have open
Python
2
star
66

smart-eval.el

helpful eval and re-eval for elisp
Emacs Lisp
2
star
67

Jeweled

A Bejeweled bot
Python
2
star
68

elisp-index

Emacs Lisp
2
star
69

Picky

An opinionated wiki
JavaScript
2
star
70

expenses

Categorising and analysing personal expenses
Python
1
star
71

ButlerBot

Haskell news email bot
Haskell
1
star
72

syntax-cafe

programming languages to suit all tastes
TypeScript
1
star
73

podkastaro2

Nova versio de Podkastaro, uzanta Django-n
Python
1
star
74

commonmark-extract-text

extract plain text from commonmark/markdown source
JavaScript
1
star
75

hubot-tube-status

A hubot script for getting the current tube status
CoffeeScript
1
star
76

bf_bench

BF implementation benchmarking
Brainfuck
1
star
77

rustls.el

Emacs Lisp
1
star
78

emailomatic

web scraper for collecting interesting events to attend
Clojure
1
star
79

sooty

a dumb lisp with a handwritten GC
Rust
1
star
80

chrome_crash_example

JavaScript
1
star
81

parsimonious

Simple command line calculator using hand written parser
Java
1
star
82

commonmark-wikiwords

Convert WikiWords to links in commonmark source
JavaScript
1
star
83

zorklike

a text adventure game inspired web page
JavaScript
1
star
84

is_my_internet_filtered

A website that tests whether any content is being filtered
JavaScript
1
star
85

dumb-code-quick

more tests, less code
TypeScript
1
star
86

blog-comments

a simple blog comments system in Clojure
Clojure
1
star