diff -r 25857e00af8e -r f422c8265ae5 mercurial/patch.py --- 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