Mercurial > public > mercurial-scm > hg
diff mercurial/patch.py @ 3096: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 Thu Sep 14 19:24:00 2006 -0700 +++ b/mercurial/patch.py Wed Sep 13 13:14:08 2006 -0700 @@ -9,7 +9,8 @@ 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 @@ 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