changeset 44647:99fa161a883c

phabricator: extract the logic to amend diff properties to a function This will be needed on a separate code path when dealing with folding revisions. And since we know that will involve adding multiple local commmits to the diff properties instead of just one, restructure the logic slightly to allow it. Differential Revision: https://phab.mercurial-scm.org/D8312
author Matt Harbison <matt_harbison@yahoo.com>
date Mon, 16 Mar 2020 14:33:35 -0400
parents 5f9c917e3b50
children 949a87145336
files hgext/phabricator.py
diffstat 1 files changed, 18 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/phabricator.py	Mon Mar 16 13:36:12 2020 -0400
+++ b/hgext/phabricator.py	Mon Mar 16 14:33:35 2020 -0400
@@ -1168,6 +1168,20 @@
     return [entry[b'phid'] for entry in data]
 
 
+def _amend_diff_properties(unfi, drevid, newnodes, diff):
+    """update the local commit list for the ``diff`` associated with ``drevid``
+
+    This is a utility function for the amend phase of ``phabsend``, which
+    converts failures to warning messages.
+    """
+    try:
+        writediffproperties([unfi[newnode] for newnode in newnodes], diff)
+    except util.urlerr.urlerror:
+        # If it fails just warn and keep going, otherwise the DREV
+        # associations will be lost
+        unfi.ui.warnnoi18n(b'Failed to update metadata for D%d\n' % drevid)
+
+
 @vcrcommand(
     b'phabsend',
     [
@@ -1357,17 +1371,10 @@
                     newnode = new.commit()
 
                     mapping[old.node()] = [newnode]
-                    # Update diff property
-                    # If it fails just warn and keep going, otherwise the DREV
-                    # associations will be lost
-                    try:
-                        writediffproperties(
-                            [unfi[newnode]], diffmap[old.node()]
-                        )
-                    except util.urlerr.urlerror:
-                        ui.warnnoi18n(
-                            b'Failed to update metadata for D%d\n' % drevid
-                        )
+
+                    _amend_diff_properties(
+                        unfi, drevid, [newnode], diffmap[old.node()]
+                    )
                 # Remove local tags since it's no longer necessary
                 tagname = b'D%d' % drevid
                 if tagname in repo.tags():