hgkw/keyword.py
changeset 319 2da9ab0bc400
parent 318 12d26936a315
child 320 83dad6b67ed9
equal deleted inserted replaced
318:12d26936a315 319:2da9ab0bc400
   288     branchname = 'demobranch'
   288     branchname = 'demobranch'
   289     tmpdir = tempfile.mkdtemp('', 'kwdemo.')
   289     tmpdir = tempfile.mkdtemp('', 'kwdemo.')
   290     ui.note(_('creating temporary repo at %s\n') % tmpdir)
   290     ui.note(_('creating temporary repo at %s\n') % tmpdir)
   291     repo = localrepo.localrepository(ui, path=tmpdir, create=True)
   291     repo = localrepo.localrepository(ui, path=tmpdir, create=True)
   292     ui.setconfig('keyword', fn, '')
   292     ui.setconfig('keyword', fn, '')
   293     if args or opts['rcfile']:
   293     if args or opts.get('rcfile'):
   294         kwstatus = 'custom'
   294         kwstatus = 'custom'
   295     if opts['rcfile']:
   295     if opts.get('rcfile'):
   296         ui.readconfig(opts['rcfile'])
   296         ui.readconfig(opts.get('rcfile'))
   297     if opts['default']:
   297     if opts.get('default'):
   298         kwstatus = 'default'
   298         kwstatus = 'default'
   299         kwmaps = kwtemplater.templates
   299         kwmaps = kwtemplater.templates
   300         if ui.configitems('keywordmaps'):
   300         if ui.configitems('keywordmaps'):
   301             # override maps from optional rcfile
   301             # override maps from optional rcfile
   302             for k, v in kwmaps.items():
   302             for k, v in kwmaps.items():
   306         rcmaps = ['[keywordmaps]\n'] + [a + '\n' for a in args]
   306         rcmaps = ['[keywordmaps]\n'] + [a + '\n' for a in args]
   307         fp = repo.opener('hgrc', 'w')
   307         fp = repo.opener('hgrc', 'w')
   308         fp.writelines(rcmaps)
   308         fp.writelines(rcmaps)
   309         fp.close()
   309         fp.close()
   310         ui.readconfig(repo.join('hgrc'))
   310         ui.readconfig(repo.join('hgrc'))
   311     if not opts['default']:
   311     if not opts.get('default'):
   312         kwmaps = dict(ui.configitems('keywordmaps')) or kwtemplater.templates
   312         kwmaps = dict(ui.configitems('keywordmaps')) or kwtemplater.templates
   313     reposetup(ui, repo)
   313     reposetup(ui, repo)
   314     for k, v in ui.configitems('extensions'):
   314     for k, v in ui.configitems('extensions'):
   315         if k.endswith('keyword'):
   315         if k.endswith('keyword'):
   316             extension = '%s = %s' % (k, v)
   316             extension = '%s = %s' % (k, v)
   361     keyword expansion.
   361     keyword expansion.
   362     That is, files matched by [keyword] config patterns but not symlinks.
   362     That is, files matched by [keyword] config patterns but not symlinks.
   363     '''
   363     '''
   364     status = _status(ui, repo, *pats, **opts)
   364     status = _status(ui, repo, *pats, **opts)
   365     modified, added, removed, deleted, unknown, ignored, clean = status
   365     modified, added, removed, deleted, unknown, ignored, clean = status
   366     if opts['untracked']:
   366     if opts.get('untracked'):
   367         files = modified + added + unknown + clean
   367         files = modified + added + unknown + clean
   368     else:
   368     else:
   369         files = modified + added + clean
   369         files = modified + added + clean
   370     files.sort()
   370     files.sort()
   371     kwfiles = [f for f in files if _iskwfile(f, repo._link)]
   371     kwfiles = [f for f in files if _iskwfile(f, repo._link)]
   372     cwd = pats and repo.getcwd() or ''
   372     cwd = pats and repo.getcwd() or ''
   373     allf = opts['all']
   373     if opts.get('ignore'):
   374     ignore = opts['ignore']
       
   375     if ignore:
       
   376         kwfstats = ()
   374         kwfstats = ()
   377     else:
   375     else:
   378         kwfstats = (('K', kwfiles),)
   376         kwfstats = (('K', kwfiles),)
   379     if allf or ignore:
   377     if opts.get('all') or opts.get('ignore'):
   380         kwfstats += (('I', [f for f in files if f not in kwfiles]),)
   378         kwfstats += (('I', [f for f in files if f not in kwfiles]),)
   381     for char, filenames in kwfstats:
   379     for char, filenames in kwfstats:
   382         format = (allf or ui.verbose) and '%s %%s\n' % char or '%s\n'
   380         format = (opts.get('all') or ui.verbose) and '%s %%s\n' % char or '%s\n'
   383         for f in filenames:
   381         for f in filenames:
   384             ui.write(format % repo.pathto(f, cwd))
   382             ui.write(format % repo.pathto(f, cwd))
   385 
   383 
   386 def shrink(ui, repo, *pats, **opts):
   384 def shrink(ui, repo, *pats, **opts):
   387     '''revert expanded keywords in working directory
   385     '''revert expanded keywords in working directory