comparison hgext/keyword.py @ 22918:31f34a213384

keyword: access status fields by name rather than index
author Martin von Zweigbergk <martinvonz@gmail.com>
date Fri, 03 Oct 2014 10:05:54 -0700
parents 97d5aca9bb66
children c4ce50a3d634
comparison
equal deleted inserted replaced
22917:1c38b4063586 22918:31f34a213384
169 169
170 def _preselect(wstatus, changed): 170 def _preselect(wstatus, changed):
171 '''Retrieves modified and added files from a working directory state 171 '''Retrieves modified and added files from a working directory state
172 and returns the subset of each contained in given changed files 172 and returns the subset of each contained in given changed files
173 retrieved from a change context.''' 173 retrieved from a change context.'''
174 modified, added = wstatus[:2] 174 modified = [f for f in wstatus.modified if f in changed]
175 modified = [f for f in modified if f in changed] 175 added = [f for f in wstatus.added if f in changed]
176 added = [f for f in added if f in changed]
177 return modified, added 176 return modified, added
178 177
179 178
180 class kwtemplater(object): 179 class kwtemplater(object):
181 ''' 180 '''
347 raise util.Abort(_('outstanding uncommitted merge')) 346 raise util.Abort(_('outstanding uncommitted merge'))
348 kwt = kwtools['templater'] 347 kwt = kwtools['templater']
349 wlock = repo.wlock() 348 wlock = repo.wlock()
350 try: 349 try:
351 status = _status(ui, repo, wctx, kwt, *pats, **opts) 350 status = _status(ui, repo, wctx, kwt, *pats, **opts)
352 modified, added, removed, deleted, unknown, ignored, clean = status 351 if status.modified or status.added or status.removed or status.deleted:
353 if modified or added or removed or deleted:
354 raise util.Abort(_('outstanding uncommitted changes')) 352 raise util.Abort(_('outstanding uncommitted changes'))
355 kwt.overwrite(wctx, clean, True, expand) 353 kwt.overwrite(wctx, status.clean, True, expand)
356 finally: 354 finally:
357 wlock.release() 355 wlock.release()
358 356
359 @command('kwdemo', 357 @command('kwdemo',
360 [('d', 'default', None, _('show default keyword template maps')), 358 [('d', 'default', None, _('show default keyword template maps')),
501 ''' 499 '''
502 kwt = kwtools['templater'] 500 kwt = kwtools['templater']
503 wctx = repo[None] 501 wctx = repo[None]
504 status = _status(ui, repo, wctx, kwt, *pats, **opts) 502 status = _status(ui, repo, wctx, kwt, *pats, **opts)
505 cwd = pats and repo.getcwd() or '' 503 cwd = pats and repo.getcwd() or ''
506 modified, added, removed, deleted, unknown, ignored, clean = status
507 files = [] 504 files = []
508 if not opts.get('unknown') or opts.get('all'): 505 if not opts.get('unknown') or opts.get('all'):
509 files = sorted(modified + added + clean) 506 files = sorted(status.modified + status.added + status.clean)
510 kwfiles = kwt.iskwfile(files, wctx) 507 kwfiles = kwt.iskwfile(files, wctx)
511 kwdeleted = kwt.iskwfile(deleted, wctx) 508 kwdeleted = kwt.iskwfile(status.deleted, wctx)
512 kwunknown = kwt.iskwfile(unknown, wctx) 509 kwunknown = kwt.iskwfile(status.unknown, wctx)
513 if not opts.get('ignore') or opts.get('all'): 510 if not opts.get('ignore') or opts.get('all'):
514 showfiles = kwfiles, kwdeleted, kwunknown 511 showfiles = kwfiles, kwdeleted, kwunknown
515 else: 512 else:
516 showfiles = [], [], [] 513 showfiles = [], [], []
517 if opts.get('all') or opts.get('ignore'): 514 if opts.get('all') or opts.get('ignore'):
518 showfiles += ([f for f in files if f not in kwfiles], 515 showfiles += ([f for f in files if f not in kwfiles],
519 [f for f in unknown if f not in kwunknown]) 516 [f for f in status.unknown if f not in kwunknown])
520 kwlabels = 'enabled deleted enabledunknown ignored ignoredunknown'.split() 517 kwlabels = 'enabled deleted enabledunknown ignored ignoredunknown'.split()
521 kwstates = zip(kwlabels, 'K!kIi', showfiles) 518 kwstates = zip(kwlabels, 'K!kIi', showfiles)
522 fm = ui.formatter('kwfiles', opts) 519 fm = ui.formatter('kwfiles', opts)
523 fmt = '%.0s%s\n' 520 fmt = '%.0s%s\n'
524 if opts.get('all') or ui.verbose: 521 if opts.get('all') or ui.verbose: