srcMove is a C++ command-line tool that post-processes srcDiff XML and annotates
delete/insert regions that represent relocated source code. Matching regions
receive a shared mv:id plus directional mv:from and mv:to XPath
relationships.
The project is Nicholas Stafford's master's thesis work on making structured source-code differences more interpretable, with particular emphasis on moves across file boundaries.
srcMove is the thesis's primary program and research deliverable. It is a portable CLI rather than a component tied to one development workspace: it can be built wherever srcML and srcReader are available, and it consumes XML produced by srcDiff.
SrcMLBuildTemplate
provides the recommended reproducible workspace for building the complete
toolchain. The companion srcVisual project presents srcDiff and srcMove XML in
a synchronized code-editor-like interface so detected moves can be inspected
across files.
Given a srcDiff XML document, srcMove:
- streams all
diff:deleteanddiff:insertregions from single-file or archive input - selects leaf diff regions and eligible structural children as move candidates while excluding whitespace-only and very small payloads
- builds canonical representations from the embedded srcML structure
- uses FNV-1a hashes as indexes, then confirms exact matches with the full canonical text
- recovers constrained one-to-one Type-2 matches by normalizing eligible identifier names
- suppresses overlapping parent/child selections and annotates every group containing both deletes and inserts
The output remains srcDiff XML and can be consumed by downstream analysis or visualization tools.
For macOS users, evaluators, and new contributors, the easiest supported path is SrcMLBuildTemplate. It builds the complete native dependency chain inside Ubuntu Docker, keeps the toolchain isolated from the host system, and exposes the resulting files to normal macOS editors.
Install Docker Desktop, then run:
git clone https://github.com/NickStafford2/SrcMLBuildTemplate.git
cd SrcMLBuildTemplate
make srcmove
./bin/srcml-dev-shell srcMove --versionThe build scripts clone missing source repositories and build srcML, srcReader, srcDiff, and srcMove in dependency order.
srcMove is an independent Git repository. It is commonly checked out inside the SrcMLBuildTemplate workspace scaffold, but the parent directory and sibling repositories are not part of this repository. The scaffold provides a reproducible Docker environment and coordinates dependency builds; srcMove owns its source, build interface, tests, and documentation.
The usual workspace layout is:
srcMLBuildTemplate/
srcML/
srcML-install/
srcReader/
srcDiff/
srcMove/
srcVisual/
The workspace is a convenience and the recommended installation experience, not an architectural dependency of srcMove.
To build srcMove outside SrcMLBuildTemplate, provide the same dependencies yourself:
- CMake 3.20+
- Ninja
- a C++17 compiler, preferably Clang or GCC
- the
libxml2development package - a
srcReadercheckout and build - a local srcML development installation
- the
srcdiffexecutable for source-pair tests and generating input XML
From the srcMove repository root:
make build
make testThe Makefile is the canonical developer interface when the dependency paths use
the expected sibling layout. Run make help for focused unit and
regression-suite targets.
For any other layout, configure the paths explicitly:
cmake -S . -B build \
-G Ninja \
-DWORKSPACE_ROOT=/path/to/workspace \
-DSRCREADER_ROOT=/path/to/srcReader \
-DSRCML_INSTALL_PREFIX=/path/to/srcML-install
cmake --build build./build/srcMove path/to/srcdiff.xmlThe default output is srcmove.xml in the current directory. An explicit
output path and JSON results file can also be supplied:
./build/srcMove input.srcdiff.xml output.srcmove.xml \
--results results.jsonCLI synopsis:
srcMove <srcdiff.xml> [out.xml] [--results results.json] [--profile] [-v]
srcMove --help
srcMove --version
--results <file>writes move groups, XPaths, raw texts, candidate counts, group classifications, and match kinds as JSON.--profilewrites coarseprofile.<stage>_ms=<milliseconds>timings to standard error.-vand--verboseare accepted for compatibility but currently have no effect on the pipeline.
srcMove adds xmlns:mv="http://www.srcML.org/srcMove" to the root unit and
patches the start tags of selected diff regions or structural children:
mv:ididentifies one move group.mv:tolists destination XPath values on deletions.mv:fromlists source XPath values on insertions.
Multiple partners are represented as an XPath union separated by |.
<unit xmlns="http://www.srcML.org/srcML/src"
xmlns:diff="http://www.srcML.org/srcDiff"
xmlns:mv="http://www.srcML.org/srcMove">
<diff:delete mv:id="97b1dcdaf"
mv:to="/src:unit[1]/diff:insert[1]">int a;</diff:delete>
<diff:insert mv:id="97b1dcdaf"
mv:from="/src:unit[1]/diff:delete[1]">int a;</diff:insert>
</unit>Legacy unnamespaced move attributes are preserved. They do not currently
prevent a selected region from also receiving the mv:* annotations produced
by this pipeline.
The current matcher reports:
exact: identical canonical structure and meaningful texttype2: identical identifier-normalized canonical structure for an eligible one-delete/one-insert construct
Hash equality alone never establishes a match. Many-to-many and unequal-count groups may share a move identifier and partner set, but srcMove does not yet infer a unique pairing within those groups.
For the complete implemented pipeline and its performance model, see Architecture.
Small deterministic XML fixtures live under tests/regression/xml/cases/.
Generated source-pair tests and BigCloneBench evaluation are documented by the
test and benchmark entry points above.
The build also produces text-oriented inspection tools from src/tools/:
srcdiff_rendersrcdiff_highlightsrcdiff_highlight_pos
These utilities are for debugging srcDiff/srcMove XML and use the same srcReader/srcML stack.
- Type-3 and Type-4 moves are not supported.
- Type-2 support is constrained identifier normalization, not general near-miss clone detection or semantic equivalence.
- There is no probabilistic confidence score, locality model, or behavioral interpretation.
- Many-to-many and unequal-count groups are classified but not fully paired or disambiguated.
- srcMove depends on candidate regions exposed by srcDiff and is not a general-purpose diff engine.
Research directions include richer move classification, contextual scoring, and better ambiguous-group disambiguation.
GPL-3.0-only. See LICENSE.
srcMove builds on the srcML/srcDiff ecosystem and uses srcReader and srcML for streaming parsing and writing of srcML-derived XML formats.