1 # $Hg$ |
1 # $Hg$ |
2 |
2 |
3 from mercurial import demandimport |
|
4 demandimport.enable() |
|
5 |
|
6 from mercurial.i18n import _ |
3 from mercurial.i18n import _ |
7 import mercurial.util, re |
4 from mercurial import util |
|
5 import re |
8 |
6 |
9 # name of keyword encode filter: |
7 # name of keyword encode filter: |
10 kwencodefilter = 'hgkwencode' |
8 kwencodefilter = 'hgkwencode' |
11 # look for <Dollar>Hg<Dollar> |
9 # look for <Dollar>Hg<Dollar> |
12 kwtrigger = '%sHg$' % '$' |
10 kwtrigger = '%sHg$' % '$' |
14 def wwritekw(ui, repo, f, text): |
12 def wwritekw(ui, repo, f, text): |
15 '''Writes text with kwupdates keywords to f in working directory.''' |
13 '''Writes text with kwupdates keywords to f in working directory.''' |
16 ui.note(_('expanding keywords in %s\n' % f)) |
14 ui.note(_('expanding keywords in %s\n' % f)) |
17 # # backup file (?) |
15 # # backup file (?) |
18 # absfile = repo.wjoin(f) |
16 # absfile = repo.wjoin(f) |
19 # mercurial.util.copyfile(absfile, absfile+'.kwbak') |
17 # util.copyfile(absfile, absfile+'.kwbak') |
20 repo.wfile(f, 'w').write(text) |
18 repo.wfile(f, 'w').write(text) |
21 |
19 |
22 def expandkw(ui, repo, node, cid, candidates, update=False): |
20 def expandkw(ui, repo, node, cid, candidates, update=False): |
23 '''Important: returns False on success, True on failure.''' |
21 '''Important: returns False on success, True on failure.''' |
24 |
22 |
25 # only check files that have hgkwencode assigned as encode filter |
23 # only check files that have hgkwencode assigned as encode filter |
26 files = [] |
24 files = [] |
27 # python2.4: files = set() |
25 # python2.4: files = set() |
28 for pat, cmd in repo.ui.configitems('encode'): |
26 for pat, cmd in repo.ui.configitems('encode'): |
29 if cmd.endswith(kwencodefilter): |
27 if cmd.endswith(kwencodefilter): |
30 mf = mercurial.util.matcher(repo.root, '', [pat], [], [])[1] |
28 mf = util.matcher(repo.root, '', [pat], [], [])[1] |
31 for candidate in candidates: |
29 for candidate in candidates: |
32 if mf(candidate) and candidate not in files: |
30 if mf(candidate) and candidate not in files: |
33 files.append(candidate) |
31 files.append(candidate) |
34 # python2.4: |
32 # python2.4: |
35 # if mf(candidate): files.add(candidate) |
33 # if mf(candidate): files.add(candidate) |
36 |
34 |
37 if not files: # nothing to do |
35 if not files: # nothing to do |
38 return False |
36 return False |
39 |
37 |
40 user, date = repo.changelog.read(node)[1:3] |
38 user, date = repo.changelog.read(node)[1:3] |
41 user = mercurial.util.shortuser(user) |
39 user = util.shortuser(user) |
42 date = mercurial.util.datestr(date=date, |
40 date = util.datestr(date=date, format=util.defaultdateformats[2]) |
43 format=mercurial.util.defaultdateformats[2]) |
41 # %Y-%m-%d %H:%M |
44 # %Y-%m-%d %H:%M |
|
45 |
42 |
46 # collect filenames that were changed by hg update |
43 # collect filenames that were changed by hg update |
47 kwupdates = [] |
44 kwupdates = [] |
48 |
45 |
49 for f in files: |
46 for f in files: |