Files
svn-manager/src/main/java/com/svnmanager/service/DiffService.java
liumangmang 52c099e0ba feat: support SVN auth and project credentials
- add username/password fields to project dialog and model
- pass optional auth to SVN info/status/log/diff/update/commit services
- centralize SVN CLI auth flags in SvnService and fix header text

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-04 17:54:16 +08:00

81 lines
2.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.svnmanager.service;
import com.svnmanager.util.ProcessUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeoutException;
/**
* Diff服务
*/
public class DiffService extends SvnService {
private static final Logger logger = LoggerFactory.getLogger(DiffService.class);
/**
* 获取差异
*
* @param workingDirectory 工作目录
* @param filePath 文件路径null表示所有文件
* @return 差异内容
* @throws IOException IO异常
* @throws InterruptedException 中断异常
* @throws TimeoutException 超时异常
*/
public String getDiff(String workingDirectory, String filePath, String username, String password)
throws IOException, InterruptedException, TimeoutException {
logger.debug("获取差异: {}", workingDirectory);
if (!isValidWorkingCopy(workingDirectory)) {
throw new IllegalArgumentException("无效的SVN工作副本: " + workingDirectory);
}
List<String> args = new ArrayList<>();
addAuthArgs(args, username, password);
if (filePath != null && !filePath.isEmpty()) {
args.add(filePath);
}
ProcessUtil.ProcessResult result = executeSvnCommand("diff", args, workingDirectory);
if (result.isSuccess()) {
return result.getOutputAsString();
} else {
logger.warn("获取差异失败: {}", result.getErrorAsString());
return result.getErrorAsString();
}
}
/**
* 获取所有文件的差异
*
* @param workingDirectory 工作目录
* @return 差异内容
* @throws IOException IO异常
* @throws InterruptedException 中断异常
* @throws TimeoutException 超时异常
*/
public String getDiff(String workingDirectory)
throws IOException, InterruptedException, TimeoutException {
return getDiff(workingDirectory, null, null, null);
}
/**
* 获取指定文件的差异(不带认证信息)
*
* @param workingDirectory 工作目录
* @param filePath 文件路径null表示所有文件
* @return 差异内容
* @throws IOException IO异常
* @throws InterruptedException 中断异常
* @throws TimeoutException 超时异常
*/
public String getDiff(String workingDirectory, String filePath)
throws IOException, InterruptedException, TimeoutException {
return getDiff(workingDirectory, filePath, null, null);
}
}