diff -r 0b77aa7ff437 -r 772628d1ccb5 hgkw/keyword.py --- a/hgkw/keyword.py Thu Mar 11 19:56:41 2010 +0100 +++ b/hgkw/keyword.py Wed Mar 17 23:16:44 2010 +0100 @@ -314,7 +314,7 @@ Caveat: localrepository._link fails on Windows.''' return self.matcher(path) and not islink(path) - def overwrite(self, node, expand, files): + def overwrite(self, node, expand, candidates): '''Overwrites selected files expanding/shrinking keywords.''' # repo[changeid] introduced in f6c00b17387c if node is not None: # commit @@ -323,25 +323,23 @@ except TypeError: ctx = self.repo.changectx(node) mf = ctx.manifest() - files = [f for f in ctx.files() if f in mf] - notify = self.ui.debug + candidates = [f for f in ctx.files() if f in mf] else: # kwexpand/kwshrink try: ctx = self.repo['.'] except TypeError: ctx = self.repo.changectx() mf = ctx.manifest() - notify = self.ui.note if hasattr(ctx, 'flags'): # 51b0e799352f islink = lambda p: 'l' in ctx.flags(p) else: islink = mf.linkf - candidates = [f for f in files if self.iskwfile(f, islink)] + candidates = [f for f in candidates if self.iskwfile(f, islink)] if candidates: self.restrict = True # do not expand when reading - candidates.sort() - action = expand and 'expanding' or 'shrinking' + msg = (expand and _('overwriting %s expanding keywords\n') + or _('overwriting %s shrinking keywords\n')) overwritten = [] for f in candidates: fp = self.repo.file(f) @@ -355,7 +353,7 @@ else: found = self.re_kw.search(data) if found: - notify(_('overwriting %s %s keywords\n') % (f, action)) + self.ui.note(msg % f) self.repo.wwrite(f, data, mf.flags(f)) overwritten.append(f) _normal(self.repo, overwritten) @@ -455,10 +453,10 @@ Show current, custom, or default keyword template maps and their expansions. - Extend current configuration by specifying maps as arguments and - optionally by reading from an additional hgrc file. + Extend the current configuration by specifying maps as arguments + and using -f/--rcfile to source an external hgrc file. - Override current keyword template maps with "default" option. + Use -d/--default to disable current configuration. ''' def demoitems(section, items): items.sort() @@ -466,34 +464,41 @@ for k, v in items: ui.write('%s = %s\n' % (k, v)) - msg = 'hg keyword config and expansion example' kwstatus = 'current' fn = 'demo.txt' - branchname = 'demobranch' tmpdir = tempfile.mkdtemp('', 'kwdemo.') ui.note(_('creating temporary repository at %s\n') % tmpdir) repo = localrepo.localrepository(ui, tmpdir, True) ui.setconfig('keyword', fn, '') + + uikwmaps = ui.configitems('keywordmaps') if args or opts.get('rcfile'): - kwstatus = 'custom' - if opts.get('rcfile'): - ui.readconfig(opts.get('rcfile')) - if opts.get('default'): - kwstatus = 'default' + ui.status(_('\n\tconfiguration using custom keyword template maps\n')) + if uikwmaps: + ui.status(_('\textending current template maps\n')) + if opts.get('default') or not uikwmaps: + ui.status(_('\toverriding default template maps\n')) + if opts.get('rcfile'): + ui.readconfig(opts.get('rcfile')) + if args: + # simulate hgrc parsing + rcmaps = ['[keywordmaps]\n'] + [a + '\n' for a in args] + fp = repo.opener('hgrc', 'w') + fp.writelines(rcmaps) + fp.close() + ui.readconfig(repo.join('hgrc')) + kwmaps = dict(ui.configitems('keywordmaps')) + elif opts.get('default'): + ui.status(_('\n\tconfiguration using default keyword template maps\n')) kwmaps = kwtemplater.templates - if ui.configitems('keywordmaps'): - # override maps from optional rcfile + if uikwmaps: + ui.status(_('\tdisabling current template maps\n')) for k, v in kwmaps.iteritems(): ui.setconfig('keywordmaps', k, v) - elif args: - # simulate hgrc parsing - rcmaps = ['[keywordmaps]\n'] + [a + '\n' for a in args] - fp = repo.opener('hgrc', 'w') - fp.writelines(rcmaps) - fp.close() - ui.readconfig(repo.join('hgrc')) - if not opts.get('default'): - kwmaps = dict(ui.configitems('keywordmaps')) or kwtemplater.templates + else: + ui.status(_('\n\tconfiguration using current keyword template maps\n')) + kwmaps = dict(uikwmaps) or kwtemplater.templates + reposetup(ui, repo) for k, v in ui.configitems('extensions'): if k.endswith('keyword'): @@ -508,25 +513,21 @@ keywords = '$' + '$\n$'.join(kwkeys) + '$\n' repo.wopener(fn, 'w').write(keywords) repo.add([fn]) - path = repo.wjoin(fn) - ui.note(_('\n%s keywords written to %s:\n') % (kwstatus, path)) + ui.note(_('\nkeywords written to %s:\n') % fn) ui.note(keywords) - ui.note('\nhg -R "%s" branch "%s"\n' % (tmpdir, branchname)) - # silence branch command if not verbose - quiet = ui.quiet - ui.quiet = not ui.verbose - commands.branch(ui, repo, branchname) - ui.quiet = quiet + try: + repo.dirstate.setbranch('demobranch') + except AttributeError: + # before 7e1c8a565a4f + repo.opener('branch', 'w').write('demobranch\n') for name, cmd in ui.configitems('hooks'): if name.split('.', 1)[0].find('commit') > -1: repo.ui.setconfig('hooks', name, '') - ui.note(_('unhooked all commit hooks\n')) - ui.note('hg -R "%s" ci -m "%s"\n' % (tmpdir, msg)) + msg = _('hg keyword configuration and expansion example') + ui.note("hg ci -m '%s'\n" % msg) repo.commit(text=msg) - fmt = ui.verbose and ' in %s' % path or '' - ui.status(_('\n\t%s keywords expanded%s\n') % (kwstatus, fmt)) + ui.status(_('\n\tkeywords expanded\n')) ui.write(repo.wread(fn)) - ui.debug('\nremoving temporary repository %s\n' % tmpdir) shutil.rmtree(tmpdir, ignore_errors=True) def expand(ui, repo, *pats, **opts): @@ -552,10 +553,9 @@ See "hg help keyword" on how to construct patterns both for inclusion and exclusion of files. - Use -u/--untracked to list untracked files as well. - With -A/--all and -v/--verbose the codes used to show the status of files are: + K = keyword expansion candidate k = keyword expansion candidate (not tracked) I = ignored