hgext/win32text.py
author Martin Geisler <mg@daimi.au.dk>
Tue, 21 Oct 2008 17:47:49 +0200
changeset 7225 59b4ae211584
parent 6750 fb42030d79d6
child 7873 4a4c7f6a5912
permissions -rw-r--r--
i18n: import _ instead of gettext
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
     1
# win32text.py - LF <-> CRLF/CR translation utilities for Windows/Mac users
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
     2
#
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
     3
# This software may be used and distributed according to the terms
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
     4
# of the GNU General Public License, incorporated herein by reference.
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
     5
#
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
     6
# To perform automatic newline conversion, use:
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
     7
#
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
     8
# [extensions]
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
     9
# hgext.win32text =
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    10
# [encode]
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    11
# ** = cleverencode:
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    12
# # or ** = macencode:
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    13
# [decode]
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    14
# ** = cleverdecode:
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    15
# # or ** = macdecode:
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    16
#
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    17
# If not doing conversion, to make sure you do not commit CRLF/CR by accident:
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    18
#
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    19
# [hooks]
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    20
# pretxncommit.crlf = python:hgext.win32text.forbidcrlf
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    21
# # or pretxncommit.cr = python:hgext.win32text.forbidcr
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    22
#
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    23
# To do the same check on a server to prevent CRLF/CR from being pushed or
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    24
# pulled:
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    25
#
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    26
# [hooks]
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    27
# pretxnchangegroup.crlf = python:hgext.win32text.forbidcrlf
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    28
# # or pretxnchangegroup.cr = python:hgext.win32text.forbidcr
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    29
7225
59b4ae211584 i18n: import _ instead of gettext
Martin Geisler <mg@daimi.au.dk>
parents: 6750
diff changeset
    30
from mercurial.i18n import _
6211
f89fd07fc51d Expand import * to allow Pyflakes to find problems
Joel Rosdahl <joel@rosdahl.net>
parents: 5967
diff changeset
    31
from mercurial.node import bin, short
6510
37ab2331b94c win32text: actually import util so util.binary() can be used
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6508
diff changeset
    32
from mercurial import util
4859
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    33
import re
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    34
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    35
# regexp for single LF without CR preceding.
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    36
re_single_lf = re.compile('(^|[^\r])\n', re.MULTILINE)
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    37
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    38
newlinestr = {'\r\n': 'CRLF', '\r': 'CR'}
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    39
filterstr = {'\r\n': 'clever', '\r': 'mac'}
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    40
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    41
def checknewline(s, newline, ui=None, repo=None, filename=None):
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    42
    # warn if already has 'newline' in repository.
4859
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    43
    # it might cause unexpected eol conversion.
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    44
    # see issue 302:
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    45
    #   http://www.selenic.com/mercurial/bts/issue302
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    46
    if newline in s and ui and filename and repo:
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    47
        ui.warn(_('WARNING: %s already has %s line endings\n'
5967
f8ad3b76e923 Provide better context for custom Python encode/decode filters.
Jesse Glick <jesse.glick@sun.com>
parents: 5966
diff changeset
    48
                  'and does not need EOL conversion by the win32text plugin.\n'
f8ad3b76e923 Provide better context for custom Python encode/decode filters.
Jesse Glick <jesse.glick@sun.com>
parents: 5966
diff changeset
    49
                  'Before your next commit, please reconsider your '
f8ad3b76e923 Provide better context for custom Python encode/decode filters.
Jesse Glick <jesse.glick@sun.com>
parents: 5966
diff changeset
    50
                  'encode/decode settings in \nMercurial.ini or %s.\n') %
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    51
                (filename, newlinestr[newline], repo.join('hgrc')))
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    52
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    53
def dumbdecode(s, cmd, **kwargs):
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    54
    checknewline(s, '\r\n', **kwargs)
4859
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    55
    # replace single LF to CRLF
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    56
    return re_single_lf.sub('\\1\r\n', s)
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    57
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    58
def dumbencode(s, cmd):
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    59
    return s.replace('\r\n', '\n')
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    60
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    61
def macdumbdecode(s, cmd, **kwargs):
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    62
    checknewline(s, '\r', **kwargs)
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    63
    return s.replace('\n', '\r')
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    64
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    65
def macdumbencode(s, cmd):
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    66
    return s.replace('\r', '\n')
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    67
5967
f8ad3b76e923 Provide better context for custom Python encode/decode filters.
Jesse Glick <jesse.glick@sun.com>
parents: 5966
diff changeset
    68
def cleverdecode(s, cmd, **kwargs):
6508
4b2c266bf059 Get rid of reimplementations of util.binary
Bryan O'Sullivan <bos@serpentine.com>
parents: 6484
diff changeset
    69
    if not util.binary(s):
6473
9c897ffd3637 Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents: 6247
diff changeset
    70
        return dumbdecode(s, cmd, **kwargs)
9c897ffd3637 Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents: 6247
diff changeset
    71
    return s
