Bug 6478 - IndexError in hg log when given one existing and one non-existing filename
Summary: IndexError in hg log when given one existing and one non-existing filename
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: default branch
Hardware: PC Linux
: normal bug
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-31 07:58 UTC by Kim "Zash" Alvefur
Modified: 2021-03-15 00:00 UTC (History)
2 users (show)

See Also:
Python Version: 3.7


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kim "Zash" Alvefur 2021-01-31 07:58 UTC
Some space characters accidentally escaped my revset and got me a traceback, here reproduced in the current default branch with default config:

hg$ HGPLAIN= HOME=/tmp ./hg log -r tip % .
obsolete feature not enabled but 242956 markers found!
** unknown exception encountered, please report by visiting
** https://mercurial-scm.org/wiki/BugTracker
** Python 3.7.3 (default, Jul 25 2020, 13:03:44) [GCC 8.3.0]
** Mercurial Distributed SCM (version 5.7rc0+79-16c18d5e5dc8)
** Extensions loaded: 
Traceback (most recent call last):
  File "./hg", line 59, in <module>
    dispatch.run()
  File "/home/zash/src/hg/mercurial/dispatch.py", line 143, in run
    status = dispatch(req)
  File "/home/zash/src/hg/mercurial/dispatch.py", line 245, in dispatch
    status = _rundispatch(req)
  File "/home/zash/src/hg/mercurial/dispatch.py", line 289, in _rundispatch
    ret = _runcatch(req) or 0
  File "/home/zash/src/hg/mercurial/dispatch.py", line 465, in _runcatch
    return _callcatch(ui, _runcatchfunc)
  File "/home/zash/src/hg/mercurial/dispatch.py", line 475, in _callcatch
    return scmutil.callcatch(ui, func)
  File "/home/zash/src/hg/mercurial/scmutil.py", line 155, in callcatch
    return func()
  File "/home/zash/src/hg/mercurial/dispatch.py", line 455, in _runcatchfunc
    return _dispatch(req)
  File "/home/zash/src/hg/mercurial/dispatch.py", line 1259, in _dispatch
    lui, repo, cmd, fullargs, ui, options, d, cmdpats, cmdoptions
  File "/home/zash/src/hg/mercurial/dispatch.py", line 913, in runcommand
    ret = _runcommand(ui, options, cmd, d)
  File "/home/zash/src/hg/mercurial/dispatch.py", line 1270, in _runcommand
    return cmdfunc()
  File "/home/zash/src/hg/mercurial/dispatch.py", line 1256, in <lambda>
    d = lambda: util.checksignature(func)(ui, *args, **strcmdopt)
  File "/home/zash/src/hg/mercurial/util.py", line 1867, in check
    return func(*args, **kwargs)
  File "/home/zash/src/hg/mercurial/commands.py", line 4653, in log
    revs, differ = logcmdutil.getrevs(repo, walk_opts)
  File "/home/zash/src/hg/mercurial/logcmdutil.py", line 1028, in getrevs
    revs, filematcher = makewalker(repo, wopts)
  File "/home/zash/src/hg/mercurial/logcmdutil.py", line 982, in makewalker
    match, pats, slowpath = _makematcher(repo, revs, wopts)
  File "/home/zash/src/hg/mercurial/logcmdutil.py", line 836, in _makematcher
    filelog = repo.file(f)
  File "/home/zash/src/hg/mercurial/localrepo.py", line 1138, in file
    if path[0] == b'/':
IndexError: index out of range


It seems to happen when two arguments are given, one existing path and one non-existing.
E.g. `hg log existingfile nonexistantfile`.
Comment 1 Bugzilla 2021-02-17 00:00 UTC
Bug was set to IN_PROGRESS for 14 days, moving back to confirmed
Comment 2 Yuya Nishihara 2021-02-17 04:58 UTC
https://patchwork.mercurial-scm.org/patch/48258/
Comment 3 HG Bot 2021-03-05 12:30 UTC
Fixed by https://mercurial-scm.org/repo/hg/rev/9842c00f0252
Yuya Nishihara <yuya@tcha.org>
log: fix handling of root (or empty) path provided by matcher (issue6478)

Since 27d6956d386b "match: use '' instead of '.' for root directory",
'.' should be translated to ''. We can't blame repo.file() about this because
an empty string is invalid as a file path, but I found at least two callers
(_makematcher() and revset.filelog()) would crash because of this path[0].

So let's make repo.file() accept an empty string. path[0] == b'/' wouldn't
work on Python 3 anyways.

(please test the fix)
Comment 4 Kim "Zash" Alvefur 2021-03-06 09:15 UTC
hg$ hg pull -r 9842c00f0252 && hg up -r 9842c00f0252
hg$ make local

hg$ hg log -l 5 hg .
...
** Mercurial Distributed SCM (version 5.7)
...
IndexError: index out of range

hg$ ./hg log -l 5 hg .
changeset:   46691:9842c00f0252
...

Fix seems to work.
Comment 5 Bugzilla 2021-03-15 00:00 UTC
Bug was set to TESTING for 8 days, resolving