Mercurial > public > mercurial-scm > hg
comparison mercurial/hgweb/webutil.py @ 37699:0e02eb838b96
hgweb: extract a generator function of _siblings class
_siblings will be converted to a plain function.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 01 Apr 2018 23:47:43 +0900 |
parents | 7738ae638b62 |
children | 495fbeae63cc |
comparison
equal
deleted
inserted
replaced
37698:7738ae638b62 | 37699:0e02eb838b96 |
---|---|
179 self._revlog = repo.file(path) | 179 self._revlog = repo.file(path) |
180 | 180 |
181 def hex(self, rev): | 181 def hex(self, rev): |
182 return hex(self._changelog.node(self._revlog.linkrev(rev))) | 182 return hex(self._changelog.node(self._revlog.linkrev(rev))) |
183 | 183 |
184 # TODO: maybe this can be a wrapper class for changectx/filectx list, which | |
185 # yields {'ctx': ctx} | |
186 def _ctxsgen(ctxs): | |
187 for s in ctxs: | |
188 d = { | |
189 'node': s.hex(), | |
190 'rev': s.rev(), | |
191 'user': s.user(), | |
192 'date': s.date(), | |
193 'description': s.description(), | |
194 'branch': s.branch(), | |
195 } | |
196 if util.safehasattr(s, 'path'): | |
197 d['file'] = s.path() | |
198 yield d | |
199 | |
184 class _siblings(object): | 200 class _siblings(object): |
185 def __init__(self, siblings=None, hiderev=None): | 201 def __init__(self, siblings=None, hiderev=None): |
186 if siblings is None: | 202 if siblings is None: |
187 siblings = [] | 203 siblings = [] |
188 self.siblings = [s for s in siblings if s.node() != nullid] | 204 self.siblings = [s for s in siblings if s.node() != nullid] |
189 if len(self.siblings) == 1 and self.siblings[0].rev() == hiderev: | 205 if len(self.siblings) == 1 and self.siblings[0].rev() == hiderev: |
190 self.siblings = [] | 206 self.siblings = [] |
191 | 207 |
192 def __iter__(self): | 208 def __iter__(self): |
193 for s in self.siblings: | 209 return _ctxsgen(self.siblings) |
194 d = { | |
195 'node': s.hex(), | |
196 'rev': s.rev(), | |
197 'user': s.user(), | |
198 'date': s.date(), | |
199 'description': s.description(), | |
200 'branch': s.branch(), | |
201 } | |
202 if util.safehasattr(s, 'path'): | |
203 d['file'] = s.path() | |
204 yield d | |
205 | 210 |
206 def __len__(self): | 211 def __len__(self): |
207 return len(self.siblings) | 212 return len(self.siblings) |
208 | 213 |
209 def difffeatureopts(req, ui, section): | 214 def difffeatureopts(req, ui, section): |