Files
dl_old/dl/io/dl_svn.cpp
T

226 lines
4.3 KiB
C++

#include "dl_svn.h"
#include "system/dl_windows.h"
#include "io/dl_file.h"
namespace dl
{
SvnManager* g_svn;
std::string_view Svn::GetWorkTypeName(WorkType type)
{
switch (type)
{
case WorkType::NONE:
return "空闲";
case WorkType::CHECKOUT:
return "检出";
case WorkType::UPDATE:
return "更新";
case WorkType::ADD:
return "添加";
case WorkType::COMMIT:
return "提交";
case WorkType::CLEANUP:
return "清理";
default:
break;
}
return "错误";
}
constexpr bool NO_INTERACTIVE = false;
void Svn::Checkout()
{
//路径(目录或文件的全路径) [本地目录全路径]
// --username 用户名 --password 密码
// --non-interactive 禁止输入
std::string cmd = fmt::format(
"svn co {} \"{}\"",
_url, _path);
if (NO_INTERACTIVE)
cmd += " --non-interactive";
cmd += fmt::format(" --username {} --password {}",
_username, _password);
if (!_bSaveAccount)
cmd += " --no-auth-cache";
_work._data->_exe = g_svn->GetPathExe();
_work._data->_cmd = cmd;
// 记录当前操作
_workLast = _workCurrent;
_workCurrent._type = WorkType::CHECKOUT;
_workCurrent._url = _url;
_workCurrent._path = _path;
Process::ExecMulti(_work._data);
}
void Svn::Update()
{
std::string cmd = fmt::format(
"svn update \"{}\"", _path);
if (true)
{
cmd += " --non-interactive";
}
if (!_bSaveAccount)
{
cmd += fmt::format(" --username {} --password {}",
_username, _password);
cmd += " --no-auth-cache";
}
_work._data->_exe = g_svn->GetPathExe();
_work._data->_cmd = cmd;
// 记录当前操作
_workLast = _workCurrent;
_workCurrent._type = WorkType::UPDATE;
_workCurrent._url = _url;
_workCurrent._path = _path;
Process::ExecMulti(_work._data);
}
void Svn::Add(const std::vector<std::string>& vec_path)
{
std::string all_path;
for (auto& iter : vec_path)
{
all_path += fmt::format("\"{}{}\" ", _path, iter);
}
std::string cmd = fmt::format("svn add {} --force",
all_path);
if (NO_INTERACTIVE)
{
cmd += " --non-interactive";
}
if (!_bSaveAccount)
{
cmd += fmt::format(" --username {} --password {}",
_username, _password);
cmd += " --no-auth-cache";
}
_work._data->_exe = g_svn->GetPathExe();
_work._data->_cmd = cmd;
// 记录当前操作
_workLast = _workCurrent;
_workCurrent._type = WorkType::ADD;
_workCurrent._url = _url;
_workCurrent._path = _path;
_workCurrent._vecAdd = vec_path;
Process::ExecMulti(_work._data);
}
void Svn::Commit()
{
std::string cmd = fmt::format(
"svn commit \"{}\" -m \"{}\"",
_path, _comment);
if (NO_INTERACTIVE)
{
cmd += " --non-interactive";
}
if (!_bSaveAccount)
{
cmd += fmt::format(" --username {} --password {}",
_username, _password);
cmd += " --no-auth-cache";
}
_work._data->_exe = g_svn->GetPathExe();
_work._data->_cmd = cmd;
// 记录当前操作
_workLast = _workCurrent;
_workCurrent._type = WorkType::COMMIT;
_workCurrent._url = _url;
_workCurrent._path = _path;
Process::ExecMulti(_work._data);
}
void Svn::Cleanup()
{
std::string cmd = fmt::format(
"svn cleanup \"{}\"", _path);
if (NO_INTERACTIVE)
{
cmd += " --non-interactive";
}
if (!_bSaveAccount)
{
cmd += fmt::format(" --username {} --password {}",
_username, _password);
cmd += " --no-auth-cache";
}
_work._data->_exe = g_svn->GetPathExe();
_work._data->_cmd = cmd;
// 记录当前操作
_workLast = _workCurrent;
_workCurrent._type = WorkType::CLEANUP;
_workCurrent._url = _url;
_workCurrent._path = _path;
Process::ExecMulti(_work._data);
}
void Svn::DoWorkLast()
{
Work& work = _workLast;
auto fn_set = [&]() {
_url = work._url;
_path = work._path;
};
switch (work._type)
{
case WorkType::CHECKOUT:
fn_set();
Checkout();
break;
case WorkType::UPDATE:
fn_set();
Update();
break;
case WorkType::ADD:
fn_set();
Add(work._vecAdd);
break;
case WorkType::COMMIT:
fn_set();
Commit();
break;
case WorkType::CLEANUP:
fn_set();
Cleanup();
break;
case WorkType::NONE:
default:
assert(0);
break;
}
}
Svn::~Svn()
{
g_svn->_remove_ref(this);
}
bool SvnManager::Init(std::string_view svn_path)
{
_exe = svn_path;
if (!dl::File::IsExist(_exe)
|| dl::File::GetFileName(svn_path) != "svn.exe")
return false;
return true;
}
}