hgkw/keyword.py
branchkwmap-templates
changeset 123 6cf933de685a
parent 122 d5c80df59655
child 126 47b45198a30d
equal deleted inserted replaced
122:d5c80df59655 123:6cf933de685a
   140 
   140 
   141     if not repo.local():
   141     if not repo.local():
   142         return
   142         return
   143 
   143 
   144     inc, exc = [], ['.hg*']
   144     inc, exc = [], ['.hg*']
   145     for pat, opt in ui.configitems('keyword'):
   145     for pat, opt in repo.ui.configitems('keyword'):
   146         if opt != 'ignore':
   146         if opt != 'ignore':
   147             inc.append(pat)
   147             inc.append(pat)
   148         else:
   148         else:
   149             exc.append(pat)
   149             exc.append(pat)
   150     if not inc:
   150     if not inc:
   151         return
   151         return
   152 
   152 
   153     ui.kwfmatcher = util.matcher(repo.root, inc=inc, exc=exc)[1]
   153     repo.kwfmatcher = util.matcher(repo.root, inc=inc, exc=exc)[1]
   154 
   154 
   155     class kwrepo(repo.__class__):
   155     class kwrepo(repo.__class__):
   156         def file(self, f):
   156         def file(self, f):
   157             if f[0] == '/':
   157             if f[0] == '/':
   158                 f = f[1:]
   158                 f = f[1:]
   167                      defversion=revlog.REVLOG_DEFAULT_VERSION):
   167                      defversion=revlog.REVLOG_DEFAULT_VERSION):
   168             super(kwfilelog, self).__init__(opener, path, defversion)
   168             super(kwfilelog, self).__init__(opener, path, defversion)
   169             self._repo = repo
   169             self._repo = repo
   170             self._path = path
   170             self._path = path
   171             # only init kwtemplater if needed
   171             # only init kwtemplater if needed
   172             if not isinstance(repo, int) and ui.kwfmatcher(path):
   172             if not isinstance(repo, int) and repo.kwfmatcher(path):
   173                 self.kwt = kwtemplater(ui, repo)
   173                 self.kwt = kwtemplater(repo.ui, repo)
   174             else:
   174             else:
   175                 self.kwt = None
   175                 self.kwt = None
   176 
   176 
   177         def iskwcandidate(self, data):
   177         def iskwcandidate(self, data):
   178             '''Decides whether to act on keywords.'''
   178             '''Decides whether to act on keywords.'''
   202             return super(kwfilelog, self).cmp(node, text)
   202             return super(kwfilelog, self).cmp(node, text)
   203 
   203 
   204     filelog.filelog = kwfilelog
   204     filelog.filelog = kwfilelog
   205     repo.__class__ = kwrepo
   205     repo.__class__ = kwrepo
   206     # configure pretxncommit hook
   206     # configure pretxncommit hook
   207     ui.setconfig('hooks', 'pretxncommit.keyword',
   207     repo.ui.setconfig('hooks', 'pretxncommit.keyword',
   208             'python:%s.pretxnkw' % getmodulename())
   208             'python:%s.pretxnkw' % getmodulename())
   209 
   209 
   210 
   210 
   211 def pretxnkw(ui, repo, hooktype, **args):
   211 def pretxnkw(ui, repo, hooktype, **args):
   212     '''pretxncommit hook that collects candidates for keyword expansion
   212     '''pretxncommit hook that collects candidates for keyword expansion
   216     if repr(cmd).split()[1] in ('tag', 'import_'):
   216     if repr(cmd).split()[1] in ('tag', 'import_'):
   217         return
   217         return
   218 
   218 
   219     files, match, anypats = cmdutil.matchpats(repo, sysargs, cmdopts)
   219     files, match, anypats = cmdutil.matchpats(repo, sysargs, cmdopts)
   220     modified, added = repo.status(files=files, match=match)[:2]
   220     modified, added = repo.status(files=files, match=match)[:2]
   221     candidates = [f for f in modified + added if ui.kwfmatcher(f)]
   221     candidates = [f for f in modified + added if repo.kwfmatcher(f)]
   222     if not candidates:
   222     if not candidates:
   223         return
   223         return
   224 
   224 
   225     kwt = kwtemplater(ui, repo)
   225     kwt = kwtemplater(ui, repo)
   226     node = bin(args['node'])
   226     node = bin(args['node'])