4859
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    72
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    73
def cleverencode(s, cmd):
6508
4b2c266bf059 Get rid of reimplementations of util.binary
Bryan O'Sullivan <bos@serpentine.com>
parents: 6484
diff changeset
    74
    if not util.binary(s):
6473
9c897ffd3637 Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents: 6247
diff changeset
    75
        return dumbencode(s, cmd)
9c897ffd3637 Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents: 6247
diff changeset
    76
    return s
4859
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    77
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    78
def macdecode(s, cmd, **kwargs):
6508
4b2c266bf059 Get rid of reimplementations of util.binary
Bryan O'Sullivan <bos@serpentine.com>
parents: 6484
diff changeset
    79
    if not util.binary(s):
6484
ab8038bf5127 Merge with macencode branch
Patrick Mezard <pmezard@gmail.com>
parents: 6473 6483
diff changeset
    80
        return macdumbdecode(s, cmd, **kwargs)
ab8038bf5127 Merge with macencode branch
Patrick Mezard <pmezard@gmail.com>
parents: 6473 6483
diff changeset
    81
    return s
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    82
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    83
def macencode(s, cmd):
6508
4b2c266bf059 Get rid of reimplementations of util.binary
Bryan O'Sullivan <bos@serpentine.com>
parents: 6484
diff changeset
    84
    if not util.binary(s):
6484
ab8038bf5127 Merge with macencode branch
Patrick Mezard <pmezard@gmail.com>
parents: 6473 6483
diff changeset
    85
        return macdumbencode(s, cmd)
ab8038bf5127 Merge with macencode branch
Patrick Mezard <pmezard@gmail.com>
parents: 6473 6483
diff changeset
    86
    return s
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    87
5966
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
    88
_filters = {
4859
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    89
    'dumbdecode:': dumbdecode,
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    90
    'dumbencode:': dumbencode,
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    91
    'cleverdecode:': cleverdecode,
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
    92
    'cleverencode:': cleverencode,
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    93
    'macdumbdecode:': macdumbdecode,
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    94
    'macdumbencode:': macdumbencode,
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    95
    'macdecode:': macdecode,
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
    96
    'macencode:': macencode,
5966
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
    97
    }
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
    98
6483
0a803195bb29 win32text: rename forbidcrlforcr() function
Patrick Mezard <pmezard@gmail.com>
parents: 6481
diff changeset
    99
def forbidnewline(ui, repo, hooktype, node, newline, **kwargs):
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   100
    halt = False
6750
fb42030d79d6 add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents: 6747
diff changeset
   101
    for rev in xrange(repo[node].rev(), len(repo)):
6747
f6c00b17387c use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents: 6510
diff changeset
   102
        c = repo[rev]
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   103
        for f in c.files():
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   104
            if f not in c:
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   105
                continue
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   106
            data = c[f].data()
6508
4b2c266bf059 Get rid of reimplementations of util.binary
Bryan O'Sullivan <bos@serpentine.com>
parents: 6484
diff changeset
   107
            if not util.binary(data) and newline in data:
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   108
                if not halt:
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   109
                    ui.warn(_('Attempt to commit or push text file(s) '
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
   110
                              'using %s line endings\n') %
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
   111
                              newlinestr[newline])
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   112
                ui.warn(_('in %s: %s\n') % (short(c.node()), f))
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   113
                halt = True
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   114
    if halt and hooktype == 'pretxnchangegroup':
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
   115
        crlf = newlinestr[newline].lower()
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
   116
        filter = filterstr[newline]
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   117
        ui.warn(_('\nTo prevent this mistake in your local repository,\n'
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   118
                  'add to Mercurial.ini or .hg/hgrc:\n'
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   119
                  '\n'
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   120
                  '[hooks]\n'
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
   121
                  'pretxncommit.%s = python:hgext.win32text.forbid%s\n'
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   122
                  '\n'
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   123
                  'and also consider adding:\n'
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   124
                  '\n'
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   125
                  '[extensions]\n'
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   126
                  'hgext.win32text =\n'
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   127
                  '[encode]\n'
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
   128
                  '** = %sencode:\n'
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   129
                  '[decode]\n'
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
   130
                  '** = %sdecode:\n') % (crlf, crlf, filter, filter))
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
   131
    return halt
5966
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
   132
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
   133
def forbidcrlf(ui, repo, hooktype, node, **kwargs):
6483
0a803195bb29 win32text: rename forbidcrlforcr() function
Patrick Mezard <pmezard@gmail.com>
parents: 6481
diff changeset
   134
    return forbidnewline(ui, repo, hooktype, node, '\r\n', **kwargs)
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
   135
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
   136
def forbidcr(ui, repo, hooktype, node, **kwargs):
6483
0a803195bb29 win32text: rename forbidcrlforcr() function
Patrick Mezard <pmezard@gmail.com>
parents: 6481
diff changeset
   137
    return forbidnewline(ui, repo, hooktype, node, '\r', **kwargs)
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
   138
5966
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
   139
def reposetup(ui, repo):
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
   140
    if not repo.local():
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
   141
        return
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
   142
    for name, fn in _filters.iteritems():
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
   143
        repo.adddatafilter(name, fn)
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
   144