Design and Implementation of a Custom CodeDiff Platform Supporting SVN and Git
This article explains the motivation, design principles, and technical implementation of a self‑developed CodeDiff platform that unifies SVN and Git diff operations, details the underlying SVNKit and JGit integrations, and describes how diff results are acquired, parsed, and presented to improve testing efficiency and risk control.
Preface – CodeDiff, literally meaning code difference comparison, can supplement testing by allowing testers to assess changes directly from code, thereby better controlling project risk and quality.
Significance of CodeDiff – Various tools are used to compare two versions, but the goal is to extract differences, evaluate their impact on requirements and business, and define test/regression scope based on an understanding of module interactions, data flow, and state changes.
Why develop our own tool?
Provide a unified, simple platform supporting both SVN and Git, eliminating the need to open IDEs or handle permission issues.
Enable diff between any two commit IDs or branches, independent of Git platform limitations.
Offer stronger extensibility and seamless integration with internal project‑management processes.
Integrate with the Beetle build system to show incremental diffs per compilation for developers and testers.
Support all code‑difference‑based testing methods such as CodeReview, coverage analysis, static analysis, and syntax checking.
Design Implementation
1. Basic Idea – The self‑built platform supports both SVN and Git. Regardless of the VCS, the core workflow is: select any two versions/branches, compute the code diff, parse the result, and display it.
2. Implementation方案
SVN‑SVNKit
SVNKit is a pure‑Java library that provides two API layers:
Low‑Level API – Directly interacts with the Subversion repository protocol, offering abstract operations on the repository tree.
High‑Level API – Wraps low‑level calls into familiar client‑like commands (e.g., SVNUpdateClient for checkout/update).
GIT‑JGit
JGit is a pure‑Java implementation of Git commands. It offers a Java API to perform actions such as clone, fetch, push, and diff. Below is an example method that clones a remote repository using JGit:
/**
* Clone a Git repository to a local directory.
* @param gitUrl remote Git HTTP URL
* @param destPath local directory path
* @return the local repository path
*/
public String cloneMasterRepository(String gitUrl, String destPath) throws GitAPIException, IOException {
CredentialsProvider cp = checkPermissionForGit(gitUrl);
File file = new File(destPath);
long beginTime = System.currentTimeMillis();
CloneCommand cloneCommand = git.cloneRepository();
cloneCommand.setURI(gitUrl);
cloneCommand.setDirectory(file);
cloneCommand.setCredentialsProvider(cp);
cloneCommand.setCloneAllBranches(true);
cloneCommand.call();
if (file.exists()) {
git = Git.open(file);
}
long endTime = System.currentTimeMillis();
logger.info("cloneMasterRepository time=" + (endTime - beginTime));
return destPath;
}Part 1 – Obtaining Diff Content
JGit authentication supports SSH and HTTPS via its API.
Operations such as clone, fetch, checkout are performed through command objects derived from TransportCommand .
After acquiring the two target versions, git.diff() is called to retrieve the diff, which is then parsed line‑by‑line.
Part 2 – Assembling Full File Content
Locate the target file in the local repository using its filename.
Parse the file line‑by‑line.
Based on the change type (modify/add/remove), apply a merging strategy to reconstruct the complete file content.
Conclusion
The CodeDiff solution has undergone multiple iterations and, after integration with the Beetle platform, now provides a one‑click diff experience without manual code checkout, supporting testing, risk control, coverage statistics, CodeReview, static analysis, and other diff‑based testing methods.
转转QA
In the era of knowledge sharing, discover 转转QA from a new perspective.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.