Patchwork D8135: phabricator: refactor `phabread` to write all patches at once

login
register
mail settings
Submitter phabricator
Date March 4, 2020, 1:17 p.m.
Message ID <bd81c3383c3c12a7395e55bc7916a68a@localhost.localdomain>
Download mbox | patch
Permalink /patch/45450/
State Not Applicable
Headers show

Comments

phabricator - March 4, 2020, 1:17 p.m.
Closed by commit rHGee5ea026ba8f: phabricator: refactor `phabread` to write all patches at once (authored by mharbison72).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8135?vs=20425&id=20445

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8135/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8135

AFFECTED FILES
  hgext/phabricator.py

CHANGE DETAILS




To: mharbison72, #hg-reviewers, pulkit
Cc: Kwan, mercurial-devel

Patch

diff --git a/hgext/phabricator.py b/hgext/phabricator.py
--- a/hgext/phabricator.py
+++ b/hgext/phabricator.py
@@ -1615,13 +1615,17 @@ 
 def readpatch(ui, drevs, write):
     """generate plain-text patch readable by 'hg import'
 
-    write is usually ui.write. drevs is what "querydrev" returns, results of
+    write takes a list of (DREV, bytes), where DREV is the differential number
+    (as bytes, without the "D" prefix) and the bytes are the text of a patch
+    to be imported. drevs is what "querydrev" returns, results of
     "differential.query".
     """
     # Prefetch hg:meta property for all diffs
     diffids = sorted(set(max(int(v) for v in drev[b'diffs']) for drev in drevs))
     diffs = callconduit(ui, b'differential.querydiffs', {b'ids': diffids})
 
+    patches = []
+
     # Generate patch for each drev
     for drev in drevs:
         ui.note(_(b'reading D%s\n') % drev[b'id'])
@@ -1640,7 +1644,10 @@ 
                 header += b'# %s %s\n' % (_metanamemap[k], meta[k])
 
         content = b'%s%s\n%s' % (header, desc, body)
-        write(content)
+        patches.append((drev[b'id'], content))
+
+    # Write patches to the supplied callback
+    write(patches)
 
 
 @vcrcommand(
@@ -1672,7 +1679,12 @@ 
     if opts.get(b'stack'):
         spec = b':(%s)' % spec
     drevs = querydrev(repo.ui, spec)
-    readpatch(repo.ui, drevs, ui.write)
+
+    def _write(patches):
+        for drev, content in patches:
+            ui.write(content)
+
+    readpatch(repo.ui, drevs, _write)
 
 
 @vcrcommand(