Base ClearCase FAQ: 1.3.6. How to use annotate to produce a greppable output (directory elements)?

See here for file elements.

The annotate tool is mostly interesting with grep post-processing. It is not obvious to set up with text files, but it is even more tricky with directories, since the whole information is in the header part of the output, mostly in the comments.

In fact, one uses annotate almost as plain ct lshis -d, with the main difference that the latter takes branch activity into account, which the former doesn't.

The following gives something greppable (1545 lines):

$ ct annotate -nda -out - -fmt ",%Nd %Vn %u %o:%c\n" -rm . | tail +3 | egrep -v '^\s*$' | perl -ne 'if(/^([^:]+):(.*)$/){$k=$1;push @{$t{$k}},$2}else{push @{$t{$k}}, $_};END{foreach $k (reverse sort keys %t){map{print"$k $_\n"}@{$t{$k}}}}'
The same post-processing can be used for the output of ct lshis -d -fmt "%Nd %Vn %u %o:%c\n" either if one wants the activity within the branches (finer grain), or just for simplicity...

E.g.

$ ct lshis -d -fmt "%Nd %Vn %u %o:%c\n" . | perl -ne 'if(/^([^:]+):(.*)$/){$k=$1;push @{$t{$k}},$2}else{push @{$t{$k}}, $_};END{foreach $k (reverse sort keys %t){map{print"$k $_\n"}@{$t{$k}}}}' | grep cppemuconfig
20080108.130606 /main/23 vobcade checkin Added symbolic link "cppemuconfig".
20071217.063940 /main/21 vobcade checkin Uncataloged symbolic link "cppemuconfig".
20060328.142612 /main/4 erabodo checkin Added symbolic link "cppemuconfig".
20060328.142612 /main/4 erabodo checkin Uncataloged symbolic link "cppemuconfig".
20060328.142612 /main/4 erabodo checkin Added symbolic link "cppemuconfig".

Notes

  • The ':' sign is important in the format, as it is used as separator between the event info and the comment.
  • The time (or whatever is printed first) format must be sortable.
  • What the perl code does is it prefixes all the comment lines with information on the event (time stamp, version, account, and operation).
    This way the output is line-oriented: one may grep it for the file names (present in the comments), and get the event information.

-- MarcGirod - 15 Feb 2009