Refactor kwtemplater.overwrite()
Make kwexpand, kwshrink restricted commands - i.e. read from
filelog without expansion for substition in kwtemplater.overwrite,
and set/unset restricted mode for overwrite() in in kwcommitctx
and the dorecord wrapper.
Preselect candidates when working on changed files (rollback, record)
outside kwtemplater class, and remove 6th argument from overwrite().
Avoid duplicate substitution/search in overwrite():
Only go into restricted read mode when reading from filelog.
rollback and record read from the working directory, where
restricted mode would already shrink keywords before overwrite()
either expands or shrinks them again.
This ensures that the usual automatic operations on keywords
are turned off during overwrite() and only overwrite() itself
acts on them.
Reduce manifest calculation to the cases where it is needed.
Move helper function for expansion removal outside kwtemplater class.
$cat<<EOF>>$HGRCPATH>[extensions]>keyword=>mq=>notify=>record=>transplant=>[ui]>interactive=true>EOFRunkwdemobefore[keyword]filesaresetupasitwouldsucceedwithoutuisetupotherwise$hg--quietkwdemo[extensions]keyword=[keyword]demo.txt=[keywordmaps]Author={author|user}Date={date|utcdate}Header={root}/{file},v{node|short}{date|utcdate}{author|user}Id={file|basename},v{node|short}{date|utcdate}{author|user}RCSFile={file|basename},vRCSfile={file|basename},vRevision={node|short}Source={root}/{file},v$Author:test$$Date:????/??/????:??:??$(glob)$Header:*/demo.txt,v????????????????/??/????:??:??test$(glob)$Id:demo.txt,v????????????????/??/????:??:??test$(glob)$RCSFile:demo.txt,v$$RCSfile:demo.txt,v$$Revision:????????????$(glob)$Source:*/demo.txt,v$(glob)$hg--quietkwdemo"Branch = {branches}"[extensions]keyword=[keyword]demo.txt=[keywordmaps]Branch={branches}$Branch:demobranch$$cat<<EOF>>$HGRCPATH>[keyword]>**=>b=ignore>[hooks]>commit=>commit.test=cpahooktest>EOF$hginitTest-bndl$cdTest-bndlkwshrinkshouldexitsilentlyinempty/invalidrepo$hgkwshrinkSymlinkscannotbecreatedonWindows.Abundletotestthiswasmadewith:hginittcdtechoa>aln-sasymhgaddsymhgci-maddsym-umercurialhgbundle--basenull../test-keyword.hg$hgpull-u"$TESTDIR"/test-keyword.hgpullingfrom*test-keyword.hg(glob)requestingallchangesaddingchangesetsaddingmanifestsaddingfilechangesadded1changesetswith1changesto1files1filesupdated,0filesmerged,0filesremoved,0filesunresolved$echo'expand $Id$'>a$echo'do not process $Id:'>>a$echo'xxx $'>>a$echo'ignore $Id$'>bOutputfilesastheywerecreated$catabexpand$Id$donotprocess$Id:xxx$ignore$Id$nokwfiles$hgkwfilesuntrackedcandidates$hg-vkwfiles--unknownkaAddfilesandcheckstatus$hgaddremoveaddingaaddingb$hgstatusAaAbDefaultkeywordexpansionincludingcommithookInterruptedcommitshouldnotchangestateorruncommithook$hg--debugcommitabort:emptycommitmessage[255]$hgstatusAaAbCommitwithseveralchecks$hg--debugcommit-mabsym-u'User Name <user@example.com>'aboverwritingaexpandingkeywordsrunninghookcommit.test:cpahooktestcommittedchangeset1:ef63ca68695bc9495032c6fda1350c71e6d256e9$hgstatus?hooktest$hgdebugrebuildstate$hg--quietidentifyef63ca68695bcatfilesinworkingdirectorywithkeywordsexpanded$catabexpand$Id:a,vef63ca68695b1970/01/0100:00:00user$donotprocess$Id:xxx$ignore$Id$hgcatfilesandsymlink,noexpansion$hgcatsymab&&echoexpand$Id:a,vef63ca68695b1970/01/0100:00:00user$donotprocess$Id:xxx$ignore$Id$a*(glob)Testhookexecution$diffahooktestRemovingcommithookfromconfig$sed-e'/\[hooks\]/,$ d'"$HGRCPATH">$HGRCPATH.nohook$mv"$HGRCPATH".nohook"$HGRCPATH"$rmhooktestbundle$hgbundle--basenull../kw.hg2changesetsfound$cd..$hginitTest$cdTestNotifyonpulltocheckwhetherkeywordsstayasisinemailie.ifpatch.diffwrapperactsasitshould$cat<<EOF>>$HGRCPATH>[hooks]>incoming.notify=python:hgext.notify.hook>[notify]>sources=pull>diffstat=False>[reposubs]>*=Test>EOFPullfrombundleandtriggernotify$hgpull-u../kw.hgpullingfrom../kw.hgrequestingallchangesaddingchangesetsaddingmanifestsaddingfilechangesadded2changesetswith3changesto3filesContent-Type:text/plain;charset="us-ascii"MIME-Version:1.0Content-Transfer-Encoding:7bitDate:*(glob)Subject:changesetin*(glob)From:mercurialX-Hg-Notification:changeseta2392c293916Message-Id:<hg.a2392c293916*>(glob)To:Testchangeseta2392c293916in*(glob)details:*cmd=changeset;node=a2392c293916(glob)description:addsymdiffs(6lines):diff-r000000000000-ra2392c293916sym---/dev/nullThuJan0100:00:001970+0000+++b/symSatFeb0920:25:472008+0100@@-0,0+1,1@@+a \ NonewlineatendoffileContent-Type:text/plain;charset="us-ascii"MIME-Version:1.0Content-Transfer-Encoding:7bitDate:*(glob)Subject:changesetin*(glob)From:UserName<user@example.com>X-Hg-Notification:changesetef63ca68695bMessage-Id:<hg.ef63ca68695b*>(glob)To:Testchangesetef63ca68695bin*(glob)details:*cmd=changeset;node=ef63ca68695b(glob)description:absymdiffs(12lines):diff-ra2392c293916-ref63ca68695ba---/dev/nullThuJan0100:00:001970+0000+++b/aThuJan0100:00:001970+0000@@-0,0+1,3@@+expand$Id$+donotprocess$Id:+xxx$diff-ra2392c293916-ref63ca68695bb---/dev/nullThuJan0100:00:001970+0000+++b/bThuJan0100:00:001970+0000@@-0,0+1,1@@+ignore$Id$3filesupdated,0filesmerged,0filesremoved,0filesunresolvedRemovenotifyconfig$sed-e'/\[hooks\]/,$ d'"$HGRCPATH">$HGRCPATH.nonotify$mv"$HGRCPATH".nonotify"$HGRCPATH"Touchfilesandcheckwithstatus$touchab$hgstatusUpdateandexpand$rmsymab$hgupdate-C3filesupdated,0filesmerged,0filesremoved,0filesunresolved$catabexpand$Id:a,vef63ca68695b1970/01/0100:00:00user$donotprocess$Id:xxx$ignore$Id$Checkwhetherexpansionisfilewise$echo'$Id$'>c$echo'tests for different changenodes'>>ccommitfilec$hgcommit-A-mcndiff-d'1 0'-u'User Name <user@example.com>'addingcforceexpansion$hg-vkwexpandoverwritingaexpandingkeywordsoverwritingcexpandingkeywordscomparechangenodesinaandc$catacexpand$Id:a,vef63ca68695b1970/01/0100:00:00user$donotprocess$Id:xxx$$Id:c,v40a904bbbe4c1970/01/0100:00:01user$testsfordifferentchangenodesrecordchunk$python-c \>'l=open("a").readlines();l.insert(1,"foo\n");l.append("bar\n");open("a","w").writelines(l);'$hgrecord-d'1 10'-mrectest<<EOF>y>y>n>EOFdiff--gita/ab/a2hunks,2lineschangedexaminechangesto'a'?[Ynsfdaq?]@@-1,3+1,4@@expand$Id$+foodonotprocess$Id:xxx$recordchange1/2to'a'?[Ynsfdaq?]@@-2,2+3,3@@donotprocess$Id:xxx$+barrecordchange2/2to'a'?[Ynsfdaq?]$hgidentifyd17e03c92c97+tip$hgstatusMaCatmodifiedfilea$cataexpand$Id:a,vd17e03c92c971970/01/0100:00:01test$foodonotprocess$Id:xxx$barDiffremainingchunk$hgdiffdiff-rd17e03c92c97a---a/aWedDec3123:59:511969-0000+++b/a*(glob)@@-2,3+2,4@@foodonotprocess$Id:xxx$+bar$hgrollbackrollingbacktorevision2(undocommit)Recordallchunksinfilea$echofoo>msg-donotuse"hg record -m"here!$hgrecord-lmsg-d'1 11'<<EOF>y>y>y>EOFdiff--gita/ab/a2hunks,2lineschangedexaminechangesto'a'?[Ynsfdaq?]@@-1,3+1,4@@expand$Id$+foodonotprocess$Id:xxx$recordchange1/2to'a'?[Ynsfdaq?]@@-2,2+3,3@@donotprocess$Id:xxx$+barrecordchange2/2to'a'?[Ynsfdaq?]Fileashouldbeclean$hgstatus-AaCa$rmmsgrollbackandrevertexpansion$cataexpand$Id:a,v59f969a3b52c1970/01/0100:00:01test$foodonotprocess$Id:xxx$bar$hg--verboserollbackrollingbacktorevision2(undocommit)overwritingaexpandingkeywords$hgstatusaMa$cataexpand$Id:a,vef63ca68695b1970/01/0100:00:00user$foodonotprocess$Id:xxx$bar$echo'$Id$'>y$echo'$Id$'>z$hgaddy$hgcommit-Am"rollback only"z$catz$Id:z,v45a5d3adce531970/01/0100:00:00test$$hg--verboserollbackrollingbacktorevision2(undocommit)overwritingzshrinkingkeywordsOnlyzshouldbeoverwritten$hgstatusayzMaAyAz$catz$Id$$hgforgetyz$rmyz$hgupdate-C1filesupdated,0filesmerged,0filesremoved,0filesunresolvedTestpatchqueuerepo$hginit--mq$hgqimport-rtip-nmqtest.diff$hgcommit--mq-mmqtestKeywordsshouldnotbeexpandedinpatch$cat.hg/patches/mqtest.diff # HG changeset patch # User User Name <user@example.com> # Date 1 0 # Node ID 40a904bbbe4cd4ab0a1f28411e35db26341a40ad # Parent ef63ca68695bc9495032c6fda1350c71e6d256e9cndiffdiff-ref63ca68695b-r40a904bbbe4cc---/dev/nullThuJan0100:00:001970+0000+++b/cThuJan0100:00:011970+0000@@-0,0+1,2@@+$Id$+testsfordifferentchangenodes$hgqpoppoppingmqtest.diffpatchqueuenowemptyqgoto,implyingqpush,shouldexpand$hgqgotomqtest.diffapplyingmqtest.diffnowat:mqtest.diff$catc$Id:c,v40a904bbbe4c1970/01/0100:00:01user$testsfordifferentchangenodes$hgcatc$Id:c,v40a904bbbe4c1970/01/0100:00:01user$testsfordifferentchangenodesKeywordsshouldnotbeexpandedinfilelog$hg--config'extensions.keyword=!'catc$Id$testsfordifferentchangenodesqpopandmoveon$hgqpoppoppingmqtest.diffpatchqueuenowemptyCopyandshowaddedkwfiles$hgcpac$hgkwfilesacCommitandshowexpansioninoriginalandcopy$hg--debugcommit-ma2c-d'1 0'-u'User Name <user@example.com>'cc:copya:0045e12f6c5791aac80ca6cbfd97709a88307292overwritingcexpandingkeywordscommittedchangeset2:25736cf2f5cbe41f6be4e6784ef6ecf9f3bbcc7d$catacexpand$Id:a,vef63ca68695b1970/01/0100:00:00user$donotprocess$Id:xxx$expand$Id:c,v25736cf2f5cb1970/01/0100:00:01user$donotprocess$Id:xxx$Touchcopiedcandcheckitsstatus$touchc$hgstatusTestdifferentoptionsofhgkwfiles$hgkwfilesac$hg-vkwfiles--ignoreIbIsym$hgkwfiles--allKaKcIbIsymDiffspecificrevision$hgdiff--rev1diff-ref63ca68695bc---/dev/nullThuJan0100:00:001970+0000+++b/c*(glob)@@-0,0+1,3@@+expand$Id$+donotprocess$Id:+xxx$Statusafterrollback:$hgrollbackrollingbacktorevision1(undocommit)$hgstatusAc$hgupdate--clean0filesupdated,0filesmerged,0filesremoved,0filesunresolvedCustomkeywordmapsasargumenttokwdemo$hg--quietkwdemo"Xinfo = {author}: {desc}"[extensions]keyword=[keyword]**=b=ignoredemo.txt=[keywordmaps]Xinfo={author}:{desc}$Xinfo:test:hgkeywordconfigurationandexpansionexample$Configurecustomkeywordmaps$cat<<EOF>>$HGRCPATH>[keywordmaps]>Id={file}{node|short}{date|rfc822date}{author|user}>Xinfo={author}:{desc}>EOFCatandhgcatfilesbeforecustomexpansion$catabexpand$Id:a,vef63ca68695b1970/01/0100:00:00user$donotprocess$Id:xxx$ignore$Id$$hgcatsymab&&echoexpand$Id:aef63ca68695bThu,01Jan197000:00:00+0000user$donotprocess$Id:xxx$ignore$Id$a*(glob)Writecustomkeywordandpreparemultilinecommitmessage$echo'$Xinfo$'>>a$cat<<EOF>>log>firstline>secondline>EOFInterruptedcommitshouldnotchangestate$hgcommitabort:emptycommitmessage[255]$hgstatusMa?c?logCommitwithmultilinemessageandcustomexpansion$hg--debugcommit-llog-d'2 0'-u'User Name <user@example.com>'aoverwritingaexpandingkeywordscommittedchangeset2:bb948857c743469b22bbf51f7ec8112279ca5d83$rmlogStat,verifyandshowcustomexpansion(firstline)$hgstatus?c$hgverifycheckingchangesetscheckingmanifestscrosscheckingfilesinchangesetsandmanifestscheckingfiles3files,3changesets,4totalrevisions$catabexpand$Id:abb948857c743Thu,01Jan197000:00:02+0000user$donotprocess$Id:xxx$$Xinfo:UserName<user@example.com>:firstline$ignore$Id$$hgcatsymab&&echoexpand$Id:abb948857c743Thu,01Jan197000:00:02+0000user$donotprocess$Id:xxx$$Xinfo:UserName<user@example.com>:firstline$ignore$Id$a*(glob)annotate$hgannotatea1:expand$Id$1:donotprocess$Id:1:xxx$2:$Xinfo$removewithstatuschecks$hgdebugrebuildstate$hgremovea$hg--debugcommit-mrmacommittedchangeset3:d14c712653769de926994cf7fbb06c8fbd68f012$hgstatus?cRollback,revert,andcheckexpansion$hgrollbackrollingbacktorevision2(undocommit)$hgstatusRa?c$hgrevert--no-backup--revtipa$cataexpand$Id:abb948857c743Thu,01Jan197000:00:02+0000user$donotprocess$Id:xxx$$Xinfo:UserName<user@example.com>:firstline$Clonetotestglobalandlocalconfigurations$cd..Expansionindestinatonwithglobalconfiguration$hg--quietcloneTestglobalconf$catglobalconf/aexpand$Id:abb948857c743Thu,01Jan197000:00:02+0000user$donotprocess$Id:xxx$$Xinfo:UserName<user@example.com>:firstline$Noexpansionindestinationwithlocalconfigurationinoriginonly$hg--quiet--config'keyword.**=ignore'cloneTestlocalconf$catlocalconf/aexpand$Id$donotprocess$Id:xxx$$Xinfo$Clonetotestincoming$hgclone-r1TestTest-arequestingallchangesaddingchangesetsaddingmanifestsaddingfilechangesadded2changesetswith3changesto3filesupdatingtobranchdefault3filesupdated,0filesmerged,0filesremoved,0filesunresolved$cdTest-a$cat<<EOF>>.hg/hgrc>[paths]>default=../Test>EOF$hgincomingcomparingwith*test-keyword.t/Test(glob)searchingforchangeschangeset:2:bb948857c743tag:tipuser:UserName<user@example.com>date:ThuJan0100:00:021970+0000summary:firstlineImportedpatchshouldnotberejected$sed-e's/Id.*/& rejecttest/'a>a.new$mva.newa$hg--debugcommit-m'rejects?'-d'3 0'-u'User Name <user@example.com>'aoverwritingaexpandingkeywordscommittedchangeset2:85e279d709ffc28c9fdd1b868570985fc3d87082$hgexport-o../rejecttest.difftip$cd../Test$hgimport../rejecttest.diffapplying../rejecttest.diff$catabexpand$Id:a4e0994474d25Thu,01Jan197000:00:03+0000user$rejecttestdonotprocess$Id:rejecttestxxx$$Xinfo:UserName<user@example.com>:rejects?$ignore$Id$$hgrollbackrollingbacktorevision2(undocommit)$hgupdate--clean1filesupdated,0filesmerged,0filesremoved,0filesunresolvedkwexpand/kwshrinkonselectedfiles$mkdirx$hgcopyax/a$hg--verbosekwexpandaoverwritingaexpandingkeywordskwexpandx/ashouldabort$hg--verbosekwexpandx/aabort:outstandinguncommittedchanges[255]$cdx$hg--debugcommit-mxa-d'3 0'-u'User Name <user@example.com>'x/ax/a:copya:779c764182ce5d43e2b1eb66ce06d7b47bfe342eoverwritingx/aexpandingkeywordscommittedchangeset3:b4560182a3f9a358179fd2d835c15e9da379c1e4$cataexpand$Id:x/ab4560182a3f9Thu,01Jan197000:00:03+0000user$donotprocess$Id:xxx$$Xinfo:UserName<user@example.com>:xa$kwshrinkainsidedirectoryx$hg--verbosekwshrinkaoverwritingx/ashrinkingkeywords$cataexpand$Id$donotprocess$Id:xxx$$Xinfo$$cd..kwexpandnonexistent$hgkwexpandnonexistentnonexistent:*(glob)hgserve-expandwithhgwebfile-noexpansionwithhgwebannotate/changeset/filediff-checkerrors$hgserve-p$HGPORT-d--pid-file=hg.pid-Aaccess.log-Eerrors.log$cathg.pid>>$DAEMON_PIDS$$TESTDIR/get-with-headers.pylocalhost:$HGPORT'/file/tip/a/?style=raw'200Scriptoutputfollowsexpand$Id:abb948857c743Thu,01Jan197000:00:02+0000user$donotprocess$Id:xxx$$Xinfo:UserName<user@example.com>:firstline$$$TESTDIR/get-with-headers.pylocalhost:$HGPORT'/annotate/tip/a/?style=raw'200Scriptoutputfollowsuser@1:expand$Id$user@1:donotprocess$Id:user@1:xxx$user@2:$Xinfo$$$TESTDIR/get-with-headers.pylocalhost:$HGPORT'/rev/tip/?style=raw'200Scriptoutputfollows # HG changeset patch # User User Name <user@example.com> # Date 3 0 # Node ID b4560182a3f9a358179fd2d835c15e9da379c1e4 # Parent bb948857c743469b22bbf51f7ec8112279ca5d83xadiff-rbb948857c743-rb4560182a3f9x/a---/dev/nullThuJan0100:00:001970+0000+++b/x/aThuJan0100:00:031970+0000@@-0,0+1,4@@+expand$Id$+donotprocess$Id:+xxx$+$Xinfo$$$TESTDIR/get-with-headers.pylocalhost:$HGPORT'/diff/bb948857c743/a?style=raw'200Scriptoutputfollowsdiff-ref63ca68695b-rbb948857c743a---a/aThuJan0100:00:001970+0000+++b/aThuJan0100:00:021970+0000@@-1,3+1,4@@expand$Id$donotprocess$Id:xxx$+$Xinfo$$caterrors.logPreparemergeandresolvetests$echo'$Id$'>m$hgaddm$hgcommit-m4kw$echofoo>>m$hgcommit-m5foosimplemerge$hgupdate41filesupdated,0filesmerged,0filesremoved,0filesunresolved$echofoo>>m$hgcommit-m6foocreatednewhead$hgmerge0filesupdated,0filesmerged,0filesremoved,0filesunresolved(branchmerge,don't forget to commit) $ hg commit -m simplemerge $ cat m $Id: m 27d48ee14f67 Thu, 01 Jan 1970 00:00:00 +0000 test $ fooconflict: keyword should stay outside conflict zone $ hg update 4 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ echo bar >> m $ hg commit -m 8bar created new head $ hg merge merging m warning: conflicts during merge. merging m failed! 0 files updated, 0 files merged, 0 files removed, 1 files unresolved use 'hgresolve' to retry unresolved file merges or 'hgupdate-C.' to abandon [1] $ cat m $Id$<<<<<<<localbar=======foo>>>>>>>otherresolvetolocal$HGMERGE=internal:localhgresolve-a$hgcommit-mlocalresolve$catm$Id:m41efa6d38e9bThu,01Jan197000:00:00+0000test$barTestrestrictedmodewithtransplant-b$hgupdate61filesupdated,0filesmerged,0filesremoved,0filesunresolved$hgbranchfoomarkedworkingdirectoryasbranchfoo$mvaa.bak$echofoobranch>a$cata.bak>> a $ rm a.bak $ hg commit -m 9foobranch $ hg update default 2 files updated, 0 files merged, 0 files removed, 0 files unresolved $ hg -y transplant -b foo tip applying 4aa30d025d50 4aa30d025d50 transplanted to 5a4da427c162Expansion in changeset but not in file $ hg tip -p changeset: 11:5a4da427c162 tag: tip parent: 9:41efa6d38e9b user: test date: Thu Jan 01 00:00:00 1970 +0000 summary: 9foobranch diff -r 41efa6d38e9b -r 5a4da427c162 a --- a/a Thu Jan 01 00:00:00 1970 +0000 +++ b/a Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +1,4 @@ +foobranch expand $Id$ do not process $Id: xxx $ $ head -n 2 a foobranch expand $Id: a 5a4da427c162 Thu, 01 Jan 1970 00:00:00 +0000 test $Turn off expansion $ hg -q rollback $ hg -q update -Ckwshrink with unknown file u $ cp a u $ hg --verbose kwshrink overwriting a shrinking keywords overwriting m shrinking keywords overwriting x/a shrinking keywordsKeywords shrunk in working directory, but not yet disabled - cat shows unexpanded keywords - hg cat shows expanded keywords $ cat a b expand $Id$ do not process $Id: xxx $ $Xinfo$ ignore $Id$ $ hg cat sym a b && echo expand $Id: a bb948857c743 Thu, 01 Jan 1970 00:00:02 +0000 user $ do not process $Id: xxx $ $Xinfo: User Name <user@example.com>: firstline $ ignore $Id$ a* (glob)Now disable keyword expansion $ rm "$HGRCPATH" $ cat a b expand $Id$ do not process $Id: xxx $ $Xinfo$ ignore $Id$ $ hg cat sym a b && echo expand $Id$ do not process $Id: xxx $ $Xinfo$ ignore $Id$ a* (glob)