##// END OF EJS Templates
Strip filter name from command before passing to filter function....
Jesse Glick -
r6066:f3a8b536 default
parent child Browse files
Show More
@@ -0,0 +1,60 b''
1 #!/bin/sh
2
3 hg init
4
5 cat > .hg/hgrc <<EOF
6 [extensions]
7 prefixfilter = prefix.py
8 [encode]
9 *.txt = stripprefix: Copyright 2046, The Masters
10 [decode]
11 *.txt = insertprefix: Copyright 2046, The Masters
12 EOF
13
14 cat > prefix.py <<EOF
15 from mercurial import util
16 def stripprefix(s, cmd, filename, **kwargs):
17 header = '%s\n' % cmd
18 if s[:len(header)] != header:
19 raise util.Abort('missing header "%s" in %s' % (cmd, filename))
20 return s[len(header):]
21 def insertprefix(s, cmd):
22 return '%s\n%s' % (cmd, s)
23 def reposetup(ui, repo):
24 repo.adddatafilter('stripprefix:', stripprefix)
25 repo.adddatafilter('insertprefix:', insertprefix)
26 EOF
27
28 cat > .hgignore <<EOF
29 .hgignore
30 prefix.py
31 prefix.pyc
32 EOF
33
34 cat > stuff.txt <<EOF
35 Copyright 2046, The Masters
36 Some stuff to ponder very carefully.
37 EOF
38 hg add stuff.txt
39 hg ci -m stuff
40
41 echo '% Repository data:'
42 hg cat stuff.txt
43
44 echo '% Fresh checkout:'
45 rm stuff.txt
46 hg up
47 cat stuff.txt
48 echo >> stuff.txt <<EOF
49 Very very carefully.
50 EOF
51 hg stat
52
53 cat > morestuff.txt <<EOF
54 Unauthorized material subject to destruction.
55 EOF
56
57 echo '% Problem encoding:'
58 hg add morestuff.txt
59 hg ci -m morestuff
60 hg stat
@@ -0,0 +1,11 b''
1 % Repository data:
2 Some stuff to ponder very carefully.
3 % Fresh checkout:
4 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
5 Copyright 2046, The Masters
6 Some stuff to ponder very carefully.
7 M stuff.txt
8 % Problem encoding:
9 abort: missing header "Copyright 2046, The Masters" in morestuff.txt
10 M stuff.txt
11 A morestuff.txt
@@ -501,9 +501,11 b' class localrepository(repo.repository):'
501 for pat, cmd in self.ui.configitems(filter):
501 for pat, cmd in self.ui.configitems(filter):
502 mf = util.matcher(self.root, "", [pat], [], [])[1]
502 mf = util.matcher(self.root, "", [pat], [], [])[1]
503 fn = None
503 fn = None
504 params = cmd
504 for name, filterfn in self._datafilters.iteritems():
505 for name, filterfn in self._datafilters.iteritems():
505 if cmd.startswith(name):
506 if cmd.startswith(name):
506 fn = filterfn
507 fn = filterfn
508 params = cmd[len(name):].lstrip()
507 break
509 break
508 if not fn:
510 if not fn:
509 fn = lambda s, c, **kwargs: util.filter(s, c)
511 fn = lambda s, c, **kwargs: util.filter(s, c)
@@ -511,7 +513,7 b' class localrepository(repo.repository):'
511 if not inspect.getargspec(fn)[2]:
513 if not inspect.getargspec(fn)[2]:
512 oldfn = fn
514 oldfn = fn
513 fn = lambda s, c, **kwargs: oldfn(s, c)
515 fn = lambda s, c, **kwargs: oldfn(s, c)
514 l.append((mf, fn, cmd))
516 l.append((mf, fn, params))
515 self.filterpats[filter] = l
517 self.filterpats[filter] = l
516
518
517 for mf, fn, cmd in self.filterpats[filter]:
519 for mf, fn, cmd in self.filterpats[filter]:
General Comments 0
You need to be logged in to leave comments. Login now