comparison mercurial/patch.py @ 12167:d2c5b0927c28

diff: recurse into subrepositories with --subrepos/-S flag
author Martin Geisler <mg@lazybytes.net>
date Fri, 03 Sep 2010 12:58:51 +0200
parents be9c4131a8f4
children 00658492e2aa
comparison
equal deleted inserted replaced
12166:441a74b8def1 12167:d2c5b0927c28
1402 ignorewsamount=get('ignore_space_change', 'ignorewsamount'), 1402 ignorewsamount=get('ignore_space_change', 'ignorewsamount'),
1403 ignoreblanklines=get('ignore_blank_lines', 'ignoreblanklines'), 1403 ignoreblanklines=get('ignore_blank_lines', 'ignoreblanklines'),
1404 context=get('unified', getter=ui.config)) 1404 context=get('unified', getter=ui.config))
1405 1405
1406 def diff(repo, node1=None, node2=None, match=None, changes=None, opts=None, 1406 def diff(repo, node1=None, node2=None, match=None, changes=None, opts=None,
1407 losedatafn=None): 1407 losedatafn=None, prefix=''):
1408 '''yields diff of changes to files between two nodes, or node and 1408 '''yields diff of changes to files between two nodes, or node and
1409 working directory. 1409 working directory.
1410 1410
1411 if node1 is None, use first dirstate parent instead. 1411 if node1 is None, use first dirstate parent instead.
1412 if node2 is None, compare node1 with working directory. 1412 if node2 is None, compare node1 with working directory.
1416 patch format. Return False to upgrade to git patch format, True to 1416 patch format. Return False to upgrade to git patch format, True to
1417 accept the loss or raise an exception to abort the diff. It is 1417 accept the loss or raise an exception to abort the diff. It is
1418 called with the name of current file being diffed as 'fn'. If set 1418 called with the name of current file being diffed as 'fn'. If set
1419 to None, patches will always be upgraded to git format when 1419 to None, patches will always be upgraded to git format when
1420 necessary. 1420 necessary.
1421
1422 prefix is a filename prefix that is prepended to all filenames on
1423 display (used for subrepos).
1421 ''' 1424 '''
1422 1425
1423 if opts is None: 1426 if opts is None:
1424 opts = mdiff.defaultopts 1427 opts = mdiff.defaultopts
1425 1428
1460 copy = {} 1463 copy = {}
1461 if opts.git or opts.upgrade: 1464 if opts.git or opts.upgrade:
1462 copy = copies.copies(repo, ctx1, ctx2, repo[nullid])[0] 1465 copy = copies.copies(repo, ctx1, ctx2, repo[nullid])[0]
1463 1466
1464 difffn = lambda opts, losedata: trydiff(repo, revs, ctx1, ctx2, 1467 difffn = lambda opts, losedata: trydiff(repo, revs, ctx1, ctx2,
1465 modified, added, removed, copy, getfilectx, opts, losedata) 1468 modified, added, removed, copy, getfilectx, opts, losedata, prefix)
1466 if opts.upgrade and not opts.git: 1469 if opts.upgrade and not opts.git:
1467 try: 1470 try:
1468 def losedata(fn): 1471 def losedata(fn):
1469 if not losedatafn or not losedatafn(fn=fn): 1472 if not losedatafn or not losedatafn(fn=fn):
1470 raise GitDiffRequired() 1473 raise GitDiffRequired()
1516 if omode != nmode: 1519 if omode != nmode:
1517 header.append('old mode %s\n' % omode) 1520 header.append('old mode %s\n' % omode)
1518 header.append('new mode %s\n' % nmode) 1521 header.append('new mode %s\n' % nmode)
1519 1522
1520 def trydiff(repo, revs, ctx1, ctx2, modified, added, removed, 1523 def trydiff(repo, revs, ctx1, ctx2, modified, added, removed,
1521 copy, getfilectx, opts, losedatafn): 1524 copy, getfilectx, opts, losedatafn, prefix):
1525
1526 def join(f):
1527 return os.path.join(prefix, f)
1522 1528
1523 date1 = util.datestr(ctx1.date()) 1529 date1 = util.datestr(ctx1.date())
1524 man1 = ctx1.manifest() 1530 man1 = ctx1.manifest()
1525 1531
1526 gone = set() 1532 gone = set()
1555 if a in removed and a not in gone: 1561 if a in removed and a not in gone:
1556 op = 'rename' 1562 op = 'rename'
1557 gone.add(a) 1563 gone.add(a)
1558 else: 1564 else:
1559 op = 'copy' 1565 op = 'copy'
1560 header.append('%s from %s\n' % (op, a)) 1566 header.append('%s from %s\n' % (op, join(a)))
1561 header.append('%s to %s\n' % (op, f)) 1567 header.append('%s to %s\n' % (op, join(f)))
1562 to = getfilectx(a, ctx1).data() 1568 to = getfilectx(a, ctx1).data()
1563 else: 1569 else:
1564 losedatafn(f) 1570 losedatafn(f)
1565 else: 1571 else:
1566 if opts.git: 1572 if opts.git:
1598 if binary: 1604 if binary:
1599 dodiff = 'binary' 1605 dodiff = 'binary'
1600 elif binary or nflag != oflag: 1606 elif binary or nflag != oflag:
1601 losedatafn(f) 1607 losedatafn(f)
1602 if opts.git: 1608 if opts.git:
1603 header.insert(0, mdiff.diffline(revs, a, b, opts)) 1609 header.insert(0, mdiff.diffline(revs, join(a), join(b), opts))
1604 1610
1605 if dodiff: 1611 if dodiff:
1606 if dodiff == 'binary': 1612 if dodiff == 'binary':
1607 text = b85diff(to, tn) 1613 text = b85diff(to, tn)
1608 else: 1614 else:
1609 text = mdiff.unidiff(to, date1, 1615 text = mdiff.unidiff(to, date1,
1610 # ctx2 date may be dynamic 1616 # ctx2 date may be dynamic
1611 tn, util.datestr(ctx2.date()), 1617 tn, util.datestr(ctx2.date()),
1612 a, b, revs, opts=opts) 1618 join(a), join(b), revs, opts=opts)
1613 if header and (text or len(header) > 1): 1619 if header and (text or len(header) > 1):
1614 yield ''.join(header) 1620 yield ''.join(header)
1615 if text: 1621 if text:
1616 yield text 1622 yield text
1617 1623