author | Matt Mackall <mpm@selenic.com> |
Tue, 22 Mar 2011 12:00:38 -0500 | |
branch | stable |
changeset 13718 | 5b3383ea67d2 |
parent 13624 | 78cc35e75ecc |
child 13625 | 8aec2516602b |
permissions | -rw-r--r-- |
11249
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
1 |
"""automatically manage newlines in repository files |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
2 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
3 |
This extension allows you to manage the type of line endings (CRLF or |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
4 |
LF) that are used in the repository and in the local working |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
5 |
directory. That way you can get CRLF line endings on Windows and LF on |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
6 |
Unix/Mac, thereby letting everybody use their OS native line endings. |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
7 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
8 |
The extension reads its configuration from a versioned ``.hgeol`` |
13471
bffa00360e13
eol: clarify where the .hgeol file is located
Martin Geisler <mg@aragost.com>
parents:
13127
diff
changeset
|
9 |
configuration file found in the root of the working copy. The |
11249
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
10 |
``.hgeol`` file use the same syntax as all other Mercurial |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
11 |
configuration files. It uses two sections, ``[patterns]`` and |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
12 |
``[repository]``. |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
13 |
|
13124
cc5f0c0c19bc
eol: improve help on whether EOLs are changed in working copy or repository
Erik Zielke <ez@aragost.com>
parents:
12980
diff
changeset
|
14 |
The ``[patterns]`` section specifies how line endings should be |
cc5f0c0c19bc
eol: improve help on whether EOLs are changed in working copy or repository
Erik Zielke <ez@aragost.com>
parents:
12980
diff
changeset
|
15 |
converted between the working copy and the repository. The format is |
cc5f0c0c19bc
eol: improve help on whether EOLs are changed in working copy or repository
Erik Zielke <ez@aragost.com>
parents:
12980
diff
changeset
|
16 |
specified by a file pattern. The first match is used, so put more |
cc5f0c0c19bc
eol: improve help on whether EOLs are changed in working copy or repository
Erik Zielke <ez@aragost.com>
parents:
12980
diff
changeset
|
17 |
specific patterns first. The available line endings are ``LF``, |
cc5f0c0c19bc
eol: improve help on whether EOLs are changed in working copy or repository
Erik Zielke <ez@aragost.com>
parents:
12980
diff
changeset
|
18 |
``CRLF``, and ``BIN``. |
11249
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
19 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
20 |
Files with the declared format of ``CRLF`` or ``LF`` are always |
13124
cc5f0c0c19bc
eol: improve help on whether EOLs are changed in working copy or repository
Erik Zielke <ez@aragost.com>
parents:
12980
diff
changeset
|
21 |
checked out and stored in the repository in that format and files |
cc5f0c0c19bc
eol: improve help on whether EOLs are changed in working copy or repository
Erik Zielke <ez@aragost.com>
parents:
12980
diff
changeset
|
22 |
declared to be binary (``BIN``) are left unchanged. Additionally, |
cc5f0c0c19bc
eol: improve help on whether EOLs are changed in working copy or repository
Erik Zielke <ez@aragost.com>
parents:
12980
diff
changeset
|
23 |
``native`` is an alias for checking out in the platform's default line |
cc5f0c0c19bc
eol: improve help on whether EOLs are changed in working copy or repository
Erik Zielke <ez@aragost.com>
parents:
12980
diff
changeset
|
24 |
ending: ``LF`` on Unix (including Mac OS X) and ``CRLF`` on |
cc5f0c0c19bc
eol: improve help on whether EOLs are changed in working copy or repository
Erik Zielke <ez@aragost.com>
parents:
12980
diff
changeset
|
25 |
Windows. Note that ``BIN`` (do nothing to line endings) is Mercurial's |
cc5f0c0c19bc
eol: improve help on whether EOLs are changed in working copy or repository
Erik Zielke <ez@aragost.com>
parents:
12980
diff
changeset
|
26 |
default behaviour; it is only needed if you need to override a later, |
cc5f0c0c19bc
eol: improve help on whether EOLs are changed in working copy or repository
Erik Zielke <ez@aragost.com>
parents:
12980
diff
changeset
|
27 |
more general pattern. |
11249
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
28 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
29 |
The optional ``[repository]`` section specifies the line endings to |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
30 |
use for files stored in the repository. It has a single setting, |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
31 |
``native``, which determines the storage line endings for files |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
32 |
declared as ``native`` in the ``[patterns]`` section. It can be set to |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
33 |
``LF`` or ``CRLF``. The default is ``LF``. For example, this means |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
34 |
that on Windows, files configured as ``native`` (``CRLF`` by default) |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
35 |
will be converted to ``LF`` when stored in the repository. Files |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
36 |
declared as ``LF``, ``CRLF``, or ``BIN`` in the ``[patterns]`` section |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
37 |
are always stored as-is in the repository. |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
38 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
39 |
Example versioned ``.hgeol`` file:: |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
40 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
41 |
[patterns] |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
42 |
**.py = native |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
43 |
**.vcproj = CRLF |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
44 |
**.txt = native |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
45 |
Makefile = LF |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
46 |
**.jpg = BIN |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
47 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
48 |
[repository] |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
49 |
native = LF |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
50 |
|
13124
cc5f0c0c19bc
eol: improve help on whether EOLs are changed in working copy or repository
Erik Zielke <ez@aragost.com>
parents:
12980
diff
changeset
|
51 |
.. note:: |
cc5f0c0c19bc
eol: improve help on whether EOLs are changed in working copy or repository
Erik Zielke <ez@aragost.com>
parents:
12980
diff
changeset
|
52 |
The rules will first apply when files are touched in the working |
cc5f0c0c19bc
eol: improve help on whether EOLs are changed in working copy or repository
Erik Zielke <ez@aragost.com>
parents:
12980
diff
changeset
|
53 |
copy, e.g. by updating to null and back to tip to touch all files. |
cc5f0c0c19bc
eol: improve help on whether EOLs are changed in working copy or repository
Erik Zielke <ez@aragost.com>
parents:
12980
diff
changeset
|
54 |
|
11249
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
55 |
The extension uses an optional ``[eol]`` section in your hgrc file |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
56 |
(not the ``.hgeol`` file) for settings that control the overall |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
57 |
behavior. There are two settings: |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
58 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
59 |
- ``eol.native`` (default ``os.linesep``) can be set to ``LF`` or |
12802
c82cd7b08158
eol: add missing word in module docstring
Georg Brandl <georg@python.org>
parents:
12308
diff
changeset
|
60 |
``CRLF`` to override the default interpretation of ``native`` for |
11249
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
61 |
checkout. This can be used with :hg:`archive` on Unix, say, to |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
62 |
generate an archive where files have line endings for Windows. |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
63 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
64 |
- ``eol.only-consistent`` (default True) can be set to False to make |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
65 |
the extension convert files with inconsistent EOLs. Inconsistent |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
66 |
means that there is both ``CRLF`` and ``LF`` present in the file. |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
67 |
Such files are normally not touched under the assumption that they |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
68 |
have mixed EOLs on purpose. |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
69 |
|
12979
733345a127ca
eol: fix win32text encode/decode filter names
Martin Geisler <mg@lazybytes.net>
parents:
12976
diff
changeset
|
70 |
The extension provides ``cleverencode:`` and ``cleverdecode:`` filters |
733345a127ca
eol: fix win32text encode/decode filter names
Martin Geisler <mg@lazybytes.net>
parents:
12976
diff
changeset
|
71 |
like the deprecated win32text extension does. This means that you can |
733345a127ca
eol: fix win32text encode/decode filter names
Martin Geisler <mg@lazybytes.net>
parents:
12976
diff
changeset
|
72 |
disable win32text and enable eol and your filters will still work. You |
733345a127ca
eol: fix win32text encode/decode filter names
Martin Geisler <mg@lazybytes.net>
parents:
12976
diff
changeset
|
73 |
only need to these filters until you have prepared a ``.hgeol`` file. |
733345a127ca
eol: fix win32text encode/decode filter names
Martin Geisler <mg@lazybytes.net>
parents:
12976
diff
changeset
|
74 |
|
12980
20974e51383a
eol: mention the hook in the module docstring
Martin Geisler <mg@lazybytes.net>
parents:
12974
diff
changeset
|
75 |
The ``win32text.forbid*`` hooks provided by the win32text extension |
20974e51383a
eol: mention the hook in the module docstring
Martin Geisler <mg@lazybytes.net>
parents:
12974
diff
changeset
|
76 |
have been unified into a single hook named ``eol.hook``. The hook will |
20974e51383a
eol: mention the hook in the module docstring
Martin Geisler <mg@lazybytes.net>
parents:
12974
diff
changeset
|
77 |
lookup the expected line endings from the ``.hgeol`` file, which means |
20974e51383a
eol: mention the hook in the module docstring
Martin Geisler <mg@lazybytes.net>
parents:
12974
diff
changeset
|
78 |
you must migrate to a ``.hgeol`` file first before using the hook. |
13502
c0f252757b41
eol: be explicit about how to enable hook (issue2661)
Martin Geisler <mg@aragost.com>
parents:
13501
diff
changeset
|
79 |
Remember to enable the eol extension in the repository where you |
c0f252757b41
eol: be explicit about how to enable hook (issue2661)
Martin Geisler <mg@aragost.com>
parents:
13501
diff
changeset
|
80 |
install the hook. |
12980
20974e51383a
eol: mention the hook in the module docstring
Martin Geisler <mg@lazybytes.net>
parents:
12974
diff
changeset
|
81 |
|
11249
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
82 |
See :hg:`help patterns` for more information about the glob patterns |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
83 |
used. |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
84 |
""" |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
85 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
86 |
from mercurial.i18n import _ |
13475
c7bef25ca393
eol: handle LockUnavailable error (issue2569)
Martin Geisler <mg@aragost.com>
parents:
13471
diff
changeset
|
87 |
from mercurial import util, config, extensions, match, error |
11249
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
88 |
import re, os |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
89 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
90 |
# Matches a lone LF, i.e., one that is not part of CRLF. |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
91 |
singlelf = re.compile('(^|[^\r])\n') |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
92 |
# Matches a single EOL which can either be a CRLF where repeated CR |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
93 |
# are removed or a LF. We do not care about old Machintosh files, so a |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
94 |
# stray CR is an error. |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
95 |
eolre = re.compile('\r*\n') |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
96 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
97 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
98 |
def inconsistenteol(data): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
99 |
return '\r\n' in data and singlelf.search(data) |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
100 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
101 |
def tolf(s, params, ui, **kwargs): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
102 |
"""Filter to convert to LF EOLs.""" |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
103 |
if util.binary(s): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
104 |
return s |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
105 |
if ui.configbool('eol', 'only-consistent', True) and inconsistenteol(s): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
106 |
return s |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
107 |
return eolre.sub('\n', s) |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
108 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
109 |
def tocrlf(s, params, ui, **kwargs): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
110 |
"""Filter to convert to CRLF EOLs.""" |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
111 |
if util.binary(s): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
112 |
return s |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
113 |
if ui.configbool('eol', 'only-consistent', True) and inconsistenteol(s): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
114 |
return s |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
115 |
return eolre.sub('\r\n', s) |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
116 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
117 |
def isbinary(s, params): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
118 |
"""Filter to do nothing with the file.""" |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
119 |
return s |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
120 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
121 |
filters = { |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
122 |
'to-lf': tolf, |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
123 |
'to-crlf': tocrlf, |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
124 |
'is-binary': isbinary, |
12975
278e3c9b939e
eol: added filter aliases for backwards compatibility with win32text
Colin Caughie <c.caughie@indigovision.com>
parents:
12802
diff
changeset
|
125 |
# The following provide backwards compatibility with win32text |
12979
733345a127ca
eol: fix win32text encode/decode filter names
Martin Geisler <mg@lazybytes.net>
parents:
12976
diff
changeset
|
126 |
'cleverencode:': tolf, |
733345a127ca
eol: fix win32text encode/decode filter names
Martin Geisler <mg@lazybytes.net>
parents:
12976
diff
changeset
|
127 |
'cleverdecode:': tocrlf |
11249
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
128 |
} |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
129 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
130 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
131 |
def hook(ui, repo, node, hooktype, **kwargs): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
132 |
"""verify that files have expected EOLs""" |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
133 |
files = set() |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
134 |
for rev in xrange(repo[node].rev(), len(repo)): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
135 |
files.update(repo[rev].files()) |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
136 |
tip = repo['tip'] |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
137 |
for f in files: |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
138 |
if f not in tip: |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
139 |
continue |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
140 |
for pattern, target in ui.configitems('encode'): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
141 |
if match.match(repo.root, '', [pattern])(f): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
142 |
data = tip[f].data() |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
143 |
if target == "to-lf" and "\r\n" in data: |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
144 |
raise util.Abort(_("%s should not have CRLF line endings") |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
145 |
% f) |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
146 |
elif target == "to-crlf" and singlelf.search(data): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
147 |
raise util.Abort(_("%s should not have LF line endings") |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
148 |
% f) |
13501
50b825c1adb1
eol: stop after first matched rule in hook (issue2660)
Antoine Pitrou <solipsis@pitrou.net>
parents:
13475
diff
changeset
|
149 |
# Ignore other rules for this file |
50b825c1adb1
eol: stop after first matched rule in hook (issue2660)
Antoine Pitrou <solipsis@pitrou.net>
parents:
13475
diff
changeset
|
150 |
break |
11249
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
151 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
152 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
153 |
def preupdate(ui, repo, hooktype, parent1, parent2): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
154 |
#print "preupdate for %s: %s -> %s" % (repo.root, parent1, parent2) |
13505
9b617c56eb65
eol: do not abort on parse error
Martin Geisler <mg@aragost.com>
parents:
13502
diff
changeset
|
155 |
try: |
9b617c56eb65
eol: do not abort on parse error
Martin Geisler <mg@aragost.com>
parents:
13502
diff
changeset
|
156 |
repo.readhgeol(parent1) |
9b617c56eb65
eol: do not abort on parse error
Martin Geisler <mg@aragost.com>
parents:
13502
diff
changeset
|
157 |
except error.ParseError, inst: |
9b617c56eb65
eol: do not abort on parse error
Martin Geisler <mg@aragost.com>
parents:
13502
diff
changeset
|
158 |
ui.warn(_("warning: ignoring .hgeol file due to parse error " |
9b617c56eb65
eol: do not abort on parse error
Martin Geisler <mg@aragost.com>
parents:
13502
diff
changeset
|
159 |
"at %s: %s\n") % (inst.args[1], inst.args[0])) |
11249
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
160 |
return False |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
161 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
162 |
def uisetup(ui): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
163 |
ui.setconfig('hooks', 'preupdate.eol', preupdate) |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
164 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
165 |
def extsetup(ui): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
166 |
try: |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
167 |
extensions.find('win32text') |
13624
78cc35e75ecc
eol: do not abort when win32text is found, only warn
Steve Borho <steve@borho.org>
parents:
13581
diff
changeset
|
168 |
ui.warn(_("the eol extension is incompatible with the " |
78cc35e75ecc
eol: do not abort when win32text is found, only warn
Steve Borho <steve@borho.org>
parents:
13581
diff
changeset
|
169 |
"win32text extension\n")) |
11249
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
170 |
except KeyError: |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
171 |
pass |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
172 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
173 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
174 |
def reposetup(ui, repo): |
12307
0852da25a31b
eol: setup the repo.ui in reposetup()
Steve Borho <steve@borho.org>
parents:
11249
diff
changeset
|
175 |
uisetup(repo.ui) |
11249
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
176 |
#print "reposetup for", repo.root |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
177 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
178 |
if not repo.local(): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
179 |
return |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
180 |
for name, fn in filters.iteritems(): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
181 |
repo.adddatafilter(name, fn) |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
182 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
183 |
ui.setconfig('patch', 'eol', 'auto') |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
184 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
185 |
class eolrepo(repo.__class__): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
186 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
187 |
_decode = {'LF': 'to-lf', 'CRLF': 'to-crlf', 'BIN': 'is-binary'} |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
188 |
_encode = {'LF': 'to-lf', 'CRLF': 'to-crlf', 'BIN': 'is-binary'} |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
189 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
190 |
def readhgeol(self, node=None, data=None): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
191 |
if data is None: |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
192 |
try: |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
193 |
if node is None: |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
194 |
data = self.wfile('.hgeol').read() |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
195 |
else: |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
196 |
data = self[node]['.hgeol'].data() |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
197 |
except (IOError, LookupError): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
198 |
return None |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
199 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
200 |
if self.ui.config('eol', 'native', os.linesep) in ('LF', '\n'): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
201 |
self._decode['NATIVE'] = 'to-lf' |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
202 |
else: |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
203 |
self._decode['NATIVE'] = 'to-crlf' |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
204 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
205 |
eol = config.config() |
12974
75e4fade4ad9
eol: exclude .hgtags file from eol translation (issue2493)
Colin Caughie <c.caughie@indigovision.com>
parents:
12802
diff
changeset
|
206 |
# Our files should not be touched. The pattern must be |
75e4fade4ad9
eol: exclude .hgtags file from eol translation (issue2493)
Colin Caughie <c.caughie@indigovision.com>
parents:
12802
diff
changeset
|
207 |
# inserted first override a '** = native' pattern. |
75e4fade4ad9
eol: exclude .hgtags file from eol translation (issue2493)
Colin Caughie <c.caughie@indigovision.com>
parents:
12802
diff
changeset
|
208 |
eol.set('patterns', '.hg*', 'BIN') |
75e4fade4ad9
eol: exclude .hgtags file from eol translation (issue2493)
Colin Caughie <c.caughie@indigovision.com>
parents:
12802
diff
changeset
|
209 |
# We can then parse the user's patterns. |
11249
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
210 |
eol.parse('.hgeol', data) |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
211 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
212 |
if eol.get('repository', 'native') == 'CRLF': |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
213 |
self._encode['NATIVE'] = 'to-crlf' |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
214 |
else: |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
215 |
self._encode['NATIVE'] = 'to-lf' |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
216 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
217 |
for pattern, style in eol.items('patterns'): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
218 |
key = style.upper() |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
219 |
try: |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
220 |
self.ui.setconfig('decode', pattern, self._decode[key]) |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
221 |
self.ui.setconfig('encode', pattern, self._encode[key]) |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
222 |
except KeyError: |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
223 |
self.ui.warn(_("ignoring unknown EOL style '%s' from %s\n") |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
224 |
% (style, eol.source('patterns', pattern))) |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
225 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
226 |
include = [] |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
227 |
exclude = [] |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
228 |
for pattern, style in eol.items('patterns'): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
229 |
key = style.upper() |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
230 |
if key == 'BIN': |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
231 |
exclude.append(pattern) |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
232 |
else: |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
233 |
include.append(pattern) |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
234 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
235 |
# This will match the files for which we need to care |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
236 |
# about inconsistent newlines. |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
237 |
return match.match(self.root, '', [], include, exclude) |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
238 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
239 |
def _hgcleardirstate(self): |
13505
9b617c56eb65
eol: do not abort on parse error
Martin Geisler <mg@aragost.com>
parents:
13502
diff
changeset
|
240 |
try: |
9b617c56eb65
eol: do not abort on parse error
Martin Geisler <mg@aragost.com>
parents:
13502
diff
changeset
|
241 |
self._eolfile = self.readhgeol() or self.readhgeol('tip') |
9b617c56eb65
eol: do not abort on parse error
Martin Geisler <mg@aragost.com>
parents:
13502
diff
changeset
|
242 |
except error.ParseError, inst: |
9b617c56eb65
eol: do not abort on parse error
Martin Geisler <mg@aragost.com>
parents:
13502
diff
changeset
|
243 |
ui.warn(_("warning: ignoring .hgeol file due to parse error " |
9b617c56eb65
eol: do not abort on parse error
Martin Geisler <mg@aragost.com>
parents:
13502
diff
changeset
|
244 |
"at %s: %s\n") % (inst.args[1], inst.args[0])) |
9b617c56eb65
eol: do not abort on parse error
Martin Geisler <mg@aragost.com>
parents:
13502
diff
changeset
|
245 |
self._eolfile = None |
11249
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
246 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
247 |
if not self._eolfile: |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
248 |
self._eolfile = util.never |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
249 |
return |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
250 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
251 |
try: |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
252 |
cachemtime = os.path.getmtime(self.join("eol.cache")) |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
253 |
except OSError: |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
254 |
cachemtime = 0 |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
255 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
256 |
try: |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
257 |
eolmtime = os.path.getmtime(self.wjoin(".hgeol")) |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
258 |
except OSError: |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
259 |
eolmtime = 0 |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
260 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
261 |
if eolmtime > cachemtime: |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
262 |
ui.debug("eol: detected change in .hgeol\n") |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
263 |
wlock = None |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
264 |
try: |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
265 |
wlock = self.wlock() |
13581
b30a488762e1
eol: use dirstate methods to clear dirstate
Martin Geisler <mg@lazybytes.net>
parents:
13505
diff
changeset
|
266 |
for f in self.dirstate: |
b30a488762e1
eol: use dirstate methods to clear dirstate
Martin Geisler <mg@lazybytes.net>
parents:
13505
diff
changeset
|
267 |
if self.dirstate[f] == 'n': |
b30a488762e1
eol: use dirstate methods to clear dirstate
Martin Geisler <mg@lazybytes.net>
parents:
13505
diff
changeset
|
268 |
# all normal files need to be looked at |
b30a488762e1
eol: use dirstate methods to clear dirstate
Martin Geisler <mg@lazybytes.net>
parents:
13505
diff
changeset
|
269 |
# again since the new .hgeol file might no |
b30a488762e1
eol: use dirstate methods to clear dirstate
Martin Geisler <mg@lazybytes.net>
parents:
13505
diff
changeset
|
270 |
# longer match a file it matched before |
b30a488762e1
eol: use dirstate methods to clear dirstate
Martin Geisler <mg@lazybytes.net>
parents:
13505
diff
changeset
|
271 |
self.dirstate.normallookup(f) |
13475
c7bef25ca393
eol: handle LockUnavailable error (issue2569)
Martin Geisler <mg@aragost.com>
parents:
13471
diff
changeset
|
272 |
# Touch the cache to update mtime. |
11249
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
273 |
self.opener("eol.cache", "w").close() |
13475
c7bef25ca393
eol: handle LockUnavailable error (issue2569)
Martin Geisler <mg@aragost.com>
parents:
13471
diff
changeset
|
274 |
wlock.release() |
c7bef25ca393
eol: handle LockUnavailable error (issue2569)
Martin Geisler <mg@aragost.com>
parents:
13471
diff
changeset
|
275 |
except error.LockUnavailable: |
c7bef25ca393
eol: handle LockUnavailable error (issue2569)
Martin Geisler <mg@aragost.com>
parents:
13471
diff
changeset
|
276 |
# If we cannot lock the repository and clear the |
c7bef25ca393
eol: handle LockUnavailable error (issue2569)
Martin Geisler <mg@aragost.com>
parents:
13471
diff
changeset
|
277 |
# dirstate, then a commit might not see all files |
c7bef25ca393
eol: handle LockUnavailable error (issue2569)
Martin Geisler <mg@aragost.com>
parents:
13471
diff
changeset
|
278 |
# as modified. But if we cannot lock the |
c7bef25ca393
eol: handle LockUnavailable error (issue2569)
Martin Geisler <mg@aragost.com>
parents:
13471
diff
changeset
|
279 |
# repository, then we can also not make a commit, |
c7bef25ca393
eol: handle LockUnavailable error (issue2569)
Martin Geisler <mg@aragost.com>
parents:
13471
diff
changeset
|
280 |
# so ignore the error. |
c7bef25ca393
eol: handle LockUnavailable error (issue2569)
Martin Geisler <mg@aragost.com>
parents:
13471
diff
changeset
|
281 |
pass |
11249
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
282 |
|
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
283 |
def commitctx(self, ctx, error=False): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
284 |
for f in sorted(ctx.added() + ctx.modified()): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
285 |
if not self._eolfile(f): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
286 |
continue |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
287 |
data = ctx[f].data() |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
288 |
if util.binary(data): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
289 |
# We should not abort here, since the user should |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
290 |
# be able to say "** = native" to automatically |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
291 |
# have all non-binary files taken care of. |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
292 |
continue |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
293 |
if inconsistenteol(data): |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
294 |
raise util.Abort(_("inconsistent newline style " |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
295 |
"in %s\n" % f)) |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
296 |
return super(eolrepo, self).commitctx(ctx, error) |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
297 |
repo.__class__ = eolrepo |
0bb67503ad4b
eol: extension for managing file EOLs
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
298 |
repo._hgcleardirstate() |