changeset 42618:c17e6a3e7356

phabricator: handle local:commits time being string or int When setting local:commits arcanist has different behaviour depending on whether the repo is git or hg. With hg it sets the time as a number, since it calls PHP's strtotime on the value, but with git it sets it as a string. Normally this wouldn't be an issue since phabread wouldn't be interacting with Phabricator Revisions for git repos, but Mozilla has a secondary workflow for git users that uses the git-cinnabar tool to interact with their hg repos. When a git-cinnabar user uses the moz-phab tool to submit patches for mozilla-central it makes use of Mozilla's fork of arcanist, which works with their local git version of m-c, and thus sets the local:commit time as a string, and then translates the commit hashes. Currently when encountering such DREVS phabread dies with "TypeError: %d format: a number is required, not str". phabsend also used to set it as a string but wouldn't have encountered the issue with its own DREVs since it would read hg:meta first. Differential Revision: https://phab.mercurial-scm.org/D6650
author Ian Moody <moz-ian@perix.co.uk>
date Tue, 16 Jul 2019 19:18:16 +0100
parents 7629eb87e7f2
children 20d0e59be79b
files hgext/phabricator.py tests/test-phabricator.t
diffstat 2 files changed, 17 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/phabricator.py	Tue Jul 16 18:38:38 2019 +0100
+++ b/hgext/phabricator.py	Tue Jul 16 19:18:16 2019 +0100
@@ -950,7 +950,7 @@
                 meta[b'user'] = b'%s <%s>' % (commit[b'author'],
                                               commit[b'authorEmail'])
             if b'time' in commit:
-                meta[b'date'] = b'%d 0' % commit[b'time']
+                meta[b'date'] = b'%d 0' % int(commit[b'time'])
             if b'branch' in commit:
                 meta[b'branch'] = commit[b'branch']
             node = commit.get(b'commit', commit.get(b'rev'))
--- a/tests/test-phabricator.t	Tue Jul 16 18:38:38 2019 +0100
+++ b/tests/test-phabricator.t	Tue Jul 16 19:18:16 2019 +0100
@@ -132,47 +132,22 @@
   D1253 - updated - 1acd4b60af38: create comment for phabricator test
 
 Phabreading a DREV with a local:commits time as a string:
-BROKEN: shouldn't error
   $ hg phabread --test-vcr "$VCR/phabread-str-time.json" D1285
-  ** unknown exception encountered, please report by visiting
-  ** https://mercurial-scm.org/wiki/BugTracker
-  ** Python * (glob)
-  ** Mercurial Distributed SCM (version *) (glob)
-  ** Extensions loaded: phabricator
-  Traceback (most recent call last):
-    File "*/install/bin/hg", line *, in <module> (glob)
-      dispatch.run()
-    File "*/install/lib/python/mercurial/dispatch.py", line *, in run (glob)
-      status = dispatch(req)
-    File "*/install/lib/python/mercurial/dispatch.py", line *, in dispatch (glob)
-      ret = _runcatch(req) or 0
-    File "*/install/lib/python/mercurial/dispatch.py", line *, in _runcatch (glob)
-      return _callcatch(ui, _runcatchfunc)
-    File "*/install/lib/python/mercurial/dispatch.py", line *, in _callcatch (glob)
-      return scmutil.callcatch(ui, func)
-    File "*/install/lib/python/mercurial/scmutil.py", line *, in callcatch (glob)
-      return func()
-    File "*/install/lib/python/mercurial/dispatch.py", line *, in _runcatchfunc (glob)
-      return _dispatch(req)
-    File "*/install/lib/python/mercurial/dispatch.py", line *, in _dispatch (glob)
-      cmdpats, cmdoptions)
-    File "*/install/lib/python/mercurial/dispatch.py", line *, in runcommand (glob)
-      ret = _runcommand(ui, options, cmd, d)
-    File "*/install/lib/python/mercurial/dispatch.py", line *, in _runcommand (glob)
-      return cmdfunc()
-    File "*/install/lib/python/mercurial/dispatch.py", line *, in <lambda> (glob)
-      d = lambda: util.checksignature(func)(ui, *args, **strcmdopt)
-    File "*/install/lib/python/mercurial/util.py", line *, in check (glob)
-      return func(*args, **kwargs)
-    File "*/install/lib/python/hgext/phabricator.py", line *, in inner (glob)
-      return fn(*args, **kwargs)
-    File "*/install/lib/python/hgext/phabricator.py", line *, in phabread (glob)
-      readpatch(repo, drevs, ui.write)
-    File "*/install/lib/python/hgext/phabricator.py", line *, in readpatch (glob)
-      meta = getdiffmeta(diffs[b'%d' % diffid])
-    File "*/install/lib/python/hgext/phabricator.py", line *, in getdiffmeta (glob)
-      meta[b'date'] = b'%d 0' % commit[b'time']
-  TypeError: %d format: a number is required, not str
-  [1]
+  # HG changeset patch
+  # User test <test>
+  # Date 1562019844 0
+  # Branch default
+  # Node ID da5c8c6bf23a36b6e3af011bc3734460692c23ce
+  # Parent  1f634396406d03e565ed645370e5fecd062cf215
+  test string time
+  
+  Differential Revision: https://phab.mercurial-scm.org/D1285
+  diff --git a/test b/test
+  new file mode 100644
+  --- /dev/null
+  +++ b/test
+  @@ * @@ (glob)
+  +test
+  
 
   $ cd ..