Mercurial > public > mercurial-scm > hg-stable
comparison 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 |
comparison
equal
deleted
inserted
replaced
3095:25857e00af8e | 3096:f422c8265ae5 |
---|---|
7 | 7 |
8 from demandload import demandload | 8 from demandload import demandload |
9 from i18n import gettext as _ | 9 from i18n import gettext as _ |
10 from node import * | 10 from node import * |
11 demandload(globals(), "cmdutil mdiff util") | 11 demandload(globals(), "cmdutil mdiff util") |
12 demandload(globals(), "cStringIO email.Parser errno os re shutil sys tempfile") | 12 demandload(globals(), '''cStringIO email.Parser errno os re shutil sys tempfile |
13 popen2''') | |
13 | 14 |
14 # helper functions | 15 # helper functions |
15 | 16 |
16 def copyfile(src, dst, basedir=None): | 17 def copyfile(src, dst, basedir=None): |
17 if not basedir: | 18 if not basedir: |
548 if fp not in (sys.stdout, repo.ui): | 549 if fp not in (sys.stdout, repo.ui): |
549 fp.close() | 550 fp.close() |
550 | 551 |
551 for seqno, cset in enumerate(revs): | 552 for seqno, cset in enumerate(revs): |
552 single(cset, seqno, fp) | 553 single(cset, seqno, fp) |
554 | |
555 def diffstat(patchlines): | |
556 fd, name = tempfile.mkstemp(prefix="hg-patchbomb-", suffix=".txt") | |
557 try: | |
558 p = popen2.Popen3('diffstat -p1 -w79 2>/dev/null > ' + name) | |
559 try: | |
560 for line in patchlines: print >> p.tochild, line | |
561 p.tochild.close() | |
562 if p.wait(): return | |
563 fp = os.fdopen(fd, 'r') | |
564 stat = [] | |
565 for line in fp: stat.append(line.lstrip()) | |
566 last = stat.pop() | |
567 stat.insert(0, last) | |
568 stat = ''.join(stat) | |
569 if stat.startswith('0 files'): raise ValueError | |
570 return stat | |
571 except: raise | |
572 finally: | |
573 try: os.unlink(name) | |
574 except: pass |