hgbook

diff contrib/hg-interdiff @ 622:2180358c32c4

Move some files to contrib
author Dongsheng Song <dongsheng.song@gmail.com>
date Thu Mar 12 15:40:40 2009 +0800 (2009-03-12)
parents examples/hg-interdiff@f992b16d18a1
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/contrib/hg-interdiff	Thu Mar 12 15:40:40 2009 +0800
     1.3 @@ -0,0 +1,45 @@
     1.4 +#!/usr/bin/env python
     1.5 +#
     1.6 +# Adapter for using interdiff with mercurial's extdiff extension.
     1.7 +#
     1.8 +# Copyright 2006 Bryan O'Sullivan <bos@serpentine.com>
     1.9 +#
    1.10 +# This software may be used and distributed according to the terms of
    1.11 +# the GNU General Public License, incorporated herein by reference.
    1.12 +
    1.13 +import os, sys
    1.14 +
    1.15 +def walk(base):
    1.16 +    # yield all non-directories below the base path.
    1.17 +    for root, dirs, files in os.walk(base):
    1.18 +        for f in files:
    1.19 +            path = os.path.join(root, f)
    1.20 +            yield path[len(base)+1:], path
    1.21 +    else:
    1.22 +        if os.path.isfile(base):
    1.23 +            yield '', base
    1.24 +
    1.25 +# create list of unique file names under both directories.
    1.26 +files = dict(walk(sys.argv[1]))
    1.27 +files.update(walk(sys.argv[2]))
    1.28 +files = files.keys()
    1.29 +files.sort()
    1.30 +
    1.31 +def name(base, f):
    1.32 +    if f:
    1.33 +        path = os.path.join(base, f)
    1.34 +    else:
    1.35 +        path = base
    1.36 +    # interdiff requires two files; use /dev/null if one is missing.
    1.37 +    if os.path.exists(path):
    1.38 +        return path
    1.39 +    return '/dev/null'
    1.40 +
    1.41 +ret = 0
    1.42 +
    1.43 +for f in files:
    1.44 +    if os.system('interdiff "%s" "%s"' % (name(sys.argv[1], f),
    1.45 +                                          name(sys.argv[2], f))):
    1.46 +        ret = 1
    1.47 +
    1.48 +sys.exit(ret)