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