Mercurial > hg
comparison hgext/eol.py @ 13617:9cb1a42cd4b3
eol: rename hook into checkheadshook, add checkallhook (issue2665)
"hook" is still an alias for "checkheadshook".
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Sun, 13 Mar 2011 15:07:44 +0100 |
parents | e6f93ca9ce86 |
children | 8aec2516602b |
comparison
equal
deleted
inserted
replaced
13616:e6f93ca9ce86 | 13617:9cb1a42cd4b3 |
---|---|
71 like the deprecated win32text extension does. This means that you can | 71 like the deprecated win32text extension does. This means that you can |
72 disable win32text and enable eol and your filters will still work. You | 72 disable win32text and enable eol and your filters will still work. You |
73 only need to these filters until you have prepared a ``.hgeol`` file. | 73 only need to these filters until you have prepared a ``.hgeol`` file. |
74 | 74 |
75 The ``win32text.forbid*`` hooks provided by the win32text extension | 75 The ``win32text.forbid*`` hooks provided by the win32text extension |
76 have been unified into a single hook named ``eol.hook``. The hook will | 76 have been unified into a single hook named ``eol.checkheadshook``. The |
77 lookup the expected line endings from the ``.hgeol`` file, which means | 77 hook will lookup the expected line endings from the ``.hgeol`` file, |
78 you must migrate to a ``.hgeol`` file first before using the hook. | 78 which means you must migrate to a ``.hgeol`` file first before using |
79 the hook. ``eol.checkheadshook`` only checks heads, intermediate | |
80 invalid revisions will be pushed. To forbid them completely, use the | |
81 ``eol.checkallhook`` hook. These hooks are best used as | |
82 ``pretxnchangegroup`` hooks. | |
79 | 83 |
80 See :hg:`help patterns` for more information about the glob patterns | 84 See :hg:`help patterns` for more information about the glob patterns |
81 used. | 85 used. |
82 """ | 86 """ |
83 | 87 |
198 except error.ParseError, inst: | 202 except error.ParseError, inst: |
199 ui.warn(_("warning: ignoring .hgeol file due to parse error " | 203 ui.warn(_("warning: ignoring .hgeol file due to parse error " |
200 "at %s: %s\n") % (inst.args[1], inst.args[0])) | 204 "at %s: %s\n") % (inst.args[1], inst.args[0])) |
201 return None | 205 return None |
202 | 206 |
203 def hook(ui, repo, node, hooktype, **kwargs): | 207 def _checkhook(ui, repo, node, headsonly): |
204 """verify that files have expected EOLs""" | 208 # Get revisions to check and touched files at the same time |
205 # Extract heads and get touched files set at the same time | |
206 files = set() | 209 files = set() |
207 heads = set() | 210 revs = set() |
208 for rev in xrange(repo[node].rev(), len(repo)): | 211 for rev in xrange(repo[node].rev(), len(repo)): |
209 ctx = repo[rev] | 212 ctx = repo[rev] |
210 files.update(ctx.files()) | 213 files.update(ctx.files()) |
211 heads.add(rev) | 214 revs.add(rev) |
212 for pctx in ctx.parents(): | 215 if headsonly: |
213 heads.discard(pctx.rev()) | 216 for pctx in ctx.parents(): |
214 for rev in heads: | 217 revs.discard(pctx.rev()) |
218 for rev in revs: | |
215 ctx = repo[rev] | 219 ctx = repo[rev] |
216 eol = parseeol(ui, repo, [ctx.node()]) | 220 eol = parseeol(ui, repo, [ctx.node()]) |
217 if eol: | 221 if eol: |
218 eol.checkrev(repo, ctx, files) | 222 eol.checkrev(repo, ctx, files) |
223 | |
224 def checkallhook(ui, repo, node, hooktype, **kwargs): | |
225 """verify that files have expected EOLs""" | |
226 _checkhook(ui, repo, node, False) | |
227 | |
228 def checkheadshook(ui, repo, node, hooktype, **kwargs): | |
229 """verify that files have expected EOLs""" | |
230 _checkhook(ui, repo, node, True) | |
231 | |
232 # "checkheadshook" used to be called "hook" | |
233 hook = checkheadshook | |
219 | 234 |
220 def preupdate(ui, repo, hooktype, parent1, parent2): | 235 def preupdate(ui, repo, hooktype, parent1, parent2): |
221 #print "preupdate for %s: %s -> %s" % (repo.root, parent1, parent2) | 236 #print "preupdate for %s: %s -> %s" % (repo.root, parent1, parent2) |
222 repo.loadeol([parent1]) | 237 repo.loadeol([parent1]) |
223 return False | 238 return False |