hgbook

annotate examples/hg-interdiff @ 106:9cbc5d0db542

Finish off advanced MQ chapter (maybe).
author Bryan O'Sullivan <bos@serpentine.com>
date Mon Oct 23 15:43:04 2006 -0700 (2006-10-23)
parents
children ba2334e2ba9a
rev   line source
bos@106 1 #!/usr/bin/env python
bos@106 2 #
bos@106 3 # Adapter for using interdiff with mercurial's extdiff extension.
bos@106 4 # Copyright 2006 Bryan O'Sullivan <bos@serpentine.com>
bos@106 5
bos@106 6 import os, sys
bos@106 7
bos@106 8 def walk(base):
bos@106 9 # yield all non-directories below the base path.
bos@106 10 for root, dirs, files in os.walk(base):
bos@106 11 for f in files:
bos@106 12 path = os.path.join(root, f)
bos@106 13 yield path[len(base)+1:], path
bos@106 14
bos@106 15 # create list of unique file names under both directories.
bos@106 16 files = dict(walk(sys.argv[1]))
bos@106 17 files.update(walk(sys.argv[2]))
bos@106 18 files = files.keys()
bos@106 19 files.sort()
bos@106 20
bos@106 21 def name(base, f):
bos@106 22 # interdiff requires two files; use /dev/null if one is missing.
bos@106 23 path = os.path.join(base, f)
bos@106 24 if os.path.exists(path):
bos@106 25 return path
bos@106 26 return '/dev/null'
bos@106 27
bos@106 28 ret = 0
bos@106 29
bos@106 30 for f in files:
bos@106 31 if os.system('interdiff "%s" "%s"' % (name(sys.argv[1], f),
bos@106 32 name(sys.argv[2], f))):
bos@106 33 ret = 1
bos@106 34
bos@106 35 sys.exit(ret)