See main core code for details.
We don't factor the code in a common function yet, because we will have to adapt
a bit more things in the keyword case at the end of the series.
( )
Alphare |
hg-reviewers |
See main core code for details.
We don't factor the code in a common function yet, because we will have to adapt
a bit more things in the keyword case at the end of the series.
No Linters Available |
No Unit Test Coverage |
Path | Packages | |||
---|---|---|---|---|
M | hgext/keyword.py (9 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
f0edaebf9fd5 | 22acc6a595fe | Pierre-Yves David | Nov 18 2021, 4:49 PM |
Status | Author | Revision | |
---|---|---|---|
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute |
templatefilters, | templatefilters, | ||||
templateutil, | templateutil, | ||||
util, | util, | ||||
) | ) | ||||
from mercurial.utils import ( | from mercurial.utils import ( | ||||
dateutil, | dateutil, | ||||
stringutil, | stringutil, | ||||
) | ) | ||||
from mercurial.dirstateutils import timestamp | |||||
cmdtable = {} | cmdtable = {} | ||||
command = registrar.command(cmdtable) | command = registrar.command(cmdtable) | ||||
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for | # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for | ||||
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should | # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should | ||||
# be specifying the version(s) of Mercurial they are tested with, or | # be specifying the version(s) of Mercurial they are tested with, or | ||||
# leave the attribute unspecified. | # leave the attribute unspecified. | ||||
testedwith = b'ships-with-hg-core' | testedwith = b'ships-with-hg-core' | ||||
if self.restrict or rekw: | if self.restrict or rekw: | ||||
re_kw = self.rekw | re_kw = self.rekw | ||||
else: | else: | ||||
re_kw = self.rekwexp | re_kw = self.rekwexp | ||||
if expand: | if expand: | ||||
msg = _(b'overwriting %s expanding keywords\n') | msg = _(b'overwriting %s expanding keywords\n') | ||||
else: | else: | ||||
msg = _(b'overwriting %s shrinking keywords\n') | msg = _(b'overwriting %s shrinking keywords\n') | ||||
wctx = self.repo[None] | |||||
for f in candidates: | for f in candidates: | ||||
if self.restrict: | if self.restrict: | ||||
data = self.repo.file(f).read(mf[f]) | data = self.repo.file(f).read(mf[f]) | ||||
else: | else: | ||||
data = self.repo.wread(f) | data = self.repo.wread(f) | ||||
if stringutil.binary(data): | if stringutil.binary(data): | ||||
continue | continue | ||||
if expand: | if expand: | ||||
else: | else: | ||||
data, found = _shrinktext(data, re_kw.subn) | data, found = _shrinktext(data, re_kw.subn) | ||||
if found: | if found: | ||||
self.ui.note(msg % f) | self.ui.note(msg % f) | ||||
fp = self.repo.wvfs(f, b"wb", atomictemp=True) | fp = self.repo.wvfs(f, b"wb", atomictemp=True) | ||||
fp.write(data) | fp.write(data) | ||||
fp.close() | fp.close() | ||||
if kwcmd: | if kwcmd: | ||||
self.repo.dirstate.set_clean(f) | s = wctx[f].lstat() | ||||
mode = s.st_mode | |||||
size = s.st_size | |||||
mtime = timestamp.mtime_of(s) | |||||
cache_data = (mode, size, mtime) | |||||
self.repo.dirstate.set_clean(f, cache_data) | |||||
elif self.postcommit: | elif self.postcommit: | ||||
self.repo.dirstate.update_file_p1(f, p1_tracked=True) | self.repo.dirstate.update_file_p1(f, p1_tracked=True) | ||||
def shrink(self, fname, text): | def shrink(self, fname, text): | ||||
'''Returns text with all keyword substitutions removed.''' | '''Returns text with all keyword substitutions removed.''' | ||||
if self.match(fname) and not stringutil.binary(text): | if self.match(fname) and not stringutil.binary(text): | ||||
return _shrinktext(text, self.rekwexp.sub) | return _shrinktext(text, self.rekwexp.sub) | ||||
return text | return text |