在 ClearCase 中检索源文件的版本号

发布于 2024-07-13 20:01:25 字数 116 浏览 6 评论 0原文

我创建了一个小插件来帮助我进行源代码控制。

有谁知道我如何在 Rational ClearCase 中检索源文件的分支名称和版本号。 我想使用 C# 来完成此操作。 所有信息实际存储在哪里?

I creating a small addin to help with my source control.

Does anybody know how I could retrieve the Branch Name and Version Number of a source file in Rational ClearCase. I want to do this using C#. Where is all the information actually stored?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

汐鸠 2024-07-20 20:01:25

您需要在 C# 中执行 cleartool 命令,

更具体地说,是一个 descr ,其中包含 格式选项仅显示准确< /em> 你在追求什么。

cleartool descr -fmt "%Sn" youFileFullPath

这将返回一个类似 /main/34 的字符串,意思是 /branch/version

System.Diagnostics.ProcessStartInfo psi =
new System.Diagnostics.ProcessStartInfo(@"cleartool");
psi.RedirectStandardOutput = true;
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
psi.Arguments = "descr -fmt \"%Sn\" \"" + yourFilePath + "\"";
psi.UseShellExecute = false;
System.Diagnostics.Process monProcess;
monProcess= System.Diagnostics.Process.Start(psi);
System.IO.StreamReader myOutput = monProcess.StandardOutput;
monProcess.WaitForExit();
if (monProcess.HasExited)
{
    //la sortie du process est recuperee dans un string
    string output = myOutput.ReadToEnd();
    MessageBox.Show(output);
}

注意:建议始终在文件完整路径周围使用双引号,以防该路径或者文件名包含空格


正如我在其他 ClearCase SO 问题中所解释的,您也可以使用 CAL 接口(COM 对象),但我一直找到 cleartool(基本的 CLI——命令行界面——)更可靠,尤其是在出现问题时:错误消息更加精确。

You need, from C#, to execute a cleartool command

More specifically, a descr with a format option only displaying exactly what you are after.

cleartool descr -fmt "%Sn" youFileFullPath

That will return a string like /main/34, meaning /branch/version

System.Diagnostics.ProcessStartInfo psi =
new System.Diagnostics.ProcessStartInfo(@"cleartool");
psi.RedirectStandardOutput = true;
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
psi.Arguments = "descr -fmt \"%Sn\" \"" + yourFilePath + "\"";
psi.UseShellExecute = false;
System.Diagnostics.Process monProcess;
monProcess= System.Diagnostics.Process.Start(psi);
System.IO.StreamReader myOutput = monProcess.StandardOutput;
monProcess.WaitForExit();
if (monProcess.HasExited)
{
    //la sortie du process est recuperee dans un string
    string output = myOutput.ReadToEnd();
    MessageBox.Show(output);
}

Note: it is recommended to always use double quotes around your file full path, in case that path or that file name includes spaces


As I have explained in this other ClearCase SO question, you could also use the CAL interface (COM object), but I have always found cleartool (the basic CLI -- Command Line Interface --) more reliable especially when things go wrong: the error message is much more precise.

夜访吸血鬼 2024-07-20 20:01:25

您最好的选择可能是使用cleartool.exe命令行并解析结果。 理想情况下,这通常是通过 perl 或 python 脚本完成的,但它也可以通过 C# 运行。 我怀疑您会找到任何更直接的方式来询问如此简单的clearcase。

Your best bet is probably to use the cleartool.exe command line and parse the result. Ideally this is usually done from a perl or python script but it'll work from C# as well. I doubt you'll find any more direct way of interrogating clearcase which is as simple.

如梦 2024-07-20 20:01:25

您必须从 COM 添加 Clearcase Automation 引用,然后这是获取源文件的版本和分支名称的代码。

ClearCase.Application cc = new ClearCase.Application();
ClearCase.CCView view = cc.get_View("YOUR VIEW");
ClearCase.CCActivity activity = view.CurrentActivity;
ClearCase.CCVersions versions = activity.get_ChangeSet(view);

int nVersion = -1;
String name = String.Empty;

foreach (ClearCase.CCVersion version in versions)
{
      if (version.Path.Contains("YOUR FILENAME"))
      {
           nVersion = version.VersionNumber;
           ClearCase.CCBranch branch = version.Branch;
           ClearCase.CCBranchType type = branch.Type;
           name = type.Name;
           break;
      }
}

You'll have to add Clearcase Automation reference from COM, then this is the code that will get you the version and branch name of your source file.

ClearCase.Application cc = new ClearCase.Application();
ClearCase.CCView view = cc.get_View("YOUR VIEW");
ClearCase.CCActivity activity = view.CurrentActivity;
ClearCase.CCVersions versions = activity.get_ChangeSet(view);

int nVersion = -1;
String name = String.Empty;

foreach (ClearCase.CCVersion version in versions)
{
      if (version.Path.Contains("YOUR FILENAME"))
      {
           nVersion = version.VersionNumber;
           ClearCase.CCBranch branch = version.Branch;
           ClearCase.CCBranchType type = branch.Type;
           name = type.Name;
           break;
      }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文