On 10/5/2012 1:52 PM, Ross Boylan wrote:
> On 10/5/2012 1:12 PM, Steve Borho wrote:
>> On Fri, Oct 5, 2012 at 2:32 PM, Ross Boylan <[email protected]> 
>> wrote:
>>> I have output files that tend to differ in ways I don't care about
>>> between runs; in particular there is date stamp at the top of every 
>>> page.
>>> I would like to be able to avoid having those differences detected, so
>>> that it is easier to tell if anything has changed.
>>>
>>> If I could process the file before the diff tools get it, that would
>>> solve the problem.  I think doing this extra processing based on the
>>> file extension would suffice, though it might be nice to have some 
>>> other
>>> way to control it.
>>>
>>> How can I do this?  I can write a little python script to do the
>>> transform, but I don't know how to hook it up.
>>>
>>> The GUI seems to permit only the tools that tortoisehg autodetects. 
>>> If I
>>> could tell it to run my script I think I'd have a solution.
>> You need to register your script as a diff/merge tool.  See
>> contrib/mergetools.rc in the TortoiseHg repo
>>
>> https://bitbucket.org/tortoisehg/thg/src/tip/contrib/mergetools.rc
For the record, here's how I did it, along with some general discoveries 
about MergeTools.rc.
I used a lot of hard-coded paths and catered to the one case I cared 
about (2 way diff).  I also made no effort to clean up the temp files; 
on the other hand, the basic machinery seems to leave them around 
anyway--which was quite convenient for testing.

Releasing this under GPL 2 or 3.

1)  c:/Program Files/TortoiseHg/hgrc.d/MergeTools.rc
add these lines (modified from kdiff3 entries)
wrapper.priority=10
wrapper.args=--auto --L1 base --L2 parent1 --L3 parent2 $base $local 
$other -o $output
wrapper.executable=c:/Program Files/TortoiseHg/wrapper.bat
wrapper.fixeol=False
wrapper.premerge=False
wrapper.gui=True
wrapper.diffargs=--L1 '$plabel1' --L2 '$clabel' $parent $child

2) wrapper.bat is
C:/Python27/python.exe I:/LAMOC/Ross/diffwrapper.py %*
There is probably a way to combine 2 (just above) and 3 (below), but I 
didn't bother.  I guess I could have made the python executable
wrapper.executable and stuck diffwrapper.py at the start of the diffargs.

3) diffwrapper.py is
#! /usr/bin/python
# python script to suppress unintersting difference in sas output
import os.path, re, subprocess, sys, tempfile

THGDIR = "C:/Program Files/TortoiseHG"
DIFFPROG = os.path.join(THGDIR, "kdiff3.exe")
TEMPI = 5  # where to find  temporary directory
WORKINGI = 6   # where to find working copy (in usual useage)

# prepare file named fn for comparison of SAS .lst output
# result goes in tdir
# returns path of  the temporary file created
def prep_list(fn, tdir):
     #11:48 Thursday, October 11, 2012
     sub = re.compile(r"\d\d:\d\d 
(Mon|Tues|Wednes|Thurs|Fri|Satur|Sun)(day)?, 
(January|February|March|April|May|June|July|"
                      r"August|September|October|November|December) 
\d?\d, \d{4}", re.IGNORECASE)
     fout = tempfile.NamedTemporaryFile(dir=tdir, delete=False)
     foutname = fout.name
     fin = open(fn, "r")
     for line in fin:
         fout.write(sub.sub("HH:MM DDD, MM DD, YYYY", line))
     fin.close()
     fout.close()
     return foutname


temp_path = sys.argv[TEMPI]
temp_dir = os.path.dirname(temp_path)
file_type = os.path.splitext(temp_path)[1].lower()
if file_type == ".lst":
     print "lst file"
     sys.argv[0] = DIFFPROG
     sys.argv[TEMPI] = prep_list(temp_path, temp_dir)
     sys.argv[WORKINGI] = prep_list(sys.argv[WORKINGI], temp_dir)

f = open("C:/Users/rdboylan/capture2", "w")
for arg in sys.argv:
     f.write("%s\n"%arg)
f.close()
subprocess.call(sys.argv)


I put some comments in MergeTools.rc about my discoveries, some of which 
may not be exactly correct!
; This configuration file is mostly processed by Mercurial, although it 
includes modifications for THg.
; hg/mercurial/filemerge.py handles merges
; thg/tortoishg/hgqt/visdiff.py handles visual differences
; for each tool there are a series of entries like
; TOOL.PROPERTY = XX
; where TOOL is the tool name, property is the name of a feature, and XX 
is the value.
;
; GUIDE TO PROPERTIES
; filemerge.py _findtool gets the program to launch
; regkey (registry path) where to find the program
; regkeyalt (registry path) tried if regkey does not point to an executable
; assuming it finds one those it will look for
; regname (registry key?) under the registry path previously found
; If the regname lookup succeeds look for the actual executable in the path.
; regappend (string) if present, add this to previous value before 
executable search
; If that search fails, or if the necessary properties are missing, look 
instead for
; executable   (program name)
; in path
;
; symlink (boolean) True if program can handle symlinks
; binary (boolean) True if program can handle binaries
; gui (boolean) True if program has a GUI
;
; priority (signed integer?) which tool to use if multiple are available.

; from visdiff.py in tortoisehg
; dirdiff (boolean)
; dirdiff3 (boolean)
; usewin (boolean)

; values respect the following substitution parameters
; The substitutions available vary with the command.
; $parent1
; $plabel1    visual label for first file (default [working copy])
; $label1a   also 1b and 2
; $repo
; $hash
; $phash1
; $chash
; $child
; $clabel     visual label for child? (default [original])

This implies the answers to some of my question, which I'll interpolate 
below.
> Thanks. I forgot to mention that in my earlier post, though I managed 
> to track it down in c:\Program Files\TortoiseHg\hgrc.d (Windows 7). I 
> guess I can sort of figure out what an entry should look like, but is 
> there any guidance?  In particular, I'm not clear how Tortoise knows 
> which programs are 2 vs 3 way or diff vs merge. Sometimes there seem 
> to be different entries, e.g., beyondcompare2 vs beyondcompare3, while 
> other times there are individual lines like
>
> kdiff3.diffargs=--L1 '$plabel1' --L2 '$clabel' $parent $child
> kdiff3.diff3args=--L1 '$plabel1' --L2 '$clabel' --L3 '$plabel2' 
> $parent1 $child $parent2
>
> Also, do I have to create a registry entry?
No.  But it does seem the program must be on the path, and it may need 
to have an extension in PATHEXT (windows environment variable).
>
> I'm guessing priority -9 is lower than priority -3.
Yes, since my priority 10 beat kdiff3 with priority -3.
>
> Finally, what args are available through the $xxx syntax?
A few of them are indicated above.  Since I was mostly passing through 
to kdiff I just copied from it.
>
> BTW, this is another area the documentation is a bit terse:
> 4.1 says "If there are no options in either drop-down list, you must 
> install a diff/merge tool that is supported by our mergetools.rc or 
> configure your own tool." How to configure your own tool, or even the 
> location of mergetools.rc, are left to the imagination.
>
>
>>
>> I don't think you can do this on Windows in such a way that it uses
>> thg's Python interpreter, you will need to have Python installed
>> separately.
I do have a separate python.  However, when I wanted to test 
windows.findexe() I discovered I didn't have all the extensions in your 
DLL (I installed the basic python package, not one of the python for 
windows ones).

Ross


------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
Tortoisehg-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tortoisehg-discuss

Reply via email to