72 "hg kwexpand". |
72 "hg kwexpand". |
73 |
73 |
74 Expansions spanning more than one line and incremental expansions, |
74 Expansions spanning more than one line and incremental expansions, |
75 like CVS' $Log$, are not supported. A keyword template map |
75 like CVS' $Log$, are not supported. A keyword template map |
76 "Log = {desc}" expands to the first line of the changeset description. |
76 "Log = {desc}" expands to the first line of the changeset description. |
77 |
|
78 Caveat: "hg import" fails if the patch context contains an active |
|
79 keyword. In that case run "hg kwshrink", and then reimport. |
|
80 Or, better, use bundle/unbundle to share changes. |
|
81 ''' |
77 ''' |
82 |
78 |
83 from mercurial import commands, cmdutil, context, fancyopts |
79 from mercurial import commands, cmdutil, context, fancyopts, filelog |
84 from mercurial import filelog, localrepo, revlog, templater, util |
80 from mercurial import patch, localrepo, revlog, templater, util |
85 from mercurial.node import * |
81 from mercurial.node import * |
86 from mercurial.i18n import _ |
82 from mercurial.i18n import _ |
87 import re, shutil, sys, tempfile, time |
83 import re, shutil, sys, tempfile, time |
88 |
84 |
89 commands.optionalrepo += ' kwdemo' |
85 commands.optionalrepo += ' kwdemo' |
199 text = _kwtemplater.shrink(text) |
195 text = _kwtemplater.shrink(text) |
200 if self.renamed(node): |
196 if self.renamed(node): |
201 t2 = super(kwfilelog, self).read(node) |
197 t2 = super(kwfilelog, self).read(node) |
202 return t2 != text |
198 return t2 != text |
203 return revlog.revlog.cmp(self, node, text) |
199 return revlog.revlog.cmp(self, node, text) |
|
200 |
|
201 |
|
202 def _kwpatchfile_init(self, ui, fname, missing=False): |
|
203 '''Monkeypatch patch.patchfile.__init__, to avoid |
|
204 rejects or conflicts due to expanded keywords in working dir.''' |
|
205 self.fname = fname |
|
206 self.ui = ui |
|
207 self.lines = [] |
|
208 self.exists = False |
|
209 self.missing = missing |
|
210 if not missing: |
|
211 try: |
|
212 fp = file(fname, 'rb') |
|
213 |
|
214 if _kwtemplater.matcher(self.fname): |
|
215 # shrink keywords in working dir |
|
216 kwshrunk = _kwtemplater.shrink(fp.read()) |
|
217 self.lines = kwshrunk.splitlines(True) |
|
218 |
|
219 else: |
|
220 self.lines = fp.readlines() |
|
221 self.exists = True |
|
222 except IOError: |
|
223 pass |
|
224 else: |
|
225 self.ui.warn(_("unable to find '%s' for patching\n") % self.fname) |
|
226 |
|
227 if not self.exists: |
|
228 dirname = os.path.dirname(fname) |
|
229 if dirname and not os.path.isdir(dirname): |
|
230 os.makedirs(dirname) |
|
231 |
|
232 self.hash = {} |
|
233 self.dirty = 0 |
|
234 self.offset = 0 |
|
235 self.rej = [] |
|
236 self.fileprinted = False |
|
237 self.printfile(False) |
|
238 self.hunks = 0 |
|
239 |
204 |
240 |
205 def _iskwfile(f, link): |
241 def _iskwfile(f, link): |
206 return not link(f) and _kwtemplater.matcher(f) |
242 return not link(f) and _kwtemplater.matcher(f) |
207 |
243 |
208 def _status(ui, repo, *pats, **opts): |
244 def _status(ui, repo, *pats, **opts): |