- 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>
81 lines
2.6 KiB
Java
81 lines
2.6 KiB
Java
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);
|
||
}
|
||
}
|