GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - codinuum/diffast: Diff/AST: A fine-grained source code differencing tool

BranchesTags
Open more actions menu

Latest commit

 

History

362 Commits
362 Commits

Folders and files

NameName
Last commit message
Last commit date
diffviewer @ efba1cd
diffviewer @ efba1cd
 
 
opam
opam
 
 
samples
samples
 
 
src
src
 
 
.gitignore
.gitignore
 
 
.gitmodules
.gitmodules
 
 
Dockerfile
Dockerfile
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
cca.py
cca.py
 
 
dune
dune
 
 
dune-project
dune-project
 
 
dune-workspace
dune-workspace
 
 
git_ext_diff
git_ext_diff
 
 

Repository files navigation

Diff/AST: A Fine-Grained Source Code Differencing Tool

The tool is currently able to recognize Python, Java, Verilog, Fortran, and C/C++ via dedicated parsers. It compares abstract syntax trees (ASTs) node by node, while popular diff tools compare any (text) files line by line. The algorithm is based on an algorithm for computing tree edit distance (TED) between two ordered labeled trees. The TED between two trees is the minimum (weighted) number of edit operations to transform one tree into another. Unfortunately, however, applying TED algorithms directly to wild ASTs is not feasible in general because their computational complexity is essentially, at best, quadratic according to the number of AST nodes. Therefore Diff/AST makes moderate use of a TED algorithm in a divide-and-conquer manner backed by elaborated heuristics to approximate tree edit distances. Nevertheless, Diff/AST still requires much time for non-trivial massive inputs. Thus it always caches the results.

Diff/AST is able to export ASTs, changes between them, and other syntactic/semantic information as facts in XML or N-Triples. In particular, facts in N-Triples format can be loaded into an RDF store such as Virtuoso to build a factbase or a database of facts. Factbases are intended to be queried for software engineering tasks such as code comprehension, debugging, change pattern mining, and code homology analysis.

Diff/AST is an experimental implementation of the tree differencing algorithm reported in the following paper:

Masatomo Hashimoto and Akira Mori, "Diff/TS: A Tool for Fine-Grained Structural Change Analysis," In Proc. 15th Working Conference on Reverse Engineering, 2008, pp. 279-288, DOI: 10.1109/WCRE.2008.44.

Screenshots

You can see the results of comparing some pairs of source files taken from samples here.

Quick start

You can instantly try Diff/AST by utilizing Docker and a ready-made container image.

$ docker pull codinuum/diffast

The following command line executes Diff/AST within a container to compare sample Java programs and then saves the results in results (host) directory.

$ ./cca.py diffast -c results samples/java/0/Test.java samples/java/1/Test.java

If you want to inspect the AST differences in a viewer window, you have to initialize a submodule diffviewer first.

$ git submodule init
$ git submodule update

See diffviewer/README.md to build the viewer. Once you heve built the viewer, you can run the viewer as follows.

$ diffviewer/run.py -c results samples/java/0/Test.java samples/java/1/Test.java

You can also run both at once.

$ ./cca.py diffast -c results --view samples/java/0/Test.java samples/java/1/Test.java

Installing Diff/AST via OPAM

Requirements

  • OCaml (>=4.14)
  • OPAM (>=2.1)

Installation

The following will install parsesrc and diffast.

$ opam install diffast

Building Diff/AST

You can also build Diff/AST from the source.

Requirements

  • OCaml (>=4.14)
  • Dune (>=3.17)
  • OPAM (>=2.1) (for installing required packages)

Compilation

The following will create ./dist/bin/{parsesrc,diffast}.

$ opam install bytesrw camlp-streams camlzip cryptokit csv dune dune-site git-unix markup menhir sedlex uuidm vlt
$ dune build
$ dune install --relocatable --prefix ./dist

Using with Git

If you have built Diff/AST, you can use it with Git. Add the following lines to your .gitconfig. Note that PATH_TO_THIS_REPO should be replaced by your local path to this repository.

[diff]
    tool = diffast
[difftool]
    prompt = false
[difftool "diffast"]
    cmd = PATH_TO_THIS_REPO/git_ext_diff "$LOCAL" "$REMOTE"
[alias]
    diffast = difftool

Then you should be able to use git diffast like git diff. You will be prompted to launch diffast for each source file comparison. Other file comparisons will be ignored.

Building docker image

The following command line creates a docker image named diffast.

$ docker build -t diffast .

License

Apache License, Version 2.0

About

Diff/AST: A fine-grained source code differencing tool

Resources

Readme
Apache-2.0 license
Activity

Stars

25 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.