dl
dl_svn.h
浏览该文件的文档.
1
12#pragma once
13
14#include "system/dl_process.h"
15
16namespace dl
17{
19 class Svn
20 {
21 friend class SvnManager;
22 public:
32 static std::string_view GetWorkTypeName(WorkType type);
33 struct Work
34 {
36 std::string _url;
37 std::string _path;
38 std::vector<std::string> _vecAdd;
39
40 std::string_view GetTypeName() const
41 {
42 return GetWorkTypeName(_type);
43 }
44 };
45 // 工作线程
47 {
51 {
52 _t = g_thread->Create();
54 _data->_thread = _t;
55 }
57 {
58 delete _t;
60 delete _data;
61 }
62 };
63 // 设置仓库地址
64 void SetUrl(std::string_view url) { _url = url; }
65 // 设置工作路径
66 void SetPath(std::string_view path) { _path = path; }
67 // 设置账号密码
68 void SetAccount(std::string_view username, std::string_view password, bool save_account)
69 {
70 _username = username;
71 _password = password;
72 _bSaveAccount = save_account;
73 }
74 // 设置提交注释
75 void SetComment(std::string_view comment) { _comment = comment; }
76 // 检出
77 void Checkout();
78 // 更新
79 void Update();
80 // 添加(传入子目录)
81 void Add(const std::vector<std::string>& vec_path);
82 // 提交
83 void Commit();
84 // 清理
85 void Cleanup();
86
87 void DoWorkLast();
88
89 const ThreadWork& GetThreadWork() { return _work; }
90 std::string GetUrl() { return _url; }
91 std::string GetPath() { return _path; }
92
93 const Work& GetWork() { return _workCurrent; }
94 const Work& GetWorkLast() { return _workLast; }
95 void* GetUserData() { return _userData; }
96
97 Svn() :
98 _bSaveAccount{ false },
99 _userData{ nullptr }
100 {
101 _workLast._type = WorkType::NONE;
102 }
104 private:
105 std::string _url;
106 std::string _path;
107 std::string _username;
108 std::string _password;
109 std::string _comment;// 提交日志
110 bool _bSaveAccount;
111
112 ThreadWork _work;// 只开一个线程
113
114 Work _workLast;
115 Work _workCurrent;
116
117 void* _userData;
118 };
119
121 {
122 public:
123 Svn* Create(std::string_view url, std::string_view path, void* user_data)
124 {
125 assert(!Has(url, path));
126
127 Svn* ret = new Svn;
128 ret->_userData = user_data;
129 ret->_url = url;
130 ret->_path = path;
131 _allSvn.push_back(ret);
132 return ret;
133 }
134 // 不同时下载同一个URL或者本存保存路径
135 bool Has(std::string_view url, std::string_view path)
136 {
137 for (Svn* svn : _allSvn)
138 {
139 if (svn->_url == url
140 || svn->_path == path)
141 return true;
142 }
143 return false;
144 }
145
146 // 初始化,设置svn.exe路径
147 bool Init(std::string_view svn_path);
148 bool IsInit() { return !_exe.empty(); }
149 //
150 std::string GetPathExe()
151 {
152 return _exe;
153 }
154
155 // 遍历时禁止删除
156 const std::list<Svn*>& GetAllSvn()
157 {
158 return _allSvn;
159 }
160
161 void _remove_ref(Svn* svn)
162 {
163 auto iter = std::find(_allSvn.begin(), _allSvn.end(), svn);
164 assert(iter != _allSvn.end());
165 if (iter != _allSvn.end())
166 {
167 _allSvn.erase(iter);
168 }
169 }
170 private:
171 std::string _exe;
172 std::list<Svn*> _allSvn;
173 };
174 extern SvnManager* g_svn;
175}
176
static void Terminate(ExecMultiData *data)
svn命令封装
void Add(const std::vector< std::string > &vec_path)
void DoWorkLast()
static std::string_view GetWorkTypeName(WorkType type)
void Checkout()
std::string GetPath()
void SetComment(std::string_view comment)
void Update()
void Commit()
const Work & GetWorkLast()
friend class SvnManager
void SetUrl(std::string_view url)
void SetPath(std::string_view path)
const ThreadWork & GetThreadWork()
void * GetUserData()
void Cleanup()
std::string GetUrl()
void SetAccount(std::string_view username, std::string_view password, bool save_account)
const Work & GetWork()
svn管理器
const std::list< Svn * > & GetAllSvn()
bool Has(std::string_view url, std::string_view path)
Svn * Create(std::string_view url, std::string_view path, void *user_data)
void _remove_ref(Svn *svn)
std::string GetPathExe()
bool Init(std::string_view svn_path)
进程封装
SvnManager * g_svn
ThreadManager * g_thread
Process::ExecMultiData * _data
std::vector< std::string > _vecAdd
WorkType _type
std::string_view GetTypeName() const
std::string _path
std::string _url