comparison tests/test-revset.t @ 23754:3a4d8a6ce432

revset: introduce new operator "##" to concatenate strings/symbols at runtime Before this patch, there is no way to concatenate strings at runtime. For example, to search for the issue ID "1234" in descriptions against all of "issue 1234", "issue:1234", issue1234" and "bug(1234)" patterns, the revset below should be written fully from scratch for each issue ID. grep(r"\bissue[ :]?1234\b|\bbug\(1234\)") This patch introduces new infix operator "##" to concatenate strings/symbols at runtime. Operator symbol "##" comes from the same one of C pre-processor. This concatenation allows parametrizing a part of strings in revset queries. In the case of example above, the definition of the revset alias using operator "##" below can search issue ID "1234" in complicated patterns by "issue(1234)" simply: issue($1) = grep(r"\bissue[ :]?" ## $1 ## r"\b|\bbug\(" ## $1 ## r"\)") "##" operator does: - concatenate not only strings but also symbols into the string Exact distinction between strings and symbols seems not to be convenience, because it is tiresome for users (and "revset.getstring" treats both similarly) For example of revset alias "issue()", "issue(1234)" is easier than "issue('1234')". - have higher priority than any other prefix, infix and postfix operators (like as "##" of C pre-processor) This patch (re-)assigns the priority 20 to "##", and 21 to "(", because priority 19 is already assigned to "-" as prefix "negate".
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Tue, 06 Jan 2015 23:46:18 +0900
parents 6a81f88758aa
children 537a2669a113
comparison
equal deleted inserted replaced
23753:f2893cd8d1e5 23754:3a4d8a6ce432
1120 7 1120 7
1121 $ log 'remote("a-b-c-")' 1121 $ log 'remote("a-b-c-")'
1122 2 1122 2
1123 $ cd ../repo 1123 $ cd ../repo
1124 $ log 'remote(".a.b.c.", "../remote3")' 1124 $ log 'remote(".a.b.c.", "../remote3")'
1125
1126 tests for concatenation of strings/symbols by "##"
1127
1128 $ try "278 ## '5f5' ## 1ee ## 'ce5'"
1129 (_concat
1130 (_concat
1131 (_concat
1132 ('symbol', '278')
1133 ('string', '5f5'))
1134 ('symbol', '1ee'))
1135 ('string', 'ce5'))
1136 ('string', '2785f51eece5')
1137 0
1138
1139 $ echo 'cat4($1, $2, $3, $4) = $1 ## $2 ## $3 ## $4' >> .hg/hgrc
1140 $ try "cat4(278, '5f5', 1ee, 'ce5')"
1141 (func
1142 ('symbol', 'cat4')
1143 (list
1144 (list
1145 (list
1146 ('symbol', '278')
1147 ('string', '5f5'))
1148 ('symbol', '1ee'))
1149 ('string', 'ce5')))
1150 (_concat
1151 (_concat
1152 (_concat
1153 ('symbol', '278')
1154 ('string', '5f5'))
1155 ('symbol', '1ee'))
1156 ('string', 'ce5'))
1157 ('string', '2785f51eece5')
1158 0
1159
1160 (check concatenation in alias nesting)
1161
1162 $ echo 'cat2($1, $2) = $1 ## $2' >> .hg/hgrc
1163 $ echo 'cat2x2($1, $2, $3, $4) = cat2($1 ## $2, $3 ## $4)' >> .hg/hgrc
1164 $ log "cat2x2(278, '5f5', 1ee, 'ce5')"
1165 0
1166
1167 (check operator priority)
1168
1169 $ echo 'cat2n2($1, $2, $3, $4) = $1 ## $2 or $3 ## $4~2' >> .hg/hgrc
1170 $ log "cat2n2(2785f5, 1eece5, 24286f, 4ae135)"
1171 0
1172 4
1125 1173
1126 $ cd .. 1174 $ cd ..
1127 1175
1128 test author/desc/keyword in problematic encoding 1176 test author/desc/keyword in problematic encoding
1129 # unicode: cp932: 1177 # unicode: cp932: