[PATCH 7 of 9 RFC] normfn: normalize paths for subrepo in global style
FUJIWARA Katsunori
foozy at lares.dti.ne.jp
Fri May 25 10:00:56 CDT 2012
# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1337957587 -32400
# Node ID 3b83b592a5b4289ecb65cf9b26225bce20162ada
# Parent c65c6da434ee4fbcc8176ba98773a30b1213042d
normfn: normalize paths for subrepo in global style
mercurial implementation uses paths in on-memory-objects
(e.g. manifest, context, and so on) for subrepo operatons as the path
prefix: diff and archive, now
they are normalized in "local style", so should be normalized in
"global style" to create portable external representations.
diff -r c65c6da434ee -r 3b83b592a5b4 mercurial/subrepo.py
--- a/mercurial/subrepo.py Fri May 25 23:53:07 2012 +0900
+++ b/mercurial/subrepo.py Fri May 25 23:53:07 2012 +0900
@@ -271,7 +271,8 @@
state = ctx.substate[path]
if state[2] not in types:
raise util.Abort(_('unknown subrepo type %s') % state[2])
- return types[state[2]](ctx, path, state[:2])
+ fnfromlocal = getattr(ctx._repo, 'fnfromlocal', lambda x: x)
+ return types[state[2]](ctx, path, fnfromlocal(path), state[:2])
# subrepo classes need to implement the following abstract class:
@@ -352,6 +353,7 @@
return ''
def archive(self, ui, archiver, prefix):
+ fnfromlocal = getattr(self, 'fnfromlocal', lambda x: x)
files = self.files()
total = len(files)
relpath = subrelpath(self)
@@ -361,7 +363,8 @@
flags = self.fileflags(name)
mode = 'x' in flags and 0755 or 0644
symlink = 'l' in flags
- archiver.addfile(os.path.join(prefix, self._path, name),
+ archiver.addfile(os.path.join(prefix, self._extpath,
+ fnfromlocal(name)),
mode, symlink, self.filedata(name))
ui.progress(_('archiving (%s)') % relpath, i + 1,
unit=_('files'), total=total)
@@ -383,8 +386,9 @@
return []
class hgsubrepo(abstractsubrepo):
- def __init__(self, ctx, path, state):
+ def __init__(self, ctx, path, extpath, state):
self._path = path
+ self._extpath = extpath
self._state = state
r = ctx._repo
root = r.wjoin(path)
@@ -394,6 +398,7 @@
util.makedirs(root)
self._repo = hg.repository(r.ui, root, create=create)
self._initrepo(r, state[0], create)
+ self.fnfromlocal = getattr(self._repo, 'fnfromlocal', lambda x: x)
def _initrepo(self, parentrepo, source, create):
self._repo._subparent = parentrepo
@@ -439,7 +444,7 @@
node2 = node.bin(node2)
cmdutil.diffordiffstat(self._repo.ui, self._repo, diffopts,
node1, node2, match,
- prefix=os.path.join(prefix, self._path),
+ prefix=os.path.join(prefix, self._extpath),
listsubrepos=True, **opts)
except error.RepoLookupError, inst:
self._repo.ui.warn(_('warning: error "%s" in subrepository "%s"\n')
@@ -453,7 +458,7 @@
ctx = self._repo[rev]
for subpath in ctx.substate:
s = subrepo(ctx, subpath)
- s.archive(ui, archiver, os.path.join(prefix, self._path))
+ s.archive(ui, archiver, os.path.join(prefix, self._extpath))
def dirty(self, ignoreupdate=False):
r = self._state[1]
@@ -621,8 +626,9 @@
cmdutil.revert(ui, self._repo, ctx, parents, *pats, **opts)
class svnsubrepo(abstractsubrepo):
- def __init__(self, ctx, path, state):
+ def __init__(self, ctx, path, extpath, state):
self._path = path
+ self._extpath = extpath
self._state = state
self._ctx = ctx
self._ui = ctx._repo.ui
@@ -841,11 +847,12 @@
class gitsubrepo(abstractsubrepo):
- def __init__(self, ctx, path, state):
+ def __init__(self, ctx, path, extpath, state):
# TODO add git version check.
self._state = state
self._ctx = ctx
self._path = path
+ self._extpath = extpath
self._relpath = os.path.join(reporelpath(ctx._repo), path)
self._abspath = ctx._repo.wjoin(path)
self._subparent = ctx._repo
@@ -1203,7 +1210,7 @@
data = info.linkname
else:
data = tar.extractfile(info).read()
- archiver.addfile(os.path.join(prefix, self._path, info.name),
+ archiver.addfile(os.path.join(prefix, self._extpath, info.name),
info.mode, info.issym(), data)
ui.progress(_('archiving (%s)') % relpath, i + 1,
unit=_('files'))
More information about the Mercurial-devel
mailing list