Show More
@@ -86,10 +86,13 b' import re, shutil, sys, tempfile, time' | |||||
86 |
|
86 | |||
87 | commands.optionalrepo += ' kwdemo' |
|
87 | commands.optionalrepo += ' kwdemo' | |
88 |
|
88 | |||
|
89 | # hg commands that do not act on keywords | |||
|
90 | nokwcommands = ('add addremove bundle copy export grep identify incoming init' | |||
|
91 | ' log outgoing push remove rename rollback tip convert') | |||
|
92 | ||||
89 | # hg commands that trigger expansion only when writing to working dir, |
|
93 | # hg commands that trigger expansion only when writing to working dir, | |
90 | # not when reading filelog, and unexpand when reading from working dir |
|
94 | # not when reading filelog, and unexpand when reading from working dir | |
91 | restricted = ('diff1', 'record', |
|
95 | restricted = 'diff1 record qfold qimport qnew qpush qrefresh qrecord' | |
92 | 'qfold', 'qimport', 'qnew', 'qpush', 'qrefresh', 'qrecord') |
|
|||
93 |
|
96 | |||
94 | def utcdate(date): |
|
97 | def utcdate(date): | |
95 | '''Returns hgdate in cvs-like UTC format.''' |
|
98 | '''Returns hgdate in cvs-like UTC format.''' | |
@@ -113,11 +116,11 b' class kwtemplater(object):' | |||||
113 | 'Header': '{root}/{file},v {node|short} {date|utcdate} {author|user}', |
|
116 | 'Header': '{root}/{file},v {node|short} {date|utcdate} {author|user}', | |
114 | } |
|
117 | } | |
115 |
|
118 | |||
116 |
def __init__(self, ui, repo, inc, exc, |
|
119 | def __init__(self, ui, repo, inc, exc, restricted): | |
117 | self.ui = ui |
|
120 | self.ui = ui | |
118 | self.repo = repo |
|
121 | self.repo = repo | |
119 | self.matcher = util.matcher(repo.root, inc=inc, exc=exc)[1] |
|
122 | self.matcher = util.matcher(repo.root, inc=inc, exc=exc)[1] | |
120 |
self. |
|
123 | self.restricted = restricted | |
121 | self.commitnode = None |
|
124 | self.commitnode = None | |
122 | self.path = '' |
|
125 | self.path = '' | |
123 |
|
126 | |||
@@ -149,14 +152,14 b' class kwtemplater(object):' | |||||
149 | self.ct.use_template(self.templates[kw]) |
|
152 | self.ct.use_template(self.templates[kw]) | |
150 | self.ui.pushbuffer() |
|
153 | self.ui.pushbuffer() | |
151 | self.ct.show(changenode=fnode, root=self.repo.root, file=self.path) |
|
154 | self.ct.show(changenode=fnode, root=self.repo.root, file=self.path) | |
152 |
|
|
155 | ekw = templatefilters.firstline(self.ui.popbuffer()) | |
153 | self.ui.popbuffer())) |
|
156 | return '$%s: %s $' % (kw, ekw) | |
154 |
|
157 | |||
155 | return subfunc(kwsub, data) |
|
158 | return subfunc(kwsub, data) | |
156 |
|
159 | |||
157 | def expand(self, node, data): |
|
160 | def expand(self, node, data): | |
158 | '''Returns data with keywords expanded.''' |
|
161 | '''Returns data with keywords expanded.''' | |
159 | if util.binary(data) or self.hgcmd in restricted: |
|
162 | if self.restricted or util.binary(data): | |
160 | return data |
|
163 | return data | |
161 | return self.substitute(node, data, self.re_kw.sub) |
|
164 | return self.substitute(node, data, self.re_kw.sub) | |
162 |
|
165 | |||
@@ -410,13 +413,8 b' def reposetup(ui, repo):' | |||||
410 | if not repo.local(): |
|
413 | if not repo.local(): | |
411 | return |
|
414 | return | |
412 |
|
415 | |||
413 | nokwcommands = ('add', 'addremove', 'bundle', 'clone', 'copy', |
|
|||
414 | 'export', 'grep', 'identify', 'incoming', 'init', |
|
|||
415 | 'log', 'outgoing', 'push', 'remove', 'rename', |
|
|||
416 | 'rollback', 'tip', |
|
|||
417 | 'convert') |
|
|||
418 | hgcmd, func, args, opts, cmdopts = dispatch._parse(ui, sys.argv[1:]) |
|
416 | hgcmd, func, args, opts, cmdopts = dispatch._parse(ui, sys.argv[1:]) | |
419 | if hgcmd in nokwcommands: |
|
417 | if hgcmd in nokwcommands.split(): | |
420 | return |
|
418 | return | |
421 |
|
419 | |||
422 | if hgcmd == 'diff': |
|
420 | if hgcmd == 'diff': | |
@@ -438,7 +436,8 b' def reposetup(ui, repo):' | |||||
438 | return |
|
436 | return | |
439 |
|
437 | |||
440 | global _kwtemplater |
|
438 | global _kwtemplater | |
441 | _kwtemplater = kwtemplater(ui, repo, inc, exc, hgcmd) |
|
439 | _restricted = hgcmd in restricted.split() | |
|
440 | _kwtemplater = kwtemplater(ui, repo, inc, exc, _restricted) | |||
442 |
|
441 | |||
443 | class kwrepo(repo.__class__): |
|
442 | class kwrepo(repo.__class__): | |
444 | def file(self, f, kwmatch=False): |
|
443 | def file(self, f, kwmatch=False): | |
@@ -450,13 +449,13 b' def reposetup(ui, repo):' | |||||
450 |
|
449 | |||
451 | def wread(self, filename): |
|
450 | def wread(self, filename): | |
452 | data = super(kwrepo, self).wread(filename) |
|
451 | data = super(kwrepo, self).wread(filename) | |
453 |
if |
|
452 | if _restricted and _kwtemplater.matcher(filename): | |
454 | return _kwtemplater.shrink(data) |
|
453 | return _kwtemplater.shrink(data) | |
455 | return data |
|
454 | return data | |
456 |
|
455 | |||
457 | def commit(self, files=None, text='', user=None, date=None, |
|
456 | def commit(self, files=None, text='', user=None, date=None, | |
458 | match=util.always, force=False, force_editor=False, |
|
457 | match=util.always, force=False, force_editor=False, | |
459 | p1=None, p2=None, extra={}): |
|
458 | p1=None, p2=None, extra={}, empty_ok=False): | |
460 | wlock = lock = None |
|
459 | wlock = lock = None | |
461 | _p1 = _p2 = None |
|
460 | _p1 = _p2 = None | |
462 | try: |
|
461 | try: | |
@@ -484,7 +483,8 b' def reposetup(ui, repo):' | |||||
484 | self).commit(files=files, text=text, user=user, |
|
483 | self).commit(files=files, text=text, user=user, | |
485 | date=date, match=match, force=force, |
|
484 | date=date, match=match, force=force, | |
486 | force_editor=force_editor, |
|
485 | force_editor=force_editor, | |
487 |
p1=p1, p2=p2, extra=extra |
|
486 | p1=p1, p2=p2, extra=extra, | |
|
487 | empty_ok=empty_ok) | |||
488 |
|
488 | |||
489 | # restore commit hooks |
|
489 | # restore commit hooks | |
490 | for name, cmd in commithooks.iteritems(): |
|
490 | for name, cmd in commithooks.iteritems(): |
@@ -43,14 +43,16 b' def _picktool(repo, ui, path, binary, sy' | |||||
43 | return False |
|
43 | return False | |
44 |
|
44 | |||
45 | # HGMERGE takes precedence |
|
45 | # HGMERGE takes precedence | |
46 |
|
|
46 | hgmerge = os.environ.get("HGMERGE") | |
47 | return os.environ.get("HGMERGE") |
|
47 | if hgmerge: | |
|
48 | return (hgmerge, hgmerge) | |||
48 |
|
49 | |||
49 | # then patterns |
|
50 | # then patterns | |
50 | for pat, tool in ui.configitems("merge-patterns"): |
|
51 | for pat, tool in ui.configitems("merge-patterns"): | |
51 | mf = util.matcher(repo.root, "", [pat], [], [])[1] |
|
52 | mf = util.matcher(repo.root, "", [pat], [], [])[1] | |
52 | if mf(path) and check(tool, pat, symlink, False): |
|
53 | if mf(path) and check(tool, pat, symlink, False): | |
53 |
|
|
54 | toolpath = _findtool(ui, tool) | |
|
55 | return (tool, '"' + toolpath + '"') | |||
54 |
|
56 | |||
55 | # then merge tools |
|
57 | # then merge tools | |
56 | tools = {} |
|
58 | tools = {} | |
@@ -63,10 +65,12 b' def _picktool(repo, ui, path, binary, sy' | |||||
63 | if ui.config("ui", "merge"): |
|
65 | if ui.config("ui", "merge"): | |
64 | tools.insert(0, (None, ui.config("ui", "merge"))) # highest priority |
|
66 | tools.insert(0, (None, ui.config("ui", "merge"))) # highest priority | |
65 | tools.append((None, "hgmerge")) # the old default, if found |
|
67 | tools.append((None, "hgmerge")) # the old default, if found | |
66 | tools.append((None, "internal:merge")) # internal merge as last resort |
|
|||
67 | for p,t in tools: |
|
68 | for p,t in tools: | |
68 | if _findtool(ui, t) and check(t, None, symlink, binary): |
|
69 | toolpath = _findtool(ui, t) | |
69 | return t |
|
70 | if toolpath and check(t, None, symlink, binary): | |
|
71 | return (t, '"' + toolpath + '"') | |||
|
72 | # internal merge as last resort | |||
|
73 | return (not (symlink or binary) and "internal:merge" or None, None) | |||
70 |
|
74 | |||
71 | def _eoltype(data): |
|
75 | def _eoltype(data): | |
72 | "Guess the EOL type of a file" |
|
76 | "Guess the EOL type of a file" | |
@@ -124,7 +128,7 b' def filemerge(repo, fw, fd, fo, wctx, mc' | |||||
124 | fca = fcm.ancestor(fco) or repo.filectx(fw, fileid=nullrev) |
|
128 | fca = fcm.ancestor(fco) or repo.filectx(fw, fileid=nullrev) | |
125 | binary = isbin(fcm) or isbin(fco) or isbin(fca) |
|
129 | binary = isbin(fcm) or isbin(fco) or isbin(fca) | |
126 | symlink = fcm.islink() or fco.islink() |
|
130 | symlink = fcm.islink() or fco.islink() | |
127 | tool = _picktool(repo, ui, fw, binary, symlink) |
|
131 | tool, toolpath = _picktool(repo, ui, fw, binary, symlink) | |
128 | ui.debug(_("picked tool '%s' for %s (binary %s symlink %s)\n") % |
|
132 | ui.debug(_("picked tool '%s' for %s (binary %s symlink %s)\n") % | |
129 | (tool, fw, binary, symlink)) |
|
133 | (tool, fw, binary, symlink)) | |
130 |
|
134 | |||
@@ -177,7 +181,6 b' def filemerge(repo, fw, fd, fo, wctx, mc' | |||||
177 | if tool == "internal:merge": |
|
181 | if tool == "internal:merge": | |
178 | r = simplemerge.simplemerge(a, b, c, label=['local', 'other']) |
|
182 | r = simplemerge.simplemerge(a, b, c, label=['local', 'other']) | |
179 | else: |
|
183 | else: | |
180 | toolpath = _findtool(ui, tool) |
|
|||
181 | args = _toolstr(ui, tool, "args", '$local $base $other') |
|
184 | args = _toolstr(ui, tool, "args", '$local $base $other') | |
182 | if "$output" in args: |
|
185 | if "$output" in args: | |
183 | out, a = a, back # read input from backup, write to original |
|
186 | out, a = a, back # read input from backup, write to original |
General Comments 0
You need to be logged in to leave comments.
Login now