Mercurial > hg > mercurial-crew-with-dirclash
diff mercurial/patch.py @ 3093:f422c8265ae5
Add support for diffstat in commit emails, and move diffstat from
patchbomb to patch
author | Matt Doar <matt@xensource.com> |
---|---|
date | Wed, 13 Sep 2006 13:14:08 -0700 |
parents | 035fd2029575 |
children | e43fd1623fe1 |
line wrap: on
line diff
--- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -9,7 +9,8 @@ from demandload import demandload from i18n import gettext as _ from node import * demandload(globals(), "cmdutil mdiff util") -demandload(globals(), "cStringIO email.Parser errno os re shutil sys tempfile") +demandload(globals(), '''cStringIO email.Parser errno os re shutil sys tempfile + popen2''') # helper functions @@ -550,3 +551,24 @@ def export(repo, revs, template='hg-%h.p for seqno, cset in enumerate(revs): single(cset, seqno, fp) + +def diffstat(patchlines): + fd, name = tempfile.mkstemp(prefix="hg-patchbomb-", suffix=".txt") + try: + p = popen2.Popen3('diffstat -p1 -w79 2>/dev/null > ' + name) + try: + for line in patchlines: print >> p.tochild, line + p.tochild.close() + if p.wait(): return + fp = os.fdopen(fd, 'r') + stat = [] + for line in fp: stat.append(line.lstrip()) + last = stat.pop() + stat.insert(0, last) + stat = ''.join(stat) + if stat.startswith('0 files'): raise ValueError + return stat + except: raise + finally: + try: os.unlink(name) + except: pass