- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一堆源代码管理文件夹,我想删除所有不再需要的项目。这些项目已被删除(代码已被移动或重写),并且由于我们大多数人默认使用“显示已删除项目”选项,其中一些文件夹现在显示更多已删除项目和文件夹以及合法项目。我想确保所有这些冗余代码永远消失——因为它绝对不会被需要。这些新项目是从尚未有人使用的旧项目的分支构建的。
不过,有相当多的文件分布在多个文件夹中,因此我宁愿避免逐一执行。我也在命令行,而不是使用 API。
我知道最终我将需要 tf destroy
命令。
我也知道 tf dir [wildcard]/recursive/deleted
将返回路径中所有已删除的项目(不幸的是与所有合法项目一起)。
谁能想出一个快速的好方法?
我想到了两种解决方案:
1) 获取 dir 命令的输出并找到所有在 :Xnnnnnnn
之后的项目 - 这些是已删除的项目;然后简单地吐出一堆 tf destroy 调用,或构建一个响应文件(虽然不确定这一点)。这听起来像是 Powershell 的潜在用途,但实际上还没有对此做任何事情......
2) 准备好所有项目,然后简单地从 TFS 中销毁它们,然后重新添加它们,这样 TFS 中就只有需要的东西了。但是,这确实删除了可能有用的分支关系,因为有一段时间我将不得不维护其中一些库的两个版本(升级前和升级后)。不理想,但我对此无能为力。
显然,选项 2 是一种作弊,但它会起作用 - 我只是理想地喜欢一个可重用的脚本,将来可以用于 TFS 中的任何文件夹(其他几个团队有其他长期存在的项目,可以完全清除!)。
提前致谢。
最佳答案
好吧,我写了一个控制台应用程序 (.Net 4):
不用说,我对此不提供任何保证 - 它会破坏 TFS 中的项目!!!!
更新(2012 年 5 月 8 日)如果您在包含大量(我的意思是数千或数万)已删除项目的文件夹上运行它,它可能无法在 TFS 命令之前完成 -线路超时。此命令花费的大部分时间用于生成 .tfc 脚本。如果您运行它并发现发生这种情况,请先尝试定位一些子文件夹
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using System.Diagnostics;
namespace TFDestroyDeleted
{
class Program
{
static void Main(string[] args)
{
if (args.Length < 1 || args.Length > 3)
Usage();
bool prepareOnly = false;
bool previewOnly = false;
if (args.Any(s => StringComparer.InvariantCultureIgnoreCase
.Compare(s, "preview") == 0)) previewOnly = true;
if (args.Any(s => StringComparer.InvariantCultureIgnoreCase
.Compare(s, "norun") == 0)) prepareOnly = true;
string tfOutput = null;
Process p = new Process();
p.StartInfo = new ProcessStartInfo("tf")
{
Arguments = string.Format
("dir /recursive /deleted \"{0}\"", args[0]),
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true
};
p.Start();
tfOutput = p.StandardOutput.ReadToEnd();
p.WaitForExit();
string basePath = null;
string nextDelete = null;
List<string> toDelete = new List<string>();
using (var ms =
new MemoryStream(Encoding.Default.GetBytes(tfOutput)))
{
using (StreamReader sr = new StreamReader(ms))
{
while (!sr.EndOfStream)
{
nextDelete = null;
string line = sr.ReadLine();
if (string.IsNullOrWhiteSpace(line))
basePath = null;
else
{
if (basePath == null)
{
if (line.EndsWith(":"))
basePath = line.Substring(0, line.Length - 1);
else
continue;
}
else
{
nextDelete = Regex.Match(line, @"^.*?;X[0-9]+").Value;
if (!string.IsNullOrWhiteSpace(nextDelete))
{
toDelete.Add(
string.Format
(
"{0}/{1}", basePath,
nextDelete.StartsWith("$") ? nextDelete.Substring(1)
: nextDelete
));
}
}
}
}
}
}
using (var fs = File.OpenWrite("destroy.tfc"))
{
fs.SetLength(0);
using (var sw = new StreamWriter(fs))
{
//do the longest items first, naturally deleting items before their
//parent folders
foreach (var s in toDelete.OrderByDescending(s => s.Length))
{
if (!previewOnly)
sw.WriteLine("destroy \"{0}\" /i", s);
else
sw.WriteLine("destroy \"{0}\" /i /preview", s);
}
sw.Flush();
}
}
if (!prepareOnly)
{
p.StartInfo = new ProcessStartInfo("tf")
{
Arguments = string.Format("@{0}", "destroy.tfc"),
UseShellExecute = false
};
p.Start();
p.WaitForExit();
}
p.Close();
}
static void Usage()
{
Console.WriteLine(@"Usage:
TFDestroyDeleted [TFFolder] (preview) (norun)
Where [TFFolder] is the TFS root folder to be purged - it should be quoted if there are spaces. E.g: ""$/folder/subfolder"".
norun - Specify this if you only want a command file prepared for tf.
preview - Specify this if you want each destroy to be only a preview (i.e. when run, it won't actually do the destroy) ");
Environment.Exit(0);
}
}
}
您必须传递要删除的 TFS 文件夹,例如“$/folder”。如果您只是通过它,那么所有匹配的已删除项目将被一个接一个地检测和销毁。
出于某种原因 - 如果您不小心传递了一个实际不存在的文件夹,那么该操作将永远。当然,CTRL+C 将停止它。
应用程序使用 /deleted
开关在文件夹上执行递归目录。
然后它遍历输出中的每一行,寻找删除提示,即带有 ;Xnnnnnnn
的项目。如果找到,它会将该项的完整 tfs 路径添加到列表中。
完成后,列表按长度降序排列,并将内容写入 tf.exe
命令行的 tfc 响应文件。
如果指定了 preview
选项,那么 tf
命令将使用/preview 开关写出(参见 MSDN 上的 TFS Destroy)那么实际上并没有执行删除操作。
最后,您可以指定 norun
,这会导致创建 tfc 文件,但不会实际运行。
关于c# - TFS 2008 源代码管理 - 销毁所有已删除项目的快速方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4920677/
我正在编写一个 Java 应用程序,该应用程序检查网页的源代码,并在满足源代码中的条件时在我的默认浏览器中向我显示该网页。我通过以下方式获取源代码: String source = getUrlSou
数周以来,我一直在为 Android 上的蓝牙项目而苦苦挣扎。有谁知道我可以去哪里查看 Google 用于使其蓝牙配对和连接逻辑正常工作的实际代码? 我浏览了所有的文档、BluetoothChat 应
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 4 年前。
Android 源代码有多个目录,其中包含针对不同设备的代码。此外,在特定目录中,存在显示不同分支和标签的路径。举个例子,在“android/platform/external/iptables”目录
在哪里可以找到 SQLMembershipProvider (.NET2.0) 的源代码? 是可用的么? 最佳答案 源代码已经发布。 See ScottGu's blog for further de
我只想知道如何下载特定版本的 Android 源代码。我已经尝试过以下命令 repo init -u https://android.googlesource.com/platform/manifes
我想看看OpenCL框架是如何实现的。我发现的只是已经编译好的可供下载的库。 当然,OpenCL 可以有许多不同的实现,但我想看看其中的一个来了解它是如何完成的。 为了确保我自己清楚,OpenCL 框
latex 源代码列表应该是什么样子才能产生像已知书籍中那样的输出,例如 Spring 框架的输出?我尝试过使用 latex 列表包,但无法生成看起来像下面一样好的东西。因此,我主要对生成类似以下示例
PHP 是用 C 语言编写的吗?我在哪里可以在线找到 PHP 源代码而无需下载全部内容? 最佳答案 PHP 函数是用 C 编写的 - 您可以在 lxr.php.net 找到可浏览的源代码. 例如:ht
我正在使用Elasticsearch OSS的官方Docker镜像(docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.4),似乎完全无法使用s
我试图在Cython中同时编译C和C++源代码。这是我当前的设置: -setup.py from distutils.core import setup from Cython.Build impor
好吧,事情是这样的:你们所有人可能都在想同样的事情:您可以使用 driver.getPageSource(); 这部分是正确的。唯一的问题是源代码以一种相当奇怪的方式编译,所有代码都在其中 \&quo
由于 TwoLineListItem 自 API 17 起已被弃用,因此我已采取措施将其替换为自定义 XML 和 ViewHolder。但是,我真的希望我的应用程序看起来与使用 TwoLineList
要从 HttpURLConnection 获取 InputStream,我们的代码如下 urlConnection.getInputStream(); 如果InputStream是一个Abstract
我刚刚开始学习更多关于 C/C++ 的知识,我正在使用 Visual Studio 2013 来管理代码。 我正在使用 Tobii EyeX 眼睛注视系统的项目要求我能够稍微调整此代码,但是我不明白如
我在按钮上有一个IBAction,其中包含以下代码,我尝试使用它来检索 UIWebView 的源代码: - (IBAction)loadInAWebView:(id)sender { [self
我正在 asp.net 中创建一个网站,我只是想知道有什么方法可以使用 JavaScript 从图像生成调色板吗?类似于 1) http://www.cssdrive.com/imagepalette
有人可以分享 WinKill() from AutoIt 的源代码吗? ? 我想知道它如何处理消息(是/否/取消)以确保它得到正确处理。我想用它来清理桌面上的意外弹出窗口。 最佳答案 正如我们在下面的
我的问题与 Opencv 的源代码有关。在我看来不同的平台the Opencv website提供不同的代码结构。我只是想知道是否有可能为所有不同的平台提供一个源代码。使用相同的源代码,我可以针对不同
这个问题在这里已经有了答案: Convert Python program to C/C++ code? [closed] (8 个答案) 关闭 3 年前。 我一直在努力寻找一种方法将 .py 源文
我是一名优秀的程序员,十分优秀!