2

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.

ckcin
  • 49
  • 1
  • 6

2 Answers2

3

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.)

einpoklum
  • 118,144
  • 57
  • 340
  • 684
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • is there a way to use diff directly with snapshot views? – ckcin Dec 19 '13 at 16:24
  • @ckcin not easily, considering extended pathname aren't directly readable from a snapshot view (see http://stackoverflow.com/a/177350/6309, although you can actually try a `cleartool get`: see http://stackoverflow.com/a/18716494/6309). I would stick with dynamic view. – VonC Dec 19 '13 at 16:26
  • What `$CLEARCASE_PN` and `$CLEARCASE_XPN` here? who sets then? – einpoklum May 24 '20 at 10:06
  • 1
    @einpoklum path names and extended path names, set by the `cleartool find` command for each and every elements found by said command (`cleartool find`), fir the `-exec` directive to use. – VonC May 24 '20 at 10:59
2

Transferring the answer from VonC and einpoklum to Windows I came up with the following. Create a separate batch file, which I called diffClearCase.bat, this eases up the command line significantly. It creates a separate tree for all modified files, which I personally liked, but the file and folders can be deleted afterwards.

@echo off
SET PLAINFILE=%1
SET PLAINDIR=%~dp1
SET CLEARCASE_FILE=%2
SET BRANCH_NAME=%3
SET SOURCE_DRIVE=T:
SET TARGET_TEMP_DIR=D:
SET DIFF_TARGET_FILE=D:\allPatch.diff
call set BASE_FILE=%%CLEARCASE_FILE:%BRANCH_NAME%=LATEST%%
call set TARGET_FILE=%%PLAINFILE:%SOURCE_DRIVE%=%TARGET_TEMP_DIR%%%
call set TARGET_DIR=%%PLAINDIR:%SOURCE_DRIVE%=%TARGET_TEMP_DIR%%%
echo Diffing file %PLAINFILE%
IF NOT EXIST %TARGET_DIR% mkdir %TARGET_DIR%
cleartool get -to %TARGET_FILE% %BASE_FILE%
diff -u %TARGET_FILE% %PLAINFILE% >> %DIFF_TARGET_FILE%
rem del /F/Q %TARGET_FILE%

And then I created a second bat file which simply takes the branch name as argument. In our case this directory contains multiple VOBs, so I iterate over them and do this per VOB.

@echo off
SET BRANCHNAME=%1
SET DIFF_TARGET_FILE=D:\allPatch.diff
SET SOURCE_DRIVE=T:
SET DIFF_TOOL=D:\Data\Scripts\diffClearCase.bat
IF EXIST %DIFF_TARGET_FILE% DEL /Q %DIFF_TARGET_FILE%
for /D %%V in ("%SOURCE_DRIVE%\*") DO (
    echo Checking VOB %%V
    cd %%V
    cleartool find %%V -type f -branch "brtype(%BRANCHNAME%)" -exec "%DIFF_TOOL% \"%%CLEARCASE_PN%%\" \"%%CLEARCASE_XPN%%\" %BRANCHNAME%"
)
Karsten Becker
  • 502
  • 5
  • 11