# HG changeset patch # User jcoomes # Date 1393374300 28800 # Node ID 6df5092777791a14b1ff152e42d30bcaeeece4f8 # Parent 4287704dd0bf1c7bdab09abe68b897df5b541a6d tconfig: refactor into separate methods diff -r 4287704dd0bf -r 6df509277779 trees.py --- 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)"""