Make keyword.py depend on resurrected kwutil.py
This makes pretxnkw perhaps a bit slower, but is more readable.
fromhgkwimportkwutilfrommercurial.i18nimport_frommercurialimportcmdutil,commands,utilimportre,sysdefpretxnkw(ui,repo,hooktype,**args):'''Collects candidates for keyword expansion on commit and expands keywords in working dir. NOTE: for use in combination with hgext.keyword!'''ifhooktype!='pretxncommit':# bail out with errorreturnTrue# reparse args, opts again as pretxncommit hook is silent about themcmd,sysargs,globalopts,cmdopts=commands.parse(ui,sys.argv[1:])[1:]# exclude tag and importifrepr(cmd).split()[1]in('tag','import_'):returnFalsefiles,match,anypats=cmdutil.matchpats(repo,sysargs,cmdopts)# validity checks should have been done alreadymodified,added=repo.status(files=files,match=match)[:2]candidates=[fforfinmodified+addedifnotf.startswith('.hg')]ifnotcandidates:returnFalse# only check files that have hgkwencode assigned as encode filterfiles=[]# python2.4: files = set()forpat,optinrepo.ui.configitems('keyword'):ifopt=='expand':mf=util.matcher(repo.root,'',[pat],[],[])[1]forcandidateincandidates:ifmf(candidate)andcandidatenotinfiles:files.append(candidate)# python2.4:# if mf(candidate): files.add(candidate)ifnotfiles:# nothing to doreturnFalseuser,date=repo.changelog.read(repo.changelog.tip())[1:3]re_kw=re.compile(r'\$(%s)(: [^$]+? )?\$'%kwutil.hgkeywords)forfinfiles:data=repo.wfile(f).read()ifnotutil.binary(data):defkwexpand(matchobj):returnkwutil.kwexpand(matchobj,repo,args['node'][:12],f,date,user)data,kwct=re_kw.subn(kwexpand,data)ifkwct:ui.note(_('expanding keywords in %s\n'%f))# backup file?repo.wfile(f,'w').write(data)