Unity整合TortoiseSVN
解决各种漏传 资源 / 代码 的疑难杂症.
因为Unity比较特殊的meta文件系统, 忘传漏传文件在后期可能导致重大引用丢失, 将SVN整合进项目势在必行. TortoiseSVN自带了命令行工具, 安装的时候选择了的话就能用了
直接代码:
using UnityEngine;
using UnityEditor;
using System.Diagnostics;
using System.Collections.Generic; namespace MyEditor
{
public class UnitySVN
{
private const string Add_CMD = "add";
private const string COMMIT_CMD = "commit";
private const string UPDATE_CMD = "update";
private const string REVERT_CMD = "revert"; private static System.Text.StringBuilder ms_sb = new System.Text.StringBuilder(); #region MenuItem Funcs
[MenuItem("Assets/SVN/Update", false, 1001)]
public static void SVN_Update()
{
var paths = GetAssetPathList();
if(paths.Count > 0)
{
Update(paths: paths.ToArray());
}
}
[MenuItem("Assets/SVN/Revert", false, 1002)]
public static void SVN_Revert()
{
var paths = GetAssetPathList();
if(paths.Count > 0)
{
Revert(paths.ToArray());
}
}
[MenuItem("Assets/SVN/Commit", false, 1003)]
public static void SVN_Commit()
{
var paths = GetAssetPathList();
if(paths.Count > 0)
{
Commit("UnitySVN Upload", true, paths.ToArray());
}
}
#endregion #region Wrapped Funcs
// add
public static void Add(params string[] paths)
{
WrappedCommadn(Add_CMD, paths, false);
}
// update
public static void Update(params string[] paths)
{
WrappedCommadn(UPDATE_CMD, paths, false);
SaveAndRefresh();
}
// revert
public static void Revert(params string[] paths)
{
WrappedCommadn(REVERT_CMD, paths, false);
SaveAndRefresh();
}
// add->update->commit
public static void Commit(string log, bool add = true, params string[] paths)
{
if(add)
{
Add(paths);
}
Update(paths);
string extMsg = log ?? string.Empty;
WrappedCommadn(command: COMMIT_CMD, paths: paths, newThread: true, extCommand: "/logmsg:\"Auto Upload : " + (extMsg) + "\"");
} /// <summary>
/// Wrap SVN Command
/// </summary>
/// <param name="command"></param>
/// <param name="path"></param>
/// <param name="extCommand"></param>
public static void WrappedCommadn(string command, string[] paths, bool newThread = false, string extCommand = null)
{
if(paths == null || paths.Length == 0)
{
return;
} ms_sb.Append(paths[0]);
for(int i = 1; i < paths.Length; i++)
{
ms_sb.Append("*");
ms_sb.Append(paths[i]);
} string cmd = "/c tortoiseproc.exe /command:{0} /path:\"{1}\" {2} /closeonend 2";
string pathString = ms_sb.ToString();
var commandString = string.Format(cmd, command, pathString, extCommand ?? string.Empty); ProcessStartInfo info = new ProcessStartInfo("cmd.exe", commandString);
info.WindowStyle = ProcessWindowStyle.Hidden;
if(newThread)
{
System.Threading.ThreadPool.QueueUserWorkItem((_obj) =>
{
RunProcess(info);
});
}
else
{
RunProcess(info);
}
}
#endregion #region Help Funcs
public static HashSet<string> GetAssets()
{
HashSet<string> allAssets = new HashSet<string>();
const string BaseFolder = "Assets";
foreach(var obj in Selection.objects)
{
var assetPath = AssetDatabase.GetAssetPath(obj); List<string> fullDirs = FullDirectories(assetPath, BaseFolder);
allAssets.UnionWith(fullDirs); var dps = AssetDatabase.GetDependencies(assetPath, true);
foreach(var dp in dps)
{
if(dp != assetPath)
{
List<string> dpsDirs = FullDirectories(dp, BaseFolder);
allAssets.UnionWith(dpsDirs);
}
}
}
return allAssets;
}
public static List<string> GetAssetPathList()
{
var path = new List<string>(GetAssets());
path.Sort((_l, _r) =>
{
if(_l.Length > _r.Length)
{
return 1;
}
if(_l.Length < _r.Length)
{
return -1;
}
return 0;
});
return path;
}
public static void SaveAndRefresh()
{
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
public static List<string> FullDirectories(string path, string baseFolder)
{
List<string> retVal = new List<string>();
retVal.Add(path);
retVal.Add(path + ".meta");
baseFolder = baseFolder.Replace("\\", "/");
var dir = System.IO.Path.GetDirectoryName(path).Replace("\\", "/");
while(string.IsNullOrEmpty(dir) == false && dir != baseFolder)
{
retVal.Add(dir);
retVal.Add(dir + ".meta");
dir = System.IO.Path.GetDirectoryName(dir).Replace("\\", "/");
}
return retVal;
}
private static void RunProcess(ProcessStartInfo info)
{
Process p = null;
try
{
using(p = Process.Start(info))
{
p.WaitForExit();
}
}
catch(System.Exception ex)
{
UnityEngine.Debug.LogError(@ex.ToString());
if(p != null)
{
p.Kill();
}
}
}
#endregion } /*
/ closeonend:0不自动关闭对话框 / closeonend:1会自动关闭,如果没有错误 / closeonend:2会自动关闭,如果没有发生错误和冲突 / closeonend:3会自动关闭,如果没有错误,冲突和合并 / closeonend:4会自动关闭,如果没有错误,冲突和合并
*/
}
主要的功能还是自动上传功能, 被选中物体的所有关联引用都会被加入上传列表, 并且所有文件夹也会被加入, 这样就保证了Add逻辑不会错误.
还是把所有功能都贴上来吧, 网址: https://tortoisesvn.net/docs/nightly/TortoiseSVN_en/tsvn-automation.html#tsvn-automation-basics
Appendix D. Automating TortoiseSVN
Table of Contents
Since all commands for TortoiseSVN are controlled through command line parameters, you can automate it with batch scripts or start specific commands and dialogs from other programs (e.g. your favourite text editor).
Important
Remember that TortoiseSVN is a GUI client, and this automation guide shows you how to make the TortoiseSVN dialogs appear to collect user input. If you want to write a script which requires no input, you should use the official Subversion command line client instead.
TortoiseSVN Commands
The TortoiseSVN GUI program is called TortoiseProc.exe
. All commands are specified with the parameter /command:abcd
where abcd
is the required command name. Most of these commands need at least one path argument, which is given with /path:"some\path"
. In the following table the command refers to the /command:abcd
parameter and the path refers to the /path:"some\path"
parameter.
There's a special command that does not require the parameter /command:abcd
but, if nothing is specified on the command line, starts the project monitor instead. If /tray
is specified, the project monitor starts hidden and only adds its icon to the system tray.
Since some of the commands can take a list of target paths (e.g. committing several specific files) the /path
parameter can take several paths, separated by a *
character.
You can also specify a file which contains a list of paths, separated by newlines. The file must be in UTF-16 format, without a BOM. If you pass such a file, use /pathfile
instead of /path
. To have TortoiseProc delete that file after the command is finished, you can pass the parameter /deletepathfile
. If you don't pass /deletepathfile
, you have to delete the file yourself or the file gets left behind.
The progress dialog which is used for commits, updates and many more commands usually stays open after the command has finished until the user presses the OK button. This can be changed by checking the corresponding option in the settings dialog. But using that setting will close the progress dialog, no matter if you start the command from your batch file or from the TortoiseSVN context menu.
To specify a different location of the configuration file, use the parameter /configdir:"path\to\config\directory"
. This will override the default path, including any registry setting.
To close the progress dialog at the end of a command automatically without using the permanent setting you can pass the /closeonend
parameter.
/closeonend:0
don't close the dialog automatically/closeonend:1
auto close if no errors/closeonend:2
auto close if no errors and conflicts/closeonend:3
auto close if no errors, conflicts and merges
To close the progress dialog for local operations if there were no errors or conflicts, pass the /closeforlocal
parameter.
The table below lists all the commands which can be accessed using the TortoiseProc.exe command line. As described above, these should be used in the form /command:abcd
. In the table, the /command
prefix is omitted to save space.
Table D.1. List of available commands and options
Command | Description |
---|---|
:about | Shows the about dialog. This is also shown if no command is given. |
:log |
Opens the log dialog. The
An svn date revision can be in one of the following formats:
|
:checkout | Opens the checkout dialog. The /path specifies the target directory and the /url specifies the URL to checkout from. If you specify the key /blockpathadjustments , the automatic checkout path adjustments are blocked. The /revision:XXX specifies the revision to check out. |
:import | Opens the import dialog. The /path specifies the directory with the data to import. You can also specify the /logmsg switch to pass a predefined log message to the import dialog. Or, if you don't want to pass the log message on the command line, use /logmsgfile:path , where path points to a file containing the log message. |
:update | Updates the working copy in /path to HEAD. If the option /rev is given then a dialog is shown to ask the user to which revision the update should go. To avoid the dialog specify a revision number /rev:1234 . Other options are /nonrecursive , /ignoreexternals and/includeexternals . The /stickydepth indicates that the specified depth should be sticky, creating a sparse checkout. The /skipprechecks can be set to skip all checks that are done before an update. If this is specified, then the Show log button is disabled, and the context menu to show diffs is also disabled after the update. |
:commit | Opens the commit dialog. The /path specifies the target directory or the list of files to commit. You can also specify the /logmsg switch to pass a predefined log message to the commit dialog. Or, if you don't want to pass the log message on the command line, use /logmsgfile:path , where path points to a file containing the log message. To pre-fill the bug ID box (in case you've set up integration with bug trackers properly), you can use the /bugid:"the bug id here" to do that. |
:add | Adds the files in /path to version control. |
:revert | Reverts local modifications of a working copy. The /path tells which items to revert. |
:cleanup | Cleans up interrupted or aborted operations and unlocks the working copy in /path . You also have to pass the /cleanup to actually do the cleanup. Use /noui to prevent the result dialog from popping up (either telling about the cleanup being finished or showing an error message). /noprogressui also disables the progress dialog. /nodlg disables showing the cleanup dialog where the user can choose what exactly should be done in the cleanup. The available actions can be specified with the options /cleanup for status cleanup, /breaklocks to break all locks, /revert to revert uncommitted changes, /delunversioned , /delignored , /refreshshell , /externals , /fixtimestamps and /vacuum . |
:resolve | Marks a conflicted file specified in /path as resolved. If /noquestion is given, then resolving is done without asking the user first if it really should be done. |
:repocreate | Creates a repository in /path |
:switch | Opens the switch dialog. The /path specifies the target directory and /url the URL to switch to. |
:export | Exports the working copy in /path to another directory. If the /path points to an unversioned directory, a dialog will ask for an URL to export to the directory in /path . If you specify the key /blockpathadjustments , the automatic export path adjustments are blocked. |
:dropexport | Exports the working copy in /path to the directory specified in /droptarget . This exporting does not use the export dialog but executes directly. The option /overwrite specifies that existing files are overwritten without user confirmation, and the option /autorename specifies that if files already exist, the exported files get automatically renamed to avoid overwriting them. The option /extended can specify either localchanges to only export files that got changed locally, or unversioned to also export all unversioned items as well. |
:dropvendor | Copies the folder in /path recursively to the directory specified in /droptarget . New files are added automatically, and missing files get removed in the target working copy, basically ensuring that source and destination are exactly the same. Specify /noui to skip the confirmation dialog, and /noprogressui to also disable showing the progress dialog. |
:merge | Opens the merge dialog. The /path specifies the target directory. For merging a revision range, the following options are available:/fromurl:URL , /revrange:string . For merging two repository trees, the following options are available: /fromurl:URL , /tourl:URL , /fromrev:xxx and/torev:xxx . |
:mergeall | Opens the merge all dialog. The /path specifies the target directory. |
:copy | Brings up the branch/tag dialog. The /path is the working copy to branch/tag from. And the /url is the target URL. If the urls starts with a ^ it is assumed to be relative to the repository root. To already check the option Switch working copy to new branch/tag you can pass the /switchaftercopy switch. To check the option Create intermediate folders pass the /makeparents switch. You can also specify the /logmsg switch to pass a predefined log message to the branch/tag dialog. Or, if you don't want to pass the log message on the command line, use /logmsgfile:path , where path points to a file containing the log message. |
:settings | Opens the settings dialog. |
:remove | Removes the file(s) in /path from version control. |
:rename | Renames the file in /path . The new name for the file is asked with a dialog. To avoid the question about renaming similar files in one step, pass /noquestion . |
:diff | Starts the external diff program specified in the TortoiseSVN settings. The /path specifies the first file. If the option /path2 is set, then the diff program is started with those two files. If /path2 is omitted, then the diff is done between the file in /path and its BASE. If the specified file also has property modifications, the external diff tool is also started for each modified property. To prevent that, pass the option /ignoreprops . To explicitly set the revision numbers use /startrev:xxx and /endrev:xxx , and for the optional peg revision use /pegrevision:xxx . If /blame is set and /path2 is not set, then the diff is done by first blaming the files with the given revisions. The parameter /line:xxx specifies the line to jump to when the diff is shown. |
:shelve | Shelves the specified paths in a new shelf. The option /shelfname:name specifies the name of the shelf. An optional log message can be specified with /logmsg:message . If option /checkpoint is passed, the modifications of the files are kept. |
:unshelve | Applies the shelf with the name /shelfname:name to the working copy path. By default the last version of the shelf is applied, but you can specify a version with /version:X . |
:showcompare |
Depending on the URLs and revisions to compare, this either shows a unified diff (if the option The options If the specified url also has property modifications, the external diff tool is also started for each modified property. To prevent that, pass the option If a unified diff is requested, an optional |
:conflicteditor | Starts the conflict editor specified in the TortoiseSVN settings with the correct files for the conflicted file in /path . |
:relocate | Opens the relocate dialog. The /path specifies the working copy path to relocate. |
:help | Opens the help file. |
:repostatus | Opens the check-for-modifications dialog. The /path specifies the working copy directory. If /remote is specified, the dialog contacts the repository immediately on startup, as if the user clicked on the Check repository button. |
:repobrowser |
Starts the repository browser dialog, pointing to the URL of the working copy given in An additional option If If |
:ignore | Adds all targets in /path to the ignore list, i.e. adds the svn:ignore property to those files. |
:blame |
Opens the blame dialog for the file specified in If the options If the option The options |
:cat | Saves a file from an URL or working copy path given in /path to the location given in /savepath:path . The revision is given in /revision:xxx . This can be used to get a file with a specific revision. |
:createpatch | Creates a patch file for the path given in /path . To skip the file Save-As dialog you can pass /savepath:path to specify the path where to save the patch file to directly. To prevent the unified diff viewer from being started showing the patch file, pass /noview . If a unified diff is requested, an optional prettyprint option can be specified which will show the merge-info properties in a more user readable format. |
:revisiongraph |
Shows the revision graph for the path given in To create an image file of the revision graph for a specific path, but without showing the graph window, pass Since the revision graph has many options that affect how it is shown, you can also set the options to use when creating the output image file. Pass these options with |
:lock | Locks a file or all files in a directory given in /path . The 'lock' dialog is shown so the user can enter a comment for the lock. |
:unlock | Unlocks a file or all files in a directory given in /path . |
:rebuildiconcache | Rebuilds the windows icon cache. Only use this in case the windows icons are corrupted. A side effect of this (which can't be avoided) is that the icons on the desktop get rearranged. To suppress the message box, pass /noquestion . |
:properties |
Shows the properties dialog for the path given in For dealing with versioned properties this command requires a working copy. Revision properties can be viewed/changed if To open the properties dialog directly for a specific property, pass the property name as |
:sync |
Exports/imports settings, either depending on whether the current settings or the exported settings are newer, or as specified. If a path is passed with The parameter If neither If If The parameter |
Examples (which should be entered on one line):
TortoiseProc.exe /command:commit
/path:"c:\svn_wc\file1.txt*c:\svn_wc\file2.txt"
/logmsg:"test log message" /closeonend: TortoiseProc.exe /command:update /path:"c:\svn_wc\" /closeonend:0 TortoiseProc.exe /command:log /path:"c:\svn_wc\file1.txt"
/startrev: /endrev: /closeonend:
Tsvncmd URL handler | ||
---|---|---|
Prev | Appendix D. Automating TortoiseSVN | Next |
Tsvncmd URL handler
Using special URLs, it is also possible to call TortoiseProc from a web page.
TortoiseSVN registers a new protocol tsvncmd:
which can be used to create hyperlinks that execute TortoiseSVN commands. The commands and parameters are the same as when automating TortoiseSVN from the command line.
The format of the tsvncmd:
URL is like this:
tsvncmd:command:cmd?parameter:paramvalue?parameter:paramvalue
with cmd
being one of the allowed commands, parameter
being the name of a parameter like path
or revision
, and paramvalue
being the value to use for that parameter. The list of parameters allowed depends on the command used.
The following commands are allowed with tsvncmd:
URLs:
:update
:commit
:diff
:repobrowser
:checkout
:export
:blame
:repostatus
:revisiongraph
:showcompare
:log
A simple example URL might look like this:
<a href="tsvncmd:command:update?path:c:\svn_wc?rev:1234">Update</a>
or in a more complex case:
<a href="tsvncmd:command:showcompare?
url1:https://svn.code.sf.net/p/stefanstools/code/trunk/StExBar/src/setup/Setup.wxs?
url2:https://svn.code.sf.net/p/stefanstools/code/trunk/StExBar/src/setup/Setup.wxs?
revision1:188?revision2:189">compare</a>
TortoiseIDiff Commands | ||
---|---|---|
Prev | Appendix D. Automating TortoiseSVN | Next |
TortoiseIDiff Commands
The image diff tool has a few command line options which you can use to control how the tool is started. The program is called TortoiseIDiff.exe
.
The table below lists all the options which can be passed to the image diff tool on the command line.
Table D.2. List of available options
Option | Description |
---|---|
:left | Path to the file shown on the left. |
:lefttitle | A title string. This string is used in the image view title instead of the full path to the image file. |
:right | Path to the file shown on the right. |
:righttitle | A title string. This string is used in the image view title instead of the full path to the image file. |
:overlay | If specified, the image diff tool switches to the overlay mode (alpha blend). |
:fit | If specified, the image diff tool fits both images together. |
:showinfo | Shows the image info box. |
Example (which should be entered on one line):
TortoiseIDiff.exe /left:"c:\images\img1.jpg" /lefttitle:"image 1"
/right:"c:\images\img2.jpg" /righttitle:"image 2"
/fit /overlay
TortoiseUDiff Commands | ||
---|---|---|
Prev | Appendix D. Automating TortoiseSVN | Next |
TortoiseUDiff Commands
The unified diff viewer has only two command line options:
Table D.3. List of available options
Option | Description |
---|---|
:patchfile | Path to the unified diff file. |
:p | Activates pipe mode. The unified diff is read from the console input. |
Examples (which should be entered on one line):
TortoiseUDiff.exe /patchfile:"c:\diff.patch"
If you create the diff from another command, you can use TortoiseUDiff to show that diff directly:
svn diff | TortoiseUDiff.exe /u
this also works if you omit the /p
parameter:
svn diff | TortoiseUDiff.exe
Unity整合TortoiseSVN的更多相关文章
- Unity整合Asp.Net MVC
先来看一下我们的解决方案 我们建立Yubay.Models项目, using System; using System.Collections.Generic; using System.Data.E ...
- 第七节:WebApi与Unity整合进行依赖注入和AOP的实现
一. IOC和DI 1. 通过Nuget引入Unity程序集. PS:[版本:5.8.6] 2. 新建DIFactory类,用来读取Unity的配置文件并创建Unity容器,需要注意的是DIFacto ...
- Unity 2D入门基础教程之僵尸先生
注:这是根据网上教程完成的. 翻译:http://blog.1vr.cn/?p=1422 原文:http://www.raywenderlich.com/61532/unity-2d-tutorial ...
- Unity下的ECS框架 Entitas简介
最近随着守望先锋制作组在gdc上发布的一个关于ecs的talk,ecs这个架构算是得到了一定的曝光度. 在这之前,github上就一直有一个C#的ecs框架名为Entitas,截止现在已经有1300+ ...
- Steamworks and Unity – P2P多人游戏
之前我们讨论过“如何把Steamworks.Net和Unity整合起来”,这是一个很好的开始,现在我们研究深一点,谈一谈Steam中的多人游戏.这不是教程,但是可以指导你在你的游戏中如何使用Steam ...
- 转:Oculus Unity Development Guide开发指南(2015-7-21更新)
http://forum.exceedu.com/forum/forum.php?mod=viewthread&tid=34175 Oculus Unity Development Guide ...
- 干掉Unity3D
我为什么想干掉Unity3D? 这个问题容我不答,每个做技术的人总有一些完美主义. 你使用u3d的过程中是不是痛并快乐着呢. 就从两个国内具有相当普遍性的痛点说起. il2cpp,unity作出了这个 ...
- ar技术序章-SDK介绍和选择
转自: http://blog.csdn.net/kun1234567/article/details/10402535 ar技术序章-SDK介绍和选择 分类: Augmented Reality20 ...
- AR增强现实开发介绍(续)
AR增强现实开发介绍(续) ---开发基础篇 开发增强现实技术,无论是商业级应用,还是面向幼儿教育的游戏产品,都需要从了解.获取.下载增强现实插件开始.目前全世界使用量最大公认最好的增强现实插件是高通 ...
随机推荐
- JMeter配置数据库连接
在平时接口的测试中,很多时候是需要直接连接数据库,查询对应数据信息的. 我将其中一些内容整理出来,方便以后调阅. 1.首先是配置数据库的连接,也就是JDBC Connection Configurat ...
- 2019.6.13_SQL语句中----删除表数据drop、truncate和delete的用法
一.SQL中的语法 1.drop table 表名称 eg: drop table dbo.Sys_Test 2.truncate table 表 ...
- 读取只包含标签的xml
什么是XML XML是可扩展标记语言(Extensible Markup Language)的缩写,其中标记是关键部分.用户可以创建内容,然后使用限定标记标记它,从而使每个单词.短语或块成为可识别.可 ...
- RPC系列:基本概念
RPC(Remote Procedure Call):远程过程调用,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的思想. RPC 是一种技术思想而非一种规范或协议,常见 RPC ...
- 使用VisualVM 进行性能分析及调优
概述 开发大型 Java 应用程序的过程中难免遇到内存泄露.性能瓶颈等问题,比如文件.网络.数据库的连接未释放,未优化的算法等.随着应用程序的持续运行,可能会造成整个系统运行效率下降,严重的则会造成系 ...
- 大话设计模式Python实现-备忘录模式
备忘录模式(Memento Pattern):不破坏封装性的前提下捕获一个对象的内部状态,并在该对象之外保存这个状态,这样已经后就可将该对象恢复到原先保存的状态 下面是一个备忘录模式的demo: #! ...
- 文件安全复制之 FastCopy
FastCopy是Windows平台上最快的文件拷贝.删除软件.由于其功能强劲,性能优越,一时间便超越相同类型的所有其他软件.由于该软件十分小巧,你甚至可以在安装后,直接将安装目录中的文件复制到任何可 ...
- SATA接口、PCI/PCIe、NVMe的介绍
SATA接口.PCI/PCIe.NVMe的介绍 SATA接口 SATA是Serial ATA的缩写,即串行ATA. SATA已经完全取代旧式PATA(Parallel ATA或旧称IDE)接口的旧式硬 ...
- [Flutter] 转一个Flutter学习思维导图
本文的思维导图均转自QQ群,感谢原作者(是谁?) 表单 按钮 视图 Sliver 路由 (Routes) 输入控件 对话框 MDC (Material Design Component) 状态管理 R ...
- [CrackMe]160个CrackMe之002
吾爱破解专题汇总:[反汇编练习]160个CrackME索引目录1~160建议收藏备用 一.逆向分析之暴力破解 暴力破解,对于这种具有提示框的,很好定位. 定位好之后,爆破其跳转语句,就能达到破解目的. ...