Re-Centris 开源项目教程
1. 项目的目录结构及介绍
Re-Centris 是一个基于 TLSH 算法实现的代码相似度分析工具,项目目录结构如下:
-
Python版本
re-centris/ ├── core/ # 核心功能模块 ├── osscollector/ # 开源代码收集 ├── preprocessor/ # 代码预处理 ├── detector/ # 相似度检测 ├── config.yaml # 配置文件 └── requirements.txt # 项目依赖
-
Go版本
re-centris-go/ ├── cmd/ # CLI入口 ├── internal/ # 核心实现 │ ├── analyzer/ # 代码分析 │ ├── collector/ # 代码收集 │ ├── detector/ # 相似度检测 │ └── preprocessor/ # 预处理 └── config.yaml # 配置文件
每个目录和文件的具体功能已在项目说明中描述。
2. 项目的启动文件介绍
-
Python版本启动
Python版本的启动通常需要先设置虚拟环境并安装依赖:
python -m venv venv source venv/bin/activate # Windows下使用 venv\Scripts\activate pip install -r requirements.txt
根据不同的操作,可以执行以下命令:
-
收集开源代码信息:
python -m osscollector.collector -c config.yaml
-
预处理代码:
python -m preprocessor.preprocessor -c config.yaml
-
执行相似度检测:
python -m detector.detector -c config.yaml -i path/to/input/code
-
-
Go版本启动
Go版本的项目启动需要先构建项目:
go build -o re-centris ./cmd/re-centris
或者系统级安装:
go install ./cmd/re-centris
然后根据不同的操作,可以执行以下命令:
-
克隆并收集代码:
re-centris clone repo-list.txt -o ./repos
-
分析代码:
re-centris analyze ./source-code -o ./analysis
-
执行相似度检测:
re-centris detect target-file.cpp -k ./known-files -o results.json
-
3. 项目的配置文件介绍
项目的配置文件为 config.yaml
,使用 YAML 格式。配置文件支持以下主要配置项:
-
paths
:包含项目路径配置,如代码仓库路径、日期标签路径、结果路径等。paths: repo_path: "./repos" tag_date_path: "./data/repo_date" result_path: "./data/repo_functions"
-
performance
:性能相关的配置,如最大工作进程数、缓存大小、内存限制等。performance: max_workers: 0 # 自动使用可用CPU核心数 cache_size: 1000 memory_limit: 0.8 # 最大内存使用率
-
languages
:支持的语言配置,可以启用或禁用特定语言,并指定文件扩展名。languages: cpp: enabled: true extensions: [".c", ".cc", ".cpp", ".cxx", ".h", ".hpp"] java: enabled: false extensions: [".java"] python: enabled: false extensions: [".py"]