##// END OF EJS Templates
ui.paths: expand paths directly in fixconfig (issue2373)...
Benoit Boissinot -
r12662:7285b282 default
parent child Browse files
Show More
@@ -98,12 +98,21 b' class ui(object):'
98 self.fixconfig(root=root)
98 self.fixconfig(root=root)
99
99
100 def fixconfig(self, root=None):
100 def fixconfig(self, root=None):
101 # expand vars and ~
101 # translate paths relative to root (or home) into absolute paths
102 # translate paths relative to root (or home) into absolute paths
102 root = root or os.getcwd()
103 root = root or os.getcwd()
103 for c in self._tcfg, self._ucfg, self._ocfg:
104 for c in self._tcfg, self._ucfg, self._ocfg:
104 for n, p in c.items('paths'):
105 for n, p in c.items('paths'):
105 if p and "://" not in p and not os.path.isabs(p):
106 if not p:
106 c.set("paths", n, os.path.normpath(os.path.join(root, p)))
107 continue
108 if '%%' in p:
109 self.warn(_("(deprecated '%%' in path %s=%s from %s)\n")
110 % (n, p, self.configsource('paths', n)))
111 p = p.replace('%%', '%')
112 p = util.expandpath(p)
113 if '://' not in p and not os.path.isabs(p):
114 p = os.path.normpath(os.path.join(root, p))
115 c.set("paths", n, p)
107
116
108 # update ui options
117 # update ui options
109 self.debugflag = self.configbool('ui', 'debug')
118 self.debugflag = self.configbool('ui', 'debug')
@@ -300,24 +309,14 b' class ui(object):'
300 user = util.shortuser(user)
309 user = util.shortuser(user)
301 return user
310 return user
302
311
303 def _path(self, loc):
304 p = self.config('paths', loc)
305 if p:
306 if '%%' in p:
307 self.warn(_("(deprecated '%%' in path %s=%s from %s)\n") %
308 (loc, p, self.configsource('paths', loc)))
309 p = p.replace('%%', '%')
310 p = util.expandpath(p)
311 return p
312
313 def expandpath(self, loc, default=None):
312 def expandpath(self, loc, default=None):
314 """Return repository location relative to cwd or from [paths]"""
313 """Return repository location relative to cwd or from [paths]"""
315 if "://" in loc or os.path.isdir(os.path.join(loc, '.hg')):
314 if "://" in loc or os.path.isdir(os.path.join(loc, '.hg')):
316 return loc
315 return loc
317
316
318 path = self._path(loc)
317 path = self.config('paths', loc)
319 if not path and default is not None:
318 if not path and default is not None:
320 path = self._path(default)
319 path = self.config('paths', default)
321 return path or loc
320 return path or loc
322
321
323 def pushbuffer(self):
322 def pushbuffer(self):
@@ -5,6 +5,7 b''
5 $ cd a
5 $ cd a
6 $ echo '[paths]' >> .hg/hgrc
6 $ echo '[paths]' >> .hg/hgrc
7 $ echo 'dupe = ../b' >> .hg/hgrc
7 $ echo 'dupe = ../b' >> .hg/hgrc
8 $ echo 'expand = $SOMETHING/bar' >> .hg/hgrc
8 $ hg in dupe
9 $ hg in dupe
9 comparing with $TESTTMP/b
10 comparing with $TESTTMP/b
10 no changes found
11 no changes found
@@ -14,3 +15,13 b''
14 comparing with $TESTTMP/b
15 comparing with $TESTTMP/b
15 no changes found
16 no changes found
16 [1]
17 [1]
18 $ cd a
19 $ hg paths
20 dupe = $TESTTMP/b
21 expand = $TESTTMP/a/$SOMETHING/bar
22 $ SOMETHING=foo hg paths
23 dupe = $TESTTMP/b
24 expand = $TESTTMP/a/foo/bar
25 $ SOMETHING=/foo hg paths
26 dupe = $TESTTMP/b
27 expand = /foo/bar
General Comments 0
You need to be logged in to leave comments. Login now