diffclearcase

clearcase create diff between parent and child branches


So the typical way I would create a diff log/patch between two branches in clearcase would to simply create two views and do a typical unix diff. But I have to assume that there is a more clearcase way (and also a '1-liner').

so knowing how to get a list of all files that have been modified on a branch:

cleartool find . -type f -branch "brtype(<BRANCH_NAME>)" -print

and knowing how to get the diff formatted output for two separate files:

cleartool diff FILE FILE@@/main/PARENT_BRANCH_PATH/LATEST

so does anyone see any issues with the following to get a diff for all files that have been changed in a branch?

cleartool find . -type f -branch "brtype(CHILD_BRANCH)" -exec 'cleartool diff -ser $CLEARCASE_PN `echo $CLEARCASE_XPN | sed "s/CHILD_BRANCH/LATEST/"` ' > diff.log

Any modifications and comments are greatly welcomed

thanks in advance!

update: any ideas on how to get this too be a unix unified diff would also be greatly appreciated.

update2: So I think I have my solution, thanks go to VonC for sending me in the right directions:

cleartool find . -type f -branch "brtype(CHILD_BRANCH)" -exec 'cleartool get -to $CLEARCASE_PN.prev `echo $CLEARCASE_XPN | sed "s/CHILD_BRANCH/LATEST/"`; diff -u $CLEARCASE_PN.prev $CLEARCASE_PN; rm -f $CLEARCASE_PN.prev' > CHILD_BRANCH.diff

the output seems to work, I can read the file in via kompare without complaints.


Solution

  • The idea is sound.

    I would simply make sure the $CLEARCASE_PN and $CLEARCASE_XPN are used with double quotes around them, to take into account with potential spaces in the file path or file name (as illustrated in "How do I list ClearCase versions without the Fully-qualified version?").

    cleartool find . -type f -branch "brtype(CHILD_BRANCH)" -exec 'cleartool diff -ser "$CLEARCASE_PN" `echo "$CLEARCASE_XPN" | sed "s/CHILD_BRANCH/LATEST/"` ' > diff.log
    

    Using simple quotes for the -exec directive is a good idea, as explained in "CLEARCASE_XPN not parsed as variable in clearcase command".


    However, cleartool diff, even with the -ser (-serial) option don't produce exactly an Unix unified diff format (or Unified Format for short).

    The -diff(_format) option is the closest, as I mention in "How would you measure inserted / changed / removed code lines (LoC)?"

    The -diff_format option causes both the headers and differences to be reported in the style of the UNIX and Linux diff utility, writing a list of the changes necessary to convert the first file being compared into the second file.

    One idea would be to not use cleartool diff, but use directly diff, since it can access in a dynamic view the right version through the extended pathname of the elements found.


    The OP ckcin's solution is close that what I suggested with cleartool get:

    cleartool find . -type f -branch "brtype(CHILD_BRANCH)" -exec 'cleartool get -to $CLEARCASE_PN.prev `echo $CLEARCASE_XPN | sed "s/CHILD_BRANCH/LATEST/"`; diff -u $CLEARCASE_PN.prev $CLEARCASE_PN; rm -f $CLEARCASE_PN.prev' > CHILD_BRANCH.diff 
    

    the output seems to work, I can read the file in via kompare without complaints.

    In multiple line, for readability:

    cleartool find . -type f -branch "brtype(CHILD_BRANCH)" 
      -exec 'cleartool get -to $CLEARCASE_PN.prev 
               `echo $CLEARCASE_XPN | sed "s/CHILD_BRANCH/LATEST/"`; 
             diff -u $CLEARCASE_PN.prev $CLEARCASE_PN; 
             rm -f $CLEARCASE_PN.prev' > CHILD_BRANCH.diff 
    

    (Note that $CLEARCASE_XPN and $CLEARCASE_PN are set by the cleartool find commant, they're not variables you set yourself.)