Bug 5702 - hg import --exact throws traceback
Summary: hg import --exact throws traceback
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: 4.3.3
Hardware: PC Linux
: wish bug
Assignee: Bugzilla
URL:
Keywords: easy
: 5745 (view as bug list)
Depends on:
Blocks:
 
Reported: 2017-10-06 10:45 UTC by Kim "Zash" Alvefur
Modified: 2018-05-09 00:00 UTC (History)
4 users (show)

See Also:
Python Version: ---


Attachments
patch being imported (912 bytes, text/plain)
2017-10-06 10:45 UTC, Kim "Zash" Alvefur
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kim "Zash" Alvefur 2017-10-06 10:45 UTC
Created attachment 1977 [details]
patch being imported

An attempt to import a patch from an email causes this traceback:

modules$ hg import --exact ~/issue820
applying /home/zash/issue820
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
** unknown exception encountered, please report by visiting
** https://mercurial-scm.org/wiki/BugTracker
** Python 2.7.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170118]
** Mercurial Distributed SCM (version 4.3.3)
** Extensions loaded: extdiff, histedit, pager, patchbomb, purge, rebase, relink, schemes, shelve, show, strip, transplant
Traceback (most recent call last):
  File "/usr/bin/hg", line 45, in <module>
    mercurial.dispatch.run()
  File "/usr/lib/python2.7/dist-packages/mercurial/dispatch.py", line 81, in run
    status = (dispatch(req) or 0) & 255
  File "/usr/lib/python2.7/dist-packages/mercurial/dispatch.py", line 162, in dispatch
    ret = _runcatch(req)
  File "/usr/lib/python2.7/dist-packages/mercurial/dispatch.py", line 302, in _runcatch
    return _callcatch(ui, _runcatchfunc)
  File "/usr/lib/python2.7/dist-packages/mercurial/dispatch.py", line 310, in _callcatch
    return scmutil.callcatch(ui, func)
  File "/usr/lib/python2.7/dist-packages/mercurial/scmutil.py", line 150, in callcatch
    return func()
  File "/usr/lib/python2.7/dist-packages/mercurial/dispatch.py", line 292, in _runcatchfunc
    return _dispatch(req)
  File "/usr/lib/python2.7/dist-packages/mercurial/dispatch.py", line 896, in _dispatch
    cmdpats, cmdoptions)
  File "/usr/lib/python2.7/dist-packages/mercurial/dispatch.py", line 658, in runcommand
    ret = _runcommand(ui, options, cmd, d)
  File "/usr/lib/python2.7/dist-packages/mercurial/extensions.py", line 322, in closure
    return func(*(args + a), **kw)
  File "/usr/lib/python2.7/dist-packages/hgext/pager.py", line 69, in pagecmd
    return orig(ui, options, cmd, cmdfunc)
  File "/usr/lib/python2.7/dist-packages/mercurial/dispatch.py", line 904, in _runcommand
    return cmdfunc()
  File "/usr/lib/python2.7/dist-packages/mercurial/dispatch.py", line 893, in <lambda>
    d = lambda: util.checksignature(func)(ui, *args, **strcmdopt)
  File "/usr/lib/python2.7/dist-packages/mercurial/util.py", line 1077, in check
    return func(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/mercurial/commands.py", line 3024, in import_
    msgs, hg.clean)
  File "/usr/lib/python2.7/dist-packages/mercurial/cmdutil.py", line 1297, in tryimportone
    elif opts.get('exact') and hex(n) != nodeid:
TypeError: b2a_hex() argument 1 must be string or buffer, not None

The repo is a clone of https://hg.prosody.im/prosody-modules/ and the patch is attached (received over email).

Attempting to import without --excact appears as follows:

modules$ hg import ~/issue820
applying /home/zash/issue820

But the change is not applied or committed.
Comment 1 Pierre-Yves David 2017-10-06 10:51 UTC
I can reproduce with Mercurial version 4.3.2+605-7b1e524ad73f
Comment 2 Pierre-Yves David 2017-10-06 10:59 UTC
digging deeper, the patch provided is damaged. The longer line got wrapped (the the two dates and the first line of context). This lead the patch to be interpreted as empty for some reason. Fixing the line wrapping led to a successful import of the patch (with or without --exact).

So it seems like the --exact checking panics and crash when the patch import do not results in the creation of a changeset.
Comment 3 Anton Shestakov 2017-10-06 11:18 UTC
Sounds like it's easy to fix, because the usage of hex() there is checking if the patch is damaged.
Comment 4 Yuya Nishihara 2017-11-26 08:29 UTC
*** Bug 5745 has been marked as a duplicate of this bug. ***
Comment 5 Bugzilla 2018-04-26 00:00 UTC
Bug was inactive for 150 days, archiving
Comment 6 HG Bot 2018-04-30 20:40 UTC
Fixed by https://mercurial-scm.org/repo/hg/rev/32a75a8a5b0f
Yuya Nishihara <yuya@tcha.org>
import: fix crash on --exact check of empty commit (issue5702)

(please test the fix)
Comment 7 Kim "Zash" Alvefur 2018-05-01 09:04 UTC
Works, thanks!
Comment 8 Bugzilla 2018-05-09 00:00 UTC
Bug was set to TESTING for 7 days, resolving