Mercurial > evolve
comparison hgext3rd/evolve/templatekw.py @ 2594:a3fbe5293bf6 stable
merge with stable
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Fri, 16 Jun 2017 11:32:21 +0200 |
parents | 606722a686ef 1991935fb603 |
children | 54ac473663ff 3d432af2f6cd |
comparison
equal
deleted
inserted
replaced
2557:e3acb8823900 | 2594:a3fbe5293bf6 |
---|---|
89 [ctx1, ctx2], [ctx3] if ctx has been splitted into ctx1 and ctx2 while | 89 [ctx1, ctx2], [ctx3] if ctx has been splitted into ctx1 and ctx2 while |
90 also diverged into ctx3""" | 90 also diverged into ctx3""" |
91 if not ctx.obsolete(): | 91 if not ctx.obsolete(): |
92 return '' | 92 return '' |
93 | 93 |
94 ssets = closestsuccessors(repo, ctx.node()) | 94 ssets, _ = closestsuccessors(repo, ctx.node()) |
95 | 95 |
96 data = [] | 96 data = [] |
97 gen = [] | 97 gen = [] |
98 for ss in ssets: | 98 for ss in ssets: |
99 subgen = '[%s]' % ', '.join(map(node.short, ss)) | 99 subgen = '[%s]' % ', '.join(map(node.short, ss)) |
104 | 104 |
105 gen = ', '.join(gen) | 105 gen = ', '.join(gen) |
106 return templatekw._hybrid(iter(gen), data, lambda x: {'successorset': x}, | 106 return templatekw._hybrid(iter(gen), data, lambda x: {'successorset': x}, |
107 lambda d: d["successorset"]) | 107 lambda d: d["successorset"]) |
108 | 108 |
109 @eh.templatekw("obsfate_quiet") | 109 def obsfatedefaulttempl(): |
110 def showobsfate_quiet(repo, ctx, templ, **args): | 110 """ Returns a dict with the default templates for obs fate |
111 """ | |
112 # Prepare templates | |
113 verbtempl = '{verb}' | |
114 usertempl = '{if(users, " by {join(users, ", ")}")}' | |
115 succtempl = '{if(successors, " as ")}{successors}' # Bypass if limitation | |
116 datetempleq = ' (at {min_date|isodate})' | |
117 datetemplnoteq = ' (between {min_date|isodate} and {max_date|isodate})' | |
118 datetempl = '{if(max_date, "{ifeq(min_date, max_date, "%s", "%s")}")}' % (datetempleq, datetemplnoteq) | |
119 newline = '\n' | |
120 | |
121 # Assemble them | |
122 return { | |
123 'obsfate_quiet': verbtempl + succtempl + newline, | |
124 'obsfate': verbtempl + usertempl + succtempl + newline, | |
125 'obsfate_verbose': verbtempl + usertempl + succtempl + datetempl + newline | |
126 } | |
127 | |
128 @eh.templatekw("obsfate") | |
129 def showobsfate(repo, ctx, **args): | |
111 if not ctx.obsolete(): | 130 if not ctx.obsolete(): |
112 return '' | 131 return '' |
113 | 132 |
114 successorssets = closestsuccessors(repo, ctx.node()) | 133 successorssets, pathcache = closestsuccessors(repo, ctx.node()) |
115 return obshistory._humanizedobsfate(*obshistory._getobsfateandsuccs(repo, ctx, successorssets)) | 134 |
135 # closestsuccessors returns an empty list for pruned revisions, remap it | |
136 # into a list containing en empty list for future processing | |
137 if successorssets == []: | |
138 successorssets = [[]] | |
139 | |
140 values = [] | |
141 for successorset in successorssets: | |
142 raw = obshistory._preparesuccessorset(successorset, pathcache) | |
143 | |
144 # As we can't do something like | |
145 # "{join(map(nodeshort, successors), ', '}" in template, manually | |
146 # create a correct textual representation | |
147 gen = ', '.join(map(node.short, raw['successors'])) | |
148 | |
149 makemap = lambda x: {'successor': x} | |
150 joinfmt = lambda d: "%s" % d['successor'] | |
151 raw['successors'] = templatekw._hybrid(gen, raw['successors'], makemap, | |
152 joinfmt) | |
153 | |
154 values.append(raw) | |
155 | |
156 # Insert default obsfate templates | |
157 args['templ'].cache.update(obsfatedefaulttempl()) | |
158 | |
159 if repo.ui.quiet: | |
160 name = "obsfate_quiet" | |
161 elif repo.ui.verbose: | |
162 name = "obsfate_verbose" | |
163 elif repo.ui.debugflag: | |
164 name = "obsfate_debug" | |
165 else: | |
166 name = "obsfate" | |
167 | |
168 return templatekw.showlist(name, values, args, separator=' + ') | |
116 | 169 |
117 # copy from mercurial.obsolete with a small change to stop at first known changeset. | 170 # copy from mercurial.obsolete with a small change to stop at first known changeset. |
118 | 171 |
119 def directsuccessorssets(repo, initialnode, cache=None): | 172 def directsuccessorssets(repo, initialnode, cache=None): |
120 """return set of all direct successors of initial nodes | 173 """return set of all direct successors of initial nodes |
125 # Stack of nodes we search successors sets for | 178 # Stack of nodes we search successors sets for |
126 toproceed = [initialnode] | 179 toproceed = [initialnode] |
127 # set version of above list for fast loop detection | 180 # set version of above list for fast loop detection |
128 # element added to "toproceed" must be added here | 181 # element added to "toproceed" must be added here |
129 stackedset = set(toproceed) | 182 stackedset = set(toproceed) |
183 | |
184 pathscache = {} | |
185 | |
130 if cache is None: | 186 if cache is None: |
131 cache = {} | 187 cache = {} |
132 while toproceed: | 188 while toproceed: |
133 current = toproceed[-1] | 189 current = toproceed[-1] |
134 if current in cache: | 190 if current in cache: |
154 else: | 210 else: |
155 # case (3) If we have not computed successors sets | 211 # case (3) If we have not computed successors sets |
156 # of one of those successors we add it to the | 212 # of one of those successors we add it to the |
157 # `toproceed` stack and stop all work for this | 213 # `toproceed` stack and stop all work for this |
158 # iteration. | 214 # iteration. |
215 pathscache.setdefault(suc, []).append((current, mark)) | |
159 toproceed.append(suc) | 216 toproceed.append(suc) |
160 stackedset.add(suc) | 217 stackedset.add(suc) |
161 break | 218 break |
162 else: | 219 else: |
163 continue | 220 continue |
193 else: | 250 else: |
194 final.append(listversion) | 251 final.append(listversion) |
195 seen.append(setversion) | 252 seen.append(setversion) |
196 final.reverse() # put small successors set first | 253 final.reverse() # put small successors set first |
197 cache[current] = final | 254 cache[current] = final |
198 return cache[initialnode] | 255 |
256 return cache[initialnode], pathscache |