mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 23:38:50 +03:00
keyword: detect restricted commands thru variable
This commit is contained in:
parent
1c23ba81a1
commit
bb3bdb2336
@ -86,17 +86,15 @@ import re, shutil, sys, tempfile, time
|
|||||||
|
|
||||||
commands.optionalrepo += ' kwdemo'
|
commands.optionalrepo += ' kwdemo'
|
||||||
|
|
||||||
|
# hg commands that trigger expansion only when writing to working dir,
|
||||||
|
# not when reading filelog, and unexpand when reading from working dir
|
||||||
|
restricted = ('diff1', 'record',
|
||||||
|
'qfold', 'qimport', 'qnew', 'qpush', 'qrefresh', 'qrecord')
|
||||||
|
|
||||||
def utcdate(date):
|
def utcdate(date):
|
||||||
'''Returns hgdate in cvs-like UTC format.'''
|
'''Returns hgdate in cvs-like UTC format.'''
|
||||||
return time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime(date[0]))
|
return time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime(date[0]))
|
||||||
|
|
||||||
def _kwrestrict(cmd):
|
|
||||||
'''Returns True if cmd should trigger restricted expansion.
|
|
||||||
Keywords will only expanded when writing to working dir.
|
|
||||||
Crucial for mq as expanded keywords should not make it into patches.'''
|
|
||||||
return cmd in ('diff1', 'record',
|
|
||||||
'qfold', 'qimport', 'qnew', 'qpush', 'qrefresh', 'qrecord')
|
|
||||||
|
|
||||||
|
|
||||||
_kwtemplater = None
|
_kwtemplater = None
|
||||||
|
|
||||||
@ -157,7 +155,7 @@ class kwtemplater(object):
|
|||||||
|
|
||||||
def expand(self, node, data):
|
def expand(self, node, data):
|
||||||
'''Returns data with keywords expanded.'''
|
'''Returns data with keywords expanded.'''
|
||||||
if util.binary(data) or _kwrestrict(self.hgcmd):
|
if util.binary(data) or self.hgcmd in restricted:
|
||||||
return data
|
return data
|
||||||
return self.substitute(node, data, self.re_kw.sub)
|
return self.substitute(node, data, self.re_kw.sub)
|
||||||
|
|
||||||
@ -451,7 +449,7 @@ def reposetup(ui, repo):
|
|||||||
|
|
||||||
def wread(self, filename):
|
def wread(self, filename):
|
||||||
data = super(kwrepo, self).wread(filename)
|
data = super(kwrepo, self).wread(filename)
|
||||||
if _kwrestrict(hgcmd) and _kwtemplater.matcher(filename):
|
if hgcmd in restricted and _kwtemplater.matcher(filename):
|
||||||
return _kwtemplater.shrink(data)
|
return _kwtemplater.shrink(data)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user