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