Make patterns stricter again, to avoid unvolontary expansions
frommercurial.i18nimport_frommercurialimportcmdutil,commands,utilimportos.path,re,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 themsysargs,globalopts,cmdopts=commands.parse(ui,sys.argv[1:])[2:]files,match,anypats=cmdutil.matchpats(repo,sysargs,cmdopts)# validity checks should have been done alreadymodified,added=repo.status(files=files,match=match)[:2]candidates=modified+addedifnotcandidates: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 doreturnFalsecid=args['node'][:12]user,date=repo.changelog.read(repo.changelog.tip())[1:3]user=util.shortuser(user)date=util.datestr(date=date,format=util.defaultdateformats[0])# %Y-%m-%d %H:%M:%Sre_kw=re.compile(r'\$Hg(: [^$]+?,v [a-z0-9]{12} [^$]+? )?\$')forfinfiles:data=repo.wfile(f).read()ifnotutil.binary(data):kw='$Hg: %s,v %s%s%s $'%(os.path.basename(f),cid,date,user)data,kwct=re_kw.subn(kw,data)ifkwct:ui.note(_('expanding keywords in %s\n'%f))# backup file?repo.wfile(f,'w').write(data)