【问题标题】:Retrieving the version number of a source file in ClearCase在 ClearCase 中检索源文件的版本号
【发布时间】:2009-02-14 08:32:43
【问题描述】:

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

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

【问题讨论】:

  • 您可以在 C# 中使用 Clearcase 自动化 COM 库

标签: c# clearcase visual-studio-addins


【解决方案1】:

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

更具体地说,descrformat option 仅显示准确您所追求的内容。

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 question 中解释的那样,您也可以使用CAL interface(COM 对象),但我一直发现cleartool(基本CLI -- 命令行界面 --)更可靠,尤其是当出现问题时:错误信息更加准确。

【讨论】:

  • 超级酷。我实际上发现了如何轻松使用“描述”。但是,-fmt 选项很有帮助,因为它减少了解析整个描述的开销。
【解决方案2】:

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

【讨论】:

    【解决方案3】:

    您必须从 COM 添加 Clearcase 自动化引用,然后这是可以让您获得源文件的版本和分支名称的代码。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-06
      • 1970-01-01
      相关资源
      最近更新 更多