##// END OF EJS Templates
keyword: monkeypatch patch.diff for non-interactive diffs...
Christian Ebert -
r6092:911f5be5 default
parent child Browse files
Show More
@@ -94,7 +94,7 b" nokwcommands = ('add addremove bundle co"
94
94
95 # hg commands that trigger expansion only when writing to working dir,
95 # hg commands that trigger expansion only when writing to working dir,
96 # not when reading filelog, and unexpand when reading from working dir
96 # not when reading filelog, and unexpand when reading from working dir
97 restricted = 'diff1 record qfold qimport qnew qpush qrefresh qrecord'
97 restricted = 'record qfold qimport qnew qpush qrefresh qrecord'
98
98
99 def utcdate(date):
99 def utcdate(date):
100 '''Returns hgdate in cvs-like UTC format.'''
100 '''Returns hgdate in cvs-like UTC format.'''
@@ -105,6 +105,7 b' def utcdate(date):'
105
105
106 # store originals of monkeypatches
106 # store originals of monkeypatches
107 _patchfile_init = patch.patchfile.__init__
107 _patchfile_init = patch.patchfile.__init__
108 _patch_diff = patch.diff
108 _dispatch_parse = dispatch._parse
109 _dispatch_parse = dispatch._parse
109
110
110 def _kwpatchfile_init(self, ui, fname, missing=False):
111 def _kwpatchfile_init(self, ui, fname, missing=False):
@@ -116,6 +117,16 b' def _kwpatchfile_init(self, ui, fname, m'
116 kwshrunk = _kwtemplater.shrink(''.join(self.lines))
117 kwshrunk = _kwtemplater.shrink(''.join(self.lines))
117 self.lines = kwshrunk.splitlines(True)
118 self.lines = kwshrunk.splitlines(True)
118
119
120 def _kw_diff(repo, node1=None, node2=None, files=None, match=util.always,
121 fp=None, changes=None, opts=None):
122 # only expand if comparing against working dir
123 if node2 is not None:
124 _kwtemplater.matcher = util.never
125 if node1 is not None and node1 != repo.changectx().node():
126 _kwtemplater.restrict = True
127 _patch_diff(repo, node1=node1, node2=node2, files=files, match=match,
128 fp=fp, changes=changes, opts=opts)
129
119 def _kwweb_changeset(web, req, tmpl):
130 def _kwweb_changeset(web, req, tmpl):
120 '''Wraps webcommands.changeset turning off keyword expansion.'''
131 '''Wraps webcommands.changeset turning off keyword expansion.'''
121 _kwtemplater.matcher = util.never
132 _kwtemplater.matcher = util.never
@@ -127,11 +138,10 b' def _kwweb_filediff(web, req, tmpl):'
127 return web.filediff(tmpl, web.filectx(req))
138 return web.filediff(tmpl, web.filectx(req))
128
139
129 def _kwdispatch_parse(ui, args):
140 def _kwdispatch_parse(ui, args):
130 '''Monkeypatch dispatch._parse to obtain
141 '''Monkeypatch dispatch._parse to obtain running hg command.'''
131 current command and command options (global _cmd, _cmdoptions).'''
142 global _cmd
132 global _cmd, _cmdoptions
143 _cmd, func, args, options, cmdoptions = _dispatch_parse(ui, args)
133 _cmd, func, args, options, _cmdoptions = _dispatch_parse(ui, args)
144 return _cmd, func, args, options, cmdoptions
134 return _cmd, func, args, options, _cmdoptions
135
145
136 # dispatch._parse is run before reposetup, so wrap it here
146 # dispatch._parse is run before reposetup, so wrap it here
137 dispatch._parse = _kwdispatch_parse
147 dispatch._parse = _kwdispatch_parse
@@ -434,10 +444,9 b' def reposetup(ui, repo):'
434 files configured at all for keyword substitution.'''
444 files configured at all for keyword substitution.'''
435
445
436 global _kwtemplater
446 global _kwtemplater
437 hgcmd, hgcmdopts = _cmd, _cmdoptions
438
447
439 try:
448 try:
440 if (not repo.local() or hgcmd in nokwcommands.split()
449 if (not repo.local() or _cmd in nokwcommands.split()
441 or '.hg' in util.splitpath(repo.root)
450 or '.hg' in util.splitpath(repo.root)
442 or repo._url.startswith('bundle:')):
451 or repo._url.startswith('bundle:')):
443 return
452 return
@@ -453,16 +462,7 b' def reposetup(ui, repo):'
453 if not inc:
462 if not inc:
454 return
463 return
455
464
456 if hgcmd == 'diff':
465 _kwtemplater = kwtemplater(ui, repo, inc, exc, _cmd)
457 # only expand if comparing against working dir
458 node1, node2 = cmdutil.revpair(repo, hgcmdopts.get('rev'))
459 if node2 is not None:
460 return
461 # shrink if rev is not current node
462 if node1 is not None and node1 != repo.changectx().node():
463 hgcmd = 'diff1'
464
465 _kwtemplater = kwtemplater(ui, repo, inc, exc, hgcmd)
466
466
467 class kwrepo(repo.__class__):
467 class kwrepo(repo.__class__):
468 def file(self, f, kwmatch=False):
468 def file(self, f, kwmatch=False):
@@ -523,6 +523,7 b' def reposetup(ui, repo):'
523
523
524 repo.__class__ = kwrepo
524 repo.__class__ = kwrepo
525 patch.patchfile.__init__ = _kwpatchfile_init
525 patch.patchfile.__init__ = _kwpatchfile_init
526 patch.diff = _kw_diff
526 webcommands.changeset = webcommands.rev = _kwweb_changeset
527 webcommands.changeset = webcommands.rev = _kwweb_changeset
527 webcommands.filediff = webcommands.diff = _kwweb_filediff
528 webcommands.filediff = webcommands.diff = _kwweb_filediff
528
529
General Comments 0
You need to be logged in to leave comments. Login now