changeset 10611:e764f24a45ee

patch/diff: move patch.export() to cmdutil.export() This API change will allow us to break a cycle between patch and cmdutil.
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Mon, 08 Mar 2010 19:43:24 +0100
parents eea2db5f56ba
children 312997642788
files hgext/hgcia.py hgext/mq.py hgext/patchbomb.py mercurial/cmdutil.py mercurial/commands.py mercurial/patch.py
diffstat 6 files changed, 44 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/hgcia.py	Mon Mar 08 11:12:48 2010 -0600
+++ b/hgext/hgcia.py	Mon Mar 08 19:43:24 2010 +0100
@@ -113,7 +113,7 @@
 
         n = self.ctx.node()
         pbuf = patchbuf()
-        patch.export(self.cia.repo, [n], fp=pbuf)
+        cmdutil.export(self.cia.repo, [n], fp=pbuf)
         return patch.diffstat(pbuf.lines) or ''
 
     def logmsg(self):
--- a/hgext/mq.py	Mon Mar 08 11:12:48 2010 -0600
+++ b/hgext/mq.py	Mon Mar 08 19:43:24 2010 +0100
@@ -1681,7 +1681,7 @@
                 self.full_series.insert(0, patchname)
 
                 patchf = self.opener(patchname, "w")
-                patch.export(repo, [n], fp=patchf, opts=diffopts)
+                cmdutil.export(repo, [n], fp=patchf, opts=diffopts)
                 patchf.close()
 
                 se = statusentry(hex(n), patchname)
--- a/hgext/patchbomb.py	Mon Mar 08 11:12:48 2010 -0600
+++ b/hgext/patchbomb.py	Mon Mar 08 19:43:24 2010 +0100
@@ -249,7 +249,7 @@
     def getpatches(revs):
         for r in cmdutil.revrange(repo, revs):
             output = cStringIO.StringIO()
-            patch.export(repo, [r], fp=output,
+            cmdutil.export(repo, [r], fp=output,
                          opts=patch.diffopts(ui, opts))
             yield output.getvalue().split('\n')
 
--- a/mercurial/cmdutil.py	Mon Mar 08 11:12:48 2010 -0600
+++ b/mercurial/cmdutil.py	Mon Mar 08 19:43:24 2010 +0100
@@ -660,6 +660,46 @@
     if runfn:
         return runfn()
 
+def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False,
+           opts=None):
+    '''export changesets as hg patches.'''
+
+    total = len(revs)
+    revwidth = max([len(str(rev)) for rev in revs])
+
+    def single(rev, seqno, fp):
+        ctx = repo[rev]
+        node = ctx.node()
+        parents = [p.node() for p in ctx.parents() if p]
+        branch = ctx.branch()
+        if switch_parent:
+            parents.reverse()
+        prev = (parents and parents[0]) or nullid
+
+        if not fp:
+            fp = make_file(repo, template, node, total=total, seqno=seqno,
+                           revwidth=revwidth, mode='ab')
+        if fp != sys.stdout and hasattr(fp, 'name'):
+            repo.ui.note("%s\n" % fp.name)
+
+        fp.write("# HG changeset patch\n")
+        fp.write("# User %s\n" % ctx.user())
+        fp.write("# Date %d %d\n" % ctx.date())
+        if branch and (branch != 'default'):
+            fp.write("# Branch %s\n" % branch)
+        fp.write("# Node ID %s\n" % hex(node))
+        fp.write("# Parent  %s\n" % hex(prev))
+        if len(parents) > 1:
+            fp.write("# Parent  %s\n" % hex(parents[1]))
+        fp.write(ctx.description().rstrip())
+        fp.write("\n\n")
+
+        for chunk in patch.diff(repo, prev, node, opts=opts):
+            fp.write(chunk)
+
+    for seqno, rev in enumerate(revs):
+        single(rev, seqno + 1, fp)
+
 class changeset_printer(object):
     '''show changeset information when templating not requested.'''
 
--- a/mercurial/commands.py	Mon Mar 08 11:12:48 2010 -0600
+++ b/mercurial/commands.py	Mon Mar 08 19:43:24 2010 +0100
@@ -1204,7 +1204,7 @@
         ui.note(_('exporting patches:\n'))
     else:
         ui.note(_('exporting patch:\n'))
-    patch.export(repo, revs, template=opts.get('output'),
+    cmdutil.export(repo, revs, template=opts.get('output'),
                  switch_parent=opts.get('switch_parent'),
                  opts=patch.diffopts(ui, opts))
 
--- a/mercurial/patch.py	Mon Mar 08 11:12:48 2010 -0600
+++ b/mercurial/patch.py	Mon Mar 08 19:43:24 2010 +0100
@@ -1551,47 +1551,6 @@
             if text:
                 yield text
 
-def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False,
-           opts=None):
-    '''export changesets as hg patches.'''
-
-    total = len(revs)
-    revwidth = max([len(str(rev)) for rev in revs])
-
-    def single(rev, seqno, fp):
-        ctx = repo[rev]
-        node = ctx.node()
-        parents = [p.node() for p in ctx.parents() if p]
-        branch = ctx.branch()
-        if switch_parent:
-            parents.reverse()
-        prev = (parents and parents[0]) or nullid
-
-        if not fp:
-            fp = cmdutil.make_file(repo, template, node, total=total,
-                                   seqno=seqno, revwidth=revwidth,
-                                   mode='ab')
-        if fp != sys.stdout and hasattr(fp, 'name'):
-            repo.ui.note("%s\n" % fp.name)
-
-        fp.write("# HG changeset patch\n")
-        fp.write("# User %s\n" % ctx.user())
-        fp.write("# Date %d %d\n" % ctx.date())
-        if branch and (branch != 'default'):
-            fp.write("# Branch %s\n" % branch)
-        fp.write("# Node ID %s\n" % hex(node))
-        fp.write("# Parent  %s\n" % hex(prev))
-        if len(parents) > 1:
-            fp.write("# Parent  %s\n" % hex(parents[1]))
-        fp.write(ctx.description().rstrip())
-        fp.write("\n\n")
-
-        for chunk in diff(repo, prev, node, opts=opts):
-            fp.write(chunk)
-
-    for seqno, rev in enumerate(revs):
-        single(rev, seqno + 1, fp)
-
 def diffstatdata(lines):
     filename, adds, removes = None, 0, 0
     for line in lines: