get_views_for_stream/create_dev_snapview.pl

  • Posted on
  • by
  • in
  • Found and fixed bug in get_views_for_stream
  • Fixed bug in create_dev_snapview.pl::ParseBaselines

get_views_for_stream

Hi Naga. I'm writing you this because I believe there's a bug, possibly with Clearcase, but that seems to manifest itself in code I believe you wrote. I came across this implementing enhancements to create_dev_snapview.pl for Andrew Feltham. In essence Andrew wants to be able to have multiple views in a stream. I've implemented a -reuse_stream parm to allow this. If -reuse_stream is used then the code will skip recreating the stream and effectively just make another view in that same stream. If -reuse_stream is not specified then the stream is removed - along with any views that that stream has.

It appears as if the code was coded to attempt to handle the case where a stream has multiple views however it fails due to a possible but with lsstream. When calling create_stream the code checks to see if the stream exists and if it does it attempts to recreate the stream by determining the view(s) in the stream, deleting them, deleting the stream and creating the stream anew.

To determine the view(s) in the stream get_views_for_stream is called. Here's the original function:

sub get_views_for_stream {
    my $sel_pvob = $_[0];
    my $sel_stream = $_[1];

    my @views = split(/\n/, `cleartool lsstream -fmt \"\%\[views\]p\\n\" stream:$sel_stream\@\\$sel_pvob`);
    return @views;
}

Essentially it does an lsstream asking for only the views, separated by newlines. The problem is that lsstream (with that format) does not return the views separated by newlines:

P:\>cleartool lsstream -fmt "%[views]p\n" stream:Build_rmnaNT_adefaria_LTSJCA-ADEFARIA_sv_ldx_2.3@\rmna_projects
adefaria_test adefaria_test2 adefaria_test3

P:\>

As you can see adefaria_test, adefaria_test2 and adefaria_test3 all appear on the same line. The code then splits the line on \n and effectively always returns a 1 entry array with possibly multiple view names in the first entry separated by spaces. Needless to say this will fail later on when remove_view is called and it generates a "cleartool rmview -force <view names>".

Here's my proposed fix:

sub get_views_for_stream {
    my $sel_pvob = $_[0];
    my $sel_stream = $_[1];
    # Modified Wed Dec 14 11:25:09 PST 2005 Andrew@DeFaria.com
    #
    # Note: The format -fmt "%[views]p\n" below does not work! What is
    # expected to be returned is:
    #
    # view1
    # view2
    # view3
    #
    # However what is actually returned is:
    #
    # view1 view2 view3
    #
    # Therefore the old spilt of /\n/ always returned a single entry
    # array with possibly multiple view names in the first
    # entry. Changed to use / / for split and not append a \n.
    my @views = split(/ /, `cleartool lsstream -fmt \"\%\[views\]p\" stream:$sel_stream\@\\$sel_pvob`);
    return @views;
}

Is this acceptable to you?