D6650: phabricator: handle local:commits time being string or int

Kwan (Ian Moody) phabricator at mercurial-scm.org
Tue Jul 16 18:23:27 UTC 2019


Kwan created this revision.
Kwan added a comment.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.


  I'm not sure if the test is actually needed, so feel free to drop it/ask me to.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  hgext/phabricator.py
  tests/test-phabricator.t

CHANGE DETAILS

diff --git a/tests/test-phabricator.t b/tests/test-phabricator.t
--- a/tests/test-phabricator.t
+++ b/tests/test-phabricator.t
@@ -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
+  @@ -N,n +N* @@ (glob)
+  +test
+  
 
   $ cd ..
diff --git a/hgext/phabricator.py b/hgext/phabricator.py
--- a/hgext/phabricator.py
+++ b/hgext/phabricator.py
@@ -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'))



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


More information about the Mercurial-devel mailing list