基于subversion1.6.3动态库实现简单版本管理

基于subversion1.6.3动态库实现简单版本管理

一、运行环境

  • windows10 64位系统

基于subversion1.6.3动态库实现简单版本管理_第1张图片

  • VS2015、C++

  • Subversion1.6.3

二、功能设计与实现

1、需求背景

  • 编码自动化版本部署、发布验证;

  • svn cli命令行能满足基本功能,但是动作执行是否成功的判断不可靠,只能通过控制台输出分析判断,容易出现遗漏或bug,不可靠;

  • 采用源码编译后生成的lib库文件,可以准确控制获取接口相关执行状态,进而实现高质量的扩展业务功能;

2、技术选型

  • PC端Demo工具界面 Qt5.9.0 lts

  • 依赖库(libsvn_xxx.dll),采用动态链接方式

参考 文章
  • 采用CMake管理工程编译规则;

  • 采用前后端分离框架,前端QT,后端纯粹C++

3、程序设计

3.1、需要实现的功能

  • 可指定版本Checkout

  • 可指定版本Update

  • 查询版本信息(支持本地workcopy版本及svn上版本信息)

3.2、调用实现

  • svn库函数调用基本流程

基于subversion1.6.3动态库实现简单版本管理_第2张图片

  • 准备svn-clent-context流程

基于subversion1.6.3动态库实现简单版本管理_第3张图片

4、功能实现

4.1、Checkout

  • 调用函数

svn_error_t *
svn_client_checkout3(svn_revnum_t *result_rev,
                     const char *URL,
                     const char *path,
                     const svn_opt_revision_t *peg_revision,
                     const svn_opt_revision_t *revision,
                     svn_depth_t depth,
                     svn_boolean_t ignore_externals,
                     svn_boolean_t allow_unver_obstructions,
                     svn_client_ctx_t *ctx,
                     apr_pool_t *pool);
result_rev:如果参数不为空,返回当前版本信息即WC Version;
URL:要checkout的svn url路径;
path:本地目录
peg_revision:根据资料来看,跟extern外部引用trunk有关,跟revision一样即可;
revision:指定要checkout的版本;
depth:checkout目录层数,一般设置svn_depth_infinity全部获取
ignore_externals:忽略外部链接版本,即tsvn客户端的omit externals,一般设置false
allow_unver_obstructions:false即可;
ctx:client ctx;
pool:apr pool;

参考资料

If neither revision is specified, it is effectively an operative revision of HEAD. In that case, the search starts with the HEAD of the repo, it THEN gets the path. If the path doesn't exist in the HEAD, it won't be found, resulting in a path not found error. The extern needs to start the search with a revision where the path existed - a peg revision can do just that.

I always set the peg revision for my externals to ensure that if I checkout a particular revision of the main repo, I'm always building the same code. Without a specified revision for the extern, checking out the same revision from the main repo at different times will generate different results (because the externs could be different).

As I said, the Subversion Red Book probably explains it better than me, and there's always the risk that I'm wrong. [However, it is based on having a similar issue and trying to overcome it.]

HTH,
Bruce


This email and any attachments or links herein are confidential and may contain Metrol Technology Limited proprietary information that is legally privileged or otherwise protected from disclosure. It is solely intended for the person(s) named above. If you are not the intended recipient, any reading, use, disclosure, copying or distribution of all or parts of this email or associated attachments or links to other web locations, is strictly prohibited. If you are not the intended recipient, please notify the sender immediately by replying to this message or by telephone and delete this email and any attachments or links permanently from your system. Metrol accepts no liability for any damage of whatever nature caused by this email.

基于subversion1.6.3动态库实现简单版本管理_第4张图片

  • Checkout过程信息获取

设置回调函数notify_func或notify_func2
#
pCtxActual->notify_func = (svn_wc_notify_func_t)CActionCheckout::notify_func;
#
void* CActionCheckout::notify_func(void *baton,
	const char *path,
	svn_wc_notify_action_t action,
	svn_node_kind_t kind,
	const char *mime_type,
	svn_wc_notify_state_t content_state,
	svn_wc_notify_state_t prop_state,
	svn_revnum_t revision) {
	//打印checkout文件信息
	CLogger4Cpp::GetInstance()->Debug("checkout %s", path);
	//
	return NULL;
}

4.2、Update

  • 调用函数

svn_error_t *
svn_client_update3(apr_array_header_t **result_revs,
                   const apr_array_header_t *paths,
                   const svn_opt_revision_t *revision,
                   svn_depth_t depth,
                   svn_boolean_t depth_is_sticky,
                   svn_boolean_t ignore_externals,
                   svn_boolean_t allow_unver_obstructions,
                   svn_client_ctx_t *ctx,
                   apr_pool_t *pool);
  • Update过程信息获取

设置回调函数notify_func或notify_func2
#
pCtxActual->notify_func = (svn_wc_notify_func_t)checkout::notify_func;
#
void* checkout::notify_func(void *baton,
	const char *path,
	svn_wc_notify_action_t action,
	svn_node_kind_t kind,
	const char *mime_type,
	svn_wc_notify_state_t content_state,
	svn_wc_notify_state_t prop_state,
	svn_revnum_t revision) {
	//打印Update文件信息
	CLogger4Cpp::GetInstance()->Debug("update %s", path);
	//
	return NULL;
}

4.3 Info

  • 调用函数

svn_error_t *
svn_client_info2(const char *path_or_url,
                 const svn_opt_revision_t *peg_revision,
                 const svn_opt_revision_t *revision,
                 svn_info_receiver_t receiver,
                 void *receiver_baton,
                 svn_depth_t depth,
                 const apr_array_header_t *changelists,
                 svn_client_ctx_t *ctx,
                 apr_pool_t *pool);
如果peg_revision跟revision设置为NULL,查询获取的是本地副本的信息,这个也才是一般情况比较关心的,否则就获取svn版本上的信息;
  • Info版本信息获取

#
svn_error_t *CActionInfo::svn_info_receiver_t
(void *baton,
	const char *path,
	const svn_info_t *info,
	apr_pool_t *pool) {
	//
	CActionInfo* pParent = NULL;
	//
	if (baton == NULL) {
		goto exit;
	}
	if (info == NULL) {
		goto exit;
	}
	//
	pParent = (CActionInfo*)(baton);
      //
	pParent->m_workCopyVersion = info->last_changed_rev;
	//
	exit: return NULL;
}

三、运行效果

  • 界面展示

基于subversion1.6.3动态库实现简单版本管理_第5张图片

  • Checkout–>导出指定版本

  • Update–>更新到指定版本

  • Info–>查看当前版本信息

四、附件下载

基于subversion1.6.3动态库实现简单版本管理.rar (访问密码: 1150)

你可能感兴趣的:(svn,windows10,vs2015,c++)