comparison mercurial/patch.py @ 17945:45766e2a7384

patch: make _addmodehdr a function under trydiff addmodehdr is a header helper, same as diffline, so it doesn't need to be a top-level function and can be nested under trydiff. In upcoming patches we will generalize this approach for all headers.
author Guillermo P?rez <bisho@fb.com>
date Thu, 15 Nov 2012 15:06:32 -0800
parents 7ac2a7720724
children 1e13b1184292
comparison
equal deleted inserted replaced
17944:7ac2a7720724 17945:45766e2a7384
1649 1649
1650 def diffui(*args, **kw): 1650 def diffui(*args, **kw):
1651 '''like diff(), but yields 2-tuples of (output, label) for ui.write()''' 1651 '''like diff(), but yields 2-tuples of (output, label) for ui.write()'''
1652 return difflabel(diff, *args, **kw) 1652 return difflabel(diff, *args, **kw)
1653 1653
1654
1655 def _addmodehdr(header, omode, nmode):
1656 if omode != nmode:
1657 header.append('old mode %s\n' % omode)
1658 header.append('new mode %s\n' % nmode)
1659
1660 def trydiff(repo, revs, ctx1, ctx2, modified, added, removed, 1654 def trydiff(repo, revs, ctx1, ctx2, modified, added, removed,
1661 copy, getfilectx, opts, losedatafn, prefix): 1655 copy, getfilectx, opts, losedatafn, prefix):
1662 1656
1663 def join(f): 1657 def join(f):
1664 return os.path.join(prefix, f) 1658 return os.path.join(prefix, f)
1659
1660 def addmodehdr(header, omode, nmode):
1661 if omode != nmode:
1662 header.append('old mode %s\n' % omode)
1663 header.append('new mode %s\n' % nmode)
1665 1664
1666 def diffline(a, b, revs): 1665 def diffline(a, b, revs):
1667 if opts.git: 1666 if opts.git:
1668 line = 'diff --git a/%s b/%s\n' % (a, b) 1667 line = 'diff --git a/%s b/%s\n' % (a, b)
1669 elif not repo.ui.quiet: 1668 elif not repo.ui.quiet:
1705 if f in copy: 1704 if f in copy:
1706 a = copy[f] 1705 a = copy[f]
1707 else: 1706 else:
1708 a = copyto[f] 1707 a = copyto[f]
1709 omode = gitmode[man1.flags(a)] 1708 omode = gitmode[man1.flags(a)]
1710 _addmodehdr(header, omode, mode) 1709 addmodehdr(header, omode, mode)
1711 if a in removed and a not in gone: 1710 if a in removed and a not in gone:
1712 op = 'rename' 1711 op = 'rename'
1713 gone.add(a) 1712 gone.add(a)
1714 else: 1713 else:
1715 op = 'copy' 1714 op = 'copy'
1751 else: 1750 else:
1752 oflag = man1.flags(f) 1751 oflag = man1.flags(f)
1753 nflag = ctx2.flags(f) 1752 nflag = ctx2.flags(f)
1754 binary = util.binary(to) or util.binary(tn) 1753 binary = util.binary(to) or util.binary(tn)
1755 if opts.git: 1754 if opts.git:
1756 _addmodehdr(header, gitmode[oflag], gitmode[nflag]) 1755 addmodehdr(header, gitmode[oflag], gitmode[nflag])
1757 if binary: 1756 if binary:
1758 dodiff = 'binary' 1757 dodiff = 'binary'
1759 elif binary or nflag != oflag: 1758 elif binary or nflag != oflag:
1760 losedatafn(f) 1759 losedatafn(f)
1761 1760