Bug 3089 - KeyError in _modecache on convert from bzr with directory renames
Summary: KeyError in _modecache on convert from bzr with directory renames
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: unspecified
Hardware: All All
: normal bug
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-07 12:55 UTC by kiilerix
Modified: 2012-05-13 04:52 UTC (History)
3 users (show)

See Also:
Python Version: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description kiilerix 2011-11-07 12:55 UTC
Converting http://bzr.savannah.gnu.org/r/grub/trunk/grub/ failed after more
than 90%:
...
385 Remove few bad hunks
384 merge ia64-emu into ia64
transaction abort!
rollback completed
** unknown exception encountered, please report by visiting
**  http://mercurial.selenic.com/wiki/BugTracker
** Python 2.7.1 (r271:86832, Apr 12 2011, 16:16:18) [GCC 4.6.0 20110331 (Red
Hat 4.6.0-2)]
** Mercurial Distributed SCM (version 2.0+23-f3b5ba25d217)
** Extensions loaded: purge, mq, extdiff, graphlog, patchbomb, convert,
hg-git, rebase, fetch
Traceback (most recent call last):
  File "/home/mk/hg-bin/hg", line 38, in <module>
    mercurial.dispatch.run()
  File "/home/mk/hg-bin/mercurial/dispatch.py", line 27, in run
    sys.exit(dispatch(request(sys.argv[1:])))
  File "/home/mk/hg-bin/mercurial/dispatch.py", line 64, in dispatch
    return _runcatch(req)
  File "/home/mk/hg-bin/mercurial/dispatch.py", line 87, in _runcatch
    return _dispatch(req)
  File "/home/mk/hg-bin/mercurial/dispatch.py", line 684, in _dispatch
    cmdpats, cmdoptions)
  File "/home/mk/hg-bin/mercurial/dispatch.py", line 466, in runcommand
    ret = _runcommand(ui, options, cmd, d)
  File "/home/mk/hg-bin/mercurial/dispatch.py", line 738, in _runcommand
    return checkargs()
  File "/home/mk/hg-bin/mercurial/dispatch.py", line 692, in checkargs
    return cmdfunc()
  File "/home/mk/hg-bin/mercurial/dispatch.py", line 681, in <lambda>
    d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
  File "/home/mk/hg-bin/mercurial/util.py", line 454, in check
    return func(*args, **kwargs)
  File "/home/mk/hg-bin/hgext/convert/__init__.py", line 269, in convert
    return convcmd.convert(ui, src, dest, revmapfile, **opts)
  File "/home/mk/hg-bin/hgext/convert/convcmd.py", line 445, in convert
    c.convert(sortmode)
  File "/home/mk/hg-bin/hgext/convert/convcmd.py", line 361, in convert
    self.copy(c)
  File "/home/mk/hg-bin/hgext/convert/convcmd.py", line 330, in copy
    source, self.map)
  File "/home/mk/hg-bin/hgext/convert/hg.py", line 171, in putcommit
    self.repo.commitctx(ctx)
  File "/home/mk/hg-bin/mercurial/localrepo.py", line 1193, in commitctx
    fctx = ctx[f]
  File "/home/mk/hg-bin/mercurial/context.py", line 1056, in __getitem__
    return self.filectx(key)
  File "/home/mk/hg-bin/mercurial/context.py", line 1098, in filectx
    return self._filectxfn(self._repo, self, path)
  File "/home/mk/hg-bin/hgext/convert/hg.py", line 137, in getfilectx
    data, mode = source.getfile(f, v)
  File "/home/mk/hg-bin/hgext/convert/convcmd.py", line 88, in getfile
    return self.source.getfile(file, rev)
  File "/home/mk/hg-bin/hgext/convert/bzr.py", line 112, in getfile
    mode = self._modecache[(name, rev)]
KeyError: ('grub-core/kern/ia64/efi/elf_ia64_efi.lds',
'phcoder@gmail.com-20110102225550-9g84yoqkcunztl67')
Comment 1 kiilerix 2011-11-08 05:23 UTC
It fails on a merge changeset with a directory rename:

$ bzr log --include-merges -v -p -r 591.1.26
revno: 591.1.26 [merge]
committer: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
branch nick: ia64
timestamp: Sun 2011-01-02 23:55:50 +0100
message:
  merge ia64-emu into ia64
...
renamed:
  grub-core/kern/ia64/ => grub-core/kern/ia64.moved/
  grub-core/kern/ia64/efi/ => grub-core/kern/ia64/efi/
  include/grub/ia64/efi/ => include/grub/ia64/efi/
  include/grub/ia64/kernel.h => include/grub/ia64/kernel.h
...

A simple workaround (that probably will loose permission bits of the moved
files) is

--- a/hgext/convert/bzr.py
+++ b/hgext/convert/bzr.py
@@ -109,7 +109,7 @@
             # the file is not available anymore - was deleted
             raise IOError(_('%s is not available in %s anymore') %
                     (name, rev))
-        mode = self._modecache[(name, rev)]
+        mode = self._modecache.get((name, rev), '')
         if kind == 'symlink':
             target = revtree.get_symlink_target(fileid)
             if target is None:
Comment 2 Patrick Mézard 2011-11-08 09:12 UTC
The real issue is nested divergent renames are not handled correctly:

  grub-core/kern/ia64/ => grub-core/kern/ia64.moved/
  grub-core/kern/ia64/efi/ => grub-core/kern/ia64/efi/

I am trying to fix it right now.
Comment 3 HG Bot 2011-11-10 12:00 UTC
Fixed by http://selenic.com/repo/hg/rev/6ba2fc0a87ab
Patrick Mezard <pmezard@gmail.com>
convert/bzr: correctly handle divergent nested renames (issue3089)

(please test the fix)
Comment 4 Bugzilla 2012-05-12 09:25 UTC

--- Bug imported by bugzilla@serpentine.com 2012-05-12 09:25 EDT  ---

This bug was previously known as _bug_ 3089 at http://mercurial.selenic.com/bts/issue3089