# HG changeset patch # User jcoomes # Date 1301960344 25200 # Node ID bd32d04e966f444b412825f3f93ec0bbdb2404c6 # Parent 57963313969204d913cddea875bc5f9fd009c4d7 commands: make it easier to specify subtrees on the command-line Use a boolean config entry, trees.splitargs, to control whether to split --subtree args at whitespace, while respecting any quoting. The splitting uses code added in mercurial 1.6, and so does not work with earlier versions. The workaround is to use multiple --subtree options. diff -r 579633139692 -r bd32d04e966f tests/test-trees-local-x.t --- a/tests/test-trees-local-x.t Mon Jan 03 21:14:19 2011 -0800 +++ b/tests/test-trees-local-x.t Mon Apr 04 16:39:04 2011 -0700 @@ -33,3 +33,20 @@ 0: s1 has a space 1: s2 2: s3 has a space + +Test splitting of --subtrees args and quoting. + +This requires mercurial with quoted config item support (1.6 and later). + + $ hg tpaths -R r1 --subtrees '"s1 has a space" s2' --config trees.splitargs=0 + [$TESTTMP/r1]: + + abort: repository $TESTTMP/r1/"s1 has a space" s2 not found! + [255] + $ hg tpaths -R r1 --subtrees '"s1 has a space" s2' --config trees.splitargs=1 + [$TESTTMP/r1]: + + [$TESTTMP/r1/s1 has a space]: + + [$TESTTMP/r1/s2]: + diff -r 579633139692 -r bd32d04e966f tests/test-trees-local.t --- a/tests/test-trees-local.t Mon Jan 03 21:14:19 2011 -0800 +++ b/tests/test-trees-local.t Mon Apr 04 16:39:04 2011 -0700 @@ -6,15 +6,15 @@ Create test repos. $ for r in rflat rflat/s1 rflat/s2 rflat/s3 rflat/s4 rflat/s5 rflat/s6 \ - > r1 r1/s1 'r1/s1/s1.1 with spaces' r1/s2 r1/s2/s2.1 r1/s2/s2.2 \ - > r1/s2/s2.2/s2.2.1 + > r1 r1/s1 'r1/s1/s1.1 with spaces' r1/s1/s1.2 'r1/s1/s1.3 with spaces' \ + > r1/s2 r1/s2/s2.1 r1/s2/s2.2 r1/s2/s2.2/s2.2.1 > do > hg init "$r" > echo "$r" > "$r/x" && hg -R "$r" ci -qAm "$r" > done $ hg tconfig -R rflat --set --walk $ hg tconfig -R r1 --set s1 s2 - $ hg tconfig -R r1/s1 --set 's1.1 with spaces' + $ hg tconfig -R r1/s1 --set 's1.1 with spaces' s1.2 's1.3 with spaces' $ hg tconfig -R r1/s2 --set --walk $ hg tclone -q r1 r2 @@ -37,6 +37,16 @@ updating (to branch default|working directory) (re) 1 files updated, 0 files merged, 0 files removed, 0 files unresolved created $TESTTMP/r4/s1/s1.1 with spaces + + cloning $TESTTMP/r1/s1/s1.2 + updating (to branch default|working directory) (re) + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + created $TESTTMP/r4/s1/s1.2 + + cloning $TESTTMP/r1/s1/s1.3 with spaces + updating (to branch default|working directory) (re) + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + created $TESTTMP/r4/s1/s1.3 with spaces $ hg tclone --skiproot r3 r4 s2 skipping root r3 @@ -73,6 +83,16 @@ updating (to branch default|working directory) (re) 1 files updated, 0 files merged, 0 files removed, 0 files unresolved created $TESTTMP/rx/s1.1 with spaces + + cloning $TESTTMP/r1/s1/s1.2 + updating (to branch default|working directory) (re) + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + created $TESTTMP/rx/s1.2 + + cloning $TESTTMP/r1/s1/s1.3 with spaces + updating (to branch default|working directory) (re) + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + created $TESTTMP/rx/s1.3 with spaces $ hg tclone --skiproot rflat rx skipping root rflat @@ -141,6 +161,8 @@ $ hg tconfig -R rx s1.1 with spaces + s1.2 + s1.3 with spaces s1 s2 s3 @@ -160,6 +182,8 @@ $TESTTMP/r1 $TESTTMP/r1/s1 $TESTTMP/r1/s1/s1.1 with spaces + $TESTTMP/r1/s1/s1.2 + $TESTTMP/r1/s1/s1.3 with spaces $TESTTMP/r1/s2 $TESTTMP/r1/s2/s2.1 $TESTTMP/r1/s2/s2.2 @@ -170,6 +194,10 @@ [$TESTTMP/r1/s1/s1.1 with spaces]: + [$TESTTMP/r1/s1/s1.2]: + + [$TESTTMP/r1/s1/s1.3 with spaces]: + [$TESTTMP/r1/s2]: [$TESTTMP/r1/s2/s2.1]: @@ -181,6 +209,8 @@ $TESTTMP/r2 $TESTTMP/r2/s1 $TESTTMP/r2/s1/s1.1 with spaces + $TESTTMP/r2/s1/s1.2 + $TESTTMP/r2/s1/s1.3 with spaces $TESTTMP/r2/s2 $TESTTMP/r2/s2/s2.1 $TESTTMP/r2/s2/s2.2 @@ -194,6 +224,12 @@ [$TESTTMP/r2/s1/s1.1 with spaces]: default = $TESTTMP/r1/s1/s1.1 with spaces + [$TESTTMP/r2/s1/s1.2]: + default = $TESTTMP/r1/s1/s1.2 + + [$TESTTMP/r2/s1/s1.3 with spaces]: + default = $TESTTMP/r1/s1/s1.3 with spaces + [$TESTTMP/r2/s2]: default = $TESTTMP/r1/s2 @@ -209,6 +245,8 @@ $TESTTMP/r3 $TESTTMP/r3/s1 $TESTTMP/r3/s1/s1.1 with spaces + $TESTTMP/r3/s1/s1.2 + $TESTTMP/r3/s1/s1.3 with spaces $TESTTMP/r3/s2 $TESTTMP/r3/s2/s2.1 $TESTTMP/r3/s2/s2.2 @@ -222,6 +260,12 @@ [$TESTTMP/r3/s1/s1.1 with spaces]: default = $TESTTMP/r1/s1/s1.1 with spaces + [$TESTTMP/r3/s1/s1.2]: + default = $TESTTMP/r1/s1/s1.2 + + [$TESTTMP/r3/s1/s1.3 with spaces]: + default = $TESTTMP/r1/s1/s1.3 with spaces + [$TESTTMP/r3/s2]: default = $TESTTMP/r2/s2 @@ -237,6 +281,8 @@ $TESTTMP/r4 $TESTTMP/r4/s1 $TESTTMP/r4/s1/s1.1 with spaces + $TESTTMP/r4/s1/s1.2 + $TESTTMP/r4/s1/s1.3 with spaces $TESTTMP/r4/s2 $TESTTMP/r4/s2/s2.1 $TESTTMP/r4/s2/s2.2 @@ -250,6 +296,12 @@ [$TESTTMP/r4/s1/s1.1 with spaces]: default = $TESTTMP/r1/s1/s1.1 with spaces + [$TESTTMP/r4/s1/s1.2]: + default = $TESTTMP/r1/s1/s1.2 + + [$TESTTMP/r4/s1/s1.3 with spaces]: + default = $TESTTMP/r1/s1/s1.3 with spaces + [$TESTTMP/r4/s2]: default = $TESTTMP/r3/s2 @@ -312,6 +364,8 @@ $TESTTMP/r4 $TESTTMP/r4/s1 $TESTTMP/r4/s1/s1.1 with spaces + $TESTTMP/r4/s1/s1.2 + $TESTTMP/r4/s1/s1.3 with spaces $TESTTMP/r4/s2 $TESTTMP/r4/s2/s2.1 $TESTTMP/r4/s2/s2.2 @@ -320,6 +374,8 @@ $TESTTMP/r4 $TESTTMP/r4/s1 $TESTTMP/r4/s1/s1.1 with spaces + $TESTTMP/r4/s1/s1.2 + $TESTTMP/r4/s1/s1.3 with spaces $TESTTMP/r4/s2 $TESTTMP/r4/s2/s2.1 $TESTTMP/r4/s2/s2.2 @@ -357,6 +413,16 @@ searching for changes no changes found + [$TESTTMP/r1/s1/s1.2]: + comparing with r2/s1/s1.2 + searching for changes + no changes found + + [$TESTTMP/r1/s1/s1.3 with spaces]: + comparing with r2/s1/s1.3 with spaces + searching for changes + no changes found + [$TESTTMP/r1/s2]: comparing with r2/s2 searching for changes @@ -407,6 +473,16 @@ searching for changes no changes found + [$TESTTMP/r2/s1/s1.2]: + comparing with $TESTTMP/r1/s1/s1.2 + searching for changes + no changes found + + [$TESTTMP/r2/s1/s1.3 with spaces]: + comparing with $TESTTMP/r1/s1/s1.3 with spaces + searching for changes + no changes found + [$TESTTMP/r2/s2]: comparing with $TESTTMP/r1/s2 searching for changes @@ -457,6 +533,16 @@ searching for changes no changes found + [$TESTTMP/r1/s1/s1.2]: + comparing with r2/s1/s1.2 + searching for changes + no changes found + + [$TESTTMP/r1/s1/s1.3 with spaces]: + comparing with r2/s1/s1.3 with spaces + searching for changes + no changes found + [$TESTTMP/r1/s2]: comparing with r2/s2 searching for changes @@ -507,6 +593,16 @@ searching for changes no changes found + [$TESTTMP/r2/s1/s1.2]: + comparing with $TESTTMP/r1/s1/s1.2 + searching for changes + no changes found + + [$TESTTMP/r2/s1/s1.3 with spaces]: + comparing with $TESTTMP/r1/s1/s1.3 with spaces + searching for changes + no changes found + [$TESTTMP/r2/s2]: comparing with $TESTTMP/r1/s2 searching for changes @@ -560,6 +656,16 @@ searching for changes no changes found + [$TESTTMP/r2/s1/s1.2]: + pulling from $TESTTMP/r1/s1/s1.2 + searching for changes + no changes found + + [$TESTTMP/r2/s1/s1.3 with spaces]: + pulling from $TESTTMP/r1/s1/s1.3 with spaces + searching for changes + no changes found + [$TESTTMP/r2/s2]: pulling from $TESTTMP/r1/s2 searching for changes @@ -621,6 +727,16 @@ searching for changes no changes found + [$TESTTMP/r2/s1/s1.2]: + pushing to $TESTTMP/r1/s1/s1.2 + searching for changes + no changes found + + [$TESTTMP/r2/s1/s1.3 with spaces]: + pushing to $TESTTMP/r1/s1/s1.3 with spaces + searching for changes + no changes found + [$TESTTMP/r2/s2]: pushing to $TESTTMP/r1/s2 searching for changes @@ -675,6 +791,22 @@ summary: r1/s1/s1.1 with spaces + [$TESTTMP/r1/s1/s1.2]: + changeset: 0:7457850caaf5 + tag: tip + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: r1/s1/s1.2 + + + [$TESTTMP/r1/s1/s1.3 with spaces]: + changeset: 0:7c1472d16a1f + tag: tip + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: r1/s1/s1.3 with spaces + + [$TESTTMP/r1/s2]: changeset: 3:3d0a1cb52bf2 tag: tip @@ -730,6 +862,16 @@ searching for changes no changes found + [$TESTTMP/r2/s1/s1.2]: + comparing with $TESTTMP/r1/s1/s1.2 + searching for changes + no changes found + + [$TESTTMP/r2/s1/s1.3 with spaces]: + comparing with $TESTTMP/r1/s1/s1.3 with spaces + searching for changes + no changes found + [$TESTTMP/r2/s2]: comparing with $TESTTMP/r1/s2 searching for changes diff -r 579633139692 -r bd32d04e966f trees.py --- a/trees.py Mon Jan 03 21:14:19 2011 -0800 +++ b/trees.py Mon Apr 04 16:39:04 2011 -0700 @@ -60,11 +60,28 @@ l += [subtree] return l +_splitui = None + +def _splitsubtrees(l): + global _splitui + res = [] + for s in l: + if "'" in s or '"' in s: + # Use ui.configlist() for quoted strings; requires hg 1.6 or later. + if not _splitui: + _splitui = ui.ui() + _splitui.setconfig('x', 'x', s) + res += _splitui.configlist('x', 'x') + else: + res += s.split() + return res + def _subtreelist(ui, repo, opts): l = opts.get('subtrees') if l: del opts['subtrees'] - return _expandsubtrees(ui, l) + cansplit = ui.configbool('trees', 'splitargs', True) + return _expandsubtrees(ui, cansplit and _splitsubtrees(l) or l) l = [] try: for line in repo.opener('trees'):