Enhancement made to tkdiff: diffing two depot files directly

JedIrvineirvine at roguewave.com JedIrvineirvine at roguewave.com
Fri Apr 3 11:07:54 PST 1998


John,

Thanks for contributing tkdiff as shareware.  I pulled it from the Perforce web site and am using it
to help evaluate whether our company as a whole will switch to perforce as a CM system.  It
was great to get your code and to be able to modify it easily to adapt it to our needs.
I'm including the enhancement I made (just the changed section) in case you want to incorporate it.
The minor mod is to allow the following syntax:

tkdiff -depot file1 file2

This allows directly diffing two depot files which is something that our current perforce users wanted.
Basically I call "p4 print" on the two files, trim off the header that "p4 print" applies and throw the
trimmed files to your code.  Also, I adjust the titles of the displayed files to reflect the depot name of the
file.  One assumption I made was that the two depot file names are correct and exist as we have a different
driving the tkdiff which takes care of that.  Thanks to your easy-to-comprehend and well organized code, this 
was an easy fix!  

I added a single chunk of code to the if/elseif sequence in the procedure init_files


    } elseif {[regexp {^([^-][^ ]*) ([^-][^ ]*)$} $cmd d f1 f2]} {

        ############################################################
        #  tkdiff FILE1 FILE2
        ############################################################

        if {[file isdirectory $f1] && [file isdirectory $f2]} {
            puts stderr "Either <file1> or <file2> must be a plain file."
            exit
        }

        if {[file isdirectory $f1]} {
            set f1 "[string trimright $f1 /]/[file tail $f2]"
        } elseif {[file isdirectory $f2]} {
            set f2 "[string trimright $f2 /]/[file tail $f1]"
        }

        if {[file exists $f1] != 1} {
            puts stderr "$f1 does not exist."
            exit
        } elseif {[file exists $f2] != 1} {
            puts stderr "$f2 does not exist."
            exit
        }

        set finfo(lbl,1) "$f1"
        set finfo(pth,1) "$f1"
        set finfo(lbl,2) "$f2"
        set finfo(pth,2) "$f2"
=============================================<- start of new code
    #######################################
   # patch added by Jed Irvine 3/31/98
   #
   # the tkdiff -depot f1 f2 feature support diffing two files directly
   # from the depot.  To do this, we use the p4 print command which dumps
   # out the file contents of depot files.  Then we take that output, trim
   # off the header supplied by p4 print, and then diff the resulting files
   # (which should reflect exactly the true contents in the depot).
   #######################################
    } elseif {[regexp {^-depot[ ]+([^-][^ ]*) ([^-][^ ]*)$} $cmd d f1 f2]} {

        ############################################################
        #  tkdiff -depot FILE1 FILE2
        ############################################################

	set username [exec whoami]
	set filename_left_raw   /tmp/tk_depotdiff.left.$username
	set filename_right_raw  /tmp/tk_depotdiff.right.$username
	set filename_left_true  /tmp/tk_depotdiff.left.true.$username
	set filename_right_true /tmp/tk_depotdiff.right.true.$username

	#...assume two depot files are valid
	exec p4 print $f1  > $filename_left_raw
	exec p4 print $f2 > $filename_right_raw
	
	#...trim out left info
	set fl_raw  [open $filename_left_raw r]
	set fl_true [open $filename_left_true w]
	gets $fl_raw depot_info_line_left
	puts $depot_info_line_left
	while { [gets $fl_raw foo_line] >= 0} { puts $fl_true $foo_line }
	close $fl_raw
	close $fl_true

	#...trim out right info
	set fr_raw  [open $filename_right_raw r]
	set fr_true [open $filename_right_true w]
	gets $fr_raw depot_info_line_right
	while { [gets $fr_raw foo_line] >= 0} { puts $fr_true $foo_line }
	close $fr_raw
	close $fr_true


	exec rm $filename_left_raw $filename_right_raw

	set left_label [lindex $depot_info_line_left 0]
	set right_label [lindex $depot_info_line_right 0]


            set finfo(lbl,1) "$left_label"
            set finfo(pth,1) "$filename_left_true"
	set finfo(tmp,1) 1
            set finfo(lbl,2) "$right_label"
            set finfo(pth,2) "$filename_right_true"
	set finfo(tmp,2) 1
==================================================== <---end of new code
    } elseif {[regexp {^([^-][^ ]*)$} $cmd d f]} {

        ############################################################
        #  tkdiff FILE
        ############################################################

        if {[file exists $f] != 1 || [file isdirectory $f]} {
            puts stderr "$f does not exist or is a directory."
            exit
        }

Thanks again,

Jed Irvine

p.s. in the off-chance that you aren't supporting tkdiff anymore or aren't at this address anymore, I've cc'd the
perforce user mailing list directly if folks there are interested.






More information about the perforce-user mailing list