view tests/test-locate.t @ 19933:621a26eb3a99

demandimport: allow extensions to import own modules by absolute name Before this patch, python modules of each extensions can't import another one in own extension by absolute name, because root modules of each extensions are loaded with "hgext_" prefix. For example, "import extroot.bar" in "extroot/foo.py" of "extroot" extension fails, even though "import bar" in it succeeds. Installing extensions into site-packages of python library path can avoid this problem, but this solution is not reasonable in some cases: using binary package of Mercurial on Windows, for example. This patch retries to import with "hgext_" prefix after ImportError, if the module in the extension may try to import another one in own extension. This patch doesn't change some "_import()"/"_origimport()" invocations below, because ordinary extensions shouldn't cause such invocations. - invocation of "_import()" when root module imports sub-module by absolute path without "fromlist" for example, "import a.b" in "a.__init__.py". extensions are loaded with "hgext_" prefix, and this causes execution of another (= fixed by this patch) code path. - invocation of "_origimport()" when "level != -1" with "fromlist" for example, importing after "from __future__ import absolute_import" (level == 0), or "from . import b" or "from .a import b" (0 < level), for portability between python versions and environments, extensions shouldn't cause "level != -1".
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Sat, 05 Oct 2013 01:02:22 +0900
parents 6ef3107c661e
children edf07a804ac4
line wrap: on
line source

  $ hg init repo
  $ cd repo
  $ echo 0 > a
  $ echo 0 > b
  $ echo 0 > t.h
  $ mkdir t
  $ echo 0 > t/x
  $ echo 0 > t/b
  $ echo 0 > t/e.h
  $ mkdir dir.h
  $ echo 0 > dir.h/foo

  $ hg ci -A -m m
  adding a
  adding b
  adding dir.h/foo
  adding t.h
  adding t/b
  adding t/e.h
  adding t/x

  $ touch nottracked

  $ hg locate a
  a

  $ hg locate NONEXISTENT
  [1]

  $ hg locate
  a
  b
  dir.h/foo
  t.h
  t/b
  t/e.h
  t/x

  $ hg rm a
  $ hg ci -m m

  $ hg locate a
  [1]
  $ hg locate NONEXISTENT
  [1]
  $ hg locate relpath:NONEXISTENT
  [1]
  $ hg locate
  b
  dir.h/foo
  t.h
  t/b
  t/e.h
  t/x
  $ hg locate -r 0 a
  a
  $ hg locate -r 0 NONEXISTENT
  [1]
  $ hg locate -r 0 relpath:NONEXISTENT
  [1]
  $ hg locate -r 0
  a
  b
  dir.h/foo
  t.h
  t/b
  t/e.h
  t/x

-I/-X with relative path should work:

  $ cd t
  $ hg locate
  b
  dir.h/foo
  t.h
  t/b
  t/e.h
  t/x
  $ hg locate -I ../t
  t/b
  t/e.h
  t/x

Issue294: hg remove --after dir fails when dir.* also exists

  $ cd ..
  $ rm -r t

  $ hg locate 't/**'
  t/b (glob)
  t/e.h (glob)
  t/x (glob)

  $ mkdir otherdir
  $ cd otherdir

  $ hg locate b
  ../b (glob)
  ../t/b (glob)
  $ hg locate '*.h'
  ../t.h (glob)
  ../t/e.h (glob)
  $ hg locate path:t/x
  ../t/x (glob)
  $ hg locate 're:.*\.h$'
  ../t.h (glob)
  ../t/e.h (glob)
  $ hg locate -r 0 b
  ../b (glob)
  ../t/b (glob)
  $ hg locate -r 0 '*.h'
  ../t.h (glob)
  ../t/e.h (glob)
  $ hg locate -r 0 path:t/x
  ../t/x (glob)
  $ hg locate -r 0 're:.*\.h$'
  ../t.h (glob)
  ../t/e.h (glob)

  $ cd ../..