comparison hgext3rd/evolve/templatekw.py @ 2615:01e32f11f1ef mercurial-4.1

compat-test: merge with stable
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 16 Jun 2017 19:27:36 +0200
parents 54ac473663ff 3d432af2f6cd
children feabbaa01ff0 52d5c5ce27e4
comparison
equal deleted inserted replaced
2614:9a1c92132519 2615:01e32f11f1ef
7 # GNU General Public License version 2 or any later version. 7 # GNU General Public License version 2 or any later version.
8 """evolve templates 8 """evolve templates
9 """ 9 """
10 10
11 from . import ( 11 from . import (
12 error,
12 exthelper, 13 exthelper,
13 obshistory 14 obshistory
14 ) 15 )
15 16
16 from mercurial import ( 17 from mercurial import (
63 else: 64 else:
64 stack.append(precnodeid) 65 stack.append(precnodeid)
65 66
66 @eh.templatekw("precursors") 67 @eh.templatekw("precursors")
67 def shownextvisibleprecursors(repo, ctx, **args): 68 def shownextvisibleprecursors(repo, ctx, **args):
68 """Returns a string containing the list if the closest successors 69 """Returns a string containing the list of the closest precursors
69 displayed
70 """ 70 """
71 precursors = sorted(closestprecursors(repo, ctx.node())) 71 precursors = sorted(closestprecursors(repo, ctx.node()))
72 precursors = [node.hex(p) for p in precursors]
72 73
73 # <= hg-4.1 requires an explicite gen. 74 # <= hg-4.1 requires an explicite gen.
74 # we can use None once the support is dropped 75 # we can use None once the support is dropped
75 # 76 #
76 # They also requires an iterator instead of an iterable. 77 # They also requires an iterator instead of an iterable.
77 gen = iter(" ".join(map(node.short, precursors))) 78 gen = iter(" ".join(p[:12] for p in precursors))
78 return templatekw._hybrid(gen.__iter__(), precursors, lambda x: {'precursor': x}, 79 return templatekw._hybrid(gen.__iter__(), precursors, lambda x: {'precursor': x},
79 lambda d: "%s" % node.short(d['precursor'])) 80 lambda d: d['precursor'][:12])
80 81
81 def closestsuccessors(repo, nodeid): 82 def closestsuccessors(repo, nodeid):
82 """ returns the closest visible successors sets instead. 83 """ returns the closest visible successors sets instead.
83 """ 84 """
84 return directsuccessorssets(repo, nodeid) 85 return directsuccessorssets(repo, nodeid)
85 86
86 @eh.templatekw("successors") 87 @eh.templatekw("successors")
87 def shownextvisiblesuccessors(repo, ctx, templ, **args): 88 def shownextvisiblesuccessors(repo, ctx, templ, **args):
88 """Returns a string of sets of successors for a changectx in this format: 89 """Returns a string of sets of successors for a changectx
89 [ctx1, ctx2], [ctx3] if ctx has been splitted into ctx1 and ctx2 while 90
90 also diverged into ctx3""" 91 Format used is: [ctx1, ctx2], [ctx3] if ctx has been splitted into ctx1 and
92 ctx2 while also diverged into ctx3"""
91 if not ctx.obsolete(): 93 if not ctx.obsolete():
92 return '' 94 return ''
93 95
94 ssets, _ = closestsuccessors(repo, ctx.node()) 96 ssets, _ = closestsuccessors(repo, ctx.node())
97 ssets = [[node.hex(n) for n in ss] for ss in ssets]
95 98
96 data = [] 99 data = []
97 gen = [] 100 gen = []
98 for ss in ssets: 101 for ss in ssets:
99 subgen = '[%s]' % ', '.join(map(node.short, ss)) 102 subgen = '[%s]' % ', '.join(n[:12] for n in ss)
100 gen.append(subgen) 103 gen.append(subgen)
101 h = templatekw._hybrid(iter(subgen), ss, lambda x: {'successor': x}, 104 h = templatekw._hybrid(iter(subgen), ss, lambda x: {'successor': x},
102 lambda d: "%s" % d["successor"]) 105 lambda d: "%s" % d["successor"])
103 data.append(h) 106 data.append(h)
104 107
105 gen = ', '.join(gen) 108 gen = ', '.join(gen)
106 return templatekw._hybrid(iter(gen), data, lambda x: {'successorset': x}, 109 return templatekw._hybrid(iter(gen), data, lambda x: {'successorset': x},
107 lambda d: d["successorset"]) 110 lambda d: d["successorset"])
108 111
109 def obsfatedefaulttempl(): 112 def _getusername(ui):
113 """the default username in the config or None"""
114 try:
115 return ui.username()
116 except error.Abort: # no easy way to avoid ui raising Abort here :-/
117 return None
118
119 def obsfatedefaulttempl(ui):
110 """ Returns a dict with the default templates for obs fate 120 """ Returns a dict with the default templates for obs fate
111 """ 121 """
112 # Prepare templates 122 # Prepare templates
113 verbtempl = '{verb}' 123 verbtempl = '{verb}'
114 usertempl = '{if(users, " by {join(users, ", ")}")}' 124 usertempl = '{if(users, " by {join(users, ", ")}")}'
116 datetempleq = ' (at {min_date|isodate})' 126 datetempleq = ' (at {min_date|isodate})'
117 datetemplnoteq = ' (between {min_date|isodate} and {max_date|isodate})' 127 datetemplnoteq = ' (between {min_date|isodate} and {max_date|isodate})'
118 datetempl = '{if(max_date, "{ifeq(min_date, max_date, "%s", "%s")}")}' % (datetempleq, datetemplnoteq) 128 datetempl = '{if(max_date, "{ifeq(min_date, max_date, "%s", "%s")}")}' % (datetempleq, datetemplnoteq)
119 newline = '\n' 129 newline = '\n'
120 130
131 optionalusertempl = usertempl
132 username = _getusername(ui)
133 if username is not None:
134 optionalusertempl = ('{ifeq(join(users, "\0"), "%s", "", "%s")}'
135 % (username, usertempl))
136
121 # Assemble them 137 # Assemble them
122 return { 138 return {
123 'obsfate_quiet': verbtempl + succtempl + newline, 139 'obsfate_quiet': verbtempl + succtempl + newline,
124 'obsfate': verbtempl + usertempl + succtempl + newline, 140 'obsfate': verbtempl + optionalusertempl + succtempl + newline,
125 'obsfate_verbose': verbtempl + usertempl + succtempl + datetempl + newline 141 'obsfate_verbose': verbtempl + usertempl + succtempl + datetempl + newline
126 } 142 }
127 143
128 @eh.templatekw("obsfate") 144 @eh.templatekw("obsfate")
129 def showobsfate(repo, ctx, **args): 145 def showobsfate(repo, ctx, **args):
135 # closestsuccessors returns an empty list for pruned revisions, remap it 151 # closestsuccessors returns an empty list for pruned revisions, remap it
136 # into a list containing en empty list for future processing 152 # into a list containing en empty list for future processing
137 if successorssets == []: 153 if successorssets == []:
138 successorssets = [[]] 154 successorssets = [[]]
139 155
156 succsmap = repo.obsstore.successors
157 fullsuccessorsets = [] # successor set + markers
158 for sset in successorssets:
159 if sset:
160 markers = obshistory.successorsetallmarkers(sset, pathcache)
161 fullsuccessorsets.append((sset, markers))
162 else:
163 # XXX we do not catch all prune markers (eg rewritten then pruned)
164 # (fix me later)
165 foundany = False
166 for mark in succsmap.get(ctx.node(), ()):
167 if not mark[1]:
168 foundany = True
169 fullsuccessorsets.append((sset, [mark]))
170 if not foundany:
171 fullsuccessorsets.append(([], []))
172
140 values = [] 173 values = []
141 for successorset in successorssets: 174 for sset, rawmarkers in fullsuccessorsets:
142 raw = obshistory._preparesuccessorset(successorset, pathcache) 175 raw = obshistory.preparesuccessorset(sset, rawmarkers)
143 176
144 # As we can't do something like 177 # As we can't do something like
145 # "{join(map(nodeshort, successors), ', '}" in template, manually 178 # "{join(map(nodeshort, successors), ', '}" in template, manually
146 # create a correct textual representation 179 # create a correct textual representation
147 gen = ', '.join(map(node.short, raw['successors'])) 180 gen = ', '.join(n[:12] for n in raw['successors'])
148 181
149 makemap = lambda x: {'successor': x} 182 makemap = lambda x: {'successor': x}
150 joinfmt = lambda d: "%s" % d['successor'] 183 joinfmt = lambda d: "%s" % d['successor']
151 raw['successors'] = templatekw._hybrid(gen, raw['successors'], makemap, 184 raw['successors'] = templatekw._hybrid(gen, raw['successors'], makemap,
152 joinfmt) 185 joinfmt)
153 186
154 values.append(raw) 187 values.append(raw)
155 188
156 # Insert default obsfate templates 189 # Insert default obsfate templates
157 args['templ'].cache.update(obsfatedefaulttempl()) 190 args['templ'].cache.update(obsfatedefaulttempl(repo.ui))
158 191
159 if repo.ui.quiet: 192 if repo.ui.quiet:
160 name = "obsfate_quiet" 193 name = "obsfate_quiet"
161 elif repo.ui.verbose: 194 elif repo.ui.verbose:
162 name = "obsfate_verbose" 195 name = "obsfate_verbose"