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

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

一、运行环境

  • windows10 64位系统

在这里插入图片描述

  • 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库函数调用基本流程

在这里插入图片描述

  • 准备svn-clent-context流程

在这里插入图片描述

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.

在这里插入图片描述

  • 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;
}

三、运行效果

  • 界面展示

在这里插入图片描述

  • Checkout–>导出指定版本

  • Update–>更新到指定版本

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

四、附件下载

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值