Mercurial > hg > openjdk > trees
changeset 18:6df509277779
tconfig: refactor into separate methods
author | jcoomes |
---|---|
date | Tue, 25 Feb 2014 16:25:00 -0800 |
parents | 4287704dd0bf |
children | c90ebb4991b6 |
files | trees.py |
diffstat | 1 files changed, 38 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/trees.py Tue Feb 25 06:42:56 2014 -0800 +++ b/trees.py Tue Feb 25 16:25:00 2014 -0800 @@ -457,6 +457,36 @@ return _docmd1(condcommit, ui, repo, *pats, **opts) +def addconfig(ui, repo, subtrees, opts): + l = _subtreelist(ui, repo, opts) + for subtree in subtrees: + if subtree in l: + raise util.Abort(_('subtree %s already configured' % subtree)) + l += [subtree] + return _writeconfig(repo, _ns(ui, opts), l) + +def delconfig(ui, repo, subtrees, opts): + all = opts.get('all') + if all and subtrees: + raise util.Abort(_('use either --all or subtrees (but not both)')) + if all: + return _writeconfig(repo, _ns(ui, opts), []) + l = _subtreelist(ui, repo, opts) + for subtree in subtrees: + if not subtree in l: + raise util.Abort(_('no subtree %s' % subtree)) + l.remove(subtree) + return _writeconfig(repo, _ns(ui, opts), l) + +def setconfig(ui, repo, subtrees, opts): + walk = opts.get('walk') + if walk + bool(subtrees) != 1: + raise util.Abort(_('use either --walk or subtrees (but not both)')) + if walk: + l = _shortpaths(repo.root, _walk(ui, repo, {}))[1:] + return _writeconfig(repo, _ns(ui, opts), l) + return _writeconfig(repo, _ns(ui, opts), subtrees) + def config(ui, repo, *subtrees, **opts): """list or change the subtrees configuration @@ -476,38 +506,16 @@ if cnt > 1: raise util.Abort(_('at most one of --add, --del, --list or --set is ' + 'allowed')) - if cnt == 0 or oplst: - l = _subtreelist(ui, repo, opts) - for subtree in l: - ui.write(subtree + '\n') - return 0 - if opadd and subtrees: - l = _subtreelist(ui, repo, opts) - for subtree in subtrees: - if subtree in l: - raise util.Abort(_('subtree %s already configured' % subtree)) - l += [subtree] - return _writeconfig(repo, _ns(ui, opts), l) + if opadd: + return addconfig(ui, repo, subtrees, opts) if opdel: - all = opts.get('all') - if all + bool(subtrees) != 1: - raise util.Abort(_('use either --all or subtrees (but not both)')) - if all: - return _writeconfig(repo, _ns(ui, opts), []) - l = _subtreelist(ui, repo, opts) - for subtree in subtrees: - if not subtree in l: - raise util.Abort(_('no subtree %s' % subtree)) - l.remove(subtree) - return _writeconfig(repo, _ns(ui, opts), l) + return delconfig(ui, repo, subtrees, opts) if opset: - walk = opts.get('walk') - if walk + bool(subtrees) != 1: - raise util.Abort(_('use either --walk or subtrees (but not both)')) - l = subtrees - if walk: - l = _shortpaths(repo.root, _walk(ui, repo, {}))[1:] - return _writeconfig(repo, _ns(ui, opts), l) + return setconfig(ui, repo, subtrees, opts) + + for subtree in _subtreelist(ui, repo, opts): + ui.write(subtree + '\n') + return 0 def diff(ui, repo, *args, **opts): """diff repository (or selected files)"""