Show More
@@ -0,0 +1,34 b'' | |||||
|
1 | #!/bin/sh | |||
|
2 | ||||
|
3 | hg init | |||
|
4 | ||||
|
5 | cat > .hg/hgrc <<EOF | |||
|
6 | [encode] | |||
|
7 | *.gz = gunzip | |||
|
8 | ||||
|
9 | [decode] | |||
|
10 | *.gz = gzip | |||
|
11 | ||||
|
12 | EOF | |||
|
13 | ||||
|
14 | echo "this is a test" | gzip > a.gz | |||
|
15 | hg add a.gz | |||
|
16 | hg ci -m "test" -d "0 0" | |||
|
17 | echo %% no changes | |||
|
18 | hg status | |||
|
19 | touch a.gz | |||
|
20 | ||||
|
21 | echo %% no changes | |||
|
22 | hg status | |||
|
23 | ||||
|
24 | echo %% uncompressed contents in repo | |||
|
25 | hg debugdata .hg/data/a.gz.d 0 | |||
|
26 | ||||
|
27 | echo %% uncompress our working dir copy | |||
|
28 | gunzip < a.gz | |||
|
29 | ||||
|
30 | rm a.gz | |||
|
31 | hg co | |||
|
32 | ||||
|
33 | echo %% uncompress our new working dir copy | |||
|
34 | gunzip < a.gz |
@@ -0,0 +1,8 b'' | |||||
|
1 | %% no changes | |||
|
2 | %% no changes | |||
|
3 | %% uncompressed contents in repo | |||
|
4 | this is a test | |||
|
5 | %% uncompress our working dir copy | |||
|
6 | this is a test | |||
|
7 | %% uncompress our new working dir copy | |||
|
8 | this is a test |
@@ -61,6 +61,26 b' This section describes the different sec' | |||||
61 | Mercurial "hgrc" file, the purpose of each section, its possible |
|
61 | Mercurial "hgrc" file, the purpose of each section, its possible | |
62 | keys, and their possible values. |
|
62 | keys, and their possible values. | |
63 |
|
63 | |||
|
64 | decode/encode:: | |||
|
65 | Filters for transforming files on checkout/checkin. This would | |||
|
66 | typically be used for newline processing or other | |||
|
67 | localization/canonicalization of files. | |||
|
68 | ||||
|
69 | Filters consist of a filter pattern followed by a filter command. | |||
|
70 | The command must accept data on stdin and return the transformed | |||
|
71 | data on stdout. | |||
|
72 | ||||
|
73 | Example: | |||
|
74 | ||||
|
75 | [encode] | |||
|
76 | # uncompress gzip files on checkin to improve delta compression | |||
|
77 | # note: not necessarily a good idea, just an example | |||
|
78 | *.gz = gunzip | |||
|
79 | ||||
|
80 | [decode] | |||
|
81 | # recompress gzip files when writing them to the working dir | |||
|
82 | *.gz = gzip | |||
|
83 | ||||
64 | hooks:: |
|
84 | hooks:: | |
65 | Commands that get automatically executed by various actions such as |
|
85 | Commands that get automatically executed by various actions such as | |
66 | starting or finishing a commit. |
|
86 | starting or finishing a commit. |
@@ -33,6 +33,8 b' class localrepository:' | |||||
33 | self.changelog = changelog.changelog(self.opener) |
|
33 | self.changelog = changelog.changelog(self.opener) | |
34 | self.tagscache = None |
|
34 | self.tagscache = None | |
35 | self.nodetagscache = None |
|
35 | self.nodetagscache = None | |
|
36 | self.encodepats = None | |||
|
37 | self.decodepats = None | |||
36 |
|
38 | |||
37 | if create: |
|
39 | if create: | |
38 | os.mkdir(self.path) |
|
40 | os.mkdir(self.path) | |
@@ -160,9 +162,37 b' class localrepository:' | |||||
160 | return self.wopener(f, mode) |
|
162 | return self.wopener(f, mode) | |
161 |
|
163 | |||
162 | def wread(self, filename): |
|
164 | def wread(self, filename): | |
163 | return self.wopener(filename, 'r').read() |
|
165 | if self.encodepats == None: | |
|
166 | l = [] | |||
|
167 | for pat, cmd in self.ui.configitems("encode"): | |||
|
168 | mf = util.matcher("", "/", [pat], [], [])[1] | |||
|
169 | l.append((mf, cmd)) | |||
|
170 | self.encodepats = l | |||
|
171 | ||||
|
172 | data = self.wopener(filename, 'r').read() | |||
|
173 | ||||
|
174 | for mf, cmd in self.encodepats: | |||
|
175 | if mf(filename): | |||
|
176 | self.ui.debug("filtering %s through %s\n" % (filename, cmd)) | |||
|
177 | data = util.filter(data, cmd) | |||
|
178 | break | |||
|
179 | ||||
|
180 | return data | |||
164 |
|
181 | |||
165 | def wwrite(self, filename, data, fd=None): |
|
182 | def wwrite(self, filename, data, fd=None): | |
|
183 | if self.decodepats == None: | |||
|
184 | l = [] | |||
|
185 | for pat, cmd in self.ui.configitems("decode"): | |||
|
186 | mf = util.matcher("", "/", [pat], [], [])[1] | |||
|
187 | l.append((mf, cmd)) | |||
|
188 | self.decodepats = l | |||
|
189 | ||||
|
190 | for mf, cmd in self.decodepats: | |||
|
191 | if mf(filename): | |||
|
192 | self.ui.debug("filtering %s through %s\n" % (filename, cmd)) | |||
|
193 | data = util.filter(data, cmd) | |||
|
194 | break | |||
|
195 | ||||
166 | if fd: |
|
196 | if fd: | |
167 | return fd.write(data) |
|
197 | return fd.write(data) | |
168 | return self.wopener(filename, 'w').write(data) |
|
198 | return self.wopener(filename, 'w').write(data) |
@@ -12,7 +12,23 b' platform-specific details from the core.' | |||||
12 |
|
12 | |||
13 | import os, errno |
|
13 | import os, errno | |
14 | from demandload import * |
|
14 | from demandload import * | |
15 | demandload(globals(), "re cStringIO shutil") |
|
15 | demandload(globals(), "re cStringIO shutil popen2 threading") | |
|
16 | ||||
|
17 | def filter(s, cmd): | |||
|
18 | "filter a string through a command that transforms its input to its output" | |||
|
19 | (pout, pin) = popen2.popen2(cmd, -1, 'b') | |||
|
20 | def writer(): | |||
|
21 | pin.write(s) | |||
|
22 | pin.close() | |||
|
23 | ||||
|
24 | # we should use select instead on UNIX, but this will work on most | |||
|
25 | # systems, including Windows | |||
|
26 | w = threading.Thread(target=writer) | |||
|
27 | w.start() | |||
|
28 | f = pout.read() | |||
|
29 | pout.close() | |||
|
30 | w.join() | |||
|
31 | return f | |||
16 |
|
32 | |||
17 | def binary(s): |
|
33 | def binary(s): | |
18 | """return true if a string is binary data using diff's heuristic""" |
|
34 | """return true if a string is binary data using diff's heuristic""" |
General Comments 0
You need to be logged in to leave comments.
Login now