diff -r 80a300088654 -r b05795ad5632 hgkw/keyword.py --- a/hgkw/keyword.py Tue Nov 06 13:20:39 2007 +0100 +++ b/hgkw/keyword.py Wed Nov 07 13:40:58 2007 +0100 @@ -80,65 +80,10 @@ Or, better, use bundle/unbundle to share changes. ''' -from mercurial import commands, cmdutil, context, fancyopts +from mercurial import commands, cmdutil, context, dispatch from mercurial import filelog, localrepo, revlog, templater, util -from mercurial.i18n import gettext as _ -import getopt, os.path, re, shutil, sys, tempfile, time - -# backwards compatibility hacks - -try: - # cmdutil.parse moves to dispatch._parse in 18a9fbb5cd78 - # also avoid name conflict with other dispatch package(s) - from mercurial.dispatch import _parse -except ImportError: - try: - # commands.parse moves to cmdutil.parse in 0c61124ad877 - _parse = cmdutil.parse - except AttributeError: - _parse = commands.parse - -def _pathto(repo, f, cwd=None): - '''kwfiles behaves similar to status, using pathto since 78b6add1f966.''' - try: - return repo.pathto(f, cwd) - except AttributeError: - return f - -# commands.parse/cmdutil.parse returned nothing for -# "hg diff --rev" before 88803a69b24a due to bug in fancyopts -def _fancyopts(args, options, state): - '''Fixed fancyopts from 88803a69b24a.''' - long = [] - short = '' - map = {} - dt = {} - for s, l, d, c in options: - pl = l.replace('-', '_') - map['-'+s] = map['--'+l] = pl - if isinstance(d, list): - state[pl] = d[:] - else: - state[pl] = d - dt[pl] = type(d) - if (d is not None and d is not True and d is not False and - not callable(d)): - if s: s += ':' - if l: l += '=' - if s: short = short + s - if l: long.append(l) - opts, args = getopt.getopt(args, short, long) - for opt, arg in opts: - if dt[map[opt]] is type(fancyopts): state[map[opt]](state, map[opt], arg) - elif dt[map[opt]] is type(1): state[map[opt]] = int(arg) - elif dt[map[opt]] is type(''): state[map[opt]] = arg - elif dt[map[opt]] is type([]): state[map[opt]].append(arg) - elif dt[map[opt]] is type(None): state[map[opt]] = True - elif dt[map[opt]] is type(False): state[map[opt]] = True - return args - -fancyopts.fancyopts = _fancyopts - +from mercurial.i18n import _ +import re, shutil, sys, tempfile, time commands.optionalrepo += ' kwdemo' @@ -179,35 +124,8 @@ self.re_kw = re.compile(kwpat) if self.t: templater.common_filters['utcdate'] = utcdate - self.t = self._changeset_templater() - - def _changeset_templater(self): - '''Backwards compatible cmdutil.changeset_templater.''' - # before 1e0b94cfba0e there was an extra "brinfo" argument - try: - return cmdutil.changeset_templater(self.ui, self.repo, - False, '', False) - except TypeError: - return cmdutil.changeset_templater(self.ui, self.repo, - False, None, '', False) - - def _wwrite(self, f, data, man): - '''Makes repo.wwrite backwards compatible.''' - # 656e06eebda7 removed file descriptor argument - # 67982d3ee76c added flags argument - try: - self.repo.wwrite(f, data, man.flags(f)) - except (AttributeError, TypeError): - self.repo.wwrite(f, data) - - def _normal(self, files): - '''Backwards compatible repo.dirstate.normal/update.''' - # 6fd953d5faea introduced dirstate.normal() - try: - for f in files: - self.repo.dirstate.normal(f) - except AttributeError: - self.repo.dirstate.update(files, 'n') + self.t = cmdutil.changeset_templater(self.ui, self.repo, + False, '', False) def kwsub(self, mobj): '''Substitutes keyword using corresponding template.''' @@ -238,7 +156,8 @@ def process(self, node, data): '''Returns a tuple: data, count. - Count is number of keywords/keyword substitutions. + Count is number of keywords/keyword substitutions, indicates + to caller whether to act on file containing data. Keywords in data are expanded, if templater was initialized.''' if util.binary(data): return data, None @@ -259,15 +178,13 @@ expand = self.t is not None action = ('shrinking', 'expanding')[expand] notify = (self.ui.note, self.ui.debug)[commit] - overwritten = [] for f in candidates: fp = self.repo.file(f, kwexp=expand, kwmatch=True) data, kwfound = fp.kwctread(man[f]) if kwfound: notify(_('overwriting %s %s keywords\n') % (f, action)) - self._wwrite(f, data, man) - overwritten.append(f) - self._normal(overwritten) + self.repo.wwrite(f, data, man.flags(f)) + self.repo.dirstate.normal(f) class kwfilelog(filelog.filelog): ''' @@ -303,6 +220,8 @@ return revlog.revlog.cmp(self, node, text) def _status(ui, repo, *pats, **opts): + '''Bails out if [keyword] configuration is not active. + Returns status of working directory.''' if hasattr(ui, 'kwfmatcher'): files, match, anypats = cmdutil.matchpats(repo, pats, opts) return repo.status(files=files, match=match, list_clean=True) @@ -440,9 +359,7 @@ else: files = modified + added + clean files.sort() - # use the full definition of repo._link for backwards compatibility - kwfiles = [f for f in files if ui.kwfmatcher(f) - and not os.path.islink(repo.wjoin(f))] + kwfiles = [f for f in files if ui.kwfmatcher(f) and not repo._link(f)] cwd = pats and repo.getcwd() or '' allf = opts['all'] ignore = opts['ignore'] @@ -450,11 +367,11 @@ if not ignore: format = ('%s\n', 'K %s\n')[flag] for k in kwfiles: - ui.write(format % _pathto(repo, k, cwd)) + ui.write(format % repo.pathto(k, cwd)) if allf or ignore: format = ('%s\n', 'I %s\n')[flag] for i in [f for f in files if f not in kwfiles]: - ui.write(format % _pathto(repo, i, cwd)) + ui.write(format % repo.pathto(i, cwd)) def shrink(ui, repo, *pats, **opts): '''revert expanded keywords in working directory @@ -481,7 +398,8 @@ 'grep', 'identify', 'incoming', 'init', 'outgoing', 'push', 'remove', 'rename', 'rollback', 'convert'] - if not repo.local() or _parse(ui, sys.argv[1:])[0] in nokwcommands: + if (not repo.local() or + dispatch._parse(ui, sys.argv[1:])[0] in nokwcommands): return inc, exc = [], ['.hgtags'] @@ -504,39 +422,18 @@ return kwfilelog(self.sopener, f, kwt) return filelog.filelog(self.sopener, f) - def _commit(self, files, text, user, date, match, force, lock, wlock, - force_editor, p1, p2, extra): - '''Private commit wrapper for backwards compatibility.''' + def commit(self, files=None, text='', user=None, date=None, + match=util.always, force=False, force_editor=False, + p1=None, p2=None, extra={}): + wlock = lock = None try: - return super(kwrepo, self).commit(files=files, text=text, - user=user, date=date, - match=match, force=force, - lock=lock, wlock=wlock, - force_editor=force_editor, - p1=p1, p2=p2, extra=extra) - except TypeError: - return super(kwrepo, self).commit(files=files, text=text, - user=user, date=date, - match=match, force=force, - force_editor=force_editor, - p1=p1, p2=p2, extra=extra) - - def commit(self, files=None, text='', user=None, date=None, - match=util.always, force=False, lock=None, wlock=None, - force_editor=False, p1=None, p2=None, extra={}): - # (w)lock arguments removed in 126f527b3ba3 - # so they are None or what was passed to commit - # use private _(w)lock for deletion - _lock = lock - _wlock = wlock - del wlock, lock - try: - if not _wlock: - _wlock = self.wlock() - if not _lock: - _lock = self.lock() - node = self._commit(files, text, user, date, match, force, - _lock, _wlock, force_editor, p1, p2, extra) + wlock = self.wlock() + lock = self.lock() + node = super(kwrepo, + self).commit(files=files, text=text, user=user, + date=date, match=match, force=force, + force_editor=force_editor, + p1=p1, p2=p2, extra=extra) if node is not None: cl = self.changelog.read(node) mn = self.manifest.read(cl[0]) @@ -547,7 +444,7 @@ _overwrite(ui, self, candidates, node, mn, True, True) return node finally: - del _wlock, _lock + del wlock, lock repo.__class__ = kwrepo