##// END OF EJS Templates
revset: add 'l' flag to formatspec for args...
Matt Mackall -
r15140:353a1ba9 default
parent child Browse files
Show More
@@ -1059,6 +1059,8 b' def formatspec(expr, *args):'
1059 %n = hex(arg), single-quoted
1059 %n = hex(arg), single-quoted
1060 %% = a literal '%'
1060 %% = a literal '%'
1061
1061
1062 Prefixing the type with 'l' specifies a list of that type.
1063
1062 >>> formatspec('%d:: and not %d::', 10, 20)
1064 >>> formatspec('%d:: and not %d::', 10, 20)
1063 '10:: and not 20::'
1065 '10:: and not 20::'
1064 >>> formatspec('keyword(%s)', 'foo\\xe9')
1066 >>> formatspec('keyword(%s)', 'foo\\xe9')
@@ -1067,11 +1069,23 b' def formatspec(expr, *args):'
1067 >>> b.branch = b
1069 >>> b.branch = b
1068 >>> formatspec('branch(%b)', b)
1070 >>> formatspec('branch(%b)', b)
1069 "branch('default')"
1071 "branch('default')"
1072 >>> formatspec('root(%ls)', ['a', 'b', 'c', 'd'])
1073 "root(('a' or 'b' or 'c' or 'd'))"
1070 '''
1074 '''
1071
1075
1072 def quote(s):
1076 def quote(s):
1073 return repr(str(s))
1077 return repr(str(s))
1074
1078
1079 def argtype(c, arg):
1080 if c == 'd':
1081 return str(int(arg))
1082 elif c == 's':
1083 return quote(arg)
1084 elif c == 'n':
1085 return quote(node.hex(arg))
1086 elif c == 'b':
1087 return quote(arg.branch())
1088
1075 ret = ''
1089 ret = ''
1076 pos = 0
1090 pos = 0
1077 arg = 0
1091 arg = 0
@@ -1082,17 +1096,15 b' def formatspec(expr, *args):'
1082 d = expr[pos]
1096 d = expr[pos]
1083 if d == '%':
1097 if d == '%':
1084 ret += d
1098 ret += d
1085 elif d == 'd':
1099 elif d in 'dsnb':
1086 ret += str(int(args[arg]))
1100 ret += argtype(d, args[arg])
1087 arg += 1
1088 elif d == 's':
1089 ret += quote(args[arg])
1090 arg += 1
1101 arg += 1
1091 elif d == 'n':
1102 elif d == 'l':
1092 ret += quote(node.hex(args[arg]))
1103 # a list of some type
1093 arg += 1
1104 pos += 1
1094 elif d == 'b':
1105 d = expr[pos]
1095 ret += quote(args[arg].branch())
1106 lv = ' or '.join(argtype(d, e) for e in args[arg])
1107 ret += '(%s)' % lv
1096 arg += 1
1108 arg += 1
1097 else:
1109 else:
1098 raise util.Abort('unexpected revspec format character %s' % d)
1110 raise util.Abort('unexpected revspec format character %s' % d)
General Comments 0
You need to be logged in to leave comments. Login now