[PATCH 2 of 2] paths: Added 'force-alias' option in ui.expandpaths()
Augie Fackler
durin42 at gmail.com
Tue Nov 15 14:29:06 UTC 2011
On Nov 13, 2011, at 2:31 PM, Victor Suba wrote:
> # HG changeset patch
> # User Victor Suba <vosuba at gmail.com>
> # Date 1321214772 28800
> # Node ID fcf006b1cfce252573d0e461595cd61fa366e56b
> # Parent 64efea9f1a8cc6caf370b3967d2b22ac36e9e5de
> paths: Added 'force-alias' option in ui.expandpaths()
> to force creation of a path alias if one doesn't already
> exist. Applied it as default to "hg pull", "hg incoming"
> and "hg identify".
I'd love to see this as an extension first (presumably storing to someplace other than .hg/hgrc) so we could get a feel for the feature without having to make a permanent behavior change in core. It's similar to a feature I've tinkered with in the past, but could never get right.
> diff -r 64efea9f1a8c -r fcf006b1cfce mercurial/commands.py
> --- a/mercurial/commands.py Sun Nov 13 01:44:28 2011 -0800
> +++ b/mercurial/commands.py Sun Nov 13 12:06:12 2011 -0800
> @@ -3283,7 +3283,9 @@
> revs = []
>
> if source:
> - source, branches = hg.parseurl(ui.expandpath(source))
> + pathinfo = {'force-alias': True}
> + source = ui.expandpath(source, pathinfo=pathinfo)
> + source, branches = hg.parseurl(source)
> repo = hg.peer(ui, {}, source)
> revs, checkout = hg.addbranchrevs(repo, repo, branches, None)
>
> @@ -3649,7 +3651,9 @@
> raise util.Abort(_('cannot combine --bundle and --subrepos'))
>
> if opts.get('bookmarks'):
> - source, branches = hg.parseurl(ui.expandpath(source),
> + pathinfo = {'force-alias': True}
> + source = ui.expandpath(source, pathinfo=pathinfo)
> + source, branches = hg.parseurl(source,
> opts.get('branch'))
> other = hg.peer(repo, opts, source)
> if 'bookmarks' not in other.listkeys('namespaces'):
> @@ -4255,7 +4259,9 @@
>
> Returns 0 on success, 1 if an update had unresolved files.
> """
> - source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch'))
> + pathinfo = {'force-alias': True}
> + source = ui.expandpath(source, pathinfo=pathinfo)
> + source, branches = hg.parseurl(source, opts.get('branch'))
> other = hg.peer(repo, opts, source)
> ui.status(_('pulling from %s\n') % util.hidepassword(source))
> revs, checkout = hg.addbranchrevs(repo, other, branches, opts.get('rev'))
> diff -r 64efea9f1a8c -r fcf006b1cfce mercurial/hg.py
> --- a/mercurial/hg.py Sun Nov 13 01:44:28 2011 -0800
> +++ b/mercurial/hg.py Sun Nov 13 12:06:12 2011 -0800
> @@ -441,7 +441,9 @@
> (remoterepo, incomingchangesetlist, displayer) parameters,
> and is supposed to contain only code that can't be unified.
> """
> - source, branches = parseurl(ui.expandpath(source), opts.get('branch'))
> + pathinfo = {'force-alias': True}
> + source = ui.expandpath(source, pathinfo=pathinfo)
> + source, branches = parseurl(source, opts.get('branch'))
> other = peer(repo, opts, source)
> ui.status(_('comparing with %s\n') % util.hidepassword(source))
> revs, checkout = addbranchrevs(repo, other, branches, opts.get('rev'))
> diff -r 64efea9f1a8c -r fcf006b1cfce mercurial/ui.py
> --- a/mercurial/ui.py Sun Nov 13 01:44:28 2011 -0800
> +++ b/mercurial/ui.py Sun Nov 13 12:06:12 2011 -0800
> @@ -428,17 +428,56 @@
>
> return [(alias, paths[alias]) for alias in sorted(paths.keys())]
>
> - def expandpath(self, loc, default=None):
> + def reversepath(self, path, forceAlias):
> + """Reverse search from path to path alias, and if there isn't anything
> + create a new alias"""
> + seen = set()
> + for alias, url in self.configitems("paths"):
> + if path == url:
> + return alias
> + seen.add(alias)
> + for alias, url in self._paths.items():
> + if path == url:
> + return alias
> + seen.add(alias)
> +
> + if forceAlias:
> + i = 0
> + while True:
> + alias = 'remote%d' % i
> + if alias not in seen:
> + self._paths[alias] = path
> + self.writePaths()
> + self.status(_("created new path alias '%s' -> '%s'\n" % (alias, util.hidepassword(path))))
> + return alias
> + i += 1
> + else:
> + return None
> +
> +
> + def expandpath(self, loc, default=None, pathinfo={}):
> """Return repository location relative to cwd or from [paths]"""
> + #ToDo: Teach expandpath about the url#branch format
> if util.hasscheme(loc) or os.path.isdir(os.path.join(loc, '.hg')):
> - return loc
> + pathinfo['alias'] = self.reversepath(loc, pathinfo.get('force-alias', False))
>
> path = self.config('paths', loc)
> - if not path:
> - path = self._paths.get(loc, None)
> + if not path: path = self._paths.get(loc, None)
> if not path and default is not None:
> path = self.config('paths', default)
> - return path or loc
> + if path:
> + loc = default
> +
> + if path:
> + # Update the path alias in .hg/paths if it's not there
> + if self._paths.get(loc, None) != path:
> + self._paths[loc] = path
> + self.writePaths()
> + pathinfo['alias'] = loc
> + return path
> + else:
> + pathinfo['alias'] = self.reversepath(loc, pathinfo.get('force-alias', False))
> + return loc
>
> def pushbuffer(self):
> self._buffers.append([])
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list